Stream: python
Topic: HumanName "given" bug?
Alice Sartori Monteiro de Barros (May 25 2021 at 00:39):
Hello all,
I am getting this Exception from time to time in my program:
File "C:\Users\Sartori\Documents\ADT\sapadt_to_fhir\segments\patient_identification.py", line 195, in post_process
self.patient_json = self.patient_object.as_json()
File "C:\Users\Sartori\AppData\Roaming\Python\Python38\site-packages\fhirclient\models\fhirabstractresource.py", line 42, in as_json
js = super(FHIRAbstractResource, self).as_json()
File "C:\Users\Sartori\AppData\Roaming\Python\Python38\site-packages\fhirclient\models\fhirabstractbase.py", line 297, in as_json
raise FHIRValidationError(errs)
fhirclient.models.fhirabstractbase.FHIRValidationError: {root}:
contact.0:
name:
given:
Expecting property "given" on <class 'fhirclient.models.humanname.HumanName'> to be <class 'str'>, but is <class 'list'>
Is this a bug? "Given" in Humanname clearly supposed to be a list according to documentation https://simplifier.net/packages/hl7.fhir.r4.core/4.0.1/files/78879. The strangest thing is that I only get this exception from time to time (like 1/1000 patient ressources created).
My code builds the name like this:
name_obj = humanname.HumanName()
name_obj.family = family
name_obj.given = [given] if given else None
name_obj.use = "official"
name_obj.suffix = [suffix] if suffix else None
Julian Sass (May 25 2021 at 12:16):
HumanName.given is a list of strings. I think your code works as long as the given variable here is a string because you're already assigning it inside a list. But if your source patient data has multiple given names already in a list, this will probably cause this error because then you're putting a list inside a list.
Eric Haas (May 25 2021 at 16:23):
here is what @Julian Sass is talking about...
from fhirclient.r4models import humanname
from json import dumps, loads, load
given = ['given1','given2']
suffix = None
name_obj.family = 'family'
name_obj.given = [given] if given else None
name_obj.use = "official"
name_obj.suffix = [suffix] if suffix else None
name_obj.as_json()
---------------------------------------------------------------------------
FHIRValidationError Traceback (most recent call last)
<ipython-input-44-f9172b1b931a> in <module>
7 name_obj.suffix = [suffix] if suffix else None
8
----> 9 name_obj.as_json()
~/Documents/Python/Venv/venv37/lib/python3.7/site-packages/fhirclient/r4models/fhirabstractbase.py in as_json(self)
295
296 if len(errs) > 0:
--> 297 raise FHIRValidationError(errs)
298 return js
299
FHIRValidationError: {root}:
given:
Expecting property "given" on <class 'fhirclient.r4models.humanname.HumanName'> to be <class 'str'>, but is <class 'list'>
Last updated: Apr 12 2022 at 19:14 UTC