Extracting lists from FHIR Responses
I am making a FHIR request against Epic, in when I get the Response back using "fromDao" I am extracting the stream into HS.FHIRModel.R4.Patient. However, the patient's name comes back as name within a list that references HS.FHIRModel.R4.SeqOfHumanName.
- How do I extract the name from HS.FHIRModel.R4.SeqOfHumanName?
- Do I have to then do another "fromDao" to pull the list into string format?
- How do I navigate around the lists that are in a FHIRModel response, to extract the string values?
Comments
Hello @Scott Roth
The HS.FHIRModel.R4.SeqOfHumanNamehas property "list" which is %DynamicArray. So, If you access via object r4Patient.name.list.%Get(0) for get 0 index value $ZCVT(r4Patient.name.list.toString(),"I","JSON") get entire value. Here r4Patient is a object of HS.FHIRModel.R4.Patient
FHIRDEV>Write r4Patient.name.list.%Get(0)
{"use":"official","text":"Ashok,Kumar"}
FHIRDEV>Write$ZCVT(r4Patient.name.list.toString(),"I","JSON")
["{"use":"official","text":"Ashok,Kumar"}","{"text":"Ashok,Kumar"}"]
FHIRDEV>Write$ClassName(r4Patient)
HS.FHIRModel.R4.PatientHow would I iterate through the string result to parse the family and given name...
{"use":"official","text":"Archie Obrotest","family":"Obrotest","given":["Archie"]}In the above example, the list property holds a %DynamicObject value, not a string literal. Therefore, you can use DAO (Dynamic Access Object) methods to work with it. However, if you're using the latest IRIS version (2023.2 or later), you can also use the apply method to retrieve the family and given fields directly from the %DynamicObject.
Version 2024.1
Write r4Patient.name.list.apply("$[*].family").%ToJSON()
write r4Patient.name.list.apply("$[*].given").%ToJSON()For older versions that do not support the apply method, you can use traditional JSON access techniques:
/// loop by sizefor i=0:1:r4Patient.name.list.size()-1 {
Set humanName = r4Patient.name.list.%Get(i)
Write humanName.family_" "_humanName.given
}
Using an iterator:
/// By iteratorSet iter = r4Patient.name.list.%GetIterator()
While iter.%GetNext(,.humanName) {
Write humanName.family_" "_humanName.given
}Sample code for the human name testing
ClassMethod FHIRHunmanNameTest()
{
Set r4Patient = ##class(HS.FHIRModel.R4.Patient).%New()
;Set seqHuman = ##class(HS.FHIRModel.R4.SeqOfHumanName).%New()
Set human = ##class(HS.FHIRModel.R4.HumanName).%New()
Set human.family="pil"Set human.text="Ashok,kumar";Set human1 = ##class(HS.FHIRModel.R4.HumanName).%New()
Set human1.family="pil"Set human1.text="Ashok,kumar";; seq stringSet seqString = ##class(HS.FHIRModel.R4.SeqOfString).%New()
Set seqString.list=["ashok","kumar"]
;Set human1.given=seqString
;Do seqHuman.add(human.toDao())
Do seqHuman.add(human1.toDao())
Set r4Patient.name = seqHuman
Set iter = r4Patient.name.list.%GetIterator()
While iter.%GetNext(,.humanName) {
Write humanName.family_" "_humanName.given
}
For i=0:1:r4Patient.name.list.size()-1 {
Set humanName = r4Patient.name.list.%Get(i)
Write humanName.family_" "_humanName.given
}
Write r4Patient.name.list.apply("$[*].family").%ToJSON(),!
Write r4Patient.name.list.apply("$[*].given").%ToJSON()
}I did not have any luck with either option within the DTL editor..
.png)
<INVALID OREF>Transform+16^osuwmc.Epic.FHIR.DTL.ResponsePatientSearch.1 -- logged as '-' number - @' set iter = target.name.list.%GetIterator()'
What I am trying to do is take the R4.PatientResponse and return it into a Data Class Structure format for those that are within my Team who can't read FHIR response or know how to code around it to use to update an HL7 message.
I tried taking the R4.PatientResponse and transforming it into a Record Map data class structure without success.
Found that the FHIR R4 Patient Resource that I was receiving from my EMR did not follow the Model R4 Patient Resource, so once the fromDao tries to transform the JSON it does not map correctly to the model R4 Patient.
I was able to pull the Patient Resource out of the Bundle, but now I am still stuck on how to pull out the name.list..
.png)
Does anyone have any suggestions? %GetIterator() is not working just on target.name.list, I get a message that %GetIterator() does not exist.
Thanks
Scott
Hello @Scott Roth
I hope the target is a object reference of HS.FHIRModel.R4.Patientand the "name" property in in R4.Patient is an object property(HS.FHIRModel.R4.SeqOfHumanName ) and thisSeqOfHumanName stores the %DynamicArray of HS.FHIRModel.R4.HumanName object values into property called "list"
So, First we have to check the name is $IsObject(r4Patient.name)&&(r4Patient.name.%IsA("HS.FHIRModel.R4.SeqOfHumanName")) and if it's true you can iterate the list (%DynamicArray) Set iter = r4Patient.name.list.%GetIterator()
You can directly copy and run this example directly and it works for me.
ClassMethod ParseHumanName()
{
Set r4Patient = ##class(HS.FHIRModel.R4.Patient).%New()
;Set seqHuman = ##class(HS.FHIRModel.R4.SeqOfHumanName).%New()
; create human name for seqHumanSet human = ##class(HS.FHIRModel.R4.HumanName).%New()
Set human.family="pil"Set human.text="Ashok,kumar";;push the HumanName into SeqOfHumanNameDo seqHuman.add(human)
; Set SeqOfHumanName into Patient.nameSet r4Patient.name = seqHuman
If$IsObject(r4Patient.name)&&(r4Patient.name.%IsA("HS.FHIRModel.R4.SeqOfHumanName")) {
Set iter = r4Patient.name.list.%GetIterator()
#;while iter.%GetNext(,.humanName) {
zw humanName.toDao()
}
}
quit
}Even though the vendor is stating it, I don't think my name.list is SequenceOfHumanName
The name property is Property name As HS.FHIRModel.R4.SeqOfHumanName; and the SeqOfHumanName class have Property list As %Library.DynamicArray;
This list property holds the object of HS.FHIRModel.R4.HumanName