FHIR Chat · latest FHIR Parser issues · python

Stream: python

Topic: latest FHIR Parser issues


view this post on Zulip Eric Haas (Dec 29 2019 at 04:33):

I have merged the latest changes from FHIR parser and getting errors on generation of CI build:

these changes let me get a set of Classes

  • added "!=":'neq', to mappings.py
  • added '{cd}' "'some data' to mappings.py
  • short-circuited the unit tests using a try except TypeError pass at line 157

but then trying to import Patient

  • address Class tries to import AddressType and AddressUse class which don't exist see below:

view this post on Zulip Eric Haas (Dec 29 2019 at 04:33):

    def elementProperties(self):
        js = super(Address, self).elementProperties()
        js.extend([
            ("use", "use", AddressUse.str, False, None, False),
            ("type", "type", AddressType.str, False, None, False),
            ("text", "text", str, False, None, False),
            ("line", "line", str, True, None, False),
            ("city", "city", str, False, None, False),
            ("district", "district", str, False, None, False),
            ("state", "state", str, False, None, False),
            ("postalCode", "postalCode", str, False, None, False),
            ("country", "country", str, False, None, False),
            ("period", "period", period.Period, False, None, False),
        ])
        return js


from . import AddressType
from . import AddressUse
from . import period

view this post on Zulip Eric Haas (Dec 29 2019 at 04:38):

the codesystem_AddressType and codesystem_AddressUse do indeed exist and I believe there is some missing in the JInja2 templates or the parser settings.

view this post on Zulip Pascal Pfiffner (Dec 30 2019 at 13:36):

The latest changes to fhir-parser include breaking changes to codesystem → enum generation, the templates will probably have to be updated to support those changes.

view this post on Zulip Eric Haas (Dec 30 2019 at 15:44):

(deleted)

view this post on Zulip Eric Haas (Jan 02 2020 at 22:19):

I don't understand how the enums will work...

here is example using address.py where I hacked the Properties and imports to work:

        super(Address, self).__init__(jsondict=jsondict, strict=strict)

    def elementProperties(self):
        js = super(Address, self).elementProperties()
        js.extend([
            ("use", "use", addressuse.AddressUse, False, None, False),
            ("type", "type", addresstype.AddressType, False, None, False),
            ("text", "text", str, False, None, False),
            ("line", "line", str, True, None, False),
            ("city", "city", str, False, None, False),
            ("district", "district", str, False, None, False),
            ("state", "state", str, False, None, False),
            ("postalCode", "postalCode", str, False, None, False),
            ("country", "country", str, False, None, False),
            ("period", "period", period.Period, False, None, False),
        ])
        return js


from . import codesystem_AddressType as addresstype
from . import codesystem_AddressUse as addressuse
from . import period

so to implement this, the class expects an object now and not a code as a string?

import R4models.address as A
import R4models.codesystem_AddressUse as AU

address = A.Address()
address.use = AU.AddressUse()


print(address.as_json())

-------
{'use': <R4models.codesystem_AddressUse.AddressUse object at 0x109870a20>}
[Finished in 0.32s]

view this post on Zulip Eric Haas (Jan 03 2020 at 23:04):

also the FHIR parser template for code systems give invalid Class definitions... (looks like a carry over from Swift) So I am wondering if introducing the enums classes into Python was intentional or accidental?

view this post on Zulip Eric Haas (Jan 03 2020 at 23:07):

Here is a CodeSystem Class which I needed to edit to make legal python by removing some curly brackets and replacing with colon

...

class AddressUse(object):
    """ The use of an address.

    URL: http://hl7.org/fhir/address-use
    ValueSet: http://hl7.org/fhir/ValueSet/address-use
    """

    home = "home"
    """ A communication address at a home.
    """

    work = "work"
    """ An office address. First choice for business related contacts during business hours.
    """

    temp = "temp"
    """ A temporary address. The period can provide more detailed information.
    """

    old = "old"
    """ This address is no longer in use (or was never correct but retained for records).
    """

    billing = "billing"
    """ An address to be used to send bills, invoices, receipts etc.
    """

view this post on Zulip Pascal Pfiffner (Jan 06 2020 at 12:32):

Which template did you use for that? fhir-parser doesn't provide templates, you have to write your own.

view this post on Zulip Eric Haas (Jan 06 2020 at 16:42):

I just the used sample templates “out of the box “ after doing a git pull. Also note I did not directly edit the templates. I wanted to see what happened first if the enum classes where legal python. So I edited the classes directly after they were generated. After looking at this again. I think that there is something missing the as_json method. And that these classes would ideally inherit from Enum. Post 3.4

view this post on Zulip Pascal Pfiffner (Jan 06 2020 at 17:21):

The sample templates do not work out of the box, they are just samples. But you can work backwards from the fixes you made to add the learnings to the templates that live in client-py.


Last updated: Apr 12 2022 at 19:14 UTC