Comments (7)
here is what I did:
element_type = next(i.type_.__resource_type__ for i in resource.element_properties() if i.name == element)
from fhir.resources.
We should have a class method available.
>>> from fhir.resources.observation import Observation
>>> Observation.get_resource_type()
from fhir.resources.
Thanks but it does not work for the elements...
1 from fhir.resources.observation import Observation
----> 2 Observation.code.get_resource_type
AttributeError: type object 'Observation' has no attribute 'code'
from fhir.resources.
@Healthedata1 that is something not possible, unfortunately.
from fhir.resources.
For my application, I wished to search a FHIR resource for objects of type Coding, and return the list of all Coding relevant to the resource.
For any who follow, I used a different approach:
from fhir.resources.coding import Coding
def reflect_get_coding(fhir):
response_objects = []
if not isinstance(fhir, str):
if isinstance(fhir, Coding):
response_objects.append(fhir)
elif isinstance(fhir, Iterable):
for item in fhir:
response_objects.extend(reflect_get_coding(item))
elif hasattr(fhir, '__dict__'):
for prop, value in vars(fhir).items():
if not prop.startswith("_"):
response_objects.extend(reflect_get_coding(value))
return response_objects
It would be awesome if there were a clearer story for using reflection in nested fhir.resources objects.
from fhir.resources.
Hi @theGOTOguy , thanks! That helped me a lot.
I use it to translate Coding.displays in all my resources examples. :) And +1 for having something that is clearer to filter on element types.
from fhir.resources.
I had a hard time finding if an element is a List - in case anyone else runs into it, this works:
from typing import get_origin
get_origin(parent.__fields__[element_name].annotation) is list
Suggestions for improvement welcome.
from fhir.resources.
Related Issues (20)
- Transition to R5 HOT 2
- `pkg_resources.declare_namespace` deprecation HOT 1
- urn not supported in Url
- FHIR resource as pydantic request model in FastAPI
- Pydantic 2.0 Migration Plan HOT 17
- Restrict Pydantic to <2.0.0 HOT 3
- Sample code execution error HOT 3
- Use warnings.warn() instead of logging the warning about the ignored extra parameters passed to json() and dict()
- Improve documentation of orjson HOT 1
- Parsing XML byte string MESH acknowledgment response HOT 2
- Instant on DocumentReference not properly output on json HOT 1
- Resource / element to be json-serializable HOT 2
- How to override validation HOT 2
- Handling FHIR Versions
- Error in ID length on EPIC Sandbox data HOT 4
- A way to get list of all resources and their inner elements, help needed in getting sub elements of inner elements HOT 1
- Security vulnerability in orjson package: CVE-2024-27454
- AllergyIntolerance object gives "Extra fields not permitted" error for reaction object.
- Update pydantic version for FHIR R4 or fhir.resources == 6.4.0
- Parsing error for StructureDefinitions with type slicing in R4B HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from fhir.resources.