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

Validation error with a split primitive #97

Open
azmeuk opened this issue Apr 13, 2022 · 1 comment
Open

Validation error with a split primitive #97

azmeuk opened this issue Apr 13, 2022 · 1 comment
Assignees
Labels
bug Something isn't working enhancement New feature or request

Comments

@azmeuk
Copy link

azmeuk commented Apr 13, 2022

  • fhir.resources version: 6.2.2
  • Python version: 3.10.4
  • Operating System: Linux

Hello,

Using fhir-kindling on production data, I encountered a validation error with an Organization resource which address line is split between line and line_. The HL7 specification on JSON representation of primitive elements seems to indicate that the data I try to read is valid:

FHIR elements with primitive datatypes are represented in two parts:

A JSON property with the name of the element, which has a JSON type of number, boolean, or string
a JSON property with _ prepended to the name of the element, which, if present, contains the value's id and/or extensions

The data I handled comes from the French government health public data API. I have asked them about this and they say their data is valid.

I have cleaned up the data so the following snippet is readable. You can copy/paste this in a REPL to reproduce the exception:

>>> from fhir.resources.organization import Organization
>>> Organization(**{
...   "resourceType": "Organization",
...   "address": [
...     {
...       "line": [
...         None
...       ],
...       "_line": [
...         {
...           "extension": [
...             {
...               "url": "http://hl7.org/fhir/StructureDefinition/iso21090-ADXP-houseNumber",
...               "valueString": "80"
...             },
...             {
...               "url": "http://hl7.org/fhir/StructureDefinition/iso21090-ADXP-streetNameType",
...               "valueString": "AV"
...             },
...             {
...               "url": "http://hl7.org/fhir/StructureDefinition/iso21090-ADXP-streetNameBase",
...               "valueString": "FOOBAR"
...             },
...           ]
...         }
...       ],
...     }
...   ]
... })
Traceback (most recent call last):
  File ".../env/lib/python3.10/site-packages/fhir/resources/fhirabstractmodel.py", line 105, in __init__
    BaseModel.__init__(__pydantic_self__, **data)
  File "pydantic/main.py", line 331, in pydantic.main.BaseModel.__init__
pydantic.error_wrappers.ValidationError: 1 validation error for Organization
address -> 0 -> line -> 0
  none is not an allowed value (type=type_error.none.not_allowed)

1 validation error for Organization
address -> 0 -> line -> 0
  none is not an allowed value (type=type_error.none.not_allowed)

Is my data wrong in the end, or is this something fhir.resources does not support yet?

Thank you for your help

@nazrulworld nazrulworld added bug Something isn't working enhancement New feature or request labels Apr 13, 2022
@nazrulworld
Copy link
Owner

nazrulworld commented Apr 13, 2022

Hi @azmeuk,
Firstly thanks a lot for this extraordinary issue!

  1. According to our current implementation, the member line value (list of strings) cannot be None or empty string! But you can provide an empty list or None (not None inside the list). In your example, if you remove None from the list, it will not give you a validation error. Or instead of None, you can use any fixed string to prevent validation error.
  2. I tried to Create an Organization at http://hapi.fhir.org/create with your data and it is working. So I think None is allowed inside a list.
  3. For more confirmation, I added the issue here https://chat.fhir.org/#narrow/stream/179166-implementers/topic/Address.2Eline
  4. It will be breaking business logic changes if we want to support (None as a member of the list), but I think we should. It will take a little bit more time as I am currently busy with professional work. I will try to manage time as soon as possible but in the meanwhile any PR is welcome.

@nazrulworld nazrulworld self-assigned this Apr 14, 2022
nazrulworld added a commit that referenced this issue Apr 15, 2022
* some helper functions are created to handled primitive types inside Union or Optional type.
* in response to issue #97 xml serializer has been updated to work with Optional/Union types. [nazrulworld]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants