Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

  • .type set to logic-library

  • .parameter[0]

    • .use set to in for input

    • .type set to QuestionnaireResponse

  • .parameter[1]

    • .use set to out for output

    • .type set to CodeableConcept

The Library rule sets examines the answers of the QuestionnaireResponse and determines the corresponding SituationQuality Coding(s).

...

Prerequisite to submitting the Observation, the QuestionnaireResponse for the said Questionnaire would be passed as parameter to the evaluate operation on the Library, returning one or more Coding for UsageQuality. The returned Coding(s) would then be carried to Observation.ehealth-quality.

The Library type, input and input output are identical to that of Library for Calculating Situation Quality, and the rule differs in that the resulting Coding specifies UsageQuality.

Library for Calculating

...

Body Mass Index

The Library for calculating the body mass index (BMI) is intended for providing an Observation with the BMI which can defined as an ActivityDefinition with associated reference ranges. Given an Observation of height and an Observation of weight as parameters, the evaluate operation returns a Quantity which can be set as the BMI Observation’s Observation.valueQuantity.

The Library has:

  • .type set to logic-library

  • .parameter[0]

    • .use set to in for input

    • .type set to Observation

  • .parameter[1]

    • .use set to in for input

    • .type set to Observation

  • .parameter[2]

    • .use set to out for output

    • .type set to Quantity

Expand
titleBMI Calculation Rule
Code Block
package rules
import org.hl7.fhir.dstu3.model.Observation
// additional imports omitted for brevity

global org.hl7.fhir.dstu3.model.Quantity ruleResult

function CodingDTO getWeightObservationCode() {
   return new CodingDTO("urn:oid:1.2.208.176.2.1", "NPU03804", "Pt—Legeme; masse = ? kg");
}

function CodingDTO getHeightObservationCode() {
   return new CodingDTO("urn:oid:1.2.208.176.2.1", "NPU03794", "Pt—Legeme; højde = ? m");
}

function Quantity getWeight(Collection observations) {
   for (Object o: observations) {
      Observation observation = (Observation)o;
	  if (getWeightObservationCode().getCode.equals(observation.getCode()) && getWeightObservationCode().getSystem().equals(observation.getSystem())) {
	     return (Quantity)observation.getValue();
	  }
   }
   return null;
}

function Quantity getHeight(Collection observations) {
   for (Object o: observations) {
      Observation observation = (Observation)o;
	  if (getHeightObservationCode().getCode.equals(observation.getCode()) && getHeightObservationCode().getSystem().equals(observation.getSystem())) {
	     return (Quantity)observation.getValue();
	  }
   }
   return null;
}

rule "BodyMassIndexCalculationRule"

dialect "java"

when
    $observations: Collection()
then
   Quantity weightQuantity = getWeight($observations);
   Quantity heightQuantity = getHeight($observations);
   
   // Compute BMI
   BigDecimal squareHeight = heightQuantity.getValue().multiply(heightQuantity.getValue());
   BigDecimal bmi = weightQuantity.divide(squareHeight, 2, RoundingMode.HALF_UP);
   
   ruleResult.setValue(bmi);
   ruleResult.setCode("kg/m2");
   ruleResult.setSystem("http://unitsofmeasure.org");
   ruleResult.setUnit("kg/m2");
end;