ezmedicationinput 0.1.56 → 0.1.58
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/body-site-grammar.d.ts +18 -0
- package/dist/hpsg/signature.d.ts +3 -0
- package/dist/hpsg/timing-lexicon.d.ts +6 -0
- package/dist/index.cjs +678 -209
- package/dist/index.js +678 -209
- package/dist/instruction-graph.d.ts +2 -0
- package/dist/relation-terminology.d.ts +1 -0
- package/package.json +11 -11
package/dist/index.cjs
CHANGED
|
@@ -1919,7 +1919,8 @@ var instruction_action_terminology_default = {
|
|
|
1919
1919
|
},
|
|
1920
1920
|
aliases: [
|
|
1921
1921
|
"drink",
|
|
1922
|
-
"\u0E14\u0E37\u0E48\u0E21"
|
|
1922
|
+
"\u0E14\u0E37\u0E48\u0E21",
|
|
1923
|
+
"drinking"
|
|
1923
1924
|
],
|
|
1924
1925
|
procedural: false,
|
|
1925
1926
|
acceptsAmount: true,
|
|
@@ -3452,6 +3453,19 @@ var instruction_concept_terminology_default = {
|
|
|
3452
3453
|
"\u0E41\u0E1C\u0E48\u0E19\u0E43\u0E2B\u0E21\u0E48"
|
|
3453
3454
|
]
|
|
3454
3455
|
},
|
|
3456
|
+
{
|
|
3457
|
+
code: "thoroughly",
|
|
3458
|
+
role: "manner",
|
|
3459
|
+
display: "thoroughly",
|
|
3460
|
+
i18n: {
|
|
3461
|
+
th: "\u0E43\u0E2B\u0E49\u0E17\u0E31\u0E48\u0E27"
|
|
3462
|
+
},
|
|
3463
|
+
aliases: [
|
|
3464
|
+
"thoroughly",
|
|
3465
|
+
"\u0E43\u0E2B\u0E49\u0E17\u0E31\u0E48\u0E27",
|
|
3466
|
+
"\u0E2D\u0E22\u0E48\u0E32\u0E07\u0E17\u0E31\u0E48\u0E27\u0E16\u0E36\u0E07"
|
|
3467
|
+
]
|
|
3468
|
+
},
|
|
3455
3469
|
{
|
|
3456
3470
|
code: "clean-result",
|
|
3457
3471
|
role: "result",
|
|
@@ -3535,6 +3549,21 @@ var instruction_concept_terminology_default = {
|
|
|
3535
3549
|
"sleep",
|
|
3536
3550
|
"\u0E19\u0E2D\u0E19"
|
|
3537
3551
|
]
|
|
3552
|
+
},
|
|
3553
|
+
{
|
|
3554
|
+
code: "dissolved",
|
|
3555
|
+
role: "result",
|
|
3556
|
+
display: "dissolved",
|
|
3557
|
+
i18n: {
|
|
3558
|
+
th: "\u0E25\u0E30\u0E25\u0E32\u0E22\u0E2B\u0E21\u0E14"
|
|
3559
|
+
},
|
|
3560
|
+
aliases: [
|
|
3561
|
+
"dissolved",
|
|
3562
|
+
"fully dissolved",
|
|
3563
|
+
"completely dissolved",
|
|
3564
|
+
"\u0E25\u0E30\u0E25\u0E32\u0E22\u0E2B\u0E21\u0E14",
|
|
3565
|
+
"\u0E25\u0E30\u0E25\u0E32\u0E22\u0E08\u0E19\u0E2B\u0E21\u0E14"
|
|
3566
|
+
]
|
|
3538
3567
|
}
|
|
3539
3568
|
]
|
|
3540
3569
|
};
|
|
@@ -4103,7 +4132,10 @@ var symptom_terminology_default = {
|
|
|
4103
4132
|
"pain",
|
|
4104
4133
|
"ache",
|
|
4105
4134
|
"aches",
|
|
4106
|
-
"pains"
|
|
4135
|
+
"pains",
|
|
4136
|
+
"painful",
|
|
4137
|
+
"hurt",
|
|
4138
|
+
"hurts"
|
|
4107
4139
|
],
|
|
4108
4140
|
definition: {
|
|
4109
4141
|
coding: {
|
|
@@ -4118,6 +4150,10 @@ var symptom_terminology_default = {
|
|
|
4118
4150
|
],
|
|
4119
4151
|
i18n: {
|
|
4120
4152
|
th: "\u0E1B\u0E27\u0E14"
|
|
4153
|
+
},
|
|
4154
|
+
conditionI18n: {
|
|
4155
|
+
en: "painful",
|
|
4156
|
+
th: "\u0E1B\u0E27\u0E14"
|
|
4121
4157
|
}
|
|
4122
4158
|
}
|
|
4123
4159
|
},
|
|
@@ -7122,7 +7158,11 @@ var DEFAULT_BODY_SITE_SNOMED_SOURCE = [
|
|
|
7122
7158
|
},
|
|
7123
7159
|
{
|
|
7124
7160
|
names: ["tongue", "tongues"],
|
|
7125
|
-
definition: {
|
|
7161
|
+
definition: {
|
|
7162
|
+
coding: { code: "21974007", display: "Tongue" },
|
|
7163
|
+
i18n: { th: "\u0E25\u0E34\u0E49\u0E19" },
|
|
7164
|
+
routeHint: RouteCode["Sublingual route"]
|
|
7165
|
+
}
|
|
7126
7166
|
},
|
|
7127
7167
|
{
|
|
7128
7168
|
names: ["lip", "lips"],
|
|
@@ -7788,6 +7828,10 @@ var DEFAULT_BODY_SITE_SNOMED_SOURCE = [
|
|
|
7788
7828
|
names: [
|
|
7789
7829
|
"interdigital spaces",
|
|
7790
7830
|
"interdigital space",
|
|
7831
|
+
"interdigital web spaces",
|
|
7832
|
+
"interdigital web space",
|
|
7833
|
+
"web spaces",
|
|
7834
|
+
"web space",
|
|
7791
7835
|
"\u0E23\u0E30\u0E2B\u0E27\u0E48\u0E32\u0E07\u0E23\u0E48\u0E2D\u0E07\u0E19\u0E34\u0E49\u0E27",
|
|
7792
7836
|
"\u0E23\u0E48\u0E2D\u0E07\u0E19\u0E34\u0E49\u0E27",
|
|
7793
7837
|
"\u0E0B\u0E2D\u0E01\u0E19\u0E34\u0E49\u0E27",
|
|
@@ -9867,7 +9911,8 @@ var relation_terminology_default = {
|
|
|
9867
9911
|
{
|
|
9868
9912
|
canonical: "outside",
|
|
9869
9913
|
aliases: [
|
|
9870
|
-
"outside"
|
|
9914
|
+
"outside",
|
|
9915
|
+
"outside of"
|
|
9871
9916
|
],
|
|
9872
9917
|
locative: true,
|
|
9873
9918
|
realization: {
|
|
@@ -10142,6 +10187,46 @@ var relation_terminology_default = {
|
|
|
10142
10187
|
strategy: "prefix"
|
|
10143
10188
|
}
|
|
10144
10189
|
}
|
|
10190
|
+
},
|
|
10191
|
+
{
|
|
10192
|
+
canonical: "at",
|
|
10193
|
+
aliases: [
|
|
10194
|
+
"at"
|
|
10195
|
+
],
|
|
10196
|
+
realization: {
|
|
10197
|
+
en: {
|
|
10198
|
+
surface: "at",
|
|
10199
|
+
strategy: "prefix"
|
|
10200
|
+
},
|
|
10201
|
+
th: {
|
|
10202
|
+
surface: "\u0E15\u0E23\u0E07",
|
|
10203
|
+
strategy: "prefix",
|
|
10204
|
+
omitOuterSitePreposition: true
|
|
10205
|
+
}
|
|
10206
|
+
},
|
|
10207
|
+
grammar: {
|
|
10208
|
+
qualifierTarget: "site"
|
|
10209
|
+
}
|
|
10210
|
+
},
|
|
10211
|
+
{
|
|
10212
|
+
canonical: "where",
|
|
10213
|
+
aliases: [
|
|
10214
|
+
"where"
|
|
10215
|
+
],
|
|
10216
|
+
realization: {
|
|
10217
|
+
en: {
|
|
10218
|
+
surface: "where",
|
|
10219
|
+
strategy: "prefix"
|
|
10220
|
+
},
|
|
10221
|
+
th: {
|
|
10222
|
+
surface: "\u0E17\u0E35\u0E48",
|
|
10223
|
+
strategy: "prefix",
|
|
10224
|
+
omitOuterSitePreposition: true
|
|
10225
|
+
}
|
|
10226
|
+
},
|
|
10227
|
+
grammar: {
|
|
10228
|
+
qualifierTarget: "symptom"
|
|
10229
|
+
}
|
|
10145
10230
|
}
|
|
10146
10231
|
]
|
|
10147
10232
|
};
|
|
@@ -10282,6 +10367,10 @@ for (const relation of ADVICE_RELATION_VALUES) {
|
|
|
10282
10367
|
}
|
|
10283
10368
|
var ACTION_SEQUENCE_MARKERS = ACTION_SEQUENCE_MARKERS_INTERNAL;
|
|
10284
10369
|
var ACTION_SEQUENCE_RELATION_SURFACES = ACTION_SEQUENCE_RELATION_SURFACES_INTERNAL;
|
|
10370
|
+
function resolveActionRelationSurfaceCandidates(surface) {
|
|
10371
|
+
var _a26;
|
|
10372
|
+
return (_a26 = ACTION_RELATION_INDEX.get(normalize(surface))) != null ? _a26 : [];
|
|
10373
|
+
}
|
|
10285
10374
|
function resolveActionRelationSurface(surface, preferredSemanticClasses) {
|
|
10286
10375
|
var _a26, _b3;
|
|
10287
10376
|
const normalized = normalize(surface);
|
|
@@ -12619,6 +12708,7 @@ function matchBodySiteLocativeRelation(words, start = 0) {
|
|
|
12619
12708
|
return relation ? { relation, length: 1 } : void 0;
|
|
12620
12709
|
}
|
|
12621
12710
|
function parseBodySiteFeatures(text, coding, customSiteMap) {
|
|
12711
|
+
var _a26;
|
|
12622
12712
|
const normalized = normalizeBodySiteKey(text);
|
|
12623
12713
|
if (!normalized) {
|
|
12624
12714
|
return buildNominalFeatures(text, normalized, coding, customSiteMap);
|
|
@@ -12667,30 +12757,49 @@ function parseBodySiteFeatures(text, coding, customSiteMap) {
|
|
|
12667
12757
|
whole: buildNominalFeatures(wholeText, normalizeBodySiteKey(wholeText), void 0, customSiteMap)
|
|
12668
12758
|
};
|
|
12669
12759
|
}
|
|
12760
|
+
if (words.length > 1 && (firstWord === "left" || firstWord === "right") && !lookupDefinitionForCanonical(normalized, customSiteMap)) {
|
|
12761
|
+
const wholeText = words.slice(1).join(" ");
|
|
12762
|
+
const wholeCanonical = normalizeBodySiteKey(wholeText);
|
|
12763
|
+
const wholeDefinition = lookupDefinitionForCanonical(wholeCanonical, customSiteMap);
|
|
12764
|
+
if (((_a26 = wholeDefinition == null ? void 0 : wholeDefinition.coding) == null ? void 0 : _a26.code) || (wholeDefinition == null ? void 0 : wholeDefinition.routeHint)) {
|
|
12765
|
+
return {
|
|
12766
|
+
kind: "partitive",
|
|
12767
|
+
part: `${firstWord} side`,
|
|
12768
|
+
relationKey: "side",
|
|
12769
|
+
whole: buildNominalFeatures(wholeText, wholeCanonical, void 0, customSiteMap),
|
|
12770
|
+
attributive: true
|
|
12771
|
+
};
|
|
12772
|
+
}
|
|
12773
|
+
}
|
|
12670
12774
|
return buildNominalFeatures(text, normalized, coding, customSiteMap);
|
|
12671
12775
|
}
|
|
12672
12776
|
function renderNominalObject(features) {
|
|
12673
12777
|
return features.article === "bare" ? features.text : `the ${features.text}`;
|
|
12674
12778
|
}
|
|
12675
12779
|
function renderBodySiteObject(features) {
|
|
12676
|
-
var _a26, _b3;
|
|
12780
|
+
var _a26, _b3, _c2;
|
|
12677
12781
|
switch (features.kind) {
|
|
12678
12782
|
case "locative": {
|
|
12679
12783
|
const surface = (_b3 = (_a26 = getBodySiteRelationRealization(features.relation, "en")) == null ? void 0 : _a26.surface) != null ? _b3 : features.relation;
|
|
12680
12784
|
return `${surface} ${renderBodySiteObject(features.target)}`;
|
|
12681
12785
|
}
|
|
12682
12786
|
case "partitive":
|
|
12787
|
+
if (features.attributive) {
|
|
12788
|
+
const side = (_c2 = features.part.split(/\s+/u)[0]) != null ? _c2 : features.part;
|
|
12789
|
+
return features.whole.article === "bare" ? `${side} ${features.whole.text}` : `the ${side} ${features.whole.text}`;
|
|
12790
|
+
}
|
|
12683
12791
|
return `${features.part.startsWith("both") || features.part.startsWith("bilateral") ? features.part : `the ${features.part}`} of ${renderNominalObject(features.whole)}`;
|
|
12684
12792
|
case "nominal":
|
|
12685
12793
|
return renderNominalObject(features);
|
|
12686
12794
|
}
|
|
12687
12795
|
}
|
|
12688
12796
|
function featureDisplayText(features) {
|
|
12797
|
+
var _a26;
|
|
12689
12798
|
switch (features.kind) {
|
|
12690
12799
|
case "locative":
|
|
12691
12800
|
return `${features.relation} ${featureDisplayText(features.target)}`;
|
|
12692
12801
|
case "partitive":
|
|
12693
|
-
return `${features.part} of ${features.whole.text}`;
|
|
12802
|
+
return features.attributive ? `${(_a26 = features.part.split(/\s+/u)[0]) != null ? _a26 : features.part} ${features.whole.text}` : `${features.part} of ${features.whole.text}`;
|
|
12694
12803
|
case "nominal":
|
|
12695
12804
|
return features.text;
|
|
12696
12805
|
}
|
|
@@ -12765,6 +12874,103 @@ function inferPreferredPreposition(canonical, features, definition) {
|
|
|
12765
12874
|
}
|
|
12766
12875
|
return void 0;
|
|
12767
12876
|
}
|
|
12877
|
+
function withBodySiteQualifier(features, qualifier) {
|
|
12878
|
+
return __spreadProps(__spreadValues({}, features), { qualifier });
|
|
12879
|
+
}
|
|
12880
|
+
var BODY_SITE_QUALIFIER_MATCHERS = (() => {
|
|
12881
|
+
var _a26, _b3;
|
|
12882
|
+
const matchers = [];
|
|
12883
|
+
const seen = /* @__PURE__ */ new Set();
|
|
12884
|
+
for (const definition of listBodySiteRelationDefinitions()) {
|
|
12885
|
+
const target = definition.grammar.qualifierTarget;
|
|
12886
|
+
if (!target) continue;
|
|
12887
|
+
const surfaces = [
|
|
12888
|
+
definition.canonical,
|
|
12889
|
+
...definition.aliases,
|
|
12890
|
+
(_a26 = definition.realization.en) == null ? void 0 : _a26.surface,
|
|
12891
|
+
(_b3 = definition.realization.th) == null ? void 0 : _b3.surface
|
|
12892
|
+
];
|
|
12893
|
+
for (const surface of surfaces) {
|
|
12894
|
+
const normalizedSurface = surface ? normalizeBodySiteKey(surface) : "";
|
|
12895
|
+
if (!normalizedSurface) continue;
|
|
12896
|
+
const key2 = `${definition.canonical}|${target}|${normalizedSurface}`;
|
|
12897
|
+
if (seen.has(key2)) continue;
|
|
12898
|
+
seen.add(key2);
|
|
12899
|
+
matchers.push({
|
|
12900
|
+
relation: definition.canonical,
|
|
12901
|
+
target,
|
|
12902
|
+
marker: ` ${normalizedSurface} `
|
|
12903
|
+
});
|
|
12904
|
+
}
|
|
12905
|
+
}
|
|
12906
|
+
return matchers.sort((left, right) => right.marker.length - left.marker.length);
|
|
12907
|
+
})();
|
|
12908
|
+
function matchBodySiteQualifier(lookupCanonical) {
|
|
12909
|
+
let best;
|
|
12910
|
+
for (const matcher of BODY_SITE_QUALIFIER_MATCHERS) {
|
|
12911
|
+
const index = lookupCanonical.lastIndexOf(matcher.marker);
|
|
12912
|
+
if (index <= 0 || index + matcher.marker.length >= lookupCanonical.length) continue;
|
|
12913
|
+
const candidate = {
|
|
12914
|
+
relation: matcher.relation,
|
|
12915
|
+
target: matcher.target,
|
|
12916
|
+
start: index,
|
|
12917
|
+
end: index + matcher.marker.length
|
|
12918
|
+
};
|
|
12919
|
+
if (!best || candidate.start > best.start || candidate.start === best.start && candidate.end > best.end) best = candidate;
|
|
12920
|
+
}
|
|
12921
|
+
return best;
|
|
12922
|
+
}
|
|
12923
|
+
function qualifiedBodySitePhrase(lookupCanonical, customSiteMap, context) {
|
|
12924
|
+
var _a26, _b3, _c2, _d, _e, _f, _g, _h;
|
|
12925
|
+
const match = matchBodySiteQualifier(lookupCanonical);
|
|
12926
|
+
if (!match) return void 0;
|
|
12927
|
+
const base = resolveBodySitePhrase(lookupCanonical.slice(0, match.start), customSiteMap, context);
|
|
12928
|
+
if (!base) return void 0;
|
|
12929
|
+
const targetText = lookupCanonical.slice(match.end);
|
|
12930
|
+
const realization = getBodySiteRelationRealization(match.relation, "en");
|
|
12931
|
+
if (!realization) return void 0;
|
|
12932
|
+
if (match.target === "symptom") {
|
|
12933
|
+
const symptom = resolveSymptomDefinition(targetText);
|
|
12934
|
+
if (!symptom) return void 0;
|
|
12935
|
+
const conditionText = (_d = (_c2 = (_a26 = symptom.conditionI18n) == null ? void 0 : _a26.en) != null ? _c2 : (_b3 = symptom.text) == null ? void 0 : _b3.toLowerCase()) != null ? _d : targetText;
|
|
12936
|
+
const qualifier2 = {
|
|
12937
|
+
kind: "symptom",
|
|
12938
|
+
relation: match.relation,
|
|
12939
|
+
text: targetText,
|
|
12940
|
+
canonical: (_f = (_e = symptom.text) == null ? void 0 : _e.toLowerCase()) != null ? _f : targetText,
|
|
12941
|
+
coding: symptom.coding ? __spreadValues({}, symptom.coding) : void 0,
|
|
12942
|
+
i18n: __spreadValues(__spreadValues({ en: conditionText }, (_g = symptom.i18n) != null ? _g : {}), (_h = symptom.conditionI18n) != null ? _h : {})
|
|
12943
|
+
};
|
|
12944
|
+
return __spreadProps(__spreadValues({}, base), {
|
|
12945
|
+
lookupCanonical,
|
|
12946
|
+
resolutionCanonical: `${base.resolutionCanonical} ${match.relation} ${qualifier2.canonical}`,
|
|
12947
|
+
canonical: `${base.canonical} ${match.relation} ${qualifier2.canonical}`,
|
|
12948
|
+
displayText: `${base.displayText} ${realization.surface} ${conditionText}`,
|
|
12949
|
+
features: withBodySiteQualifier(base.features, qualifier2),
|
|
12950
|
+
englishObjectText: `${base.englishObjectText} ${realization.surface} ${conditionText}`
|
|
12951
|
+
});
|
|
12952
|
+
}
|
|
12953
|
+
const target = resolveBodySitePhrase(targetText, customSiteMap, context);
|
|
12954
|
+
if (!target) return void 0;
|
|
12955
|
+
if (base.resolutionCanonical === target.resolutionCanonical) return base;
|
|
12956
|
+
if (!(base.coding || base.definition || base.spatialRelation)) return void 0;
|
|
12957
|
+
if (!(target.coding || target.definition || target.spatialRelation)) return void 0;
|
|
12958
|
+
const qualifier = {
|
|
12959
|
+
kind: "site",
|
|
12960
|
+
relation: match.relation,
|
|
12961
|
+
text: target.displayText,
|
|
12962
|
+
targetText: target.displayText,
|
|
12963
|
+
targetCoding: target.coding ? __spreadValues({}, target.coding) : void 0
|
|
12964
|
+
};
|
|
12965
|
+
return __spreadProps(__spreadValues({}, base), {
|
|
12966
|
+
lookupCanonical,
|
|
12967
|
+
resolutionCanonical: `${base.resolutionCanonical} ${match.relation} ${target.resolutionCanonical}`,
|
|
12968
|
+
canonical: `${base.canonical} ${match.relation} ${target.canonical}`,
|
|
12969
|
+
displayText: `${base.displayText} ${realization.surface} ${target.displayText}`,
|
|
12970
|
+
features: withBodySiteQualifier(base.features, qualifier),
|
|
12971
|
+
englishObjectText: `${base.englishObjectText} ${realization.surface} ${target.englishObjectText}`
|
|
12972
|
+
});
|
|
12973
|
+
}
|
|
12768
12974
|
function resolveBodySitePhrase(text, customSiteMap, context) {
|
|
12769
12975
|
var _a26, _b3, _c2, _d, _e, _f, _g, _h;
|
|
12770
12976
|
const trimmed = text.trim().replace(/\s+/g, " ");
|
|
@@ -12772,6 +12978,8 @@ function resolveBodySitePhrase(text, customSiteMap, context) {
|
|
|
12772
12978
|
return void 0;
|
|
12773
12979
|
}
|
|
12774
12980
|
const lookupCanonical = normalizeBodySiteKey(trimmed);
|
|
12981
|
+
const qualified = qualifiedBodySitePhrase(lookupCanonical, customSiteMap, context);
|
|
12982
|
+
if (qualified) return qualified;
|
|
12775
12983
|
const contextualCanonical = resolveContextualBodySiteAlias(lookupCanonical, context);
|
|
12776
12984
|
const displaySourceText = contextualCanonical != null ? contextualCanonical : trimmed;
|
|
12777
12985
|
const displayText = normalizeSiteDisplayText(displaySourceText, customSiteMap);
|
|
@@ -12779,9 +12987,17 @@ function resolveBodySitePhrase(text, customSiteMap, context) {
|
|
|
12779
12987
|
const directDefinition = (_e = (_d = (_c2 = (_b3 = (_a26 = lookupBodySiteDefinition(customSiteMap, lookupCanonical)) != null ? _a26 : contextualCanonical ? lookupBodySiteDefinition(customSiteMap, contextualCanonical) : void 0) != null ? _b3 : contextualCanonical ? DEFAULT_BODY_SITE_SNOMED[contextualCanonical] : void 0) != null ? _c2 : DEFAULT_BODY_SITE_SNOMED[lookupCanonical]) != null ? _d : lookupBodySiteDefinition(customSiteMap, canonical)) != null ? _e : DEFAULT_BODY_SITE_SNOMED[canonical];
|
|
12780
12988
|
const preliminaryFeatures = parseBodySiteFeatures(displayText, void 0, customSiteMap);
|
|
12781
12989
|
const terminal = directDefinition || !(context == null ? void 0 : context.allowTerminalModifierInheritance) || preliminaryFeatures.kind !== "nominal" || !terminalInheritanceIsLicensed(canonical) ? void 0 : longestTerminalBodySiteDefinition(canonical, customSiteMap);
|
|
12782
|
-
const
|
|
12783
|
-
const coding = buildBodySiteCoding(definition);
|
|
12990
|
+
const baseDefinition = directDefinition != null ? directDefinition : terminal == null ? void 0 : terminal.definition;
|
|
12784
12991
|
const finalDisplayText = (_f = directDefinition == null ? void 0 : directDefinition.text) != null ? _f : displayText;
|
|
12992
|
+
let inheritedDefinition;
|
|
12993
|
+
if (!baseDefinition) {
|
|
12994
|
+
const candidateFeatures = parseBodySiteFeatures(finalDisplayText, void 0, customSiteMap);
|
|
12995
|
+
if (candidateFeatures.kind === "partitive" && candidateFeatures.attributive) {
|
|
12996
|
+
inheritedDefinition = lookupDefinitionForCanonical(candidateFeatures.whole.canonical, customSiteMap);
|
|
12997
|
+
}
|
|
12998
|
+
}
|
|
12999
|
+
const definition = baseDefinition != null ? baseDefinition : inheritedDefinition;
|
|
13000
|
+
const coding = buildBodySiteCoding(definition);
|
|
12785
13001
|
const features = parseBodySiteFeatures(finalDisplayText, coding, customSiteMap);
|
|
12786
13002
|
const spatialRelation = (_g = definition == null ? void 0 : definition.spatialRelation) != null ? _g : buildSpatialRelation(features, finalDisplayText, customSiteMap);
|
|
12787
13003
|
return {
|
|
@@ -15918,6 +16134,139 @@ function resolveEventTimingExpression(parts, start = 0, endExclusive = parts.len
|
|
|
15918
16134
|
return direct ? { timing: direct, length: 1 } : void 0;
|
|
15919
16135
|
}
|
|
15920
16136
|
|
|
16137
|
+
// src/hpsg/timing-lexicon.ts
|
|
16138
|
+
var EVERY_INTERVAL_TOKENS = EVERY_INTERVAL_TOKENS_DATA;
|
|
16139
|
+
var COUNT_MARKER_TOKENS = COUNT_MARKER_TOKENS_DATA;
|
|
16140
|
+
var FREQUENCY_SIMPLE_WORDS = FREQUENCY_SIMPLE_WORDS_DATA;
|
|
16141
|
+
var FREQUENCY_NUMBER_WORDS = FREQUENCY_NUMBER_WORDS_DATA;
|
|
16142
|
+
var FREQUENCY_TIMES_WORDS = FREQUENCY_TIMES_WORDS_DATA;
|
|
16143
|
+
var FREQUENCY_CONNECTOR_WORDS = FREQUENCY_CONNECTOR_WORDS_DATA;
|
|
16144
|
+
function mapPeriodUnitLabel(label) {
|
|
16145
|
+
return FhirPeriodUnit[label];
|
|
16146
|
+
}
|
|
16147
|
+
var FREQUENCY_ADVERB_UNITS = new Map(
|
|
16148
|
+
Array.from(FREQUENCY_ADVERB_UNITS_DATA.entries()).map(([token, label]) => [token, mapPeriodUnitLabel(label)]).filter((entry) => Boolean(entry[1]))
|
|
16149
|
+
);
|
|
16150
|
+
var INTERVAL_UNITS = new Map(
|
|
16151
|
+
Array.from(INTERVAL_UNIT_TOKENS_DATA.entries()).map(([token, label]) => [token, mapPeriodUnitLabel(label)]).filter((entry) => Boolean(entry[1]))
|
|
16152
|
+
);
|
|
16153
|
+
function normalizePeriodValue(value, unit) {
|
|
16154
|
+
if (unit === "h" /* Hour */ && (!Number.isInteger(value) || value < 1)) {
|
|
16155
|
+
return { value: Math.round(value * 60 * 1e3) / 1e3, unit: "min" /* Minute */ };
|
|
16156
|
+
}
|
|
16157
|
+
return { value, unit };
|
|
16158
|
+
}
|
|
16159
|
+
function normalizePeriodRange(low, high, unit) {
|
|
16160
|
+
if (unit === "h" /* Hour */ && (!Number.isInteger(low) || !Number.isInteger(high) || low < 1 || high < 1)) {
|
|
16161
|
+
return {
|
|
16162
|
+
low: Math.round(low * 60 * 1e3) / 1e3,
|
|
16163
|
+
high: Math.round(high * 60 * 1e3) / 1e3,
|
|
16164
|
+
unit: "min" /* Minute */
|
|
16165
|
+
};
|
|
16166
|
+
}
|
|
16167
|
+
return { low, high, unit };
|
|
16168
|
+
}
|
|
16169
|
+
var FIXED_PERIOD_SECONDS = {
|
|
16170
|
+
["s" /* Second */]: 1,
|
|
16171
|
+
["min" /* Minute */]: 60,
|
|
16172
|
+
["h" /* Hour */]: 60 * 60,
|
|
16173
|
+
["d" /* Day */]: 24 * 60 * 60,
|
|
16174
|
+
["wk" /* Week */]: 7 * 24 * 60 * 60
|
|
16175
|
+
};
|
|
16176
|
+
function normalizeMixedPeriodRange(low, lowUnit, high, highUnit) {
|
|
16177
|
+
if (lowUnit === highUnit) {
|
|
16178
|
+
const normalized = normalizePeriodRange(low, high, lowUnit);
|
|
16179
|
+
return normalized.low <= normalized.high ? normalized : void 0;
|
|
16180
|
+
}
|
|
16181
|
+
const lowScale = FIXED_PERIOD_SECONDS[lowUnit];
|
|
16182
|
+
const highScale = FIXED_PERIOD_SECONDS[highUnit];
|
|
16183
|
+
if (!lowScale || !highScale) return void 0;
|
|
16184
|
+
const unit = lowScale <= highScale ? lowUnit : highUnit;
|
|
16185
|
+
const unitScale = FIXED_PERIOD_SECONDS[unit];
|
|
16186
|
+
const normalizedLow = Math.round(low * lowScale / unitScale * 1e3) / 1e3;
|
|
16187
|
+
const normalizedHigh = Math.round(high * highScale / unitScale * 1e3) / 1e3;
|
|
16188
|
+
if (normalizedLow > normalizedHigh) return void 0;
|
|
16189
|
+
return { low: normalizedLow, high: normalizedHigh, unit };
|
|
16190
|
+
}
|
|
16191
|
+
function periodUnitSuffix(unit) {
|
|
16192
|
+
switch (unit) {
|
|
16193
|
+
case "min" /* Minute */:
|
|
16194
|
+
return "min";
|
|
16195
|
+
case "h" /* Hour */:
|
|
16196
|
+
return "h";
|
|
16197
|
+
case "d" /* Day */:
|
|
16198
|
+
return "d";
|
|
16199
|
+
case "wk" /* Week */:
|
|
16200
|
+
return "wk";
|
|
16201
|
+
case "mo" /* Month */:
|
|
16202
|
+
return "mo";
|
|
16203
|
+
case "a" /* Year */:
|
|
16204
|
+
return "a";
|
|
16205
|
+
default:
|
|
16206
|
+
return void 0;
|
|
16207
|
+
}
|
|
16208
|
+
}
|
|
16209
|
+
function deriveDefaultTimingForPeriod(value, unit, currentTimingCode) {
|
|
16210
|
+
let timingCode = currentTimingCode;
|
|
16211
|
+
const suffix = periodUnitSuffix(unit);
|
|
16212
|
+
if (suffix) {
|
|
16213
|
+
const key2 = `q${value}${suffix}`;
|
|
16214
|
+
const descriptor = TIMING_ABBREVIATIONS[key2];
|
|
16215
|
+
if (descriptor == null ? void 0 : descriptor.code) {
|
|
16216
|
+
timingCode = timingCode != null ? timingCode : descriptor.code;
|
|
16217
|
+
}
|
|
16218
|
+
}
|
|
16219
|
+
if (unit === "wk" /* Week */ && value === 1) {
|
|
16220
|
+
timingCode = timingCode != null ? timingCode : "WK";
|
|
16221
|
+
}
|
|
16222
|
+
if (unit === "mo" /* Month */ && value === 1) {
|
|
16223
|
+
timingCode = timingCode != null ? timingCode : "MO";
|
|
16224
|
+
}
|
|
16225
|
+
return {
|
|
16226
|
+
frequency: unit === "d" /* Day */ && value === 1 ? 1 : void 0,
|
|
16227
|
+
timingCode
|
|
16228
|
+
};
|
|
16229
|
+
}
|
|
16230
|
+
function buildPeriodScheduleFeature(period, unit) {
|
|
16231
|
+
const normalized = normalizePeriodValue(period, unit);
|
|
16232
|
+
const defaults = deriveDefaultTimingForPeriod(normalized.value, normalized.unit);
|
|
16233
|
+
return {
|
|
16234
|
+
period: normalized.value,
|
|
16235
|
+
periodUnit: normalized.unit,
|
|
16236
|
+
frequency: defaults.frequency,
|
|
16237
|
+
timingCode: defaults.timingCode
|
|
16238
|
+
};
|
|
16239
|
+
}
|
|
16240
|
+
function mapIntervalUnit(token) {
|
|
16241
|
+
const unit = INTERVAL_UNITS.get(token);
|
|
16242
|
+
return unit === "min" /* Minute */ || unit === "h" /* Hour */ || unit === "d" /* Day */ || unit === "wk" /* Week */ || unit === "mo" /* Month */ ? unit : void 0;
|
|
16243
|
+
}
|
|
16244
|
+
function mapFrequencyAdverb(token) {
|
|
16245
|
+
return FREQUENCY_ADVERB_UNITS.get(token);
|
|
16246
|
+
}
|
|
16247
|
+
function parseNumericRange(token) {
|
|
16248
|
+
const rangeMatch = token.match(/^([0-9]+(?:\.[0-9]+)?)[-–—]([0-9]+(?:\.[0-9]+)?)$/);
|
|
16249
|
+
if (!rangeMatch) {
|
|
16250
|
+
return void 0;
|
|
16251
|
+
}
|
|
16252
|
+
const low = parseFloat(rangeMatch[1]);
|
|
16253
|
+
const high = parseFloat(rangeMatch[2]);
|
|
16254
|
+
if (!Number.isFinite(low) || !Number.isFinite(high) || high < low) {
|
|
16255
|
+
return void 0;
|
|
16256
|
+
}
|
|
16257
|
+
return { low, high };
|
|
16258
|
+
}
|
|
16259
|
+
function buildDurationScheduleFeature(value, unit, max) {
|
|
16260
|
+
if (value === void 0 || !Number.isFinite(value) || value <= 0 || !unit) {
|
|
16261
|
+
return void 0;
|
|
16262
|
+
}
|
|
16263
|
+
return {
|
|
16264
|
+
duration: value,
|
|
16265
|
+
durationMax: max !== void 0 && Number.isFinite(max) && max > value ? max : void 0,
|
|
16266
|
+
durationUnit: unit
|
|
16267
|
+
};
|
|
16268
|
+
}
|
|
16269
|
+
|
|
15921
16270
|
// src/instruction-graph.ts
|
|
15922
16271
|
var SNOMED_SYSTEM4 = "http://snomed.info/sct";
|
|
15923
16272
|
var ACTION_ROUTE_TAIL_SURFACES = /* @__PURE__ */ new Set([
|
|
@@ -16801,6 +17150,9 @@ function buildActionFrame(parts, segmentStart, segmentEnd, input, offset, sequen
|
|
|
16801
17150
|
const conditionalTail = relationHasGrammarFeature(rawRelation, "conditionalTail");
|
|
16802
17151
|
const secondaryConditionalTail = relationHasGrammarFeature(nextRelation, "conditionalTail");
|
|
16803
17152
|
const relation = conditionalTail ? void 0 : rawRelation;
|
|
17153
|
+
const secondaryActivityTarget = nextRelationIndex >= 0 ? resolveMedicationInstructionAction(key(parts[nextRelationIndex + 1]), options) : void 0;
|
|
17154
|
+
const secondaryActivityRelation = nextRelationIndex >= 0 && secondaryActivityTarget && relationHasGrammarFeature(nextRelation, "activityFallback") ? nextRelation : void 0;
|
|
17155
|
+
const frameRelation = secondaryActivityRelation != null ? secondaryActivityRelation : relation;
|
|
16804
17156
|
const amount = definition.acceptsAmount ? parseQuantityArgument(parts, argumentStart, segmentEnd, input, offset, options) : void 0;
|
|
16805
17157
|
const duration = parseAnyDurationArgument(parts, argumentStart, segmentEnd, input, offset);
|
|
16806
17158
|
let semanticEnd = conditionalTail && relIndex >= 0 ? relIndex : secondaryConditionalTail && nextRelationIndex >= 0 ? nextRelationIndex : segmentEnd;
|
|
@@ -16823,6 +17175,16 @@ function buildActionFrame(parts, segmentStart, segmentEnd, input, offset, sequen
|
|
|
16823
17175
|
separableParticleIndex: actionMatch.separableParticleIndex
|
|
16824
17176
|
});
|
|
16825
17177
|
const args = parsed.args;
|
|
17178
|
+
if (secondaryActivityRelation && nextRelationIndex >= 0) {
|
|
17179
|
+
pushArgument(args, argumentFromParts(
|
|
17180
|
+
parts,
|
|
17181
|
+
nextRelationIndex + 1,
|
|
17182
|
+
segmentEnd,
|
|
17183
|
+
input,
|
|
17184
|
+
"activity" /* Activity */,
|
|
17185
|
+
options
|
|
17186
|
+
));
|
|
17187
|
+
}
|
|
16826
17188
|
if (definition.argumentParser === "preposed-duration" && !args.some((arg) => arg.role === "duration" /* Duration */)) {
|
|
16827
17189
|
return void 0;
|
|
16828
17190
|
}
|
|
@@ -16853,7 +17215,7 @@ function buildActionFrame(parts, segmentStart, segmentEnd, input, offset, sequen
|
|
|
16853
17215
|
}) : void 0,
|
|
16854
17216
|
codings
|
|
16855
17217
|
},
|
|
16856
|
-
relation,
|
|
17218
|
+
relation: frameRelation,
|
|
16857
17219
|
args,
|
|
16858
17220
|
span,
|
|
16859
17221
|
sourceText: input.slice(span.start - offset, span.end - offset),
|
|
@@ -16978,8 +17340,17 @@ function actionTailIsRegimenModifier(parts, actionStart, index, definition) {
|
|
|
16978
17340
|
return true;
|
|
16979
17341
|
}
|
|
16980
17342
|
if (ACTION_ROUTE_TAIL_SURFACES.has(token)) return true;
|
|
16981
|
-
const timing = Boolean(
|
|
16982
|
-
|
|
17343
|
+
const timing = Boolean(
|
|
17344
|
+
TIMING_ABBREVIATIONS[token] || WORD_FREQUENCIES[token] || EVENT_TIMING_TOKENS[token] || FREQUENCY_SIMPLE_WORDS[token] !== void 0
|
|
17345
|
+
);
|
|
17346
|
+
if (!timing) {
|
|
17347
|
+
const previous = parts[index - 1];
|
|
17348
|
+
if (!previous || !/^[,;:]$/u.test(previous.original.trim())) return false;
|
|
17349
|
+
const relation = resolveActionRelationSurface(token);
|
|
17350
|
+
if (!relation) return false;
|
|
17351
|
+
const eventTail = parts.slice(index + 1, Math.min(parts.length, index + 4));
|
|
17352
|
+
if (!eventTail.some((part) => Boolean(EVENT_TIMING_TOKENS[key(part)]))) return false;
|
|
17353
|
+
}
|
|
16983
17354
|
if ((definition == null ? void 0 : definition.argumentParser) === "object-time") return false;
|
|
16984
17355
|
return !actionHasLocalRelationBefore(parts, actionStart, index);
|
|
16985
17356
|
}
|
|
@@ -17020,6 +17391,10 @@ function parseInstructionActions(sourceText, baseOffset = 0, options) {
|
|
|
17020
17391
|
end = ACTION_COORDINATION_CONNECTORS.has(previousKey) ? index - 1 : index;
|
|
17021
17392
|
break;
|
|
17022
17393
|
}
|
|
17394
|
+
if (/^[,;:]$/u.test(currentKey) && INSTRUCTION_START_WORDS.has(key(parts[index + 1]))) {
|
|
17395
|
+
end = index;
|
|
17396
|
+
break;
|
|
17397
|
+
}
|
|
17023
17398
|
if (ACTION_DIRECTIVE_BOUNDARIES.has(currentKey) && !prefixedActionAt(parts, index, options) && !resultativeLeadAt(parts, index, options)) {
|
|
17024
17399
|
end = index;
|
|
17025
17400
|
break;
|
|
@@ -17558,15 +17933,26 @@ function promoteDoseFromDefiningAction(clause, actions, options) {
|
|
|
17558
17933
|
}
|
|
17559
17934
|
function canonicalPrimaryAdministrationSpan(clause, frames) {
|
|
17560
17935
|
const semantic = frames.filter((frame) => frame.polarity !== "negate" /* Negate */ && actionMatchesCanonicalMethod(frame, clause)).slice().sort((left, right) => left.span.start - right.span.start || left.span.end - right.span.end)[0];
|
|
17561
|
-
if (semantic)
|
|
17562
|
-
|
|
17936
|
+
if (semantic) {
|
|
17937
|
+
let best;
|
|
17938
|
+
for (const evidence of clause.evidence) {
|
|
17939
|
+
if (evidence.rule !== "hpsg.lex.method") continue;
|
|
17940
|
+
for (const span of evidence.spans) {
|
|
17941
|
+
if (span.start < semantic.span.start || semantic.span.end < span.end) continue;
|
|
17942
|
+
const candidate = { start: span.start, end: span.end };
|
|
17943
|
+
if (!best || candidate.end - candidate.start < best.end - best.start || candidate.end - candidate.start === best.end - best.start && candidate.start < best.start) {
|
|
17944
|
+
best = candidate;
|
|
17945
|
+
}
|
|
17946
|
+
}
|
|
17947
|
+
}
|
|
17948
|
+
return best != null ? best : { start: semantic.span.start, end: semantic.span.end };
|
|
17949
|
+
}
|
|
17563
17950
|
for (const evidence of clause.evidence) {
|
|
17564
17951
|
if (evidence.rule !== "hpsg.lex.method") continue;
|
|
17565
|
-
|
|
17952
|
+
const span = evidence.spans[0];
|
|
17953
|
+
if (span) return { start: span.start, end: span.end };
|
|
17566
17954
|
}
|
|
17567
|
-
|
|
17568
|
-
spans.sort((left, right) => left.start - right.start || left.end - right.end);
|
|
17569
|
-
return spans[0];
|
|
17955
|
+
return void 0;
|
|
17570
17956
|
}
|
|
17571
17957
|
function buildInstructionGraph(input, clause, options) {
|
|
17572
17958
|
const actions = [];
|
|
@@ -17714,7 +18100,7 @@ function actionLabel(frame, locale, roundtripSafe = false) {
|
|
|
17714
18100
|
return (_i = (_h = (_g = (_f = (_d = (_c2 = roundtripSafe ? (_a26 = definition == null ? void 0 : definition.roundtripI18n) == null ? void 0 : _a26[language] : void 0) != null ? _c2 : (_b3 = frame.predicate.i18n) == null ? void 0 : _b3[language]) != null ? _d : language === "en" ? frame.predicate.display : void 0) != null ? _f : (_e = definition == null ? void 0 : definition.i18n) == null ? void 0 : _e[language]) != null ? _g : definition == null ? void 0 : definition.display) != null ? _h : frame.predicate.display) != null ? _i : frame.predicate.lemma;
|
|
17715
18101
|
}
|
|
17716
18102
|
var DEFAULT_ACTION_REALIZER = (c) => {
|
|
17717
|
-
var _a26, _b3, _c2, _d;
|
|
18103
|
+
var _a26, _b3, _c2, _d, _e;
|
|
17718
18104
|
const objectArgs = c.frame.args.filter(
|
|
17719
18105
|
(arg) => arg.role === "theme" /* Theme */ || arg.role === "object" /* Object */ || arg.role === "site" /* Site */ || arg.role === "substance" /* Substance */
|
|
17720
18106
|
);
|
|
@@ -17727,7 +18113,9 @@ var DEFAULT_ACTION_REALIZER = (c) => {
|
|
|
17727
18113
|
const relationTargetArg = objectArgs.length > 1 ? objectArgs[1] : void 0;
|
|
17728
18114
|
const relationTarget = relationTargetArg ? translatedArgument(relationTargetArg, c.locale) : void 0;
|
|
17729
18115
|
const withTarget = relationHasGrammarFeature(c.frame.relation, "accompanimentComplement") ? relationTarget : void 0;
|
|
17730
|
-
|
|
18116
|
+
const activityRelation = c.activity && relationHasGrammarFeature(c.frame.relation, "activityFallback") ? (_e = localizeAdviceRelation(c.frame.relation, c.locale)) != null ? _e : c.frame.relation : void 0;
|
|
18117
|
+
const activitySuffix = activityRelation && c.activity ? c.thai ? `${activityRelation}${c.activity}` : ` ${activityRelation} ${c.activity}` : "";
|
|
18118
|
+
return c.thai ? `${c.label}${object != null ? object : ""}${amount ? ` ${amount}` : ""}${c.duration ? ` ${c.duration}` : ""}${withTarget ? `\u0E23\u0E48\u0E27\u0E21\u0E01\u0E31\u0E1A${withTarget}` : ""}${activitySuffix}` : `${c.label}${object ? ` ${object}` : ""}${amount ? ` ${amount}` : ""}${c.duration ? ` for ${c.duration}` : ""}${withTarget ? ` with ${withTarget}` : ""}${activitySuffix}`;
|
|
17731
18119
|
};
|
|
17732
18120
|
var SOURCE_FAITHFUL_REALIZER = (c) => {
|
|
17733
18121
|
const sourceIsThai = /[\u0E00-\u0E7F]/.test(c.frame.sourceText);
|
|
@@ -17769,6 +18157,7 @@ var RESULT_REALIZER = (c) => c.thai ? `${c.label}${c.result ? `\u0E43\u0E2B\u0E4
|
|
|
17769
18157
|
var SITE_RELATION_REALIZER = (c) => {
|
|
17770
18158
|
var _a26, _b3, _c2, _d, _e, _f, _g, _h, _i;
|
|
17771
18159
|
const relationTarget = (_a26 = c.time) != null ? _a26 : c.activity;
|
|
18160
|
+
const mannerSuffix = c.manner ? c.thai ? c.manner : ` ${c.manner}` : "";
|
|
17772
18161
|
if (relationTarget) {
|
|
17773
18162
|
const siteArg = c.frame.args.find((arg) => arg.role === "site" /* Site */);
|
|
17774
18163
|
const suppressThaiSite = Boolean(
|
|
@@ -17778,22 +18167,22 @@ var SITE_RELATION_REALIZER = (c) => {
|
|
|
17778
18167
|
if (c.time && relationHasGrammarFeature(c.frame.relation, "directTimeRealization")) {
|
|
17779
18168
|
if (c.thai) {
|
|
17780
18169
|
const timePhrase2 = c.time === "\u0E01\u0E25\u0E32\u0E07\u0E04\u0E37\u0E19" ? "\u0E15\u0E2D\u0E19\u0E01\u0E25\u0E32\u0E07\u0E04\u0E37\u0E19" : c.time === "\u0E19\u0E2D\u0E19" || c.time === "bedtime" ? "\u0E01\u0E48\u0E2D\u0E19\u0E19\u0E2D\u0E19" : c.time;
|
|
17781
|
-
return `${c.label}${target}${timePhrase2}`;
|
|
18170
|
+
return `${c.label}${target}${mannerSuffix}${timePhrase2}`;
|
|
17782
18171
|
}
|
|
17783
18172
|
const lower = c.time.toLowerCase();
|
|
17784
18173
|
const timePhrase = lower === "night" ? "at night" : lower === "bed" || lower === "bedtime" || lower === "sleep" ? "at bedtime" : /^(?:the )?(?:morning|afternoon|evening)$/.test(lower) ? `in ${lower.startsWith("the ") ? lower : `the ${lower}`}` : `at ${c.time}`;
|
|
17785
|
-
return `${c.label}${target} ${timePhrase}`;
|
|
18174
|
+
return `${c.label}${target}${mannerSuffix} ${timePhrase}`;
|
|
17786
18175
|
}
|
|
17787
18176
|
const semanticRelation = (_f = (_e = c.frame.relation) != null ? _e : getUniqueAdviceRelationByGrammarFeature("defaultSiteRelation")) != null ? _f : (() => {
|
|
17788
18177
|
throw new Error("Missing declarative default site relation");
|
|
17789
18178
|
})();
|
|
17790
18179
|
const relationProfile = (_h = (_g = getAdviceRelationDefinition(semanticRelation)) == null ? void 0 : _g.grammar.timeRealizationProfile) != null ? _h : "default";
|
|
17791
18180
|
const relationText = (_i = localizeAdviceRelation(semanticRelation, c.locale, relationProfile)) != null ? _i : semanticRelation;
|
|
17792
|
-
return c.thai ? `${c.label}${target}${relationText}${relationTarget}` : `${c.label}${target} ${relationText} ${relationTarget}`;
|
|
18181
|
+
return c.thai ? `${c.label}${target}${mannerSuffix}${relationText}${relationTarget}` : `${c.label}${target}${mannerSuffix} ${relationText} ${relationTarget}`;
|
|
17793
18182
|
}
|
|
17794
18183
|
const resultSuffix = c.result ? c.thai ? `\u0E43\u0E2B\u0E49${c.result}` : ` until ${c.result}` : "";
|
|
17795
|
-
if (c.site) return c.thai ? `${c.label}${c.site}${c.substance ? `\u0E14\u0E49\u0E27\u0E22${c.substance}` : ""}${resultSuffix}` : `${c.label} ${c.site}${c.substance ? ` with ${c.substance}` : ""}${resultSuffix}`;
|
|
17796
|
-
return c.thai ? `${c.label}${c.substance ? `\u0E14\u0E49\u0E27\u0E22${c.substance}` : ""}${resultSuffix}` : `${c.label}${c.substance ? ` with ${c.substance}` : ""}${resultSuffix}`;
|
|
18184
|
+
if (c.site) return c.thai ? `${c.label}${c.site}${mannerSuffix}${c.substance ? `\u0E14\u0E49\u0E27\u0E22${c.substance}` : ""}${resultSuffix}` : `${c.label} ${c.site}${mannerSuffix}${c.substance ? ` with ${c.substance}` : ""}${resultSuffix}`;
|
|
18185
|
+
return c.thai ? `${c.label}${mannerSuffix}${c.substance ? `\u0E14\u0E49\u0E27\u0E22${c.substance}` : ""}${resultSuffix}` : `${c.label}${mannerSuffix}${c.substance ? ` with ${c.substance}` : ""}${resultSuffix}`;
|
|
17797
18186
|
};
|
|
17798
18187
|
var OBJECT_AMOUNT_MATERIAL_REALIZER = (c) => {
|
|
17799
18188
|
var _a26;
|
|
@@ -17857,13 +18246,17 @@ var LEAVE_DURATION_REALIZER = (c) => {
|
|
|
17857
18246
|
};
|
|
17858
18247
|
var DURATION_REALIZER = (c) => c.thai ? `${c.label}${c.duration ? ` ${c.duration}` : ""}` : `${c.label}${c.duration ? ` for ${c.duration}` : ""}`;
|
|
17859
18248
|
var DURATION_ACTIVITY_REALIZER = (c) => {
|
|
17860
|
-
var _a26;
|
|
17861
|
-
|
|
17862
|
-
if (
|
|
17863
|
-
|
|
17864
|
-
|
|
18249
|
+
var _a26, _b3;
|
|
18250
|
+
const target = (_a26 = c.activity) != null ? _a26 : c.result;
|
|
18251
|
+
if (!target) return `${c.label}${c.duration ? ` ${c.duration}` : ""}`;
|
|
18252
|
+
if (c.frame.relation) {
|
|
18253
|
+
const relation = (_b3 = localizeAdviceRelation(c.frame.relation, c.locale)) != null ? _b3 : c.frame.relation;
|
|
18254
|
+
if (relationHasSemanticClass(c.frame.relation, "interval")) {
|
|
18255
|
+
return c.thai ? `${c.label}${c.duration ? ` ${c.duration}` : ""} ${relation}${target}` : `${c.label}${c.duration ? ` ${c.duration}` : ""} ${relation} ${target}`;
|
|
18256
|
+
}
|
|
18257
|
+
return c.thai ? `${c.label}${c.duration ? ` ${c.duration}` : ""}${relation}${target}` : `${c.label}${c.duration ? ` ${c.duration}` : ""} ${relation} ${target}`;
|
|
17865
18258
|
}
|
|
17866
|
-
return `${c.label}${c.duration ? ` ${c.duration}` : ""} ${
|
|
18259
|
+
return `${c.label}${c.duration ? ` ${c.duration}` : ""} ${target}`;
|
|
17867
18260
|
};
|
|
17868
18261
|
var ACTIVITY_REALIZER = (c) => {
|
|
17869
18262
|
var _a26, _b3, _c2;
|
|
@@ -17952,6 +18345,7 @@ function realizeAction(frame, locale, roundtripSafe = false) {
|
|
|
17952
18345
|
const time = timeArg ? thai && /[\u0E00-\u0E7F]/u.test(timeArg.text) ? timeArg.text : translatedArgument(timeArg, locale) : void 0;
|
|
17953
18346
|
const duration = first("duration" /* Duration */);
|
|
17954
18347
|
const material = first("material" /* Material */);
|
|
18348
|
+
const manner = first("manner" /* Manner */);
|
|
17955
18349
|
if (frame.polarity === "negate" /* Negate */) {
|
|
17956
18350
|
const object = (_c2 = (_b3 = site != null ? site : theme) != null ? _b3 : substance) != null ? _c2 : material;
|
|
17957
18351
|
const relationTarget = activity != null ? activity : time;
|
|
@@ -17990,6 +18384,7 @@ function realizeAction(frame, locale, roundtripSafe = false) {
|
|
|
17990
18384
|
time,
|
|
17991
18385
|
duration,
|
|
17992
18386
|
material,
|
|
18387
|
+
manner,
|
|
17993
18388
|
realizerConfig: (_i = frame.predicate.realizerConfig) != null ? _i : definition == null ? void 0 : definition.realizerConfig,
|
|
17994
18389
|
definition
|
|
17995
18390
|
});
|
|
@@ -18032,6 +18427,28 @@ function instructionGraphRepresentsText(graph, text) {
|
|
|
18032
18427
|
return Boolean(candidate && (candidate === normalized || candidate.includes(normalized)));
|
|
18033
18428
|
});
|
|
18034
18429
|
}
|
|
18430
|
+
function instructionGraphTextParticipatesInRelation(graph, text) {
|
|
18431
|
+
var _a26, _b3;
|
|
18432
|
+
const normalized = normalizedInstructionSurface(text);
|
|
18433
|
+
if (!normalized) return false;
|
|
18434
|
+
const compact = (value) => value.replace(/\s+/gu, "");
|
|
18435
|
+
const matchingIndices = [];
|
|
18436
|
+
for (let index = 0; index < graph.actions.length; index += 1) {
|
|
18437
|
+
const source = normalizedInstructionSurface((_b3 = (_a26 = graph.actions[index]) == null ? void 0 : _a26.sourceText) != null ? _b3 : "");
|
|
18438
|
+
if (!source) continue;
|
|
18439
|
+
if (source === normalized || compact(source).includes(compact(normalized)) || compact(normalized).includes(compact(source))) {
|
|
18440
|
+
matchingIndices.push(index);
|
|
18441
|
+
}
|
|
18442
|
+
}
|
|
18443
|
+
return matchingIndices.some(
|
|
18444
|
+
(index) => {
|
|
18445
|
+
var _a27, _b4;
|
|
18446
|
+
return (_b4 = (_a27 = graph.relations) == null ? void 0 : _a27.some(
|
|
18447
|
+
(relation) => relation.fromActionIndex === index || relation.toActionIndex === index
|
|
18448
|
+
)) != null ? _b4 : false;
|
|
18449
|
+
}
|
|
18450
|
+
);
|
|
18451
|
+
}
|
|
18035
18452
|
function instructionGraphSingleActionRepresentsText(graph, text) {
|
|
18036
18453
|
const normalized = normalizedInstructionSurface(text);
|
|
18037
18454
|
if (!normalized) return false;
|
|
@@ -18231,6 +18648,28 @@ function instructionGraphRichPrimaryAction(clause) {
|
|
|
18231
18648
|
return (rich || suppliesMissingHead) && (!dose || matchesDose(action));
|
|
18232
18649
|
});
|
|
18233
18650
|
}
|
|
18651
|
+
function instructionGraphRoundTripPrimaryAction(clause) {
|
|
18652
|
+
const graph = clause.instructionGraph;
|
|
18653
|
+
const primary = graph == null ? void 0 : graph.primaryAdministrationSpan;
|
|
18654
|
+
if (!graph || !primary) return void 0;
|
|
18655
|
+
return graph.actions.find((action) => {
|
|
18656
|
+
if (action.span.end <= primary.start || action.span.start >= primary.end) return false;
|
|
18657
|
+
const hasLocalRelation = relationHasGrammarFeature(action.relation, "roundtripRichRelation");
|
|
18658
|
+
const hasRichArgument = action.args.some(
|
|
18659
|
+
(arg) => [
|
|
18660
|
+
"time" /* Time */,
|
|
18661
|
+
"duration" /* Duration */,
|
|
18662
|
+
"material" /* Material */,
|
|
18663
|
+
"activity" /* Activity */,
|
|
18664
|
+
"result" /* Result */,
|
|
18665
|
+
"destination" /* Destination */,
|
|
18666
|
+
"substance" /* Substance */,
|
|
18667
|
+
"manner" /* Manner */
|
|
18668
|
+
].indexOf(arg.role) >= 0 || (arg.role === "object" /* Object */ || arg.role === "theme" /* Theme */) && /\b(?:new|replacement|another|fresh)\b/i.test(arg.text)
|
|
18669
|
+
);
|
|
18670
|
+
return hasLocalRelation || hasRichArgument;
|
|
18671
|
+
});
|
|
18672
|
+
}
|
|
18234
18673
|
function instructionGraphPrimaryAdministrationModality(clause) {
|
|
18235
18674
|
var _a26;
|
|
18236
18675
|
const graph = clause.instructionGraph;
|
|
@@ -19362,7 +19801,7 @@ function applyEnglishAdministrationModality(verb, clause) {
|
|
|
19362
19801
|
return `${prefix} ${verb.charAt(0).toLowerCase()}${verb.slice(1)}`;
|
|
19363
19802
|
}
|
|
19364
19803
|
function formatLong(clause, options) {
|
|
19365
|
-
var _a26, _b3, _c2, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _A, _B, _C, _D, _E, _F, _G, _H, _I, _J, _K, _L, _M, _N, _O, _P, _Q, _R, _S, _T, _U, _V, _W, _X
|
|
19804
|
+
var _a26, _b3, _c2, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _A, _B, _C, _D, _E, _F, _G, _H, _I, _J, _K, _L, _M, _N, _O, _P, _Q, _R, _S, _T, _U, _V, _W, _X;
|
|
19366
19805
|
const schedule = scheduleOf(clause);
|
|
19367
19806
|
const grammar = resolveRouteGrammar(clause);
|
|
19368
19807
|
const baseVerb = resolveMethodVerb(clause, grammar);
|
|
@@ -19490,36 +19929,19 @@ function formatLong(clause, options) {
|
|
|
19490
19929
|
const richGraphAdministrationSentence = richPrimaryGraphText ? formatPatientInstructionSentence(
|
|
19491
19930
|
[richPrimaryGraphText, ...graphRegimenTail].filter(Boolean).join(" ")
|
|
19492
19931
|
) : void 0;
|
|
19493
|
-
const primaryGraphAction = roundTrip
|
|
19494
|
-
var _a27;
|
|
19495
|
-
const primary = (_a27 = clause.instructionGraph) == null ? void 0 : _a27.primaryAdministrationSpan;
|
|
19496
|
-
if (!primary || action.span.end <= primary.start || action.span.start >= primary.end) return false;
|
|
19497
|
-
const hasLocalRelation = relationHasGrammarFeature(action.relation, "roundtripRichRelation");
|
|
19498
|
-
const hasRichArgument = action.args.some(
|
|
19499
|
-
(arg) => [
|
|
19500
|
-
"time" /* Time */,
|
|
19501
|
-
"duration" /* Duration */,
|
|
19502
|
-
"material" /* Material */,
|
|
19503
|
-
"activity" /* Activity */,
|
|
19504
|
-
"result" /* Result */,
|
|
19505
|
-
"destination" /* Destination */,
|
|
19506
|
-
"substance" /* Substance */,
|
|
19507
|
-
"manner" /* Manner */
|
|
19508
|
-
].indexOf(arg.role) >= 0 || (arg.role === "object" /* Object */ || arg.role === "theme" /* Theme */) && /\b(?:new|replacement|another|fresh)\b/i.test(arg.text)
|
|
19509
|
-
);
|
|
19510
|
-
return hasLocalRelation || hasRichArgument;
|
|
19511
|
-
}) : void 0;
|
|
19932
|
+
const primaryGraphAction = roundTrip ? instructionGraphRoundTripPrimaryAction(clause) : void 0;
|
|
19512
19933
|
const instructionPhrases = [];
|
|
19513
19934
|
const hasCodedAdditionalInstruction = Boolean(
|
|
19514
|
-
(
|
|
19935
|
+
(_s = clause.additionalInstructions) == null ? void 0 : _s.some((instruction) => {
|
|
19515
19936
|
var _a27;
|
|
19516
19937
|
return (_a27 = instruction.coding) == null ? void 0 : _a27.code;
|
|
19517
19938
|
})
|
|
19518
19939
|
);
|
|
19519
19940
|
const normalizeInstruction = (value) => value.toLowerCase().replace(/[\s,;:.()]+/g, " ").trim();
|
|
19520
|
-
const graphWarnings = (
|
|
19941
|
+
const graphWarnings = (_u = (_t = clause.instructionGraph) == null ? void 0 : _t.actions.filter(
|
|
19521
19942
|
(action) => action.polarity === "negate" /* Negate */
|
|
19522
|
-
)) != null ?
|
|
19943
|
+
)) != null ? _u : [];
|
|
19944
|
+
const positionedGraph = Boolean((_v = clause.instructionGraph) == null ? void 0 : _v.primaryAdministrationSpan);
|
|
19523
19945
|
const graphOwnedAdditional = ((_w = clause.additionalInstructions) != null ? _w : []).filter((instruction) => {
|
|
19524
19946
|
var _a27, _b4;
|
|
19525
19947
|
if (((_a27 = instruction.coding) == null ? void 0 : _a27.code) || !instruction.text || !clause.instructionGraph) return false;
|
|
@@ -19528,7 +19950,7 @@ function formatLong(clause, options) {
|
|
|
19528
19950
|
const source = normalizeInstruction(action.sourceText);
|
|
19529
19951
|
return source === normalized || source.includes(normalized) || normalized.includes(source);
|
|
19530
19952
|
});
|
|
19531
|
-
return instructionGraphRepresentsText(clause.instructionGraph, instruction.text) && (representedByWarning || !((_b4 = instruction.frames) == null ? void 0 : _b4.length) || !canonicalClauseHasAdministrationSemantics(clause) && instructionGraphSingleActionRepresentsText(clause.instructionGraph, instruction.text));
|
|
19953
|
+
return instructionGraphRepresentsText(clause.instructionGraph, instruction.text) && (representedByWarning || !((_b4 = instruction.frames) == null ? void 0 : _b4.length) || positionedGraph && instructionGraphSingleActionRepresentsText(clause.instructionGraph, instruction.text) && instructionGraphTextParticipatesInRelation(clause.instructionGraph, instruction.text) || !canonicalClauseHasAdministrationSemantics(clause) && instructionGraphSingleActionRepresentsText(clause.instructionGraph, instruction.text));
|
|
19532
19954
|
});
|
|
19533
19955
|
const additionalForDirectRendering = ((_x = clause.additionalInstructions) != null ? _x : []).filter(
|
|
19534
19956
|
(instruction) => graphOwnedAdditional.indexOf(instruction) === -1 && instruction !== integratedThinLayer
|
|
@@ -19555,7 +19977,6 @@ function formatLong(clause, options) {
|
|
|
19555
19977
|
});
|
|
19556
19978
|
})
|
|
19557
19979
|
);
|
|
19558
|
-
const positionedGraph = Boolean((_A = clause.instructionGraph) == null ? void 0 : _A.primaryAdministrationSpan);
|
|
19559
19980
|
const positionedRoundTrip = Boolean(roundTrip && positionedGraph);
|
|
19560
19981
|
const graphWholeInstruction = clause.instructionGraph && !positionedGraph && !hasCodedAdditionalInstruction && allAdditionalRepresentedByGraphWarnings ? realizeInstructionGraph(clause.instructionGraph, "en", {
|
|
19561
19982
|
includeWarnings: true,
|
|
@@ -19602,18 +20023,18 @@ function formatLong(clause, options) {
|
|
|
19602
20023
|
omitSourceTexts: postGraphOmissions,
|
|
19603
20024
|
position: "post"
|
|
19604
20025
|
}) : void 0;
|
|
19605
|
-
const graphInstruction = (
|
|
20026
|
+
const graphInstruction = (_A = graphWholeInstruction != null ? graphWholeInstruction : postGraphInstruction) != null ? _A : !positionedGraph && clause.instructionGraph && instructionGraphHasNovelNonWarningContent(clause.instructionGraph, representedInstructionTexts) ? realizeInstructionGraph(clause.instructionGraph, "en", {
|
|
19606
20027
|
includeWarnings: false,
|
|
19607
20028
|
omitCanonicalAdministration: clause,
|
|
19608
20029
|
preferSourceText: roundTrip,
|
|
19609
20030
|
roundtripSafe: roundTrip,
|
|
19610
20031
|
omitSourceTexts: postGraphOmissions
|
|
19611
20032
|
}) : void 0;
|
|
19612
|
-
const primarySpanForFlow = (
|
|
19613
|
-
const graphActionsForFlow = (
|
|
20033
|
+
const primarySpanForFlow = (_B = clause.instructionGraph) == null ? void 0 : _B.primaryAdministrationSpan;
|
|
20034
|
+
const graphActionsForFlow = (_D = (_C = clause.instructionGraph) == null ? void 0 : _C.actions) != null ? _D : [];
|
|
19614
20035
|
const lastPreActionForFlow = primarySpanForFlow ? graphActionsForFlow.filter((action) => action.span.end <= primarySpanForFlow.start).sort((a, b) => b.span.end - a.span.end)[0] : void 0;
|
|
19615
20036
|
const firstPostActionForFlow = primarySpanForFlow ? graphActionsForFlow.filter((action) => action.span.start >= primarySpanForFlow.end).sort((a, b) => a.span.start - b.span.start)[0] : void 0;
|
|
19616
|
-
const graphFlowSource = (
|
|
20037
|
+
const graphFlowSource = (_F = (_E = clause.instructionGraph) == null ? void 0 : _E.sourceText) != null ? _F : clause.rawText;
|
|
19617
20038
|
const noStrongBoundaryForFlow = (start, end) => !/[.!?;]/u.test(graphFlowSource.slice(start, end));
|
|
19618
20039
|
const preFlowsIntoAdministration = Boolean(
|
|
19619
20040
|
!roundTrip && preGraphInstruction && primarySpanForFlow && lastPreActionForFlow && lastPreActionForFlow.polarity !== "negate" /* Negate */ && noStrongBoundaryForFlow(lastPreActionForFlow.span.end, primarySpanForFlow.start)
|
|
@@ -19629,9 +20050,9 @@ function formatLong(clause, options) {
|
|
|
19629
20050
|
);
|
|
19630
20051
|
if (patientInstruction) instructionPhrases.push(patientInstruction);
|
|
19631
20052
|
const trailingInstructionText = instructionPhrases.join(" ").trim() || void 0;
|
|
19632
|
-
const hasExplicitMethod = Boolean(((
|
|
19633
|
-
const graphSourceIsEnglish = !((
|
|
19634
|
-
if (roundTrip && !hasExplicitMethod && graphSourceIsEnglish && ((
|
|
20053
|
+
const hasExplicitMethod = Boolean(((_H = (_G = clause.method) == null ? void 0 : _G.text) == null ? void 0 : _H.trim()) || ((_J = (_I = clause.method) == null ? void 0 : _I.coding) == null ? void 0 : _J.code));
|
|
20054
|
+
const graphSourceIsEnglish = !((_K = clause.instructionGraph) == null ? void 0 : _K.sourceLocale) || !clause.instructionGraph.sourceLocale.toLowerCase().startsWith("th");
|
|
20055
|
+
if (roundTrip && !hasExplicitMethod && graphSourceIsEnglish && ((_L = clause.instructionGraph) == null ? void 0 : _L.sourceText.trim())) {
|
|
19635
20056
|
return clause.instructionGraph.sourceText.trim();
|
|
19636
20057
|
}
|
|
19637
20058
|
if (!canonicalClauseHasAdministrationSemantics(clause)) {
|
|
@@ -19641,10 +20062,20 @@ function formatLong(clause, options) {
|
|
|
19641
20062
|
roundtripSafe: roundTrip
|
|
19642
20063
|
}) : void 0;
|
|
19643
20064
|
const wholeGraphText = formatPatientInstructionSentence(wholeGraph);
|
|
19644
|
-
|
|
20065
|
+
const parts = [];
|
|
20066
|
+
for (const value of [wholeGraphText, ...instructionPhrases]) {
|
|
20067
|
+
if (!value) continue;
|
|
20068
|
+
const normalized = normalizeInstruction(value);
|
|
20069
|
+
if (parts.some((existing) => {
|
|
20070
|
+
const candidate = normalizeInstruction(existing);
|
|
20071
|
+
return candidate === normalized || candidate.includes(normalized) || normalized.includes(candidate);
|
|
20072
|
+
})) continue;
|
|
20073
|
+
parts.push(value);
|
|
20074
|
+
}
|
|
20075
|
+
return parts.join(" ").trim() || `${verb}.`;
|
|
19645
20076
|
}
|
|
19646
20077
|
const leadingInstructionText = preFlowsIntoAdministration ? void 0 : preGraphInstruction ? formatPatientInstructionSentence(preGraphInstruction) : void 0;
|
|
19647
|
-
const graphRepresentsDose = !clause.dose || Boolean((
|
|
20078
|
+
const graphRepresentsDose = !clause.dose || Boolean((_M = clause.instructionGraph) == null ? void 0 : _M.actions.some(
|
|
19648
20079
|
(action) => action.args.some(
|
|
19649
20080
|
(arg) => {
|
|
19650
20081
|
var _a27, _b4, _c3, _d2, _e2, _f2, _g2, _h2, _i2, _j2, _k2, _l2;
|
|
@@ -19653,26 +20084,26 @@ function formatLong(clause, options) {
|
|
|
19653
20084
|
)
|
|
19654
20085
|
));
|
|
19655
20086
|
const hasAdministrationTiming = Boolean(
|
|
19656
|
-
schedule.frequency !== void 0 || schedule.frequencyMax !== void 0 || schedule.period !== void 0 || schedule.periodMax !== void 0 || ((
|
|
20087
|
+
schedule.frequency !== void 0 || schedule.frequencyMax !== void 0 || schedule.period !== void 0 || schedule.periodMax !== void 0 || ((_N = schedule.when) == null ? void 0 : _N.length) || ((_O = schedule.dayOfWeek) == null ? void 0 : _O.length) || ((_P = schedule.timeOfDay) == null ? void 0 : _P.length) || schedule.count !== void 0 || schedule.countMax !== void 0 || schedule.timingCode || schedule.duration !== void 0 || schedule.durationMax !== void 0 || schedule.durationUnit !== void 0 || schedule.offset !== void 0 || schedule.offsetMin !== void 0 || schedule.offsetMax !== void 0 || Boolean((_Q = schedule.activityTiming) == null ? void 0 : _Q.length) || schedule.occurrenceCap !== void 0
|
|
19657
20088
|
);
|
|
19658
20089
|
const graphCanStandAlone = Boolean(
|
|
19659
|
-
!hasExplicitMethod && trailingInstructionText && ((
|
|
20090
|
+
!hasExplicitMethod && trailingInstructionText && ((_R = clause.instructionGraph) == null ? void 0 : _R.actions.length) && !clause.route && !clause.site && !hasAdministrationTiming && graphRepresentsDose
|
|
19660
20091
|
);
|
|
19661
20092
|
if (graphCanStandAlone) return trailingInstructionText;
|
|
19662
20093
|
const primarySourceSentence = primaryGraphAction ? formatPatientInstructionSentence(primaryGraphAction.sourceText) : void 0;
|
|
19663
|
-
const primaryActionIndex = primaryGraphAction ? (
|
|
19664
|
-
const entersPrimaryWithThen = primaryActionIndex !== void 0 && primaryActionIndex >= 0 ? (
|
|
20094
|
+
const primaryActionIndex = primaryGraphAction ? (_S = clause.instructionGraph) == null ? void 0 : _S.actions.indexOf(primaryGraphAction) : void 0;
|
|
20095
|
+
const entersPrimaryWithThen = primaryActionIndex !== void 0 && primaryActionIndex >= 0 ? (_U = (_T = clause.instructionGraph) == null ? void 0 : _T.relations) == null ? void 0 : _U.some(
|
|
19665
20096
|
(relation) => relationHasSemanticClass(relation.kind, "sequence") && relation.toActionIndex === primaryActionIndex && relation.fromActionIndex !== void 0
|
|
19666
20097
|
) : false;
|
|
19667
20098
|
const richPrimaryActionIndex = richPrimaryGraphAction && clause.instructionGraph ? clause.instructionGraph.actions.indexOf(richPrimaryGraphAction) : -1;
|
|
19668
20099
|
const graphContinuesWithThen = richPrimaryActionIndex >= 0 && Boolean(
|
|
19669
|
-
(
|
|
20100
|
+
(_W = (_V = clause.instructionGraph) == null ? void 0 : _V.relations) == null ? void 0 : _W.some(
|
|
19670
20101
|
(relation) => relationHasSemanticClass(relation.kind, "sequence") && relation.fromActionIndex === richPrimaryActionIndex
|
|
19671
20102
|
)
|
|
19672
20103
|
);
|
|
19673
20104
|
const sequenceRelation = getUniqueAdviceRelationByGrammarFeature("defaultSequenceRelation");
|
|
19674
20105
|
if (!sequenceRelation) throw new Error("Missing declarative default sequence relation");
|
|
19675
|
-
const sequenceSurface = (
|
|
20106
|
+
const sequenceSurface = (_X = localizeAdviceRelation(sequenceRelation, "en")) != null ? _X : sequenceRelation;
|
|
19676
20107
|
const compose = (base) => {
|
|
19677
20108
|
var _a27;
|
|
19678
20109
|
let effectiveBase = (_a27 = richGraphAdministrationSentence != null ? richGraphAdministrationSentence : primarySourceSentence) != null ? _a27 : base;
|
|
@@ -19818,8 +20249,8 @@ var advice_terminology_default = {
|
|
|
19818
20249
|
{ surface: "drive", lemma: "drive", partOfSpeech: "verb", semanticClass: "activity" },
|
|
19819
20250
|
{ surface: "driving", lemma: "drive", partOfSpeech: "verb", semanticClass: "activity" },
|
|
19820
20251
|
{ surface: "eat", lemma: "eat", partOfSpeech: "verb", semanticClass: "ingest" },
|
|
19821
|
-
{ surface: "cause", lemma: "cause", partOfSpeech: "verb", semanticClass: "effect", realizerProfile: "effect" },
|
|
19822
|
-
{ surface: "causes", lemma: "cause", partOfSpeech: "verb", semanticClass: "effect" },
|
|
20252
|
+
{ surface: "cause", lemma: "cause", partOfSpeech: "verb", semanticClass: "effect", realizerProfile: "effect", i18n: { th: "\u0E17\u0E33\u0E43\u0E2B\u0E49\u0E40\u0E01\u0E34\u0E14" } },
|
|
20253
|
+
{ surface: "causes", lemma: "cause", partOfSpeech: "verb", semanticClass: "effect", realizerProfile: "effect", i18n: { th: "\u0E17\u0E33\u0E43\u0E2B\u0E49\u0E40\u0E01\u0E34\u0E14" } },
|
|
19823
20254
|
{ surface: "use", lemma: "use", partOfSpeech: "verb", semanticClass: "administration" },
|
|
19824
20255
|
{ surface: "take", lemma: "take", partOfSpeech: "verb", semanticClass: "administration" },
|
|
19825
20256
|
{ surface: "apply", lemma: "apply", partOfSpeech: "verb", semanticClass: "administration" },
|
|
@@ -20653,6 +21084,7 @@ function mapSemanticClassToRole(semanticClass) {
|
|
|
20653
21084
|
return (_a26 = enumValue(AdviceArgumentRole, configured)) != null ? _a26 : "object" /* Object */;
|
|
20654
21085
|
}
|
|
20655
21086
|
function classifyArgument(text) {
|
|
21087
|
+
var _a26, _b3, _c2, _d, _e;
|
|
20656
21088
|
const cleaned = cleanFreeText(text);
|
|
20657
21089
|
const normalized = normalizeAdditionalInstructionKey(cleaned);
|
|
20658
21090
|
if (!normalized) {
|
|
@@ -20667,6 +21099,21 @@ function classifyArgument(text) {
|
|
|
20667
21099
|
concept.conceptId
|
|
20668
21100
|
);
|
|
20669
21101
|
}
|
|
21102
|
+
const symptom = resolveSymptomDefinition(normalized);
|
|
21103
|
+
if (symptom) {
|
|
21104
|
+
const coding = symptom.coding ? __spreadValues({}, symptom.coding) : void 0;
|
|
21105
|
+
return {
|
|
21106
|
+
role: "object" /* Object */,
|
|
21107
|
+
text: cleaned,
|
|
21108
|
+
normalized: (_b3 = (_a26 = symptom.text) == null ? void 0 : _a26.toLowerCase()) != null ? _b3 : normalized,
|
|
21109
|
+
conceptId: (_d = (_c2 = coding == null ? void 0 : coding.code) != null ? _c2 : symptom.text) != null ? _d : normalized,
|
|
21110
|
+
coding,
|
|
21111
|
+
codings: coding ? [coding] : void 0,
|
|
21112
|
+
i18n: __spreadValues({
|
|
21113
|
+
en: symptom.text ? symptom.text.charAt(0).toLowerCase() + symptom.text.slice(1) : cleaned
|
|
21114
|
+
}, (_e = symptom.i18n) != null ? _e : {})
|
|
21115
|
+
};
|
|
21116
|
+
}
|
|
20670
21117
|
const parts = normalized.split(" ");
|
|
20671
21118
|
if (parts.length >= 2) {
|
|
20672
21119
|
const first = parts[0];
|
|
@@ -21306,8 +21753,9 @@ var AVOIDANCE_ADVICE_PREDICATE_REALIZER = ({ frame, argText, modalityText }) =>
|
|
|
21306
21753
|
};
|
|
21307
21754
|
var EFFECT_ADVICE_PREDICATE_REALIZER = ({ frame, argText, modalityText }) => {
|
|
21308
21755
|
const effectiveModality = modalityText != null ? modalityText : capitalizeSentence("may" /* May */);
|
|
21309
|
-
const
|
|
21310
|
-
|
|
21756
|
+
const thai = /[\u0E00-\u0E7F]/u.test(frame.predicate.lemma);
|
|
21757
|
+
const predicate = thai ? `${effectiveModality}${frame.predicate.lemma}` : `${effectiveModality} ${frame.predicate.lemma}`;
|
|
21758
|
+
return argText ? `${predicate}${thai ? "" : " "}${argText}` : predicate;
|
|
21311
21759
|
};
|
|
21312
21760
|
var ADVICE_PREDICATE_REALIZERS = {
|
|
21313
21761
|
default: DEFAULT_ADVICE_PREDICATE_REALIZER,
|
|
@@ -24986,7 +25434,7 @@ function buildRoutePhraseThai(clause, grammar, hasSite) {
|
|
|
24986
25434
|
return text;
|
|
24987
25435
|
}
|
|
24988
25436
|
function formatSiteThai(clause, grammar) {
|
|
24989
|
-
var _a26, _b3, _c2, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x;
|
|
25437
|
+
var _a26, _b3, _c2, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _A, _B;
|
|
24990
25438
|
const text = ((_b3 = (_a26 = clause.site) == null ? void 0 : _a26.text) == null ? void 0 : _b3.trim()) || ((_e = (_d = (_c2 = clause.site) == null ? void 0 : _c2.coding) == null ? void 0 : _d.display) == null ? void 0 : _e.trim());
|
|
24991
25439
|
const lower = text == null ? void 0 : text.toLowerCase();
|
|
24992
25440
|
const codingCode = (_g = (_f = clause.site) == null ? void 0 : _f.coding) == null ? void 0 : _g.code;
|
|
@@ -25001,20 +25449,22 @@ function formatSiteThai(clause, grammar) {
|
|
|
25001
25449
|
if (isVaginalRoute && isVaginaSite) {
|
|
25002
25450
|
return void 0;
|
|
25003
25451
|
}
|
|
25004
|
-
const
|
|
25452
|
+
const resolvedSite = text ? resolveBodySitePhrase(text) : void 0;
|
|
25453
|
+
const structuralTranslation = ((_l = clause.site) == null ? void 0 : _l.spatialRelation) || (resolvedSite == null ? void 0 : resolvedSite.features.qualifier) ? text ? translateSiteThai(text, codingCode, (_m = clause.site) == null ? void 0 : _m.spatialRelation) : translateSpatialSiteThai(void 0, (_n = clause.site) == null ? void 0 : _n.spatialRelation) : void 0;
|
|
25454
|
+
const translated = (_y = (_v = (_r = (_o = perTargetSiteThai(clause)) != null ? _o : structuralTranslation) != null ? _r : (_q = (_p = clause.site) == null ? void 0 : _p.i18n) == null ? void 0 : _q.th) != null ? _v : (_u = (_t = (_s = clause.site) == null ? void 0 : _s.coding) == null ? void 0 : _t.i18n) == null ? void 0 : _u.th) != null ? _y : text ? translateSiteThai(text, codingCode, (_w = clause.site) == null ? void 0 : _w.spatialRelation) : translateSpatialSiteThai(void 0, (_x = clause.site) == null ? void 0 : _x.spatialRelation);
|
|
25005
25455
|
if (!translated) {
|
|
25006
25456
|
return void 0;
|
|
25007
25457
|
}
|
|
25008
|
-
if (((
|
|
25458
|
+
if (((_z = clause.route) == null ? void 0 : _z.code) === RouteCode["Nasal route"]) {
|
|
25009
25459
|
return `\u0E40\u0E02\u0E49\u0E32${translated}`;
|
|
25010
25460
|
}
|
|
25011
|
-
const spatialRelation = (
|
|
25461
|
+
const spatialRelation = (_A = clause.site) == null ? void 0 : _A.spatialRelation;
|
|
25012
25462
|
const spatialRealization = (spatialRelation == null ? void 0 : spatialRelation.relationText) ? getBodySiteRelationRealization(spatialRelation.relationText, "th") : void 0;
|
|
25013
25463
|
const spatialTargetThai = spatialRelation ? translateSpatialTargetThai(spatialRelation) : void 0;
|
|
25014
25464
|
if (spatialRealization && (spatialRealization.omitOuterSitePreposition || (spatialTargetThai == null ? void 0 : spatialTargetThai.startsWith("\u0E1A\u0E23\u0E34\u0E40\u0E27\u0E13")))) {
|
|
25015
25465
|
return translated;
|
|
25016
25466
|
}
|
|
25017
|
-
const preposition = (
|
|
25467
|
+
const preposition = (_B = grammar.sitePreposition) != null ? _B : "\u0E17\u0E35\u0E48";
|
|
25018
25468
|
if (translated.startsWith(preposition)) {
|
|
25019
25469
|
return translated;
|
|
25020
25470
|
}
|
|
@@ -25058,6 +25508,18 @@ function translateSpatialSiteThai(site, relation) {
|
|
|
25058
25508
|
}
|
|
25059
25509
|
return realization.strategy === "suffix" ? `${target}${realization.surface}` : `${realization.surface}${target}`;
|
|
25060
25510
|
}
|
|
25511
|
+
function appendBodySiteQualifierThai(base, qualifier) {
|
|
25512
|
+
var _a26, _b3, _c2, _d;
|
|
25513
|
+
if (!qualifier) return base;
|
|
25514
|
+
const realization = getBodySiteRelationRealization(qualifier.relation, "th");
|
|
25515
|
+
if (!realization) return base;
|
|
25516
|
+
const relation = realization.surface;
|
|
25517
|
+
if (qualifier.kind === "symptom") {
|
|
25518
|
+
return `${base}${relation}${(_b3 = (_a26 = qualifier.i18n) == null ? void 0 : _a26.th) != null ? _b3 : qualifier.text}`;
|
|
25519
|
+
}
|
|
25520
|
+
const target = (_d = translateSiteThai(qualifier.targetText, (_c2 = qualifier.targetCoding) == null ? void 0 : _c2.code)) != null ? _d : qualifier.targetText;
|
|
25521
|
+
return `${base}${relation}${target}`;
|
|
25522
|
+
}
|
|
25061
25523
|
function translateSiteThai(site, code, spatialRelation) {
|
|
25062
25524
|
if (!site) {
|
|
25063
25525
|
if (code) {
|
|
@@ -25069,25 +25531,28 @@ function translateSiteThai(site, code, spatialRelation) {
|
|
|
25069
25531
|
if (!normalized) {
|
|
25070
25532
|
return site;
|
|
25071
25533
|
}
|
|
25534
|
+
const resolvedPhrase = resolveBodySitePhrase(site);
|
|
25535
|
+
const qualifier = resolvedPhrase == null ? void 0 : resolvedPhrase.features.qualifier;
|
|
25536
|
+
const qualified = (value) => appendBodySiteQualifierThai(value, qualifier);
|
|
25072
25537
|
const spatial = translateSpatialSiteThai(site, spatialRelation);
|
|
25073
25538
|
if (spatial) {
|
|
25074
|
-
return spatial;
|
|
25539
|
+
return qualified(spatial);
|
|
25075
25540
|
}
|
|
25076
25541
|
if (code) {
|
|
25077
25542
|
const translatedByCode = THAI_SITE_CODE_TRANSLATIONS[code];
|
|
25078
25543
|
if (translatedByCode) {
|
|
25079
|
-
return translatedByCode;
|
|
25544
|
+
return qualified(translatedByCode);
|
|
25080
25545
|
}
|
|
25081
25546
|
}
|
|
25082
25547
|
const definitionTranslation = THAI_SITE_DEFINITION_TRANSLATIONS[normalized];
|
|
25083
25548
|
if (definitionTranslation) {
|
|
25084
|
-
return definitionTranslation;
|
|
25549
|
+
return qualified(definitionTranslation);
|
|
25085
25550
|
}
|
|
25086
25551
|
const direct = THAI_SITE_TRANSLATIONS[normalized];
|
|
25087
25552
|
if (direct) {
|
|
25088
|
-
return direct;
|
|
25553
|
+
return qualified(direct);
|
|
25089
25554
|
}
|
|
25090
|
-
return site;
|
|
25555
|
+
return qualified(site);
|
|
25091
25556
|
}
|
|
25092
25557
|
function describeDayOfWeekThai(schedule) {
|
|
25093
25558
|
var _a26;
|
|
@@ -25414,7 +25879,7 @@ function formatLongThai(clause, options) {
|
|
|
25414
25879
|
segments.push(sitePart);
|
|
25415
25880
|
}
|
|
25416
25881
|
const body = segments.filter(Boolean).join(" ").replace(/\s+/g, " ").trim();
|
|
25417
|
-
const richPrimaryGraphAction = (options == null ? void 0 : options.realizationMode)
|
|
25882
|
+
const richPrimaryGraphAction = (options == null ? void 0 : options.realizationMode) === "roundtrip" ? instructionGraphRoundTripPrimaryAction(clause) : instructionGraphRichPrimaryAction(clause);
|
|
25418
25883
|
const richPrimaryGraphText = richPrimaryGraphAction ? realizeInstructionAction(richPrimaryGraphAction, "th") : void 0;
|
|
25419
25884
|
const richPrimaryHasSite = Boolean(
|
|
25420
25885
|
richPrimaryGraphAction == null ? void 0 : richPrimaryGraphAction.args.some((arg) => arg.role === "site" /* Site */)
|
|
@@ -25451,7 +25916,8 @@ function formatLongThai(clause, options) {
|
|
|
25451
25916
|
}
|
|
25452
25917
|
const richGraphAdministrationText = richPrimaryGraphText ? [richPrimaryGraphText, ...graphRegimenTail].filter(Boolean).join(" ").replace(/\s+/g, " ").trim() : void 0;
|
|
25453
25918
|
const roundTrip = (options == null ? void 0 : options.realizationMode) === "roundtrip";
|
|
25454
|
-
const
|
|
25919
|
+
const positionedGraph = Boolean((_k = clause.instructionGraph) == null ? void 0 : _k.primaryAdministrationSpan);
|
|
25920
|
+
const graphOwnedAdditional = ((_l = clause.additionalInstructions) != null ? _l : []).filter((instruction) => {
|
|
25455
25921
|
var _a27, _b4;
|
|
25456
25922
|
if (((_a27 = instruction.coding) == null ? void 0 : _a27.code) || !instruction.text || !clause.instructionGraph) return false;
|
|
25457
25923
|
const normalized = instruction.text.toLowerCase().replace(/[\s,;:.()]+/g, " ").trim();
|
|
@@ -25459,9 +25925,9 @@ function formatLongThai(clause, options) {
|
|
|
25459
25925
|
const source = action.sourceText.toLowerCase().replace(/[\s,;:.()]+/g, " ").trim();
|
|
25460
25926
|
return source === normalized || source.includes(normalized) || normalized.includes(source);
|
|
25461
25927
|
});
|
|
25462
|
-
return instructionGraphRepresentsText(clause.instructionGraph, instruction.text) && (representedByWarning || !((_b4 = instruction.frames) == null ? void 0 : _b4.length) || !canonicalClauseHasAdministrationSemantics(clause) && instructionGraphSingleActionRepresentsText(clause.instructionGraph, instruction.text));
|
|
25928
|
+
return instructionGraphRepresentsText(clause.instructionGraph, instruction.text) && (representedByWarning || !((_b4 = instruction.frames) == null ? void 0 : _b4.length) || positionedGraph && instructionGraphSingleActionRepresentsText(clause.instructionGraph, instruction.text) && instructionGraphTextParticipatesInRelation(clause.instructionGraph, instruction.text) || !canonicalClauseHasAdministrationSemantics(clause) && instructionGraphSingleActionRepresentsText(clause.instructionGraph, instruction.text));
|
|
25463
25929
|
});
|
|
25464
|
-
const directAdditional = ((
|
|
25930
|
+
const directAdditional = ((_m = clause.additionalInstructions) != null ? _m : []).filter(
|
|
25465
25931
|
(instruction) => graphOwnedAdditional.indexOf(instruction) === -1 && !integratedQualifiers.has(instruction)
|
|
25466
25932
|
);
|
|
25467
25933
|
const additionalSemanticSourceTexts = directAdditional.map((instruction) => {
|
|
@@ -25469,14 +25935,13 @@ function formatLongThai(clause, options) {
|
|
|
25469
25935
|
return (_a27 = instruction.text) == null ? void 0 : _a27.trim();
|
|
25470
25936
|
}).filter((text) => Boolean(text));
|
|
25471
25937
|
for (const instruction of directAdditional) {
|
|
25472
|
-
for (const frame of (
|
|
25473
|
-
const source = (
|
|
25938
|
+
for (const frame of (_n = instruction.frames) != null ? _n : []) {
|
|
25939
|
+
const source = (_o = frame.sourceText) == null ? void 0 : _o.trim();
|
|
25474
25940
|
if (source && additionalSemanticSourceTexts.indexOf(source) === -1) {
|
|
25475
25941
|
additionalSemanticSourceTexts.push(source);
|
|
25476
25942
|
}
|
|
25477
25943
|
}
|
|
25478
25944
|
}
|
|
25479
|
-
const positionedGraph = Boolean((_o = clause.instructionGraph) == null ? void 0 : _o.primaryAdministrationSpan);
|
|
25480
25945
|
const graphRealizationOmissions = richPrimaryGraphAction ? [...additionalSemanticSourceTexts, richPrimaryGraphAction.sourceText] : additionalSemanticSourceTexts;
|
|
25481
25946
|
const graphRealizationOptions = {
|
|
25482
25947
|
includeWarnings: true,
|
|
@@ -25538,7 +26003,24 @@ function formatLongThai(clause, options) {
|
|
|
25538
26003
|
roundtripSafe: roundTrip
|
|
25539
26004
|
}) : void 0;
|
|
25540
26005
|
const wholeGraphText = formatPatientInstructionSentence2(wholeGraph);
|
|
25541
|
-
|
|
26006
|
+
const parts = [];
|
|
26007
|
+
const normalizedInstruction2 = (value) => value.toLowerCase().replace(/[\s,;:.()]+/gu, " ").trim();
|
|
26008
|
+
for (const value of [
|
|
26009
|
+
leadingInstructionText,
|
|
26010
|
+
wholeGraphText,
|
|
26011
|
+
directInstruction,
|
|
26012
|
+
graphInstructionText,
|
|
26013
|
+
fallbackPatientInstruction
|
|
26014
|
+
]) {
|
|
26015
|
+
if (!value) continue;
|
|
26016
|
+
const normalized = normalizedInstruction2(value);
|
|
26017
|
+
if (parts.some((existing) => {
|
|
26018
|
+
const candidate = normalizedInstruction2(existing);
|
|
26019
|
+
return candidate === normalized || candidate.includes(normalized) || normalized.includes(candidate);
|
|
26020
|
+
})) continue;
|
|
26021
|
+
parts.push(value);
|
|
26022
|
+
}
|
|
26023
|
+
return parts.join(" ").trim() || `${verb}.`;
|
|
25542
26024
|
}
|
|
25543
26025
|
const hasExplicitMethod = Boolean(((_z = (_y = clause.method) == null ? void 0 : _y.text) == null ? void 0 : _z.trim()) || ((_B = (_A = clause.method) == null ? void 0 : _A.coding) == null ? void 0 : _B.code));
|
|
25544
26026
|
const graphRepresentsDose = !clause.dose || Boolean((_C = clause.instructionGraph) == null ? void 0 : _C.actions.some(
|
|
@@ -27134,19 +27616,45 @@ function unifySynsem(left, right, context) {
|
|
|
27134
27616
|
}
|
|
27135
27617
|
};
|
|
27136
27618
|
}
|
|
27619
|
+
function hasDailyFrequencyDefaultEvidence(sign) {
|
|
27620
|
+
return sign.evidence.some((item) => item.scheduleDefault === "daily-frequency");
|
|
27621
|
+
}
|
|
27622
|
+
function schedulePeriodMatches(left, right) {
|
|
27623
|
+
return left.period !== void 0 && right.period !== void 0 && left.period === right.period && left.periodUnit !== void 0 && left.periodUnit === right.periodUnit;
|
|
27624
|
+
}
|
|
27625
|
+
function refinedDailyCadenceSynsem(cadenceSign, explicitSign) {
|
|
27626
|
+
const cadence = cadenceSign.synsem.head.schedule;
|
|
27627
|
+
const explicit = explicitSign.synsem.head.schedule;
|
|
27628
|
+
if (!cadence || !explicit || !hasDailyFrequencyDefaultEvidence(cadenceSign)) return void 0;
|
|
27629
|
+
if (cadence.frequency !== 1 || explicit.frequency === void 0 || explicit.frequency === 1) return void 0;
|
|
27630
|
+
if (!schedulePeriodMatches(cadence, explicit)) return void 0;
|
|
27631
|
+
return __spreadProps(__spreadValues({}, cadenceSign.synsem), {
|
|
27632
|
+
head: __spreadProps(__spreadValues({}, cadenceSign.synsem.head), {
|
|
27633
|
+
schedule: __spreadProps(__spreadValues({}, cadence), { frequency: void 0, timingCode: void 0 })
|
|
27634
|
+
})
|
|
27635
|
+
});
|
|
27636
|
+
}
|
|
27637
|
+
function scheduleRefinementSynsems(left, right) {
|
|
27638
|
+
const refinedLeft = refinedDailyCadenceSynsem(left, right);
|
|
27639
|
+
if (refinedLeft) return { left: refinedLeft, right: right.synsem, refined: true };
|
|
27640
|
+
const refinedRight = refinedDailyCadenceSynsem(right, left);
|
|
27641
|
+
if (refinedRight) return { left: left.synsem, right: refinedRight, refined: true };
|
|
27642
|
+
return { left: left.synsem, right: right.synsem, refined: false };
|
|
27643
|
+
}
|
|
27137
27644
|
function combineSigns(left, right, context, rule) {
|
|
27138
27645
|
const selectedConstruction = selectHpsgConstruction(left, right);
|
|
27139
27646
|
if (!selectedConstruction) return void 0;
|
|
27140
27647
|
const target = selectedConstruction.construction.headSide === "left" ? left : right;
|
|
27141
27648
|
const condition = selectedConstruction.construction.headSide === "left" ? right : left;
|
|
27142
|
-
const
|
|
27649
|
+
const refinement = scheduleRefinementSynsems(left, right);
|
|
27650
|
+
const synsem = selectedConstruction.construction.operation === "scope" ? scopeSynsem(condition, target) : unifySynsem(refinement.left, refinement.right, context);
|
|
27143
27651
|
if (!synsem) return void 0;
|
|
27144
27652
|
const fs = combineSignFeatureStructures(
|
|
27145
27653
|
left.fs,
|
|
27146
27654
|
right.fs,
|
|
27147
27655
|
selectedConstruction.motherType,
|
|
27148
27656
|
selectedConstruction.construction.headSide,
|
|
27149
|
-
selectedConstruction.construction.operation === "scope" ? synsem : void 0
|
|
27657
|
+
selectedConstruction.construction.operation === "scope" || refinement.refined ? synsem : void 0
|
|
27150
27658
|
);
|
|
27151
27659
|
if (!fs) {
|
|
27152
27660
|
return void 0;
|
|
@@ -27642,117 +28150,6 @@ function getPrimarySiteMeaningCandidate(token) {
|
|
|
27642
28150
|
return candidates && candidates.length > 0 ? candidates[0] : void 0;
|
|
27643
28151
|
}
|
|
27644
28152
|
|
|
27645
|
-
// src/hpsg/timing-lexicon.ts
|
|
27646
|
-
var EVERY_INTERVAL_TOKENS = EVERY_INTERVAL_TOKENS_DATA;
|
|
27647
|
-
var COUNT_MARKER_TOKENS = COUNT_MARKER_TOKENS_DATA;
|
|
27648
|
-
var FREQUENCY_SIMPLE_WORDS = FREQUENCY_SIMPLE_WORDS_DATA;
|
|
27649
|
-
var FREQUENCY_NUMBER_WORDS = FREQUENCY_NUMBER_WORDS_DATA;
|
|
27650
|
-
var FREQUENCY_TIMES_WORDS = FREQUENCY_TIMES_WORDS_DATA;
|
|
27651
|
-
var FREQUENCY_CONNECTOR_WORDS = FREQUENCY_CONNECTOR_WORDS_DATA;
|
|
27652
|
-
function mapPeriodUnitLabel(label) {
|
|
27653
|
-
return FhirPeriodUnit[label];
|
|
27654
|
-
}
|
|
27655
|
-
var FREQUENCY_ADVERB_UNITS = new Map(
|
|
27656
|
-
Array.from(FREQUENCY_ADVERB_UNITS_DATA.entries()).map(([token, label]) => [token, mapPeriodUnitLabel(label)]).filter((entry) => Boolean(entry[1]))
|
|
27657
|
-
);
|
|
27658
|
-
var INTERVAL_UNITS = new Map(
|
|
27659
|
-
Array.from(INTERVAL_UNIT_TOKENS_DATA.entries()).map(([token, label]) => [token, mapPeriodUnitLabel(label)]).filter((entry) => Boolean(entry[1]))
|
|
27660
|
-
);
|
|
27661
|
-
function normalizePeriodValue(value, unit) {
|
|
27662
|
-
if (unit === "h" /* Hour */ && (!Number.isInteger(value) || value < 1)) {
|
|
27663
|
-
return { value: Math.round(value * 60 * 1e3) / 1e3, unit: "min" /* Minute */ };
|
|
27664
|
-
}
|
|
27665
|
-
return { value, unit };
|
|
27666
|
-
}
|
|
27667
|
-
function normalizePeriodRange(low, high, unit) {
|
|
27668
|
-
if (unit === "h" /* Hour */ && (!Number.isInteger(low) || !Number.isInteger(high) || low < 1 || high < 1)) {
|
|
27669
|
-
return {
|
|
27670
|
-
low: Math.round(low * 60 * 1e3) / 1e3,
|
|
27671
|
-
high: Math.round(high * 60 * 1e3) / 1e3,
|
|
27672
|
-
unit: "min" /* Minute */
|
|
27673
|
-
};
|
|
27674
|
-
}
|
|
27675
|
-
return { low, high, unit };
|
|
27676
|
-
}
|
|
27677
|
-
function periodUnitSuffix(unit) {
|
|
27678
|
-
switch (unit) {
|
|
27679
|
-
case "min" /* Minute */:
|
|
27680
|
-
return "min";
|
|
27681
|
-
case "h" /* Hour */:
|
|
27682
|
-
return "h";
|
|
27683
|
-
case "d" /* Day */:
|
|
27684
|
-
return "d";
|
|
27685
|
-
case "wk" /* Week */:
|
|
27686
|
-
return "wk";
|
|
27687
|
-
case "mo" /* Month */:
|
|
27688
|
-
return "mo";
|
|
27689
|
-
case "a" /* Year */:
|
|
27690
|
-
return "a";
|
|
27691
|
-
default:
|
|
27692
|
-
return void 0;
|
|
27693
|
-
}
|
|
27694
|
-
}
|
|
27695
|
-
function deriveDefaultTimingForPeriod(value, unit, currentTimingCode) {
|
|
27696
|
-
let timingCode = currentTimingCode;
|
|
27697
|
-
const suffix = periodUnitSuffix(unit);
|
|
27698
|
-
if (suffix) {
|
|
27699
|
-
const key2 = `q${value}${suffix}`;
|
|
27700
|
-
const descriptor = TIMING_ABBREVIATIONS[key2];
|
|
27701
|
-
if (descriptor == null ? void 0 : descriptor.code) {
|
|
27702
|
-
timingCode = timingCode != null ? timingCode : descriptor.code;
|
|
27703
|
-
}
|
|
27704
|
-
}
|
|
27705
|
-
if (unit === "wk" /* Week */ && value === 1) {
|
|
27706
|
-
timingCode = timingCode != null ? timingCode : "WK";
|
|
27707
|
-
}
|
|
27708
|
-
if (unit === "mo" /* Month */ && value === 1) {
|
|
27709
|
-
timingCode = timingCode != null ? timingCode : "MO";
|
|
27710
|
-
}
|
|
27711
|
-
return {
|
|
27712
|
-
frequency: unit === "d" /* Day */ && value === 1 ? 1 : void 0,
|
|
27713
|
-
timingCode
|
|
27714
|
-
};
|
|
27715
|
-
}
|
|
27716
|
-
function buildPeriodScheduleFeature(period, unit) {
|
|
27717
|
-
const normalized = normalizePeriodValue(period, unit);
|
|
27718
|
-
const defaults = deriveDefaultTimingForPeriod(normalized.value, normalized.unit);
|
|
27719
|
-
return {
|
|
27720
|
-
period: normalized.value,
|
|
27721
|
-
periodUnit: normalized.unit,
|
|
27722
|
-
frequency: defaults.frequency,
|
|
27723
|
-
timingCode: defaults.timingCode
|
|
27724
|
-
};
|
|
27725
|
-
}
|
|
27726
|
-
function mapIntervalUnit(token) {
|
|
27727
|
-
const unit = INTERVAL_UNITS.get(token);
|
|
27728
|
-
return unit === "min" /* Minute */ || unit === "h" /* Hour */ || unit === "d" /* Day */ || unit === "wk" /* Week */ || unit === "mo" /* Month */ ? unit : void 0;
|
|
27729
|
-
}
|
|
27730
|
-
function mapFrequencyAdverb(token) {
|
|
27731
|
-
return FREQUENCY_ADVERB_UNITS.get(token);
|
|
27732
|
-
}
|
|
27733
|
-
function parseNumericRange(token) {
|
|
27734
|
-
const rangeMatch = token.match(/^([0-9]+(?:\.[0-9]+)?)[-–—]([0-9]+(?:\.[0-9]+)?)$/);
|
|
27735
|
-
if (!rangeMatch) {
|
|
27736
|
-
return void 0;
|
|
27737
|
-
}
|
|
27738
|
-
const low = parseFloat(rangeMatch[1]);
|
|
27739
|
-
const high = parseFloat(rangeMatch[2]);
|
|
27740
|
-
if (!Number.isFinite(low) || !Number.isFinite(high) || high < low) {
|
|
27741
|
-
return void 0;
|
|
27742
|
-
}
|
|
27743
|
-
return { low, high };
|
|
27744
|
-
}
|
|
27745
|
-
function buildDurationScheduleFeature(value, unit, max) {
|
|
27746
|
-
if (value === void 0 || !Number.isFinite(value) || value <= 0 || !unit) {
|
|
27747
|
-
return void 0;
|
|
27748
|
-
}
|
|
27749
|
-
return {
|
|
27750
|
-
duration: value,
|
|
27751
|
-
durationMax: max !== void 0 && Number.isFinite(max) && max > value ? max : void 0,
|
|
27752
|
-
durationUnit: unit
|
|
27753
|
-
};
|
|
27754
|
-
}
|
|
27755
|
-
|
|
27756
28153
|
// src/hpsg/rule-context.ts
|
|
27757
28154
|
function normalizeTokenLower(token) {
|
|
27758
28155
|
var _a26;
|
|
@@ -27929,7 +28326,8 @@ function lexicalSign(args) {
|
|
|
27929
28326
|
evidence: [
|
|
27930
28327
|
{
|
|
27931
28328
|
rule: args.rule,
|
|
27932
|
-
tokenIndices
|
|
28329
|
+
tokenIndices,
|
|
28330
|
+
scheduleDefault: args.scheduleDefault
|
|
27933
28331
|
}
|
|
27934
28332
|
],
|
|
27935
28333
|
score: (_b3 = args.score) != null ? _b3 : 1
|
|
@@ -28215,11 +28613,44 @@ function separatedIntervalRule() {
|
|
|
28215
28613
|
valence: {},
|
|
28216
28614
|
cont: { clauseKind: "administration" }
|
|
28217
28615
|
},
|
|
28616
|
+
scheduleDefault: directUnit === "d" /* Day */ ? "daily-frequency" : void 0,
|
|
28218
28617
|
score: 9
|
|
28219
28618
|
})
|
|
28220
28619
|
];
|
|
28221
28620
|
}
|
|
28222
28621
|
const unitToken = context.tokens[start + 2];
|
|
28622
|
+
const explicitLowUnit = unitToken && !context.state.consumed.has(unitToken.index) ? mapIntervalUnit(normalizeTokenLower(unitToken)) : void 0;
|
|
28623
|
+
const explicitRangeConnectorToken = context.tokens[start + 3];
|
|
28624
|
+
const explicitRangeConnector = explicitRangeConnectorToken && !context.state.consumed.has(explicitRangeConnectorToken.index) ? normalizeTokenLower(explicitRangeConnectorToken) : void 0;
|
|
28625
|
+
const explicitHighToken = context.tokens[start + 4];
|
|
28626
|
+
const explicitHighLower = explicitHighToken && !context.state.consumed.has(explicitHighToken.index) ? normalizeTokenLower(explicitHighToken) : void 0;
|
|
28627
|
+
const explicitHighUnitToken = context.tokens[start + 5];
|
|
28628
|
+
const explicitHighUnit = explicitHighUnitToken && !context.state.consumed.has(explicitHighUnitToken.index) ? mapIntervalUnit(normalizeTokenLower(explicitHighUnitToken)) : void 0;
|
|
28629
|
+
if (explicitLowUnit && explicitRangeConnector && RANGE_CONNECTORS.has(explicitRangeConnector) && explicitHighToken && explicitHighLower && explicitHighUnit && explicitHighUnitToken && /^[0-9]+(?:\.[0-9]+)?$/.test(quantityLower) && /^[0-9]+(?:\.[0-9]+)?$/.test(explicitHighLower)) {
|
|
28630
|
+
const normalizedRange = normalizeMixedPeriodRange(
|
|
28631
|
+
parseFloat(quantityLower),
|
|
28632
|
+
explicitLowUnit,
|
|
28633
|
+
parseFloat(explicitHighLower),
|
|
28634
|
+
explicitHighUnit
|
|
28635
|
+
);
|
|
28636
|
+
if (normalizedRange) {
|
|
28637
|
+
return [lexicalSign({
|
|
28638
|
+
type: "schedule-sign",
|
|
28639
|
+
rule: "hpsg.lex.schedule.separatedMixedUnitIntervalRange",
|
|
28640
|
+
tokens: [lead, quantity, unitToken, explicitRangeConnectorToken, explicitHighToken, explicitHighUnitToken],
|
|
28641
|
+
synsem: {
|
|
28642
|
+
head: { schedule: {
|
|
28643
|
+
period: normalizedRange.low,
|
|
28644
|
+
periodMax: normalizedRange.high,
|
|
28645
|
+
periodUnit: normalizedRange.unit
|
|
28646
|
+
} },
|
|
28647
|
+
valence: {},
|
|
28648
|
+
cont: { clauseKind: "administration" }
|
|
28649
|
+
},
|
|
28650
|
+
score: 14
|
|
28651
|
+
})];
|
|
28652
|
+
}
|
|
28653
|
+
}
|
|
28223
28654
|
const rangeConnector = unitToken && !context.state.consumed.has(unitToken.index) ? normalizeTokenLower(unitToken) : void 0;
|
|
28224
28655
|
const highToken = context.tokens[start + 3];
|
|
28225
28656
|
const highLower = highToken && !context.state.consumed.has(highToken.index) ? normalizeTokenLower(highToken) : void 0;
|
|
@@ -30955,6 +31386,28 @@ function anchoredModifierLeadsToResolvableSite(context, start) {
|
|
|
30955
31386
|
}
|
|
30956
31387
|
return false;
|
|
30957
31388
|
}
|
|
31389
|
+
function relationIntroducesNonSiteComplement(context, index) {
|
|
31390
|
+
const token = context.tokens[index];
|
|
31391
|
+
if (!token) return false;
|
|
31392
|
+
const relations = resolveActionRelationSurfaceCandidates(normalizeTokenLower(token));
|
|
31393
|
+
if (!relations.length) return false;
|
|
31394
|
+
for (let cursor = index + 1; cursor < Math.min(context.limit, index + 4); cursor += 1) {
|
|
31395
|
+
const candidate = context.tokens[cursor];
|
|
31396
|
+
if (!candidate || context.state.consumed.has(candidate.index) || isPunctuation(normalizeTokenLower(candidate))) {
|
|
31397
|
+
break;
|
|
31398
|
+
}
|
|
31399
|
+
if (EVENT_TIMING_TOKENS[normalizeTokenLower(candidate)]) return true;
|
|
31400
|
+
}
|
|
31401
|
+
return false;
|
|
31402
|
+
}
|
|
31403
|
+
function coordinationStartsAction(context, index) {
|
|
31404
|
+
const token = context.tokens[index];
|
|
31405
|
+
if (!token || !ACTION_COORDINATION_CONNECTORS.has(normalizeTokenLower(token))) return false;
|
|
31406
|
+
const next = context.tokens[index + 1];
|
|
31407
|
+
return Boolean(
|
|
31408
|
+
next && !context.state.consumed.has(next.index) && resolveMedicationInstructionAction(normalizeTokenLower(next), context.options)
|
|
31409
|
+
);
|
|
31410
|
+
}
|
|
30958
31411
|
function siteBoundary(lower, context) {
|
|
30959
31412
|
var _a26, _b3, _c2;
|
|
30960
31413
|
if (SITE_MULTIPLICITY_WORDS.has(lower)) {
|
|
@@ -31011,6 +31464,21 @@ function hasSystemicCueBeforeSiteAbbreviation(context, start) {
|
|
|
31011
31464
|
}
|
|
31012
31465
|
return sawNonOcularDose;
|
|
31013
31466
|
}
|
|
31467
|
+
function anchorTargetsTypedNonSiteConcept(context, start) {
|
|
31468
|
+
var _a26;
|
|
31469
|
+
const current = (_a26 = tokensAvailable(context, start, 1)) == null ? void 0 : _a26[0];
|
|
31470
|
+
if (!current || !resolveActionRelationSurface(normalizeTokenLower(current))) return false;
|
|
31471
|
+
for (let cursor = start + 1; cursor < Math.min(context.limit, start + 4); cursor += 1) {
|
|
31472
|
+
const candidate = context.tokens[cursor];
|
|
31473
|
+
if (!candidate || context.state.consumed.has(candidate.index)) break;
|
|
31474
|
+
const lower = normalizeTokenLower(candidate);
|
|
31475
|
+
if (isPunctuation(lower)) break;
|
|
31476
|
+
const concept = resolveMedicationInstructionConcept(lower, context.options);
|
|
31477
|
+
if (!concept) continue;
|
|
31478
|
+
return concept.role !== "site" /* Site */ && concept.role !== "destination" /* Destination */;
|
|
31479
|
+
}
|
|
31480
|
+
return false;
|
|
31481
|
+
}
|
|
31014
31482
|
function contextSuggestsNonOcularSite(context) {
|
|
31015
31483
|
var _a26, _b3, _c2, _d, _e, _f;
|
|
31016
31484
|
const dosageForm = (_c2 = (_b3 = (_a26 = context.options) == null ? void 0 : _a26.context) == null ? void 0 : _b3.dosageForm) == null ? void 0 : _c2.trim().toLowerCase().replace(/\s+/g, " ");
|
|
@@ -31029,7 +31497,7 @@ function siteLexicalRule() {
|
|
|
31029
31497
|
}
|
|
31030
31498
|
const signs = [];
|
|
31031
31499
|
const lower = normalizeTokenLower(token);
|
|
31032
|
-
if (tokenBelongsToContextualPrnReasonLead(context, start)) {
|
|
31500
|
+
if (tokenBelongsToContextualPrnReasonLead(context, start) || anchorTargetsTypedNonSiteConcept(context, start)) {
|
|
31033
31501
|
return signs;
|
|
31034
31502
|
}
|
|
31035
31503
|
const siteCandidate = getPrimarySiteMeaningCandidate(token);
|
|
@@ -31072,11 +31540,12 @@ function siteLexicalRule() {
|
|
|
31072
31540
|
if (candidate.kind === "NUMBER" /* Number */) {
|
|
31073
31541
|
break;
|
|
31074
31542
|
}
|
|
31075
|
-
if (getDayOfWeekMeaning(candidate)) {
|
|
31543
|
+
if (getDayOfWeekMeaning(candidate) || ACTION_SEQUENCE_MARKERS.has(candidateLower)) {
|
|
31076
31544
|
break;
|
|
31077
31545
|
}
|
|
31546
|
+
if (coordinationStartsAction(context, cursor)) break;
|
|
31078
31547
|
const siteModifierCanBridgeBoundary = (SITE_SELF_DISPLAY_ANCHORS.has(candidateLower) || EXTERNAL_SITE_LOCATIVE_PREFIXES.has(candidateLower) || BODY_SITE_ATTRIBUTIVE_MODIFIERS.has(candidateLower)) && anchoredModifierLeadsToResolvableSite(context, cursor);
|
|
31079
|
-
if (siteBoundary(candidateLower, context) && (isPunctuation(candidateLower) || !siteModifierCanBridgeBoundary)) {
|
|
31548
|
+
if ((siteBoundary(candidateLower, context) || relationIntroducesNonSiteComplement(context, cursor)) && (isPunctuation(candidateLower) || !siteModifierCanBridgeBoundary)) {
|
|
31080
31549
|
const next = context.tokens[cursor + 1];
|
|
31081
31550
|
const nextLower = next && !context.state.consumed.has(next.index) ? normalizeTokenLower(next) : void 0;
|
|
31082
31551
|
const continuedText = nextLower ? [...displayTokens, next].map((part) => part.original).join(" ") : "";
|