ezmedicationinput 0.1.29 → 0.1.30
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/fhir.js +19 -12
- package/dist/maps.d.ts +8 -0
- package/dist/maps.js +16 -0
- package/dist/parser.js +13 -4
- package/package.json +1 -1
package/dist/fhir.js
CHANGED
|
@@ -162,7 +162,7 @@ function toFhir(internal) {
|
|
|
162
162
|
return dosage;
|
|
163
163
|
}
|
|
164
164
|
function internalFromFhir(dosage) {
|
|
165
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13;
|
|
165
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14;
|
|
166
166
|
const internal = {
|
|
167
167
|
input: (_a = dosage.text) !== null && _a !== void 0 ? _a : "",
|
|
168
168
|
tokens: [],
|
|
@@ -212,34 +212,41 @@ function internalFromFhir(dosage) {
|
|
|
212
212
|
}
|
|
213
213
|
const reasonCoding = (_9 = (_8 = (_7 = dosage.asNeededFor) === null || _7 === void 0 ? void 0 : _7[0]) === null || _8 === void 0 ? void 0 : _8.coding) === null || _9 === void 0 ? void 0 : _9[0];
|
|
214
214
|
if (reasonCoding === null || reasonCoding === void 0 ? void 0 : reasonCoding.code) {
|
|
215
|
+
const defaultDef = (0, maps_1.findPrnReasonDefinitionByCoding)((_10 = reasonCoding.system) !== null && _10 !== void 0 ? _10 : SNOMED_SYSTEM, reasonCoding.code);
|
|
215
216
|
internal.asNeededReasonCoding = {
|
|
216
217
|
code: reasonCoding.code,
|
|
217
218
|
display: reasonCoding.display,
|
|
218
|
-
system: reasonCoding.system
|
|
219
|
+
system: reasonCoding.system,
|
|
220
|
+
i18n: defaultDef === null || defaultDef === void 0 ? void 0 : defaultDef.i18n
|
|
219
221
|
};
|
|
220
222
|
}
|
|
221
|
-
if ((
|
|
223
|
+
if ((_11 = dosage.additionalInstruction) === null || _11 === void 0 ? void 0 : _11.length) {
|
|
222
224
|
internal.additionalInstructions = dosage.additionalInstruction.map((concept) => {
|
|
223
|
-
var _a;
|
|
224
|
-
|
|
225
|
+
var _a, _b;
|
|
226
|
+
const coding = (_a = concept.coding) === null || _a === void 0 ? void 0 : _a[0];
|
|
227
|
+
const defaultDef = (coding === null || coding === void 0 ? void 0 : coding.code)
|
|
228
|
+
? (0, maps_1.findAdditionalInstructionDefinitionByCoding)((_b = coding.system) !== null && _b !== void 0 ? _b : SNOMED_SYSTEM, coding.code)
|
|
229
|
+
: undefined;
|
|
230
|
+
return {
|
|
225
231
|
text: concept.text,
|
|
226
|
-
coding: (
|
|
232
|
+
coding: (coding === null || coding === void 0 ? void 0 : coding.code)
|
|
227
233
|
? {
|
|
228
|
-
code:
|
|
229
|
-
display:
|
|
230
|
-
system:
|
|
234
|
+
code: coding.code,
|
|
235
|
+
display: coding.display,
|
|
236
|
+
system: coding.system,
|
|
237
|
+
i18n: defaultDef === null || defaultDef === void 0 ? void 0 : defaultDef.i18n
|
|
231
238
|
}
|
|
232
239
|
: undefined
|
|
233
|
-
}
|
|
240
|
+
};
|
|
234
241
|
});
|
|
235
242
|
}
|
|
236
|
-
const doseAndRate = (
|
|
243
|
+
const doseAndRate = (_12 = dosage.doseAndRate) === null || _12 === void 0 ? void 0 : _12[0];
|
|
237
244
|
if (doseAndRate === null || doseAndRate === void 0 ? void 0 : doseAndRate.doseRange) {
|
|
238
245
|
const { low, high } = doseAndRate.doseRange;
|
|
239
246
|
if ((low === null || low === void 0 ? void 0 : low.value) !== undefined && (high === null || high === void 0 ? void 0 : high.value) !== undefined) {
|
|
240
247
|
internal.doseRange = { low: low.value, high: high.value };
|
|
241
248
|
}
|
|
242
|
-
internal.unit = (
|
|
249
|
+
internal.unit = (_14 = (_13 = low === null || low === void 0 ? void 0 : low.unit) !== null && _13 !== void 0 ? _13 : high === null || high === void 0 ? void 0 : high.unit) !== null && _14 !== void 0 ? _14 : internal.unit;
|
|
243
250
|
}
|
|
244
251
|
else if (doseAndRate === null || doseAndRate === void 0 ? void 0 : doseAndRate.doseQuantity) {
|
|
245
252
|
const dose = doseAndRate.doseQuantity;
|
package/dist/maps.d.ts
CHANGED
|
@@ -74,3 +74,11 @@ export interface AdditionalInstructionDictionaryEntry {
|
|
|
74
74
|
}
|
|
75
75
|
export declare const DEFAULT_ADDITIONAL_INSTRUCTION_ENTRIES: AdditionalInstructionDictionaryEntry[];
|
|
76
76
|
export declare const DEFAULT_ADDITIONAL_INSTRUCTION_DEFINITIONS: Record<string, AdditionalInstructionDefinition>;
|
|
77
|
+
/**
|
|
78
|
+
* Finds a default PRN reason definition by its SNOMED coding.
|
|
79
|
+
*/
|
|
80
|
+
export declare function findPrnReasonDefinitionByCoding(system: string, code: string): PrnReasonDefinition | undefined;
|
|
81
|
+
/**
|
|
82
|
+
* Finds a default additional instruction definition by its SNOMED coding.
|
|
83
|
+
*/
|
|
84
|
+
export declare function findAdditionalInstructionDefinitionByCoding(system: string, code: string): AdditionalInstructionDefinition | undefined;
|
package/dist/maps.js
CHANGED
|
@@ -4,6 +4,8 @@ exports.DEFAULT_ADDITIONAL_INSTRUCTION_DEFINITIONS = exports.DEFAULT_ADDITIONAL_
|
|
|
4
4
|
exports.normalizeBodySiteKey = normalizeBodySiteKey;
|
|
5
5
|
exports.normalizePrnReasonKey = normalizePrnReasonKey;
|
|
6
6
|
exports.normalizeAdditionalInstructionKey = normalizeAdditionalInstructionKey;
|
|
7
|
+
exports.findPrnReasonDefinitionByCoding = findPrnReasonDefinitionByCoding;
|
|
8
|
+
exports.findAdditionalInstructionDefinitionByCoding = findAdditionalInstructionDefinitionByCoding;
|
|
7
9
|
const types_1 = require("./types");
|
|
8
10
|
const object_1 = require("./utils/object");
|
|
9
11
|
const SNOMED_SYSTEM = "http://snomed.info/sct";
|
|
@@ -1611,3 +1613,17 @@ exports.DEFAULT_ADDITIONAL_INSTRUCTION_DEFINITIONS = (0, object_1.objectFromEntr
|
|
|
1611
1613
|
}
|
|
1612
1614
|
return entries;
|
|
1613
1615
|
}, []));
|
|
1616
|
+
/**
|
|
1617
|
+
* Finds a default PRN reason definition by its SNOMED coding.
|
|
1618
|
+
*/
|
|
1619
|
+
function findPrnReasonDefinitionByCoding(system, code) {
|
|
1620
|
+
var _a;
|
|
1621
|
+
return (_a = DEFAULT_PRN_REASON_SOURCE.find((source) => { var _a, _b; return ((_a = source.definition.coding) === null || _a === void 0 ? void 0 : _a.system) === system && ((_b = source.definition.coding) === null || _b === void 0 ? void 0 : _b.code) === code; })) === null || _a === void 0 ? void 0 : _a.definition;
|
|
1622
|
+
}
|
|
1623
|
+
/**
|
|
1624
|
+
* Finds a default additional instruction definition by its SNOMED coding.
|
|
1625
|
+
*/
|
|
1626
|
+
function findAdditionalInstructionDefinitionByCoding(system, code) {
|
|
1627
|
+
var _a;
|
|
1628
|
+
return (_a = DEFAULT_ADDITIONAL_INSTRUCTION_SOURCE.find((source) => { var _a, _b; return ((_a = source.definition.coding) === null || _a === void 0 ? void 0 : _a.system) === system && ((_b = source.definition.coding) === null || _b === void 0 ? void 0 : _b.code) === code; })) === null || _a === void 0 ? void 0 : _a.definition;
|
|
1629
|
+
}
|
package/dist/parser.js
CHANGED
|
@@ -3126,7 +3126,7 @@ function collectAdditionalInstructions(internal, tokens) {
|
|
|
3126
3126
|
if (/\s/.test(ch)) {
|
|
3127
3127
|
continue;
|
|
3128
3128
|
}
|
|
3129
|
-
if (
|
|
3129
|
+
if (/-|;|:|\.|\,/.test(ch)) {
|
|
3130
3130
|
separatorDetected = true;
|
|
3131
3131
|
}
|
|
3132
3132
|
break;
|
|
@@ -3135,9 +3135,6 @@ function collectAdditionalInstructions(internal, tokens) {
|
|
|
3135
3135
|
const sourceText = range
|
|
3136
3136
|
? internal.input.slice(range.start, range.end)
|
|
3137
3137
|
: joined;
|
|
3138
|
-
if (!separatorDetected && !/[-;:.]/.test(sourceText)) {
|
|
3139
|
-
return;
|
|
3140
|
-
}
|
|
3141
3138
|
const normalized = sourceText
|
|
3142
3139
|
.replace(/\s*[-:]+\s*/g, "; ")
|
|
3143
3140
|
.replace(/\s*(?:\r?\n)+\s*/g, "; ")
|
|
@@ -3146,6 +3143,18 @@ function collectAdditionalInstructions(internal, tokens) {
|
|
|
3146
3143
|
.split(/(?:;|\.)/)
|
|
3147
3144
|
.map((segment) => segment.trim())
|
|
3148
3145
|
.filter((segment) => segment.length > 0);
|
|
3146
|
+
// If no punctuation was detected, we only collect if at least one segment matches a known definition.
|
|
3147
|
+
// This avoids capturing random trailing text as instructions unless it's codified.
|
|
3148
|
+
if (!separatorDetected && !/[-;:.]/.test(sourceText)) {
|
|
3149
|
+
const hasKnownDefinition = segments.some((phrase) => {
|
|
3150
|
+
const canonical = (0, maps_1.normalizeAdditionalInstructionKey)(phrase);
|
|
3151
|
+
return (maps_1.DEFAULT_ADDITIONAL_INSTRUCTION_DEFINITIONS[canonical] ||
|
|
3152
|
+
findAdditionalInstructionDefinition(phrase, canonical));
|
|
3153
|
+
});
|
|
3154
|
+
if (!hasKnownDefinition) {
|
|
3155
|
+
return;
|
|
3156
|
+
}
|
|
3157
|
+
}
|
|
3149
3158
|
const phrases = segments.length ? segments : [joined];
|
|
3150
3159
|
const seen = new Set();
|
|
3151
3160
|
const instructions = [];
|