UNPKG

@atomic-ehr/fhirpath

Version:

A TypeScript implementation of FHIRPath

40 lines (35 loc) 1.39 kB
import type { FunctionDefinition, FunctionEvaluator } from '../types'; import { box, unbox } from '../boxing'; export const evaluate: FunctionEvaluator = async (input, context, args, evaluator) => { // Empty input returns false per spec if (input.length === 0) { return { value: [box(false, { type: 'Boolean', singleton: true })], context }; } // Check if any item in the collection is false for (const boxedItem of input) { const item = unbox(boxedItem); if (typeof item !== 'boolean') { continue; // Skip non-boolean values } if (item === false) { return { value: [box(true, { type: 'Boolean', singleton: true })], context }; } } // All items are true or non-boolean return { value: [box(false, { type: 'Boolean', singleton: true })], context }; }; export const anyFalseFunction: FunctionDefinition & { evaluate: FunctionEvaluator } = { name: 'anyFalse', category: ['existence'], description: 'Takes a collection of Boolean values and returns true if any of the items are false. If all the items are true, or if the input is empty, the result is false.', examples: [ "Observation.select(component.value > 90 'mm[Hg]').anyFalse()" ], signatures: [{ name: 'anyFalse', input: { type: 'Boolean', singleton: false }, parameters: [], result: { type: 'Boolean', singleton: true } }], evaluate };