import type { Encounter } from 'fhir/r4'; /** * One decision about a visit (start it, park it, finish it, room it, link a diagnosis), made on the visit as the * server holds it now rather than on the copy a board or workspace was drawn from. * * It answers the visit with only that change, or says the visit already is what was asked ('unchanged'), or that * the decision no longer applies to it ('refused'): Finish on a visit the desk has since cancelled is not a * finish, and writing it would undo the cancel. */ export type EncounterChange = (current: Encounter) => Encounter | 'unchanged' | 'refused'; export const VISIT_CHANGED_MESSAGE = 'Someone else changed this visit while you were working on it, so nothing was changed. Look at it as it is now and try again.'; /** Moves a visit from one of `from` to `to`, adding what `shape` says the move also changes. */ export const moveEncounter = ( from: Encounter['status'][], to: Encounter['status'], shape?: (current: Encounter) => Partial, ): EncounterChange => (current) => { if (current.status === to) return 'unchanged'; if (!from.includes(current.status)) return 'refused'; return { ...current, status: to, ...shape?.(current) }; }; /** A visit that has ended takes no further change from the board. */ export const ENDED_ENCOUNTER_STATUSES: Encounter['status'][] = ['finished', 'cancelled', 'entered-in-error']; /** Before the visit begins, or while it is under way. */ export const OPEN_ENCOUNTER_STATUSES: Encounter['status'][] = ['planned', 'arrived', 'triaged', 'in-progress', 'onleave'];