Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parsing drops extensions on primitives #30

Open
jmandel opened this issue Mar 22, 2017 · 6 comments
Open

Parsing drops extensions on primitives #30

jmandel opened this issue Mar 22, 2017 · 6 comments

Comments

@jmandel
Copy link
Member

jmandel commented Mar 22, 2017

Documenting a known issue: parsing FHIR resources with extensions on primitives silently drops the extensions. For example:

{
  "resourceType": "Patient",
  "gender": "male",
  "_gender": {
    "extension": [{
      "url": "http://test-extension",
      "valueString": "with extra data"
    }]
  }
}
@p2
Copy link
Member

p2 commented Mar 22, 2017

Yes, thanks! Also to have it documented: the Swift-FHIR framework now solves this by providing custom classes/structs for primitives. Those can handle extensions (and ids), as opposed to the native strings/numbers used by the Python client.

@dajaffe
Copy link

dajaffe commented Aug 2, 2024

Hi - I just ran into this trying to return back resources which are using string extensions for language translations and attempting to as_json the resource, i.e.:

"item": [
  "text": "hello",
  "_text": {
    "extension": [
      {
        "url": "http://hl7.org/fhir/StructureDefinition/translation",
         "extension": [
           {
             "url": "lang",
             "valueCode": "fr"
           },
           {
             "url": "content",
             "valueString": "bonjour"
           }
         ]
      }
    ]
  }
]

Is being able to support this planned in the future?

@mikix
Copy link
Contributor

mikix commented Aug 5, 2024

It is definitely something we ought to do. And as Pascal says above, one reasonable approach would be custom types. Something as simple as the following might work:

class StringType:
  value = None
  extensions = None

But... that's a big change, and a breaking one. There are also backwards-compatible options, like adding underscored fields that shadow all the primitives in the model classes.

I dunno, I haven't thought about it much yet.

But it's a direction we'd want to go and worth doing. Patches appreciated if folks have thoughts / time for it. But note that patches like that should be done in fhir-parser first, then ported here.

@p2-apple
Copy link

p2-apple commented Aug 5, 2024

This should be possible without changes to fhir-parser, just updates to the Python-specific templates like fhir-parser-resources/template-resource.py

@mikix
Copy link
Contributor

mikix commented Aug 5, 2024

Yes it's possible for sure. But if we can keep the two repos in rough sync, that'd be nice - since this change isn't specific to fhirclient and all consumers of fhir-parser would appreciate the improvement.

@p2-apple
Copy link

p2-apple commented Aug 5, 2024

We already do support extensions on primitive types in https://github.com/smart-on-fhir/Swift-FHIR (and https://github.com/apple/fhirmodels), with the current version of fhir-parser. We have a mappings.py override file for each FHIR release that we support, which contains classmap (and other properties). This is used to map the FHIR types to the type of our own library, you could do the same here.

See https://github.com/smart-on-fhir/Swift-FHIR/blob/master/fhir-parser-resources/mappings.py

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants