T0017 — Functions: tree navigation and utility
Part of the roadmap. Phase 1 · wave 4 · size S.
Goal
N1 §5.8–5.9: children, descendants, trace(name[, projection]), now, timeOfDay, today.
Scope
childrenanddescendantsare registered onnavigateChildren()inruntime/navigation.ts, which T0018 delivered: with a model, a typed node's elements in definition order, with_nameextensions folded into their primitives; without one, the own JSON keys in document order (spec notes).- FHIR versions (roadmap): the element order and names come from the provider, so the engine has no version-specific code. The model-aware cases also run against the real
r4,r5andr6providers inpackages/core/test/generated-models.test.ts, including an element that only some versions have (Observation.triggeredByexists in R5 and R6, not in R4) and the recursiveQuestionnaire.item.item. R6 results are engine tests on the pinned draft, not conformance. tracesends events to thetracehook (a no-op by default). Until T0021 adds the other hooks, the hook is thehooks.traceevaluate option of the internal API, and reaches the public API with T0038. It takes the event of theEvaluationHooks.tracesketch in T0021: host hooks,{ name, values, span }, and extends the sketch in one point: where the sketch returnsvoid, the hook may return a promise, whichevaluateAsync()waits for andevaluate()rejects witheval/async-in-sync, as for every host hook (ADR-0004). #185 aligns the T0021 sketch with this. Passing it to the function needs a field inEvalContext, so the task also touchesarea:core. The name, the projection and the hook's results follow the spec notes.now,todayandtimeOfDayread the per-evaluation snapshot and honour thenowandtimezoneOffsetoptions. By default they are computed in UTC (ADR-0012);timezoneOffset: 'local'uses the host's offset.
Acceptance criteria
-
now()returns the same value when called twice within one evaluation, and the injectednowis respected. -
_fieldkeys never appear as children.descendants()terminates and keeps document order (spec notes). - With the real
r4,r5andr6providers,children()gives each version's elements in definition order, so on an Observation whose JSON has atriggeredByentry,children()includes it under R5 and R6 but not under R4, where it is not an element, anddescendants()terminates on a nestedQuestionnaire.item. No R6 conformance result is claimed. - Conformance groups:
testTrace,testToday,testNow. In R4 and R5,testTrace1,testTrace2,testToday1andtestNow1pass.testToday2andtestNow2also calltoString()(T0014) andlength()(T0015), and pass once those are merged.