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/
/phpunit*.xml
/public/.htaccess

View File

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