feat: chatbot CDT lookup — SRP quad, 4-digit auto-prefix, quad field to Selenium
- parseSrpCode: recognize "D4341 UL" / "4341 LR" etc., store quadrant in quad field - matchOne: auto-prefix D for 4-digit inputs like "0120" → D0120 - LLM prompt: keep SRP code and quadrant together as one procedureName entry - CdtMatch / CdtResult: add quad field, thread through matchedCodes action data - claim-form.tsx: include quad in chatbot_claim_prefill type and spread to service line - selenium_claimSubmitWorker.py: pass quad to fill_service_line, select quadrant dropdown by index (UR=1, UL=2, LL=3, LR=4) matching MassHealth form structure Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -19,6 +19,7 @@ interface CdtMatch {
|
||||
input: string;
|
||||
toothNumber?: string;
|
||||
toothSurface?: string;
|
||||
quad?: string;
|
||||
}
|
||||
|
||||
// Load once at module init
|
||||
@@ -284,6 +285,21 @@ function parseCompositeCode(input: string): CdtMatch | null {
|
||||
return { code, description: row?.Description ?? code, input, toothNumber: String(toothNum), toothSurface: surfaces.toUpperCase() };
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse SRP code with quadrant: "D4341 UL", "4341 LR", "D4342 UR", etc.
|
||||
* UL/UR/LL/LR only appear with D4341 or D4342.
|
||||
*/
|
||||
function parseSrpCode(input: string): CdtMatch | null {
|
||||
const m = input.trim().match(/^(D?4341|D?4342)\s+(UL|UR|LL|LR)$/i);
|
||||
if (!m) return null;
|
||||
const base = m[1]!.toUpperCase();
|
||||
const codeStr = base.startsWith("D") ? base : "D" + base;
|
||||
const quadrant = m[2]!.toUpperCase();
|
||||
const row = ALL_CODES.find((r) => r["Procedure Code"].toUpperCase() === codeStr);
|
||||
if (!row) return null;
|
||||
return { code: codeStr, description: row.Description, input, quad: quadrant };
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse RCT/root-canal notation like "rct #29", "#14 rct", "root canal #6".
|
||||
* Returns D3310 (anterior), D3320 (premolar), or D3330 (molar) based on tooth number.
|
||||
@@ -352,6 +368,14 @@ function matchOne(input: string): CdtMatch | null {
|
||||
return { code, description: row?.Description ?? code, input };
|
||||
}
|
||||
|
||||
// 4-digit shorthand: auto-prefix "D" (e.g. "0120" → "D0120")
|
||||
if (/^\d{4}$/.test(cleaned)) {
|
||||
const withD = "D" + cleaned;
|
||||
const row = ALL_CODES.find((r) => r["Procedure Code"].toUpperCase() === withD.toUpperCase());
|
||||
const code = row?.["Procedure Code"] ?? withD.toUpperCase();
|
||||
return { code, description: row?.Description ?? code, input };
|
||||
}
|
||||
|
||||
// Apply alias before tokenizing
|
||||
const normalized = ALIAS_MAP[cleaned] ?? cleaned;
|
||||
const queryTokens = normalized
|
||||
@@ -420,6 +444,10 @@ export function lookupCdtCodes(
|
||||
const rctMatch = parseRctCode(name);
|
||||
if (rctMatch) return rctMatch;
|
||||
|
||||
// 2c. SRP + quadrant — D4341/D4342 with UL/UR/LL/LR
|
||||
const srpMatch = parseSrpCode(name);
|
||||
if (srpMatch) return srpMatch;
|
||||
|
||||
// 3. Hardcoded direct code map (short abbreviations / codes not in MH schedule)
|
||||
const directKey = DIRECT_CODE_MAP[cleaned] ? cleaned : DIRECT_CODE_MAP[strippedCleaned] ? strippedCleaned : null;
|
||||
if (directKey) {
|
||||
|
||||
@@ -101,6 +101,8 @@ Rules:
|
||||
e.g. "composite #29 O", "#8 MO", "composite #11 MOD" — keep the #number and surface letters together as one entry
|
||||
- For RCT/root canal with a tooth number, preserve the tooth# in the entry:
|
||||
e.g. "rct #29", "#14 root canal", "rct #6" — keep the #number with the procedure so the correct code can be selected
|
||||
- For SRP with a quadrant abbreviation (UL, UR, LL, LR), keep the code and quadrant together as one entry:
|
||||
e.g. "D4341 UL", "4341 LR", "D4342 UR" — the quadrant always travels with the SRP code
|
||||
- For multiple PA X-rays with tooth numbers, expand each PA into its own entry:
|
||||
"1 pa, #T" for the first tooth, "2nd pa, #T" for each additional tooth
|
||||
e.g. "2 PA (#30, 15)" → ["1 pa, #30", "2nd pa, #15"]
|
||||
|
||||
@@ -35,6 +35,7 @@ export interface CdtResult {
|
||||
input: string;
|
||||
toothNumber?: string;
|
||||
toothSurface?: string;
|
||||
quad?: string;
|
||||
}
|
||||
|
||||
export interface ChatResponse {
|
||||
@@ -467,8 +468,9 @@ async function handleCheckAndClaim(
|
||||
siteKey,
|
||||
autoCheck: siteKeyToAutoCheck(siteKey),
|
||||
cdtResults,
|
||||
matchedCodes: matched.map((r) => ({ code: r.code!, description: r.description, toothNumber: r.toothNumber, toothSurface: r.toothSurface })),
|
||||
matchedCodes: matched.map((r) => ({ code: r.code!, description: r.description, toothNumber: r.toothNumber, toothSurface: r.toothSurface, quad: r.quad })),
|
||||
serviceDate: c.appointmentDate ?? null,
|
||||
renderingProvider: c.renderingProvider ?? null,
|
||||
},
|
||||
};
|
||||
}
|
||||
@@ -550,7 +552,7 @@ async function handleClaimOnly(
|
||||
actionData: {
|
||||
patient,
|
||||
siteKey: resolveSiteKey(patient.insuranceProvider ?? null, c.insuranceHint ?? null) ?? "MH",
|
||||
matchedCodes: matched.map((r) => ({ code: r.code!, description: r.description, toothNumber: r.toothNumber, toothSurface: r.toothSurface })),
|
||||
matchedCodes: matched.map((r) => ({ code: r.code!, description: r.description, toothNumber: r.toothNumber, toothSurface: r.toothSurface, quad: r.quad })),
|
||||
options: [
|
||||
{ label: fmtUTC(sorted[0]), appointmentId: sorted[0].id, serviceDate: isoUTC(sorted[0]) },
|
||||
{ label: fmtUTC(sorted[1]), appointmentId: sorted[1].id, serviceDate: isoUTC(sorted[1]) },
|
||||
@@ -593,7 +595,7 @@ async function handleClaimOnly(
|
||||
siteKey,
|
||||
serviceDate,
|
||||
appointmentId,
|
||||
matchedCodes: matched.map((r) => ({ code: r.code!, description: r.description, toothNumber: r.toothNumber, toothSurface: r.toothSurface })),
|
||||
matchedCodes: matched.map((r) => ({ code: r.code!, description: r.description, toothNumber: r.toothNumber, toothSurface: r.toothSurface, quad: r.quad })),
|
||||
renderingProvider: c.renderingProvider ?? null,
|
||||
},
|
||||
};
|
||||
|
||||
@@ -825,6 +825,7 @@ router.post(
|
||||
insuranceSiteKey: "DDMA",
|
||||
massddmaUsername: credentials.username,
|
||||
massddmaPassword: credentials.password,
|
||||
providerName: resolvedNpiProvider?.providerName ?? "",
|
||||
},
|
||||
};
|
||||
jobId = enqueueSeleniumJob({
|
||||
|
||||
@@ -40,16 +40,20 @@ router.post("/ddma-claim", async (req: Request, res: Response): Promise<any> =>
|
||||
});
|
||||
}
|
||||
|
||||
// Fetch NPI providers to pick the target provider on the DDMA portal
|
||||
// Use provider from the claim form if set; fall back to Provider #1 (default)
|
||||
const npiProviders = await storage.getNpiProvidersByUser(req.user.id);
|
||||
const primaryProvider = npiProviders[0]; // sorted by sortOrder asc, then id asc
|
||||
const primaryProvider = npiProviders[0];
|
||||
const providerName =
|
||||
(claimData.npiProvider?.providerName as string | undefined)?.trim() ||
|
||||
primaryProvider?.providerName ||
|
||||
"";
|
||||
|
||||
const enrichedPayload = {
|
||||
claim: {
|
||||
...claimData,
|
||||
massddmaUsername: credentials.username,
|
||||
massddmaPassword: credentials.password,
|
||||
providerName: primaryProvider?.providerName ?? "",
|
||||
providerName,
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user