Comments (3)
@yvesonline Hello. I was wondering if you resolved this and what approach you took?
from fhir.resources.
Yes @bwalsh we resolved this by directly using the Patient
object, there wasn't a lot of added value in creating a dedicated MIO DiGA Patient class.
So we do something like this:
from datetime import datetime, timezone
from fhir.resources.patient import Patient
data = {
'id': '...',
'name': [
{
'text': '...',
'use': 'official',
'family': '...',
'family__ext': {
'extension': [
{
'url': 'http://hl7.org/fhir/StructureDefinition/humanname-own-name',
'valueString': '...',
},
],
},
'given': ['...'],
},
],
'identifier': [...],
'meta': {
'versionId': 1,
'lastUpdated': datetime.now(tz=timezone.utc),
'profile': [
'https://fhir.kbv.de/StructureDefinition/KBV_PR_MIO_DIGA_Patient|1.0.0'
],
},
'telecom': [...],
'communication': [...],
}
p = Patient(**data)
from fhir.resources.
I needed to define resources as part of Aidbox that weren't defined fhir.resources
. It took some time to figure out, but eventually I came up with the following function:
def define_fhir_resource(
fhirtypes,
fhirtypesvalidators,
cls: typing.Type[DomainResource],
) -> typing.Type[DomainResource]:
resource_name = cls.__name__
resource_type_name = f"{resource_name}Type"
resource_validator_name = f"{resource_name.lower()}_validator"
resource_type = type(
resource_type_name,
(fhirtypes.AbstractType,),
{"__resource_type__": resource_name},
)
setattr(fhirtypes, resource_type_name, resource_type)
fhirtypesvalidators.MODEL_CLASSES[resource_name] = (cls, None)
def resource_validator(value):
return fhirtypesvalidators.fhir_model_validator(resource_name, value)
setattr(fhirtypesvalidators, resource_validator_name, resource_validator)
To use this to create a User
resource:
from fhir.resources.R4B import fhirtypes
from fhir.resources.R4B import fhirtypesvalidators
from fhir.resources.R4B.domainresource import DomainResource
from pydantic import Field
class User(DomainResource):
resource_type = Field("User", const=True)
userName: str = Field(None, element_property=True)
password: str = Field(None, element_property=True)
@classmethod
def elements_sequence(cls):
return [
"id",
"meta",
"implicitRules",
"language",
"text",
"contained",
"extension",
"modifierExtension",
"userName",
"password",
]
define_fhir_resource(
fhirtypes=fhirtypes, fhirtypesvalidators=fhirtypesvalidators, cls=User
)
This was needed because fhir.resources would try to look up UserType
in its fhirtypes
and user_validator
in fhirtypesvalidators
. The above isn't pretty, but I couldn't find a better solution.
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.