Update PatientController Create, Update, Show
This commit is contained in:
parent
6111c63cf4
commit
e97360c8dd
@ -82,10 +82,10 @@ class Patient extends Controller {
|
|||||||
} else {
|
} else {
|
||||||
|
|
||||||
$patient["Age"] = $this->calculateAgeFromBirthdate($patient["Birthdate"]);
|
$patient["Age"] = $this->calculateAgeFromBirthdate($patient["Birthdate"]);
|
||||||
|
$patient["Birthdate"] = $this->formatedDate($patient["Birthdate"]);
|
||||||
$patient["Birthdate"] = $this->formatDateForDB($patient["Birthdate"]);
|
$patient["CreateDate"] = $this->formatedDate($patient["CreateDate"]);
|
||||||
$patient["DeathDateTime"] = $this->formatDateForDB($patient["DeathDateTime"]);
|
$patient["DeathDateTime"] = $this->formatedDate($patient["DeathDateTime"]);
|
||||||
$patient["BirthdateConversion"] = $this->formatDateForDisplay($patient["Birthdate"]);
|
$patient["BirthdateConversion"] = $this->formatedDateForDisplay($patient["Birthdate"]);
|
||||||
|
|
||||||
if ($patient['LinkTo'] != null) {
|
if ($patient['LinkTo'] != null) {
|
||||||
|
|
||||||
@ -138,42 +138,75 @@ class Patient extends Controller {
|
|||||||
// =========================
|
// =========================
|
||||||
// 1. Data untuk tabel patient
|
// 1. Data untuk tabel patient
|
||||||
// =========================
|
// =========================
|
||||||
|
// $dataPatient = [
|
||||||
|
// "PatientID" => $input['PatientID'] ?? null,
|
||||||
|
// "AlternatePID" => $input['AlternatePID'] ?? null,
|
||||||
|
// "Prefix" => $input['Prefix'] ?? null,
|
||||||
|
// "NameFirst" => $input['NameFirst'] ?? null,
|
||||||
|
// "NameMiddle" => $input['NameMiddle'] ?? null,
|
||||||
|
// "NameMaiden" => $input['NameMaiden'] ?? null,
|
||||||
|
// "NameLast" => $input['NameLast'] ?? null,
|
||||||
|
// "Suffix" => $input['Suffix'] ?? null,
|
||||||
|
// "NameAlias" => $input['NameAlias'] ?? null,
|
||||||
|
// "Gender" => isset($input['Gender']) ? (int) $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,
|
||||||
|
// "ZIP" => $input['ZIP'] ?? null,
|
||||||
|
// "EmailAddress1" => $input['EmailAddress1'] ?? null,
|
||||||
|
// "EmailAddress2" => $input['EmailAddress2'] ?? null,
|
||||||
|
// "Phone" => $input['Phone'] ?? null,
|
||||||
|
// "MobilePhone" => $input['MobilePhone'] ?? null,
|
||||||
|
// "RaceID" => isset($input['RaceID']) ? (int) $input['RaceID'] : null,
|
||||||
|
// "IntCountryID" => isset($input['IntCountryID']) ? (int) $input['IntCountryID'] : null,
|
||||||
|
// "MaritalStatus" => $input['MaritalStatus'] ?? null,
|
||||||
|
// "ReligionID" => isset($input['ReligionID']) ? (int) $input['ReligionID'] : null,
|
||||||
|
// "EthnicID" => isset($input['EthnicID']) ? (int) $input['EthnicID'] : null,
|
||||||
|
// "Citizenship" => $input['Citizenship'] ?? null,
|
||||||
|
// "DeathIndicator" => isset($input['DeathIndicator']) ? (int) $input['DeathIndicator'] : null,
|
||||||
|
// 'DeathDateTime' => $input['DeathDateTime'] ?: null,
|
||||||
|
// "CreateDate" => date('Y-m-d H:i:s'),
|
||||||
|
// "DelDate" => null,
|
||||||
|
// "LinkTo" => $LinkTo
|
||||||
|
// ];
|
||||||
$dataPatient = [
|
$dataPatient = [
|
||||||
"PatientID" => $input['PatientID'] ?? null,
|
"PatientID" => ($input['PatientID'] ?? '') !== '' ? $input['PatientID'] : null,
|
||||||
"AlternatePID" => $input['AlternatePID'] ?? null,
|
"AlternatePID" => ($input['AlternatePID'] ?? '') !== '' ? $input['AlternatePID'] : null,
|
||||||
"Prefix" => $input['Prefix'] ?? null,
|
"Prefix" => ($input['Prefix'] ?? '') !== '' ? $input['Prefix'] : null,
|
||||||
"NameFirst" => $input['NameFirst'] ?? null,
|
"NameFirst" => ($input['NameFirst'] ?? '') !== '' ? $input['NameFirst'] : null,
|
||||||
"NameMiddle" => $input['NameMiddle'] ?? null,
|
"NameMiddle" => ($input['NameMiddle'] ?? '') !== '' ? $input['NameMiddle'] : null,
|
||||||
"NameMaiden" => $input['NameMaiden'] ?? null,
|
"NameMaiden" => ($input['NameMaiden'] ?? '') !== '' ? $input['NameMaiden'] : null,
|
||||||
"NameLast" => $input['NameLast'] ?? null,
|
"NameLast" => ($input['NameLast'] ?? '') !== '' ? $input['NameLast'] : null,
|
||||||
"Suffix" => $input['Suffix'] ?? null,
|
"Suffix" => ($input['Suffix'] ?? '') !== '' ? $input['Suffix'] : null,
|
||||||
"NameAlias" => $input['NameAlias'] ?? null,
|
"NameAlias" => ($input['NameAlias'] ?? '') !== '' ? $input['NameAlias'] : null,
|
||||||
"Gender" => isset($input['Gender']) ? (int) $input['Gender'] : null,
|
"Gender" => ($input['Gender'] ?? '') !== '' ? (int)$input['Gender'] : null,
|
||||||
"PlaceOfBirth" => $input['PlaceOfBirth'] ?? null,
|
"PlaceOfBirth" => ($input['PlaceOfBirth'] ?? '') !== '' ? $input['PlaceOfBirth'] : null,
|
||||||
"Birthdate" => $input['Birthdate'] ?: null,
|
"Birthdate" => ($input['Birthdate'] ?? '') !== '' ? $input['Birthdate'] : null,
|
||||||
"Street_1" => $input['Street_1'] ?? null,
|
"Street_1" => ($input['Street_1'] ?? '') !== '' ? $input['Street_1'] : null,
|
||||||
"Street_2" => $input['Street_2'] ?? null,
|
"Street_2" => ($input['Street_2'] ?? '') !== '' ? $input['Street_2'] : null,
|
||||||
"Street_3" => $input['Street_3'] ?? null,
|
"Street_3" => ($input['Street_3'] ?? '') !== '' ? $input['Street_3'] : null,
|
||||||
"City" => $input['City'] ?? null,
|
"City" => ($input['City'] ?? '') !== '' ? $input['City'] : null,
|
||||||
"Province" => $input['Province'] ?? null,
|
"Province" => ($input['Province'] ?? '') !== '' ? $input['Province'] : null,
|
||||||
"ZIP" => $input['ZIP'] ?? null,
|
"ZIP" => ($input['ZIP'] ?? '') !== '' ? $input['ZIP'] : null,
|
||||||
"EmailAddress1" => $input['EmailAddress1'] ?? null,
|
"EmailAddress1" => ($input['EmailAddress1'] ?? '') !== '' ? $input['EmailAddress1'] : null,
|
||||||
"EmailAddress2" => $input['EmailAddress2'] ?? null,
|
"EmailAddress2" => ($input['EmailAddress2'] ?? '') !== '' ? $input['EmailAddress2'] : null,
|
||||||
"Phone" => $input['Phone'] ?? null,
|
"Phone" => ($input['Phone'] ?? '') !== '' ? $input['Phone'] : null,
|
||||||
"MobilePhone" => $input['MobilePhone'] ?? null,
|
"MobilePhone" => ($input['MobilePhone'] ?? '') !== '' ? $input['MobilePhone'] : null,
|
||||||
"RaceID" => isset($input['RaceID']) ? (int) $input['RaceID'] : null,
|
"RaceID" => ($input['RaceID'] ?? '') !== '' ? (int)$input['RaceID'] : null,
|
||||||
"IntCountryID" => isset($input['IntCountryID']) ? (int) $input['IntCountryID'] : null,
|
"IntCountryID" => ($input['IntCountryID'] ?? '') !== '' ? (int)$input['IntCountryID'] : null,
|
||||||
"MaritalStatus" => $input['MaritalStatus'] ?? null,
|
"MaritalStatus" => ($input['MaritalStatus'] ?? '') !== '' ? $input['MaritalStatus'] : null,
|
||||||
"ReligionID" => isset($input['ReligionID']) ? (int) $input['ReligionID'] : null,
|
"ReligionID" => ($input['ReligionID'] ?? '') !== '' ? (int)$input['ReligionID'] : null,
|
||||||
"EthnicID" => isset($input['EthnicID']) ? (int) $input['EthnicID'] : null,
|
"EthnicID" => ($input['EthnicID'] ?? '') !== '' ? (int)$input['EthnicID'] : null,
|
||||||
"Citizenship" => $input['Citizenship'] ?? null,
|
"Citizenship" => ($input['Citizenship'] ?? '') !== '' ? $input['Citizenship'] : null,
|
||||||
"DeathIndicator" => isset($input['DeathIndicator']) ? (int) $input['DeathIndicator'] : null,
|
"DeathIndicator" => ($input['DeathIndicator'] ?? '') !== '' ? (int)$input['DeathIndicator'] : null,
|
||||||
'DeathDateTime' => $input['DeathDateTime'] ?: null,
|
"DeathDateTime" => ($input['DeathDateTime'] ?? '') !== '' ? $input['DeathDateTime'] : null,
|
||||||
"CreateDate" => date('Y-m-d H:i:s'),
|
"CreateDate" => date('Y-m-d H:i:s'),
|
||||||
"DelDate" => null,
|
"DelDate" => null,
|
||||||
"LinkTo" => $LinkTo
|
"LinkTo" => $LinkTo
|
||||||
// Mother
|
|
||||||
// AccountNumber
|
|
||||||
];
|
];
|
||||||
|
|
||||||
$rulesDataPatient = [
|
$rulesDataPatient = [
|
||||||
@ -186,11 +219,10 @@ class Patient extends Controller {
|
|||||||
];
|
];
|
||||||
|
|
||||||
$dataPatidt = [
|
$dataPatidt = [
|
||||||
"IdentifierType" => $input['Identity']['IdentifierType'] ?? null,
|
"IdentifierType" => $input['Identity']['IdentifierType'] === '' ? null : ($input['Identity']['IdentifierType'] ?? null),
|
||||||
"Identifier" => $input['Identity']['Identifier'] ?? null,
|
"Identifier" => $input['Identity']['Identifier'] === '' ? null : ($input['Identity']['Identifier'] ?? null),
|
||||||
"CreateDate" => date('Y-m-d H:i:s'),
|
"CreateDate" => date('Y-m-d H:i:s'),
|
||||||
];
|
];
|
||||||
|
|
||||||
$rulesDataPatidt = [
|
$rulesDataPatidt = [
|
||||||
'Identifier' => 'required|is_unique[patidt.Identifier]',
|
'Identifier' => 'required|is_unique[patidt.Identifier]',
|
||||||
];
|
];
|
||||||
@ -253,115 +285,6 @@ class Patient extends Controller {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// OK - Done
|
// OK - Done
|
||||||
// public function update($InternalPID = null) {
|
|
||||||
|
|
||||||
// try {
|
|
||||||
|
|
||||||
// $InternalPID = (int) $InternalPID;
|
|
||||||
|
|
||||||
// $input = $this->request->getJSON(true);
|
|
||||||
|
|
||||||
// $dataPatient = [
|
|
||||||
// "PatientID" => $input['PatientID'] ?? null,
|
|
||||||
// "AlternatePID" => $input['AlternatePID'] ?? null,
|
|
||||||
// "Prefix" => $input['Prefix'] ?? null,
|
|
||||||
// "NameFirst" => $input['NameFirst'] ?? null,
|
|
||||||
// "NameMiddle" => $input['NameMiddle'] ?? null,
|
|
||||||
// "NameMaiden" => $input['NameMaiden'] ?? null,
|
|
||||||
// "NameLast" => $input['NameLast'] ?? null,
|
|
||||||
// "Suffix" => $input['Suffix'] ?? null,
|
|
||||||
// "NameAlias" => $input['NameAlias'] ?? null,
|
|
||||||
// "Gender" => isset($input['Gender']) ? (int) $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,
|
|
||||||
// "ZIP" => $input['ZIP'] ?? null,
|
|
||||||
// "EmailAddress1" => $input['EmailAddress1'] ?? null,
|
|
||||||
// "EmailAddress2" => $input['EmailAddress2'] ?? null,
|
|
||||||
// "Phone" => $input['Phone'] ?? null,
|
|
||||||
// "MobilePhone" => $input['MobilePhone'] ?? null,
|
|
||||||
// "RaceID" => isset($input['RaceID']) ? (int) $input['RaceID'] : null,
|
|
||||||
// "IntCountryID" => isset($input['IntCountryID']) ? (int) $input['IntCountryID'] : null,
|
|
||||||
// "MaritalStatus" => $input['MaritalStatus'] ?? null,
|
|
||||||
// "ReligionID" => isset($input['ReligionID']) ? (int) $input['ReligionID'] : null,
|
|
||||||
// "EthnicID" => isset($input['EthnicID']) ? (int) $input['EthnicID'] : null,
|
|
||||||
// "Citizenship" => $input['Citizenship'] ?? null,
|
|
||||||
// "DeathIndicator" => isset($input['DeathIndicator']) ? (int) $input['DeathIndicator'] : null,
|
|
||||||
// 'DeathDateTime' => $input['DeathDateTime'] ?: null,
|
|
||||||
// "CreateDate" => date('Y-m-d H:i:s'),
|
|
||||||
// "DelDate" => null,
|
|
||||||
// // Linkto
|
|
||||||
// // Mother
|
|
||||||
// // AccountNumber
|
|
||||||
// ];
|
|
||||||
|
|
||||||
// $rulesDataPatient = [
|
|
||||||
// 'PatientID' => 'required|is_unique[patient.PatientID]|max_length[50]',
|
|
||||||
// 'AlternatePID' => 'permit_empty|max_length[50]',
|
|
||||||
// 'NameFirst' => 'required|min_length[1]|max_length[255]',
|
|
||||||
// 'EmailAddress1' => 'required|is_unique[patient.EmailAddress1]',
|
|
||||||
// 'DeathIndicator' => 'required',
|
|
||||||
// 'Gender' => 'required'
|
|
||||||
// ];
|
|
||||||
|
|
||||||
// $dataPatidt = [
|
|
||||||
// "IdentifierType" => $input['IdentifierType'] ?? null,
|
|
||||||
// "Identifier" => $input['Identifier'] ?? null,
|
|
||||||
// "CreateDate" => date('Y-m-d H:i:s'),
|
|
||||||
// ];
|
|
||||||
|
|
||||||
// $rulesDataPatidt = [
|
|
||||||
// 'Identifier' => 'required|is_unique[patidt.Identifier]',
|
|
||||||
// ];
|
|
||||||
|
|
||||||
// $existingPatient = $this->db->table('patient')->where('InternalPID', $InternalPID)->get()->getRowArray();
|
|
||||||
|
|
||||||
// // Mengembalikan 404
|
|
||||||
// if (empty($existingPatient)) {
|
|
||||||
// return $this->failNotFound('Patient with ID ' . $InternalPID . ' not found.');
|
|
||||||
// }
|
|
||||||
|
|
||||||
// // Request dari client tidak valid atau tidak bisa diproses oleh server - 400
|
|
||||||
// if (!$this->validateData($dataPatient, $rules)) {
|
|
||||||
// return $this->failValidationErrors($this->validator->getErrors());
|
|
||||||
// }
|
|
||||||
|
|
||||||
// $allowedUpdateFields = [
|
|
||||||
// 'NameFirst', 'NameLast', 'NameMiddle',
|
|
||||||
// 'PatientID', 'AlternatePID', 'Birthdate', 'PlaceOfBirth',
|
|
||||||
// 'Street_1', 'Street_2', 'Street_3', 'City', 'Province', 'ZIP',
|
|
||||||
// 'EmailAddress1', 'EmailAddress2', 'Phone', 'MobilePhone', 'Mother', 'AccountNumber'
|
|
||||||
// ];
|
|
||||||
|
|
||||||
// $datas = [];
|
|
||||||
// foreach ($allowedUpdateFields as $field) {
|
|
||||||
// if (isset($dataPatient[$field])) {
|
|
||||||
// $datas[$field] = $dataPatient[$field];
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
// if (empty($dataPatient)) {
|
|
||||||
// return $this->failValidationError('No data provided for update.');
|
|
||||||
// }
|
|
||||||
|
|
||||||
// $this->db->table('patient')->where('InternalPID', $InternalPID)->update($dataPatient);
|
|
||||||
|
|
||||||
// // Sukses & Insert = 201 - Kirim data patient ID
|
|
||||||
// return $this->respondCreated([
|
|
||||||
// 'status' => 'success',
|
|
||||||
// 'message' => 'Patient updated successfully',
|
|
||||||
// 'data' => $dataPatient
|
|
||||||
// ], 201);
|
|
||||||
|
|
||||||
// } catch (\Exception $e) {
|
|
||||||
// // Error Server = 500
|
|
||||||
// return $this->failServerError('Something went wrong '.$e->getMessage());
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
public function update($InternalPID = null) {
|
public function update($InternalPID = null) {
|
||||||
try {
|
try {
|
||||||
if (!$InternalPID || !is_numeric($InternalPID)) {
|
if (!$InternalPID || !is_numeric($InternalPID)) {
|
||||||
@ -391,37 +314,70 @@ class Patient extends Controller {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Data untuk update patient
|
// Data untuk update patient
|
||||||
|
// $dataPatient = [
|
||||||
|
// "PatientID" => $input['PatientID'] ?? $patient['PatientID'],
|
||||||
|
// "AlternatePID" => $input['AlternatePID'] ?? $patient['AlternatePID'],
|
||||||
|
// "Prefix" => $input['Prefix'] ?? $patient['Prefix'],
|
||||||
|
// "NameFirst" => $input['NameFirst'] ?? $patient['NameFirst'],
|
||||||
|
// "NameMiddle" => $input['NameMiddle'] ?? $patient['NameMiddle'],
|
||||||
|
// "NameMaiden" => $input['NameMaiden'] ?? $patient['NameMaiden'],
|
||||||
|
// "NameLast" => $input['NameLast'] ?? $patient['NameLast'],
|
||||||
|
// "Suffix" => $input['Suffix'] ?? $patient['Suffix'],
|
||||||
|
// "NameAlias" => $input['NameAlias'] ?? $patient['NameAlias'],
|
||||||
|
// "Gender" => isset($input['Gender']) && is_numeric($input['Gender']) ? (int)$input['Gender'] : $patient['Gender'],
|
||||||
|
// "PlaceOfBirth" => $input['PlaceOfBirth'] ?? $patient['PlaceOfBirth'],
|
||||||
|
// "Birthdate" => $input['Birthdate'] ?: $patient['Birthdate'],
|
||||||
|
// "Street_1" => $input['Street_1'] ?? $patient['Street_1'],
|
||||||
|
// "Street_2" => $input['Street_2'] ?? $patient['Street_2'],
|
||||||
|
// "Street_3" => $input['Street_3'] ?? $patient['Street_3'],
|
||||||
|
// "City" => $input['City'] ?? $patient['City'],
|
||||||
|
// "Province" => $input['Province'] ?? $patient['Province'],
|
||||||
|
// "ZIP" => $input['ZIP'] ?? $patient['ZIP'],
|
||||||
|
// "EmailAddress1" => $input['EmailAddress1'] ?? $patient['EmailAddress1'],
|
||||||
|
// "EmailAddress2" => $input['EmailAddress2'] ?? $patient['EmailAddress2'],
|
||||||
|
// "Phone" => $input['Phone'] ?? $patient['Phone'],
|
||||||
|
// "MobilePhone" => $input['MobilePhone'] ?? $patient['MobilePhone'],
|
||||||
|
// "RaceID" => isset($input['RaceID']) && is_numeric($input['RaceID']) ? (int)$input['RaceID'] : $patient['RaceID'],
|
||||||
|
// "IntCountryID" => isset($input['IntCountryID']) && is_numeric($input['IntCountryID']) ? (int)$input['IntCountryID'] : $patient['IntCountryID'],
|
||||||
|
// "MaritalStatus" => $input['MaritalStatus'] ?? $patient['MaritalStatus'],
|
||||||
|
// "ReligionID" => isset($input['ReligionID']) && is_numeric($input['ReligionID']) ? (int)$input['ReligionID'] : $patient['ReligionID'],
|
||||||
|
// "EthnicID" => isset($input['EthnicID']) && is_numeric($input['EthnicID']) ? (int)$input['EthnicID'] : $patient['EthnicID'],
|
||||||
|
// "Citizenship" => $input['Citizenship'] ?? $patient['Citizenship'],
|
||||||
|
// "DeathIndicator" => isset($input['DeathIndicator']) && is_numeric($input['DeathIndicator']) ? (int)$input['DeathIndicator'] : $patient['DeathIndicator'],
|
||||||
|
// 'DeathDateTime' => $input['DeathDateTime'] ?: $patient['DeathDateTime'],
|
||||||
|
// "LinkTo" => $LinkTo,
|
||||||
|
// ];
|
||||||
$dataPatient = [
|
$dataPatient = [
|
||||||
"PatientID" => $input['PatientID'] ?? $patient['PatientID'],
|
"PatientID" => ($input['PatientID'] ?? null) === '' ? null : ($input['PatientID'] ?? null),
|
||||||
"AlternatePID" => $input['AlternatePID'] ?? $patient['AlternatePID'],
|
"AlternatePID" => ($input['AlternatePID'] ?? null) === '' ? null : ($input['AlternatePID'] ?? null),
|
||||||
"Prefix" => $input['Prefix'] ?? $patient['Prefix'],
|
"Prefix" => ($input['Prefix'] ?? null) === '' ? null : ($input['Prefix'] ?? null),
|
||||||
"NameFirst" => $input['NameFirst'] ?? $patient['NameFirst'],
|
"NameFirst" => ($input['NameFirst'] ?? null) === '' ? null : ($input['NameFirst'] ?? null),
|
||||||
"NameMiddle" => $input['NameMiddle'] ?? $patient['NameMiddle'],
|
"NameMiddle" => ($input['NameMiddle'] ?? null) === '' ? null : ($input['NameMiddle'] ?? null),
|
||||||
"NameMaiden" => $input['NameMaiden'] ?? $patient['NameMaiden'],
|
"NameMaiden" => ($input['NameMaiden'] ?? null) === '' ? null : ($input['NameMaiden'] ?? null),
|
||||||
"NameLast" => $input['NameLast'] ?? $patient['NameLast'],
|
"NameLast" => ($input['NameLast'] ?? null) === '' ? null : ($input['NameLast'] ?? null),
|
||||||
"Suffix" => $input['Suffix'] ?? $patient['Suffix'],
|
"Suffix" => ($input['Suffix'] ?? null) === '' ? null : ($input['Suffix'] ?? null),
|
||||||
"NameAlias" => $input['NameAlias'] ?? $patient['NameAlias'],
|
"NameAlias" => ($input['NameAlias'] ?? null) === '' ? null : ($input['NameAlias'] ?? null),
|
||||||
"Gender" => isset($input['Gender']) && is_numeric($input['Gender']) ? (int)$input['Gender'] : $patient['Gender'],
|
"Gender" => ($input['Gender'] ?? null) === '' ? null : (isset($input['Gender']) ? (int)$input['Gender'] : null),
|
||||||
"PlaceOfBirth" => $input['PlaceOfBirth'] ?? $patient['PlaceOfBirth'],
|
"PlaceOfBirth" => ($input['PlaceOfBirth'] ?? null) === '' ? null : ($input['PlaceOfBirth'] ?? null),
|
||||||
"Birthdate" => $input['Birthdate'] ?: $patient['Birthdate'],
|
"Birthdate" => ($input['Birthdate'] ?? null) === '' ? null : ($input['Birthdate'] ?? null),
|
||||||
"Street_1" => $input['Street_1'] ?? $patient['Street_1'],
|
"Street_1" => ($input['Street_1'] ?? null) === '' ? null : ($input['Street_1'] ?? null),
|
||||||
"Street_2" => $input['Street_2'] ?? $patient['Street_2'],
|
"Street_2" => ($input['Street_2'] ?? null) === '' ? null : ($input['Street_2'] ?? null),
|
||||||
"Street_3" => $input['Street_3'] ?? $patient['Street_3'],
|
"Street_3" => ($input['Street_3'] ?? null) === '' ? null : ($input['Street_3'] ?? null),
|
||||||
"City" => $input['City'] ?? $patient['City'],
|
"City" => ($input['City'] ?? null) === '' ? null : ($input['City'] ?? null),
|
||||||
"Province" => $input['Province'] ?? $patient['Province'],
|
"Province" => ($input['Province'] ?? null) === '' ? null : ($input['Province'] ?? null),
|
||||||
"ZIP" => $input['ZIP'] ?? $patient['ZIP'],
|
"ZIP" => ($input['ZIP'] ?? null) === '' ? null : ($input['ZIP'] ?? null),
|
||||||
"EmailAddress1" => $input['EmailAddress1'] ?? $patient['EmailAddress1'],
|
"EmailAddress1" => ($input['EmailAddress1'] ?? null) === '' ? null : ($input['EmailAddress1'] ?? null),
|
||||||
"EmailAddress2" => $input['EmailAddress2'] ?? $patient['EmailAddress2'],
|
"EmailAddress2" => ($input['EmailAddress2'] ?? null) === '' ? null : ($input['EmailAddress2'] ?? null),
|
||||||
"Phone" => $input['Phone'] ?? $patient['Phone'],
|
"Phone" => ($input['Phone'] ?? null) === '' ? null : ($input['Phone'] ?? null),
|
||||||
"MobilePhone" => $input['MobilePhone'] ?? $patient['MobilePhone'],
|
"MobilePhone" => ($input['MobilePhone'] ?? null) === '' ? null : ($input['MobilePhone'] ?? null),
|
||||||
"RaceID" => isset($input['RaceID']) && is_numeric($input['RaceID']) ? (int)$input['RaceID'] : $patient['RaceID'],
|
"RaceID" => ($input['RaceID'] ?? null) === '' ? null : (isset($input['RaceID']) ? (int)$input['RaceID'] : null),
|
||||||
"IntCountryID" => isset($input['IntCountryID']) && is_numeric($input['IntCountryID']) ? (int)$input['IntCountryID'] : $patient['IntCountryID'],
|
"IntCountryID" => ($input['IntCountryID'] ?? null) === '' ? null : (isset($input['IntCountryID']) ? (int)$input['IntCountryID'] : null),
|
||||||
"MaritalStatus" => $input['MaritalStatus'] ?? $patient['MaritalStatus'],
|
"MaritalStatus" => ($input['MaritalStatus'] ?? null) === '' ? null : ($input['MaritalStatus'] ?? null),
|
||||||
"ReligionID" => isset($input['ReligionID']) && is_numeric($input['ReligionID']) ? (int)$input['ReligionID'] : $patient['ReligionID'],
|
"ReligionID" => ($input['ReligionID'] ?? null) === '' ? null : (isset($input['ReligionID']) ? (int)$input['ReligionID'] : null),
|
||||||
"EthnicID" => isset($input['EthnicID']) && is_numeric($input['EthnicID']) ? (int)$input['EthnicID'] : $patient['EthnicID'],
|
"EthnicID" => ($input['EthnicID'] ?? null) === '' ? null : (isset($input['EthnicID']) ? (int)$input['EthnicID'] : null),
|
||||||
"Citizenship" => $input['Citizenship'] ?? $patient['Citizenship'],
|
"Citizenship" => ($input['Citizenship'] ?? null) === '' ? null : ($input['Citizenship'] ?? null),
|
||||||
"DeathIndicator" => isset($input['DeathIndicator']) && is_numeric($input['DeathIndicator']) ? (int)$input['DeathIndicator'] : $patient['DeathIndicator'],
|
"DeathIndicator" => ($input['DeathIndicator'] ?? null) === '' ? null : (isset($input['DeathIndicator']) ? (int)$input['DeathIndicator'] : null),
|
||||||
'DeathDateTime' => $input['DeathDateTime'] ?: $patient['DeathDateTime'],
|
"DeathDateTime" => ($input['DeathDateTime'] ?? null) === '' ? null : ($input['DeathDateTime'] ?? null),
|
||||||
"LinkTo" => $LinkTo,
|
"LinkTo" => $LinkTo,
|
||||||
];
|
];
|
||||||
|
|
||||||
@ -438,8 +394,8 @@ class Patient extends Controller {
|
|||||||
// Ambil data patidt
|
// Ambil data patidt
|
||||||
$patidt = $this->db->table('patidt')->where('InternalPID', $InternalPID)->get()->getRowArray();
|
$patidt = $this->db->table('patidt')->where('InternalPID', $InternalPID)->get()->getRowArray();
|
||||||
$dataPatidt = [
|
$dataPatidt = [
|
||||||
"IdentifierType" => $input['Identity']['IdentifierType'] ?? ($patidt['IdentifierType'] ?? null),
|
"IdentifierType" => $input['Identity']['IdentifierType'] === '' ? null : ($input['Identity']['IdentifierType'] ?? null),
|
||||||
"Identifier" => $input['Identity']['Identifier'] ?? ($patidt['Identifier'] ?? null),
|
"Identifier" => $input['Identity']['Identifier'] === '' ? null : ($input['Identity']['Identifier'] ?? null),
|
||||||
];
|
];
|
||||||
|
|
||||||
$rulesDataPatidt = [
|
$rulesDataPatidt = [
|
||||||
@ -499,7 +455,6 @@ class Patient extends Controller {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// OK - Done
|
// OK - Done
|
||||||
public function delete($InternalPID = null) {
|
public function delete($InternalPID = null) {
|
||||||
|
|
||||||
@ -532,6 +487,7 @@ class Patient extends Controller {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Ubah ke format Years Months Days
|
||||||
private function calculateAgeFromBirthdate($birthdate) {
|
private function calculateAgeFromBirthdate($birthdate) {
|
||||||
$dob = new \DateTime($birthdate);
|
$dob = new \DateTime($birthdate);
|
||||||
$today = new \DateTime();
|
$today = new \DateTime();
|
||||||
@ -551,11 +507,10 @@ class Patient extends Controller {
|
|||||||
return $formattedAge;
|
return $formattedAge;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function formatDateForDB($dateString) {
|
// Ubah ke format Y-m-d H:i
|
||||||
// Ubah ke format Y-m-d H:i
|
private function formatedDate($dateString) {
|
||||||
$date = \DateTime::createFromFormat('Y-m-d H:i', $dateString);
|
$date = \DateTime::createFromFormat('Y-m-d H:i', $dateString);
|
||||||
|
|
||||||
// Kalau gagal, coba parse bebas
|
|
||||||
if (!$date) {
|
if (!$date) {
|
||||||
$timestamp = strtotime($dateString);
|
$timestamp = strtotime($dateString);
|
||||||
if ($timestamp) {
|
if ($timestamp) {
|
||||||
@ -567,11 +522,10 @@ class Patient extends Controller {
|
|||||||
return $date->format('Y-m-d H:i');
|
return $date->format('Y-m-d H:i');
|
||||||
}
|
}
|
||||||
|
|
||||||
private function formatDateForDisplay($dateString) {
|
// Ubah ke format j M Y
|
||||||
// Ubah ke format j M Y
|
private function formatedDateForDisplay($dateString) {
|
||||||
$date = \DateTime::createFromFormat('Y-m-d H:i', $dateString);
|
$date = \DateTime::createFromFormat('Y-m-d H:i', $dateString);
|
||||||
|
|
||||||
// Kalau gagal, coba parse bebas
|
|
||||||
if (!$date) {
|
if (!$date) {
|
||||||
$timestamp = strtotime($dateString);
|
$timestamp = strtotime($dateString);
|
||||||
if ($timestamp) {
|
if ($timestamp) {
|
||||||
@ -583,5 +537,4 @@ class Patient extends Controller {
|
|||||||
return $date->format('j M Y');
|
return $date->format('j M Y');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user