types updated

This commit is contained in:
2025-08-10 18:21:38 +05:30
parent 31ed4cd1da
commit 4b1ee273e4
44 changed files with 2049 additions and 1263 deletions

View File

@@ -14,39 +14,10 @@ import {
DialogContent,
DialogFooter,
} from "@/components/ui/dialog";
import { PatientForm, PatientFormRef } from "./patient-form";
import { useToast } from "@/hooks/use-toast";
import { PatientForm, PatientFormRef } from "./patient-form";
import { X, Calendar } from "lucide-react";
import { useLocation } from "wouter";
import { PatientUncheckedCreateInputObjectSchema } from "@repo/db/usedSchemas";
import { z } from "zod";
const PatientSchema = (
PatientUncheckedCreateInputObjectSchema as unknown as z.ZodObject<any>
).omit({
appointments: true,
});
type Patient = z.infer<typeof PatientSchema>;
const insertPatientSchema = (
PatientUncheckedCreateInputObjectSchema as unknown as z.ZodObject<any>
).omit({
id: true,
createdAt: true,
});
type InsertPatient = z.infer<typeof insertPatientSchema>;
const updatePatientSchema = (
PatientUncheckedCreateInputObjectSchema as unknown as z.ZodObject<any>
)
.omit({
id: true,
createdAt: true,
userId: true,
})
.partial();
type UpdatePatient = z.infer<typeof updatePatientSchema>;
import { InsertPatient, Patient, UpdatePatient } from "@repo/db/types";
interface AddPatientModalProps {
open: boolean;
@@ -108,12 +79,11 @@ export const AddPatientModal = forwardRef<
};
const handleSaveAndSchedule = () => {
setSaveAndSchedule(true);
if (patientFormRef.current) {
patientFormRef.current.submit();
}
};
setSaveAndSchedule(true);
if (patientFormRef.current) {
patientFormRef.current.submit();
}
};
return (
<Dialog open={open} onOpenChange={onOpenChange}>

View File

@@ -1,7 +1,5 @@
import { useForm } from "react-hook-form";
import { zodResolver } from "@hookform/resolvers/zod";
import { z } from "zod";
import { PatientUncheckedCreateInputObjectSchema } from "@repo/db/usedSchemas";
import { useAuth } from "@/hooks/use-auth";
import {
Form,
@@ -32,34 +30,14 @@ import { format } from "date-fns";
import { Button } from "../ui/button";
import { cn } from "@/lib/utils";
import { formatLocalDate, parseLocalDate } from "@/utils/dateUtils";
const PatientSchema = (
PatientUncheckedCreateInputObjectSchema as unknown as z.ZodObject<any>
).omit({
appointments: true,
});
type Patient = z.infer<typeof PatientSchema>;
const insertPatientSchema = (
PatientUncheckedCreateInputObjectSchema as unknown as z.ZodObject<any>
).omit({
id: true,
createdAt: true,
userId: true,
});
type InsertPatient = z.infer<typeof insertPatientSchema>;
const updatePatientSchema = (
PatientUncheckedCreateInputObjectSchema as unknown as z.ZodObject<any>
)
.omit({
id: true,
createdAt: true,
userId: true,
})
.partial();
type UpdatePatient = z.infer<typeof updatePatientSchema>;
import {
InsertPatient,
insertPatientSchema,
Patient,
UpdatePatient,
updatePatientSchema,
} from "@repo/db/types";
import { z } from "zod";
interface PatientFormProps {
patient?: Patient;

View File

@@ -85,25 +85,25 @@ export function PatientSearch({
<div className="relative flex-1">
{searchBy === "dob" ? (
<Popover>
<PopoverTrigger asChild>
<Button
variant="outline"
onKeyDown={(e) => {
if (e.key === "Enter") handleSearch();
}}
className={cn(
"w-full pl-3 pr-20 text-left font-normal",
!searchTerm && "text-muted-foreground"
)}
>
{searchTerm ? (
format(new Date(searchTerm), "PPP")
) : (
<span>Pick a date</span>
)}
<CalendarIcon className="ml-auto h-4 w-4 opacity-50" />
</Button>
</PopoverTrigger>
<PopoverTrigger asChild>
<Button
variant="outline"
onKeyDown={(e) => {
if (e.key === "Enter") handleSearch();
}}
className={cn(
"w-full pl-3 pr-20 text-left font-normal",
!searchTerm && "text-muted-foreground"
)}
>
{searchTerm ? (
format(new Date(searchTerm), "PPP")
) : (
<span>Pick a date</span>
)}
<CalendarIcon className="ml-auto h-4 w-4 opacity-50" />
</Button>
</PopoverTrigger>
<PopoverContent className="w-auto p-4">
<Calendar
mode="single"

View File

@@ -18,8 +18,6 @@ import {
PaginationNext,
PaginationPrevious,
} from "@/components/ui/pagination";
import { PatientUncheckedCreateInputObjectSchema } from "@repo/db/usedSchemas";
import { z } from "zod";
import { apiRequest, queryClient } from "@/lib/queryClient";
import { useMutation, useQuery } from "@tanstack/react-query";
import LoadingScreen from "../ui/LoadingScreen";
@@ -39,25 +37,7 @@ import { useDebounce } from "use-debounce";
import { cn } from "@/lib/utils";
import { Checkbox } from "../ui/checkbox";
import { formatDateToHumanReadable } from "@/utils/dateUtils";
const PatientSchema = (
PatientUncheckedCreateInputObjectSchema as unknown as z.ZodObject<any>
).omit({
appointments: true,
});
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>;
import { Patient, UpdatePatient } from "@repo/db/types";
interface PatientApiResponse {
patients: Patient[];
@@ -114,7 +94,7 @@ export function PatientTable({
const handleSelectPatient = (patient: Patient) => {
const isSelected = selectedPatientId === patient.id;
const newSelectedId = isSelected ? null : patient.id;
setSelectedPatientId(newSelectedId);
setSelectedPatientId(Number(newSelectedId));
if (onSelectPatient) {
onSelectPatient(isSelected ? null : patient);
@@ -258,7 +238,7 @@ export function PatientTable({
if (currentPatient && user) {
const { id, ...sanitizedPatient } = patient;
updatePatientMutation.mutate({
id: currentPatient.id,
id: Number(currentPatient.id),
patient: sanitizedPatient,
});
} else {
@@ -288,7 +268,7 @@ export function PatientTable({
const handleConfirmDeletePatient = async () => {
if (currentPatient) {
deletePatientMutation.mutate(currentPatient.id);
deletePatientMutation.mutate(Number(currentPatient.id));
} else {
toast({
title: "Error",
@@ -424,7 +404,7 @@ export function PatientTable({
<TableCell>
<div className="flex items-center">
<Avatar
className={`h-10 w-10 ${getAvatarColor(patient.id)}`}
className={`h-10 w-10 ${getAvatarColor(Number(patient.id))}`}
>
<AvatarFallback className="text-white">
{getInitials(patient.firstName, patient.lastName)}
@@ -436,7 +416,7 @@ export function PatientTable({
{patient.firstName} {patient.lastName}
</div>
<div className="text-sm text-gray-500">
PID-{patient.id.toString().padStart(4, "0")}
PID-{patient.id?.toString().padStart(4, "0")}
</div>
</div>
</div>
@@ -505,16 +485,16 @@ export function PatientTable({
</Button>
)}
{allowNewClaim && (
<Button
variant="ghost"
size="icon"
onClick={() => onNewClaim?.(patient.id)}
className="text-green-600 hover:text-green-800 hover:bg-green-50"
aria-label="New Claim"
>
<FileCheck className="h-5 w-5" />
</Button>
)}
<Button
variant="ghost"
size="icon"
onClick={() => onNewClaim?.(Number(patient.id))}
className="text-green-600 hover:text-green-800 hover:bg-green-50"
aria-label="New Claim"
>
<FileCheck className="h-5 w-5" />
</Button>
)}
{allowView && (
<Button
variant="ghost"
@@ -558,7 +538,7 @@ export function PatientTable({
{currentPatient.firstName} {currentPatient.lastName}
</h3>
<p className="text-gray-500">
Patient ID: {currentPatient.id.toString().padStart(4, "0")}
Patient ID: {currentPatient.id?.toString().padStart(4, "0")}
</p>
</div>
</div>
@@ -587,8 +567,10 @@ export function PatientTable({
: "text-red-600"
} font-medium`}
>
{currentPatient.status.charAt(0).toUpperCase() +
currentPatient.status.slice(1)}
{currentPatient.status
? currentPatient.status.charAt(0).toUpperCase() +
currentPatient.status.slice(1)
: "Unknown"}
</span>
</p>
</div>
@@ -706,7 +688,7 @@ export function PatientTable({
isOpen={isDeletePatientOpen}
onConfirm={handleConfirmDeletePatient}
onCancel={() => setIsDeletePatientOpen(false)}
entityName={currentPatient?.name}
entityName={currentPatient?.firstName}
/>
{/* Pagination */}
@@ -731,25 +713,25 @@ export function PatientTable({
}
/>
</PaginationItem>
{getPageNumbers(currentPage, totalPages).map((page, idx) => (
<PaginationItem key={idx}>
{page === "..." ? (
<span className="px-2 text-gray-500">...</span>
) : (
<PaginationLink
href="#"
onClick={(e) => {
e.preventDefault();
setCurrentPage(page as number);
}}
isActive={currentPage === page}
>
{page}
</PaginationLink>
)}
</PaginationItem>
))}
<PaginationItem key={idx}>
{page === "..." ? (
<span className="px-2 text-gray-500">...</span>
) : (
<PaginationLink
href="#"
onClick={(e) => {
e.preventDefault();
setCurrentPage(page as number);
}}
isActive={currentPage === page}
>
{page}
</PaginationLink>
)}
</PaginationItem>
))}
<PaginationItem>
<PaginationNext