forked from adrianhajdin/healthcare
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvalidation.ts
118 lines (112 loc) · 3.75 KB
/
validation.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
import { z } from "zod";
export const UserFormValidation = z.object({
name: z
.string()
.min(2, "Name must be at least 2 characters")
.max(50, "Name must be at most 50 characters"),
email: z.string().email("Invalid email address"),
phone: z
.string()
.refine((phone) => /^\+\d{10,15}$/.test(phone), "Invalid phone number"),
});
export const PatientFormValidation = z.object({
name: z
.string()
.min(2, "Name must be at least 2 characters")
.max(50, "Name must be at most 50 characters"),
email: z.string().email("Invalid email address"),
phone: z
.string()
.refine((phone) => /^\+\d{10,15}$/.test(phone), "Invalid phone number"),
birthDate: z.coerce.date(),
gender: z.enum(["Male", "Female", "Other"]),
address: z
.string()
.min(5, "Address must be at least 5 characters")
.max(500, "Address must be at most 500 characters"),
occupation: z
.string()
.min(2, "Occupation must be at least 2 characters")
.max(500, "Occupation must be at most 500 characters"),
emergencyContactName: z
.string()
.min(2, "Contact name must be at least 2 characters")
.max(50, "Contact name must be at most 50 characters"),
emergencyContactNumber: z
.string()
.refine(
(emergencyContactNumber) => /^\+\d{10,15}$/.test(emergencyContactNumber),
"Invalid phone number"
),
primaryPhysician: z.string().min(2, "Select at least one doctor"),
insuranceProvider: z
.string()
.min(2, "Insurance name must be at least 2 characters")
.max(50, "Insurance name must be at most 50 characters"),
insurancePolicyNumber: z
.string()
.min(2, "Policy number must be at least 2 characters")
.max(50, "Policy number must be at most 50 characters"),
allergies: z.string().optional(),
currentMedication: z.string().optional(),
familyMedicalHistory: z.string().optional(),
pastMedicalHistory: z.string().optional(),
identificationType: z.string().optional(),
identificationNumber: z.string().optional(),
identificationDocument: z.custom<File[]>().optional(),
treatmentConsent: z
.boolean()
.default(false)
.refine((value) => value === true, {
message: "You must consent to treatment in order to proceed",
}),
disclosureConsent: z
.boolean()
.default(false)
.refine((value) => value === true, {
message: "You must consent to disclosure in order to proceed",
}),
privacyConsent: z
.boolean()
.default(false)
.refine((value) => value === true, {
message: "You must consent to privacy in order to proceed",
}),
});
export const CreateAppointmentSchema = z.object({
primaryPhysician: z.string().min(2, "Select at least one doctor"),
schedule: z.coerce.date(),
reason: z
.string()
.min(2, "Reason must be at least 2 characters")
.max(500, "Reason must be at most 500 characters"),
note: z.string().optional(),
cancellationReason: z.string().optional(),
});
export const ScheduleAppointmentSchema = z.object({
primaryPhysician: z.string().min(2, "Select at least one doctor"),
schedule: z.coerce.date(),
reason: z.string().optional(),
note: z.string().optional(),
cancellationReason: z.string().optional(),
});
export const CancelAppointmentSchema = z.object({
primaryPhysician: z.string().min(2, "Select at least one doctor"),
schedule: z.coerce.date(),
reason: z.string().optional(),
note: z.string().optional(),
cancellationReason: z
.string()
.min(2, "Reason must be at least 2 characters")
.max(500, "Reason must be at most 500 characters"),
});
export function getAppointmentSchema(type: string) {
switch (type) {
case "create":
return CreateAppointmentSchema;
case "cancel":
return CancelAppointmentSchema;
default:
return ScheduleAppointmentSchema;
}
}