Error with the patchResource function
# support
m
Currently I am attempting to take formData from a QuestionnaireForm response and then use the medplum patchResource function to add this data into the Patient resource for a specific patient. I did this operation before however instead of using the 'replace' operation i'm using the 'add' operation and doing everything else how i have before, which worked. I am met with errors that i will paste below along with my code. I will show the payload which shows that the values are not null or undefined, which is why this is a frustrating issue. I would love some guidance. errors:
Copy code
Error: Value required at path: /photo/0/contentType
Value required at path: /photo/0/url
Value required at path: /photo/0/title
Value required at path: /address/0/line/0
Value required at path: /address/0/city
Value required at path: /address/0/state
Value required at path: /address/0/country
Value required at path: /address/0/postalCode
r
What value are you putting in for the URL? Also, for that resource do those paths already exist in he resource?
m
No those paths dont exist in the resource, that may be the issue? Its a Patient resource that is missing gender, birthday, picture and address so im adding those details to the resource.
Which is why I’m using the add operation and not replace
Gender and birthday gets added by the way. Something with the photo and address fields is a problem.
Update... I ended up using the updateResource method instead and it works that way. So i'll continue with that.
r
Hi @mikee6290 - the reason you were seeing issues with
add
is because there was no existing array at the location for
Patient.address
. doing a patch for on
add /address/0/*
, assumes that the array at
Patient.address
already exists
Replace just sets the whole
Patient.address
key, which is why you didn't run into this issue before
Unfortunately, it's a known issue with json patch that you can't express the following "Create an array if it doesn't exist, then add a new eleement" https://stackoverflow.com/questions/47670366/jsonpatch-adding-element-to-array-and-creating-it-if-not-exist
m
Ahhh ok that makes sense. Thanks for clarifying. Defintely good to know for future use!
164 Views