Skip to content

Commit 9c02526

Browse files
committed
fix prompt
1 parent 1a7ec05 commit 9c02526

2 files changed

Lines changed: 32 additions & 29 deletions

File tree

js/ai-expand.js

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,18 @@ CRITICAL RULES:
5151

5252
const typeSpecific = {
5353
dx: `
54-
You are generating diagnosis search keywords.
55-
- Include the full disease name AND common abbreviations
56-
- Include related conditions and subtypes
57-
- For cancer: include organ-specific terms, staging terms, histology types
58-
- For chronic diseases: include all stages and complications
59-
- Example: "type 2 diabetes" should return: diabetes, diabetic, dm2, hyperglycemia, insulin resistance, etc.`,
54+
You are generating search keywords to match ICD-10-CM code descriptions in a clinical data warehouse.
55+
The dictionary contains the literal text of ICD-10-CM descriptions (e.g. "Malignant neoplasm of breast").
56+
Keywords are matched as substrings against those descriptions.
57+
58+
RULES FOR DX KEYWORDS:
59+
- Use formal ICD-10-CM terminology that uniquely identifies the disease or diagnosis
60+
- Include the disease name, anatomical site, and histology/morphology terms as they appear in ICD descriptions
61+
- DO NOT include: laterality (right, left, bilateral), generic qualifiers (unspecified, in situ, acute, chronic, primary, secondary, with complications, without complications), or common words that appear across many unrelated diagnoses
62+
- Do NOT include abbreviations, clinical slang, or lay terms
63+
- Focus on the words that distinguish THIS diagnosis from others
64+
- Example: "breast cancer" → malignant neoplasm, breast, carcinoma, adenocarcinoma, nipple, areola, axillary tail
65+
- Example: "type 2 diabetes" → diabetes mellitus, type 2, diabetic`,
6066

6167
medication: `
6268
You are generating medication search keywords.

js/app.js

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -208,25 +208,26 @@ const DictApp = (function () {
208208
*/
209209
function buildMatcher(keyword) {
210210
const kw = keyword.toLowerCase().trim();
211-
const startsWithStar = kw.startsWith('*');
212-
const endsWithStar = kw.endsWith('*');
213211
const core = kw.replace(/^\*+|\*+$/g, '');
214212

215213
if (!core) return () => false;
216214

217-
if (startsWithStar && endsWithStar) {
218-
// *term* → contains
219-
return (val) => val.includes(core);
220-
} else if (endsWithStar) {
221-
// term* → starts with (word-boundary aware: also matches mid-string word starts)
222-
return (val) => val.includes(core);
223-
} else if (startsWithStar) {
224-
// *term → ends with
225-
return (val) => val.includes(core);
226-
} else {
227-
// no wildcard → contains (LIKE '%term%')
228-
return (val) => val.includes(core);
215+
// Multi-word phrase: split on whitespace and require ALL words to appear
216+
// somewhere in the row (AND logic across words, OR logic across cells).
217+
// e.g. "neoplasm breast" matches any row containing both words.
218+
const words = core.split(/\s+/).filter(w => w);
219+
if (words.length > 1) {
220+
return function (rowValues) {
221+
return words.every(function (word) {
222+
return rowValues.some(function (val) { return val.includes(word); });
223+
});
224+
};
229225
}
226+
227+
// Single word — check if any cell in the row contains it
228+
return function (rowValues) {
229+
return rowValues.some(function (val) { return val.includes(core); });
230+
};
230231
}
231232

232233
/**
@@ -276,10 +277,8 @@ const DictApp = (function () {
276277
// searchData is an array of the rendered column values (strings)
277278
const rowText = searchData.map(s => (s || '').toLowerCase());
278279

279-
// OR logic: match if ANY keyword matches ANY column text
280-
return matchers.some(matcher => {
281-
return rowText.some(cellText => matcher(cellText));
282-
});
280+
// OR logic across chips; within a multi-word chip, AND logic across words
281+
return matchers.some(matcher => matcher(rowText));
283282
};
284283
filterFn._kwFilterType = type;
285284
$.fn.dataTable.ext.search.push(filterFn);
@@ -324,9 +323,7 @@ const DictApp = (function () {
324323
return !k.startsWith('_') && k !== 'desired' && k !== 'category' && k !== 'keyword_matched';
325324
})
326325
.map(function (k) { return (row[k] || '').toString().toLowerCase(); });
327-
return matchers.some(function (matcher) {
328-
return rowValues.some(function (val) { return matcher(val); });
329-
});
326+
return matchers.some(function (matcher) { return matcher(rowValues); });
330327
});
331328

332329
// Auto-desire every matched row and record which keyword triggered the match
@@ -341,7 +338,7 @@ const DictApp = (function () {
341338
.map(function (k) { return (row[k] || '').toString().toLowerCase(); });
342339
var matchedKw = '';
343340
for (var i = 0; i < kwMatchers.length; i++) {
344-
if (rowValues.some(function (val) { return kwMatchers[i].matcher(val); })) {
341+
if (kwMatchers[i].matcher(rowValues)) {
345342
matchedKw = kwMatchers[i].keyword;
346343
break;
347344
}
@@ -380,7 +377,7 @@ const DictApp = (function () {
380377
const rowValues = Object.values(row).map(v => (v || '').toString().toLowerCase());
381378
let matchedKw = '';
382379
for (const { keyword, matcher } of matchers) {
383-
if (rowValues.some(val => matcher(val))) {
380+
if (matcher(rowValues)) {
384381
matchedKw = keyword;
385382
break;
386383
}

0 commit comments

Comments
 (0)