feat: add CCA claim submission with Selenium automation
- Add CCA claim submit Selenium worker (login, fill form, attach docs, submit, capture dashboard PDF) - Add CCA fee schedule (procedureCodesMH.json renamed, procedureCodesCCA.json added with D6010) - Add backend route /api/claims/cca-claim, processor, and Selenium client - Wire CCA claim handler in claims-page with job tracking and PDF preview popup - Add insurance type dropdown in claim form (same options as eligibility page) - Auto-populate insurance type from patient.insuranceProvider in claim form and patient edit form - Map fee schedule by insurance type in Map Price button and combo buttons - Fix CCA login speed (remove fixed sleeps, use readyState check) - Fix CCA claim DOB format bug (was sending MM-DD-YYYY, now sends YYYY-MM-DD) - Fix npiProviderId not saved for CCA claims - Change Add Service → CCA Claim button (blue), MH → MH Claim Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
241
apps/Frontend/src/utils/procedureCombosMapping.js
Normal file
241
apps/Frontend/src/utils/procedureCombosMapping.js
Normal file
@@ -0,0 +1,241 @@
|
||||
import Decimal from "decimal.js";
|
||||
import rawCodeTable from "@/assets/data/procedureCodesMH.json";
|
||||
import { PROCEDURE_COMBOS } from "./procedureCombos";
|
||||
const CODE_TABLE = rawCodeTable;
|
||||
/* ----------------------------- Helpers ----------------------------- */
|
||||
export const COMBO_BUTTONS = Object.values(PROCEDURE_COMBOS).map((c) => ({
|
||||
id: c.id,
|
||||
label: c.label,
|
||||
}));
|
||||
// Build a fast lookup map keyed by normalized code
|
||||
const normalizeCode = (code) => code.replace(/\s+/g, "").toUpperCase();
|
||||
const CODE_MAP = (() => {
|
||||
const m = new Map();
|
||||
for (const r of CODE_TABLE) {
|
||||
const k = normalizeCode(String(r["Procedure Code"] || ""));
|
||||
if (k && !m.has(k))
|
||||
m.set(k, r);
|
||||
}
|
||||
return m;
|
||||
})();
|
||||
// this function is solely for abbrevations feature in claim-form
|
||||
export function getDescriptionForCode(code) {
|
||||
if (!code)
|
||||
return undefined;
|
||||
const row = CODE_MAP.get(normalizeCode(code));
|
||||
return row?.Description;
|
||||
}
|
||||
const isBlankPrice = (v) => {
|
||||
if (v == null)
|
||||
return true;
|
||||
const s = String(v).trim().toUpperCase();
|
||||
return s === "" || s === "IC" || s === "NC";
|
||||
};
|
||||
const toDecimalOrZero = (v) => {
|
||||
if (isBlankPrice(v))
|
||||
return new Decimal(0);
|
||||
const n = typeof v === "string" ? parseFloat(v) : v;
|
||||
return new Decimal(Number.isFinite(n) ? n : 0);
|
||||
};
|
||||
const parseDate = (d) => {
|
||||
if (d instanceof Date)
|
||||
return new Date(d.getFullYear(), d.getMonth(), d.getDate());
|
||||
const s = String(d).trim();
|
||||
// MM/DD/YYYY
|
||||
const mdy = /^(\d{2})\/(\d{2})\/(\d{4})$/;
|
||||
const m1 = mdy.exec(s);
|
||||
if (m1) {
|
||||
const mm = Number(m1[1]);
|
||||
const dd = Number(m1[2]);
|
||||
const yyyy = Number(m1[3]);
|
||||
return new Date(yyyy, mm - 1, dd);
|
||||
}
|
||||
// YYYY-MM-DD
|
||||
const ymd = /^(\d{4})-(\d{2})-(\d{2})$/;
|
||||
const m2 = ymd.exec(s);
|
||||
if (m2) {
|
||||
const yyyy = Number(m2[1]);
|
||||
const mm = Number(m2[2]);
|
||||
const dd = Number(m2[3]);
|
||||
return new Date(yyyy, mm - 1, dd);
|
||||
}
|
||||
// Fallback
|
||||
return new Date(s);
|
||||
};
|
||||
const ageOnDate = (dob, on) => {
|
||||
const birth = parseDate(dob);
|
||||
const ref = parseDate(on);
|
||||
let age = ref.getFullYear() - birth.getFullYear();
|
||||
const hadBirthday = ref.getMonth() > birth.getMonth() ||
|
||||
(ref.getMonth() === birth.getMonth() && ref.getDate() >= birth.getDate());
|
||||
if (!hadBirthday)
|
||||
age -= 1;
|
||||
return age;
|
||||
};
|
||||
/**
|
||||
* we can implement per-code age buckets without changing the JSON.
|
||||
*
|
||||
* Behavior:
|
||||
* - Default: same as before: age <= 21 -> PriceLTEQ21, else PriceGT21
|
||||
* - Fallback to Price if tiered field is blank/IC/NC
|
||||
* - Special-cases D1110 and D1120 according to MH rules
|
||||
*/
|
||||
export function pickPriceForRowByAge(row, age, normalizedCode) {
|
||||
// Special-case rules (add more codes here if needed)
|
||||
if (normalizedCode) {
|
||||
// D1110: only valid for age >=14 (14..21 => PriceLTEQ21, >21 => PriceGT21)
|
||||
if (normalizedCode === "D1110") {
|
||||
if (age < 14) {
|
||||
// D1110 not applicable to children <14 (those belong to D1120)
|
||||
return new Decimal(0);
|
||||
}
|
||||
if (age >= 14 && age <= 21) {
|
||||
// use PriceLTEQ21 only if present
|
||||
if (!isBlankPrice(row.PriceLTEQ21))
|
||||
return toDecimalOrZero(row.PriceLTEQ21);
|
||||
return new Decimal(0);
|
||||
}
|
||||
// age > 21
|
||||
if (!isBlankPrice(row.PriceGT21))
|
||||
return toDecimalOrZero(row.PriceGT21);
|
||||
return new Decimal(0);
|
||||
}
|
||||
// D1120: child 0-13 => PriceLTEQ21, otherwise no price (NC)
|
||||
if (normalizedCode === "D1120") {
|
||||
if (age < 14) {
|
||||
if (!isBlankPrice(row.PriceLTEQ21))
|
||||
return toDecimalOrZero(row.PriceLTEQ21);
|
||||
return new Decimal(0);
|
||||
}
|
||||
// age >= 14 => NC / no price
|
||||
return new Decimal(0);
|
||||
}
|
||||
}
|
||||
// Generic/default behavior (unchanged)
|
||||
if (age <= 21) {
|
||||
if (!isBlankPrice(row.PriceLTEQ21))
|
||||
return toDecimalOrZero(row.PriceLTEQ21);
|
||||
}
|
||||
else {
|
||||
if (!isBlankPrice(row.PriceGT21))
|
||||
return toDecimalOrZero(row.PriceGT21);
|
||||
}
|
||||
// Fallback to Price if tiered not available/blank
|
||||
if (!isBlankPrice(row.Price))
|
||||
return toDecimalOrZero(row.Price);
|
||||
return new Decimal(0);
|
||||
}
|
||||
/**
|
||||
* Gets price for a code using age & code table.
|
||||
*/
|
||||
function getPriceForCodeWithAgeFromMap(map, code, age) {
|
||||
const norm = normalizeCode(code);
|
||||
const row = map.get(norm);
|
||||
return row ? pickPriceForRowByAge(row, age, norm) : new Decimal(0);
|
||||
}
|
||||
// helper keeping lines empty,
|
||||
export const makeEmptyLine = (lineDate) => ({
|
||||
procedureCode: "",
|
||||
procedureDate: lineDate,
|
||||
quad: "",
|
||||
arch: "",
|
||||
toothNumber: "",
|
||||
toothSurface: "",
|
||||
totalBilled: new Decimal(0),
|
||||
totalAdjusted: new Decimal(0),
|
||||
totalPaid: new Decimal(0),
|
||||
});
|
||||
// Ensure the array has at least `min` lines; append blank ones if needed.
|
||||
const ensureCapacity = (lines, min, lineDate) => {
|
||||
while (lines.length < min) {
|
||||
lines.push(makeEmptyLine(lineDate));
|
||||
}
|
||||
};
|
||||
/* ------------------------- Main entry points ------------------------- */
|
||||
/**
|
||||
* Map prices for ALL existing lines in a form (your "Map Price" button),
|
||||
* using patient's DOB and the form's serviceDate (or per-line procedureDate).
|
||||
* Returns a NEW form object (immutable).
|
||||
*/
|
||||
export function mapPricesForForm(params) {
|
||||
const { form, patientDOB } = params;
|
||||
return {
|
||||
...form,
|
||||
serviceLines: form.serviceLines.map((ln) => {
|
||||
const age = ageOnDate(patientDOB, form.serviceDate);
|
||||
const code = normalizeCode(ln.procedureCode || "");
|
||||
if (!code)
|
||||
return { ...ln };
|
||||
const price = getPriceForCodeWithAgeFromMap(CODE_MAP, code, age);
|
||||
return { ...ln, procedureCode: code, totalBilled: price };
|
||||
}),
|
||||
};
|
||||
}
|
||||
/**
|
||||
* Apply a preset combo (fills codes & prices) using patientDOB and serviceDate.
|
||||
* Returns a NEW form object (immutable).
|
||||
*/
|
||||
export function applyComboToForm(form, comboId, patientDOB, options = {}) {
|
||||
const preset = PROCEDURE_COMBOS[String(comboId)];
|
||||
if (!preset)
|
||||
return form;
|
||||
const { append = true, startIndex, lineDate = form.serviceDate, clearTrailing = false, replaceAll = false, // NEW
|
||||
} = options;
|
||||
const next = { ...form, serviceLines: [...form.serviceLines] };
|
||||
// Replace-all: blank all existing and start from 0
|
||||
if (replaceAll) {
|
||||
for (let i = 0; i < next.serviceLines.length; i++) {
|
||||
next.serviceLines[i] = makeEmptyLine(lineDate);
|
||||
}
|
||||
}
|
||||
// determine insertion index
|
||||
let insertAt = 0;
|
||||
if (!replaceAll) {
|
||||
if (append) {
|
||||
let last = -1;
|
||||
next.serviceLines.forEach((ln, i) => {
|
||||
if (ln.procedureCode?.trim())
|
||||
last = i;
|
||||
});
|
||||
insertAt = Math.max(0, last + 1);
|
||||
}
|
||||
else if (typeof startIndex === "number") {
|
||||
insertAt = Math.max(0, Math.min(startIndex, next.serviceLines.length - 1));
|
||||
}
|
||||
} // if replaceAll, insertAt stays 0
|
||||
// Make sure we have enough rows for the whole combo
|
||||
ensureCapacity(next.serviceLines, insertAt + preset.codes.length, lineDate);
|
||||
// Age on the specific line date we will set
|
||||
const age = ageOnDate(patientDOB, lineDate);
|
||||
for (let j = 0; j < preset.codes.length; j++) {
|
||||
const i = insertAt + j;
|
||||
if (i >= next.serviceLines.length)
|
||||
break;
|
||||
const codeRaw = preset.codes[j];
|
||||
if (!codeRaw)
|
||||
continue;
|
||||
const code = normalizeCode(codeRaw);
|
||||
const price = getPriceForCodeWithAgeFromMap(CODE_MAP, code, age);
|
||||
const original = next.serviceLines[i];
|
||||
next.serviceLines[i] = {
|
||||
...original,
|
||||
procedureCode: code,
|
||||
procedureDate: lineDate,
|
||||
quad: original?.quad ?? "",
|
||||
arch: original?.arch ?? "",
|
||||
toothNumber: preset.toothNumbers?.[j] ?? original?.toothNumber ?? "",
|
||||
toothSurface: original?.toothSurface ?? "",
|
||||
totalBilled: price,
|
||||
totalAdjusted: new Decimal(0),
|
||||
totalPaid: new Decimal(0),
|
||||
};
|
||||
}
|
||||
if (replaceAll || clearTrailing) {
|
||||
const after = insertAt + preset.codes.length;
|
||||
for (let i = after; i < next.serviceLines.length; i++) {
|
||||
next.serviceLines[i] = makeEmptyLine(lineDate);
|
||||
}
|
||||
}
|
||||
return next;
|
||||
}
|
||||
export { CODE_MAP, getPriceForCodeWithAgeFromMap };
|
||||
Reference in New Issue
Block a user