nazrulworld / fhir.resources

FHIR Resources https://www.hl7.org/fhir/resourcelist.html
https://pypi.org/project/fhir.resources/
Other
372 stars 104 forks source link

(version 6) How to build resources with extensions from dict? #52

Closed PeteW closed 3 years ago

PeteW commented 3 years ago

Description

I'm trying to construct a basic resource with extension fields. In the example below I'm trying to add an extension to Patient resource.

What I Did

        result = fhir.resources.patient.Patient(**{
            'id': str(self.id),
            '_banana': {
                'extension': [{
                    'url': 'https://tempuri.org',
                    'valueInteger': self.specialid,
                }],
            },
...
)
_banana
 extra fields not permitted (type=value_error.extra).
nazrulworld commented 3 years ago

As far as know, there is no element/field name, called banana, you can make extensions only for available fields/element For example:

result = fhir.resources.patient.Patient(**{
            'id': str(self.id),
            '_gender' or ''_id'': {
                'extension': [{
                    'url': 'https://tempuri.org',
                    'valueInteger': self.specialid,
                }],
            },
PeteW commented 3 years ago

Thanks for the quick response. That variable banana is sort of tongue-in-cheek, but the point was we often have requirements to exchange some resource such as Patient but we also must include a series of internal/proprietary key/value pairs of metadata related to the resource (better examples: "created by", "internal-department-id", "origin-system-category" etc...)

My interpretation is that the FHIR standard intentionally doesnt leave a place for arbitrary/extensible key/pairs, and that extensions are the preferred means of accomplishing this. Hopefully I'm missing a place in the resource for holding these sort of fields?

PeteW commented 3 years ago

Not sure if this is the "right" way to do this, but I ended up sub-classing the fhir resources and add new fields where needed.

nazrulworld commented 3 years ago

You can have a look at https://www.hl7.org/fhir/auditevent.html I am not fully sure if it is a good idea but you can put AuditEvents inside Patient.contained

Other options could be, create extensions and append Patient. extension

PeteW commented 3 years ago

I like your latter suggestion, create extensions and append Patient.extension . I will close this one up.