Make patient identification the unique identity instead of mobile.
mobile stays required but is no longer globally unique.
This commit is contained in:
@@ -11,7 +11,7 @@ Monorepo: `backend/` (NestJS + Prisma), `frontend/` (Next.js + next-intl), `infr
|
||||
|
||||
- **CLINIC** orgs: patients, appointments, treatment, staff.
|
||||
- **LAB** orgs: cases, tasks, lab workflows.
|
||||
- Named **patients** are scoped to `createdByOrganizationId`. `mobile` stays globally unique — other-org / walk-in hit `PATIENT_MOBILE_UNAVAILABLE` (no shared row).
|
||||
- Named **patients** are scoped to `createdByOrganizationId`. `identification` stays globally unique — other-org / walk-in hit `PATIENT_IDENTIFICATION_UNAVAILABLE` (no shared row). `mobile` is not unique.
|
||||
- Tab access: `TAB_*_READ` / `TAB_*_EDIT` in `backend/src/common/permissions.ts`. EDIT implies READ.
|
||||
|
||||
## Agent behavior
|
||||
|
||||
@@ -7,6 +7,7 @@ alwaysApply: false
|
||||
# Patients
|
||||
|
||||
- List / get / update / create: **this org** + `isWalkIn: false` (`createdByOrganizationId`).
|
||||
- `Patient.mobile` stays **globally unique**. Same-org named create returns `{ existing: true }`. Other org, walk-in, or null creator → `PATIENT_MOBILE_UNAVAILABLE` (409). Do **not** return or mention the other clinic’s row.
|
||||
- `Patient.identification` stays **globally unique**. Same-org named create returns `{ existing: true }`. Other org, walk-in, or null creator → `PATIENT_IDENTIFICATION_UNAVAILABLE` (409). Do **not** return or mention the other clinic’s row.
|
||||
- `Patient.mobile` is required for named patients but **not** unique.
|
||||
- Appointment create/update and `POST /treatments` named `patientId`: `ensurePatientInOrg` (named + this org). Walk-in sentinel is per clinic (`walk-in-patient.ts`), hidden from Patients/search/booking.
|
||||
- History / lab-case lists still query treatments for **this** `organizationId` even if the patient UUID is guessed.
|
||||
|
||||
@@ -202,7 +202,7 @@ Use shared `Checkbox` (not native `<input type="checkbox">`) to avoid focus-driv
|
||||
|
||||
|
||||
|
||||
Walk-in uses one sentinel `Patient` per clinic (`isWalkIn`, hidden from Patients/search/booking). Display via i18n, never the stored name. Named patients are this-org only (`createdByOrganizationId`); another clinic’s mobile is `PATIENT_MOBILE_UNAVAILABLE`, not a shared row. Patient search: same workspace patient with a live visit → no-op; else open today’s strip visit if any; else load latest history into the editor; **no history and no strip visit → do not auto-create**. Detach the previous visit, keep the searched patient, and show an inline editor empty state (`noTreatmentFoundTitle` / `noTreatmentFoundBody`) that points to **New treatment** in the rail (Walk-in, current named patient card, or search).
|
||||
Walk-in uses one sentinel `Patient` per clinic (`isWalkIn`, hidden from Patients/search/booking). Display via i18n, never the stored name. Named patients are this-org only (`createdByOrganizationId`); another clinic’s identification is `PATIENT_IDENTIFICATION_UNAVAILABLE`, not a shared row. Patient search: same workspace patient with a live visit → no-op; else open today’s strip visit if any; else load latest history into the editor; **no history and no strip visit → do not auto-create**. Detach the previous visit, keep the searched patient, and show an inline editor empty state (`noTreatmentFoundTitle` / `noTreatmentFoundBody`) that points to **New treatment** in the rail (Walk-in, current named patient card, or search).
|
||||
|
||||
Draft writes for appointments require provider match (`ensureAppointmentProvider`). Standalone requires `treatment.providerUserId === actor`.
|
||||
|
||||
|
||||
@@ -64,7 +64,7 @@ frontend/src/
|
||||
|
||||
**Appointments (quick ref):** Do not delete (or change patient) when `hasTreatment`; codes `APPOINTMENT_HAS_TREATMENT` / `APPOINTMENT_PATIENT_LOCKED`. Past days: no new bookings; edit/delete OK without treatment; with treatment → toast. Appointment delete does not cascade-delete treatments. Working hours: client IANA `timeZone` on create/update — never `Date#getHours()`/`getDay()` on the UTC server. Logical API errors: `AppException` + `errors.*` (never Nest English throws). Patient must belong to this org (`ensurePatientInOrg`). See `.cursor/rules/appointments.mdc`, `.cursor/skills/api-errors/SKILL.md`.
|
||||
|
||||
**Patients (quick ref):** List/get/update/create are this-org named patients (`createdByOrganizationId`, `isWalkIn: false`). Mobile stays globally unique. Same-org mobile create returns `existing: true`; other org / walk-in / null creator → `PATIENT_MOBILE_UNAVAILABLE` (409, no leak). See `.cursor/rules/patients.mdc`.
|
||||
**Patients (quick ref):** List/get/update/create are this-org named patients (`createdByOrganizationId`, `isWalkIn: false`). `identification` stays globally unique; `mobile` is not. Same-org identification create returns `existing: true`; other org / walk-in / null creator → `PATIENT_IDENTIFICATION_UNAVAILABLE` (409, no leak). See `.cursor/rules/patients.mdc`.
|
||||
|
||||
**Staff (quick ref):** Owner / `TAB_STAFF_EDIT` can **remove** a password (`POST /staff/members/:id/clear-password`) and copy a setup link — never set one for someone else. Login page unchanged (`passwordHash: null` cannot sign in). `/accept-invite` `password_setup` is password-only. See `.cursor/rules/staff.mdc`.
|
||||
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
-- Move global unique identity from mobile → identification.
|
||||
|
||||
ALTER TABLE "patients" ADD COLUMN "identification" TEXT;
|
||||
|
||||
-- Walk-ins: reuse walk-in mobile sentinel (already unique per org).
|
||||
UPDATE "patients"
|
||||
SET "identification" = "mobile"
|
||||
WHERE "isWalkIn" = true;
|
||||
|
||||
-- Named / other rows: stable unique backfill from id.
|
||||
UPDATE "patients"
|
||||
SET "identification" = '__legacy__:' || "id"
|
||||
WHERE "identification" IS NULL;
|
||||
|
||||
ALTER TABLE "patients" ALTER COLUMN "identification" SET NOT NULL;
|
||||
|
||||
CREATE UNIQUE INDEX "patients_identification_key" ON "patients"("identification");
|
||||
|
||||
DROP INDEX IF EXISTS "patients_mobile_key";
|
||||
@@ -103,7 +103,8 @@ model Patient {
|
||||
id String @id @default(uuid())
|
||||
firstName String
|
||||
lastName String
|
||||
mobile String @unique
|
||||
identification String @unique
|
||||
mobile String
|
||||
email String?
|
||||
dateOfBirth DateTime?
|
||||
notes String?
|
||||
|
||||
@@ -84,7 +84,7 @@ export const ErrorCode = {
|
||||
APPOINTMENT_NOT_PROVIDER: 'APPOINTMENT_NOT_PROVIDER',
|
||||
|
||||
PATIENT_NOT_FOUND: 'PATIENT_NOT_FOUND',
|
||||
PATIENT_MOBILE_UNAVAILABLE: 'PATIENT_MOBILE_UNAVAILABLE',
|
||||
PATIENT_IDENTIFICATION_UNAVAILABLE: 'PATIENT_IDENTIFICATION_UNAVAILABLE',
|
||||
|
||||
WORKING_HOURS_INVALID: 'WORKING_HOURS_INVALID',
|
||||
WORKING_HOURS_OWNER_NOT_ALLOWED: 'WORKING_HOURS_OWNER_NOT_ALLOWED',
|
||||
|
||||
@@ -26,11 +26,13 @@ export async function ensureWalkInPatient(
|
||||
return { id: existing.id, isWalkIn: true };
|
||||
}
|
||||
|
||||
const walkInKey = walkInMobileForOrganization(organizationId);
|
||||
const created = await prisma.patient.create({
|
||||
data: {
|
||||
firstName: 'Walk-in',
|
||||
lastName: 'Walk-in',
|
||||
mobile: walkInMobileForOrganization(organizationId),
|
||||
identification: walkInKey,
|
||||
mobile: walkInKey,
|
||||
isWalkIn: true,
|
||||
createdByOrganizationId: organizationId,
|
||||
},
|
||||
|
||||
@@ -102,7 +102,7 @@ export class AppointmentsService {
|
||||
},
|
||||
include: {
|
||||
patient: {
|
||||
select: { id: true, firstName: true, lastName: true, mobile: true },
|
||||
select: { id: true, firstName: true, lastName: true, identification: true, mobile: true },
|
||||
},
|
||||
treatment: { select: { id: true } },
|
||||
},
|
||||
@@ -168,7 +168,7 @@ export class AppointmentsService {
|
||||
},
|
||||
include: {
|
||||
patient: {
|
||||
select: { id: true, firstName: true, lastName: true, mobile: true },
|
||||
select: { id: true, firstName: true, lastName: true, identification: true, mobile: true },
|
||||
},
|
||||
},
|
||||
});
|
||||
@@ -245,7 +245,7 @@ export class AppointmentsService {
|
||||
},
|
||||
include: {
|
||||
patient: {
|
||||
select: { id: true, firstName: true, lastName: true, mobile: true },
|
||||
select: { id: true, firstName: true, lastName: true, identification: true, mobile: true },
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
@@ -13,17 +13,22 @@ export class CreatePatientDto {
|
||||
@IsString()
|
||||
@MinLength(1, { message: ErrorCode.VALIDATION_FIELD_REQUIRED })
|
||||
@MaxLength(80)
|
||||
firstName: string;
|
||||
firstName!: string;
|
||||
|
||||
@IsString()
|
||||
@MinLength(1, { message: ErrorCode.VALIDATION_FIELD_REQUIRED })
|
||||
@MaxLength(80)
|
||||
lastName: string;
|
||||
lastName!: string;
|
||||
|
||||
@IsString()
|
||||
@MinLength(1, { message: ErrorCode.VALIDATION_FIELD_REQUIRED })
|
||||
@MaxLength(80)
|
||||
identification!: string;
|
||||
|
||||
@IsString()
|
||||
@MinLength(1, { message: ErrorCode.VALIDATION_FIELD_REQUIRED })
|
||||
@MaxLength(30)
|
||||
mobile: string;
|
||||
mobile!: string;
|
||||
|
||||
@IsOptional()
|
||||
@Transform(emptyStringToUndefined)
|
||||
|
||||
@@ -25,7 +25,7 @@ export class PatientsController {
|
||||
constructor(private readonly patientsService: PatientsService) {}
|
||||
|
||||
@Post()
|
||||
@ApiOperation({ summary: 'Create or return this clinic’s patient by mobile' })
|
||||
@ApiOperation({ summary: 'Create or return this clinic’s patient by identification' })
|
||||
create(@Body() createPatientDto: CreatePatientDto, @Req() req) {
|
||||
const organizationId = this.patientsService.getOrganizationIdFromUser(req.user);
|
||||
return this.patientsService.create(createPatientDto, organizationId);
|
||||
|
||||
@@ -14,10 +14,11 @@ export class PatientsService {
|
||||
async create(createPatientDto: CreatePatientDto, organizationId: string) {
|
||||
const firstName = this.requireNonEmptyName(createPatientDto.firstName, 'firstName');
|
||||
const lastName = this.requireNonEmptyName(createPatientDto.lastName, 'lastName');
|
||||
const identification = this.requireNonEmptyIdentification(createPatientDto.identification);
|
||||
const mobile = this.resolveMobile(createPatientDto.mobile);
|
||||
|
||||
const existing = await this.prisma.patient.findUnique({
|
||||
where: { mobile },
|
||||
where: { identification },
|
||||
});
|
||||
|
||||
if (existing) {
|
||||
@@ -27,13 +28,14 @@ export class PatientsService {
|
||||
) {
|
||||
return { success: true, data: existing, existing: true as const };
|
||||
}
|
||||
throw new AppException(ErrorCode.PATIENT_MOBILE_UNAVAILABLE, HttpStatus.CONFLICT);
|
||||
throw new AppException(ErrorCode.PATIENT_IDENTIFICATION_UNAVAILABLE, HttpStatus.CONFLICT);
|
||||
}
|
||||
|
||||
const patient = await this.prisma.patient.create({
|
||||
data: {
|
||||
firstName,
|
||||
lastName,
|
||||
identification,
|
||||
mobile,
|
||||
email: createPatientDto.email?.trim() || null,
|
||||
notes: createPatientDto.notes?.trim() || null,
|
||||
@@ -90,6 +92,7 @@ export class PatientsService {
|
||||
const data: {
|
||||
firstName?: string;
|
||||
lastName?: string;
|
||||
identification?: string;
|
||||
mobile?: string;
|
||||
email?: string | null;
|
||||
notes?: string | null;
|
||||
@@ -102,16 +105,19 @@ export class PatientsService {
|
||||
if (updatePatientDto.lastName !== undefined) {
|
||||
data.lastName = this.requireNonEmptyName(updatePatientDto.lastName, 'lastName');
|
||||
}
|
||||
if (updatePatientDto.mobile !== undefined) {
|
||||
const mobile = this.resolveMobile(updatePatientDto.mobile);
|
||||
if (updatePatientDto.identification !== undefined) {
|
||||
const identification = this.requireNonEmptyIdentification(updatePatientDto.identification);
|
||||
const taken = await this.prisma.patient.findUnique({
|
||||
where: { mobile },
|
||||
select: { id: true, createdByOrganizationId: true, isWalkIn: true },
|
||||
where: { identification },
|
||||
select: { id: true },
|
||||
});
|
||||
if (taken && taken.id !== id) {
|
||||
throw new AppException(ErrorCode.PATIENT_MOBILE_UNAVAILABLE, HttpStatus.CONFLICT);
|
||||
throw new AppException(ErrorCode.PATIENT_IDENTIFICATION_UNAVAILABLE, HttpStatus.CONFLICT);
|
||||
}
|
||||
data.mobile = mobile;
|
||||
data.identification = identification;
|
||||
}
|
||||
if (updatePatientDto.mobile !== undefined) {
|
||||
data.mobile = this.resolveMobile(updatePatientDto.mobile);
|
||||
}
|
||||
if (updatePatientDto.email !== undefined) {
|
||||
data.email = updatePatientDto.email?.trim() || null;
|
||||
@@ -222,6 +228,16 @@ export class PatientsService {
|
||||
return trimmed;
|
||||
}
|
||||
|
||||
private requireNonEmptyIdentification(value: string): string {
|
||||
const trimmed = value?.trim() ?? '';
|
||||
if (!trimmed) {
|
||||
throw new AppException(ErrorCode.VALIDATION_FIELD_REQUIRED, HttpStatus.BAD_REQUEST, [
|
||||
{ field: 'identification', code: ErrorCode.VALIDATION_FIELD_REQUIRED },
|
||||
]);
|
||||
}
|
||||
return trimmed;
|
||||
}
|
||||
|
||||
private async assertCanViewPatients(userId: string, organizationId: string) {
|
||||
const membership = await this.prisma.membership.findUnique({
|
||||
where: {
|
||||
|
||||
@@ -401,10 +401,13 @@
|
||||
"errorSavePatient": "Failed to save patient.",
|
||||
"firstName": "First name",
|
||||
"lastName": "Last name",
|
||||
"identification": "Identification",
|
||||
"identificationLabel": "Identification:",
|
||||
"identificationRequired": "Identification is required.",
|
||||
"mobile": "Mobile",
|
||||
"mobilePlaceholder": "09121234567",
|
||||
"mobileLabel": "Mobile:",
|
||||
"patientAlreadyExists": "A patient with this mobile already exists: {firstName} {lastName}. They were selected for you.",
|
||||
"patientAlreadyExists": "A patient with this identification already exists: {firstName} {lastName}. They were selected for you.",
|
||||
"savePatient": "Save Patient",
|
||||
"dialogTitle": "New patient",
|
||||
"searchPlaceholder": "Search patients by name, mobile, email",
|
||||
@@ -1234,7 +1237,7 @@
|
||||
"APPOINTMENT_NOT_FOUND": "Appointment not found.",
|
||||
"APPOINTMENT_NOT_PROVIDER": "You are not the provider for this appointment.",
|
||||
"PATIENT_NOT_FOUND": "Patient not found.",
|
||||
"PATIENT_MOBILE_UNAVAILABLE": "This mobile number cannot be added for this clinic.",
|
||||
"PATIENT_IDENTIFICATION_UNAVAILABLE": "This identification cannot be added for this clinic.",
|
||||
"WORKING_HOURS_INVALID": "Working hours are invalid. Check that shifts do not overlap.",
|
||||
"WORKING_HOURS_OWNER_NOT_ALLOWED": "Set owner working hours from account settings.",
|
||||
"WORKING_HOURS_CONFLICTS_WITH_APPOINTMENTS": "These hours conflict with upcoming appointments. Reschedule or remove those appointments first.",
|
||||
|
||||
@@ -401,10 +401,13 @@
|
||||
"errorSavePatient": "ذخیره بیمار ناموفق بود.",
|
||||
"firstName": "نام",
|
||||
"lastName": "نام خانوادگی",
|
||||
"identification": "شناسه",
|
||||
"identificationLabel": "شناسه:",
|
||||
"identificationRequired": "شناسه الزامی است.",
|
||||
"mobile": "موبایل",
|
||||
"mobilePlaceholder": "09121234567",
|
||||
"mobileLabel": "موبایل:",
|
||||
"patientAlreadyExists": "بیماری با این شماره موبایل از قبل وجود دارد: {firstName} {lastName}. برای شما انتخاب شد.",
|
||||
"patientAlreadyExists": "بیماری با این شناسه از قبل وجود دارد: {firstName} {lastName}. برای شما انتخاب شد.",
|
||||
"savePatient": "ذخیره بیمار",
|
||||
"dialogTitle": "بیمار جدید",
|
||||
"searchPlaceholder": "جستجوی بیماران بر اساس نام، موبایل، ایمیل",
|
||||
@@ -1235,7 +1238,7 @@
|
||||
"APPOINTMENT_NOT_FOUND": "نوبت یافت نشد.",
|
||||
"APPOINTMENT_NOT_PROVIDER": "شما ارائهدهنده این نوبت نیستید.",
|
||||
"PATIENT_NOT_FOUND": "بیمار یافت نشد.",
|
||||
"PATIENT_MOBILE_UNAVAILABLE": "این شماره موبایل را نمیتوان برای این کلینیک ثبت کرد.",
|
||||
"PATIENT_IDENTIFICATION_UNAVAILABLE": "این شناسه را نمیتوان برای این کلینیک ثبت کرد.",
|
||||
"WORKING_HOURS_INVALID": "ساعات کاری نامعتبر است. همپوشانی شیفتها را بررسی کنید.",
|
||||
"WORKING_HOURS_OWNER_NOT_ALLOWED": "ساعات کاری مالک را از تنظیمات حساب تنظیم کنید.",
|
||||
"WORKING_HOURS_CONFLICTS_WITH_APPOINTMENTS": "این ساعات با نوبتهای آینده تداخل دارد. ابتدا آن نوبتها را تغییر دهید یا حذف کنید.",
|
||||
|
||||
@@ -401,10 +401,13 @@
|
||||
"errorSavePatient": "Patiënt opslaan mislukt.",
|
||||
"firstName": "Voornaam",
|
||||
"lastName": "Achternaam",
|
||||
"identification": "Identificatie",
|
||||
"identificationLabel": "Identificatie:",
|
||||
"identificationRequired": "Identificatie is verplicht.",
|
||||
"mobile": "Mobiel",
|
||||
"mobilePlaceholder": "0612345678",
|
||||
"mobileLabel": "Mobiel:",
|
||||
"patientAlreadyExists": "Er bestaat al een patiënt met dit mobiele nummer: {firstName} {lastName}. Deze is voor u geselecteerd.",
|
||||
"patientAlreadyExists": "Er bestaat al een patiënt met deze identificatie: {firstName} {lastName}. Deze is voor u geselecteerd.",
|
||||
"savePatient": "Patiënt opslaan",
|
||||
"dialogTitle": "Nieuwe patiënt",
|
||||
"searchPlaceholder": "Zoek patiënten op naam, mobiel, e-mail",
|
||||
@@ -1234,7 +1237,7 @@
|
||||
"APPOINTMENT_NOT_FOUND": "Afspraak niet gevonden.",
|
||||
"APPOINTMENT_NOT_PROVIDER": "U bent niet de zorgverlener van deze afspraak.",
|
||||
"PATIENT_NOT_FOUND": "Patiënt niet gevonden.",
|
||||
"PATIENT_MOBILE_UNAVAILABLE": "Dit mobiele nummer kan niet voor deze kliniek worden toegevoegd.",
|
||||
"PATIENT_IDENTIFICATION_UNAVAILABLE": "Deze identificatie kan niet voor deze kliniek worden toegevoegd.",
|
||||
"WORKING_HOURS_INVALID": "De werktijden zijn ongeldig. Controleer of diensten niet overlappen.",
|
||||
"WORKING_HOURS_OWNER_NOT_ALLOWED": "Stel werktijden van de eigenaar in via accountinstellingen.",
|
||||
"WORKING_HOURS_CONFLICTS_WITH_APPOINTMENTS": "Deze tijden conflicteren met aankomende afspraken. Plan die eerst om of verwijder ze.",
|
||||
|
||||
@@ -54,11 +54,12 @@ interface AppointmentBookingModalProps {
|
||||
|
||||
function patientFromRecord(
|
||||
patient: AppointmentRecord['patient'],
|
||||
): Pick<Patient, 'id' | 'firstName' | 'lastName' | 'mobile'> {
|
||||
): Pick<Patient, 'id' | 'firstName' | 'lastName' | 'identification' | 'mobile'> {
|
||||
return {
|
||||
id: patient.id,
|
||||
firstName: patient.firstName,
|
||||
lastName: patient.lastName,
|
||||
identification: patient.identification,
|
||||
mobile: patient.mobile,
|
||||
};
|
||||
}
|
||||
@@ -93,7 +94,7 @@ export function AppointmentBookingModal({
|
||||
const [endTime, setEndTime] = useState('09:30');
|
||||
const [purpose, setPurpose] = useState<AppointmentPurpose>(defaultPurpose);
|
||||
const [selectedPatient, setSelectedPatient] = useState<
|
||||
Pick<Patient, 'id' | 'firstName' | 'lastName' | 'mobile'> | null
|
||||
Pick<Patient, 'id' | 'firstName' | 'lastName' | 'identification' | 'mobile'> | null
|
||||
>(null);
|
||||
const [error, setError] = useState('');
|
||||
|
||||
@@ -147,6 +148,7 @@ export function AppointmentBookingModal({
|
||||
id: initialPatient.id,
|
||||
firstName: initialPatient.firstName,
|
||||
lastName: initialPatient.lastName,
|
||||
identification: initialPatient.identification,
|
||||
mobile: initialPatient.mobile,
|
||||
}
|
||||
: null,
|
||||
@@ -175,6 +177,7 @@ export function AppointmentBookingModal({
|
||||
id: patient.id,
|
||||
firstName: patient.firstName,
|
||||
lastName: patient.lastName,
|
||||
identification: patient.identification,
|
||||
mobile: patient.mobile,
|
||||
};
|
||||
setSelectedPatient(next);
|
||||
|
||||
@@ -23,7 +23,9 @@ interface CreatePatientModalProps {
|
||||
variant?: 'inline' | 'dialog';
|
||||
}
|
||||
|
||||
type FieldErrors = Partial<Record<'firstName' | 'lastName' | 'mobile' | 'email', string>>;
|
||||
type FieldErrors = Partial<
|
||||
Record<'firstName' | 'lastName' | 'identification' | 'mobile' | 'email', string>
|
||||
>;
|
||||
|
||||
function CreatePatientFormFields({
|
||||
formData,
|
||||
@@ -56,6 +58,9 @@ function CreatePatientFormFields({
|
||||
if (!formData.lastName?.trim()) {
|
||||
nextErrors.lastName = t('lastNameRequired');
|
||||
}
|
||||
if (!formData.identification?.trim()) {
|
||||
nextErrors.identification = t('identificationRequired');
|
||||
}
|
||||
if (!formData.mobile?.trim()) {
|
||||
nextErrors.mobile = tValidation('mobileRequired');
|
||||
} else if (!isValidMobile(normalizeMobile(formData.mobile) ?? '')) {
|
||||
@@ -81,8 +86,9 @@ function CreatePatientFormFields({
|
||||
() =>
|
||||
!formData.firstName?.trim() ||
|
||||
!formData.lastName?.trim() ||
|
||||
!formData.identification?.trim() ||
|
||||
!isValidMobile(normalizeMobile(formData.mobile || '') ?? ''),
|
||||
[formData.firstName, formData.lastName, formData.mobile],
|
||||
[formData.firstName, formData.lastName, formData.identification, formData.mobile],
|
||||
);
|
||||
|
||||
const mobileDisplayError = useMemo(() => {
|
||||
@@ -91,7 +97,11 @@ function CreatePatientFormFields({
|
||||
}
|
||||
const raw = formData.mobile?.trim() ?? '';
|
||||
if (!raw) {
|
||||
if (formData.firstName?.trim() && formData.lastName?.trim()) {
|
||||
if (
|
||||
formData.firstName?.trim() &&
|
||||
formData.lastName?.trim() &&
|
||||
formData.identification?.trim()
|
||||
) {
|
||||
return tValidation('mobileRequired');
|
||||
}
|
||||
return undefined;
|
||||
@@ -105,6 +115,7 @@ function CreatePatientFormFields({
|
||||
formData.mobile,
|
||||
formData.firstName,
|
||||
formData.lastName,
|
||||
formData.identification,
|
||||
tValidation,
|
||||
]);
|
||||
|
||||
@@ -137,6 +148,18 @@ function CreatePatientFormFields({
|
||||
required
|
||||
error={fieldErrors.lastName}
|
||||
/>
|
||||
<Input
|
||||
label={`${t('identification')} ${requiredMark}`}
|
||||
value={formData.identification || ''}
|
||||
onChange={(e) => {
|
||||
onChange({ identification: e.target.value });
|
||||
if (fieldErrors.identification) {
|
||||
setFieldErrors((prev) => ({ ...prev, identification: undefined }));
|
||||
}
|
||||
}}
|
||||
required
|
||||
error={fieldErrors.identification}
|
||||
/>
|
||||
<Input
|
||||
label={`${t('mobile')} ${requiredMark}`}
|
||||
value={formData.mobile || ''}
|
||||
|
||||
@@ -24,6 +24,9 @@ export function PatientSummaryCard({ patient }: PatientSummaryCardProps) {
|
||||
<h2 className="text-lg font-semibold text-text-primary">
|
||||
{patient.firstName} {patient.lastName}
|
||||
</h2>
|
||||
<p className="text-sm text-text-secondary">
|
||||
{t('identificationLabel')} {patient.identification}
|
||||
</p>
|
||||
<p className="text-sm text-text-secondary">
|
||||
{t('mobileLabel')} {formatMobileForDisplay(patient.mobile)}
|
||||
</p>
|
||||
|
||||
@@ -19,6 +19,7 @@ import { PatientAppointmentHistory } from '@/components/ui/patient/PatientAppoin
|
||||
const EMPTY_PATIENT_FORM: CreatePatientInput = {
|
||||
firstName: '',
|
||||
lastName: '',
|
||||
identification: '',
|
||||
mobile: '',
|
||||
email: '',
|
||||
};
|
||||
|
||||
@@ -22,7 +22,7 @@ export interface AppointmentRecord {
|
||||
startAt: string;
|
||||
endAt: string;
|
||||
purpose: string;
|
||||
patient: Pick<Patient, 'id' | 'firstName' | 'lastName' | 'mobile'>;
|
||||
patient: Pick<Patient, 'id' | 'firstName' | 'lastName' | 'identification' | 'mobile'>;
|
||||
/** True when a treatment record is linked to this appointment. */
|
||||
hasTreatment?: boolean;
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ export interface Patient {
|
||||
id: string;
|
||||
firstName: string;
|
||||
lastName: string;
|
||||
identification: string;
|
||||
mobile: string;
|
||||
email?: string | null;
|
||||
dateOfBirth?: string | null;
|
||||
@@ -15,6 +16,7 @@ export interface Patient {
|
||||
export interface CreatePatientInput {
|
||||
firstName: string;
|
||||
lastName: string;
|
||||
identification: string;
|
||||
mobile: string;
|
||||
email?: string;
|
||||
dateOfBirth?: string;
|
||||
|
||||
Reference in New Issue
Block a user