feat: Altus Dental eligibility check and ADA paper claim/preauth

Eligibility (no OTP, fresh browser per run like MH): logs in, opens Benefits &
Claims Information, searches by Subscriber ID (or Subscriber Last Name via
"Click Here"), First Name and DOB, picks the matching row from the patient list,
sets ACTIVE/INACTIVE from the Coverage range, reads Group Number into the
patient's Group Number, opens View Details for the last name and plan name,
and saves the details page PDF to the patient's Eligibility folder. A patient
switching plans is matched by name + DOB so Altus overwrites the old insurance
instead of creating a duplicate.

Claims: Altus uses the same 2024 ADA form as BCBS with the Altus payer address
(P.O. Box 1557, Providence, RI 02901-1557). Adds Altus Claim/PreAuth (ADA Form)
buttons, Claim All and AI queue routing, Print ADA Form in the claim viewer, and
an Altus fee schedule (copied from BCBS).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-15 00:47:01 -04:00
co-authored by Claude Opus 5.5
parent fa6c55421c
commit db7d74a13b
21 changed files with 1388 additions and 33 deletions
@@ -0,0 +1,151 @@
/**
* Processor for "altus-eligibility-check" jobs.
* Runs the Altus Dental eligibility selenium flow (sync, no OTP) and saves the
* PDF to the patient's Eligibility folder.
*/
import fs from "fs/promises";
import path from "path";
import { storage } from "../../storage";
import { emptyFolderContainingFile } from "../../utils/emptyTempFolder";
import { callPythonSync, createOrUpdatePatientByInsuranceId } from "./_shared";
export interface AltusEligibilityProcessorInput {
enrichedPayload: any;
userId: number;
insuranceId: string;
formFirstName?: string;
formLastName?: string;
formDob?: string;
}
export interface AltusEligibilityProcessorResult {
patientUpdateStatus?: string;
pdfUploadStatus?: string;
pdfFileId?: number | string | null;
pdfFilename?: string | null;
}
export async function runAltusEligibilityProcessor(
input: AltusEligibilityProcessorInput
): Promise<AltusEligibilityProcessorResult> {
const { enrichedPayload, userId, insuranceId, formFirstName, formLastName, formDob } = input;
const seleniumResult = await callPythonSync("/altus-eligibility-check", {
data: enrichedPayload,
});
const outputResult: AltusEligibilityProcessorResult = {};
const seleniumInsurance = seleniumResult.insurance?.trim() || "Altus Dental";
const seleniumGroup = String(seleniumResult.group ?? "").trim() || null;
// Name searches (no Subscriber ID typed) use the ID shown in the results row.
const scrapedId = String(seleniumResult.memberId ?? "").replace(/\s+/g, "");
const altusId = insuranceId || scrapedId;
// First name: as typed in the app. Last name: read from the Altus details page,
// else the one typed in the app.
const firstName = (formFirstName ?? "").trim();
const lastName = String(seleniumResult.lastName ?? "").trim() || (formLastName ?? "").trim();
const dobDate = formDob ? new Date(formDob) : null;
const validDob = dobDate && !isNaN(dobDate.getTime()) ? dobDate : null;
// Resolve the patient. A patient switching insurance (e.g. MetLife → Altus) is
// still on file under the old plan's member ID, so after the Altus ID lookup
// fall back to first name (+ last name) + DOB before creating anyone new.
let patient: any = null;
try {
if (altusId) patient = await storage.getPatientByInsuranceId(altusId);
if (!patient && firstName && validDob) {
const matches = await storage.searchPatients({
filters: {
firstName: { equals: firstName, mode: "insensitive" },
...(lastName ? { lastName: { equals: lastName, mode: "insensitive" } } : {}),
dateOfBirth: validDob,
},
limit: 2,
offset: 0,
});
// Only take an unambiguous match
if (matches?.length === 1) patient = matches[0];
}
if (!patient) {
patient = altusId
? await createOrUpdatePatientByInsuranceId({
insuranceId: altusId,
firstName: firstName || null,
lastName: lastName || null,
dob: formDob,
userId,
})
: await storage.createPatient({
firstName,
lastName,
dateOfBirth: validDob,
gender: "",
phone: "",
userId,
} as any);
}
} catch (e: any) {
throw new Error(`Failed to create/update patient: ${e.message}`);
}
if (patient && patient.id !== undefined) {
let newStatus = "UNKNOWN";
if (seleniumResult.eligibility === "Y") newStatus = "ACTIVE";
else if (seleniumResult.eligibility === "N") newStatus = "INACTIVE";
// Altus becomes the patient's current insurance — overwrite the previous plan's
// provider/ID/group. Earlier eligibility PDFs stay in the Eligibility folder.
const updates: any = { status: newStatus, insuranceProvider: seleniumInsurance };
if (firstName) updates.firstName = firstName;
if (lastName) updates.lastName = lastName; // never blank out an existing last name
if (altusId) updates.insuranceId = altusId;
if (seleniumGroup) updates.groupNumber = seleniumGroup;
const previousProvider = patient.insuranceProvider ?? null;
await storage.updatePatient(patient.id, updates);
outputResult.patientUpdateStatus =
`Patient status updated to ${newStatus}` +
(previousProvider && previousProvider !== seleniumInsurance
? ` (insurance changed from ${previousProvider} to ${seleniumInsurance})`
: "");
if (seleniumResult.pdf_path?.endsWith(".pdf")) {
const patientName =
`${patient.firstName ?? ""} ${patient.lastName ?? ""}`.trim() || `Patient ${patient.id}`;
try {
const buffer = await fs.readFile(seleniumResult.pdf_path);
const cloudFile = await storage.savePdfToCloudStorage(
userId,
patient.id,
patientName,
"Eligibility",
path.basename(seleniumResult.pdf_path),
buffer
);
outputResult.pdfFileId = `cloud:${cloudFile.id}`;
outputResult.pdfUploadStatus = "Eligibility PDF saved";
} catch (e: any) {
console.error("[altusEligibilityProcessor] PDF save failed:", e.message);
outputResult.pdfFileId = null;
outputResult.pdfUploadStatus = "Eligibility PDF upload failed";
}
outputResult.pdfFilename = path.basename(seleniumResult.pdf_path);
} else {
outputResult.pdfUploadStatus = "No eligibility PDF returned by Selenium";
}
} else {
outputResult.patientUpdateStatus = "Patient not found or missing ID; no update performed";
}
try {
if (seleniumResult.pdf_path) await emptyFolderContainingFile(seleniumResult.pdf_path);
} catch (e) {
console.error("[altusEligibilityProcessor] cleanup failed:", e);
}
return outputResult;
}