feat: save insurance PDFs (eligibility/claims/preauth) to Cloud Storage instead of Postgres blobs
New saves go into the patient's Cloud Storage folder under category subfolders (Eligibility/Claims/PreAuth/Claim Status/Attachments) via a new storage.savePdfToCloudStorage helper, instead of the legacy PdfGroup/PdfFile Postgres blob tables. Old records and their read paths are left untouched for backward compatibility; PDF list/content/delete endpoints and viewers now transparently handle both legacy numeric ids and new "cloud:<id>" ids. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
@@ -88,15 +88,22 @@ async function pollUntilDone(
|
||||
throw new Error(`DDMA claim polling exhausted all attempts for session ${sessionId}`);
|
||||
}
|
||||
|
||||
async function savePdfFromSelenium(pdf_url: string, patientId: number) {
|
||||
async function savePdfFromSelenium(pdf_url: string, patientId: number, userId: number) {
|
||||
try {
|
||||
const filename = path.basename(new URL(pdf_url).pathname);
|
||||
const seleniumPort = process.env.SELENIUM_PORT || "5002";
|
||||
const localUrl = `http://localhost:${seleniumPort}/downloads/${filename}`;
|
||||
const resp = await axios.get(localUrl, { responseType: "arraybuffer", timeout: 30000 });
|
||||
let group = await storage.findPdfGroupByPatientTitleKey(patientId, "INSURANCE_CLAIM");
|
||||
if (!group) group = await storage.createPdfGroup(patientId, "Claims", "INSURANCE_CLAIM");
|
||||
await storage.createPdfFile(group.id!, filename, resp.data);
|
||||
const patient = await storage.getPatient(patientId);
|
||||
const patientName = patient ? `${patient.firstName} ${patient.lastName}` : `Patient ${patientId}`;
|
||||
await storage.savePdfToCloudStorage(
|
||||
userId,
|
||||
patientId,
|
||||
patientName,
|
||||
"Claims",
|
||||
filename,
|
||||
Buffer.from(resp.data)
|
||||
);
|
||||
log("ddma-claim-processor", "PDF saved", { patientId, filename });
|
||||
} catch (err: any) {
|
||||
log("ddma-claim-processor", "failed to save PDF (non-fatal)", { error: err?.message ?? err });
|
||||
@@ -160,7 +167,7 @@ export async function runDDMAClaimProcessor(
|
||||
if (pdf_url && !socketId) {
|
||||
const claim = claimId ? await storage.getClaim(claimId).catch(() => null) : null;
|
||||
const patientId = claim?.patientId ?? enrichedPayload?.claim?.patientId ?? enrichedPayload?.patientId;
|
||||
if (patientId) await savePdfFromSelenium(pdf_url, Number(patientId));
|
||||
if (patientId) await savePdfFromSelenium(pdf_url, Number(patientId), userId);
|
||||
}
|
||||
|
||||
emitToSocket(socketId, "selenium:ddma_claim_completed", {
|
||||
|
||||
Reference in New Issue
Block a user