FHIR Chat · JSON representation of primitive elements (validation) · python

Stream: python

Topic: JSON representation of primitive elements (validation)


view this post on Zulip Stephen Whitney (Oct 28 2020 at 01:54):

https://www.hl7.org/fhir/json.html#primitive We're using SOF python model classes to create a Bundle resource with MedicationRequest entries. The MedicationRequest resources we're trying to add as an entry are leveraging the concept of prepending an underscore to the "intent" element name because there's no data to populate from the backend. The open hapi FHIR server validates the "_intent" field with an extension but neither SOF fhirclient nor fhir.resources will validate "_intent". Has anyone else experienced this issue or have a suggestion?

view this post on Zulip Jason Teeple (Oct 28 2020 at 13:18):

Stephen Whitney said:

https://www.hl7.org/fhir/json.html#primitive We're using SOF python model classes to create a Bundle resource with MedicationRequest entries. The MedicationRequest resources we're trying to add as an entry are leveraging the concept of prepending an underscore to the "intent" element name because there's no data to populate from the backend. The open hapi FHIR server validates the "_intent" field with an extension but neither SOF fhirclient nor fhir.resources will validate "_intent". Has anyone else experienced this issue or have a suggestion?

adding @Eric Haas @Md Nazrul Islam

view this post on Zulip Stephen Whitney (Oct 28 2020 at 13:24):

@Md Nazrul Islam I tested with beta 6.x.x version and this doesn't pass validation:

"_intent": {
"extension": [
{
"url": "http://hl7.org/fhir/StructureDefinition/data-absent-reason",
"valueCode": "unknown"
}
]
},

Am I doing something wrong?

pydantic.error_wrappers.ValidationError: 1 validation error for MedicationRequest
intent
field required (type=value_error.missing)

view this post on Zulip Md Nazrul Islam (Oct 28 2020 at 13:28):

@Stephen Whitney can you paste full json, so that I can test also

view this post on Zulip Stephen Whitney (Oct 28 2020 at 13:30):

{
"resourceType": "MedicationRequest",
"id": "1620518",
"meta": {
"versionId": "1",
"lastUpdated": "2020-10-27T11:04:42.215+00:00",
"source": "#z072VeAlQWM94jpc",
"tag": [ {
"system": "http://www.alpha.alp/use-case",
"code": "EX20"
} ]
},
"text": {
"status": "generated",
"div": "<div xmlns=\"http://www.w3.org/1999/xhtml\">\n <p>Prescription: Erythromycin 250 MG Oral Tablet\n </p>\n </div>"
},
"status": "completed",
"_intent": {
"extension": [
{
"url": "http://hl7.org/fhir/StructureDefinition/data-absent-reason",
"valueCode": "unknown"
}
]
},
"medicationReference": {
"reference": "Medication/1620516",
"display": "Erythromycin 250 MG Oral Tablet"
},
"subject": {
"reference": "Patient/1620472"
},
"encounter": {
"reference": "Encounter/1620506",
"display": "Follow up encounter"
},
"authoredOn": "2018-06-16",
"requester": {
"reference": "Practitioner/1620502",
"display": "Dr. Harold Hippocrates"
},
"reasonReference": [ {
"reference": "Condition/1620514",
"display": "Otitis Media"
} ],
"dosageInstruction": [ {
"text": "250 mg 4 times per day for 10 days",
"timing": {
"repeat": {
"boundsDuration": {
"value": 10,
"unit": "day",
"system": "http://unitsofmeasure.org",
"code": "d"
},
"frequency": 4,
"period": 1,
"periodUnit": "d"
}
},
"doseAndRate": [ {
"doseQuantity": {
"value": 250,
"unit": "mg",
"system": "http://unitsofmeasure.org",
"code": "mg"
}
} ]
} ],
"priorPrescription": {
"reference": "MedicationRequest/1620517",
"display": "Amoxicillin prescription"
}
}

