Update Patient create, penambahan LinkTo
This commit is contained in:
parent
d5862a37a5
commit
04eb38177e
@ -110,6 +110,15 @@ class Patient extends Controller {
|
|||||||
try {
|
try {
|
||||||
$input = $this->request->getJSON(true);
|
$input = $this->request->getJSON(true);
|
||||||
|
|
||||||
|
$LinkTo = null;
|
||||||
|
if (!empty($input['LinkTo'])) {
|
||||||
|
$ids = []; // Temporary
|
||||||
|
foreach ($input['LinkTo'] as $row) {
|
||||||
|
$ids[] = $row['InternalPID'];
|
||||||
|
}
|
||||||
|
$LinkTo = implode(',', $ids);
|
||||||
|
}
|
||||||
|
|
||||||
// =========================
|
// =========================
|
||||||
// 1. Data untuk tabel patient
|
// 1. Data untuk tabel patient
|
||||||
// =========================
|
// =========================
|
||||||
@ -125,7 +134,7 @@ class Patient extends Controller {
|
|||||||
"NameAlias" => $input['NameAlias'] ?? null,
|
"NameAlias" => $input['NameAlias'] ?? null,
|
||||||
"Gender" => isset($input['Gender']) ? (int) $input['Gender'] : null,
|
"Gender" => isset($input['Gender']) ? (int) $input['Gender'] : null,
|
||||||
"PlaceOfBirth" => $input['PlaceOfBirth'] ?? null,
|
"PlaceOfBirth" => $input['PlaceOfBirth'] ?? null,
|
||||||
"Birthdate" => $input['Birthdate'] ?? null,
|
"Birthdate" => $input['Birthdate'] ?: null,
|
||||||
"Street_1" => $input['Street_1'] ?? null,
|
"Street_1" => $input['Street_1'] ?? null,
|
||||||
"Street_2" => $input['Street_2'] ?? null,
|
"Street_2" => $input['Street_2'] ?? null,
|
||||||
"Street_3" => $input['Street_3'] ?? null,
|
"Street_3" => $input['Street_3'] ?? null,
|
||||||
@ -146,7 +155,7 @@ class Patient extends Controller {
|
|||||||
'DeathDateTime' => $input['DeathDateTime'] ?: null,
|
'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
|
||||||
// Mother
|
// Mother
|
||||||
// AccountNumber
|
// AccountNumber
|
||||||
];
|
];
|
||||||
@ -237,8 +246,7 @@ class Patient extends Controller {
|
|||||||
|
|
||||||
$input = $this->request->getJSON(true);
|
$input = $this->request->getJSON(true);
|
||||||
|
|
||||||
$data = [
|
$dataPatient = [
|
||||||
"InternalPID" => $input['InternalPID'] ?? null,
|
|
||||||
"PatientID" => $input['PatientID'] ?? null,
|
"PatientID" => $input['PatientID'] ?? null,
|
||||||
"AlternatePID" => $input['AlternatePID'] ?? null,
|
"AlternatePID" => $input['AlternatePID'] ?? null,
|
||||||
"Prefix" => $input['Prefix'] ?? null,
|
"Prefix" => $input['Prefix'] ?? null,
|
||||||
@ -247,91 +255,52 @@ class Patient extends Controller {
|
|||||||
"NameMaiden" => $input['NameMaiden'] ?? null,
|
"NameMaiden" => $input['NameMaiden'] ?? null,
|
||||||
"NameLast" => $input['NameLast'] ?? null,
|
"NameLast" => $input['NameLast'] ?? null,
|
||||||
"Suffix" => $input['Suffix'] ?? null,
|
"Suffix" => $input['Suffix'] ?? null,
|
||||||
"NameAlias" => null,
|
"NameAlias" => $input['NameAlias'] ?? null,
|
||||||
"Gender" => isset($input['Gender']) ? (int) $input['Gender'] : null,
|
"Gender" => isset($input['Gender']) ? (int) $input['Gender'] : null,
|
||||||
"PlaceOfBirth" => $input['PlaceOfBirth'] ?? null,
|
"PlaceOfBirth" => $input['PlaceOfBirth'] ?? null,
|
||||||
"Birthdate" => $input['Birthdate'] ?? null,
|
"Birthdate" => $input['Birthdate'] ?: null,
|
||||||
"Street_1" => $input['Street_1'] ?? null,
|
"Street_1" => $input['Street_1'] ?? null,
|
||||||
"Street_2" => $input['Street_2'] ?? null,
|
"Street_2" => $input['Street_2'] ?? null,
|
||||||
"Street_3" => null,
|
"Street_3" => $input['Street_3'] ?? null,
|
||||||
"City" => $input['City'] ?? null,
|
"City" => $input['City'] ?? null,
|
||||||
"Province" => $input['Province'] ?? null,
|
"Province" => $input['Province'] ?? null,
|
||||||
"ZIP" => $input['ZIP'] ?? null,
|
"ZIP" => $input['ZIP'] ?? null,
|
||||||
"CountryID" => isset($input['CountryID']) ? (int) $input['CountryID'] : null,
|
|
||||||
"EmailAddress1" => $input['EmailAddress1'] ?? null,
|
"EmailAddress1" => $input['EmailAddress1'] ?? null,
|
||||||
"EmailAddress2" => $input['EmailAddress2'] ?? null,
|
"EmailAddress2" => $input['EmailAddress2'] ?? null,
|
||||||
"Phone" => $input['Phone'] ?? null,
|
"Phone" => $input['Phone'] ?? null,
|
||||||
"MobilePhone" => $input['MobilePhone'] ?? null,
|
"MobilePhone" => $input['MobilePhone'] ?? null,
|
||||||
"Mother" => $input['Mother'] ?? null,
|
|
||||||
"AccountNumber" => isset($input['AccountNumber']) ? (int) $input['AccountNumber'] : null,
|
|
||||||
"RaceID" => isset($input['RaceID']) ? (int) $input['RaceID'] : null,
|
"RaceID" => isset($input['RaceID']) ? (int) $input['RaceID'] : null,
|
||||||
|
"IntCountryID" => isset($input['IntCountryID']) ? (int) $input['IntCountryID'] : null,
|
||||||
"MaritalStatus" => $input['MaritalStatus'] ?? null,
|
"MaritalStatus" => $input['MaritalStatus'] ?? null,
|
||||||
"ReligionID" => isset($input['ReligionID']) ? (int) $input['ReligionID'] : null,
|
"ReligionID" => isset($input['ReligionID']) ? (int) $input['ReligionID'] : null,
|
||||||
"EthnicID" => isset($input['EthnicID']) ? (int) $input['EthnicID'] : null,
|
"EthnicID" => isset($input['EthnicID']) ? (int) $input['EthnicID'] : null,
|
||||||
"Citizenship" => $input['Citizenship'] ?? null,
|
"Citizenship" => $input['Citizenship'] ?? null,
|
||||||
"DeathIndicator" => isset($input['DeathIndicator']) ? (int) $input['DeathIndicator'] : null,
|
"DeathIndicator" => isset($input['DeathIndicator']) ? (int) $input['DeathIndicator'] : null,
|
||||||
"DeathDateTime" => $input['DeathDateTime'] ?? null,
|
'DeathDateTime' => $input['DeathDateTime'] ?: null,
|
||||||
// "LinkTo" => $input['LinkTo'] ?? null,
|
|
||||||
"CreateDate" => date('Y-m-d H:i:s'),
|
"CreateDate" => date('Y-m-d H:i:s'),
|
||||||
"DelDate" => null,
|
"DelDate" => null,
|
||||||
|
// Linkto
|
||||||
// Field tambahan dari struktur sebelumnya (bisa dihapus jika tidak dipakai)
|
// Mother
|
||||||
// "PatientComment" => $input['PatientComment'] ?? null,
|
// AccountNumber
|
||||||
// "IdentityIDType" => $input['IdentityIDType'] ?? null,
|
|
||||||
// "IdentityID" => $input['IdentityID'] ?? null
|
|
||||||
];
|
];
|
||||||
// $data = [
|
|
||||||
// "PatientID" => $input['PatientID'] ?? null,
|
|
||||||
// "AlternatePID" => $input['AlternateID'] ?? null,
|
|
||||||
// "Prefix" => $input['Title'] ?? null,
|
|
||||||
// "NameFirst" => $input['NameFirst'] ?? null,
|
|
||||||
// "NameMiddle" => $input['NameMiddle'] ?? null,
|
|
||||||
// "NameMaiden" => $input['NameMaiden'] ?? null,
|
|
||||||
// "NameLast" => $input['NameLast'] ?? null,
|
|
||||||
// "Suffix" => $input['Suffix'] ?? null,
|
|
||||||
// "NameAlias" => null,
|
|
||||||
// "Gender" => ((int) $input['Gender']) ?? null, //int
|
|
||||||
// "PlaceOfBirth" => $input['PlaceOfBirthdate'] ?? null,
|
|
||||||
// "Birthdate" => $input['Birthdate'] ?? null,
|
|
||||||
// "Street1" => $input['Street1'] ?? null,
|
|
||||||
// "Street2" => $input['Street2'] ?? null,
|
|
||||||
// "Street3" => null,
|
|
||||||
// "City" => $input['City'] ?? null,
|
|
||||||
// "Province" => $input['Province'] ?? null,
|
|
||||||
// "ZIP" => null,
|
|
||||||
// "CountryID" => null, // int
|
|
||||||
// "EmailAddress1" => $input['Email1'] ?? null,
|
|
||||||
// "EmailAddress2" => $input['Email2'] ?? null,
|
|
||||||
// "Phone" => $input['Phone'] ?? null,
|
|
||||||
// "MobilePhone" => $input['Mobile'] ?? null,
|
|
||||||
// "Mother" => ((int) $input['Mother']) ?? null, //int
|
|
||||||
// "AccountNumber" => null, //int
|
|
||||||
// "RaceID" => ((int) $input['Race']) ?? null, //int
|
|
||||||
// "MaritalStatus" => $input['MaritalStatus'] ?? null,
|
|
||||||
// "ReligionID" => ((int) $input['Religion']) ?? null, //int
|
|
||||||
// "EthnicID" => ((int) $input['Ethnic']) ?? null, //int
|
|
||||||
// "Citizenship" => null,
|
|
||||||
// "DeathIndicator" => ((int) $input['Death']) ?? null, //int
|
|
||||||
// "DeathDateTime" => $input['DeathTime'] ?? null,
|
|
||||||
// "CreateDate" => date('Y-m-d H:i:s'),
|
|
||||||
|
|
||||||
// "LinkTo" => $input['LinkTo'] ?? null,
|
$rulesDataPatient = [
|
||||||
// "PatientComment" => $input['PatientComment'] ?? null,
|
'PatientID' => 'required|is_unique[patient.PatientID]|max_length[50]',
|
||||||
// "IdentityIDType" => $input['IdentityIDType'] ?? null,
|
'AlternatePID' => 'permit_empty|max_length[50]',
|
||||||
// "IdentityID" => $input['IdentityID'] ?? null
|
'NameFirst' => 'required|min_length[1]|max_length[255]',
|
||||||
// ];
|
'EmailAddress1' => 'required|is_unique[patient.EmailAddress1]',
|
||||||
|
'DeathIndicator' => 'required',
|
||||||
|
'Gender' => 'required'
|
||||||
|
];
|
||||||
|
|
||||||
$rules = [
|
$dataPatidt = [
|
||||||
'NameFirst' => 'required|min_length[3]|max_length[255]',
|
"IdentifierType" => $input['IdentifierType'] ?? null,
|
||||||
'NameMiddle' => 'permit_empty',
|
"Identifier" => $input['Identifier'] ?? null,
|
||||||
'NameMaiden' => 'permit_empty',
|
"CreateDate" => date('Y-m-d H:i:s'),
|
||||||
'NameLast' => 'permit_empty',
|
];
|
||||||
// 'birth_date' => 'permit_empty|valid_date[Y-m-d]|not_in_list[0000-00-00]',
|
|
||||||
'AlternatePID' => 'permit_empty|max_length[50]',
|
$rulesDataPatidt = [
|
||||||
'Street_1' => 'permit_empty',
|
'Identifier' => 'required|is_unique[patidt.Identifier]',
|
||||||
'Street_2' => 'permit_empty',
|
|
||||||
'Street_3' => 'permit_empty',
|
|
||||||
'City' => 'permit_empty',
|
|
||||||
];
|
];
|
||||||
|
|
||||||
$existingPatient = $this->db->table('patient')->where('InternalPID', $InternalPID)->get()->getRowArray();
|
$existingPatient = $this->db->table('patient')->where('InternalPID', $InternalPID)->get()->getRowArray();
|
||||||
@ -342,7 +311,7 @@ class Patient extends Controller {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 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($dataPatient, $rules)) {
|
||||||
return $this->failValidationErrors($this->validator->getErrors());
|
return $this->failValidationErrors($this->validator->getErrors());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -355,22 +324,22 @@ class Patient extends Controller {
|
|||||||
|
|
||||||
$datas = [];
|
$datas = [];
|
||||||
foreach ($allowedUpdateFields as $field) {
|
foreach ($allowedUpdateFields as $field) {
|
||||||
if (isset($data[$field])) {
|
if (isset($dataPatient[$field])) {
|
||||||
$datas[$field] = $data[$field];
|
$datas[$field] = $dataPatient[$field];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (empty($data)) {
|
if (empty($dataPatient)) {
|
||||||
return $this->failValidationError('No data provided for update.');
|
return $this->failValidationError('No data provided for update.');
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->db->table('patient')->where('InternalPID', $InternalPID)->update($data);
|
$this->db->table('patient')->where('InternalPID', $InternalPID)->update($dataPatient);
|
||||||
|
|
||||||
// Sukses & Insert = 201 - Kirim data patient ID
|
// Sukses & Insert = 201 - Kirim data patient ID
|
||||||
return $this->respondCreated([
|
return $this->respondCreated([
|
||||||
'status' => 'success',
|
'status' => 'success',
|
||||||
'message' => 'Patient updated successfully',
|
'message' => 'Patient updated successfully',
|
||||||
'data' => $data
|
'data' => $dataPatient
|
||||||
], 201);
|
], 201);
|
||||||
|
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user