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:
@@ -0,0 +1,53 @@
|
||||
import { describe, it, expect, beforeEach, vi } from 'vitest';
|
||||
import { waitFor } from '@testing-library/react';
|
||||
import { renderHookWithClient } from '@/test/utils';
|
||||
|
||||
vi.mock('@/lib/api', () => ({
|
||||
api: { get: vi.fn(), post: vi.fn(), patch: vi.fn(), put: vi.fn(), delete: vi.fn() },
|
||||
ApiError: class extends Error {},
|
||||
}));
|
||||
|
||||
import { api } from '@/lib/api';
|
||||
import { usePatient, useUpdatePatient } from '@/hooks/usePatient';
|
||||
|
||||
const get = api.get as ReturnType<typeof vi.fn>;
|
||||
const patch = api.patch as ReturnType<typeof vi.fn>;
|
||||
|
||||
beforeEach(() => {
|
||||
get.mockReset();
|
||||
patch.mockReset();
|
||||
});
|
||||
|
||||
describe('usePatient', () => {
|
||||
it('پروفایل را از data.data.profile استخراج میکند', async () => {
|
||||
get.mockResolvedValue({
|
||||
data: { uuid: 'u-1', profile: { name: 'ساغر', national_code: '0012345678', city_id: 42 } },
|
||||
});
|
||||
|
||||
const { result } = renderHookWithClient(() => usePatient('u-1'));
|
||||
await waitFor(() => expect(result.current.profile).not.toBeNull());
|
||||
|
||||
expect(get).toHaveBeenCalledWith('/api/v1/patient/u-1');
|
||||
expect(result.current.profile?.name).toBe('ساغر');
|
||||
expect(result.current.profile?.city_id).toBe(42);
|
||||
expect(result.current.record?.uuid).toBe('u-1');
|
||||
});
|
||||
|
||||
it('بدون uuid کوئری اجرا نمیشود', () => {
|
||||
const { result } = renderHookWithClient(() => usePatient(undefined));
|
||||
expect(get).not.toHaveBeenCalled();
|
||||
expect(result.current.profile).toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
describe('useUpdatePatient', () => {
|
||||
it('PATCH را با بدنه به آدرس بیمار میفرستد', async () => {
|
||||
patch.mockResolvedValue({ data: { uuid: 'u-1', profile: {} } });
|
||||
|
||||
const { result } = renderHookWithClient(() => useUpdatePatient('u-1'));
|
||||
result.current.mutate({ fathers_name: 'رضا', city_id: 42 });
|
||||
|
||||
await waitFor(() => expect(patch).toHaveBeenCalled());
|
||||
expect(patch).toHaveBeenCalledWith('/api/v1/patient/u-1', { fathers_name: 'رضا', city_id: 42 });
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user