patient done, ignoring htaccess update

This commit is contained in:
mahdahar 2025-08-01 13:37:13 +07:00
parent cbf4f7a486
commit d615bd72b6
3 changed files with 174 additions and 125 deletions

1
.gitignore vendored
View File

@ -124,3 +124,4 @@ _modules/*
/results/ /results/
/phpunit*.xml /phpunit*.xml
/public/.htaccess

View File

@ -15,28 +15,32 @@ class Patient extends Controller {
// OK // OK
public function index() { public function index() {
try { try {
$pat_num = $this->request->getVar('pat_num'); $PatientID = $this->request->getVar('PatientID');
$pat_altnum = $this->request->getVar('pat_altnum'); $AlternatePID = $this->request->getVar('AlternatePID');
$pat_name = $this->request->getVar('pat_name'); $Prefix = $this->request->getVar('Prefix');
$pat_dob = $this->request->getVar('pat_dob'); $name = $this->request->getVar('name');
$start_date = $this->request->getVar('start_date'); $Suffix = $this->request->getVar('Suffix');
$end_date = $this->request->getVar('end_date'); $BirthDate = $this->request->getVar('BirthDate');
$startDate = $this->request->getVar('startDate');
$endDate = $this->request->getVar('endDate');
$builder = $this->db->table('patients'); $builder = $this->db->table('patients');
if ($pat_name !== null) { if ($name !== null) {
$sql = "LOWER(CONCAT_WS(' ', IFNULL(prefix,''), IFNULL(name_first,''), IFNULL(name_middle,''), IFNULL(name_last,''), IFNULL(name_maiden,''), IFNULL(suffix,'')))"; $sql = "LOWER(CONCAT_WS(' ', IFNULL(prefix,''), IFNULL(name_first,''), IFNULL(name_middle,''), IFNULL(name_last,''), IFNULL(name_maiden,''), IFNULL(suffix,'')))";
$rawSql = new RawSql($sql); $rawSql = new RawSql($sql);
$builder->like($rawSql, $pat_name, 'both'); $builder->like($rawSql, $name, 'both');
} }
if ($pat_num !== null) { $builder->where('pat_num', $pat_num); } if ($PatientID !== null) { $builder->where('PatientID', $pat_num); }
if ($pat_altnum !== null) { $builder->where('pat_altnum', $pat_altnum); } if ($AlternatePID !== null) { $builder->where('AlternatePID', $pat_altnum); }
if ($pat_dob !== null) { $builder->where('pat_dob', $pat_dob); } if ($BirthDate !== null) { $builder->where('BirthDate', $pat_dob); }
if ($start_date !== null || $end_date !== null) { /*
if ($startDate !== null || $endDate !== null) {
$builder->join('requests', 'pat_id=patients.pat_id','left'); $builder->join('requests', 'pat_id=patients.pat_id','left');
if ($start_date !== null) { $builder->where('requests.req_date >=', $start_date . ' 00:00:00'); } if ($start_date !== null) { $builder->where('requests.req_date >=', $start_date . ' 00:00:00'); }
if ($end_date !== null) { $builder->where('requests.req_date <=', $end_date . ' 23:59:00'); } if ($end_date !== null) { $builder->where('requests.req_date <=', $end_date . ' 23:59:00'); }
} }
*/
$filteredPatients = $builder->get()->getResultArray(); $filteredPatients = $builder->get()->getResultArray();
@ -68,8 +72,8 @@ class Patient extends Controller {
try { try {
$builder = $this->db->table('patients'); $builder = $this->db->table('Patients');
$patient = $builder->where('pat_num', $id)->get()->getRowArray(); $patient = $builder->where('PatientID', $id)->get()->getRowArray();
// Data pasien tidak ada mengembalikan - success 200 // Data pasien tidak ada mengembalikan - success 200
if (empty($patient)) { if (empty($patient)) {
@ -102,61 +106,54 @@ class Patient extends Controller {
$input = $this->request->getJSON(true); $input = $this->request->getJSON(true);
$data = [ $data = [
// "pat_id" => $input['patientID'] ?? null, "PatientID" => $input['PatientID'] ?? null,
"pat_num" => $input['alternateID'] ?? null, "AlternatePID" => $input['AlternatePID'] ?? null,
// "pat_altnum" => $input['alternateID'] ?? null, "Prefix" => $input['Prefix'] ?? null,
// "prefix" => $input['prefix'] ?? null, "NameFirst" => $input['NameFirst'] ?? null,
"NameMiddle" => $input['NameMiddle'] ?? null,
"name_first" => $input['firstName'] ?? null, "NameLast" => $input['NameLast'] ?? null,
"name_middle" => $input['middleName'] ?? null, "NameMaiden" => $input['NameMaiden'] ?? null,
"name_last" => $input['lastName'] ?? null, "Suffix" => $input['Suffix'] ?? null,
"name_maiden" => $input['maidenName'] ?? null, "NameAlias" => $input['NameAlias'] ?? null,
"gender" => $input['gender'] ?? null, "Gender" => $input['Gender'] ?? null,
"birth_place" => $input['placeOfBirthdate'] ?? null, "PlaceOfBirth" => $input['PlaceOfBirth'] ?? null,
"birth_date" => $input['birthdate'] ?? null, "BirthDate" => $input['BirthDate'] ?? null,
"mother" => $input['motherName'] ?? null, "Street_1" => $input['Street_1'] ?? null,
"marital_status" => $input['maritalStatus'] ?? null, "Street_2" => $input['Street_2'] ?? null,
// "religion_id" => $input['religion'] ?? null, "Street_3" => $input['Street_3'] ?? null,
// "race_id" => $input['race'] ?? null, "City" => $input['City'] ?? null,
// "ethinc_id" => $input['ethnic'] ?? null, "Province" => $input['Province'] ?? null,
"CountryID" => $input['CountryID'] ?? null,
// "suffix" => $input['suffix'] ?? null, "ZIP" => $input['ZIP'] ?? null,
// "name_alias" => $input['nameAlias'] ?? null, "EmailAddress1" => $input['EmailAddress1'] ?? null,
"EmailAddress2" => $input['EmailAddress2'] ?? null,
"address_1" => $input['street1'] ?? null, "Phone" => $input['Phone'] ?? null,
"address_2" => $input['street2'] ?? null, "Mobilephone" => $input['Mobilephone'] ?? null,
// "address_3" => $input['street3'] ?? null, "Mother" => $input['Mother'] ?? null,
"city" => $input['city'] ?? null, "Accountnumber" => $input['Accountnumber'] ?? null,
"province" => $input['province'] ?? null, "RaceID" => $input['RaceID'] ?? null,
"MaritalStatus" => $input['MaritalStatus'] ?? null,
// "zip" => $input['zip'] ?? null, "ReligionID" => $input['ReligionID'] ?? null,
"email_1" => $input['email1'] ?? null, "EthnicID" => $input['EthnicID'] ?? null,
"email_2" => $input['email2'] ?? null, "Citizenship" => $input['Citizenship'] ?? null,
"phone" => $input['phone'] ?? null, "DeathIndicator" => $input['DeathIndicator'] ?? null,
"mobile_phone" => $input['mobile'] ?? null, "DeathDateTime" => $input['DeathDateTime'] ?? null,
"death" => $input['death'] ?? null, "LinkTo" => $input['LinkTo'] ?? null,
"death_date" => $input['deathtime'] ?? null, "create_date" => date('Y-m-d H:i:s')
// "account_number" => $input['accountNumber'] ?? null,
// "country_id" => $input['countryId'] ?? null,
// "citizenship" => $input['citizenship'] ?? null,
// "link_to" => $input['linkTo'] ?? null,
"create_date" => date('Y-m-d H:i:s'),
// "del_date" => $input['delDate'] ?? null
]; ];
$rules = [ $rules = [
'pat_num' => 'required|is_unique[patients.pat_num]|max_length[50]', 'PatientID' => 'required|is_unique[patients.pat_num]|max_length[50]',
'name_first' => 'required|min_length[3]|max_length[255]', 'NameFirst' => 'required|min_length[3]|max_length[255]',
'name_middle' => 'permit_empty', 'NameMiddle' => 'permit_empty',
'name_maiden' => 'permit_empty', 'NameMaiden' => 'permit_empty',
'name_last' => 'permit_empty', 'NameLast' => 'permit_empty',
// 'birth_date' => 'permit_empty|valid_date[Y-m-d]|not_in_list[0000-00-00]', // 'birth_date' => 'permit_empty|valid_date[Y-m-d]|not_in_list[0000-00-00]',
'pat_altnum' => 'permit_empty|max_length[50]', 'AlternatePID' => 'permit_empty|max_length[50]',
'address_1' => 'permit_empty', 'Street_1' => 'permit_empty',
'address_2' => 'permit_empty', 'Street_2' => 'permit_empty',
'address_3' => 'permit_empty', 'Street_3' => 'permit_empty',
'city' => 'permit_empty', 'City' => 'permit_empty',
]; ];
// Request dari client tidak valid atau tidak bisa diproses oleh server - 400 // Request dari client tidak valid atau tidak bisa diproses oleh server - 400
@ -168,7 +165,7 @@ class Patient extends Controller {
], 400); ], 400);
} }
$this->db->table('patients')->insert($data); $this->db->table('Patient')->insert($data);
$newPatientId = $this->db->insertID(); $newPatientId = $this->db->insertID();
// Sukses & Insert = 201 - Kirim data patient ID // Sukses & Insert = 201 - Kirim data patient ID
@ -186,73 +183,77 @@ class Patient extends Controller {
} }
// OK // OK
public function update($pat_id = null) { public function update($PatientID = null) {
try { try {
$input = $this->request->getJSON(true); $input = $this->request->getJSON(true);
$data = [ $data = [
'name_first' => $input['name_first'], // Mengambil dari firstName "AlternatePID" => $input['AlternatePID'] ?? null,
'name_last' => $input['name_last'], // Mengambil dari lastName "Prefix" => $input['Prefix'] ?? null,
'name_middle' => $input['middleName'] ?? null, // Mengambil dari middleName "NameFirst" => $input['NameFirst'] ?? null,
'name_maiden' => $input['maindenName'] ?? null, // Mengambil dari maindenName "NameMiddle" => $input['NameMiddle'] ?? null,
'pat_num' => $input['pat_num'], // Mengambil dari patientID "NameLast" => $input['NameLast'] ?? null,
'prefix' => $input['title'] ?? null, // Mengambil dari title "NameMaiden" => $input['NameMaiden'] ?? null,
'suffix' => $input['suffixName'] ?? null, // Mengambil dari suffixName "Suffix" => $input['Suffix'] ?? null,
'birth_date' => $input['birthdate'] ?? null, // Mengambil dari birthdate "NameAlias" => $input['NameAlias'] ?? null,
'pat_altnum' => $input['alternateID'] ?? null, // Mengambil dari alternateID "Gender" => $input['Gender'] ?? null,
'address_1' => $input['street1'] ?? null, // Mengambil dari street1 "PlaceOfBirth" => $input['PlaceOfBirth'] ?? null,
'address_2' => $input['street2'] ?? null, // Mengambil dari street2 "BirthDate" => $input['BirthDate'] ?? null,
'address_3' => $input['placeOfBirthdate'] ?? null, // Memetakan placeOfBirthdate ke address_3, jika diperlukan "Street_1" => $input['Street_1'] ?? null,
'city' => $input['city'] ?? null, // Mengambil dari city "Street_2" => $input['Street_2'] ?? null,
'province' => $input['province'] ?? null, // Mengambil dari province "Street_3" => $input['Street_3'] ?? null,
'zip' => null, // Tidak ada padanan langsung di newPatientForm, bisa diisi manual atau dari input lain "City" => $input['City'] ?? null,
'email_1' => $input['email1'] ?? null, // Mengambil dari email1 "Province" => $input['Province'] ?? null,
'email_2' => $input['email2'] ?? null, // Mengambil dari email2 "CountryID" => $input['CountryID'] ?? null,
'phone' => $input['phone'] ?? null, // Mengambil dari phone "ZIP" => $input['ZIP'] ?? null,
'mobile_phone' => $input['mobile'] ?? null, // Mengambil dari mobile "EmailAddress1" => $input['EmailAddress1'] ?? null,
'mother' => $input['motherName'] ?? null, // Mengambil dari motherName "EmailAddress2" => $input['EmailAddress2'] ?? null,
'account_number' => null, // Tidak ada padanan langsung, bisa diisi manual atau dari input lain "Phone" => $input['Phone'] ?? null,
'marital_status' => $input['maritalStatus'] ?? null, // Mengambil dari maritalStatus "Mobilephone" => $input['Mobilephone'] ?? null,
'country_id' => null, // Tidak ada padanan langsung, perlu penyesuaian jika ada input negara "Mother" => $input['Mother'] ?? null,
'citizenship' => null, // Tidak ada padanan langsung, perlu penyesuaian jika ada input kewarganegaraan "Accountnumber" => $input['Accountnumber'] ?? null,
'death' => $input['death'] ?? null, // Mengambil dari death (asumsi 0/1 atau boolean) "RaceID" => $input['RaceID'] ?? null,
'death_date' => $input['deathTime'] ?? null, // Mengambil dari deathTime "MaritalStatus" => $input['MaritalStatus'] ?? null,
'create_date' => date('Y-m-d H:i:s'), // Ini adalah tanggal dan waktu saat ini di server PHP "ReligionID" => $input['ReligionID'] ?? null,
"EthnicID" => $input['EthnicID'] ?? null,
"Citizenship" => $input['Citizenship'] ?? null,
"DeathIndicator" => $input['DeathIndicator'] ?? null,
"DeathDateTime" => $input['DeathDateTime'] ?? null,
"LinkTo" => $input['LinkTo'] ?? null,
"create_date" => date('Y-m-d H:i:s')
]; ];
// Apakah Pasien Ada $rules = [
$existingPatient = $this->db->table('patients')->where('pat_id', $pat_id)->get()->getRowArray(); 'NameFirst' => 'required|min_length[3]|max_length[255]',
'NameMiddle' => 'permit_empty',
'NameMaiden' => 'permit_empty',
'NameLast' => 'permit_empty',
// 'birth_date' => 'permit_empty|valid_date[Y-m-d]|not_in_list[0000-00-00]',
'AlternatePID' => 'permit_empty|max_length[50]',
'Street_1' => 'permit_empty',
'Street_2' => 'permit_empty',
'Street_3' => 'permit_empty',
'City' => 'permit_empty',
];
$existingPatient = $this->db->table('Patient')->where('PatientID', $PatientID)->get()->getRowArray();
// Mengembalikan 404 // Mengembalikan 404
if (empty($existingPatient)) { if (empty($existingPatient)) {
return $this->failNotFound('Patient with ID ' . $pat_id . ' not found.'); return $this->failNotFound('Patient with ID ' . $PatientID . ' not found.');
} }
$rules = [
'pat_num' => 'required|max_length[50]',
'name_first' => 'required|min_length[3]|max_length[255]',
'name_middle' => 'permit_empty',
'name_maiden' => 'permit_empty',
'name_last' => 'permit_empty',
'birth_date' => 'permit_empty|valid_date[Y-m-d]',
'pat_altnum' => 'permit_empty|max_length[50]',
'address_1' => 'permit_empty',
'address_2' => 'permit_empty',
'address_3' => 'permit_empty',
'city' => 'permit_empty',
];
// Request dari client tidak valid atau tidak bisa diproses oleh server - 400 // Request dari client tidak valid atau tidak bisa diproses oleh server - 400
if (!$this->validateData($data, $rules)) { if (!$this->validateData($data, $rules)) {
return $this->failValidationErrors($this->validator->getErrors()); return $this->failValidationErrors($this->validator->getErrors());
} }
$allowedUpdateFields = [ $allowedUpdateFields = [
'name_first', 'name_last', 'name_middle', 'NameFirst', 'NameLast', 'NameMiddle',
'pat_num', 'pat_altnum', 'birth_date', 'birth_place', 'PatientID', 'AlternatePID', 'BirthDate', 'PlaceOfBirth',
'address_1', 'address_2', 'address_3', 'city', 'province', 'zip', 'Street_1', 'Street_2', 'Street_3', 'City', 'Province', 'ZIP',
'email_1', 'email_2', 'phone', 'mobile_phone', 'mother', 'account_number' 'Emailaddress1', 'Emailaddress2', 'Phone', 'Mobilephone', 'Mother', 'AccountNumber'
]; ];
$datas = []; $datas = [];
@ -266,7 +267,7 @@ class Patient extends Controller {
return $this->failValidationError('No data provided for update.'); return $this->failValidationError('No data provided for update.');
} }
$this->db->table('patients')->where('pat_id', $pat_id)->update($data); $this->db->table('Patient')->where('PatientID', $PatientID)->update($data);
// Sukses & Insert = 201 - Kirim data patient ID // Sukses & Insert = 201 - Kirim data patient ID
return $this->respondCreated([ return $this->respondCreated([
@ -282,31 +283,28 @@ class Patient extends Controller {
} }
// OK // OK
public function delete($pat_id = null) { public function delete($PatientID = null) {
try { try {
if (!$pat_id) { if (!$PatientID) {
return $this->failValidationError('Patient ID is required.'); return $this->failValidationError('Patient ID is required.');
} }
// Cari data pasien // Cari data pasien
$patient = $this->db->table('patients') $patient = $this->db->table('Patient')->where('PatientID', $PatientID)->get()->getRow();
->where('pat_id', $pat_id)
->get()
->getRow();
if (!$patient) { if (!$patient) {
return $this->failNotFound("Patient ID with {$pat_id} not found."); return $this->failNotFound("Patient ID with {$PatientID} not found.");
} }
// Hapus data pasien berdasarkan pat_num // Hapus data pasien berdasarkan pat_num
$this->db->table('patients')->where('pat_id', $pat_id)->delete(); $this->db->table('Patient')->where('PatientID', $PatientID)->delete();
// Mengembalikan 200 // Mengembalikan 200
return $this->respondDeleted([ return $this->respondDeleted([
'status' => 'success', 'status' => 'success',
'message' => "Patient ID with {$pat_id} deleted successfully." 'message' => "Patient ID with {$PatientID} deleted successfully."
]); ]);
} catch (\Exception $e) { } catch (\Exception $e) {

50
public/htaccess Normal file
View File

@ -0,0 +1,50 @@
# Disable directory browsing
Options -Indexes
# ----------------------------------------------------------------------
# Rewrite engine
# ----------------------------------------------------------------------
# Turning on the rewrite engine is necessary for the following rules and features.
# FollowSymLinks must be enabled for this to work.
<IfModule mod_rewrite.c>
Options +FollowSymlinks
RewriteEngine On
# If you installed CodeIgniter in a subfolder, you will need to
# change the following line to match the subfolder you need.
# http://httpd.apache.org/docs/current/mod/mod_rewrite.html#rewritebase
# RewriteBase /
# RewriteBase /clqms01/
# Redirect Trailing Slashes...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [L,R=301]
# Rewrite "www.example.com -> example.com"
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^ http://%1%{REQUEST_URI} [R=301,L]
# Checks to see if the user is attempting to access a valid file,
# such as an image or css document, if this isn't true it sends the
# request to the front controller, index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([\s\S]*)$ index.php/$1 [L,NC,QSA]
# Ensure Authorization header is passed along
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
</IfModule>
<IfModule !mod_rewrite.c>
# If we don't have mod_rewrite installed, all 404's
# can be sent to index.php, and everything works as normal.
ErrorDocument 404 index.php
</IfModule>
# Disable server signature start
ServerSignature Off
# Disable server signature end