all ui done

This commit is contained in:
2025-05-15 20:22:04 +05:30
parent bebe6cff83
commit ffe239783f
15 changed files with 480 additions and 520 deletions

View File

@@ -219,109 +219,6 @@ export default function PatientsPage() {
});
};
// Process file and extract patient information
const handleExtractInfo = async () => {
if (!uploadedFile) {
toast({
title: "No file selected",
description: "Please select a file first.",
variant: "destructive",
});
return;
}
setIsExtracting(true);
try {
// Read the file as base64
const reader = new FileReader();
// Set up a Promise to handle file reading
const fileReadPromise = new Promise<string>((resolve, reject) => {
reader.onload = (event) => {
if (event.target && typeof event.target.result === "string") {
resolve(event.target.result);
} else {
reject(new Error("Failed to read file as base64"));
}
};
reader.onerror = () => {
reject(new Error("Error reading file"));
};
// Read the file as a data URL (base64)
reader.readAsDataURL(uploadedFile);
});
// Get the base64 data
const base64Data = await fileReadPromise;
// Send file to server as base64
const response = await fetch("/api/upload-file", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
pdfData: base64Data,
filename: uploadedFile.name,
}),
credentials: "include",
});
if (!response.ok) {
throw new Error(
`Server returned ${response.status}: ${response.statusText}`
);
}
const data = await response.json();
if (data.success) {
// Only keep firstName, lastName, dateOfBirth, and insuranceId from the extracted info
const simplifiedInfo = {
firstName: data.extractedInfo.firstName,
lastName: data.extractedInfo.lastName,
dateOfBirth: data.extractedInfo.dateOfBirth,
insuranceId: data.extractedInfo.insuranceId,
};
setExtractedInfo(simplifiedInfo);
// Show success message
toast({
title: "Information Extracted",
description:
"Basic patient information (name, DOB, ID) has been extracted successfully.",
variant: "default",
});
// Open patient form pre-filled with extracted data
setCurrentPatient(undefined);
// Pre-fill the form by opening the modal with the extracted information
setTimeout(() => {
setIsAddPatientOpen(true);
}, 500);
} else {
throw new Error(data.message || "Failed to extract information");
}
} catch (error) {
console.error("Error extracting information:", error);
toast({
title: "Error",
description:
error instanceof Error
? error.message
: "Failed to extract information from file",
variant: "destructive",
});
} finally {
setIsExtracting(false);
}
};
// Filter patients based on search criteria
const filteredPatients = useMemo(() => {
if (!searchCriteria || !searchCriteria.searchTerm) {
@@ -424,7 +321,6 @@ export default function PatientsPage() {
<div className="md:col-span-1 flex items-end">
<Button
className="w-full h-12 gap-2"
onClick={handleExtractInfo}
disabled={!uploadedFile || isExtracting}
>
{isExtracting ? (