appointment creation done, claim form raw done

This commit is contained in:
2025-05-30 18:32:23 +05:30
parent f6d7d9f93b
commit ebd5f514be
3 changed files with 54 additions and 51 deletions

View File

@@ -19,7 +19,10 @@ import {
PopoverContent, PopoverContent,
PopoverTrigger, PopoverTrigger,
} from "@/components/ui/popover"; } from "@/components/ui/popover";
import { PatientUncheckedCreateInputObjectSchema, AppointmentUncheckedCreateInputObjectSchema} from "@repo/db/usedSchemas"; import {
PatientUncheckedCreateInputObjectSchema,
AppointmentUncheckedCreateInputObjectSchema,
} from "@repo/db/usedSchemas";
import { z } from "zod"; import { z } from "zod";
import { useQuery } from "@tanstack/react-query"; import { useQuery } from "@tanstack/react-query";
import { apiRequest } from "@/lib/queryClient"; import { apiRequest } from "@/lib/queryClient";
@@ -32,7 +35,6 @@ const PatientSchema = (
}); });
type Patient = z.infer<typeof PatientSchema>; type Patient = z.infer<typeof PatientSchema>;
//creating types out of schema auto generated. //creating types out of schema auto generated.
type Appointment = z.infer<typeof AppointmentUncheckedCreateInputObjectSchema>; type Appointment = z.infer<typeof AppointmentUncheckedCreateInputObjectSchema>;
@@ -55,7 +57,6 @@ const updateAppointmentSchema = (
.partial(); .partial();
type UpdateAppointment = z.infer<typeof updateAppointmentSchema>; type UpdateAppointment = z.infer<typeof updateAppointmentSchema>;
interface ServiceLine { interface ServiceLine {
procedure_code: string; procedure_code: string;
procedure_date: string; procedure_date: string;
@@ -69,7 +70,9 @@ interface ClaimFormProps {
patientId?: number; patientId?: number;
extractedData?: Partial<Patient>; extractedData?: Partial<Patient>;
onSubmit: (claimData: any) => void; onSubmit: (claimData: any) => void;
onHandleAppointmentSubmit: (appointmentData: InsertAppointment | UpdateAppointment) => void; onHandleAppointmentSubmit: (
appointmentData: InsertAppointment | UpdateAppointment
) => void;
onClose: () => void; onClose: () => void;
} }
@@ -126,6 +129,12 @@ export function ClaimForm({
return res.json(); return res.json();
}, },
}); });
useEffect(() => {
if (staffMembersRaw.length > 0 && !staff) {
const firstStaff = staffMembersRaw[0];
if (firstStaff) setStaff(firstStaff);
}
}, [staffMembersRaw, staff]);
// Service date state // Service date state
const [serviceDateValue, setServiceDateValue] = useState<Date>(new Date()); const [serviceDateValue, setServiceDateValue] = useState<Date>(new Date());
@@ -149,8 +158,7 @@ export function ClaimForm({
function convertToISODate(mmddyyyy: string): string { function convertToISODate(mmddyyyy: string): string {
const [month, day, year] = mmddyyyy.split("/"); const [month, day, year] = mmddyyyy.split("/");
return `${year}-${month?.padStart(2, "0")}-${day?.padStart(2, "0")}`; return `${year}-${month?.padStart(2, "0")}-${day?.padStart(2, "0")}`;
} }
// Remarks state // Remarks state
const [remarks, setRemarks] = useState<string>(""); const [remarks, setRemarks] = useState<string>("");
@@ -363,8 +371,11 @@ export function ClaimForm({
}} }}
> >
<SelectTrigger className="w-36"> <SelectTrigger className="w-36">
<SelectValue placeholder="Select Staff" /> <SelectValue
placeholder={staff ? staff.name : "Select Staff"}
/>
</SelectTrigger> </SelectTrigger>
<SelectContent> <SelectContent>
{staffMembersRaw.map((member) => ( {staffMembersRaw.map((member) => (
<SelectItem key={member.id} value={member.id}> <SelectItem key={member.id} value={member.id}>
@@ -529,11 +540,15 @@ export function ClaimForm({
const appointmentData = { const appointmentData = {
patientId: patientId, patientId: patientId,
date: convertToISODate(serviceDate), date: convertToISODate(serviceDate),
staffId:staff?.id, staffId: staff?.id,
}; };
// 1. Create or update appointment // 1. Create or update appointment
onHandleAppointmentSubmit(appointmentData);}} onHandleAppointmentSubmit(appointmentData);
// close form
onClose();
}}
> >
Delta MA Delta MA
</Button> </Button>

View File

@@ -85,7 +85,7 @@ interface ScheduledAppointment {
id?: number; id?: number;
patientId: number; patientId: number;
patientName: string; patientName: string;
staffId: string; staffId: number;
date: string | Date; date: string | Date;
startTime: string | Date; startTime: string | Date;
endTime: string | Date; endTime: string | Date;
@@ -190,7 +190,7 @@ export default function AppointmentsPage() {
// Handle creating a new appointment at a specific time slot and for a specific staff member // Handle creating a new appointment at a specific time slot and for a specific staff member
const handleCreateAppointmentAtSlot = ( const handleCreateAppointmentAtSlot = (
timeSlot: TimeSlot, timeSlot: TimeSlot,
staffId: string staffId: number
) => { ) => {
// Calculate end time (30 minutes after start time) // Calculate end time (30 minutes after start time)
const startHour = parseInt(timeSlot.time.split(":")[0] as string); const startHour = parseInt(timeSlot.time.split(":")[0] as string);
@@ -202,7 +202,7 @@ export default function AppointmentsPage() {
const endTime = `${endDate.getHours().toString().padStart(2, "0")}:${endDate.getMinutes().toString().padStart(2, "0")}`; const endTime = `${endDate.getHours().toString().padStart(2, "0")}:${endDate.getMinutes().toString().padStart(2, "0")}`;
// Find staff member // Find staff member
const staff = staffMembers.find((s) => s.id === staffId); const staff = staffMembers.find((s) => Number(s.id) === Number(staffId));
// Pre-fill appointment form with default values // Pre-fill appointment form with default values
const newAppointment = { const newAppointment = {
@@ -259,7 +259,7 @@ export default function AppointmentsPage() {
timeSlots.find((slot) => slot.time === "09:00") || timeSlots[0]; timeSlots.find((slot) => slot.time === "09:00") || timeSlots[0];
// Open appointment modal with prefilled patient // Open appointment modal with prefilled patient
handleCreateAppointmentAtSlot(defaultTimeSlot!, staffId); handleCreateAppointmentAtSlot(defaultTimeSlot!, Number(staffId));
// Pre-select the patient in the appointment form // Pre-select the patient in the appointment form
const patientData = { const patientData = {
@@ -280,7 +280,6 @@ export default function AppointmentsPage() {
} }
} }
} }
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [patients, user, location]); }, [patients, user, location]);
// Create appointment mutation // Create appointment mutation
@@ -479,28 +478,17 @@ export default function AppointmentsPage() {
? `${patient.firstName} ${patient.lastName}` ? `${patient.firstName} ${patient.lastName}`
: "Unknown Patient"; : "Unknown Patient";
// Try to determine the staff from the notes or title let staffId: number;
let staffId = "doctor1"; // Default to first doctor if we can't determine
// Check notes first if (
if (apt.notes) { staffMembers &&
// Look for "Appointment with Dr. X" or similar patterns staffMembers.length > 0 &&
for (const staff of staffMembers) { staffMembers[0] !== undefined &&
if (apt.notes.includes(staff.name)) { staffMembers[0].id !== undefined
staffId = staff.id; ) {
break; staffId = Number(apt.staffId);
} } else {
} staffId = 1;
}
// If no match in notes, check title
if (staffId === "doctor1" && apt.title) {
for (const staff of staffMembers) {
if (apt.title.includes(staff.name)) {
staffId = staff.id;
break;
}
}
} }
const processed = { const processed = {
@@ -515,7 +503,7 @@ export default function AppointmentsPage() {
}); });
// Check if appointment exists at a specific time slot and staff // Check if appointment exists at a specific time slot and staff
const getAppointmentAtSlot = (timeSlot: TimeSlot, staffId: string) => { const getAppointmentAtSlot = (timeSlot: TimeSlot, staffId: number) => {
if (processedAppointments.length === 0) { if (processedAppointments.length === 0) {
return undefined; return undefined;
} }
@@ -552,7 +540,7 @@ export default function AppointmentsPage() {
const handleMoveAppointment = ( const handleMoveAppointment = (
appointmentId: number, appointmentId: number,
newTimeSlot: TimeSlot, newTimeSlot: TimeSlot,
newStaffId: string newStaffId: number
) => { ) => {
const appointment = appointments.find((a) => a.id === appointmentId); const appointment = appointments.find((a) => a.id === appointmentId);
if (!appointment) return; if (!appointment) return;
@@ -567,7 +555,7 @@ export default function AppointmentsPage() {
const endTime = `${endDate.getHours().toString().padStart(2, "0")}:${endDate.getMinutes().toString().padStart(2, "0")}`; const endTime = `${endDate.getHours().toString().padStart(2, "0")}:${endDate.getMinutes().toString().padStart(2, "0")}`;
// Find staff member // Find staff member
const staff = staffMembers.find((s) => s.id === newStaffId); const staff = staffMembers.find((s) => Number(s.id) === newStaffId);
// Update appointment data // Update appointment data
const { id, createdAt, ...sanitizedAppointment } = appointment; const { id, createdAt, ...sanitizedAppointment } = appointment;
@@ -653,7 +641,7 @@ export default function AppointmentsPage() {
staff, staff,
}: { }: {
timeSlot: TimeSlot; timeSlot: TimeSlot;
staffId: string; staffId: number;
appointment: ScheduledAppointment | undefined; appointment: ScheduledAppointment | undefined;
staff: Staff; staff: Staff;
}) { }) {
@@ -851,10 +839,10 @@ export default function AppointmentsPage() {
<DroppableTimeSlot <DroppableTimeSlot
key={`${timeSlot.time}-${staff.id}`} key={`${timeSlot.time}-${staff.id}`}
timeSlot={timeSlot} timeSlot={timeSlot}
staffId={staff.id} staffId={Number(staff.id)}
appointment={getAppointmentAtSlot( appointment={getAppointmentAtSlot(
timeSlot, timeSlot,
staff.id Number(staff.id)
)} )}
staff={staff} staff={staff}
/> />
@@ -924,7 +912,7 @@ export default function AppointmentsPage() {
{ {
processedAppointments.filter( processedAppointments.filter(
(apt) => (apt) =>
staffMembers.find((s) => s.id === apt.staffId) staffMembers.find((s) => Number(s.id) === apt.staffId)
?.role === "doctor" ?.role === "doctor"
).length ).length
} }
@@ -938,7 +926,7 @@ export default function AppointmentsPage() {
{ {
processedAppointments.filter( processedAppointments.filter(
(apt) => (apt) =>
staffMembers.find((s) => s.id === apt.staffId) staffMembers.find((s) => Number(s.id) === apt.staffId)
?.role === "hygienist" ?.role === "hygienist"
).length ).length
} }

View File

@@ -57,7 +57,7 @@ model Appointment {
id Int @id @default(autoincrement()) id Int @id @default(autoincrement())
patientId Int patientId Int
userId Int userId Int
staffId Int? // Optional: Appointment may or may not have staff assigned staffId Int
title String title String
date DateTime @db.Date date DateTime @db.Date
startTime String // Store time as "hh:mm" startTime String // Store time as "hh:mm"