ezmedicationinput 0.1.22 → 0.1.23

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/parser.js +55 -5
  2. package/package.json +1 -1
package/dist/parser.js CHANGED
@@ -1513,13 +1513,14 @@ function parseInternal(input, options) {
1513
1513
  }
1514
1514
  }
1515
1515
  // Multiplicative tokens like 1x3
1516
- for (const token of tokens) {
1516
+ for (let i = 0; i < tokens.length; i++) {
1517
+ const token = tokens[i];
1517
1518
  if (internal.consumed.has(token.index))
1518
1519
  continue;
1519
- const match = token.lower.match(/^([0-9]+(?:\.[0-9]+)?)[x*]([0-9]+(?:\.[0-9]+)?)$/);
1520
- if (match) {
1521
- const dose = parseFloat(match[1]);
1522
- const freq = parseFloat(match[2]);
1520
+ const combined = token.lower.match(/^([0-9]+(?:\.[0-9]+)?)[x*]([0-9]+(?:\.[0-9]+)?)$/);
1521
+ if (combined) {
1522
+ const dose = parseFloat(combined[1]);
1523
+ const freq = parseFloat(combined[2]);
1523
1524
  if (internal.dose === undefined) {
1524
1525
  internal.dose = dose;
1525
1526
  }
@@ -1527,6 +1528,55 @@ function parseInternal(input, options) {
1527
1528
  internal.period = 1;
1528
1529
  internal.periodUnit = types_1.FhirPeriodUnit.Day;
1529
1530
  mark(internal.consumed, token);
1531
+ continue;
1532
+ }
1533
+ const hasNumericDoseBefore = () => {
1534
+ for (let j = i - 1; j >= 0; j--) {
1535
+ const prev = tokens[j];
1536
+ if (!prev) {
1537
+ continue;
1538
+ }
1539
+ if (internal.consumed.has(prev.index)) {
1540
+ continue;
1541
+ }
1542
+ if (/^[0-9]+(?:\.[0-9]+)?$/.test(prev.lower)) {
1543
+ return true;
1544
+ }
1545
+ if (normalizeUnit(prev.lower, options)) {
1546
+ continue;
1547
+ }
1548
+ break;
1549
+ }
1550
+ return false;
1551
+ };
1552
+ if (internal.frequency === undefined && hasNumericDoseBefore()) {
1553
+ const prefix = token.lower.match(/^[x*]([0-9]+(?:\.[0-9]+)?)$/);
1554
+ if (prefix) {
1555
+ const freq = parseFloat(prefix[1]);
1556
+ if (Number.isFinite(freq)) {
1557
+ internal.frequency = freq;
1558
+ internal.period = 1;
1559
+ internal.periodUnit = types_1.FhirPeriodUnit.Day;
1560
+ mark(internal.consumed, token);
1561
+ continue;
1562
+ }
1563
+ }
1564
+ if (token.lower === "x" || token.lower === "*") {
1565
+ const next = tokens[i + 1];
1566
+ if (next &&
1567
+ !internal.consumed.has(next.index) &&
1568
+ /^[0-9]+(?:\.[0-9]+)?$/.test(next.lower)) {
1569
+ const freq = parseFloat(next.original);
1570
+ if (Number.isFinite(freq)) {
1571
+ internal.frequency = freq;
1572
+ internal.period = 1;
1573
+ internal.periodUnit = types_1.FhirPeriodUnit.Day;
1574
+ mark(internal.consumed, token);
1575
+ mark(internal.consumed, next);
1576
+ continue;
1577
+ }
1578
+ }
1579
+ }
1530
1580
  }
1531
1581
  }
1532
1582
  const applyRouteDescriptor = (code, text) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ezmedicationinput",
3
- "version": "0.1.22",
3
+ "version": "0.1.23",
4
4
  "description": "Parse concise medication sigs into FHIR R5 Dosage JSON",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",