nazrulworld / fhir.resources

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

fhir.resource 8.0.0b1 beta feedback #164

Open janwijbrand opened 1 week ago

janwijbrand commented 1 week ago

Description

fhir.resource 8.0.0b1 beta feedback.

The reason for the 8.0.0b1 release is to collect feedback. Since I couldn't find the place where that feedback currently is collected, I start this issue. I hope that this is helpful to you:

  1. no more Resource.resource attribute. Now use Resource.get_resource_type() instead? If this is intentional it should be listed in the migration guide from 7.x -> 8.x. However, I'd argue the resource_type attribute is more intuitive and also more closely resembles the JSON you get from a FHIR server.
  2. get_fhir_model_class() is gone? I use it in a central location of my codebase where I abstract out the requests to a FHIR server and return a resource object. If this function is intentionally gone, it should be listed in the migration guide from 7.x --> 8.x. However, I hope this function comes back or has a proper alternative.

Please let me know if I can help address those issues in any way, or test upcoming betas.

janwijbrand commented 1 week ago

More beta-testing feedback:

In fhir.resources == 7.1.0:

❯ python3.11 -m venv fhir.resources-7
❯ cd fhir.resources-7
❯ ./bin/pip install fhir.resources==7.1.0
❯ ./bin/python
Python 3.11.9 (main, Apr  2 2024, 08:25:04) [Clang 15.0.0 (clang-1500.3.9.4)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from fhir.resources.R4B.task import Task
>>> t1 = Task(**{'for': None, 'intent': 'plan', 'status': 'active'})
>>> t1.dict(exclude_none=True)
OrderedDict([('resourceType', 'Task'), ('status', 'active'), ('intent', 'plan')])
>>>

contrast that to fhir.resources == 8.0.0b1:

❯ python3.11 -m venv fhir.resources-8
❯ cd fhir.resources-8/
❯ ./bin/pip install fhir.resources=8.0.0b1
❯ ./bin/python
Python 3.11.9 (main, Apr  2 2024, 08:25:04) [Clang 15.0.0 (clang-1500.3.9.4)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from fhir.resources.R4B.task import Task
>>> t1 = Task(**{'for': None, 'intent': 'plan', 'status': 'active'})
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/j.kolman/tmp/fhir.resources-8/lib/python3.11/site-packages/fhir_core/fhirabstractmodel.py", line 96, in __init__
    BaseModel.__init__(self, **data)
  File "/Users/j.kolman/tmp/fhir.resources-8/lib/python3.11/site-packages/pydantic/main.py", line 209, in __init__
    validated_self = self.__pydantic_validator__.validate_python(data, self_instance=self)
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/j.kolman/tmp/fhir.resources-8/lib/python3.11/site-packages/fhir_core/types.py", line 161, in _validate
    return validator(cls.fhir_model_validator(input_value, model_klass))
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/j.kolman/tmp/fhir.resources-8/lib/python3.11/site-packages/fhir_core/types.py", line 202, in fhir_model_validator
    if model_klass.__resource_type__ != value.__resource_type__:
                                        ^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute '__resource_type__'
>>>

Is this difference in behaviour intentional? This could lead to problems perhaps, when deserializing JSON or a Python dict from some unknown source that has a null or None value for the for field.

Please let me know if I can help address those issues in any way, or test upcoming betas.

nazrulworld commented 5 days ago

@janwijbrand thanks a lot for your feedback. I think, we can use this thread to collect others feedback.