Stream: python
Topic: Creating Python model from logical model SD
Eric Haas (Sep 20 2017 at 23:28):
I looked at the fhir-parser to see if there was a way to use it to create a python model from logical model SD file. Short of adding a SD to the build bundle, I could not see an obvious entry point for a single custom resource that would still be using all the base types. Any ideas?
Pascal Pfiffner (Sep 20 2017 at 23:31):
Try running fhir-parser once, then add your SD into the "downloads" folder and run it again. That could work.
Eric Haas (Sep 21 2017 at 21:05):
Thanks I tried it and did not work. It seem that classes are not being generated from the .../client-py/fhir-parser/downloads
folder. - I removed the SD for Account from the directory but its class was still generated anyway.
Pascal Pfiffner (Sep 24 2017 at 04:37):
@Eric Haas I just checked, and the parser simply reads downloads/profiles-resources.json
, which is a Bundle containing all StructureDefinitons of the resources. You can either run the generator (from client-py) once, then replace that file with a Bundle of your own SDs, or give your Bundle of SDs a custom name, place it into downloads
as well and edit fhirspec.py
on line 95 to also read your file (there's a commented out part in place already also looking for profiles-others.json
).
Pascal Pfiffner (Sep 24 2017 at 04:38):
LMK how that goes!
Eric Haas (Sep 25 2017 at 16:31):
yes that works well - thanks
Eric Haas (Jan 25 2018 at 22:51):
I'm using the Python model for creating a Flask scheduling application and was going well until this mysterious message:
fhirclient.models.fhirabstractbase.FHIRValidationError
fhirclient.models.fhirabstractbase.FHIRValidationError: {root}: 'Non-optional property "type" on <fhirclient.models.bundle.Bundle object at 0x101ff0ac8> is missing'
Eric Haas (Jan 25 2018 at 22:52):
the bundles I created all have the type elements and I reverted back to a working version and can't find the source. Anyway is there a way to turn off the validation?
Geoff Low (Jan 26 2018 at 12:30):
It looks like you can pass a strict=False to the initialisation and it will probably work (ie _bundle = bundle.Bundle(jsondict=dict(XX), strict=False) - it defaults to True. type is a reserved word in python so their may be some clash on that maybe?
c = bundle.Bundle(jsondict=dict(type="sausage", identifier=dict(system="https://example.org/glow", value='my_erroneous_bundle'))) c = bundle.Bundle(jsondict=dict(identifier=dict(system="https://example.org/glow", value='my_erroneous_bundle'))) Traceback (most recent call last): File "<input>", line 1, in <module> File "/Users/glow/Documents/Devel/PycharmProjects/fhirton/models/models_r4/bundle.py", line 55, in __init__ super(Bundle, self).__init__(jsondict=jsondict, strict=strict) File "/Users/glow/Documents/Devel/PycharmProjects/fhirton/models/models_r4/resource.py", line 42, in __init__ super(Resource, self).__init__(jsondict=jsondict, strict=strict) File "/Users/glow/Documents/Devel/PycharmProjects/fhirton/models/models_r4/fhirabstractresource.py", line 25, in __init__ super(FHIRAbstractResource, self).__init__(jsondict=jsondict, strict=strict) File "/Users/glow/Documents/Devel/PycharmProjects/fhirton/models/models_r4/fhirabstractbase.py", line 61, in __init__ self.update_with_json(jsondict) File "/Users/glow/Documents/Devel/PycharmProjects/fhirton/models/models_r4/fhirabstractbase.py", line 226, in update_with_json raise FHIRValidationError(errs) models.models_r4.fhirabstractbase.FHIRValidationError: {root}: 'Non-optional property "type" on <models.models_r4.bundle.Bundle object at 0x10b463ba8> is missing' c = bundle.Bundle(jsondict=dict(identifier=dict(system="https://example.org/glow", value='my_erroneous_bundle')), strict=False) WARNING:root:'Non-optional property "type" on <models.models_r4.bundle.Bundle object at 0x10b456dd8> is missing'
Last updated: Apr 12 2022 at 19:14 UTC