@peerbits/medical-terminology 0.1.0
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/LICENSE +105 -0
- package/README.md +139 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.js +10 -0
- package/dist/provider.d.ts +7 -0
- package/dist/provider.js +42 -0
- package/dist/registry.d.ts +6 -0
- package/dist/registry.js +67 -0
- package/dist/types.d.ts +32 -0
- package/dist/types.js +1 -0
- package/dist/validate.d.ts +15 -0
- package/dist/validate.js +159 -0
- package/dist/validators/cpt.d.ts +9 -0
- package/dist/validators/cpt.js +14 -0
- package/dist/validators/icd10cm.d.ts +7 -0
- package/dist/validators/icd10cm.js +12 -0
- package/dist/validators/loinc.d.ts +6 -0
- package/dist/validators/loinc.js +11 -0
- package/dist/validators/rxnorm.d.ts +7 -0
- package/dist/validators/rxnorm.js +12 -0
- package/dist/validators/snomed.d.ts +19 -0
- package/dist/validators/snomed.js +68 -0
- package/dist/validators/ucum.d.ts +6 -0
- package/dist/validators/ucum.js +13 -0
- package/package.json +60 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity.
|
|
18
|
+
|
|
19
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
20
|
+
exercising permissions granted by this License.
|
|
21
|
+
|
|
22
|
+
"Source" form shall mean the preferred form for making modifications.
|
|
23
|
+
|
|
24
|
+
"Object" form shall mean any form resulting from mechanical
|
|
25
|
+
transformation or translation of a Source form.
|
|
26
|
+
|
|
27
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
28
|
+
Object form, made available under the License, as indicated by a
|
|
29
|
+
copyright notice that is included in or attached to the work.
|
|
30
|
+
|
|
31
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
32
|
+
form, that is based on (or derived from) the Work.
|
|
33
|
+
|
|
34
|
+
"Contribution" shall mean any work of authorship intentionally
|
|
35
|
+
submitted to Licensor for inclusion in the Work.
|
|
36
|
+
|
|
37
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
38
|
+
on behalf of whom a Contribution has been received by Licensor.
|
|
39
|
+
|
|
40
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
41
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
42
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
43
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
44
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
45
|
+
Work and such Derivative Works in Source or Object form.
|
|
46
|
+
|
|
47
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
48
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
49
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
50
|
+
(except as stated in this section) patent license to make, have
|
|
51
|
+
made, use, offer to sell, sell, import, and otherwise transfer the
|
|
52
|
+
Work. If You institute patent litigation against any entity
|
|
53
|
+
alleging that the Work constitutes direct or contributory patent
|
|
54
|
+
infringement, then any patent licenses granted to You under this
|
|
55
|
+
License for that Work shall terminate as of the date such
|
|
56
|
+
litigation is filed.
|
|
57
|
+
|
|
58
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
59
|
+
Work or Derivative Works thereof provided that You meet the
|
|
60
|
+
following conditions:
|
|
61
|
+
|
|
62
|
+
(a) You must give any other recipients a copy of this License; and
|
|
63
|
+
(b) You must cause modified files to carry prominent notices; and
|
|
64
|
+
(c) You must retain all copyright, patent, trademark, and
|
|
65
|
+
attribution notices from the Source form; and
|
|
66
|
+
(d) If the Work includes a NOTICE file, any Derivative Works must
|
|
67
|
+
include a readable copy of its attribution notices.
|
|
68
|
+
|
|
69
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
70
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
71
|
+
by You shall be under the terms of this License, without additional
|
|
72
|
+
terms or conditions.
|
|
73
|
+
|
|
74
|
+
6. Trademarks. This License does not grant permission to use trade
|
|
75
|
+
names, trademarks, service marks, or product names of the Licensor.
|
|
76
|
+
|
|
77
|
+
7. Disclaimer of Warranty. The Work is provided on an "AS IS" BASIS,
|
|
78
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
79
|
+
implied.
|
|
80
|
+
|
|
81
|
+
8. Limitation of Liability. In no event shall any Contributor be
|
|
82
|
+
liable for damages arising as a result of this License or out of
|
|
83
|
+
the use or inability to use the Work.
|
|
84
|
+
|
|
85
|
+
9. Accepting Warranty or Additional Liability. You may choose to offer
|
|
86
|
+
support, warranty, indemnity, or other liability obligations, but
|
|
87
|
+
only on Your own behalf and sole responsibility.
|
|
88
|
+
|
|
89
|
+
END OF TERMS AND CONDITIONS
|
|
90
|
+
|
|
91
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
92
|
+
|
|
93
|
+
Copyright [yyyy] [name of copyright owner]
|
|
94
|
+
|
|
95
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
96
|
+
you may not use this file except in compliance with the License.
|
|
97
|
+
You may obtain a copy of the License at
|
|
98
|
+
|
|
99
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
100
|
+
|
|
101
|
+
Unless required by applicable law or agreed to in writing, software
|
|
102
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
103
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
104
|
+
See the License for the specific language governing permissions and
|
|
105
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
# @peerbits/medical-terminology
|
|
2
|
+
|
|
3
|
+
> Terminology system-URI registry and code format/checksum validation utilities — ships zero licensed terminology datasets (see [Licensing](./docs/LICENSING.md))
|
|
4
|
+
|
|
5
|
+
**Category:** Medical Coding — Terminology & Code-Handling Utilities · **License:** Apache-2.0 · **Status:** Stable
|
|
6
|
+
|
|
7
|
+
[](https://github.com/PeerbitsSolution/medical-terminology/actions/workflows/ci.yml)
|
|
8
|
+
[](LICENSE)
|
|
9
|
+
[](https://www.npmjs.com/package/@peerbits/medical-terminology)
|
|
10
|
+
|
|
11
|
+
---
|
|
12
|
+
|
|
13
|
+
## 1. What problem does this solve?
|
|
14
|
+
|
|
15
|
+
Healthcare applications regularly handle coded concepts across disparate medical terminology systems—LOINC, SNOMED CT, ICD-10-CM, RxNorm, CPT, and UCUM. Validating these concepts in ingestion pipelines typically forces teams to either deploy heavy terminology servers (like Ontoserver or UMLS TS) or omit validation entirely, allowing malformed identifiers and invalid URIs to corrupt downstream FHIR records.
|
|
16
|
+
|
|
17
|
+
`@peerbits/medical-terminology` provides a zero-dependency, in-memory validation engine that standardizes canonical system URIs and validates code syntax, pattern structures, and Verhoeff check-digits client-side, with an optional pluggable provider architecture for teams that connect real terminology services.
|
|
18
|
+
|
|
19
|
+
> **⚠️ Licensing Note:** This repository ships canonical code-system URI metadata and structural format/checksum validators only. It does **not** include or distribute any proprietary CPT, SNOMED CT, or RxNorm concept datasets. See [docs/LICENSING.md](./docs/LICENSING.md) for full compliance details.
|
|
20
|
+
|
|
21
|
+
---
|
|
22
|
+
|
|
23
|
+
## 2. Features
|
|
24
|
+
|
|
25
|
+
- **Canonical System URI Registry**: Standardized URIs, OIDs, and short-names for 6 major medical coding systems:
|
|
26
|
+
- **LOINC** (`http://loinc.org`)
|
|
27
|
+
- **SNOMED CT** (`http://snomed.info/sct`)
|
|
28
|
+
- **ICD-10-CM** (`http://hl7.org/fhir/sid/icd-10-cm`)
|
|
29
|
+
- **RxNorm** (`http://www.nlm.nih.gov/research/umls/rxnorm`)
|
|
30
|
+
- **CPT** (`http://www.ama-assn.org/go/cpt`)
|
|
31
|
+
- **UCUM** (`http://unitsofmeasure.org`)
|
|
32
|
+
- **Fast Structural & Checksum Validation**:
|
|
33
|
+
- Full Verhoeff check-digit calculation and validation for SNOMED SCTIDs.
|
|
34
|
+
- RegEx & structural format validation for LOINC, ICD-10-CM, CPT (5-digit syntax), RxNorm (RxCUI numeric format), and UCUM syntax.
|
|
35
|
+
- **Pluggable Provider Architecture**: Register runtime lookup hooks (e.g., UMLS REST API, local Terminology Server) to augment structural checks with real-time concept validation.
|
|
36
|
+
- **Zero Runtime Dependencies**: Pure TypeScript with zero external network or database requirements.
|
|
37
|
+
|
|
38
|
+
---
|
|
39
|
+
|
|
40
|
+
## 3. Installation
|
|
41
|
+
|
|
42
|
+
```bash
|
|
43
|
+
npm install @peerbits/medical-terminology
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
---
|
|
47
|
+
|
|
48
|
+
## 4. Demo and Quick Start
|
|
49
|
+
|
|
50
|
+
[Peerbits HealthTech - Medical Terminology Demo](https://healthcare.peerbits.com/demo/medical-terminology)
|
|
51
|
+
|
|
52
|
+
```ts
|
|
53
|
+
import { validate, SYSTEM_REGISTRY, isValidSctid } from "@peerbits/medical-terminology";
|
|
54
|
+
|
|
55
|
+
// 1. Validate a LOINC observation code
|
|
56
|
+
const loincResult = validate({
|
|
57
|
+
system: "http://loinc.org",
|
|
58
|
+
code: "8867-4",
|
|
59
|
+
});
|
|
60
|
+
console.log(loincResult.valid); // true
|
|
61
|
+
|
|
62
|
+
// 2. Validate SNOMED CT Concept ID with Verhoeff check-digit
|
|
63
|
+
const snomedResult = validate({
|
|
64
|
+
system: "http://snomed.info/sct",
|
|
65
|
+
code: "73211009", // Diabetes mellitus
|
|
66
|
+
});
|
|
67
|
+
console.log(snomedResult.valid); // true
|
|
68
|
+
|
|
69
|
+
// 3. Catch invalid formats early
|
|
70
|
+
const invalidResult = validate({
|
|
71
|
+
system: "http://hl7.org/fhir/sid/icd-10-cm",
|
|
72
|
+
code: "INVALID_CODE",
|
|
73
|
+
});
|
|
74
|
+
console.log(invalidResult.valid); // false
|
|
75
|
+
console.log(invalidResult.issues);
|
|
76
|
+
// [ { severity: "error", path: "code", code: "invalid-format", message: "..." } ]
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
---
|
|
80
|
+
|
|
81
|
+
## 5. Pluggable Terminology Providers
|
|
82
|
+
|
|
83
|
+
You can register custom terminology lookup providers to resolve live concepts while falling back gracefully if offline:
|
|
84
|
+
|
|
85
|
+
```ts
|
|
86
|
+
import { registerProvider, validateWithProvider } from "@peerbits/medical-terminology";
|
|
87
|
+
|
|
88
|
+
// Register an in-house or external terminology resolver
|
|
89
|
+
registerProvider("loinc", async (code) => {
|
|
90
|
+
const isFound = await checkLocalDatabase(code);
|
|
91
|
+
return { found: isFound, display: isFound ? "Heart rate" : undefined };
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
// Validate format AND verify existence through the provider
|
|
95
|
+
const result = await validateWithProvider({
|
|
96
|
+
system: "http://loinc.org",
|
|
97
|
+
code: "8867-4",
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
console.log(result.valid); // true
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
---
|
|
104
|
+
|
|
105
|
+
## 6. Architecture
|
|
106
|
+
|
|
107
|
+
```
|
|
108
|
+
src/
|
|
109
|
+
├── index.ts # Package entry point and exports
|
|
110
|
+
├── registry.ts # Canonical URIs, OIDs, and system metadata
|
|
111
|
+
├── provider.ts # Pluggable terminology provider interface
|
|
112
|
+
├── types.ts # TypeScript declarations and error shapes
|
|
113
|
+
├── validate.ts # Unified validation engine
|
|
114
|
+
└── validators/
|
|
115
|
+
├── cpt.ts # CPT 5-digit format check (Zero dataset content)
|
|
116
|
+
├── icd10cm.ts # ICD-10-CM alphanumeric structural check
|
|
117
|
+
├── loinc.ts # LOINC hyphenated identifier check
|
|
118
|
+
├── rxnorm.ts # RxNorm RxCUI numeric format check
|
|
119
|
+
├── snomed.ts # SNOMED CT Verhoeff check-digit algorithm
|
|
120
|
+
└── ucum.ts # UCUM unit syntax validator
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
---
|
|
124
|
+
|
|
125
|
+
## 7. Contributing
|
|
126
|
+
|
|
127
|
+
See [CONTRIBUTING.md](./CONTRIBUTING.md).
|
|
128
|
+
|
|
129
|
+
---
|
|
130
|
+
|
|
131
|
+
## 8. License
|
|
132
|
+
|
|
133
|
+
Apache License 2.0 — see [LICENSE](./LICENSE).
|
|
134
|
+
|
|
135
|
+
---
|
|
136
|
+
|
|
137
|
+
## 9. About PeerbitsSolution
|
|
138
|
+
|
|
139
|
+
`@peerbits/medical-terminology` is part of the [PeerbitsSolution HealthTech Open Source](https://github.com/PeerbitsSolution) initiative—reusable engineering components extracted from our healthcare technology work. This repository contains generalized, reusable logic only; it is not tied to any specific client engagement or commercial product.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export declare const VERSION = "1.0.0";
|
|
2
|
+
export { validate, validateWithProvider } from "./validate.js";
|
|
3
|
+
export { registerProvider, unregisterProvider, clearProviders, lookup, hasProvider, getRegisteredProviderSystems, } from "./provider.js";
|
|
4
|
+
export { SYSTEM_REGISTRY, getSupportedSystems, getSystemByIdentifier, getSystemByShortName, getSystemByUri, } from "./registry.js";
|
|
5
|
+
export { isValidLoincFormat } from "./validators/loinc.js";
|
|
6
|
+
export { isValidIcd10CmFormat } from "./validators/icd10cm.js";
|
|
7
|
+
export { isValidCptFormat } from "./validators/cpt.js";
|
|
8
|
+
export { isValidRxNormFormat } from "./validators/rxnorm.js";
|
|
9
|
+
export { isValidUcumSyntax } from "./validators/ucum.js";
|
|
10
|
+
export { calculateSctidCheckDigit, isValidSctid, } from "./validators/snomed.js";
|
|
11
|
+
export type { CodedConcept, ProviderLookupResult, SupportedTerminologySystem, TerminologyProvider, TerminologySystem, ValidationIssue, ValidationResult, ValidationSeverity, } from "./types.js";
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export const VERSION = "1.0.0";
|
|
2
|
+
export { validate, validateWithProvider } from "./validate.js";
|
|
3
|
+
export { registerProvider, unregisterProvider, clearProviders, lookup, hasProvider, getRegisteredProviderSystems, } from "./provider.js";
|
|
4
|
+
export { SYSTEM_REGISTRY, getSupportedSystems, getSystemByIdentifier, getSystemByShortName, getSystemByUri, } from "./registry.js";
|
|
5
|
+
export { isValidLoincFormat } from "./validators/loinc.js";
|
|
6
|
+
export { isValidIcd10CmFormat } from "./validators/icd10cm.js";
|
|
7
|
+
export { isValidCptFormat } from "./validators/cpt.js";
|
|
8
|
+
export { isValidRxNormFormat } from "./validators/rxnorm.js";
|
|
9
|
+
export { isValidUcumSyntax } from "./validators/ucum.js";
|
|
10
|
+
export { calculateSctidCheckDigit, isValidSctid, } from "./validators/snomed.js";
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { CodedConcept, ProviderLookupResult, TerminologyProvider } from "./types.js";
|
|
2
|
+
export declare function registerProvider(system: string, provider: TerminologyProvider): void;
|
|
3
|
+
export declare function unregisterProvider(system: string): boolean;
|
|
4
|
+
export declare function clearProviders(): void;
|
|
5
|
+
export declare function getRegisteredProviderSystems(): readonly string[];
|
|
6
|
+
export declare function hasProvider(system: string): boolean;
|
|
7
|
+
export declare function lookup(system: string, code: string, concept: Readonly<CodedConcept>): Promise<ProviderLookupResult | undefined>;
|
package/dist/provider.js
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { getSystemByIdentifier } from "./registry.js";
|
|
2
|
+
const providers = new Map();
|
|
3
|
+
export function registerProvider(system, provider) {
|
|
4
|
+
if (typeof system !== "string") {
|
|
5
|
+
throw new TypeError("Provider registration requires a string system identifier.");
|
|
6
|
+
}
|
|
7
|
+
const s = getSystemByIdentifier(system);
|
|
8
|
+
if (!s) {
|
|
9
|
+
throw new TypeError(`Cannot register provider for unknown system identifier: "${system}".`);
|
|
10
|
+
}
|
|
11
|
+
if (typeof provider !== "function") {
|
|
12
|
+
throw new TypeError("Provider must be a function.");
|
|
13
|
+
}
|
|
14
|
+
providers.set(s.uri, provider);
|
|
15
|
+
}
|
|
16
|
+
export function unregisterProvider(system) {
|
|
17
|
+
if (typeof system !== "string")
|
|
18
|
+
return false;
|
|
19
|
+
const s = getSystemByIdentifier(system);
|
|
20
|
+
return s ? providers.delete(s.uri) : false;
|
|
21
|
+
}
|
|
22
|
+
export function clearProviders() {
|
|
23
|
+
providers.clear();
|
|
24
|
+
}
|
|
25
|
+
export function getRegisteredProviderSystems() {
|
|
26
|
+
return Object.freeze([...providers.keys()]);
|
|
27
|
+
}
|
|
28
|
+
export function hasProvider(system) {
|
|
29
|
+
if (typeof system !== "string")
|
|
30
|
+
return false;
|
|
31
|
+
const s = getSystemByIdentifier(system);
|
|
32
|
+
return !!s && providers.has(s.uri);
|
|
33
|
+
}
|
|
34
|
+
export async function lookup(system, code, concept) {
|
|
35
|
+
if (typeof system !== "string" || typeof code !== "string")
|
|
36
|
+
return undefined;
|
|
37
|
+
const s = getSystemByIdentifier(system);
|
|
38
|
+
const fn = s ? providers.get(s.uri) : undefined;
|
|
39
|
+
if (!fn)
|
|
40
|
+
return undefined;
|
|
41
|
+
return await fn(code, concept);
|
|
42
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { SupportedTerminologySystem, TerminologySystem } from "./types.js";
|
|
2
|
+
export declare const SYSTEM_REGISTRY: Readonly<Record<SupportedTerminologySystem, Readonly<TerminologySystem>>>;
|
|
3
|
+
export declare const getSupportedSystems: () => readonly TerminologySystem[];
|
|
4
|
+
export declare const getSystemByShortName: (shortName: string) => TerminologySystem | undefined;
|
|
5
|
+
export declare const getSystemByUri: (uri: string) => TerminologySystem | undefined;
|
|
6
|
+
export declare const getSystemByIdentifier: (identifier: string) => TerminologySystem | undefined;
|
package/dist/registry.js
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
export const SYSTEM_REGISTRY = Object.freeze({
|
|
2
|
+
loinc: Object.freeze({
|
|
3
|
+
shortName: "loinc",
|
|
4
|
+
uri: "http://loinc.org",
|
|
5
|
+
displayName: "LOINC",
|
|
6
|
+
oid: "2.16.840.1.113883.6.1",
|
|
7
|
+
description: "Logical Observation Identifiers Names and Codes",
|
|
8
|
+
}),
|
|
9
|
+
snomed: Object.freeze({
|
|
10
|
+
shortName: "snomed",
|
|
11
|
+
uri: "http://snomed.info/sct",
|
|
12
|
+
displayName: "SNOMED CT",
|
|
13
|
+
oid: "2.16.840.1.113883.6.96",
|
|
14
|
+
description: "SNOMED Clinical Terms",
|
|
15
|
+
}),
|
|
16
|
+
icd10cm: Object.freeze({
|
|
17
|
+
shortName: "icd10cm",
|
|
18
|
+
uri: "http://hl7.org/fhir/sid/icd-10-cm",
|
|
19
|
+
displayName: "ICD-10-CM",
|
|
20
|
+
oid: "2.16.840.1.113883.6.90",
|
|
21
|
+
description: "International Classification of Diseases, 10th Revision, Clinical Modification",
|
|
22
|
+
}),
|
|
23
|
+
rxnorm: Object.freeze({
|
|
24
|
+
shortName: "rxnorm",
|
|
25
|
+
uri: "http://www.nlm.nih.gov/research/umls/rxnorm",
|
|
26
|
+
displayName: "RxNorm",
|
|
27
|
+
oid: "2.16.840.1.113883.6.88",
|
|
28
|
+
description: "National Library of Medicine RxNorm",
|
|
29
|
+
}),
|
|
30
|
+
cpt: Object.freeze({
|
|
31
|
+
shortName: "cpt",
|
|
32
|
+
uri: "http://www.ama-assn.org/go/cpt",
|
|
33
|
+
displayName: "CPT",
|
|
34
|
+
oid: "2.16.840.1.113883.6.12",
|
|
35
|
+
description: "Current Procedural Terminology (AMA)",
|
|
36
|
+
}),
|
|
37
|
+
ucum: Object.freeze({
|
|
38
|
+
shortName: "ucum",
|
|
39
|
+
uri: "http://unitsofmeasure.org",
|
|
40
|
+
displayName: "UCUM",
|
|
41
|
+
oid: "2.16.840.1.113883.6.8",
|
|
42
|
+
description: "Unified Code for Units of Measure",
|
|
43
|
+
}),
|
|
44
|
+
});
|
|
45
|
+
const allSystems = Object.freeze(Object.values(SYSTEM_REGISTRY));
|
|
46
|
+
const byUri = new Map(allSystems.map((s) => [s.uri.toLowerCase(), s]));
|
|
47
|
+
const byShortName = new Map(allSystems.map((s) => [s.shortName.toLowerCase(), s]));
|
|
48
|
+
const byOid = new Map(allSystems
|
|
49
|
+
.filter((s) => !!s.oid)
|
|
50
|
+
.map((s) => [s.oid.toLowerCase(), s]));
|
|
51
|
+
export const getSupportedSystems = () => allSystems;
|
|
52
|
+
export const getSystemByShortName = (shortName) => {
|
|
53
|
+
if (typeof shortName !== "string")
|
|
54
|
+
return undefined;
|
|
55
|
+
return byShortName.get(shortName.trim().toLowerCase());
|
|
56
|
+
};
|
|
57
|
+
export const getSystemByUri = (uri) => {
|
|
58
|
+
if (typeof uri !== "string")
|
|
59
|
+
return undefined;
|
|
60
|
+
return byUri.get(uri.trim().toLowerCase());
|
|
61
|
+
};
|
|
62
|
+
export const getSystemByIdentifier = (identifier) => {
|
|
63
|
+
if (typeof identifier !== "string")
|
|
64
|
+
return undefined;
|
|
65
|
+
const clean = identifier.trim().toLowerCase();
|
|
66
|
+
return byUri.get(clean) ?? byShortName.get(clean) ?? byOid.get(clean);
|
|
67
|
+
};
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
export type SupportedTerminologySystem = "loinc" | "snomed" | "icd10cm" | "rxnorm" | "cpt" | "ucum";
|
|
2
|
+
export type ValidationSeverity = "error" | "warning" | "information";
|
|
3
|
+
export interface TerminologySystem {
|
|
4
|
+
shortName: SupportedTerminologySystem;
|
|
5
|
+
uri: string;
|
|
6
|
+
displayName: string;
|
|
7
|
+
oid?: string;
|
|
8
|
+
description?: string;
|
|
9
|
+
}
|
|
10
|
+
export interface CodedConcept {
|
|
11
|
+
system: string;
|
|
12
|
+
code: string;
|
|
13
|
+
display?: string;
|
|
14
|
+
}
|
|
15
|
+
export interface ValidationIssue {
|
|
16
|
+
severity: ValidationSeverity;
|
|
17
|
+
path: string;
|
|
18
|
+
code: string;
|
|
19
|
+
message: string;
|
|
20
|
+
}
|
|
21
|
+
export interface ValidationResult {
|
|
22
|
+
valid: boolean;
|
|
23
|
+
issues: ValidationIssue[];
|
|
24
|
+
system?: TerminologySystem;
|
|
25
|
+
providerConfigured: boolean;
|
|
26
|
+
}
|
|
27
|
+
export interface ProviderLookupResult {
|
|
28
|
+
found: boolean;
|
|
29
|
+
display?: string;
|
|
30
|
+
message?: string;
|
|
31
|
+
}
|
|
32
|
+
export type TerminologyProvider = (code: string, concept: Readonly<CodedConcept>) => ProviderLookupResult | Promise<ProviderLookupResult>;
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { ValidationResult } from "./types.js";
|
|
2
|
+
/**
|
|
3
|
+
* Validates the structure and code format of a coded concept.
|
|
4
|
+
*
|
|
5
|
+
* @param concept The input concept object (e.g., { system, code, display? }).
|
|
6
|
+
* @returns ValidationResult with validity flag, issues, and system metadata.
|
|
7
|
+
*/
|
|
8
|
+
export declare function validate(concept: unknown): ValidationResult;
|
|
9
|
+
/**
|
|
10
|
+
* Validates format and dispatches to a registered TerminologyProvider if configured.
|
|
11
|
+
*
|
|
12
|
+
* @param concept The input concept object (e.g., { system, code, display? }).
|
|
13
|
+
* @returns Promise<ValidationResult> with format & provider validation results.
|
|
14
|
+
*/
|
|
15
|
+
export declare function validateWithProvider(concept: unknown): Promise<ValidationResult>;
|
package/dist/validate.js
ADDED
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
import { hasProvider, lookup } from "./provider.js";
|
|
2
|
+
import { getSystemByIdentifier, getSystemByUri } from "./registry.js";
|
|
3
|
+
import { isValidLoincFormat } from "./validators/loinc.js";
|
|
4
|
+
import { isValidIcd10CmFormat } from "./validators/icd10cm.js";
|
|
5
|
+
import { isValidCptFormat } from "./validators/cpt.js";
|
|
6
|
+
import { isValidRxNormFormat } from "./validators/rxnorm.js";
|
|
7
|
+
import { isValidSctid } from "./validators/snomed.js";
|
|
8
|
+
import { isValidUcumSyntax } from "./validators/ucum.js";
|
|
9
|
+
const formatChecks = {
|
|
10
|
+
loinc: isValidLoincFormat,
|
|
11
|
+
icd10cm: isValidIcd10CmFormat,
|
|
12
|
+
cpt: isValidCptFormat,
|
|
13
|
+
rxnorm: isValidRxNormFormat,
|
|
14
|
+
snomed: isValidSctid,
|
|
15
|
+
ucum: isValidUcumSyntax,
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* Safely extracts a string property value from an unknown object without throwing
|
|
19
|
+
* or triggering prototype pollution side-effects.
|
|
20
|
+
*/
|
|
21
|
+
function extractString(target, key) {
|
|
22
|
+
if (!target || typeof target !== "object" || Array.isArray(target)) {
|
|
23
|
+
return undefined;
|
|
24
|
+
}
|
|
25
|
+
try {
|
|
26
|
+
const val = target[key];
|
|
27
|
+
if (typeof val === "string") {
|
|
28
|
+
return val;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
catch {
|
|
32
|
+
// If a getter throws or proxy traps fail, fail safely
|
|
33
|
+
return undefined;
|
|
34
|
+
}
|
|
35
|
+
return undefined;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Validates the structure and code format of a coded concept.
|
|
39
|
+
*
|
|
40
|
+
* @param concept The input concept object (e.g., { system, code, display? }).
|
|
41
|
+
* @returns ValidationResult with validity flag, issues, and system metadata.
|
|
42
|
+
*/
|
|
43
|
+
export function validate(concept) {
|
|
44
|
+
const issues = [];
|
|
45
|
+
if (!concept || typeof concept !== "object" || Array.isArray(concept)) {
|
|
46
|
+
return {
|
|
47
|
+
valid: false,
|
|
48
|
+
issues: [
|
|
49
|
+
{
|
|
50
|
+
severity: "error",
|
|
51
|
+
path: "",
|
|
52
|
+
code: "invalid-type",
|
|
53
|
+
message: "Coded concept must be a non-null object.",
|
|
54
|
+
},
|
|
55
|
+
],
|
|
56
|
+
providerConfigured: false,
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
const rawSystem = extractString(concept, "system");
|
|
60
|
+
const rawCode = extractString(concept, "code");
|
|
61
|
+
if (rawSystem === undefined || rawSystem.trim().length === 0) {
|
|
62
|
+
issues.push({
|
|
63
|
+
severity: "error",
|
|
64
|
+
path: "system",
|
|
65
|
+
code: "required",
|
|
66
|
+
message: "A string system URI is required.",
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
if (rawCode === undefined || rawCode.trim().length === 0) {
|
|
70
|
+
issues.push({
|
|
71
|
+
severity: "error",
|
|
72
|
+
path: "code",
|
|
73
|
+
code: "required",
|
|
74
|
+
message: "A non-empty code string is required.",
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
if (issues.length > 0) {
|
|
78
|
+
return {
|
|
79
|
+
valid: false,
|
|
80
|
+
issues,
|
|
81
|
+
providerConfigured: false,
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
const systemStr = rawSystem.trim();
|
|
85
|
+
const codeStr = rawCode.trim();
|
|
86
|
+
// Try matching system by URI, shortName, or OID
|
|
87
|
+
const system = getSystemByUri(systemStr) ?? getSystemByIdentifier(systemStr);
|
|
88
|
+
if (!system) {
|
|
89
|
+
issues.push({
|
|
90
|
+
severity: "warning",
|
|
91
|
+
path: "system",
|
|
92
|
+
code: "unknown-system",
|
|
93
|
+
message: `Unknown terminology system: "${systemStr}". Format validation was skipped.`,
|
|
94
|
+
});
|
|
95
|
+
return {
|
|
96
|
+
valid: true,
|
|
97
|
+
issues,
|
|
98
|
+
providerConfigured: false,
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
const validator = formatChecks[system.shortName];
|
|
102
|
+
const isFormatValid = validator ? validator(codeStr) : true;
|
|
103
|
+
if (!isFormatValid) {
|
|
104
|
+
issues.push({
|
|
105
|
+
severity: "error",
|
|
106
|
+
path: "code",
|
|
107
|
+
code: "invalid-format",
|
|
108
|
+
message: `Code "${codeStr}" does not match the structural format for ${system.displayName}.`,
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
return {
|
|
112
|
+
valid: issues.filter((i) => i.severity === "error").length === 0,
|
|
113
|
+
issues,
|
|
114
|
+
system,
|
|
115
|
+
providerConfigured: hasProvider(system.uri),
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Validates format and dispatches to a registered TerminologyProvider if configured.
|
|
120
|
+
*
|
|
121
|
+
* @param concept The input concept object (e.g., { system, code, display? }).
|
|
122
|
+
* @returns Promise<ValidationResult> with format & provider validation results.
|
|
123
|
+
*/
|
|
124
|
+
export async function validateWithProvider(concept) {
|
|
125
|
+
const result = validate(concept);
|
|
126
|
+
if (!result.valid || !result.system || !result.providerConfigured) {
|
|
127
|
+
return result;
|
|
128
|
+
}
|
|
129
|
+
const rawCode = extractString(concept, "code") ?? "";
|
|
130
|
+
const rawDisplay = extractString(concept, "display");
|
|
131
|
+
const codedConcept = {
|
|
132
|
+
system: result.system.uri,
|
|
133
|
+
code: rawCode.trim(),
|
|
134
|
+
display: rawDisplay,
|
|
135
|
+
};
|
|
136
|
+
try {
|
|
137
|
+
const providerResult = await lookup(result.system.uri, codedConcept.code, codedConcept);
|
|
138
|
+
if (providerResult && providerResult.found === false) {
|
|
139
|
+
result.issues.push({
|
|
140
|
+
severity: "warning",
|
|
141
|
+
path: "code",
|
|
142
|
+
code: "provider-not-found",
|
|
143
|
+
message: providerResult.message ??
|
|
144
|
+
`Code "${codedConcept.code}" was not found in the registered ${result.system.displayName} provider.`,
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
catch (error) {
|
|
149
|
+
result.issues.push({
|
|
150
|
+
severity: "warning",
|
|
151
|
+
path: "code",
|
|
152
|
+
code: "provider-failed",
|
|
153
|
+
message: error instanceof Error
|
|
154
|
+
? `Provider error: ${error.message}`
|
|
155
|
+
: "Provider failed during concept lookup. Format validation remains valid.",
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
return result;
|
|
159
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CPT Code Structural Format Validator.
|
|
3
|
+
*
|
|
4
|
+
* ⚠️ LEGAL BOUNDARY NOTICE:
|
|
5
|
+
* This validator checks structural syntax ONLY (5-digit numeric or 4-digit + trailing alpha).
|
|
6
|
+
* This repository contains ZERO real CPT codes, descriptions, or copyrighted AMA material.
|
|
7
|
+
* See docs/LICENSING.md for legal compliance requirements.
|
|
8
|
+
*/
|
|
9
|
+
export declare const isValidCptFormat: (code: string) => boolean;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CPT Code Structural Format Validator.
|
|
3
|
+
*
|
|
4
|
+
* ⚠️ LEGAL BOUNDARY NOTICE:
|
|
5
|
+
* This validator checks structural syntax ONLY (5-digit numeric or 4-digit + trailing alpha).
|
|
6
|
+
* This repository contains ZERO real CPT codes, descriptions, or copyrighted AMA material.
|
|
7
|
+
* See docs/LICENSING.md for legal compliance requirements.
|
|
8
|
+
*/
|
|
9
|
+
export const isValidCptFormat = (code) => {
|
|
10
|
+
if (typeof code !== "string")
|
|
11
|
+
return false;
|
|
12
|
+
const trimmed = code.trim();
|
|
13
|
+
return /^\d{5}$|^\d{4}[A-Za-z]$/.test(trimmed);
|
|
14
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ICD-10-CM Code Format Validator.
|
|
3
|
+
* Standard format: Letter (A-Z) followed by 2 alphanumeric characters,
|
|
4
|
+
* optionally followed by a period and 1-4 alphanumeric characters (e.g. "A00.1", "E11.9", "S82.101A").
|
|
5
|
+
* Public domain specification (CMS / CDC NCHS).
|
|
6
|
+
*/
|
|
7
|
+
export declare const isValidIcd10CmFormat: (code: string) => boolean;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ICD-10-CM Code Format Validator.
|
|
3
|
+
* Standard format: Letter (A-Z) followed by 2 alphanumeric characters,
|
|
4
|
+
* optionally followed by a period and 1-4 alphanumeric characters (e.g. "A00.1", "E11.9", "S82.101A").
|
|
5
|
+
* Public domain specification (CMS / CDC NCHS).
|
|
6
|
+
*/
|
|
7
|
+
export const isValidIcd10CmFormat = (code) => {
|
|
8
|
+
if (typeof code !== "string")
|
|
9
|
+
return false;
|
|
10
|
+
const trimmed = code.trim();
|
|
11
|
+
return /^[A-Za-z][0-9][0-9A-Za-z](?:\.?[0-9A-Za-z]{1,4})?$/.test(trimmed);
|
|
12
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* LOINC Code Format Validator.
|
|
3
|
+
* Standard LOINC format: 1 to 6 digits, hyphen, 1 check-digit (e.g. "8867-4", "100000-1").
|
|
4
|
+
* Sourced from Regenstrief LOINC specifications.
|
|
5
|
+
*/
|
|
6
|
+
export const isValidLoincFormat = (code) => {
|
|
7
|
+
if (typeof code !== "string")
|
|
8
|
+
return false;
|
|
9
|
+
const trimmed = code.trim();
|
|
10
|
+
return /^\d{1,6}-\d$/.test(trimmed);
|
|
11
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* RxNorm Code Structural Format Validator.
|
|
3
|
+
* RxNorm Concept Unique Identifiers (RxCUI) are numeric strings of 1 to 8 digits.
|
|
4
|
+
* Sourced from National Library of Medicine (NLM) specification.
|
|
5
|
+
* Zero proprietary code-to-concept datasets shipped.
|
|
6
|
+
*/
|
|
7
|
+
export declare const isValidRxNormFormat: (code: string) => boolean;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* RxNorm Code Structural Format Validator.
|
|
3
|
+
* RxNorm Concept Unique Identifiers (RxCUI) are numeric strings of 1 to 8 digits.
|
|
4
|
+
* Sourced from National Library of Medicine (NLM) specification.
|
|
5
|
+
* Zero proprietary code-to-concept datasets shipped.
|
|
6
|
+
*/
|
|
7
|
+
export const isValidRxNormFormat = (code) => {
|
|
8
|
+
if (typeof code !== "string")
|
|
9
|
+
return false;
|
|
10
|
+
const trimmed = code.trim();
|
|
11
|
+
return /^\d{1,8}$/.test(trimmed);
|
|
12
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SNOMED CT SCTID Checksum & Format Validator.
|
|
3
|
+
* Implements the Verhoeff check-digit algorithm specified by SNOMED International.
|
|
4
|
+
*
|
|
5
|
+
* ⚠️ LEGAL BOUNDARY NOTICE:
|
|
6
|
+
* This validator checks the structural Verhoeff check-digit ONLY.
|
|
7
|
+
* It contains ZERO proprietary SNOMED concept dictionaries or descriptions.
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* Calculates the Verhoeff check digit for a given numeric SCTID body.
|
|
11
|
+
* @param body Numeric string without the trailing check digit (1 to 17 digits).
|
|
12
|
+
* @returns The single check-digit string, or undefined if input is non-numeric.
|
|
13
|
+
*/
|
|
14
|
+
export declare function calculateSctidCheckDigit(body: string): string | undefined;
|
|
15
|
+
/**
|
|
16
|
+
* Validates whether a full SCTID string is structurally valid with a correct Verhoeff check digit.
|
|
17
|
+
* SNOMED SCTIDs are 6 to 18 digits (or 2 to 18 digits for test vectors).
|
|
18
|
+
*/
|
|
19
|
+
export declare function isValidSctid(sctid: string): boolean;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SNOMED CT SCTID Checksum & Format Validator.
|
|
3
|
+
* Implements the Verhoeff check-digit algorithm specified by SNOMED International.
|
|
4
|
+
*
|
|
5
|
+
* ⚠️ LEGAL BOUNDARY NOTICE:
|
|
6
|
+
* This validator checks the structural Verhoeff check-digit ONLY.
|
|
7
|
+
* It contains ZERO proprietary SNOMED concept dictionaries or descriptions.
|
|
8
|
+
*/
|
|
9
|
+
// Dihedral group D5 multiplication table
|
|
10
|
+
const d = [
|
|
11
|
+
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9],
|
|
12
|
+
[1, 2, 3, 4, 0, 6, 7, 8, 9, 5],
|
|
13
|
+
[2, 3, 4, 0, 1, 7, 8, 9, 5, 6],
|
|
14
|
+
[3, 4, 0, 1, 2, 8, 9, 5, 6, 7],
|
|
15
|
+
[4, 0, 1, 2, 3, 9, 5, 6, 7, 8],
|
|
16
|
+
[5, 9, 8, 7, 6, 0, 4, 3, 2, 1],
|
|
17
|
+
[6, 5, 9, 8, 7, 1, 0, 4, 3, 2],
|
|
18
|
+
[7, 6, 5, 9, 8, 2, 1, 0, 4, 3],
|
|
19
|
+
[8, 7, 6, 5, 9, 3, 2, 1, 0, 4],
|
|
20
|
+
[9, 8, 7, 6, 5, 4, 3, 2, 1, 0],
|
|
21
|
+
];
|
|
22
|
+
// Permutation table
|
|
23
|
+
const p = [
|
|
24
|
+
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9],
|
|
25
|
+
[1, 5, 7, 6, 2, 8, 3, 0, 9, 4],
|
|
26
|
+
[5, 8, 0, 3, 7, 9, 6, 1, 4, 2],
|
|
27
|
+
[8, 9, 1, 6, 0, 4, 3, 5, 2, 7],
|
|
28
|
+
[9, 4, 5, 3, 1, 2, 6, 8, 7, 0],
|
|
29
|
+
[4, 2, 8, 6, 5, 7, 3, 9, 0, 1],
|
|
30
|
+
[2, 7, 9, 3, 8, 0, 6, 4, 1, 5],
|
|
31
|
+
[7, 0, 4, 6, 9, 1, 3, 2, 5, 8],
|
|
32
|
+
];
|
|
33
|
+
// Inverse table
|
|
34
|
+
const inv = [0, 4, 3, 2, 1, 5, 6, 7, 8, 9];
|
|
35
|
+
/**
|
|
36
|
+
* Calculates the Verhoeff check digit for a given numeric SCTID body.
|
|
37
|
+
* @param body Numeric string without the trailing check digit (1 to 17 digits).
|
|
38
|
+
* @returns The single check-digit string, or undefined if input is non-numeric.
|
|
39
|
+
*/
|
|
40
|
+
export function calculateSctidCheckDigit(body) {
|
|
41
|
+
if (typeof body !== "string")
|
|
42
|
+
return undefined;
|
|
43
|
+
const trimmed = body.trim();
|
|
44
|
+
if (!/^\d{1,17}$/.test(trimmed))
|
|
45
|
+
return undefined;
|
|
46
|
+
let c = 0;
|
|
47
|
+
const digits = [...trimmed].reverse();
|
|
48
|
+
for (let i = 0; i < digits.length; i++) {
|
|
49
|
+
const digitVal = Number(digits[i]);
|
|
50
|
+
const permuted = p[(i + 1) % 8][digitVal];
|
|
51
|
+
c = d[c][permuted];
|
|
52
|
+
}
|
|
53
|
+
return String(inv[c]);
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Validates whether a full SCTID string is structurally valid with a correct Verhoeff check digit.
|
|
57
|
+
* SNOMED SCTIDs are 6 to 18 digits (or 2 to 18 digits for test vectors).
|
|
58
|
+
*/
|
|
59
|
+
export function isValidSctid(sctid) {
|
|
60
|
+
if (typeof sctid !== "string")
|
|
61
|
+
return false;
|
|
62
|
+
const trimmed = sctid.trim();
|
|
63
|
+
if (!/^\d{2,18}$/.test(trimmed))
|
|
64
|
+
return false;
|
|
65
|
+
const body = trimmed.slice(0, -1);
|
|
66
|
+
const checkDigit = trimmed.slice(-1);
|
|
67
|
+
return calculateSctidCheckDigit(body) === checkDigit;
|
|
68
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* UCUM (Unified Code for Units of Measure) Syntax Validator.
|
|
3
|
+
* Validates whether a unit string adheres to conservative UCUM lexical syntax.
|
|
4
|
+
* Sourced from the UCUM specification (Regenstrief Institute).
|
|
5
|
+
*/
|
|
6
|
+
export declare const isValidUcumSyntax: (unit: string) => boolean;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* UCUM (Unified Code for Units of Measure) Syntax Validator.
|
|
3
|
+
* Validates whether a unit string adheres to conservative UCUM lexical syntax.
|
|
4
|
+
* Sourced from the UCUM specification (Regenstrief Institute).
|
|
5
|
+
*/
|
|
6
|
+
export const isValidUcumSyntax = (unit) => {
|
|
7
|
+
if (typeof unit !== "string")
|
|
8
|
+
return false;
|
|
9
|
+
const trimmed = unit.trim();
|
|
10
|
+
if (trimmed.length === 0 || trimmed.length > 64)
|
|
11
|
+
return false;
|
|
12
|
+
return /^[A-Za-z0-9\[\]{}().*\/^+\-_%'|]+$/.test(trimmed);
|
|
13
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@peerbits/medical-terminology",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Terminology system-URI registry and code format/checksum validation utilities — ships zero licensed terminology datasets (see docs/LICENSING.md)",
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
|
+
"author": "PeerbitsSolution",
|
|
7
|
+
"homepage": "https://github.com/PeerbitsSolution/medical-terminology#readme",
|
|
8
|
+
"bugs": {
|
|
9
|
+
"url": "https://github.com/PeerbitsSolution/medical-terminology/issues"
|
|
10
|
+
},
|
|
11
|
+
"publishConfig": {
|
|
12
|
+
"access": "public"
|
|
13
|
+
},
|
|
14
|
+
"type": "module",
|
|
15
|
+
"main": "dist/index.js",
|
|
16
|
+
"types": "dist/index.d.ts",
|
|
17
|
+
"exports": {
|
|
18
|
+
".": {
|
|
19
|
+
"types": "./dist/index.d.ts",
|
|
20
|
+
"import": "./dist/index.js"
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
"sideEffects": false,
|
|
24
|
+
"files": [
|
|
25
|
+
"dist"
|
|
26
|
+
],
|
|
27
|
+
"scripts": {
|
|
28
|
+
"build": "tsc -p tsconfig.json",
|
|
29
|
+
"prepublishOnly": "npm run build",
|
|
30
|
+
"lint": "eslint .",
|
|
31
|
+
"typecheck": "tsc --noEmit",
|
|
32
|
+
"test": "vitest run"
|
|
33
|
+
},
|
|
34
|
+
"repository": {
|
|
35
|
+
"type": "git",
|
|
36
|
+
"url": "git+https://github.com/PeerbitsSolution/medical-terminology.git"
|
|
37
|
+
},
|
|
38
|
+
"keywords": [
|
|
39
|
+
"healthcare",
|
|
40
|
+
"fhir",
|
|
41
|
+
"snomed",
|
|
42
|
+
"loinc",
|
|
43
|
+
"icd-10",
|
|
44
|
+
"rxnorm",
|
|
45
|
+
"cpt",
|
|
46
|
+
"ucum",
|
|
47
|
+
"typescript",
|
|
48
|
+
"terminology"
|
|
49
|
+
],
|
|
50
|
+
"devDependencies": {
|
|
51
|
+
"typescript": "^5.5.0",
|
|
52
|
+
"vitest": "^2.0.0",
|
|
53
|
+
"eslint": "^9.0.0",
|
|
54
|
+
"@typescript-eslint/eslint-plugin": "^8.0.0",
|
|
55
|
+
"@typescript-eslint/parser": "^8.0.0"
|
|
56
|
+
},
|
|
57
|
+
"engines": {
|
|
58
|
+
"node": ">=18"
|
|
59
|
+
}
|
|
60
|
+
}
|