ezmedicationinput 0.1.43 → 0.1.45

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 DELETED
@@ -1,261 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.toFhir = toFhir;
4
- exports.internalFromFhir = internalFromFhir;
5
- const format_1 = require("./format");
6
- const maps_1 = require("./maps");
7
- const types_1 = require("./types");
8
- const object_1 = require("./utils/object");
9
- const array_1 = require("./utils/array");
10
- const SNOMED_SYSTEM = "http://snomed.info/sct";
11
- function toFhir(internal) {
12
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
13
- const dosage = {};
14
- const repeat = {};
15
- let hasRepeat = false;
16
- if (internal.frequency !== undefined) {
17
- repeat.frequency = internal.frequency;
18
- hasRepeat = true;
19
- }
20
- if (internal.count !== undefined) {
21
- repeat.count = internal.count;
22
- hasRepeat = true;
23
- }
24
- if (internal.frequencyMax !== undefined) {
25
- repeat.frequencyMax = internal.frequencyMax;
26
- hasRepeat = true;
27
- }
28
- if (internal.period !== undefined && internal.periodUnit) {
29
- repeat.period = internal.period;
30
- repeat.periodUnit = internal.periodUnit;
31
- hasRepeat = true;
32
- }
33
- if (internal.periodMax !== undefined) {
34
- repeat.periodMax = internal.periodMax;
35
- hasRepeat = true;
36
- }
37
- if (internal.dayOfWeek.length) {
38
- repeat.dayOfWeek = [...internal.dayOfWeek];
39
- hasRepeat = true;
40
- }
41
- if (internal.when.length) {
42
- repeat.when = [...internal.when];
43
- hasRepeat = true;
44
- }
45
- if ((_a = internal.timeOfDay) === null || _a === void 0 ? void 0 : _a.length) {
46
- repeat.timeOfDay = [...internal.timeOfDay];
47
- hasRepeat = true;
48
- }
49
- if (hasRepeat) {
50
- dosage.timing = { repeat };
51
- }
52
- else {
53
- dosage.timing = {};
54
- }
55
- if (internal.timingCode) {
56
- dosage.timing = (_b = dosage.timing) !== null && _b !== void 0 ? _b : {};
57
- dosage.timing.code = {
58
- coding: [{ code: internal.timingCode }],
59
- text: internal.timingCode
60
- };
61
- }
62
- if (internal.doseRange) {
63
- dosage.doseAndRate = [
64
- {
65
- doseRange: {
66
- low: internal.doseRange.low !== undefined
67
- ? { value: internal.doseRange.low, unit: internal.unit }
68
- : undefined,
69
- high: internal.doseRange.high !== undefined
70
- ? { value: internal.doseRange.high, unit: internal.unit }
71
- : undefined
72
- }
73
- }
74
- ];
75
- }
76
- else if (internal.dose !== undefined) {
77
- dosage.doseAndRate = [
78
- {
79
- doseQuantity: {
80
- value: internal.dose,
81
- unit: internal.unit
82
- }
83
- }
84
- ];
85
- }
86
- // Emit SNOMED-coded routes whenever we have parsed or inferred route data.
87
- if (internal.routeCode || internal.routeText) {
88
- const coding = internal.routeCode ? maps_1.ROUTE_SNOMED[internal.routeCode] : undefined;
89
- const text = (_c = internal.routeText) !== null && _c !== void 0 ? _c : (internal.routeCode ? maps_1.ROUTE_TEXT[internal.routeCode] : undefined);
90
- if (coding) {
91
- // Provide both text and coding so human-readable and coded systems align.
92
- dosage.route = {
93
- text,
94
- coding: [
95
- {
96
- system: SNOMED_SYSTEM,
97
- code: coding.code,
98
- display: coding.display
99
- }
100
- ]
101
- };
102
- }
103
- else if (text) {
104
- dosage.route = { text };
105
- }
106
- }
107
- if (internal.siteText || ((_d = internal.siteCoding) === null || _d === void 0 ? void 0 : _d.code)) {
108
- const coding = ((_e = internal.siteCoding) === null || _e === void 0 ? void 0 : _e.code)
109
- ? [
110
- {
111
- system: (_f = internal.siteCoding.system) !== null && _f !== void 0 ? _f : SNOMED_SYSTEM,
112
- code: internal.siteCoding.code,
113
- display: internal.siteCoding.display
114
- }
115
- ]
116
- : undefined;
117
- dosage.site = {
118
- text: internal.siteText,
119
- coding
120
- };
121
- }
122
- if ((_g = internal.additionalInstructions) === null || _g === void 0 ? void 0 : _g.length) {
123
- dosage.additionalInstruction = internal.additionalInstructions.map((instruction) => {
124
- var _a, _b;
125
- return ({
126
- text: instruction.text,
127
- coding: ((_a = instruction.coding) === null || _a === void 0 ? void 0 : _a.code)
128
- ? [
129
- {
130
- system: (_b = instruction.coding.system) !== null && _b !== void 0 ? _b : SNOMED_SYSTEM,
131
- code: instruction.coding.code,
132
- display: instruction.coding.display
133
- }
134
- ]
135
- : undefined
136
- });
137
- });
138
- }
139
- if (internal.asNeeded) {
140
- dosage.asNeededBoolean = true;
141
- if (internal.asNeededReason || ((_h = internal.asNeededReasonCoding) === null || _h === void 0 ? void 0 : _h.code)) {
142
- const concept = {};
143
- if (internal.asNeededReason) {
144
- concept.text = internal.asNeededReason;
145
- }
146
- if ((_j = internal.asNeededReasonCoding) === null || _j === void 0 ? void 0 : _j.code) {
147
- concept.coding = [
148
- {
149
- system: (_k = internal.asNeededReasonCoding.system) !== null && _k !== void 0 ? _k : SNOMED_SYSTEM,
150
- code: internal.asNeededReasonCoding.code,
151
- display: internal.asNeededReasonCoding.display
152
- }
153
- ];
154
- }
155
- dosage.asNeededFor = [concept];
156
- }
157
- }
158
- const longText = (0, format_1.formatInternal)(internal, "long");
159
- if (longText) {
160
- dosage.text = longText;
161
- }
162
- return dosage;
163
- }
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, _14;
166
- const internal = {
167
- input: (_a = dosage.text) !== null && _a !== void 0 ? _a : "",
168
- tokens: [],
169
- consumed: new Set(),
170
- dayOfWeek: ((_c = (_b = dosage.timing) === null || _b === void 0 ? void 0 : _b.repeat) === null || _c === void 0 ? void 0 : _c.dayOfWeek)
171
- ? [...dosage.timing.repeat.dayOfWeek]
172
- : [],
173
- when: ((_e = (_d = dosage.timing) === null || _d === void 0 ? void 0 : _d.repeat) === null || _e === void 0 ? void 0 : _e.when)
174
- ? dosage.timing.repeat.when.filter((value) => (0, array_1.arrayIncludes)((0, object_1.objectValues)(types_1.EventTiming), value))
175
- : [],
176
- timeOfDay: ((_g = (_f = dosage.timing) === null || _f === void 0 ? void 0 : _f.repeat) === null || _g === void 0 ? void 0 : _g.timeOfDay)
177
- ? [...dosage.timing.repeat.timeOfDay]
178
- : [],
179
- warnings: [],
180
- timingCode: (_l = (_k = (_j = (_h = dosage.timing) === null || _h === void 0 ? void 0 : _h.code) === null || _j === void 0 ? void 0 : _j.coding) === null || _k === void 0 ? void 0 : _k[0]) === null || _l === void 0 ? void 0 : _l.code,
181
- count: (_o = (_m = dosage.timing) === null || _m === void 0 ? void 0 : _m.repeat) === null || _o === void 0 ? void 0 : _o.count,
182
- frequency: (_q = (_p = dosage.timing) === null || _p === void 0 ? void 0 : _p.repeat) === null || _q === void 0 ? void 0 : _q.frequency,
183
- frequencyMax: (_s = (_r = dosage.timing) === null || _r === void 0 ? void 0 : _r.repeat) === null || _s === void 0 ? void 0 : _s.frequencyMax,
184
- period: (_u = (_t = dosage.timing) === null || _t === void 0 ? void 0 : _t.repeat) === null || _u === void 0 ? void 0 : _u.period,
185
- periodMax: (_w = (_v = dosage.timing) === null || _v === void 0 ? void 0 : _v.repeat) === null || _w === void 0 ? void 0 : _w.periodMax,
186
- periodUnit: (_y = (_x = dosage.timing) === null || _x === void 0 ? void 0 : _x.repeat) === null || _y === void 0 ? void 0 : _y.periodUnit,
187
- routeText: (_z = dosage.route) === null || _z === void 0 ? void 0 : _z.text,
188
- siteText: (_0 = dosage.site) === null || _0 === void 0 ? void 0 : _0.text,
189
- asNeeded: dosage.asNeededBoolean,
190
- asNeededReason: (_2 = (_1 = dosage.asNeededFor) === null || _1 === void 0 ? void 0 : _1[0]) === null || _2 === void 0 ? void 0 : _2.text,
191
- siteTokenIndices: new Set(),
192
- siteLookups: [],
193
- prnReasonLookups: [],
194
- additionalInstructions: []
195
- };
196
- const routeCoding = (_4 = (_3 = dosage.route) === null || _3 === void 0 ? void 0 : _3.coding) === null || _4 === void 0 ? void 0 : _4.find((code) => code.system === SNOMED_SYSTEM);
197
- if (routeCoding === null || routeCoding === void 0 ? void 0 : routeCoding.code) {
198
- // Translate SNOMED codings back into the simplified enum for round-trip fidelity.
199
- const mapped = maps_1.ROUTE_BY_SNOMED[routeCoding.code];
200
- if (mapped) {
201
- internal.routeCode = mapped;
202
- internal.routeText = maps_1.ROUTE_TEXT[mapped];
203
- }
204
- }
205
- const siteCoding = (_6 = (_5 = dosage.site) === null || _5 === void 0 ? void 0 : _5.coding) === null || _6 === void 0 ? void 0 : _6.find((code) => code.system === SNOMED_SYSTEM);
206
- if (siteCoding === null || siteCoding === void 0 ? void 0 : siteCoding.code) {
207
- internal.siteCoding = {
208
- code: siteCoding.code,
209
- display: siteCoding.display,
210
- system: siteCoding.system
211
- };
212
- }
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
- 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);
216
- internal.asNeededReasonCoding = {
217
- code: reasonCoding.code,
218
- display: reasonCoding.display,
219
- system: reasonCoding.system,
220
- i18n: defaultDef === null || defaultDef === void 0 ? void 0 : defaultDef.i18n
221
- };
222
- }
223
- if ((_11 = dosage.additionalInstruction) === null || _11 === void 0 ? void 0 : _11.length) {
224
- internal.additionalInstructions = dosage.additionalInstruction.map((concept) => {
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 {
231
- text: concept.text,
232
- coding: (coding === null || coding === void 0 ? void 0 : coding.code)
233
- ? {
234
- code: coding.code,
235
- display: coding.display,
236
- system: coding.system,
237
- i18n: defaultDef === null || defaultDef === void 0 ? void 0 : defaultDef.i18n
238
- }
239
- : undefined
240
- };
241
- });
242
- }
243
- const doseAndRate = (_12 = dosage.doseAndRate) === null || _12 === void 0 ? void 0 : _12[0];
244
- if (doseAndRate === null || doseAndRate === void 0 ? void 0 : doseAndRate.doseRange) {
245
- const { low, high } = doseAndRate.doseRange;
246
- if ((low === null || low === void 0 ? void 0 : low.value) !== undefined && (high === null || high === void 0 ? void 0 : high.value) !== undefined) {
247
- internal.doseRange = { low: low.value, high: high.value };
248
- }
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;
250
- }
251
- else if (doseAndRate === null || doseAndRate === void 0 ? void 0 : doseAndRate.doseQuantity) {
252
- const dose = doseAndRate.doseQuantity;
253
- if (dose.value !== undefined) {
254
- internal.dose = dose.value;
255
- }
256
- if (dose.unit) {
257
- internal.unit = dose.unit;
258
- }
259
- }
260
- return internal;
261
- }