feat: AI-powered eligibility detection from Copy Agent screenshots
Adds an "AI Detect & Check Eligibility" action to the Copy Agent page that sends captured screenshots to Claude to extract Member ID/DOB, then opens the chatbot's eligibility confirm step pre-filled with the result. - POST /api/ai/detect-eligibility-info: Claude vision extraction of Member ID/DOB from uploaded screenshots. - POST /api/patients/create-temp: auto-creates a placeholder "PID-<id>" patient (matched by insuranceId+dob) when no patient is selected, so screenshots can be saved immediately; the real eligibility check later rewrites the patient's name and Cloud Storage folder automatically via the existing createOrUpdatePatientByInsuranceId matching logic. - Chatbot: Member ID/DOB on the confirm card are now editable (MM/DD/YYYY), with edits synced back to the patient record before the check runs. - Fixed a useEffect ordering bug on the insurance-status page that could silently clear a chatbot-prefilled Member ID/DOB before the auto-trigger effect ran, preventing the eligibility check from ever starting. - Added a local-disk-only screenshot backup (apps/Backend/uploads/ screenshot-backups/) for debugging, not exposed anywhere in the UI. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
@@ -30,6 +30,7 @@ export interface EligibilityProcessorResult {
|
||||
patientUpdateStatus?: string;
|
||||
pdfUploadStatus?: string;
|
||||
pdfFileId?: number | string | null;
|
||||
patientId?: number | null;
|
||||
}
|
||||
|
||||
export async function runEligibilityProcessor(
|
||||
@@ -109,6 +110,8 @@ export async function runEligibilityProcessor(
|
||||
throw new Error(`Failed to create/update patient: ${e.message}`);
|
||||
}
|
||||
|
||||
outputResult.patientId = patient?.id ?? null;
|
||||
|
||||
// 5) Update patient status
|
||||
if (patient && patient.id !== undefined) {
|
||||
let newStatus = "UNKNOWN";
|
||||
@@ -121,13 +124,24 @@ export async function runEligibilityProcessor(
|
||||
await storage.updatePatient(patient.id, updates);
|
||||
outputResult.patientUpdateStatus = `Patient status updated to ${newStatus}`;
|
||||
|
||||
// Rename the Copy Agent page's temp folder ("PID-<id>") to the real name now that we know
|
||||
// it — only touches folders still using that placeholder pattern, never a normal patient's.
|
||||
const patientName = `${patient.firstName ?? ""} ${patient.lastName ?? ""}`.trim() || `Patient ${patient.id}`;
|
||||
try {
|
||||
const existingFolder = await storage.getPatientFolder(patient.id);
|
||||
if (existingFolder && /^PID-\d+$/.test(existingFolder.name) && patientName) {
|
||||
await storage.updateFolder((existingFolder as any).id, { name: patientName });
|
||||
}
|
||||
} catch (e) {
|
||||
console.error("[eligibilityProcessor] temp folder rename failed:", e);
|
||||
}
|
||||
|
||||
// 6) Save PDF
|
||||
let createdPdfFileId: number | string | null = null;
|
||||
|
||||
if (seleniumResult.pdf_path?.endsWith(".pdf")) {
|
||||
try {
|
||||
const pdfBuffer = await fs.readFile(seleniumResult.pdf_path);
|
||||
const patientName = `${patient.firstName ?? ""} ${patient.lastName ?? ""}`.trim() || `Patient ${patient.id}`;
|
||||
|
||||
const cloudFile = await storage.savePdfToCloudStorage(
|
||||
userId,
|
||||
|
||||
Reference in New Issue
Block a user