T0020 — FHIR functions and variables
Part of the roadmap. Phase 1 · wave 5 · size M.
- Depends on: T0009, T0018
- Area:
area:functions,area:core - Tier hint: likely
risk:high: the override options for%resourceand%rootResourcechange the public evaluation options, so the core tier with a second reviewer from the other vendor. - Parallel with: T0024
Goal
The FHIR additions that need no host I/O (variables, R5 §2.1.9.1).
Scope
src/fhir/:extension(url),hasValue(),getValue()resolve()for local references only: contained#idagainst%rootResource, and BundlefullUrl/type/idmatching%resourceand%rootResource(derived from the parent chain, with override options),%sct,%loinc,%`vs-*`,%`ext-*`- FHIR equivalence (
idignored;Codingonsystem+code;CodeableConcepton intersecting codings) through the T0009 extension point - FHIR
Quantity→System.Quantityin operations, including two FHIR Quantities of which one has no UCUM code: a quantity with only unit text against a UCUM-coded one, and the ordering of two without a code (testLessThan33,testLessOrEqual30,testGreaterThan30; #150, spec notes)
- Registering
memberOf,subsumes,subsumedBy,conformsToandhtmlChecksas host-backed functions that return empty without a hook. The hook plumbing is T0021. - FHIR versions (roadmap): R4 (§2.9.1.5), R5 (§2.1.9.1.5) and the R6 draft (§2.1.9.3) define these functions and variables the same way, so the engine has no version-specific code. The cases that need a model also run against the real
r4,r5andr6providers inpackages/core/test/generated-models.test.ts:extension()andhasValue()on a primitive with only extensions,%resourceand%rootResourcein a contained resource,CodingandCodeableConceptequivalence, andresolve()of a contained R6-onlyDeviceAlert, which is typed under R6, and under R4 and R5 has the declared type ofcontained,Resource, as navigation gives it (T0018 navigation rule 2), so its R6-only elements are not navigable. - Not in this task: the R6 draft adds
weight()(§2.1.9.3.13), which needs cross-resource lookups and is on the roadmap backlog until final R6 (#151), and a%profilevariable for profile invariants (§2.1.9.2). Hosts can already pass%profilethroughvariables; this task builds in no value for it.
Design notes
Variables
| Variable | Value | Source |
|---|---|---|
%context | the input passed to evaluate() | N1 §9 |
%ucum | 'http://unitsofmeasure.org' | N1 §9 |
%resource | the resource that contains %context. By default, the nearest ancestor with a resourceType (or the input itself); hosts can override it. | R5 §2.1.9.1.4 |
%rootResource | the container of %resource if it is contained, otherwise %resource | R5 §2.1.9.1.4 |
%sct | 'http://snomed.info/sct' | R5 §2.1.9.1.7 |
%loinc | 'http://loinc.org' | R5 §2.1.9.1.7 |
%`vs-[name]` | 'http://hl7.org/fhir/ValueSet/[name]' | R5 §2.1.9.1.7 |
%`ext-[name]` | 'http://hl7.org/fhir/StructureDefinition/[name]' | R5 §2.1.9.1.7 |
| user variables | from the variables option: JSON values, ModelNodes or arrays | N1 §9 |
An undefined variable raises eval/undefined-variable. A defined variable whose value is undefined, null or [] is empty, as N1 §9 requires. If the names are declared at compile time (the knownVariables option, T0025: public API sketch), the analyzer can check them early. The values are always supplied at evaluation time.
The interpretations this task made are in the spec notes: how %resource and %rootResource follow the parent chain, why hasValue() is always a Boolean, which references resolve() finds locally, and how ~ applies FHIR's equivalence rules.
Acceptance criteria
-
Patient.birthDate.extension('http://…').valueworks.hasValue()andgetValue()behave correctly for extension-only primitives. -
resolve()finds contained resources and Bundle entries, and returns empty otherwise without an error. - The same FHIR function and variable cases pass against the real
r4,r5andr6providers, including the containedDeviceAlerttyped under R6 only. No R6 conformance result is claimed, and no R6 suite exception is registered. - Conformance groups:
testExtension,testHasValue,testDollarResource,testVariables(R4 and R5), andprimitivesWithoutValue(R5 suite only) pass, except for the tests that need functions of other tasks:testExtension3(empty(), T0041) andtestValueLength(last(), T0013). Both suites have thetestDollarResourcegroup only inside an XML comment, so it has no tests;%resourceis covered byisGuardAndOtherImplies,isGuardOtherAndImplies,isGuardOrInnerImpliesandtestMultipleResolve.testLessThan33,testLessOrEqual30andtestGreaterThan30pass too (#150).