GELLO is a functional language. Referential transparency means you can lift an expression from the code and it can substitute for the variable. Loops in a usual sense are incompatible with this paradigm. Loops in GELLO have to be done
with a recursive call, passing the new value as an argument; as a function.
In this worked example for a loop, we can start with some diagnosis data:
<?xml version="1.0" encoding="UTF-8"?>
<singlePatient xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="./iso-21090-datatypes.xsd">
<observations>
<observationCode code="439401001"
codeSystem="2.16.840.1.113883.6.96"
codeSystemName="SNOMED">
<displayName value = "Diagnosis" />
</observationCode>
<dateTime value = "20201017" />
<value xsi:type = "CD" code="39579001"
codeSystem="2.16.840.1.113883.6.96"
codeSystemName="SNOMED">
<displayName value = "Anaphylaxis" />
</value>
</observations>
<observations>
<observationCode code="439401001"
codeSystem="2.16.840.1.113883.6.96"
codeSystemName="SNOMED">
<displayName value = "Diagnosis" />
</observationCode>
<dateTime value = "20201017" />
<value xsi:type = "CD" code="195951007"
codeSystem="2.16.840.1.113883.6.96"
codeSystemName="SNOMED">
<displayName value = " Acute exacerbation of COPD" />
</value>
</observations>
<observations>
<observationCode code="439401001"
codeSystem="2.16.840.1.113883.6.96"
codeSystemName="SNOMED">
<displayName value = "Diagnosis" />
</observationCode>
<dateTime value = "20201017" />
<value xsi:type = "CD" code="400047006"
codeSystem="2.16.840.1.113883.6.96"
codeSystemName="SNOMED">
<displayName value = " Peripheral vascular disease" />
</value>
</observations>
<observations>
<observationCode code="439401001"
codeSystem="2.16.840.1.113883.6.96"
codeSystemName="SNOMED">
<displayName value = "Diagnosis" />
</observationCode>
<dateTime value = "20130217" />
<value xsi:type = "CD" code="44054006"
codeSystem="2.16.840.1.113883.6.96"
codeSystemName="SNOMED">
<displayName value = "Diabetes mellitus type II" />
</value>
</observations>
</singlePatient>
Save that as loopObs.xml. Imagine we want to write some GELLO that does a little report on the patient's diagnoses. In this we will loop over the diagnosis observations and extract the diagnosis display names.
The package gello ( ie the file DemoLoopFunctions.gello_model) is:
Package DemoLoopFunctions
imports
iso_21090_datatypes,
HL7_v2_VMR_V1
GetCDDisplayNamesFromSequenceObsAsString_Internal(i:Integer, accum: String, obs: Sequence(Observation)): String =
If i <= obs.size() then
Let intermediate: String
= GetCDDisplayNamesFromSequenceObsAsString_Internal(i+1,
accum + ' ' + obs[i].observationCode.displayName.value + ',' ,
obs
)
Let result: String = intermediate.rtrim(',')
in
result
else
accum
endif
GetCDDisplayNamesFromSequenceObsAsString(obs: Sequence(Observation)): String =
GetCDDisplayNamesFromSequenceObsAsString_Internal(1, '', obs)
EndPackage
The GELLO that calls this is simply:
Imports DemoLoopFunctions, iso_21090_datatypes, HL7_v2_VMR_V1
Context SinglePatient
"Past history includes: " +
GetCDDisplayNamesFromSequenceObsAsString(observations)
+ '.'
And here is the result: