ezmedicationinput 0.1.6 → 0.1.7

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.
Files changed (2) hide show
  1. package/dist/suggest.js +83 -70
  2. package/package.json +1 -1
package/dist/suggest.js CHANGED
@@ -105,6 +105,7 @@ const WHEN_COMBINATIONS = [
105
105
  ].filter((token) => maps_1.EVENT_TIMING_TOKENS[token] !== undefined);
106
106
  const CORE_WHEN_TOKENS = ["pc", "ac", "hs"].filter((token) => maps_1.EVENT_TIMING_TOKENS[token] !== undefined);
107
107
  const FREQUENCY_CODES = ["qd", "od", "bid", "tid", "qid"].filter((token) => maps_1.TIMING_ABBREVIATIONS[token] !== undefined);
108
+ const FREQUENCY_CODE_SUFFIXES = FREQUENCY_CODES.map((code) => ` ${code}`);
108
109
  const FREQ_TOKEN_BY_NUMBER = {};
109
110
  for (const [frequency, token] of [
110
111
  [1, "qd"],
@@ -235,10 +236,15 @@ function removeDashes(value) {
235
236
  }
236
237
  return result.join("");
237
238
  }
239
+ const UNIT_VARIANT_CACHE = new Map();
238
240
  function getUnitVariants(unit) {
239
241
  var _a;
240
242
  const canonical = (_a = resolveCanonicalUnit(unit)) !== null && _a !== void 0 ? _a : normalizeSpacing(unit);
241
243
  const normalizedCanonical = normalizeKey(canonical);
244
+ const cached = UNIT_VARIANT_CACHE.get(normalizedCanonical);
245
+ if (cached) {
246
+ return cached;
247
+ }
242
248
  const variants = new Map();
243
249
  const push = (candidate) => {
244
250
  if (!candidate) {
@@ -262,7 +268,9 @@ function getUnitVariants(unit) {
262
268
  push(candidate);
263
269
  }
264
270
  }
265
- return [...variants.values()];
271
+ const result = [...variants.values()];
272
+ UNIT_VARIANT_CACHE.set(normalizedCanonical, result);
273
+ return result;
266
274
  }
267
275
  function buildIntervalTokens(input) {
268
276
  const intervals = new Set();
@@ -322,6 +330,7 @@ function buildWhenSequences() {
322
330
  return sequences;
323
331
  }
324
332
  const PRECOMPUTED_WHEN_SEQUENCES = buildWhenSequences();
333
+ const PRECOMPUTED_WHEN_SEQUENCE_SUFFIXES = PRECOMPUTED_WHEN_SEQUENCES.map((sequence) => ` ${sequence.join(" ")}`);
325
334
  function tokenizeLowercaseForMatching(value) {
326
335
  return value
327
336
  .split(/\s+/)
@@ -481,117 +490,121 @@ function generateCandidateDirections(pairs, doseValues, prnReasons, intervalToke
481
490
  suggestions.push(value);
482
491
  return suggestions.length >= limit;
483
492
  };
484
- for (const pair of pairs) {
493
+ const codeSuffixes = FREQUENCY_CODE_SUFFIXES;
494
+ const prnSuffixes = new Array(prnReasons.length);
495
+ for (let i = 0; i < prnReasons.length; i += 1) {
496
+ prnSuffixes[i] = ` prn ${prnReasons[i]}`;
497
+ }
498
+ const intervalSuffixes = new Array(intervalTokens.length);
499
+ for (let i = 0; i < intervalTokens.length; i += 1) {
500
+ intervalSuffixes[i] = ` ${intervalTokens[i]}`;
501
+ }
502
+ const whenSuffixes = whenSequences === PRECOMPUTED_WHEN_SEQUENCES
503
+ ? PRECOMPUTED_WHEN_SEQUENCE_SUFFIXES
504
+ : whenSequences.map((sequence) => ` ${sequence.join(" ")}`);
505
+ for (let pairIndex = 0; pairIndex < pairs.length; pairIndex += 1) {
506
+ const pair = pairs[pairIndex];
485
507
  const unitVariants = getUnitVariants(pair.unit);
486
508
  const route = pair.route;
487
509
  const routeLower = pair.routeLower;
488
- for (const code of FREQUENCY_CODES) {
489
- const codeSuffix = ` ${code}`;
490
- for (const unitVariant of unitVariants) {
491
- const unitRoute = `${unitVariant.value} ${route}`;
492
- const unitRouteLower = `${unitVariant.lower} ${routeLower}`;
493
- for (const doseVariant of doseVariants) {
494
- const candidate = `${doseVariant.value} ${unitRoute}${codeSuffix}`;
495
- const candidateLower = `${doseVariant.lower} ${unitRouteLower}${codeSuffix}`;
496
- if (push(candidate, candidateLower)) {
510
+ const unitDoseVariants = new Array(unitVariants.length);
511
+ for (let unitIndex = 0; unitIndex < unitVariants.length; unitIndex += 1) {
512
+ const unitVariant = unitVariants[unitIndex];
513
+ const unitRouteValue = `${unitVariant.value} ${route}`;
514
+ const unitRouteLower = `${unitVariant.lower} ${routeLower}`;
515
+ const doseBases = new Array(doseVariants.length);
516
+ for (let doseIndex = 0; doseIndex < doseVariants.length; doseIndex += 1) {
517
+ const doseVariant = doseVariants[doseIndex];
518
+ doseBases[doseIndex] = {
519
+ value: `${doseVariant.value} ${unitRouteValue}`,
520
+ lower: `${doseVariant.lower} ${unitRouteLower}`,
521
+ };
522
+ }
523
+ unitDoseVariants[unitIndex] = doseBases;
524
+ }
525
+ for (let codeIndex = 0; codeIndex < codeSuffixes.length; codeIndex += 1) {
526
+ const codeSuffix = codeSuffixes[codeIndex];
527
+ for (let unitIndex = 0; unitIndex < unitDoseVariants.length; unitIndex += 1) {
528
+ const doseBases = unitDoseVariants[unitIndex];
529
+ for (let doseIndex = 0; doseIndex < doseBases.length; doseIndex += 1) {
530
+ const base = doseBases[doseIndex];
531
+ if (push(base.value + codeSuffix, base.lower + codeSuffix)) {
497
532
  return suggestions;
498
533
  }
499
534
  }
500
535
  }
501
- const candidate = `${route}${codeSuffix}`;
502
- const candidateLower = `${routeLower}${codeSuffix}`;
503
- if (push(candidate, candidateLower)) {
536
+ if (push(route + codeSuffix, routeLower + codeSuffix)) {
504
537
  return suggestions;
505
538
  }
506
539
  }
507
- for (const interval of intervalTokens) {
508
- const intervalSuffix = ` ${interval}`;
509
- for (const unitVariant of unitVariants) {
510
- const unitRoute = `${unitVariant.value} ${route}`;
511
- const unitRouteLower = `${unitVariant.lower} ${routeLower}`;
512
- for (const doseVariant of doseVariants) {
513
- const base = `${doseVariant.value} ${unitRoute}`;
514
- const baseLower = `${doseVariant.lower} ${unitRouteLower}`;
515
- const intervalCandidate = `${base}${intervalSuffix}`;
516
- const intervalCandidateLower = `${baseLower}${intervalSuffix}`;
517
- if (push(intervalCandidate, intervalCandidateLower)) {
540
+ for (let intervalIndex = 0; intervalIndex < intervalSuffixes.length; intervalIndex += 1) {
541
+ const intervalSuffix = intervalSuffixes[intervalIndex];
542
+ for (let unitIndex = 0; unitIndex < unitDoseVariants.length; unitIndex += 1) {
543
+ const doseBases = unitDoseVariants[unitIndex];
544
+ for (let doseIndex = 0; doseIndex < doseBases.length; doseIndex += 1) {
545
+ const base = doseBases[doseIndex];
546
+ const baseIntervalValue = base.value + intervalSuffix;
547
+ const baseIntervalLower = base.lower + intervalSuffix;
548
+ if (push(baseIntervalValue, baseIntervalLower)) {
518
549
  return suggestions;
519
550
  }
520
- for (const reason of prnReasons) {
521
- const reasonSuffix = `${intervalSuffix} prn ${reason}`;
522
- const reasonCandidate = `${base}${reasonSuffix}`;
523
- const reasonCandidateLower = `${baseLower}${reasonSuffix}`;
524
- if (push(reasonCandidate, reasonCandidateLower)) {
551
+ for (let reasonIndex = 0; reasonIndex < prnSuffixes.length; reasonIndex += 1) {
552
+ const reasonSuffix = prnSuffixes[reasonIndex];
553
+ if (push(baseIntervalValue + reasonSuffix, baseIntervalLower + reasonSuffix)) {
525
554
  return suggestions;
526
555
  }
527
556
  }
528
557
  }
529
558
  }
530
- const candidate = `${route}${intervalSuffix}`;
531
- const candidateLower = `${routeLower}${intervalSuffix}`;
532
- if (push(candidate, candidateLower)) {
559
+ if (push(route + intervalSuffix, routeLower + intervalSuffix)) {
533
560
  return suggestions;
534
561
  }
535
562
  }
536
- for (const freq of FREQUENCY_NUMBERS) {
563
+ for (let freqIndex = 0; freqIndex < FREQUENCY_NUMBERS.length; freqIndex += 1) {
564
+ const freq = FREQUENCY_NUMBERS[freqIndex];
537
565
  const freqToken = FREQ_TOKEN_BY_NUMBER[freq];
538
566
  if (!freqToken) {
539
567
  continue;
540
568
  }
541
- const base = `1x${freq} ${route}`;
569
+ const baseValue = `1x${freq} ${route}`;
542
570
  const baseLower = `1x${freq} ${routeLower}`;
543
- const freqCandidate = `${base} ${freqToken}`;
544
- const freqCandidateLower = `${baseLower} ${freqToken}`;
545
- if (push(freqCandidate, freqCandidateLower)) {
571
+ if (push(`${baseValue} ${freqToken}`, `${baseLower} ${freqToken}`)) {
546
572
  return suggestions;
547
573
  }
548
- for (const when of CORE_WHEN_TOKENS) {
549
- const whenCandidate = `${base} ${when}`;
550
- const whenCandidateLower = `${baseLower} ${when}`;
551
- if (push(whenCandidate, whenCandidateLower)) {
574
+ for (let whenIndex = 0; whenIndex < CORE_WHEN_TOKENS.length; whenIndex += 1) {
575
+ const whenToken = CORE_WHEN_TOKENS[whenIndex];
576
+ if (push(`${baseValue} ${whenToken}`, `${baseLower} ${whenToken}`)) {
552
577
  return suggestions;
553
578
  }
554
579
  }
555
580
  }
556
- for (const whenSequence of whenSequences) {
557
- const suffix = ` ${whenSequence.join(" ")}`;
558
- for (const unitVariant of unitVariants) {
559
- const unitRoute = `${unitVariant.value} ${route}`;
560
- const unitRouteLower = `${unitVariant.lower} ${routeLower}`;
561
- for (const doseVariant of doseVariants) {
562
- const base = `${doseVariant.value} ${unitRoute}`;
563
- const baseLower = `${doseVariant.lower} ${unitRouteLower}`;
564
- const candidate = `${base}${suffix}`;
565
- const candidateLower = `${baseLower}${suffix}`;
566
- if (push(candidate, candidateLower)) {
581
+ for (let whenIndex = 0; whenIndex < whenSuffixes.length; whenIndex += 1) {
582
+ const whenSuffix = whenSuffixes[whenIndex];
583
+ for (let unitIndex = 0; unitIndex < unitDoseVariants.length; unitIndex += 1) {
584
+ const doseBases = unitDoseVariants[unitIndex];
585
+ for (let doseIndex = 0; doseIndex < doseBases.length; doseIndex += 1) {
586
+ const base = doseBases[doseIndex];
587
+ if (push(base.value + whenSuffix, base.lower + whenSuffix)) {
567
588
  return suggestions;
568
589
  }
569
590
  }
570
591
  }
571
- const candidate = `${route}${suffix}`;
572
- const candidateLower = `${routeLower}${suffix}`;
573
- if (push(candidate, candidateLower)) {
592
+ if (push(route + whenSuffix, routeLower + whenSuffix)) {
574
593
  return suggestions;
575
594
  }
576
595
  }
577
- for (const reason of prnReasons) {
578
- const reasonSuffix = ` prn ${reason}`;
579
- for (const unitVariant of unitVariants) {
580
- const unitRoute = `${unitVariant.value} ${route}`;
581
- const unitRouteLower = `${unitVariant.lower} ${routeLower}`;
582
- for (const doseVariant of doseVariants) {
583
- const base = `${doseVariant.value} ${unitRoute}`;
584
- const baseLower = `${doseVariant.lower} ${unitRouteLower}`;
585
- const candidate = `${base}${reasonSuffix}`;
586
- const candidateLower = `${baseLower}${reasonSuffix}`;
587
- if (push(candidate, candidateLower)) {
596
+ for (let reasonIndex = 0; reasonIndex < prnSuffixes.length; reasonIndex += 1) {
597
+ const reasonSuffix = prnSuffixes[reasonIndex];
598
+ for (let unitIndex = 0; unitIndex < unitDoseVariants.length; unitIndex += 1) {
599
+ const doseBases = unitDoseVariants[unitIndex];
600
+ for (let doseIndex = 0; doseIndex < doseBases.length; doseIndex += 1) {
601
+ const base = doseBases[doseIndex];
602
+ if (push(base.value + reasonSuffix, base.lower + reasonSuffix)) {
588
603
  return suggestions;
589
604
  }
590
605
  }
591
606
  }
592
- const candidate = `${route}${reasonSuffix}`;
593
- const candidateLower = `${routeLower}${reasonSuffix}`;
594
- if (push(candidate, candidateLower)) {
607
+ if (push(route + reasonSuffix, routeLower + reasonSuffix)) {
595
608
  return suggestions;
596
609
  }
597
610
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ezmedicationinput",
3
- "version": "0.1.6",
3
+ "version": "0.1.7",
4
4
  "description": "Parse concise medication sigs into FHIR R5 Dosage JSON",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",