execute method

  1. @override
List execute(
  1. List results,
  2. Map<String, dynamic> passed
)
override

The iterable, nested function that evaluates the entire FHIRPath expression one object at a time

Implementation

@override
List execute(List results, Map<String, dynamic> passed) {
  final variableName = value.replaceAll('`', '');

  if (variableName == '%sct') {
    return ['http://snomed.info/sct'];
  }

  if (variableName == '%loinc') {
    return ['http://loinc.org'];
  }

  if (variableName == '%ucum') {
    return ['http://unitsofmeasure.org'];
  }

  if (variableName.startsWith('%vs-')) {
    final valueSet = variableName.substring(4);
    return ['http://hl7.org/fhir/ValueSet/$valueSet'];
  }

  if (variableName.startsWith('%ext-')) {
    final extension = variableName.substring(5);
    return ['http://hl7.org/fhir/StructureDefinition/$extension'];
  }

  final passedValue = passed[variableName];
  if (passedValue == null) {
    throw FhirPathEvaluationException(
        'Variable $variableName does not exist.',
        variables: passed);
  }

  if (passedValue is! Function()) {
    return passedValue is List ? passedValue : [passedValue];
  } else {
    try {
      final result = passedValue();

      return result is List ? result : [result];
    } catch (ex) {
      throw FhirPathEvaluationException(
          'Variable $value could not be lazily evaluated.',
          cause: ex);
    }
  }
}