feat(appointment): enforce mandatory patient national code and gender with validation
This commit is contained in:
@@ -12,6 +12,7 @@ use App\Doctor\Entity\Doctor;
|
||||
use App\Auth\Entity\User;
|
||||
use App\Doctor\Repository\DoctorRepository;
|
||||
use App\Patient\Service\PatientService;
|
||||
use App\Shared\Service\InputValidator;
|
||||
use App\Shared\Constant\ErrorCodes;
|
||||
use App\Shared\Controller\BaseController;
|
||||
use Doctrine\ORM\OptimisticLockException;
|
||||
@@ -234,7 +235,28 @@ class AppointmentController extends BaseController
|
||||
|
||||
$forSelf = (bool) ($data['for_self'] ?? true);
|
||||
|
||||
// کد ملی و جنسیت بیمار همیشه الزامی است (چه برای خود، چه برای دیگری).
|
||||
$nationalCode = InputValidator::toEnglishDigits(trim((string) ($data['patient_national_code'] ?? '')));
|
||||
// فرانتاند male/female میفرستد؛ به فرمِ متعارفِ بکاند (man/woman) نگاشت میشود.
|
||||
$gender = match (strtolower(trim((string) ($data['patient_gender'] ?? '')))) {
|
||||
'man', 'male' => 'man',
|
||||
'woman', 'female' => 'woman',
|
||||
default => '',
|
||||
};
|
||||
|
||||
if ($nationalCode === '') {
|
||||
return $this->error(ErrorCodes::ERR_VALIDATION_001, 'کد ملی بیمار الزامی است', 422, 'patient_national_code');
|
||||
}
|
||||
if (!InputValidator::isValidIranNationalCode($nationalCode)) {
|
||||
return $this->error(ErrorCodes::ERR_VALIDATION_001, 'کد ملی نامعتبر است', 422, 'patient_national_code');
|
||||
}
|
||||
if ($gender === '') {
|
||||
return $this->error(ErrorCodes::ERR_VALIDATION_001, 'جنسیت بیمار الزامی است', 422, 'patient_gender');
|
||||
}
|
||||
|
||||
$appointment = new Appointment($doctor, $user, $slotStart, $slotEnd);
|
||||
$appointment->setPatientNationalCode($nationalCode);
|
||||
$appointment->setPatientGender($gender);
|
||||
if (isset($data['note'])) $appointment->setNote($data['note']);
|
||||
|
||||
// آدرس نوبت از روی session متناظر در برنامهی هفتگی تعیین میشود (location_id).
|
||||
@@ -254,8 +276,6 @@ class AppointmentController extends BaseController
|
||||
}
|
||||
$appointment->setPatientName($patientName);
|
||||
$appointment->setPatientMobile($patientMobile);
|
||||
$appointment->setPatientNationalCode($data['patient_national_code'] ?? null);
|
||||
$appointment->setPatientGender($data['patient_gender'] ?? null);
|
||||
$appointment->setPatientReason($data['patient_reason'] ?? null);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user