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

View File

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