Update Routes & Controller Patient
This commit is contained in:
parent
0b1b85b206
commit
951d5598ad
@ -16,6 +16,7 @@ $routes->post('/auth/register/', 'Auth::register');
|
|||||||
|
|
||||||
$routes->get('/api/patient', 'Patient::index');
|
$routes->get('/api/patient', 'Patient::index');
|
||||||
$routes->post('/api/patient', 'Patient::create');
|
$routes->post('/api/patient', 'Patient::create');
|
||||||
|
$routes->get('/api/patient/(:any)', 'Patient::show/$1');
|
||||||
$routes->delete('/api/patient/(:any)', 'Patient::delete/$1');
|
$routes->delete('/api/patient/(:any)', 'Patient::delete/$1');
|
||||||
$routes->patch('/api/patient/(:num)', 'Patient::update/$1');
|
$routes->patch('/api/patient/(:num)', 'Patient::update/$1');
|
||||||
|
|
||||||
|
|||||||
@ -12,7 +12,7 @@ class Patient extends Controller {
|
|||||||
$this->db = \Config\Database::connect();
|
$this->db = \Config\Database::connect();
|
||||||
}
|
}
|
||||||
|
|
||||||
// OK
|
// OK - Done
|
||||||
public function index() {
|
public function index() {
|
||||||
try {
|
try {
|
||||||
$PatientID = $this->request->getVar('PatientID');
|
$PatientID = $this->request->getVar('PatientID');
|
||||||
@ -67,13 +67,13 @@ class Patient extends Controller {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// OK
|
// OK - Done
|
||||||
public function show($id = null) {
|
public function show($InternalPID = null) {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
$builder = $this->db->table('Patient');
|
$builder = $this->db->table('Patient');
|
||||||
$patient = $builder->where('PatientID', $id)->get()->getRowArray();
|
$patient = $builder->where('InternalPID', $InternalPID)->get()->getRowArray();
|
||||||
|
|
||||||
// Data pasien tidak ada mengembalikan - success 200
|
// Data pasien tidak ada mengembalikan - success 200
|
||||||
if (empty($patient)) {
|
if (empty($patient)) {
|
||||||
@ -99,56 +99,60 @@ class Patient extends Controller {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// OK
|
// OK - Done
|
||||||
public function create() {
|
public function create() {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
$input = $this->request->getJSON(true);
|
$input = $this->request->getJSON(true);
|
||||||
|
|
||||||
$data = [
|
$data = [
|
||||||
"PatientID" => $input['PatientID'] ?? null,
|
"PatientID" => $input['patientID'] ?? null,
|
||||||
"AlternatePID" => $input['AlternatePID'] ?? null,
|
"AlternatePID" => $input['alternateID'] ?? null,
|
||||||
"Prefix" => $input['Prefix'] ?? null,
|
"Prefix" => $input['title'] ?? null,
|
||||||
"NameFirst" => $input['NameFirst'] ?? null,
|
"NameFirst" => $input['firstName'] ?? null,
|
||||||
"NameMiddle" => $input['NameMiddle'] ?? null,
|
"NameMiddle" => $input['middleName'] ?? null,
|
||||||
"NameLast" => $input['NameLast'] ?? null,
|
"NameMaiden" => $input['maidenName'] ?? null,
|
||||||
"NameMaiden" => $input['NameMaiden'] ?? null,
|
"NameLast" => $input['lastName'] ?? null,
|
||||||
"Suffix" => $input['Suffix'] ?? null,
|
"Suffix" => $input['suffixName'] ?? null,
|
||||||
"NameAlias" => $input['NameAlias'] ?? null,
|
"NameAlias" => null,
|
||||||
"Gender" => $input['Gender'] ?? null,
|
"Gender" => ((int) $input['gender']) ?? null, //int
|
||||||
"PlaceOfBirth" => $input['PlaceOfBirth'] ?? null,
|
"PlaceOfBirth" => $input['placeOfBirthdate'] ?? null,
|
||||||
"BirthDate" => $input['BirthDate'] ?? null,
|
"BirthDate" => $input['birthdate'] ?? null,
|
||||||
"Street_1" => $input['Street_1'] ?? null,
|
"Street_1" => $input['street1'] ?? null,
|
||||||
"Street_2" => $input['Street_2'] ?? null,
|
"Street_2" => $input['street2'] ?? null,
|
||||||
"Street_3" => $input['Street_3'] ?? null,
|
"Street_3" => null,
|
||||||
"City" => $input['City'] ?? null,
|
"City" => $input['city'] ?? null,
|
||||||
"Province" => $input['Province'] ?? null,
|
"Province" => $input['province'] ?? null,
|
||||||
"CountryID" => $input['CountryID'] ?? null,
|
"ZIP" => null,
|
||||||
"ZIP" => $input['ZIP'] ?? null,
|
"CountryID" => null, // int
|
||||||
"EmailAddress1" => $input['EmailAddress1'] ?? null,
|
"EmailAddress1" => $input['email1'] ?? null,
|
||||||
"EmailAddress2" => $input['EmailAddress2'] ?? null,
|
"EmailAddress2" => $input['email2'] ?? null,
|
||||||
"Phone" => $input['Phone'] ?? null,
|
"Phone" => $input['phone'] ?? null,
|
||||||
"Mobilephone" => $input['Mobilephone'] ?? null,
|
"Mobilephone" => $input['mobile'] ?? null,
|
||||||
"Mother" => $input['Mother'] ?? null,
|
// "Mother" => $input['motherName'] ?? null, //int
|
||||||
"Accountnumber" => $input['Accountnumber'] ?? null,
|
"Accountnumber" => null, //int
|
||||||
"RaceID" => $input['RaceID'] ?? null,
|
"RaceID" => ((int) $input['race']) ?? null, //int
|
||||||
"MaritalStatus" => $input['MaritalStatus'] ?? null,
|
"MaritalStatus" => $input['maritalStatus'] ?? null,
|
||||||
"ReligionID" => $input['ReligionID'] ?? null,
|
"ReligionID" => ((int)$input['religion']) ?? null, //int
|
||||||
"EthnicID" => $input['EthnicID'] ?? null,
|
"EthnicID" => ((int)$input['ethnic']) ?? null, //int
|
||||||
"Citizenship" => $input['Citizenship'] ?? null,
|
"Citizenship" => null,
|
||||||
"DeathIndicator" => $input['DeathIndicator'] ?? null,
|
"DeathIndicator" => ((int)$input['death']) ?? null, //int
|
||||||
"DeathDateTime" => $input['DeathDateTime'] ?? null,
|
"DeathDateTime" => $input['deathTime'] ?? null,
|
||||||
"LinkTo" => $input['LinkTo'] ?? null,
|
"CreateDate" => date('Y-m-d H:i:s')
|
||||||
"create_date" => date('Y-m-d H:i:s')
|
|
||||||
|
// "LinkTo" => $input['linkTo'] ?? null,
|
||||||
|
// "PatientComment" => $input['patientComment'] ?? null,
|
||||||
|
// "IdentityIDType" => $input['identityIDType'] ?? null,
|
||||||
|
// "IdentityID" => $input['identityID'] ?? null,
|
||||||
];
|
];
|
||||||
|
|
||||||
$rules = [
|
$rules = [
|
||||||
'PatientID' => 'required|is_unique[patients.pat_num]|max_length[50]',
|
'PatientID' => 'required|is_unique[patient.PatientID]|max_length[50]',
|
||||||
'NameFirst' => 'required|min_length[3]|max_length[255]',
|
'NameFirst' => 'required|min_length[3]|max_length[255]',
|
||||||
'NameMiddle' => 'permit_empty',
|
'NameMiddle' => 'permit_empty',
|
||||||
'NameMaiden' => 'permit_empty',
|
'NameMaiden' => 'permit_empty',
|
||||||
'NameLast' => '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]',
|
'AlternatePID' => 'permit_empty|max_length[50]',
|
||||||
'Street_1' => 'permit_empty',
|
'Street_1' => 'permit_empty',
|
||||||
'Street_2' => 'permit_empty',
|
'Street_2' => 'permit_empty',
|
||||||
@ -165,7 +169,7 @@ class Patient extends Controller {
|
|||||||
], 400);
|
], 400);
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->db->table('Patient')->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
|
||||||
@ -183,47 +187,51 @@ class Patient extends Controller {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// OK
|
// OK
|
||||||
public function update($PatientID = null) {
|
public function update($InternalPID = null) {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$input = $this->request->getJSON(true);
|
$input = $this->request->getJSON(true);
|
||||||
|
|
||||||
$data = [
|
$data = [
|
||||||
"AlternatePID" => $input['AlternatePID'] ?? null,
|
"PatientID" => $input['patientID'] ?? null,
|
||||||
"Prefix" => $input['Prefix'] ?? null,
|
"AlternatePID" => $input['alternateID'] ?? null,
|
||||||
"NameFirst" => $input['NameFirst'] ?? null,
|
"Prefix" => $input['title'] ?? null,
|
||||||
"NameMiddle" => $input['NameMiddle'] ?? null,
|
"NameFirst" => $input['firstName'] ?? null,
|
||||||
"NameLast" => $input['NameLast'] ?? null,
|
"NameMiddle" => $input['middleName'] ?? null,
|
||||||
"NameMaiden" => $input['NameMaiden'] ?? null,
|
"NameMaiden" => $input['maidenName'] ?? null,
|
||||||
"Suffix" => $input['Suffix'] ?? null,
|
"NameLast" => $input['lastName'] ?? null,
|
||||||
"NameAlias" => $input['NameAlias'] ?? null,
|
"Suffix" => $input['suffixName'] ?? null,
|
||||||
"Gender" => $input['Gender'] ?? null,
|
"NameAlias" => null,
|
||||||
"PlaceOfBirth" => $input['PlaceOfBirth'] ?? null,
|
"Gender" => ((int) $input['gender']) ?? null, //int
|
||||||
"BirthDate" => $input['BirthDate'] ?? null,
|
"PlaceOfBirth" => $input['placeOfBirthdate'] ?? null,
|
||||||
"Street_1" => $input['Street_1'] ?? null,
|
"BirthDate" => $input['birthdate'] ?? null,
|
||||||
"Street_2" => $input['Street_2'] ?? null,
|
"Street_1" => $input['street1'] ?? null,
|
||||||
"Street_3" => $input['Street_3'] ?? null,
|
"Street_2" => $input['street2'] ?? null,
|
||||||
"City" => $input['City'] ?? null,
|
"Street_3" => null,
|
||||||
"Province" => $input['Province'] ?? null,
|
"City" => $input['city'] ?? null,
|
||||||
"CountryID" => $input['CountryID'] ?? null,
|
"Province" => $input['province'] ?? null,
|
||||||
"ZIP" => $input['ZIP'] ?? null,
|
"ZIP" => null,
|
||||||
"EmailAddress1" => $input['EmailAddress1'] ?? null,
|
"CountryID" => null, // int
|
||||||
"EmailAddress2" => $input['EmailAddress2'] ?? null,
|
"EmailAddress1" => $input['email1'] ?? null,
|
||||||
"Phone" => $input['Phone'] ?? null,
|
"EmailAddress2" => $input['email2'] ?? null,
|
||||||
"Mobilephone" => $input['Mobilephone'] ?? null,
|
"Phone" => $input['phone'] ?? null,
|
||||||
"Mother" => $input['Mother'] ?? null,
|
"Mobilephone" => $input['mobile'] ?? null,
|
||||||
"Accountnumber" => $input['Accountnumber'] ?? null,
|
// "Mother" => $input['motherName'] ?? null, //int
|
||||||
"RaceID" => $input['RaceID'] ?? null,
|
"Accountnumber" => null, //int
|
||||||
"MaritalStatus" => $input['MaritalStatus'] ?? null,
|
"RaceID" => ((int) $input['race']) ?? null, //int
|
||||||
"ReligionID" => $input['ReligionID'] ?? null,
|
"MaritalStatus" => $input['maritalStatus'] ?? null,
|
||||||
"EthnicID" => $input['EthnicID'] ?? null,
|
"ReligionID" => ((int)$input['religion']) ?? null, //int
|
||||||
"Citizenship" => $input['Citizenship'] ?? null,
|
"EthnicID" => ((int)$input['ethnic']) ?? null, //int
|
||||||
"DeathIndicator" => $input['DeathIndicator'] ?? null,
|
"Citizenship" => null,
|
||||||
"DeathDateTime" => $input['DeathDateTime'] ?? null,
|
"DeathIndicator" => ((int)$input['death']) ?? null, //int
|
||||||
"LinkTo" => $input['LinkTo'] ?? null,
|
"DeathDateTime" => $input['deathTime'] ?? null,
|
||||||
"create_date" => date('Y-m-d H:i:s')
|
"CreateDate" => date('Y-m-d H:i:s')
|
||||||
|
// "LinkTo" => $input['linkTo'] ?? null,
|
||||||
|
// "PatientComment" => $input['patientComment'] ?? null,
|
||||||
|
// "IdentityIDType" => $input['identityIDType'] ?? null,
|
||||||
|
// "IdentityID" => $input['identityID'] ?? null,
|
||||||
];
|
];
|
||||||
|
|
||||||
$rules = [
|
$rules = [
|
||||||
'NameFirst' => 'required|min_length[3]|max_length[255]',
|
'NameFirst' => 'required|min_length[3]|max_length[255]',
|
||||||
'NameMiddle' => 'permit_empty',
|
'NameMiddle' => 'permit_empty',
|
||||||
@ -237,11 +245,11 @@ class Patient extends Controller {
|
|||||||
'City' => 'permit_empty',
|
'City' => 'permit_empty',
|
||||||
];
|
];
|
||||||
|
|
||||||
$existingPatient = $this->db->table('Patient')->where('PatientID', $PatientID)->get()->getRowArray();
|
$existingPatient = $this->db->table('Patient')->where('InternalPID', $InternalPID)->get()->getRowArray();
|
||||||
|
|
||||||
// Mengembalikan 404
|
// Mengembalikan 404
|
||||||
if (empty($existingPatient)) {
|
if (empty($existingPatient)) {
|
||||||
return $this->failNotFound('Patient with ID ' . $PatientID . ' not found.');
|
return $this->failNotFound('Patient with ID ' . $InternalPID . ' not found.');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Request dari client tidak valid atau tidak bisa diproses oleh server - 400
|
// Request dari client tidak valid atau tidak bisa diproses oleh server - 400
|
||||||
@ -267,7 +275,7 @@ class Patient extends Controller {
|
|||||||
return $this->failValidationError('No data provided for update.');
|
return $this->failValidationError('No data provided for update.');
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->db->table('Patient')->where('PatientID', $PatientID)->update($data);
|
$this->db->table('Patient')->where('PatientID', $InternalPID)->update($data);
|
||||||
|
|
||||||
// Sukses & Insert = 201 - Kirim data patient ID
|
// Sukses & Insert = 201 - Kirim data patient ID
|
||||||
return $this->respondCreated([
|
return $this->respondCreated([
|
||||||
@ -283,28 +291,28 @@ class Patient extends Controller {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// OK
|
// OK
|
||||||
public function delete($PatientID = null) {
|
public function delete($InternalPID = null) {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
if (!$PatientID) {
|
if (!$InternalPID) {
|
||||||
return $this->failValidationError('Patient ID is required.');
|
return $this->failValidationError('Patient ID is required.');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Cari data pasien
|
// Cari data pasien
|
||||||
$patient = $this->db->table('Patient')->where('PatientID', $PatientID)->get()->getRow();
|
$patient = $this->db->table('Patient')->where('InternalPID', $InternalPID)->get()->getRow();
|
||||||
|
|
||||||
if (!$patient) {
|
if (!$patient) {
|
||||||
return $this->failNotFound("Patient ID with {$PatientID} not found.");
|
return $this->failNotFound("Patient ID with {$InternalPID} not found.");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Hapus data pasien berdasarkan pat_num
|
// Hapus data pasien berdasarkan pat_num
|
||||||
$this->db->table('Patient')->where('PatientID', $PatientID)->delete();
|
$this->db->table('Patient')->where('InternalPID', $InternalPID)->delete();
|
||||||
|
|
||||||
// Mengembalikan 200
|
// Mengembalikan 200
|
||||||
return $this->respondDeleted([
|
return $this->respondDeleted([
|
||||||
'status' => 'success',
|
'status' => 'success',
|
||||||
'message' => "Patient ID with {$PatientID} deleted successfully."
|
'message' => "Patient ID with {$InternalPID} deleted successfully."
|
||||||
]);
|
]);
|
||||||
|
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user