Question
· Jul 3

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?
Product version: IRIS 2025.1
$ZV: IRIS for UNIX (Red Hat Enterprise Linux 8 for x86-64) 2025.1 (Build 223U) Tue Mar 11 2025 18:16:13 EDT [HealthConnect:8.2.2]
Discussion (9)2
Log in or sign up to continue

Hello @Scott Roth 

The  HS.FHIRModel.R4.SeqOfHumanName has 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.Patient

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 size
for i=0:1:r4Patient.name.list.size()-1 {
    Set humanName = r4Patient.name.list.%Get(i)
    Write humanName.family_"  "_humanName.given
}

Using an iterator:


/// By iterator
Set 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 string
    Set 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..

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

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 seqHuman
    Set human = ##class(HS.FHIRModel.R4.HumanName).%New()
    Set human.family="pil"
    Set human.text="Ashok,kumar"
    ;
    ;push the HumanName into SeqOfHumanName
    Do seqHuman.add(human)
    
    ; Set SeqOfHumanName into Patient.name
    Set 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
}