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.
- package/dist/suggest.js +83 -70
- 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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
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
|
-
|
|
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 (
|
|
508
|
-
const intervalSuffix =
|
|
509
|
-
for (
|
|
510
|
-
const
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
const
|
|
514
|
-
const
|
|
515
|
-
|
|
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 (
|
|
521
|
-
const reasonSuffix =
|
|
522
|
-
|
|
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
|
-
|
|
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 (
|
|
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
|
|
569
|
+
const baseValue = `1x${freq} ${route}`;
|
|
542
570
|
const baseLower = `1x${freq} ${routeLower}`;
|
|
543
|
-
|
|
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 (
|
|
549
|
-
const
|
|
550
|
-
|
|
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 (
|
|
557
|
-
const
|
|
558
|
-
for (
|
|
559
|
-
const
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
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
|
-
|
|
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 (
|
|
578
|
-
const reasonSuffix =
|
|
579
|
-
for (
|
|
580
|
-
const
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
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
|
-
|
|
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
|
}
|