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:
@@ -26,13 +26,13 @@ export interface CmspEligibilityHistoryRemainingProcessorInput {
|
||||
export interface CmspEligibilityHistoryRemainingProcessorResult {
|
||||
patientUpdateStatus?: string;
|
||||
pdfUploadStatus?: string;
|
||||
pdfFileId?: number | null;
|
||||
pdfFileId?: number | string | null;
|
||||
pdfFilename?: string | null;
|
||||
memberDetailsPdfFileId?: number | null;
|
||||
memberDetailsPdfFileId?: number | string | null;
|
||||
memberDetailsPdfFilename?: string | null;
|
||||
historyPdfFileId?: number | null;
|
||||
historyPdfFileId?: number | string | null;
|
||||
historyPdfFilename?: string | null;
|
||||
accumulatorPdfFileId?: number | null;
|
||||
accumulatorPdfFileId?: number | string | null;
|
||||
accumulatorPdfFilename?: string | null;
|
||||
}
|
||||
|
||||
@@ -108,20 +108,20 @@ export async function runCmspEligibilityHistoryRemainingProcessor(
|
||||
await storage.updatePatient(patient.id, updates);
|
||||
outputResult.patientUpdateStatus = `Patient status updated to ${newStatus}`;
|
||||
|
||||
// Helper: save a single PDF to the patient's ELIGIBILITY_STATUS group
|
||||
const saveToGroup = async (pdfPath: string): Promise<number | null> => {
|
||||
// Helper: save a single PDF to the patient's Cloud Storage Eligibility folder
|
||||
const patientName = `${patient!.firstName ?? ""} ${patient!.lastName ?? ""}`.trim() || `Patient ${patient!.id}`;
|
||||
const saveToGroup = async (pdfPath: string): Promise<number | string | null> => {
|
||||
try {
|
||||
const buffer = await fs.readFile(pdfPath);
|
||||
const groupTitleKey = "ELIGIBILITY_STATUS";
|
||||
const groupTitle = "Eligibility Status";
|
||||
let group = await storage.findPdfGroupByPatientTitleKey(patient!.id, groupTitleKey);
|
||||
if (!group) group = await storage.createPdfGroup(patient!.id, groupTitle, groupTitleKey);
|
||||
if (!group?.id) throw new Error("PDF group creation failed");
|
||||
const created = await storage.createPdfFile(group.id, path.basename(pdfPath), buffer);
|
||||
if (created && typeof created === "object" && "id" in created) {
|
||||
return Number(created.id);
|
||||
}
|
||||
return null;
|
||||
const cloudFile = await storage.savePdfToCloudStorage(
|
||||
userId,
|
||||
patient!.id,
|
||||
patientName,
|
||||
"Eligibility",
|
||||
path.basename(pdfPath),
|
||||
buffer
|
||||
);
|
||||
return `cloud:${cloudFile.id}`;
|
||||
} catch (e: any) {
|
||||
console.error("[cmspProcessor] saveToGroup failed:", e.message);
|
||||
return null;
|
||||
|
||||
Reference in New Issue
Block a user