fix: persist and correctly forward appointment attachments to insurance claims
- Add "surg ext" alias mapping to D7210 in the AI CDT lookup. - Add GET/DELETE endpoints for appointment attachments, and load existing attachments in the appointment edit modal (they were uploaded correctly but never re-fetched, so they appeared to vanish on reopen). - Fix claim-form.tsx so previously-saved appointment attachments are always loaded (even when a claim already exists) instead of only when creating a brand-new claim, preventing them from being silently wiped on save. - Merge existing appointment attachments into every insurance submit handler (MassHealth, CCA, DDMA, UnitedDH, TuftsSCO) so Selenium submission always includes files saved earlier via the Schedule editor, not just files uploaded in the current claim-form session. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
@@ -6,6 +6,8 @@ import {
|
||||
UpdateAppointmentProcedure,
|
||||
} from "@repo/db/types";
|
||||
import { prisma as db } from "@repo/db/client";
|
||||
import fs from "fs";
|
||||
import path from "path";
|
||||
|
||||
export interface AppointmentFileMeta {
|
||||
filename: string;
|
||||
@@ -50,6 +52,7 @@ export interface IAppointmentProceduresStorage {
|
||||
appointmentId: number,
|
||||
file: AppointmentFileMeta
|
||||
): Promise<AppointmentFileMeta & { id: number }>;
|
||||
deleteAppointmentFile(appointmentId: number, fileId: number): Promise<boolean>;
|
||||
getAppointmentIdsWithProcedures(ids: number[]): Promise<Set<number>>;
|
||||
getProcedureCodesByAppointmentIds(ids: number[]): Promise<Map<number, string[]>>;
|
||||
}
|
||||
@@ -225,4 +228,30 @@ export const appointmentProceduresStorage: IAppointmentProceduresStorage = {
|
||||
filePath: row.filePath,
|
||||
};
|
||||
},
|
||||
|
||||
async deleteAppointmentFile(appointmentId: number, fileId: number): Promise<boolean> {
|
||||
const file = await db.appointmentFile.findFirst({
|
||||
where: { id: fileId, appointmentId },
|
||||
});
|
||||
if (!file) return false;
|
||||
|
||||
await db.appointmentFile.delete({ where: { id: fileId } });
|
||||
|
||||
// Best-effort cleanup of the underlying cloud-storage file/disk copy.
|
||||
if (file.filePath) {
|
||||
const cloudFile = await db.cloudFile.findFirst({
|
||||
where: { diskPath: file.filePath },
|
||||
select: { id: true, diskPath: true },
|
||||
});
|
||||
if (cloudFile) {
|
||||
if (cloudFile.diskPath) {
|
||||
const abs = path.join(process.cwd(), cloudFile.diskPath);
|
||||
if (fs.existsSync(abs)) fs.unlinkSync(abs);
|
||||
}
|
||||
await db.cloudFile.delete({ where: { id: cloudFile.id } }).catch(() => null);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
},
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user