User bio
404 bio not found
Member since Apr 27, 2017
Replies:

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

Hello @Corentin Blondeau

Here is the code to retrieve the properties in the same order they are defined in the class.


ClassMethod GetPropOnDefinedSequence(pClass As %String = "", Output pProperties)
{
	For {
		Set property=$$$comMemberNext(pClass,$$$cCLASSproperty,property)
		If property="" Quit
		If property="%%OID"!(property="%Concurrency") continue
		Set pProperties(
			    +$$$defMemberKeyGet(pClass,$$$cCLASSproperty,property,$$$cPROPsequencenumber),
			    property)=""
	}
	Return $$$OK
}

 The properties assigned to the pProperties parameter

properties(1,"Name")=""
properties(2,"City")=""
properties(3,"IsActive")=""
properties(4,"State")=""
Open Exchange applications:
Certifications & Credly badges:
Ashok Kumar has no Certifications & Credly badges yet.
Global Masters badges:
Followers:
Following: