import { grantedCategories, type RecordsRetrievalSummary, type RetrievableType } from "../../../services/RecordsConnectionsService.tsx"; /** Each kind of record a retrieval reads, in the words the Records screens use. */ export const RETRIEVABLE_WORDS: Record = { AllergyIntolerance: "Allergies", Condition: "Problems and diagnoses", Immunization: "Immunizations", MedicationRequest: "Medication orders", MedicationStatement: "Medications taken", Observation: "Vitals and results", Procedure: "Procedures", }; const wordsOf = (type: string): string => RETRIEVABLE_WORDS[type as RetrievableType] ?? type; /** HL7 observation categories, as the Records screens name them; any other is named by its code. */ const CATEGORY_WORDS: Record = { laboratory: "lab results", "vital-signs": "vital signs", "social-history": "social history", imaging: "imaging", exam: "exam findings", procedure: "procedure results", survey: "surveys", therapy: "therapy", activity: "activity", }; export const categoryWords = (categories: readonly string[]): string => "only " + categories.map((code) => CATEGORY_WORDS[code] ?? code.replace(/-/g, " ")).join(", "); /** A kind a retrieval may read, with the categories it is limited to when the grant names them. */ export const retrievableWords = (type: RetrievableType, scopes: readonly string[]): string => { const categories = grantedCategories(scopes, type); return RETRIEVABLE_WORDS[type] + (categories.length ? " (" + categoryWords(categories) + ")" : ""); }; /** Where a retrieved original came from and how much was read. */ export const retrievalLine = (retrieval: RecordsRetrievalSummary): string => `From ${retrieval.issuer} · ${retrieval.pages} ${retrieval.pages === 1 ? "page" : "pages"} · ${retrieval.resources} records`; /** The kinds kept in the original that the review will not offer as items, with how many of each; none says nothing. */ export const notOfferedLine = (retrieval: RecordsRetrievalSummary): string | undefined => { if (!retrieval.notOffered.length) return undefined; const kinds = retrieval.notOffered.map((type) => `${wordsOf(type)} (${retrieval.counts[type] ?? 0})`); return "Kept in the original, not offered as items: " + kinds.join(", "); };