@cosyte/terminology
Public entry point for @cosyte/terminology - a zero-dependency, developer-focused
terminology engine for US healthcare code systems.
Unlike its sibling @cosyte/* packages, this is not a wire-format parser: it mirrors the
FHIR Terminology Module ($translate, $lookup, $validate-code, $expand, …), operating
over consumer-supplied FHIR resources. It ships the engine and no code-system release
(SNOMED CT / CPT / LOINC / UMLS / RxNorm are strictly BYO). It is not content-free: see
What is bundled at the end of this note, which includes the UCUM unit table, the code-system
identities (OID ↔ URI), the SNOMED CT concepts the crosswalk resolver names and RxNorm's
relationship and term-type names, each with its copyright.
Code-system identity and ConceptMap translation:
- resolveSystem - the code-system identity / canonical-URI resolver (mnemonic | OID → URI).
- loadConceptMap + translate - the ConceptMap
$translateengine, with the never-fabricate / never-invert invariants: an unmapped source is a typed TranslateUnmapped, never a guessed target; a directional map is never run backwards.
The CodeSystem load layer, with the FHIR $lookup / $validate-code operations:
- loadCodeSystem - load a consumer-supplied release (RRF / CSV / fixed-width / FHIR
CodeSystemJSON) into an immutable model. Ships the loader; no code-system release. - lookup - code → display + properties, carrying status (deprecated / header-not-billable).
- validateCode - is a code a valid member of the system, with its status flags.
The never-fabricate invariant holds here too: an unknown code is a typed unknown / valid: false,
never a fabricated display or a guessed valid: true.
The ValueSet binding layer - FHIR $expand / $validate-code over a compose:
- loadValueSet - load a consumer-supplied FHIR
ValueSet(intensionalcomposeand/or a pre-computedexpansion) into an immutable model. - expand - flatten membership over the supplied CodeSystems (
include/exclude, explicitconceptlists,is-a/propertyfilters, referenced value sets), with an honestcompleteflag: an unresolvable part is a typedTERM_VALUESET_CANNOT_EXPAND, never a guess. - validateCodeInValueSet - binding membership, returning a decided
resultonly when proven and a typedundeterminedotherwise (a truncated expansion never reads as complete).
The UCUM unit layer - a hand-rolled UCUM grammar parser + validation + representation canonicalization (recognition only, no magnitude conversion):
- validateUcum - is a string a valid UCUM unit; if so, its canonical descriptor. An
invalid unit is a typed
TERM_UCUM_INVALID, never a guessed "nearest" unit. - ucumEqual - do two expressions denote the same unit (
N≡kg.m/s2), by reducing both to base dimensions. Not magnitude conversion (mg/dL→mmol/Lis refused). - parseUcum / reduce / loadUcumEssence - the underlying grammar parser, dimensional reducer, and the in-memory model of the vendored, verbatim UCUM table.
The crosswalk resolvers - the never-fabricate/never-invert invariant applied to the published, directional reference maps:
- loadGems + applyGem - the CMS ICD-9↔ICD-10 GEMs (public-domain reference mappings), honoring the steward's Approximate / No-Map / Combination (scenario→choice-list) flags. A No-Map source is a typed CrosswalkNoMap; a 1:many source returns the full candidate set.
- loadComplexMap + applyComplexMap - the NLM SNOMED CT → ICD-10-CM complex map
(BYO - no SNOMED CT refset bundled), evaluating Map Group / Priority /
IFARule / Advice / Category against caller-supplied PatientContext; a rule needing context the caller lacks is a typed ComplexMapContextRequired, never a guessed branch. - invertGem - the never-invert refusal made a first-class, thrown contract (FATAL_CODES.TERM_MAP_NOT_INVERTIBLE).
The RxNorm drug relationship graph - ingredient / brand / clinical-drug / dose-form navigation over a caller-supplied RxNorm RRF release:
- loadRxNormGraph - load
RXNCONSO(concepts, typed byTTY),RXNREL(directedRELAedges, normalized to the documentedRXCUI2 ⟶RELA⟶ RXCUI1direction), and optionallyRXNSAT(NDC attributes) into an immutable graph. Ships no RxNorm release - BYO. - ingredientsOf / genericFor / brandsFor / doseFormsOf /
consistsOf / relatedByRela - graph navigation following authored edges only
(the engine never synthesizes an inverse). An absent
RXCUIis a typed RxNormUnknown. - resolveNdc - NDC →
RXCUIcarrying the temporal status and the as-of release; an absent NDC is a typed NdcUnmapped, never a guess. - approximateMatch - the opt-in, explicitly labeled similarity path (never the default, never an exact code assertion).
What is bundled. No code-system release is. What is bundled includes the following, named with its copyright:
- the UCUM unit table (
ucum-essence.xml, version 2.2, revision-date 2024-06-17) - copyright ©1999–2024 Regenstrief Institute, Inc., all rights reserved, reproduced verbatim under the UCUM Copyright Notice and License (https://ucum.org/license), embedded byte-for-byte in the published build and parsed at runtime; no modified or derivative copy is distributed. The UCUM Specification is provided "as is" without warranty of any kind - see the License for the full disclaimer. The complete notice ships with this package atvendor/ucum/NOTICE.md. - the code-system identity facts (SYSTEM_IDENTITIES) - OID ↔ canonical-URI pairings, which identify the systems rather than listing any system's codes.
- the SNOMED CT concepts the crosswalk resolver names, each with its description: the four
map-category concepts (MAP_CATEGORIES) a complex-map row's
mapCategoryIdrefers to, and the two gender findings (248152002Female,248153007Male) a genderIFArule is written against. Further SNOMED CT identifiers, and ICD-10-CM codes, appear in the API documentation examples, which are distributed in the compiled declaration files and in the build's sourcemaps. SNOMED CT is copyright © International Health Terminology Standards Development Organisation. - the RxNorm relationship and term-type names the drug-graph API is written against: the
relationship names in RELA / RELA_INVERSE (
has_ingredient,tradename_of, …), and the term-type codes in TERM_TYPES, each with its name as published by the U.S. National Library of Medicine (SCDreads "Semantic Clinical Drug"). Individual RxNorm identifiers also appear in the API documentation examples, with their RxNorm names and term types (for instanceRXCUI316151, "lisinopril 10 MG"), and inREADME.mdas well as the places named above. RxNorm is produced by the National Library of Medicine; no RxNorm release is bundled.
The LICENSE file that ships with this package carries the MIT text for the package's own code
and a third-party notices section naming each of the above.
The content packs that would change this (the CMS GEM files, the RxNorm Current Prescribable subset) are not bundled; a caller supplies them, as they do a SNOMED CT, CPT, LOINC, UMLS or VSAC release, under whatever terms its steward sets. This states what is distributed and under whose copyright; it is not legal advice, and makes no claim about whether a particular use is permitted to you.
Classes
Interfaces
- AnnotationNode
- ApproximateMatchOptions
- BillableFlag
- CodeableConcept
- CodeSystem
- Coding
- ComplexMap
- ComplexMapContextRequired
- ComplexMapEntry
- ComplexMapGroupNoMap
- ComplexMapGroupResolved
- ComplexMapLoadWarning
- ComplexMapMatched
- Concept
- ConceptMap
- ConceptMapElement
- ConceptMapGroup
- ConceptMapTarget
- ConceptMapUnmapped
- ConceptRef
- ConceptSetComponent
- ConceptSetFilter
- ConceptStatus
- CrosswalkNoMap
- CrosswalkUnmapped
- CsvColumnMap
- CsvSource
- ExpandResult
- ExpansionContains
- ExpansionContext
- ExpansionDiagnostic
- FactorNode
- FhirCodeSystemSource
- FieldSlice
- FilterMatch
- FixedWidthFieldMap
- FixedWidthPropertyField
- FixedWidthSource
- GemChoiceList
- GemEntry
- GemFlags
- GemLoadWarning
- GemMap
- GemMatched
- GemScenario
- GemSource
- GroupNode
- LinearReduction
- LoadWarning
- LookupResult
- LookupUnknown
- MapProvenance
- NdcResolution
- NdcUnmapped
- ParseFailure
- PatientContext
- Property
- RrfColumnMap
- RrfPropertyColumn
- RrfSource
- RxNormApproximateMatch
- RxNormConcept
- RxNormEdge
- RxNormGraph
- RxNormGraphSource
- RxNormLoadWarning
- RxNormRelated
- RxNormUnknown
- SimpleUnitNode
- SpecialReduction
- Subsumption
- SystemIdentity
- TranslateMatch
- TranslateMatched
- TranslateUnmapped
- UcumAtom
- UcumEssence
- UcumPrefix
- UnitNode
- UnknownSystem
- ValidateCodeResult
- ValueSet
- ValueSetCompose
- ValueSetExpansion
- ValueSetMemberDecided
- ValueSetMemberUndetermined
Type Aliases
- CodeSystemSource
- ComplexMapApplyResult
- ComplexMapGroupResult
- ComplexMapInput
- ComponentNode
- ConceptActivity
- DiagnosticCode
- FatalCode
- FilterOperator
- GemApplyResult
- GemDirection
- LookupOutcome
- MapCategoryId
- NdcResult
- NdcStatus
- ParseResult
- R4Equivalence
- Reduction
- RelaName
- Relationship
- ResolveSystemResult
- RxNormNavResult
- StatusMapper
- TermType
- TranslateResult
- UcumValidation
- UnmappedMode
- ValueSetMembership
Variables
- COMPLEX_MAP_SOURCE_SYSTEM
- defaultStatusMapper
- DIAGNOSTIC_CODES
- FATAL_CODES
- HL7_V2_OID_ROOT
- HL7_V2_URL_PREFIX
- ICD10CM_ORDER_FILE_FIELDS
- ICD10CM_SYSTEM
- ICD9CM_SYSTEM
- MAP_CATEGORIES
- NO_MAP_CATEGORIES
- RELA
- RELA_INVERSE
- RXNORM_SYSTEM
- SNOMEDCT_SYSTEM
- SYSTEM_IDENTITIES
- TERM_TYPES
- VERSION
Functions
- applyComplexMap
- applyGem
- approximateMatch
- asTermType
- brandsFor
- buildSubsumption
- codeableConcept
- coding
- consistsOf
- doseFormsOf
- expand
- genericFor
- getArray
- getBoolean
- getConcept
- getNumber
- getString
- ingredientsOf
- invertGem
- isA
- isJsonObject
- isSynonymTermType
- isUnknownSystem
- loadCodeSystem
- loadComplexMap
- loadConceptMap
- loadGems
- loadRxNormGraph
- loadUcumEssence
- loadValueSet
- lookup
- makeStatus
- matchesFilter
- parseCsv
- parseCsvSource
- parseFhirCodeSystem
- parseFixedWidth
- parseRrf
- parseRrfLine
- parseUcum
- reduce
- relatedByRela
- resolveNdc
- resolveSystem
- sliceField
- translate
- ucumEqual
- unsupportedOps
- validateCode
- validateCodeInValueSet
- validateUcum