ezmedicationinput 0.1.9 → 0.1.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/maps.js CHANGED
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DEFAULT_UNIT_BY_ROUTE = exports.DEFAULT_UNIT_BY_NORMALIZED_FORM = exports.KNOWN_TMT_DOSAGE_FORM_TO_SNOMED_ROUTE = exports.KNOWN_DOSAGE_FORMS_TO_DOSE = exports.WORD_FREQUENCIES = exports.DAY_OF_WEEK_TOKENS = exports.DISCOURAGED_TOKENS = exports.MEAL_KEYWORDS = exports.EVENT_TIMING_TOKENS = exports.TIMING_ABBREVIATIONS = exports.DEFAULT_UNIT_SYNONYMS = exports.HOUSEHOLD_VOLUME_UNITS = exports.DEFAULT_ROUTE_SYNONYMS = exports.ROUTE_BY_SNOMED = exports.ROUTE_TEXT = exports.ROUTE_SNOMED = void 0;
3
+ exports.DEFAULT_UNIT_BY_ROUTE = exports.DEFAULT_UNIT_BY_NORMALIZED_FORM = exports.KNOWN_TMT_DOSAGE_FORM_TO_SNOMED_ROUTE = exports.KNOWN_DOSAGE_FORMS_TO_DOSE = exports.WORD_FREQUENCIES = exports.DAY_OF_WEEK_TOKENS = exports.DISCOURAGED_TOKENS = exports.MEAL_KEYWORDS = exports.EVENT_TIMING_TOKENS = exports.TIMING_ABBREVIATIONS = exports.DEFAULT_UNIT_SYNONYMS = exports.HOUSEHOLD_VOLUME_UNITS = exports.DEFAULT_BODY_SITE_SNOMED = exports.DEFAULT_ROUTE_SYNONYMS = exports.ROUTE_BY_SNOMED = exports.ROUTE_TEXT = exports.ROUTE_SNOMED = void 0;
4
+ exports.normalizeBodySiteKey = normalizeBodySiteKey;
4
5
  const types_1 = require("./types");
5
6
  const object_1 = require("./utils/object");
6
7
  const ROUTE_TEXT_OVERRIDES = {
@@ -60,25 +61,48 @@ exports.DEFAULT_ROUTE_SYNONYMS = (() => {
60
61
  }
61
62
  map[normalized] = { code, text: exports.ROUTE_TEXT[code] };
62
63
  };
64
+ const assignWithAdverb = (key, code) => {
65
+ assign(key, code);
66
+ if (!key)
67
+ return;
68
+ const normalized = key.trim().toLowerCase();
69
+ if (!normalized) {
70
+ return;
71
+ }
72
+ if (!/^[a-z]+$/.test(normalized)) {
73
+ return;
74
+ }
75
+ if (normalized.length < 4 || normalized.endsWith("ly") || normalized.endsWith("eal")) {
76
+ return;
77
+ }
78
+ let adverb;
79
+ if (normalized.endsWith("ic")) {
80
+ adverb = normalized.replace(/ic$/, "ically");
81
+ }
82
+ else {
83
+ adverb = `${normalized}ly`;
84
+ }
85
+ assign(adverb, code);
86
+ };
63
87
  const registerVariants = (value, code) => {
64
88
  if (!value)
65
89
  return;
66
- assign(value, code);
90
+ assignWithAdverb(value, code);
67
91
  const withoutParens = value
68
92
  .replace(/[()]/g, " ")
69
93
  .replace(/\s+/g, " ")
70
94
  .trim();
71
- assign(withoutParens, code);
95
+ assignWithAdverb(withoutParens, code);
72
96
  const withoutCommas = value
73
97
  .replace(/,/g, " ")
74
98
  .replace(/\s+/g, " ")
75
99
  .trim();
76
- assign(withoutCommas, code);
100
+ assignWithAdverb(withoutCommas, code);
77
101
  const withoutPunctuation = value
78
102
  .replace(/[().,-]/g, " ")
79
103
  .replace(/\s+/g, " ")
80
104
  .trim();
81
- assign(withoutPunctuation, code);
105
+ assignWithAdverb(withoutPunctuation, code);
82
106
  };
83
107
  registerVariants("po", types_1.RouteCode["Oral route"]);
84
108
  registerVariants("oral", types_1.RouteCode["Oral route"]);
@@ -140,6 +164,290 @@ exports.DEFAULT_ROUTE_SYNONYMS = (() => {
140
164
  }
141
165
  return map;
142
166
  })();
