feat: Check Preauth from claim details, Tufts SCO approval PDF, all-folder appointment picker

- Same patient may be booked at the same time in different columns (appointment + preauth)
- New preauths save service lines and attachments so the details view shows them
- Claim/Preauth Details: renamed, Check Preauth button picks the worker from the claim's
  insurance (MassHealth, United SCO, Tufts SCO, CCA); OTP popup survives closing the window,
  window closes after a successful check
- Tufts SCO Check Preauth: searches Submitted by pre-auth number, saves the detail page PDF
  to the patient's new Approval folder (PdfTitleKey PREAUTH_APPROVAL migration)
- Appointment attachment picker lists files from all of the patient's folders

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-06 23:01:20 -05:00
co-authored by Claude Opus 5.5
parent 33bea3822c
commit 4cd780e9b2
40 changed files with 1003 additions and 113 deletions
@@ -25,3 +25,24 @@ export async function appendAppointmentFiles(
seenNames.add(f.filename);
}
}
// Links AppointmentFile records to a claim as ClaimFile records (dedup by filename).
// Called after claim create or update so files saved in the procedures form always appear.
export async function autoLinkAppointmentFiles(claimId: number, appointmentId: number | null | undefined) {
if (!appointmentId) return;
const { prisma: db } = await import("@repo/db/client");
const aptFiles = await db.appointmentFile.findMany({ where: { appointmentId } });
if (!aptFiles.length) return;
const existing = await db.claimFile.findMany({ where: { claimId }, select: { filename: true } });
const existingNames = new Set(existing.map((f: any) => f.filename));
const toLink = aptFiles.filter((f: any) => f.filename && !existingNames.has(f.filename));
if (!toLink.length) return;
await db.claimFile.createMany({
data: toLink.map((f: any) => ({
claimId,
filename: f.filename,
mimeType: f.mimeType ?? "",
...(f.filePath ? { filePath: String(f.filePath) } : {}),
})),
});
}
+46
View File
@@ -0,0 +1,46 @@
const safeDate = (value: unknown, fallback: Date): Date => {
if (!value) return fallback;
const parsed = new Date(value as string);
return isNaN(parsed.getTime()) ? fallback : parsed;
};
// Procedures, attachments and missing teeth to save on a PREAUTH claim record, so its
// details match a regular claim. Bad values fall back rather than throw: a failed
// createClaim would lose the record that holds the preauth number.
export function buildPreAuthClaimDetails(claimData: any, serviceDate: Date) {
const rawLines: any[] = Array.isArray(claimData.serviceLines) ? claimData.serviceLines : [];
const rawFiles: any[] = Array.isArray(claimData.claimFiles) ? claimData.claimFiles : [];
const files = rawFiles.filter((f) => f?.filename);
return {
...(rawLines.length > 0
? {
serviceLines: {
create: rawLines.map((sl) => ({
procedureCode: sl.procedureCode ?? "",
procedureDate: safeDate(sl.procedureDate, serviceDate),
quad: sl.quad ?? "",
arch: sl.arch ?? "",
toothNumber: sl.toothNumber ?? "",
toothSurface: sl.toothSurface ?? "",
totalBilled: Number(sl.totalBilled) || 0,
totalAdjusted: Number(sl.totalAdjusted) || 0,
totalPaid: Number(sl.totalPaid) || 0,
})),
},
}
: {}),
...(files.length > 0
? {
claimFiles: {
create: files.map((f) => ({
filename: String(f.filename),
mimeType: String(f.mimeType ?? ""),
...(f.filePath ? { filePath: String(f.filePath) } : {}),
})),
},
}
: {}),
...(claimData.missingTeeth ? { missingTeeth: claimData.missingTeeth } : {}),
};
}