Should you require any more information or have encountered a problem, please call the support helpdesk on (07) 5456 6000.

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 17 Next »

Overview

GELLO allows the creation of Libraries and functions. A library is a collection of non volatile resources which in this case is for the consistent implementation and reuse of code. It is useful to tuck away snippets of code for commonly used methods or to hide the complexity of large and occasionally used code. This tutorial will demonstrate two examples of the former, one of the latter and then bring them together by way of worked examples.

 

Calculate patient age

In an earlier tutorial we wrote GELLO to calculate the age of a patient in years from the VMR instance's date of birth. Now we will convert that code into a function in a Library called TestLib. Open the GELLO Editor and in a fresh workspace write:

  Package TestLib
imports HL7_v2_VMR_V1
 

 

  EndPackage

 

Compile and save as TestLib.gello_model

 

(Make sure you haven't saved it as TestLib.model. I suggest you write or cut and paste the whole file name including the extension in the File name box after choosing Save As from the menu.)

Now add at about line 4 ( making sure we are adding to the GELLO above the EndPackage line):

    

  --functions
  GetAgeInYears(vmr:SinglePatient): PQ =
                        Let dob: TS = vmr.patient.dob
                              Let ageInSeconds: PQ = factory.TS('today') - dob
                              Let ageInYrs: PQ = ageInSeconds.convert('yr')
                              Let ageInYrsRoundedDown: PQ = factory.PQ(ageInYrs.value.floor(),'yr')
                              in
                               ageInYrsRoundedDown

 

Compile and save.

 

So here is our first function in TestLib. The function name is capitalised. We have added a floor() method on the value of the age, made the patient class explicitly derived from the vmr,  and used a line containing the word 'in'. The reason for the 'in' is that a GELLO expression is intrinsically made up of an inner expression and an outer expression with the 'in' linking them.

In previous code in earlier tutes we have written it has been said that we need  a final declarative line. That was in fact the outer expression. The code above it was the inner expression and the 'in' was not needed - but it could have been added.

Ok now lets write some GELLO that makes use of this library:

In a new workspace, put:

 

     imports HL7_v2_VMR_V1, TestLib
Context SinglePatient
     Let age: PQ = GetAgeInYears(Self)
     age

 

 

and run with fourthTest.xml as the data:

 

The TestLib library is imported in the first line. The function needs a parameter called Self.

Note: the gello file and the gello_model Library file need to be in the same folder when saved on your machine.

 

Calculate BMI

Now for a similarly sized function to add to the Library. This one calculates Body Mass index (BMI) for a patient, making use of the patient's most recent height and weight measurements. We will need to add the following data to our test file and then save it as fifthTest.xml .

 

<vitals>
    <!-- weight is an Observation-->
    <weight>
         <observationCode code="27113001"
                      codeSystem="2.16.840.1.113883.6.96"
                      codeSystemName="SNOMED-CT">
           <displayName value = "body weight" />
           <translation code="3141-9"
                      codeSystem="2.16.840.1.113883.6.1"
                      codeSystemName="LN">
                     <displayName value = "Body weight Measured" />
           </translation>
        </observationCode>
        <dateTime value = "20160423" />
        <value xsi:type = "PQ" value = "68" unit = "kg" />
    </weight>
    <weight>
       <observationCode code="27113001"
                    codeSystem="2.16.840.1.113883.6.96"
                    codeSystemName="SNOMED-CT">
        <displayName value = "body weight" />
        <translation code="3141-9"
                    codeSystem="2.16.840.1.113883.6.1"
                    codeSystemName="LN">
                    <displayName value = "Body weight Measured" />
         </translation>
        </observationCode>
        <dateTime value = "20101102" />
        <value xsi:type = "PQ" value = "66" unit = "kg" />
    </weight>
    <height>
        <observationCode code="50373000"
                   codeSystem="2.16.840.1.113883.6.96"
                   codeSystemName="SNOMED-CT">
                   <displayName value = "body height" />
         <translation code=" 8308-9"
                   codeSystem="2.16.840.1.113883.6.1"
                   codeSystemName="LN">
                  <displayName value = "Body height Measured" />
          </translation>
        </observationCode>
        <dateTime value = "20101102" />
        <value xsi:type = "PQ" value = "164" unit = "cm" />
    </height>
</vitals>

 

We have two weights from different dates and a height measurement. 

The formula for BMI is Bodyweight in kilograms divided by height in meters squared.

 Add this to the functions section of the Library file and save.


    GetBMI(vmr:SinglePatient): Real =
Let latestHtObservation: Observation = vmr.vitals.height->sortedBy(dateTime)->last()
Let latestHt_PQ: PQ = latestHtObservation.value.oclAsType(PQ).convert('m')
Let latestWt: PQ = vmr.vitals.weight->sortedBy(dateTime)->last().value.oclAsType(PQ)
Let bmi: Real = latestWt.value/latestHt_PQ.value.power(2)
in
bmi

 

We are getting the latest height and weight observations and then getting the value out as PQs.

Here's how it should look:

and here is some GELLO code to call it:

 

    imports HL7_v2_VMR_V1, TestLib
Context SinglePatient
    Let bmi: Real = GetBMI(Self)
bmi

 


 

First degree relatives example

 

 


 

 

 

 

  • No labels