@cosyte/terminology 0.0.10 → 0.0.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -18,7 +18,7 @@ function codeableConcept(init) {
18
18
  // src/common/diagnostics.ts
19
19
  var DIAGNOSTIC_CODES = {
20
20
  /**
21
- * A `$translate` found no target for the source code. A **first-class outcome, never an error** —
21
+ * A `$translate` found no target for the source code. A **first-class outcome, never an error**:
22
22
  * the source is surfaced as `unmapped`, never replaced with a guessed target (the never-fabricate
23
23
  * invariant).
24
24
  */
@@ -29,30 +29,30 @@ var DIAGNOSTIC_CODES = {
29
29
  */
30
30
  TERM_SYSTEM_UNRECOGNIZED: "TERM_SYSTEM_UNRECOGNIZED",
31
31
  /**
32
- * An RRF (pipe-delimited RxNorm/UMLS release) row was structurally unusable — too few columns to
32
+ * An RRF (pipe-delimited RxNorm/UMLS release) row was structurally unusable: too few columns to
33
33
  * reach a configured field, or a missing code. The row is **skipped and surfaced** as a load
34
34
  * warning (liberal on load), never kept as a partially-parsed concept.
35
35
  */
36
36
  TERM_RRF_MALFORMED_ROW: "TERM_RRF_MALFORMED_ROW",
37
37
  /**
38
- * A CSV (RFC-4180, e.g. LOINC `Loinc.csv`) row was structurally unusable — too few fields to reach
38
+ * A CSV (RFC-4180, e.g. LOINC `Loinc.csv`) row was structurally unusable: too few fields to reach
39
39
  * a configured column. The row is **skipped and surfaced** as a load warning, never partial.
40
40
  */
41
41
  TERM_CSV_MALFORMED: "TERM_CSV_MALFORMED",
42
42
  /**
43
- * A fixed-width (e.g. ICD-10-CM order file) row was structurally unusable — too short to contain
43
+ * A fixed-width (e.g. ICD-10-CM order file) row was structurally unusable: too short to contain
44
44
  * the configured code field, or a missing code. Skipped and surfaced, never partial.
45
45
  */
46
46
  TERM_FIXED_WIDTH_MALFORMED: "TERM_FIXED_WIDTH_MALFORMED",
47
47
  /**
48
- * A concept inside a FHIR `CodeSystem` resource was unusable — not an object, or missing its
48
+ * A concept inside a FHIR `CodeSystem` resource was unusable: not an object, or missing its
49
49
  * required `code`. Skipped and surfaced (the whole resource still loads); `line` is `0` since a
50
50
  * JSON concept is not line-addressable.
51
51
  */
52
52
  TERM_FHIR_CONCEPT_MALFORMED: "TERM_FHIR_CONCEPT_MALFORMED",
53
53
  /**
54
54
  * A `$lookup`/`$validate-code` found no concept for the code in the loaded release. A **first-class
55
- * typed outcome, never a guess** — the engine returns `unknown`/`valid: false`, never a fabricated
55
+ * typed outcome, never a guess**: the engine returns `unknown`/`valid: false`, never a fabricated
56
56
  * display or a coerced `valid: true` (the never-fabricate invariant, applied to code identity).
57
57
  */
58
58
  TERM_CODE_UNKNOWN: "TERM_CODE_UNKNOWN",
@@ -69,7 +69,7 @@ var DIAGNOSTIC_CODES = {
69
69
  */
70
70
  TERM_CONCEPT_HEADER_NOT_BILLABLE: "TERM_CONCEPT_HEADER_NOT_BILLABLE",
71
71
  /**
72
- * A ValueSet `compose` part could **not be expanded** — an intensional `include`/`exclude` whose
72
+ * A ValueSet `compose` part could **not be expanded**: an intensional `include`/`exclude` whose
73
73
  * code system was not supplied, an unresolvable referenced value set, or a `filter` operator the
74
74
  * engine does not implement. Surfaced as a typed outcome that marks the expansion **incomplete**;
75
75
  * the engine **never** fabricates a member and **never** returns a silently-empty "no members"
@@ -77,14 +77,14 @@ var DIAGNOSTIC_CODES = {
77
77
  */
78
78
  TERM_VALUESET_CANNOT_EXPAND: "TERM_VALUESET_CANNOT_EXPAND",
79
79
  /**
80
- * A **pre-computed** `ValueSet.expansion` is **incomplete** — its `total` exceeds the number of
80
+ * A **pre-computed** `ValueSet.expansion` is **incomplete**: its `total` exceeds the number of
81
81
  * `contains` entries, or it is flagged too-costly (the VSAC `$expand` >1200-code truncation
82
82
  * hazard). The engine **never treats a truncated expansion as complete membership**: a code
83
83
  * absent from a truncated expansion is `undetermined`, never a confident "not a member".
84
84
  */
85
85
  TERM_VALUESET_EXPANSION_TRUNCATED: "TERM_VALUESET_EXPANSION_TRUNCATED",
86
86
  /**
87
- * A UCUM unit expression is **not valid** — it does not parse against the UCUM grammar, or it
87
+ * A UCUM unit expression is **not valid**: it does not parse against the UCUM grammar, or it
88
88
  * names an atom absent from the vendored UCUM table. A **first-class typed outcome, never an
89
89
  * error and never a guess**: {@link validateUcum} returns `{ valid: false, reason }`, never a
90
90
  * coerced or "nearest" unit (the never-fabricate invariant, applied to units). The
@@ -92,7 +92,7 @@ var DIAGNOSTIC_CODES = {
92
92
  */
93
93
  TERM_UCUM_INVALID: "TERM_UCUM_INVALID",
94
94
  /**
95
- * A crosswalk source code has an **authored No-Map** — the steward declares it has no valid target
95
+ * A crosswalk source code has an **authored No-Map**: the steward declares it has no valid target
96
96
  * in the other classification (a GEM `NoDx`/`NoPCS` sentinel, or a SNOMED complex-map `447638001`
97
97
  * "cannot be classified" category). A **first-class typed outcome, never an error and never a
98
98
  * guess** (the never-fabricate invariant, applied to crosswalks). Distinct from
@@ -100,7 +100,7 @@ var DIAGNOSTIC_CODES = {
100
100
  */
101
101
  TERM_CROSSWALK_NO_MAP: "TERM_CROSSWALK_NO_MAP",
102
102
  /**
103
- * A crosswalk source code is **absent from the map entirely** — not an authored No-Map, simply not
103
+ * A crosswalk source code is **absent from the map entirely**: not an authored No-Map, simply not
104
104
  * present. Surfaced as a typed outcome (never a fabricated target, never a silent success), and
105
105
  * kept distinct from {@link TERM_CROSSWALK_NO_MAP} so a caller can tell "the steward said no target"
106
106
  * from "this code was not in the file".
@@ -109,26 +109,26 @@ var DIAGNOSTIC_CODES = {
109
109
  /**
110
110
  * A SNOMED→ICD-10-CM complex-map group's decision needs **patient context** (an `IFA` age band or
111
111
  * gender) the caller did not supply. The engine surfaces the candidate rules + advice and **refuses
112
- * to pick a branch** it lacks the data for — never a silently-chosen target.
112
+ * to pick a branch** it lacks the data for: never a silently-chosen target.
113
113
  */
114
114
  TERM_CROSSWALK_CONTEXT_REQUIRED: "TERM_CROSSWALK_CONTEXT_REQUIRED",
115
115
  /**
116
- * A GEM file line was structurally unusable — not three whitespace-delimited fields, or a flag
116
+ * A GEM file line was structurally unusable: not three whitespace-delimited fields, or a flag
117
117
  * field that is not a 5-digit code. The row is **skipped and surfaced** as a load warning (liberal
118
118
  * on load), never kept as a partially-parsed entry.
119
119
  */
120
120
  TERM_GEM_MALFORMED_ROW: "TERM_GEM_MALFORMED_ROW",
121
121
  /**
122
- * A SNOMED complex-map RF2 refset row was structurally unusable — missing its
122
+ * A SNOMED complex-map RF2 refset row was structurally unusable: missing its
123
123
  * `referencedComponentId`/`mapGroup`/`mapPriority`. Skipped and surfaced, never partial.
124
124
  */
125
125
  TERM_COMPLEX_MAP_MALFORMED_ROW: "TERM_COMPLEX_MAP_MALFORMED_ROW",
126
126
  /**
127
- * A RxNorm RRF row (`RXNCONSO` / `RXNREL` / `RXNSAT`) was structurally unusable — too few columns to
127
+ * A RxNorm RRF row (`RXNCONSO` / `RXNREL` / `RXNSAT`) was structurally unusable: too few columns to
128
128
  * reach a required field, or a missing `RXCUI`/NDC value. The row is **skipped and surfaced** as a
129
129
  * load warning (liberal on load), never kept as a partial concept/edge. Rows that are simply *not of
130
130
  * interest* (a non-`RXNORM` atom, an atom-level relationship, a non-`NDC` attribute) are skipped
131
- * **silently** — they are expected, not faults.
131
+ * **silently**: they are expected, not faults.
132
132
  */
133
133
  TERM_RXNORM_MALFORMED_ROW: "TERM_RXNORM_MALFORMED_ROW",
134
134
  /**
@@ -142,7 +142,7 @@ var DIAGNOSTIC_CODES = {
142
142
  */
143
143
  TERM_RXNORM_UNTYPED_CONCEPT: "TERM_RXNORM_UNTYPED_CONCEPT",
144
144
  /**
145
- * A RxNorm graph navigation was asked about an `RXCUI` **absent from the loaded release** — a
145
+ * A RxNorm graph navigation was asked about an `RXCUI` **absent from the loaded release**: a
146
146
  * first-class typed outcome, never a fabricated concept and never an empty "success" (the
147
147
  * never-fabricate invariant, applied to the drug graph). Distinct from a *present*
148
148
  * concept that simply has no edge of the requested relationship (that is a found result with empty
@@ -150,7 +150,7 @@ var DIAGNOSTIC_CODES = {
150
150
  */
151
151
  TERM_RXNORM_UNKNOWN_RXCUI: "TERM_RXNORM_UNKNOWN_RXCUI",
152
152
  /**
153
- * An NDC could **not be resolved** to any `RXCUI` in the loaded RxNorm release — a typed, surfaced
153
+ * An NDC could **not be resolved** to any `RXCUI` in the loaded RxNorm release: a typed, surfaced
154
154
  * absence, never a guessed `RXCUI`. NDC↔RXCUI is many:1 and temporal, so a resolution
155
155
  * is always release-scoped; an NDC not present in the loaded release is this diagnostic.
156
156
  */
@@ -158,33 +158,33 @@ var DIAGNOSTIC_CODES = {
158
158
  };
159
159
  var FATAL_CODES = {
160
160
  /**
161
- * A `ConceptMap` resource was structurally unusable — wrong `resourceType`, or a group/element
161
+ * A `ConceptMap` resource was structurally unusable: wrong `resourceType`, or a group/element
162
162
  * missing a required field. Thrown rather than silently loading a partial, misleading map.
163
163
  */
164
164
  TERM_CONCEPTMAP_MALFORMED: "TERM_CONCEPTMAP_MALFORMED",
165
165
  /**
166
- * A CodeSystem *source* was structurally unusable — a FHIR resource with the wrong `resourceType`,
166
+ * A CodeSystem *source* was structurally unusable: a FHIR resource with the wrong `resourceType`,
167
167
  * or a delimited source whose configured code/display column is absent from the header. Thrown
168
168
  * rather than silently loading an empty or mis-keyed release. (Malformed individual **rows** are
169
- * skipped-and-surfaced load warnings, not fatals — only an unusable *source* is fatal.)
169
+ * skipped-and-surfaced load warnings, not fatals: only an unusable *source* is fatal.)
170
170
  */
171
171
  TERM_CODESYSTEM_MALFORMED: "TERM_CODESYSTEM_MALFORMED",
172
172
  /**
173
- * A `ValueSet` resource was structurally unusable — wrong `resourceType`, or a `compose`/`expansion`
173
+ * A `ValueSet` resource was structurally unusable: wrong `resourceType`, or a `compose`/`expansion`
174
174
  * whose required shape (an `include` that is not an object, a `contains` entry missing its `code`)
175
175
  * is corrupt. Thrown rather than silently loading a partial value set that would bind *some* codes
176
- * and quietly drop others. (A `filter` operator the engine does not implement is **not** fatal — it
176
+ * and quietly drop others. (A `filter` operator the engine does not implement is **not** fatal; it
177
177
  * is the surfaced `TERM_VALUESET_CANNOT_EXPAND` diagnostic at expansion time.)
178
178
  */
179
179
  TERM_VALUESET_MALFORMED: "TERM_VALUESET_MALFORMED",
180
180
  /**
181
- * A crosswalk map *source* was structurally unusable — e.g. a SNOMED complex-map RF2 refset with
181
+ * A crosswalk map *source* was structurally unusable: e.g. a SNOMED complex-map RF2 refset with
182
182
  * empty content or a header missing a required column. Thrown rather than silently loading an empty
183
183
  * or mis-keyed map. (Malformed individual **rows** are skipped-and-surfaced warnings, not fatals.)
184
184
  */
185
185
  TERM_CROSSWALK_MALFORMED: "TERM_CROSSWALK_MALFORMED",
186
186
  /**
187
- * An **inversion** of a directional crosswalk was requested — a forbidden operation. The GEMs and
187
+ * An **inversion** of a directional crosswalk was requested: a forbidden operation. The GEMs and
188
188
  * the SNOMED→ICD-10-CM map are authoritative in **one direction only**; a forward map is not the
189
189
  * inverse of the backward map. Thrown by {@link ../crosswalk/gems.invertGem} so the
190
190
  * never-invert refusal is a first-class, discoverable contract rather than a silent absence.
@@ -197,7 +197,7 @@ var TerminologyError = class _TerminologyError extends Error {
197
197
  /**
198
198
  * @param code - The stable {@link FatalCode} describing the fault.
199
199
  * @param message - A **value-free** structural description (path + fault; never an input value).
200
- * Every piece of it must be engine-owned — a literal, a frozen-table entry, or a locus this
200
+ * Every piece of it must be engine-owned: a literal, a frozen-table entry, or a locus this
201
201
  * package built. This string reaches `err.stack`, so interpolating a caller-supplied or
202
202
  * document-derived value into it is how a diagnostic becomes a leak.
203
203
  */
@@ -3912,7 +3912,7 @@ function parseTerm(cur, inParen) {
3912
3912
  factors.push({ sign: op === "/" ? -1 : 1, node: comp.node });
3913
3913
  }
3914
3914
  if (inParen) {
3915
- if (cur.s[cur.pos] !== ")") return { ok: false, reason: "unbalanced '(' \u2014 missing ')'" };
3915
+ if (cur.s[cur.pos] !== ")") return { ok: false, reason: "unbalanced '(': missing ')'" };
3916
3916
  cur.pos++;
3917
3917
  }
3918
3918
  return { ok: true, node: { kind: "term", factors } };
@@ -4185,10 +4185,10 @@ function applyGem(map, source) {
4185
4185
  return Object.freeze(matched);
4186
4186
  }
4187
4187
  var NOT_INVERTIBLE_MESSAGE = /* @__PURE__ */ new Map([
4188
- ["9-to-10", "GEM map (direction 9-to-10) cannot be inverted \u2014 load the 10-to-9 GEM file instead"],
4189
- ["10-to-9", "GEM map (direction 10-to-9) cannot be inverted \u2014 load the 9-to-10 GEM file instead"]
4188
+ ["9-to-10", "GEM map (direction 9-to-10) cannot be inverted: load the 10-to-9 GEM file instead"],
4189
+ ["10-to-9", "GEM map (direction 10-to-9) cannot be inverted: load the 9-to-10 GEM file instead"]
4190
4190
  ]);
4191
- var NOT_INVERTIBLE_UNKNOWN_DIRECTION = "GEM map cannot be inverted \u2014 load the reverse GEM file instead";
4191
+ var NOT_INVERTIBLE_UNKNOWN_DIRECTION = "GEM map cannot be inverted: load the reverse GEM file instead";
4192
4192
  function invertGem(map) {
4193
4193
  throw new TerminologyError(
4194
4194
  FATAL_CODES.TERM_MAP_NOT_INVERTIBLE,
@@ -4198,13 +4198,13 @@ function invertGem(map) {
4198
4198
 
4199
4199
  // src/crosswalk/categories.ts
4200
4200
  var MAP_CATEGORIES = {
4201
- /** `447637006` — "Map source concept is properly classified" (a normal, usable target). */
4201
+ /** `447637006`: "Map source concept is properly classified" (a normal, usable target). */
4202
4202
  PROPERLY_CLASSIFIED: "447637006",
4203
- /** `447638001` — "Map source concept cannot be classified with available data" — a **No-Map**. */
4203
+ /** `447638001`: "Map source concept cannot be classified with available data" (a **No-Map**). */
4204
4204
  NO_MAP: "447638001",
4205
- /** `447639009` — "Map of source concept is context dependent" (needs runtime patient context). */
4205
+ /** `447639009`: "Map of source concept is context dependent" (needs runtime patient context). */
4206
4206
  CONTEXT_DEPENDENT: "447639009",
4207
- /** `447640006` — "Source concept is ambiguous" — surface candidates, never pick one. */
4207
+ /** `447640006`: "Source concept is ambiguous" (surface candidates, never pick one). */
4208
4208
  AMBIGUOUS: "447640006"
4209
4209
  };
4210
4210
  var NO_MAP_CATEGORIES = /* @__PURE__ */ new Set([MAP_CATEGORIES.NO_MAP]);
@@ -4633,37 +4633,37 @@ var RELA = {
4633
4633
  * Neither reaches an `SCD`.
4634
4634
  */
4635
4635
  INGREDIENT_OF: "ingredient_of",
4636
- /** `has_precise_ingredient` — subject *has precise ingredient* object (a `PIN`). */
4636
+ /** `has_precise_ingredient`: subject *has precise ingredient* object (a `PIN`). */
4637
4637
  HAS_PRECISE_INGREDIENT: "has_precise_ingredient",
4638
- /** `precise_ingredient_of` — inverse of `has_precise_ingredient`. */
4638
+ /** `precise_ingredient_of`: inverse of `has_precise_ingredient`. */
4639
4639
  PRECISE_INGREDIENT_OF: "precise_ingredient_of",
4640
- /** `tradename_of` — subject (a branded concept) *is a tradename of* object (its generic). */
4640
+ /** `tradename_of`: subject (a branded concept) *is a tradename of* object (its generic). */
4641
4641
  TRADENAME_OF: "tradename_of",
4642
- /** `has_tradename` — subject (a generic concept) *has tradename* object (a branded concept). */
4642
+ /** `has_tradename`: subject (a generic concept) *has tradename* object (a branded concept). */
4643
4643
  HAS_TRADENAME: "has_tradename",
4644
- /** `has_dose_form` — subject (a drug) *has dose form* object (a `DF`). */
4644
+ /** `has_dose_form`: subject (a drug) *has dose form* object (a `DF`). */
4645
4645
  HAS_DOSE_FORM: "has_dose_form",
4646
- /** `dose_form_of` — subject (a `DF`) *is the dose form of* object (a drug). */
4646
+ /** `dose_form_of`: subject (a `DF`) *is the dose form of* object (a drug). */
4647
4647
  DOSE_FORM_OF: "dose_form_of",
4648
- /** `has_doseformgroup` — subject *has dose-form group* object (a `DFG`). */
4648
+ /** `has_doseformgroup`: subject *has dose-form group* object (a `DFG`). */
4649
4649
  HAS_DOSE_FORM_GROUP: "has_doseformgroup",
4650
- /** `doseformgroup_of` — inverse of `has_doseformgroup`. */
4650
+ /** `doseformgroup_of`: inverse of `has_doseformgroup`. */
4651
4651
  DOSE_FORM_GROUP_OF: "doseformgroup_of",
4652
- /** `consists_of` — subject (an `SCD`/`SBD`) *consists of* object (its `SCDC`/`SBDC` component(s)). */
4652
+ /** `consists_of`: subject (an `SCD`/`SBD`) *consists of* object (its `SCDC`/`SBDC` component(s)). */
4653
4653
  CONSISTS_OF: "consists_of",
4654
- /** `constitutes` — subject (a component) *constitutes* object (the drug). Inverse of `consists_of`. */
4654
+ /** `constitutes`: subject (a component) *constitutes* object (the drug). Inverse of `consists_of`. */
4655
4655
  CONSTITUTES: "constitutes",
4656
- /** `contains` — subject (a pack) *contains* object (a member drug). */
4656
+ /** `contains`: subject (a pack) *contains* object (a member drug). */
4657
4657
  CONTAINS: "contains",
4658
- /** `contained_in` — subject (a drug) *is contained in* object (a pack). Inverse of `contains`. */
4658
+ /** `contained_in`: subject (a drug) *is contained in* object (a pack). Inverse of `contains`. */
4659
4659
  CONTAINED_IN: "contained_in",
4660
- /** `has_quantified_form` — subject *has quantified form* object. */
4660
+ /** `has_quantified_form`: subject *has quantified form* object. */
4661
4661
  HAS_QUANTIFIED_FORM: "has_quantified_form",
4662
- /** `quantified_form_of` — inverse of `has_quantified_form`. */
4662
+ /** `quantified_form_of`: inverse of `has_quantified_form`. */
4663
4663
  QUANTIFIED_FORM_OF: "quantified_form_of",
4664
- /** `isa` — subject *is a* object (hierarchical, e.g. `SCD isa SCDG`). */
4664
+ /** `isa`: subject *is a* object (hierarchical, e.g. `SCD isa SCDG`). */
4665
4665
  ISA: "isa",
4666
- /** `inverse_isa` — subject *is a parent of* object. Inverse of `isa`. */
4666
+ /** `inverse_isa`: subject *is a parent of* object. Inverse of `isa`. */
4667
4667
  INVERSE_ISA: "inverse_isa"
4668
4668
  };
4669
4669
  var RELA_INVERSE = Object.freeze({
@@ -4774,7 +4774,7 @@ function approximateMatch(graph, query, options = {}) {
4774
4774
  }
4775
4775
 
4776
4776
  // src/index.ts
4777
- var VERSION = "0.0.10";
4777
+ var VERSION = "0.0.12";
4778
4778
 
4779
4779
  export { COMPLEX_MAP_SOURCE_SYSTEM, 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, TerminologyError, VERSION, applyComplexMap, applyGem, approximateMatch, asTermType, brandsFor, buildSubsumption, codeableConcept, coding, consistsOf, defaultStatusMapper, 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 };
4780
4780
  //# sourceMappingURL=index.mjs.map