import type { DiagnosticOrderQueueRow } from "../hooks/useDiagnosticOrderQueue"; /** * READING IS A SECTION OF THE PRACTITIONER WORKSPACE, NOT A HAT. * * A radiologist reads studies and signs reports, and that is clinical judgement rather than bench * work -- so it cannot require putting on a technologist's hat. It is deliberately NOT derived from * `lensFor` like the queue and the bench are: that expression answers "whose bench work is this", * and reading is not bench work. A different question gets its own answer rather than a widened one, * which is the mistake the queue's own rail note argues against at length. * * THIS DECIDES WHOSE RAIL READING SITS IN, NOT WHETHER SOMEBODY MAY REACH IT. Reaching it takes the * `diagnostics` permission, as the queue does (roles/diagnostics/lab-and-imaging.md section 11): the * API refuses reporting, release and addenda to a practitioner without it, whatever the master role. */ export const READING_WORKSPACES = ["Practitioner"] as const; export const workspaceReadsStudies = (workspace?: string): boolean => (READING_WORKSPACES as readonly string[]).includes(workspace ?? ""); /** * A study that has been taken and nobody has reported. * * `performed` AND NO RESULT, which are two facts rather than one: the state says the pictures were taken, * and a report filed against the order is what takes it off the list. An order still `scheduled` has * nothing to read. */ export const awaitingRead = (row: DiagnosticOrderQueueRow): boolean => row.kind === "imaging" && row.state === "performed" && !row.resultOnFile && !sentElsewhere(row) && !nothingFiled(row); /** Performed with no images filed here: nothing to read yet. Uncounted is not none, and a study read for * another practice keeps its images with them. */ const nothingFiled = (row: DiagnosticOrderQueueRow): boolean => row.images?.instances === 0 && !row.readFor; /** Out with another practice to be read, which is theirs to report unless they declined it. */ const sentElsewhere = (row: DiagnosticOrderQueueRow): boolean => Boolean(row.readElsewhere && !row.readElsewhere.declinedAt); /** The practice off Akashic whose report is owed on this study, unless the study never reached them. */ export const outsideReportDueFrom = (row: DiagnosticOrderQueueRow): string | undefined => row.outsideRead && row.outsideRead.confirmation?.outcome !== "not-received" && !row.resultOnFile ? row.outsideRead.reader : undefined; /** A report written and not yet signed, which is the second half of the same person's job. */ export const awaitingSignature = (row: DiagnosticOrderQueueRow): boolean => row.kind === "imaging" && Boolean(row.awaitingRelease); /** * Signed, and therefore no longer work -- kept on the screen because "did that go out?" is a question * a radiologist asks, and because adding to a signed report is reached from here and nowhere else in * this workspace. */ export const alreadySigned = (row: DiagnosticOrderQueueRow): boolean => row.kind === "imaging" && Boolean(row.resultOnFile) && !row.awaitingRelease;