view this post on Zulip Md Nazrul Islam (Oct 28 2020 at 13:39):

@Stephen Whitney thanks a lot, I tested your json, there is nothing wrong with _intent value instead intent field value is missing as this field value is required.

view this post on Zulip Jason Teeple (Oct 28 2020 at 13:55):

@Md Nazrul Islam Does there need to be a preprocess to strip the _ from the incoming request or is there a more graceful way to handle? Responses with Data absence reason extension for primitive types coming from the HAPI framework need an _ to support the extension.

view this post on Zulip Stephen Whitney (Oct 28 2020 at 13:56):

I see thanks @Md Nazrul Islam. It passes validation using open hapi fhir server as written at http://hapi.fhir.org/baseR4/Bundle/$validate

view this post on Zulip Md Nazrul Islam (Oct 28 2020 at 14:00):

Jason Teeple said:

Md Nazrul Islam Does there need to be a preprocess to strip the _ from the incoming request or is there a more graceful way to handle? Responses with Data absence reason extension for primitive types coming from the HAPI framework need an _ to support the extension.

No, it's fine with _, the problem here intent field is required

view this post on Zulip Md Nazrul Islam (Oct 28 2020 at 14:04):

Stephen Whitney said:

I see thanks Md Nazrul Islam. It passes validation using open hapi fhir server as written at http://hapi.fhir.org/baseR4/Bundle/$validate

Ok, that is something a little bit long discussion need to be done. Maybe there should be when _intent value is provided then the intent field should be optional.

view this post on Zulip Damian Smith (Oct 28 2020 at 15:14):

I think intent being optional would be key - when our ETL process doesn't have a value, having to choose one is misleading. A third party app would have to know to look for an underscore value of an element to see if that element is to be trusted or not

view this post on Zulip Md Nazrul Islam (Oct 28 2020 at 20:40):

Added issue https://github.com/nazrulworld/fhir.resources/issues/40 here

view this post on Zulip Jason Teeple (Oct 29 2020 at 14:34):

@Josh Mandel Would you have any insights on how SOF would handle the above situation?

view this post on Zulip Josh Mandel (Oct 29 2020 at 15:23):

Certainly SMART doesn't impose any limits on how FHIR JSON works -- it sounds like there's some question about how FHIR treats extensions that are present in place of required elements. https://www.hl7.org/fhir/extensibility.html#Special-Case provides the official guidance to corroborate @Md Nazrul Islam's note above that "Maybe... when _intent value is provided then the intent field should be optional." -- indeed, required elements can be missing if extensions are provided.

view this post on Zulip Md Nazrul Islam (Oct 29 2020 at 15:27):

Josh Mandel said:

Certainly SMART doesn't impose any limits on how FHIR JSON works -- it sounds like there's some question about how FHIR treats extensions that are present in place of required elements. https://www.hl7.org/fhir/extensibility.html#Special-Case provides the official guidance to corroborate Md Nazrul Islam's note above that "Maybe... when _intent value is provided then the intent field should be optional." -- indeed, required elements can be missing if extensions are provided.

Thanks a lot for the clarification

view this post on Zulip Pascal Pfiffner (Oct 29 2020 at 17:56):

This is part of this issue: https://github.com/smart-on-fhir/client-py/issues/30

view this post on Zulip Julian Sass (Oct 30 2020 at 17:25):

Jason Teeple said:

Josh Mandel Would you have any insights on how SOF would handle the above situation?

I encountered the same problem. At the moment, with SOF you can't have extensions like dataAbsentReason on primitive types. The only workaround I found was handling extensions on primitives with Python's built-in json module outside of fhirclient.

view this post on Zulip Josh Mandel (Oct 30 2020 at 17:59):

I see now you're referring not to SMART on FHIR in general, but to the python bindings at github.com/smart-on-fhir/client-py. @Harold Solbrig I wonder if you have eyes here?


Last updated: Apr 12 2022 at 19:14 UTC