All files / src/lib/fhir-documents document-index.ts

100% Statements 3/3
100% Branches 0/0
100% Functions 2/2
100% Lines 3/3

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53                                                  1x 1x                   1x                                
import { LAB_PROFILES, type LabReportInput } from "./lab-report";
import { EPS_PROFILES } from "./patient-summary";
 
/** One document a record yields, and where to fetch it. */
export interface DocumentIndexEntry {
  type: "patient-summary" | "lab-report";
  title: string;
  profile: string;
  href: string;
  reportId?: string;
  date?: string;
  performer?: string | null;
  results?: number;
}
 
export interface DocumentIndex {
  patientId: string;
  documents: DocumentIndexEntry[];
}
 
/** What `GET /api/patient/documents` answers for one record (#1171). */
export function documentIndex(
  patientId: string,
  reports: LabReportInput[],
): DocumentIndex {
  const id = encodeURIComponent(patientId);
  return {
    patientId,
    documents: [
      {
        type: "patient-summary",
        title: "Patient Summary",
        profile: EPS_PROFILES.bundle,
        href: `/api/patient/documents/patient-summary?patientId=${id}`,
      },
      ...reports.map(
        (r): DocumentIndexEntry => ({
          type: "lab-report",
          reportId: r.reportId,
          title: r.title,
          date: r.effective,
          performer: r.performer,
          results: r.results.length,
          profile: LAB_PROFILES.bundle,
          href: `/api/patient/documents/lab-report?patientId=${id}&reportId=${encodeURIComponent(
            r.reportId,
          )}`,
        }),
      ),
    ],
  };
}