fix: patient language field silently dropped by stale browser-side validation schema
packages/db/usedSchemas/browser.ts (the browser-resolved copy of the Patient zod schema, kept separate from the Node copy since it can't import Prisma-generated code) was missing several fields added to the real schema over time — preferredLanguage, gender, insuranceProvider, insuranceId, groupNumber, policyHolder, and the PLAN_NOT_ACCEPTED status. Since the schema isn't strict, those fields were silently stripped from every patient create/update in the browser with no validation error, so edits to them never reached the server. Also fixes the AI call greeting always playing in English regardless of the patient's preferred language — the greeting text was a single hardcoded string, unlike every later turn in the conversation which already branched by language.
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import { useForm } from "react-hook-form";
|
||||
import { zodResolver } from "@hookform/resolvers/zod";
|
||||
import { useAuth } from "@/hooks/use-auth";
|
||||
import { useToast } from "@/hooks/use-toast";
|
||||
import {
|
||||
Form,
|
||||
FormControl,
|
||||
@@ -50,6 +51,7 @@ export type PatientFormRef = {
|
||||
export const PatientForm = forwardRef<PatientFormRef, PatientFormProps>(
|
||||
({ patient, extractedInfo, onSubmit }, ref) => {
|
||||
const { user } = useAuth();
|
||||
const { toast } = useToast();
|
||||
const isEditing = !!patient;
|
||||
|
||||
const schema = useMemo(
|
||||
@@ -83,7 +85,7 @@ export const PatientForm = forwardRef<PatientFormRef, PatientFormProps>(
|
||||
|
||||
const computedDefaultValues = useMemo(() => {
|
||||
if (isEditing && patient) {
|
||||
const { id, userId, createdAt, ...sanitizedPatient } = patient;
|
||||
const { id, userId, createdAt, updatedAt, ...sanitizedPatient } = patient;
|
||||
return {
|
||||
...sanitizedPatient,
|
||||
dateOfBirth: patient.dateOfBirth
|
||||
@@ -137,7 +139,7 @@ export const PatientForm = forwardRef<PatientFormRef, PatientFormProps>(
|
||||
|
||||
useEffect(() => {
|
||||
if (patient) {
|
||||
const { id, userId, createdAt, ...sanitizedPatient } = patient;
|
||||
const { id, userId, createdAt, updatedAt, ...sanitizedPatient } = patient;
|
||||
const normalized = normalizeInsuranceProvider(patient.insuranceProvider);
|
||||
const resetValues: Partial<Patient> = {
|
||||
...sanitizedPatient,
|
||||
@@ -164,9 +166,19 @@ export const PatientForm = forwardRef<PatientFormRef, PatientFormProps>(
|
||||
id="patient-form"
|
||||
key={patient?.id || "new"}
|
||||
noValidate
|
||||
onSubmit={form.handleSubmit((data) => {
|
||||
handleSubmit2(data);
|
||||
})}
|
||||
onSubmit={form.handleSubmit(
|
||||
(data) => {
|
||||
handleSubmit2(data);
|
||||
},
|
||||
(errors) => {
|
||||
console.log("❌ Form validation errors:", errors);
|
||||
toast({
|
||||
title: "Could not save patient",
|
||||
description: "Please check the highlighted fields and try again.",
|
||||
variant: "destructive",
|
||||
});
|
||||
},
|
||||
)}
|
||||
className="space-y-6"
|
||||
>
|
||||
{/* Personal Information */}
|
||||
|
||||
Reference in New Issue
Block a user