From 2b8173208648b6793ebacddb264bac6148042e15 Mon Sep 17 00:00:00 2001 From: mikael-zakaria Date: Mon, 24 Nov 2025 14:11:02 +0700 Subject: [PATCH] Update Rules Patient Identity --- app/Controllers/Patient/Patient.php | 53 +++++++++++++++++++++++++---- 1 file changed, 47 insertions(+), 6 deletions(-) diff --git a/app/Controllers/Patient/Patient.php b/app/Controllers/Patient/Patient.php index c0ec498..c8aa828 100644 --- a/app/Controllers/Patient/Patient.php +++ b/app/Controllers/Patient/Patient.php @@ -17,13 +17,34 @@ class Patient extends Controller { $this->db = \Config\Database::connect(); $this->model = new PatientModel(); $this->rules = [ - 'PatientID' => 'required|max_length[50]', - 'AlternatePID' => 'permit_empty|max_length[50]', - 'NameFirst' => 'required|min_length[1]|max_length[255]', - 'EmailAddress1' => 'required', + 'PatientID' => 'required|regex_match[/^[A-Za-z0-9]+$/]|max_length[30]', + 'AlternatePID' => 'permit_empty|regex_match[/^[A-Za-z0-9]+$/]|max_length[30]', + 'Prefix' => 'permit_empty|regex_match[/^[A-Za-z\'\. ]+$/]|max_length[10]', 'Gender' => 'required', - 'Birthdate' => 'required', - "PatIdt.Identifier" => 'max_length[255]' + + 'NameFirst' => 'required|regex_match[/^[A-Za-z\'\. ]+$/]|min_length[1]|max_length[60]', + 'NameMiddle' => 'permit_empty|regex_match[/^[A-Za-z\'\. ]+$/]|min_length[1]|max_length[60]', + 'NameMaiden' => 'permit_empty|regex_match[/^[A-Za-z\'\. ]+$/]|min_length[1]|max_length[60]', + 'NameLast' => 'permit_empty|regex_match[/^[A-Za-z\'\. ]+$/]|min_length[1]|max_length[60]', + + 'Suffix' => 'permit_empty|regex_match[/^[A-Za-z\'\. ]+$/]|max_length[10]', + 'PlaceOfBirth' => 'permit_empty|regex_match[/^[A-Za-z\'\. ]+$/]|max_length[100]', + 'Citizenship' => 'permit_empty|regex_match[/^[A-Za-z\'\. ]+$/]|max_length[100]', + + 'Street_1' => 'permit_empty|regex_match[/^[A-Za-z0-9\'.,\/\- ]+$/]|max_length[255]', + 'Street_2' => 'permit_empty|regex_match[/^[A-Za-z0-9\'.,\/\- ]+$/]|max_length[255]', + 'Street_3' => 'permit_empty|regex_match[/^[A-Za-z0-9\'.,\/\- ]+$/]|max_length[255]', + + 'EmailAddress1' => 'permit_empty|valid_email|max_length[100]', + 'EmailAddress2' => 'permit_empty|valid_email|max_length[100]', + + 'Birthdate' => 'required', + 'PatIdt.IdentifierType' => 'permit_empty', + 'PatIdt.Identifier' => 'permit_empty|max_length[255]', + + 'ZIP' => 'permit_empty|is_natural|max_length[10]', + 'Phone' => 'permit_empty|regex_match[/^\\+?[0-9]{8,15}$/]', + 'MobilePhone' => 'permit_empty|regex_match[/^\\+?[0-9]{8,15}$/]' ]; } @@ -55,6 +76,26 @@ class Patient extends Controller { public function create() { $input = $this->request->getJSON(true); + + // Khusus untuk Override PATIDT + $type = $input['PatIdt']['IdentifierType'] ?? null; + $identifierRulesMap = [ + 'KTP' => 'required|regex_match[/^[0-9]{16}$/]', + 'PASS' => 'required|regex_match[/^[A-Za-z0-9]{6,9}$/]', + 'SSN' => 'required|regex_match[/^[0-9]{3}-[0-9]{2}-[0-9]{4}$/]', + 'SIM' => 'required|regex_match[/^[A-Za-z0-9]{12,14}$/]', + 'KTAS' => 'required|regex_match[/^[A-Za-z0-9]{12,15}$/]', + ]; + if ($type === null || $type === '') { + $identifierRule = 'permit_empty|max_length[255]'; + $this->rules['PatIdt.IdentifierType'] = 'permit_empty'; + $this->rules['PatIdt.Identifier'] = $identifierRule; + } else { + $identifierRule = $identifierRulesMap[$type] ?? 'permit_empty|max_length[255]'; + $this->rules['PatIdt.IdentifierType'] = 'required'; + $this->rules['PatIdt.Identifier'] = $identifierRule; + } + if (!$this->validateData($input, $this->rules)) { return $this->failValidationErrors($this->validator->getErrors()); } try { $InternalPID = $this->model->createPatient($input);