diff --git a/public/locale/en.json b/public/locale/en.json index 56c0472e115..85715bd73c3 100644 --- a/public/locale/en.json +++ b/public/locale/en.json @@ -340,6 +340,7 @@ "add_spoke": "Add Spoke Facility", "additional_information": "Additional Information", "address": "Address", + "address_is_required": "Address is required", "administer": "Administer", "administer_medicine": "Administer Medicine", "administer_medicines": "Administer Medicines", @@ -462,6 +463,7 @@ "beta": "beta", "bladder": "Bladder", "blood_group": "Blood Group", + "blood_group_is_required": "Blood group is required", "blood_pressure_error": { "missing": "Field is required. Either specify both or clear both.", "exceed": "Value cannot exceed 250 mmHg.", @@ -669,6 +671,8 @@ "date_of_admission": "Date of Admission", "date_of_birth": "Date of Birth", "date_of_birth_age": "Date of Birth/Age", + "date_of_birth_format": "Date of birth must be in YYYY-MM-DD format", + "date_of_birth_must_be_present": "Date of birth must be present", "date_of_birth_or_age": "Date of Birth or Age", "date_of_positive_covid_19_swab": "Date of Positive Covid 19 Swab", "date_of_result": "Covid confirmation date", @@ -977,12 +981,14 @@ "full_name": "Full Name", "full_screen": "Full Screen", "gender": "Gender", + "gender_is_required": "Gender is required", "general_info_detail": "Provide the patient's personal details, including name, date of birth, gender, and contact information for accurate identification and communication.", "generate_link_abha": "Generate/Link ABHA Number", "generate_report": "Generate Report", "generated_summary_caution": "This is a computer generated summary using the information captured in the CARE system.", "generating": "Generating", "generating_discharge_summary": "Generating discharge summary", + "geo_organization_is_required": "Geo organization is required when nationality is India", "get_auth_methods": "Get Available Authentication Methods", "get_auth_mode_error": "Could not find any supported authentication methods, Please try again with a different authentication method", "get_tests": "Get Tests", @@ -1220,9 +1226,11 @@ "my_doctors": "My Doctors", "my_profile": "My Profile", "name": "Name", + "name_is_required": "Name is required", "name_of_hospital": "Name of Hospital", "name_of_shifting_approving_facility": "Name of shifting approving facility", "nationality": "Nationality", + "nationality_is_required": "Nationality is required", "nearby_facilities": "Nearby Facilities", "never": "never", "new_password": "New Password", @@ -1405,6 +1413,7 @@ "patient_update_success": "Patient Updated Sucessfully", "patients": "Patients", "pending": "Pending", + "permanant_address_is_required": "Permanant address is required", "permanent_address": "Permanent Address", "permission_denied": "You do not have permission to perform this action", "personal_information": "Personal Information", @@ -1416,9 +1425,11 @@ "phone_number": "Phone Number", "phone_number_at_current_facility": "Phone Number of Contact person at current Facility", "phone_number_min_error": "Phone number must be at least 10 characters long", + "phone_number_must_be_10_digits": "Phone number must be a 10-digit mobile number", "phone_number_verified": "Phone Number Verified", "pincode": "Pincode", "pincode_autofill": "State and District auto-filled from Pincode", + "pincode_must_be_6_digits": "Pincode must be a 6-digit number", "play": "Play", "play_audio": "Play Audio", "please_assign_bed_to_patient": "Please assign a bed to this patient", @@ -1930,6 +1941,8 @@ "working_status": "Working Status", "year": "Year", "year_of_birth": "Year of Birth", + "year_of_birth_format": "Year of birth must be in YYYY format", + "year_of_birth_must_be_present": "Year of birth must be present", "years": "years", "years_of_experience": "Years of Experience", "years_of_experience_of_the_doctor": "Years of Experience of the Doctor", diff --git a/src/components/Patient/PatientRegistration.tsx b/src/components/Patient/PatientRegistration.tsx index a8097a77907..adff967503f 100644 --- a/src/components/Patient/PatientRegistration.tsx +++ b/src/components/Patient/PatientRegistration.tsx @@ -69,66 +69,6 @@ export const BLOOD_GROUPS = BLOOD_GROUP_CHOICES.map((bg) => bg.id) as [ (typeof BLOOD_GROUP_CHOICES)[number]["id"], ]; -const formSchema = z - .object({ - name: z.string().nonempty("Name is required"), - phone_number: z - .string() - .regex(/^\+\d{12}$/, "Phone number must be a 10-digit mobile number"), - same_phone_number: z.boolean(), - emergency_phone_number: z - .string() - .regex( - /^\+\d{12}$/, - "Emergency phone number must be a 10-digit mobile number", - ), - gender: z.enum(GENDERS, { required_error: "Gender is required" }), - blood_group: z.enum(BLOOD_GROUPS, { - required_error: "Blood group is required", - }), - yob_or_dob: z.enum(["dob", "age"]), - date_of_birth: z - .string() - .regex( - /^\d{4}-\d{2}-\d{2}$/, - "Date of birth must be in YYYY-MM-DD format", - ) - .optional(), - year_of_birth: z - .string() - .regex(/^\d{4}$/, "Year of birth must be in YYYY format") - .optional(), - address: z.string().nonempty("Address is required"), - same_address: z.boolean(), - permanent_address: z.string().nonempty("Emergency address is required"), - pincode: z - .number() - .int() - .positive() - .min(100000, "Pincode must be a 6-digit number") - .max(999999, "Pincode must be a 6-digit number"), - nationality: z.string().nonempty("Nationality is required"), - geo_organization: z - .string() - .uuid("Geo organization must be a valid UUID") - .optional(), - }) - .refine((data) => (data.yob_or_dob === "dob" ? !!data.date_of_birth : true), { - message: "Date of birth must be present", - path: ["date_of_birth"], - }) - .refine((data) => (data.yob_or_dob === "age" ? !!data.year_of_birth : true), { - message: "Year of birth must be present", - path: ["year_of_birth"], - }) - .refine( - (data) => (data.nationality === "India" ? !!data.geo_organization : true), - { - message: "Geo organization is required when nationality is India", - path: ["geo_organization"], - }, - ); - export default function PatientRegistration( props: PatientRegistrationPageProps, ) { @@ -141,6 +81,70 @@ export default function PatientRegistration( useState(!!patientId); const [debouncedNumber, setDebouncedNumber] = useState(); + const formSchema = useMemo( + () => + z + .object({ + name: z.string().nonempty(t("name_is_required")), + phone_number: z + .string() + .regex(/^\+\d{12}$/, t("phone_number_must_be_10_digits")), + same_phone_number: z.boolean(), + emergency_phone_number: z + .string() + .regex(/^\+\d{12}$/, t("phone_number_must_be_10_digits")), + gender: z.enum(GENDERS, { required_error: t("gender_is_required") }), + blood_group: z.enum(BLOOD_GROUPS, { + required_error: t("blood_group_is_required"), + }), + yob_or_dob: z.enum(["dob", "age"]), + date_of_birth: z + .string() + .regex(/^\d{4}-\d{2}-\d{2}$/, t("date_of_birth_format")) + .optional(), + year_of_birth: z + .string() + .regex(/^\d{4}$/, t("year_of_birth_format")) + .optional(), + address: z.string().nonempty(t("address_is_required")), + same_address: z.boolean(), + permanent_address: z + .string() + .nonempty(t("permanent_address_is_required")), + pincode: z + .number() + .int() + .positive() + .min(100000, t("pincode_must_be_6_digits")) + .max(999999, t("pincode_must_be_6_digits")), + nationality: z.string().nonempty(t("nationality_is_required")), + geo_organization: z.string().uuid().optional(), + }) + .refine( + (data) => (data.yob_or_dob === "dob" ? !!data.date_of_birth : true), + { + message: t("date_of_birth_must_be_present"), + path: ["date_of_birth"], + }, + ) + .refine( + (data) => (data.yob_or_dob === "age" ? !!data.year_of_birth : true), + { + message: t("year_of_birth_must_be_present"), + path: ["year_of_birth"], + }, + ) + .refine( + (data) => + data.nationality === "India" ? !!data.geo_organization : true, + { + message: t("geo_organization_required"), + path: ["geo_organization"], + }, + ), + [], // eslint-disable-line react-hooks/exhaustive-deps + ); + const form = useForm>({ resolver: zodResolver(formSchema), defaultValues: { @@ -151,7 +155,8 @@ export default function PatientRegistration( }, }); - const createPatientMutation = useMutation({ + const { mutate: createPatient, isPending: isCreatingPatient } = useMutation({ + mutationKey: ["create_patient"], mutationFn: mutate(routes.addPatient), onSuccess: (resp: PatientModel) => { Notification.Success({ @@ -176,7 +181,7 @@ export default function PatientRegistration( }, }); - const updatePatientMutation = useMutation({ + const { mutate: updatePatient, isPending: isUpdatingPatient } = useMutation({ mutationFn: mutate(routes.updatePatient, { pathParams: { id: patientId || "" }, }), @@ -195,11 +200,11 @@ export default function PatientRegistration( function onSubmit(values: z.infer) { if (patientId) { - updatePatientMutation.mutate({ ...values, ward_old: undefined }); + updatePatient({ ...values, ward_old: undefined }); return; } - createPatientMutation.mutate({ + createPatient({ ...values, facility: facilityId, ward_old: undefined, @@ -313,10 +318,7 @@ export default function PatientRegistration( name="name" render={({ field }) => ( - - {t("name")} - * - + {t("name")} @@ -330,10 +332,7 @@ export default function PatientRegistration( name="phone_number" render={({ field }) => ( - - {t("phone_number")} - * - + {t("phone_number")} ( - + {t("emergency_phone_number")} - * @@ -403,10 +401,7 @@ export default function PatientRegistration( name="gender" render={({ field }) => ( - - {t("sex")} - * - + {t("sex")} {GENDER_TYPES.map((g) => ( - + @@ -436,10 +434,7 @@ export default function PatientRegistration( name="blood_group" render={({ field }) => ( - - {t("blood_group")} - * - + {t("blood_group")} @@ -482,10 +479,8 @@ export default function PatientRegistration(
-
- {t("day")} - * -
+ {t("day")} +
-
- {t("month")} - * -
+ {t("month")} +
-
- {t("year")} - * -
+ {t("year")} + ( - - {t("age")} - * - + {t("age")} ( - - {t("current_address")} - * - + {t("current_address")}