feat(patient): complete "اطلاعات پرونده" demographic form

Backend:
- Add profile columns field_of_study, province_id, city_id, postal_code,
  referral_source (UserProfile + migration).
- Extend PATCH /api/v1/patient/{uuid} to persist all demographic fields
  and return them in the patient profile payload.
- Support editable mobile (login identifier): validation, uniqueness,
  User.setMobileNumber, new ERR_PROFILE_002.
- Update docs/api/patient.md.

Frontend:
- New reusable Input, Field, and PatientRecordInfoForm (RHF + Zod).
- usePatient/useUpdatePatient hooks and patientForm mapping helpers.
- Extend the existing "info" tab in MyPatientsPage to the full field set
  via the shared form (province/city/insurance options, Jalali date).

Tests: Patient entity + PATCH integration (PHPUnit); form, hooks, and
mapping helpers (Vitest).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
hamed
2026-07-13 11:51:18 +03:30
co-authored by Claude Opus 4.8
parent 9d8de9bc33
commit 580bc983b3
19 changed files with 1042 additions and 128 deletions
+26
View File
@@ -0,0 +1,26 @@
import React from 'react';
interface Props {
label: string;
htmlFor?: string;
error?: string;
className?: string;
style?: React.CSSProperties;
children: React.ReactNode;
}
/**
* چیدمان یک فیلد فرم: برچسب بالا، کنترل (children)، و پیام خطای زیر آن.
* presentational — منطق فرم/ولیدیشن بیرون از این کامپوننت است.
*/
export default function Field({ label, htmlFor, error, className, style, children }: Props) {
return (
<div className={className} style={{ display: 'flex', flexDirection: 'column', gap: 6, ...style }}>
<label htmlFor={htmlFor} className="cp-label">{label}</label>
{children}
{error && (
<span style={{ color: 'var(--danger)', fontSize: 12 }}>{error}</span>
)}
</div>
);
}
+23
View File
@@ -0,0 +1,23 @@
import React from 'react';
type Props = React.InputHTMLAttributes<HTMLInputElement> & {
hasError?: boolean;
};
/**
* Input متنی پایهٔ design system: کلاس `cp-input`، حالت خطا (قاب قرمز)،
* و forwardRef برای سازگاری با react-hook-form `register`.
*/
export default React.forwardRef<HTMLInputElement, Props>(function Input(
{ hasError, className, style, ...rest },
ref,
) {
return (
<input
{...rest}
ref={ref}
className={className ?? 'cp-input'}
style={hasError ? { borderColor: 'var(--danger)', ...(style || {}) } : style}
/>
);
});
@@ -0,0 +1,40 @@
import { describe, it, expect } from 'vitest';
import { render, screen } from '@testing-library/react';
import Input from '@/components/ui/Input';
import Field from '@/components/ui/Field';
describe('Input', () => {
it('مقدار و placeholder را رندر می‌کند', () => {
render(<Input defaultValue="ساغر" placeholder="نام" />);
const el = screen.getByPlaceholderText('نام') as HTMLInputElement;
expect(el.value).toBe('ساغر');
expect(el.className).toBe('cp-input');
});
it('در حالت hasError قاب قرمز می‌گیرد', () => {
render(<Input placeholder="کدملی" hasError />);
const el = screen.getByPlaceholderText('کدملی') as HTMLInputElement;
expect(el.style.borderColor).toBe('var(--danger)');
});
});
describe('Field', () => {
it('برچسب و فرزند را نشان می‌دهد و بدون خطا پیام خطا ندارد', () => {
render(
<Field label="نام پدر">
<Input placeholder="نام پدر را وارد کنید" />
</Field>,
);
expect(screen.getByText('نام پدر')).toBeInTheDocument();
expect(screen.getByPlaceholderText('نام پدر را وارد کنید')).toBeInTheDocument();
});
it('پیام خطا را وقتی error داده شود نمایش می‌دهد', () => {
render(
<Field label="کدملی" error="کد ملی باید ۱۰ رقم باشد">
<Input />
</Field>,
);
expect(screen.getByText('کد ملی باید ۱۰ رقم باشد')).toBeInTheDocument();
});
});