claim routes work being done
This commit is contained in:
@@ -35,6 +35,18 @@ const PatientSchema = (
|
||||
});
|
||||
type Patient = z.infer<typeof PatientSchema>;
|
||||
|
||||
const updatePatientSchema = (
|
||||
PatientUncheckedCreateInputObjectSchema as unknown as z.ZodObject<any>
|
||||
)
|
||||
.omit({
|
||||
id: true,
|
||||
createdAt: true,
|
||||
userId: true,
|
||||
})
|
||||
.partial();
|
||||
|
||||
type UpdatePatient = z.infer<typeof updatePatientSchema>;
|
||||
|
||||
//creating types out of schema auto generated.
|
||||
type Appointment = z.infer<typeof AppointmentUncheckedCreateInputObjectSchema>;
|
||||
|
||||
@@ -73,6 +85,7 @@ interface ClaimFormProps {
|
||||
onHandleAppointmentSubmit: (
|
||||
appointmentData: InsertAppointment | UpdateAppointment
|
||||
) => void;
|
||||
onHandleUpdatePatient: (patient: UpdatePatient & { id: number }) => void;
|
||||
onClose: () => void;
|
||||
}
|
||||
|
||||
@@ -87,11 +100,13 @@ export function ClaimForm({
|
||||
patientId,
|
||||
extractedData,
|
||||
onHandleAppointmentSubmit,
|
||||
onHandleUpdatePatient,
|
||||
onSubmit,
|
||||
onClose,
|
||||
}: ClaimFormProps) {
|
||||
const { toast } = useToast();
|
||||
|
||||
const [insuranceProvider, setInsuranceProvider] = useState(null)
|
||||
// Query patient if patientId provided
|
||||
const {
|
||||
data: fetchedPatient,
|
||||
@@ -254,6 +269,39 @@ export function ClaimForm({
|
||||
setIsUploading(false);
|
||||
};
|
||||
|
||||
const handleDeltaMASubmit = () => {
|
||||
const appointmentData = {
|
||||
patientId: patientId,
|
||||
date: convertToISODate(serviceDate),
|
||||
staffId: staff?.id,
|
||||
};
|
||||
|
||||
// 1. Create or update appointment
|
||||
onHandleAppointmentSubmit(appointmentData);
|
||||
|
||||
// 2. Update patient
|
||||
if (patient && typeof patient.id === "number") {
|
||||
const { id, createdAt, userId, ...sanitizedFields } = patient;
|
||||
const updatedPatientFields = {
|
||||
id,
|
||||
... sanitizedFields,
|
||||
insuranceProvider: "Delta MA",
|
||||
}
|
||||
onHandleUpdatePatient(updatedPatientFields);
|
||||
} else {
|
||||
toast({
|
||||
title: "Error",
|
||||
description: "Cannot update patient: Missing or invalid patient data",
|
||||
variant: "destructive",
|
||||
});
|
||||
}
|
||||
|
||||
// 3. Create Claim(if not)
|
||||
|
||||
// 4. Close form
|
||||
onClose();
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4 overflow-y-auto">
|
||||
<Card className="w-full max-w-5xl max-h-[90vh] overflow-y-auto bg-white">
|
||||
@@ -536,19 +584,7 @@ export function ClaimForm({
|
||||
<Button
|
||||
className="w-32"
|
||||
variant="outline"
|
||||
onClick={() => {
|
||||
const appointmentData = {
|
||||
patientId: patientId,
|
||||
date: convertToISODate(serviceDate),
|
||||
staffId: staff?.id,
|
||||
};
|
||||
|
||||
// 1. Create or update appointment
|
||||
onHandleAppointmentSubmit(appointmentData);
|
||||
|
||||
// close form
|
||||
onClose();
|
||||
}}
|
||||
onClick={handleDeltaMASubmit}
|
||||
>
|
||||
Delta MA
|
||||
</Button>
|
||||
|
||||
@@ -68,9 +68,6 @@ export default function ClaimsPage() {
|
||||
const [isMobileMenuOpen, setIsMobileMenuOpen] = useState(false);
|
||||
const [isClaimFormOpen, setIsClaimFormOpen] = useState(false);
|
||||
const [selectedPatient, setSelectedPatient] = useState<number | null>(null);
|
||||
const [selectedAppointment, setSelectedAppointment] = useState<number | null>(
|
||||
null
|
||||
);
|
||||
const { toast } = useToast();
|
||||
const { user } = useAuth();
|
||||
const [claimFormData, setClaimFormData] = useState<any>({
|
||||
@@ -126,6 +123,35 @@ export default function ClaimsPage() {
|
||||
},
|
||||
});
|
||||
|
||||
// Update patient mutation
|
||||
const updatePatientMutation = useMutation({
|
||||
mutationFn: async ({
|
||||
id,
|
||||
patient,
|
||||
}: {
|
||||
id: number;
|
||||
patient: UpdatePatient;
|
||||
}) => {
|
||||
const res = await apiRequest("PUT", `/api/patients/${id}`, patient);
|
||||
return res.json();
|
||||
},
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: ["/api/patients/"] });
|
||||
toast({
|
||||
title: "Success",
|
||||
description: "Patient updated successfully!",
|
||||
variant: "default",
|
||||
});
|
||||
},
|
||||
onError: (error) => {
|
||||
toast({
|
||||
title: "Error",
|
||||
description: `Failed to update patient: ${error.message}`,
|
||||
variant: "destructive",
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
// Create appointment mutation
|
||||
const createAppointmentMutation = useMutation({
|
||||
mutationFn: async (appointment: InsertAppointment) => {
|
||||
@@ -281,9 +307,8 @@ export default function ClaimsPage() {
|
||||
setIsMobileMenuOpen(!isMobileMenuOpen);
|
||||
};
|
||||
|
||||
const handleNewClaim = (patientId: number, appointmentId: number) => {
|
||||
const handleNewClaim = (patientId: number) => {
|
||||
setSelectedPatient(patientId);
|
||||
setSelectedAppointment(appointmentId);
|
||||
setIsClaimFormOpen(true);
|
||||
|
||||
const patient = patients.find((p) => p.id === patientId);
|
||||
@@ -295,7 +320,6 @@ export default function ClaimsPage() {
|
||||
const closeClaim = () => {
|
||||
setIsClaimFormOpen(false);
|
||||
setSelectedPatient(null);
|
||||
setSelectedAppointment(null);
|
||||
setClaimFormData({
|
||||
patientId: null,
|
||||
serviceDate: "",
|
||||
@@ -398,6 +422,24 @@ export default function ClaimsPage() {
|
||||
}>
|
||||
);
|
||||
|
||||
// Update Patient ( for insuranceId and Insurance Provider)
|
||||
const handleUpdatePatient = (patient: UpdatePatient & { id?: number }) => {
|
||||
if (patient && user) {
|
||||
const { id, ...sanitizedPatient } = patient;
|
||||
updatePatientMutation.mutate({
|
||||
id: Number(patient.id),
|
||||
patient: sanitizedPatient,
|
||||
});
|
||||
} else {
|
||||
console.error("No current patient or user found for update");
|
||||
toast({
|
||||
title: "Error",
|
||||
description: "Cannot update patient: No patient or user found",
|
||||
variant: "destructive",
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="flex h-screen overflow-hidden bg-gray-100">
|
||||
<Sidebar
|
||||
@@ -429,7 +471,6 @@ export default function ClaimsPage() {
|
||||
const firstPatient = patientsWithAppointments[0];
|
||||
handleNewClaim(
|
||||
Number(firstPatient?.patientId),
|
||||
Number(firstPatient?.appointmentId)
|
||||
);
|
||||
} else {
|
||||
toast({
|
||||
@@ -465,7 +506,7 @@ export default function ClaimsPage() {
|
||||
key={item.patientId}
|
||||
className="py-4 flex items-center justify-between cursor-pointer hover:bg-gray-50"
|
||||
onClick={() =>
|
||||
handleNewClaim(item.patientId, item.appointmentId)
|
||||
handleNewClaim(item.patientId)
|
||||
}
|
||||
>
|
||||
<div>
|
||||
@@ -519,6 +560,7 @@ export default function ClaimsPage() {
|
||||
extractedData={claimFormData}
|
||||
onSubmit={handleClaimSubmit}
|
||||
onHandleAppointmentSubmit={handleAppointmentSubmit}
|
||||
onHandleUpdatePatient={handleUpdatePatient}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user