ezmedicationinput 0.1.41 → 0.1.42

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/context.d.ts CHANGED
@@ -1,3 +1,4 @@
1
- import { MedicationContext } from "./types";
1
+ import { MedicationContext, RouteCode } from "./types";
2
2
  export declare function normalizeDosageForm(form: string | undefined): string | undefined;
3
3
  export declare function inferUnitFromContext(ctx: MedicationContext | undefined): string | undefined;
4
+ export declare function inferRouteFromContext(ctx: MedicationContext | undefined): RouteCode | undefined;
package/dist/context.js CHANGED
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.normalizeDosageForm = normalizeDosageForm;
4
4
  exports.inferUnitFromContext = inferUnitFromContext;
5
+ exports.inferRouteFromContext = inferRouteFromContext;
5
6
  const maps_1 = require("./maps");
6
7
  function normalizeDosageForm(form) {
7
8
  var _a;
@@ -32,3 +33,18 @@ function inferUnitFromContext(ctx) {
32
33
  }
33
34
  return undefined;
34
35
  }
36
+ function inferRouteFromContext(ctx) {
37
+ var _a;
38
+ if (!(ctx === null || ctx === void 0 ? void 0 : ctx.dosageForm)) {
39
+ return undefined;
40
+ }
41
+ const normalized = normalizeDosageForm(ctx.dosageForm);
42
+ if (!normalized) {
43
+ return undefined;
44
+ }
45
+ const snomed = maps_1.KNOWN_TMT_DOSAGE_FORM_TO_SNOMED_ROUTE[normalized];
46
+ if (!snomed) {
47
+ return (_a = maps_1.DEFAULT_ROUTE_SYNONYMS[normalized]) === null || _a === void 0 ? void 0 : _a.code;
48
+ }
49
+ return maps_1.ROUTE_BY_SNOMED[snomed];
50
+ }
package/dist/i18n.js CHANGED
@@ -231,7 +231,6 @@ const THAI_ROUTE_GRAMMAR = {
231
231
  [types_1.RouteCode["Buccal route"]]: { verb: "อมกระพุ้งแก้ม", routePhrase: "ที่กระพุ้งแก้ม" },
232
232
  [types_1.RouteCode["Respiratory tract route (qualifier value)"]]: {
233
233
  verb: "สูด",
234
- routePhrase: ({ hasSite }) => (hasSite ? undefined : "โดยการสูดดม"),
235
234
  sitePreposition: "ที่"
236
235
  },
237
236
  [types_1.RouteCode["Nasal route"]]: {
@@ -291,12 +290,18 @@ const THAI_ROUTE_GRAMMAR = {
291
290
  }
292
291
  };
293
292
  function resolveRouteGrammarThai(internal) {
294
- var _a;
293
+ var _a, _b, _c;
295
294
  if (internal.routeCode && THAI_ROUTE_GRAMMAR[internal.routeCode]) {
296
295
  return (_a = THAI_ROUTE_GRAMMAR[internal.routeCode]) !== null && _a !== void 0 ? _a : DEFAULT_THAI_ROUTE_GRAMMAR;
297
296
  }
298
297
  const grammar = grammarFromRouteTextThai(internal.routeText);
299
- return grammar !== null && grammar !== void 0 ? grammar : DEFAULT_THAI_ROUTE_GRAMMAR;
298
+ if (grammar) {
299
+ return grammar;
300
+ }
301
+ if (((_b = internal.unit) === null || _b === void 0 ? void 0 : _b.trim().toLowerCase()) === "puff") {
302
+ return (_c = THAI_ROUTE_GRAMMAR[types_1.RouteCode["Respiratory tract route (qualifier value)"]]) !== null && _c !== void 0 ? _c : DEFAULT_THAI_ROUTE_GRAMMAR;
303
+ }
304
+ return DEFAULT_THAI_ROUTE_GRAMMAR;
300
305
  }
301
306
  function grammarFromRouteTextThai(text) {
302
307
  if (!text)
@@ -606,7 +611,7 @@ function buildRoutePhraseThai(internal, grammar, hasSite) {
606
611
  return "ทางจมูก";
607
612
  }
608
613
  if (normalized.includes("inhal")) {
609
- return "โดยการสูดดม";
614
+ return undefined;
610
615
  }
611
616
  return text;
612
617
  }
package/dist/parser.js CHANGED
@@ -336,6 +336,7 @@ const EYE_SITE_TOKENS = {
336
336
  };
337
337
  const OPHTHALMIC_ROUTE_CODES = new Set([
338
338
  types_1.RouteCode["Ophthalmic route"],
339
+ types_1.RouteCode["Ocular route (qualifier value)"],
339
340
  types_1.RouteCode["Intravitreal route (qualifier value)"]
340
341
  ]);
341
342
  const OPHTHALMIC_CONTEXT_TOKENS = new Set([
@@ -538,9 +539,13 @@ function shouldTreatEyeTokenAsSite(internal, tokens, index, context) {
538
539
  const currentToken = tokens[index];
539
540
  const normalizedSelf = normalizeTokenLower(currentToken);
540
541
  const eyeMeta = EYE_SITE_TOKENS[normalizedSelf];
542
+ const contextRoute = (0, context_1.inferRouteFromContext)(context !== null && context !== void 0 ? context : undefined);
541
543
  if (internal.routeCode && !OPHTHALMIC_ROUTE_CODES.has(internal.routeCode)) {
542
544
  return false;
543
545
  }
546
+ if (contextRoute && !OPHTHALMIC_ROUTE_CODES.has(contextRoute)) {
547
+ return false;
548
+ }
544
549
  if (internal.siteText) {
545
550
  return false;
546
551
  }
@@ -548,7 +553,9 @@ function shouldTreatEyeTokenAsSite(internal, tokens, index, context) {
548
553
  return false;
549
554
  }
550
555
  const dosageForm = (_a = context === null || context === void 0 ? void 0 : context.dosageForm) === null || _a === void 0 ? void 0 : _a.toLowerCase();
551
- const contextImpliesOphthalmic = Boolean(dosageForm && /(eye|ophth|ocular|intravit)/i.test(dosageForm));
556
+ const contextImpliesOphthalmic = contextRoute
557
+ ? OPHTHALMIC_ROUTE_CODES.has(contextRoute)
558
+ : Boolean(dosageForm && /(eye|ophth|ocular|intravit)/i.test(dosageForm));
552
559
  const eyeRouteImpliesOphthalmic = (eyeMeta === null || eyeMeta === void 0 ? void 0 : eyeMeta.route) === types_1.RouteCode["Intravitreal route (qualifier value)"];
553
560
  const ophthalmicContext = hasOphthalmicContextHint(tokens, index) ||
554
561
  (internal.routeCode !== undefined && OPHTHALMIC_ROUTE_CODES.has(internal.routeCode)) ||
@@ -0,0 +1,2 @@
1
+ export declare function enumEntries<T extends Record<string, string | number>>(enumeration: T): Array<[keyof T, T[keyof T]]>;
2
+ export declare function enumValues<T extends Record<string, string | number>>(enumeration: T): Array<T[keyof T]>;
@@ -0,0 +1,7 @@
1
+ import { objectEntries, objectValues } from "./object";
2
+ export function enumEntries(enumeration) {
3
+ return objectEntries(enumeration);
4
+ }
5
+ export function enumValues(enumeration) {
6
+ return objectValues(enumeration);
7
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ezmedicationinput",
3
- "version": "0.1.41",
3
+ "version": "0.1.42",
4
4
  "description": "Parse concise medication sigs into FHIR R5 Dosage JSON",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",