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 newResults = [];

  List checkForOrdinalValues(List list) {
    final tempResults = [];

    /// check each result
    for (final val in list) {
      /// if it's a Map (if it's not, then we can't use it with Ordinal)
      if (val is Map) {
        /// First we check the element for extensions
        if (val.keys.contains('extension')) {
          /// get those extensions
          final extension = val['extension'];

          /// generally we expect the extension to be a list
          if (extension is List) {
            /// for each extension in the list
            for (final ext in extension) {
              /// if it is defined as an ordinalValue
              if (ext['url'] ==
                  'http://hl7.org/fhir/StructureDefinition/ordinalValue') {
                /// Safety check just to ensure there is a value
                if (ext['valueDecimal'] != null) {
                  /// add that value to the results to return
                  tempResults.add(ext['valueDecimal']);
                }
              }
            }
          } else

          /// just in case it's a Map and not a list
          if (extension is Map) {
            /// if it is defined as an ordinalValue
            if (extension['url'] ==
                'http://hl7.org/fhir/StructureDefinition/ordinalValue') {
              /// Safety check just to ensure there is a value
              if (extension['valueDecimal'] != null) {
                /// add that value to the results to return
                tempResults.add(extension['valueDecimal']);
              }
            }
          }
        }
      }
    }
    return tempResults;
  }

  newResults.addAll(checkForOrdinalValues(results));

  for (final result in results) {
    if (result is! Map) {
      break;
    }

    polymorphicPrefixes.forEach((element) {
      if (result['${element}Coding'] != null) {
        newResults
            .addAll(checkForOrdinalValues([result['${element}Coding']]));
      }
      if (result['${element}Code'] != null) {
        newResults.addAll(checkForOrdinalValues([result['${element}Code']]));
      }
    });
  }

  return newResults;
}