fix: Tufts SCO location select, simple ext → D7140, sanitize custom CDT aliases
- Tufts SCO claim/preauth: robust location dropdown selection (multiple
option selectors, retries, keyboard fallback, HTML dump on failure)
- CDT lookup: map ext/extraction/simple ext to D7140; ignore dangling
"on/of/for/at" left after stripping tooth number
- Custom CDT aliases: keep only the Dxxxx code ("D7140 #25" → "D7140") and
drop tooth numbers from phrases, on save and at lookup — fixes $0 fee
from code "D7140#25"
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -214,6 +214,14 @@ const DIRECT_CODE_MAP: Record<string, string> = {
|
||||
"rct primary molar": "D3240",
|
||||
"baby tooth rct": "D3230",
|
||||
// Extractions
|
||||
"ext": "D7140",
|
||||
"exts": "D7140",
|
||||
"extraction": "D7140",
|
||||
"extractions": "D7140",
|
||||
"simple ext": "D7140",
|
||||
"simple exts": "D7140",
|
||||
"simple extraction": "D7140",
|
||||
"simple extractions": "D7140",
|
||||
"baby tooth ext": "D7111",
|
||||
"baby tooth extraction": "D7111",
|
||||
"primary tooth ext": "D7111",
|
||||
@@ -631,6 +639,24 @@ function expandCompositeLists(procedureNames: string[]): string[] {
|
||||
return out;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clean a user-entered alias code down to the bare CDT code:
|
||||
* "D7140 #25" → "D7140", "7140" → "D7140". Returns null if there is no code.
|
||||
*/
|
||||
export function normalizeAliasCode(code: string): string | null {
|
||||
const m = code.trim().match(/^d?\s*(\d{4})\b/i);
|
||||
return m ? `D${m[1]}` : null;
|
||||
}
|
||||
|
||||
/** Drop tooth numbers from an alias phrase: "simple ext #25" → "simple ext". */
|
||||
export function normalizeAliasPhrase(phrase: string): string {
|
||||
return phrase
|
||||
.toLowerCase()
|
||||
.replace(/,?\s*#\s*(\d{1,2}|[a-t])\b/gi, "")
|
||||
.replace(/\s+/g, " ")
|
||||
.trim();
|
||||
}
|
||||
|
||||
// Explicit code + tooth list with no surfaces, e.g. "D6010 #5, 9 , 11, 12" or "D6057 #5 #9 and 11"
|
||||
const CODE_TOOTH_LIST_RE =
|
||||
/\b(D\d{4})\s*#\s*(\d{1,2}(?:\s*(?:,|&|\band\b)?\s*#?\s*\d{1,2})*)\b(?!\s*[OMDBLFIV]{1,5}\b)/gi;
|
||||
@@ -664,7 +690,8 @@ export function lookupCdtCodes(
|
||||
// Build a lookup map from custom aliases (phrase → cdtCode), lowercased
|
||||
const customMap: Record<string, string> = {};
|
||||
for (const { phrase, cdtCode } of customAliases) {
|
||||
if (phrase && cdtCode) customMap[phrase.toLowerCase().trim()] = cdtCode.toUpperCase().trim();
|
||||
const code = cdtCode ? normalizeAliasCode(cdtCode) : null;
|
||||
if (phrase && code) customMap[phrase.toLowerCase().trim()] = code;
|
||||
}
|
||||
|
||||
// Pontics with no stated material — re-coded below to match the crowns
|
||||
@@ -693,7 +720,9 @@ export function lookupCdtCodes(
|
||||
.replace(/,?\s*#\s*[a-t]\b/gi, "")
|
||||
.replace(/\(\s*\)/g, "")
|
||||
.replace(/\s+/g, " ")
|
||||
.trim();
|
||||
.trim()
|
||||
// dangling connector left after removing the tooth, e.g. "simple ext on #25"
|
||||
.replace(/\s+(on|of|for|at)$/, "");
|
||||
|
||||
// 1. Custom alias exact match (highest priority)
|
||||
const customKey = customMap[cleaned] ? cleaned : customMap[strippedCleaned] ? strippedCleaned : null;
|
||||
|
||||
@@ -7,6 +7,7 @@ import { storage } from "../storage";
|
||||
import { classifyInternalChat } from "../ai/internal-chat-graph";
|
||||
import { runInternalChatWorkflow, createAppointmentToday } from "../ai/internal-chat-workflow";
|
||||
import { resolveAiProvider, getLlm } from "../ai/llm-factory";
|
||||
import { normalizeAliasCode, normalizeAliasPhrase } from "../ai/cdt-lookup";
|
||||
import { backupScreenshots } from "../utils/screenshotBackup";
|
||||
|
||||
const eligibilityImageUpload = multer({ storage: multer.memoryStorage() });
|
||||
@@ -299,9 +300,10 @@ router.put("/cdt-aliases", async (req: Request, res: Response): Promise<any> =>
|
||||
const cleaned = aliases
|
||||
.filter((a: any) => typeof a?.phrase === "string" && typeof a?.cdtCode === "string")
|
||||
.map((a: any) => ({
|
||||
phrase: a.phrase.trim().toLowerCase(),
|
||||
cdtCode: a.cdtCode.trim().toUpperCase(),
|
||||
}));
|
||||
phrase: normalizeAliasPhrase(a.phrase),
|
||||
cdtCode: normalizeAliasCode(a.cdtCode),
|
||||
}))
|
||||
.filter((a): a is { phrase: string; cdtCode: string } => !!a.phrase && !!a.cdtCode);
|
||||
await storage.saveCdtAliases(userId, cleaned);
|
||||
return res.status(200).json(cleaned);
|
||||
} catch (err) {
|
||||
@@ -319,7 +321,11 @@ router.post("/cdt-aliases/add", async (req: Request, res: Response): Promise<any
|
||||
return res.status(400).json({ message: "Body must be { phrase, cdtCode }" });
|
||||
}
|
||||
const existing = await storage.getCdtAliases(userId);
|
||||
const newEntry = { phrase: phrase.trim().toLowerCase(), cdtCode: cdtCode.trim().toUpperCase() };
|
||||
const code = normalizeAliasCode(cdtCode);
|
||||
if (!code) {
|
||||
return res.status(400).json({ message: `"${cdtCode}" is not a CDT code (expected e.g. D7140)` });
|
||||
}
|
||||
const newEntry = { phrase: normalizeAliasPhrase(phrase), cdtCode: code };
|
||||
const updated = [...existing.filter((a) => a.phrase !== newEntry.phrase), newEntry];
|
||||
await storage.saveCdtAliases(userId, updated);
|
||||
return res.status(200).json(newEntry);
|
||||
|
||||
Reference in New Issue
Block a user