import type { Encounter, Reference } from 'fhir/r4'; import { useEncounterServiceContext, useFhirServiceContext, usePatientServiceContext, } from '../services'; import { activeEncounterDefault } from '../utils/activeEncounterDefault'; /** * The visit to file a clinical record against when it is being recorded from inside one. * * Every encounter-aware clinical form needs the same three context reads to build one reference, and * eight of them were each going to grow their own copy. The rule itself lives in * `activeEncounterDefault`, so it stays testable without React; this is only the wiring. * * Undefined outside a visit, which is what makes the chart route open its picker empty. */ export const useActiveEncounterReference = (): Reference | undefined => { const { encounterState } = usePatientServiceContext(); const { createReferenceObject } = useFhirServiceContext(); const { getEncounterDisplay } = useEncounterServiceContext(); return activeEncounterDefault(encounterState, (id) => createReferenceObject('Encounter', id, getEncounterDisplay(encounterState as Encounter))); };