checkpoint date working

This commit is contained in:
2025-06-01 18:35:51 +05:30
parent c91d5efb05
commit 0844c1296e
15 changed files with 511 additions and 77 deletions

View File

@@ -3,6 +3,9 @@ import { Request, Response } from "express";
import { storage } from "../storage";
import { z } from "zod";
import { ClaimUncheckedCreateInputObjectSchema } from "@repo/db/usedSchemas";
import multer from "multer";
import forwardToSeleniumAgent from "../services/seleniumClient";
const router = Router();
@@ -37,6 +40,26 @@ const ExtendedClaimSchema = (
});
// Routes
const multerStorage = multer.memoryStorage(); // NO DISK
const upload = multer({ storage: multerStorage });
router.post("/selenium", upload.array("pdfs"), async (req: Request, res: Response): Promise<any> => {
if (!req.files || !req.body.data) {
return res.status(400).json({ error: "Missing files or claim data for selenium" });
}
try {
const claimData = JSON.parse(req.body.data);
const files = req.files as Express.Multer.File[];
const result = await forwardToSeleniumAgent(claimData, files);
res.json({ success: true, data: result });
} catch (err) {
console.error(err);
res.status(500).json({ error: "Failed to forward to selenium agent" });
}
});
// Get all claims for the logged-in user
router.get("/", async (req: Request, res: Response) => {

View File

@@ -200,18 +200,10 @@ router.delete(
.json({ message: "Forbidden: Patient belongs to a different user" });
}
const appointments = await storage.getAppointmentsByPatientId(patientId);
console.log(appointments)
if (appointments.length > 0) {
throw new Error(`Cannot delete patient with ID ${patientId} because they have appointments`);
}
// Delete patient
await storage.deletePatient(patientId);
res.status(204).send();
} catch (error:any) {
if (error.message.includes("have appointments")) {
return res.status(400).json({ message: error.message });
}
console.error("Delete patient error:", error);
res.status(500).json({ message: "Failed to delete patient" });
}

View File

@@ -2,7 +2,7 @@ import { Router } from "express";
import type { Request, Response } from "express";
const router = Router();
import multer from "multer";
import forwardToPythonService from "../services/pythonClient";
import forwardToPdfService from "../services/PdfClient";
const upload = multer({ storage: multer.memoryStorage() });
@@ -12,7 +12,7 @@ router.post("/extract", upload.single("pdf"), async (req: Request, res: Response
}
try {
const result = await forwardToPythonService(req.file);
const result = await forwardToPdfService(req.file);
res.json(result);
} catch (err) {
console.error(err);

View File

@@ -9,7 +9,7 @@ export interface ExtractedData {
[key: string]: any;
}
export default async function forwardToPythonService(
export default async function forwardToPdfService(
file: Express.Multer.File
): Promise<ExtractedData> {
const form = new FormData();

View File

@@ -0,0 +1,25 @@
import axios from "axios";
export interface SeleniumPayload {
claim: any;
pdfs: {
originalname: string;
bufferBase64: string;
}[];
}
export default async function forwardToSeleniumAgent(
claimData: any,
files: Express.Multer.File[]
): Promise<any> {
const payload: SeleniumPayload = {
claim: claimData,
pdfs: files.map(file => ({
originalname: file.originalname,
bufferBase64: file.buffer.toString("base64"),
})),
};
const response = await axios.post("http://localhost:5002/run", payload);
return response.data;
}

View File

@@ -227,7 +227,8 @@ export const storage: IStorage = {
try {
await db.patient.delete({ where: { id } });
} catch (err) {
throw new Error(`Patient with ID ${id} not found`);
console.error("Error deleting patient:", err);
throw new Error(`Failed to delete patient: ${err}`);
}
},