167
+ /**
168
+ * Normalizes body-site phrases into lookup keys by trimming, lower-casing, and
169
+ * collapsing whitespace. Custom site maps should normalize their keys with the
170
+ * same logic to ensure consistent lookups.
171
+ */
172
+ function normalizeBodySiteKey(value) {
173
+ return value.trim().toLowerCase().replace(/\s+/g, " ");
174
+ }
175
+ const DEFAULT_BODY_SITE_SNOMED_SOURCE = [
176
+ {
177
+ names: ["eye", "eyes"],
178
+ definition: { coding: { code: "81745001", display: "Eye" } }
179
+ },
180
+ {
181
+ names: ["left eye"],
182
+ definition: {
183
+ coding: { code: "1290031003", display: "Structure of left eye proper" }
184
+ }
185
+ },
186
+ {
187
+ names: ["right eye"],
188
+ definition: {
189
+ coding: { code: "1290032005", display: "Structure of right eye proper" }
190
+ }
191
+ },
192
+ {
193
+ names: ["both eyes", "bilateral eyes"],
194
+ definition: { coding: { code: "362508001", display: "Both eyes, entire" } }
195
+ },
196
+ {
197
+ names: ["ear", "ears"],
198
+ definition: { coding: { code: "117590005", display: "Ear-related structure" } }
199
+ },
200
+ {
201
+ names: ["left ear"],
202
+ definition: { coding: { code: "89644007", display: "Left ear" } }
203
+ },
204
+ {
205
+ names: ["right ear"],
206
+ definition: { coding: { code: "25577004", display: "Right ear" } }
207
+ },
208
+ {
209
+ names: ["both ears", "bilateral ears"],
210
+ definition: { coding: { code: "34338003", display: "Both ears" } }
211
+ },
212
+ {
213
+ names: ["nostril", "nostrils"],
214
+ definition: { coding: { code: "1797002", display: "Naris" } }
215
+ },
216
+ {
217
+ names: ["left nostril", "left naris"],
218
+ definition: {
219
+ coding: { code: "723608007", display: "Structure of left anterior naris" }
220
+ }
221
+ },
222
+ {
223
+ names: ["right nostril", "right naris"],
224
+ definition: {
225
+ coding: { code: "723609004", display: "Structure of right anterior naris" }
226
+ }
227
+ },
228
+ {
229
+ names: ["nares", "anterior nares"],
230
+ definition: { coding: { code: "244506005", display: "Anterior nares" } }
231
+ },
232
+ {
233
+ names: ["nose"],
234
+ definition: { coding: { code: "181195007", display: "Entire nose" } }
235
+ },
236
+ {
237
+ names: ["mouth"],
238
+ definition: { coding: { code: "123851003", display: "Mouth region" } }
239
+ },
240
+ {
241
+ names: ["tongue", "tongues"],
242
+ definition: { coding: { code: "21974007", display: "Tongue" } }
243
+ },
244
+ {
245
+ names: ["cheek", "cheeks"],
246
+ definition: {
247
+ coding: { code: "60819002", display: "Buccal region of face" }
248
+ }
249
+ },
250
+ {
251
+ names: ["gum", "gums"],
252
+ definition: {
253
+ coding: {
254
+ code: "362116001",
255
+ display: "Entire gum and supporting structure of tooth"
256
+ }
257
+ }
258
+ },
259
+ {
260
+ names: ["tooth"],
261
+ definition: { coding: { code: "38199008", display: "Tooth" } }
262
+ },
263
+ {
264
+ names: ["teeth"],
265
+ definition: { coding: { code: "1162715001", display: "All teeth" } }
266
+ },
267
+ {
268
+ names: ["arm", "upper arm"],
269
+ definition: { coding: { code: "302538001", display: "Entire upper arm" } }
270
+ },
271
+ {
272
+ names: ["left arm", "left upper arm"],
273
+ definition: {
274
+ coding: { code: "368208006", display: "Left upper arm structure" }
275
+ }
276
+ },
277
+ {
278
+ names: ["right arm", "right upper arm"],
279
+ definition: { coding: { code: "368209003", display: "Right upper arm" } }
280
+ },
281
+ {
282
+ names: ["both arms", "bilateral arms"],
283
+ definition: { coding: { code: "69273007", display: "Both arms" } }
284
+ },
285
+ {
286
+ names: ["forearm"],
287
+ definition: { coding: { code: "14975008", display: "Forearm" } }
288
+ },
289
+ {
290
+ names: ["left forearm"],
291
+ definition: { coding: { code: "66480008", display: "Left forearm" } }
292
+ },
293
+ {
294
+ names: ["right forearm"],
295
+ definition: { coding: { code: "64262003", display: "Right forearm" } }
296
+ },
297
+ {
298
+ names: ["leg", "lower leg"],
299
+ definition: {
300
+ coding: { code: "362793004", display: "Entire lower leg, from knee to ankle" }
301
+ }
302
+ },
303
+ {
304
+ names: ["left leg", "left lower leg"],
305
+ definition: { coding: { code: "213384005", display: "Entire left lower leg" } }
306
+ },
307
+ {
308
+ names: ["right leg", "right lower leg"],
309
+ definition: { coding: { code: "213289002", display: "Entire right lower leg" } }
310
+ },
311
+ {
312
+ names: ["both legs", "bilateral legs"],
313
+ definition: { coding: { code: "40927001", display: "Both legs" } }
314
+ },
315
+ {
316
+ names: ["thigh"],
317
+ definition: { coding: { code: "68367000", display: "Thigh" } }
318
+ },
319
+ {
320
+ names: ["left thigh"],
321
+ definition: { coding: { code: "61396006", display: "Left thigh" } }
322
+ },
323
+ {
324
+ names: ["right thigh"],
325
+ definition: { coding: { code: "11207009", display: "Right thigh" } }
326
+ },
327
+ {
328
+ names: ["hand", "hands"],
329
+ definition: { coding: { code: "85562004", display: "Hand" } }
330
+ },
331
+ {
332
+ names: ["left hand"],
333
+ definition: { coding: { code: "85151006", display: "Left hand" } }
334
+ },
335
+ {
336
+ names: ["right hand"],
337
+ definition: { coding: { code: "78791008", display: "Right hand" } }
338
+ },
339
+ {
340
+ names: ["foot", "feet"],
341
+ definition: { coding: { code: "56459004", display: "Foot" } }
342
+ },
343
+ {
344
+ names: ["left foot"],
345
+ definition: { coding: { code: "22335008", display: "Left foot" } }
346
+ },
347
+ {
348
+ names: ["right foot"],
349
+ definition: { coding: { code: "7769000", display: "Right foot" } }
350
+ },
351
+ {
352
+ names: ["abdomen", "abdominal", "belly"],
353
+ definition: { coding: { code: "302553009", display: "Entire abdomen" } }
354
+ },
355
+ {
356
+ names: ["back"],
357
+ definition: { coding: { code: "77568009", display: "Back" } }
358
+ },
359
+ {
360
+ names: ["scalp"],
361
+ definition: { coding: { code: "41695006", display: "Scalp" } }
362
+ },
363
+ {
364
+ names: ["face"],
365
+ definition: { coding: { code: "89545001", display: "Face" } }
366
+ },
367
+ {
368
+ names: ["forehead"],
369
+ definition: { coding: { code: "52795006", display: "Forehead" } }
370
+ },
371
+ {
372
+ names: ["chin"],
373
+ definition: {
374
+ coding: {
375
+ code: "897081006",
376
+ display: "Skin and/or subcutaneous tissue of chin"
377
+ }
378
+ }
379
+ },
380
+ {
381
+ names: ["neck"],
382
+ definition: { coding: { code: "45048000", display: "Neck" } }
383
+ },
384
+ {
385
+ names: ["buttock", "buttocks", "gluteal", "glute"],
386
+ definition: { coding: { code: "46862004", display: "Buttock" } }
387
+ },
388
+ {
389
+ names: ["left buttock", "left gluteal"],
390
+ definition: { coding: { code: "723979003", display: "Structure of left buttock" } }
391
+ },
392
+ {
393
+ names: ["right buttock", "right gluteal"],
394
+ definition: { coding: { code: "723980000", display: "Structure of right buttock" } }
395
+ },
396
+ {
397
+ names: ["muscle", "muscles"],
398
+ definition: {
399
+ coding: {
400
+ code: "362876008",
401
+ display: "All skeletal and smooth muscles of the body"
402
+ }
403
+ }
404
+ },
405
+ {
406
+ names: ["vein", "veins"],
407
+ definition: { coding: { code: "181367001", display: "Entire vein" } }
408
+ },
409
+ {
410
+ names: ["vagina", "vaginal"],
411
+ definition: { coding: { code: "76784001", display: "Vagina" } }
412
+ },
413
+ {
414
+ names: ["penis", "penile"],
415
+ definition: { coding: { code: "18911002", display: "Penis structure" } }
416
+ },
417
+ {
418
+ names: ["rectum", "rectal"],
419
+ definition: { coding: { code: "34402009", display: "Rectum" } }
420
+ },
421
+ {
422
+ names: ["anus"],
423
+ definition: { coding: { code: "181262009", display: "Entire anus" } }
424
+ },
425
+ {
426
+ names: ["perineum"],
427
+ definition: { coding: { code: "243990009", display: "Entire perineum" } }
428
+ },
429
+ {
430
+ names: ["skin"],
431
+ definition: { coding: { code: "181469002", display: "Entire skin" } }
432
+ },
433
+ {
434
+ names: ["hair"],
435
+ definition: {
436
+ coding: { code: "386045008", display: "Hair structure (body structure)" }
437
+ }
438
+ }
439
+ ];
440
+ exports.DEFAULT_BODY_SITE_SNOMED = (0, object_1.objectFromEntries)(DEFAULT_BODY_SITE_SNOMED_SOURCE.reduce((entries, source) => {
441
+ const { names, definition } = source;
442
+ for (const name of names) {
443
+ const key = normalizeBodySiteKey(name);
444
+ if (!key) {
445
+ continue;
446
+ }
447
+ entries.push([key, definition]);
448
+ }
449
+ return entries;
450
+ }, []));
143
451
  const UNIT_PREFIXES = [
144
452
  { canonical: "", abbreviations: [""], names: [{ singular: "", plural: "" }] },
145
453
  {
package/dist/parser.d.ts CHANGED
@@ -2,3 +2,13 @@ import { ParsedSigInternal, Token } from "./internal-types";
2
2
  import { ParseOptions } from "./types";
3
3
  export declare function tokenize(input: string): Token[];
4
4
  export declare function parseInternal(input: string, options?: ParseOptions): ParsedSigInternal;
5
+ /**
6
+ * Resolves parsed site text against SNOMED dictionaries and synchronous
7
+ * callbacks, applying the best match to the in-progress parse result.
8
+ */
9
+ export declare function applySiteCoding(internal: ParsedSigInternal, options?: ParseOptions): void;
10
+ /**
11
+ * Asynchronous counterpart to {@link applySiteCoding} that awaits resolver and
12
+ * suggestion callbacks so remote terminology services can be used.
13
+ */
14
+ export declare function applySiteCodingAsync(internal: ParsedSigInternal, options?: ParseOptions): Promise<void>;