Question
· 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'

Discussion (8)1
Log in or sign up to continue

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 """
 

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())

#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())