Question
· 12 hr ago

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