All files / src/lib/fhir-documents samples.ts

100% Statements 4/4
100% Branches 2/2
100% Functions 2/2
100% Lines 4/4

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 54 55 56                                  2x                                                       31x 31x             9x    
import { buildLabReportDocument, type LabReportInput } from "./lab-report";
import {
  buildPatientSummaryDocument,
  type PatientSummaryInput,
} from "./patient-summary";
import type { DocumentBundle, DocumentPatient, IdentityView } from "./shared";
 
/**
 * The documents scripts/eehrxf/validate.py validates (#1171): graph rows of
 * a few seeded patients, kept in scripts/eehrxf/samples/documents/graph-rows.json
 * with the document each one gives. ui/scripts/export-fhir-document-samples.ts
 * reads the rows from a running graph and writes both; the unit test
 * fhir-documents.test.ts rebuilds every document from its rows and fails when
 * the committed one differs, so a change to a builder cannot leave the
 * validated samples behind.
 */
 
export const SAMPLE_TIMESTAMP = "2026-11-20T09:00:00Z";
 
export type DocumentSample =
  | {
      file: string;
      kind: "patient-summary";
      identity: IdentityView;
      patient: DocumentPatient;
      input: PatientSummaryInput;
    }
  | {
      file: string;
      kind: "lab-report";
      identity: IdentityView;
      patient: DocumentPatient;
      report: LabReportInput;
    };
 
export interface SampleSet {
  $comment: string;
  timestamp: string;
  samples: DocumentSample[];
}
 
export function buildSample(
  sample: DocumentSample,
  timestamp: string,
): DocumentBundle {
  const options = { timestamp, identity: sample.identity };
  return sample.kind === "patient-summary"
    ? buildPatientSummaryDocument(sample.patient, sample.input, options)
    : buildLabReportDocument(sample.patient, sample.report, options);
}
 
/** A document as the file holds it: JSON indented by one space, a final newline. */
export function sampleText(bundle: DocumentBundle): string {
  return `${JSON.stringify(bundle, null, 1)}\n`;
}