Question Dean Rochester · Feb 21, 2023

trying the python fhir example and getting an error AttributeError: 'NoneType' object has no attribute 'serialize'

In article

 

https://community.intersystems.com/print/518106

Traceback (most recent call last):
  File "c:\Users\rochesterd\PythonScripts\fhir_stuff\fhir-client-python-main\fhir-client-python-main\src\client.py", line 57, in <module>
    patient0 = Patient.parse_obj(patients_resources.search(
AttributeError: 'NoneType' object has no attribute 'serialize'

Comments

Robert Cemper · Feb 21, 2023

it's an interesting line:

patient0 = Patient.parse_obj(patients_resources.search(family='familyname',given='givenname1').first().serialize())

I miss some checks if the search was successful.
Because NONE indicates a missing content.
If search(family='familyname',given='givenname1')
fails you receive NONE and this can't be serialized.  
COS would just return NullString """
 

0
Dean Rochester · Feb 23, 2023

It is erroring on this line

#Part 3---------------------------------------------------------------------------------------------------------------------------------------------------- #Now we want to get a certain patient and add his phone number and change his name before saving our changes in the server #Get the patient as a fhir.resources Patient of our list of patient resources who has the right name, for convenience we will use the patient we created before patient0 = Patient.parse_obj(patients_resources.search(family='familyname',given='givenname1').first().serialize())

0
Dean Rochester · Feb 23, 2023

#Part 3----------------------------------------------------------------------------------------------------------------------------------------------------

#Now we want to get a certain patient and add his phone number and change his name before saving our changes in the server

#Get the patient as a fhir.resources Patient of our list of patient resources who has the right name, for convenience we will use the patient we created before

I edited the line to have the family name and one of the given names I entered earlier and it still errors

patient0 = Patient.parse_obj(patients_resources.search(family='Foobar',given='MyName').first().serialize())

0
Dean Rochester · Feb 23, 2023

If I switch to the first givename it works

# Create a HumanName and fill it with the information of our patient

name = HumanName()

name.use = "official"

#name.family = "familyname"

name.family = "Foobar"

#name.given = ["givenname1", "givenname2"]

name.given = ["MyName", "MyName1"]

0
Dean Rochester · Feb 23, 2023

Got past that point, now I am getting this error at the save line

"diagnostics": "<HSFHIRErr>MalformedRelativeReference",

0