import type { ServiceRequest } from "fhir/r4"; /** * The result waiting on an order, read from the order itself. * * The server writes this exact URL and the plugin reads it back, so the literal has to match byte for * byte -- the same contract every other Akashic extension the client reads carries. * * WHY IT IS ON THE ORDER AT ALL. A worklist that has to show "a result is waiting" searches orders, * and reading a report per row to find out would cost a request per row. The report is the truth about * the result; this says only that one exists, and names it. */ export const RESULT_ENTERED_EXTENSION_URL = "https://akashichealthrecords.com/fhir/StructureDefinition/result-entered"; /** The report filed against an order, or undefined when nothing has been filed yet. */ /** The report reference exactly as the order names it, for a reader that must check its form. */ export const readEnteredReportReference = (order: ServiceRequest): string | undefined => (order.extension ?? []) .find((e) => e.url === RESULT_ENTERED_EXTENSION_URL) ?.extension?.find((e) => e.url === "report")?.valueReference?.reference; export const readEnteredReportId = (order: ServiceRequest): string | undefined => { const found = (order.extension ?? []).find((e) => e.url === RESULT_ENTERED_EXTENSION_URL); return (found?.extension ?? []) .find((e) => e.url === "report")?.valueReference?.reference?.split("/") .pop(); };