Skip to main content
Version: v0.0.2

Function: loadCodeSystem()

loadCodeSystem(source): CodeSystem

Load a consumer-supplied code-system release into an immutable, queryable CodeSystem.

Dispatches on source.format:

  • "rrf" - pipe-delimited RxNorm/UMLS release (one parameterized reader for both).
  • "csv" - RFC-4180 CSV (e.g. LOINC Loinc.csv), with real quote handling.
  • "fixed-width" - slice-by-column order files (e.g. ICD-10-CM; see ICD10CM_ORDER_FILE_FIELDS).
  • "fhir" - a native FHIR R4 CodeSystem JSON resource.

Liberal on load: a malformed row is skipped and surfaced in warnings (never a crash, never a partial concept). Conservative on structure: an unusable source (wrong FHIR resourceType, or a CSV whose configured columns are absent from the header) throws a typed TerminologyError carrying TERM_CODESYSTEM_MALFORMED.

Parameters

source

CodeSystemSource

The release descriptor (a discriminated CodeSystemSource).

Returns

CodeSystem

The immutable, deep-frozen CodeSystem.

Throws

TERM_CODESYSTEM_MALFORMED when the source is structurally unusable.

Example

import { loadCodeSystem } from "@cosyte/terminology";

const cs = loadCodeSystem({
format: "fhir",
resource: {
resourceType: "CodeSystem",
url: "http://example.org/cs",
concept: [{ code: "A", display: "Alpha" }],
},
});
cs.count; // => 1