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

Accept extra fields when calling `parse_obj`. #84

Open Mo-Di opened 2 years ago

Mo-Di commented 2 years ago

Description

Our integrator sends us extra fields in their response JSON that aren't part of resource definition. For example, their DocumentReference resource json has extra fields created, indexed and class. Running DocumentReference.parse_obj(response_json) throws error such as extra fields not permitted (type=value_error.extra).

Our current workaround is to override the abstract model before calling parse_obj: FHIRAbstractModel.Config.extra = Extra.allow. This feels too hacky.

Maybe fhir.resources could surface an argument like allow_extra for parse_obj?

What I Did

Paste the command(s) you ran and the output.
If there was a crash, please include the traceback here.
nazrulworld commented 2 years ago

Hi @Mo-Di first of all, thanks a lot for using this library. I like your idea that would give developers more flexibilities to handle nonstandard fields. Unfortunately, we cannot allow any nonstandard field like this, as you know this library is 100% complying with FHIR Specification, besides Config.extra is in class level should not modify from function/method.

  1. I think your current approach is good for now.
  2. There are many ways to put extra (nonstandard info) inside FHIR resource for example Extension, Meta you could ask your integrator to implement, or maybe you do some filter on the extra field (perhaps generate an Extension ) before constructing FHIR Object