Update Perbaikan Patient Show, Create dan Update dan penambahan Seeders

This commit is contained in:
mikael-zakaria 2025-10-03 10:46:23 +07:00
parent ba1661ff78
commit 7844450d88
2 changed files with 38 additions and 11 deletions

View File

@ -46,12 +46,15 @@ class DummySeeder extends Seeder {
[ 'InternalPID'=>1, 'PatientID'=>'SMAJ1', 'NameFirst'=>'Dummy', 'NameLast' => 'Patient M', 'Gender'=>'1', 'BirthDate'=>'1991-09-09', 'Street_1'=>'Makati', 'EmailAddress1'=>'smaj1@5panda.id', [ 'InternalPID'=>1, 'PatientID'=>'SMAJ1', 'NameFirst'=>'Dummy', 'NameLast' => 'Patient M', 'Gender'=>'1', 'BirthDate'=>'1991-09-09', 'Street_1'=>'Makati', 'EmailAddress1'=>'smaj1@5panda.id',
'Country'=>'325', 'Race'=>'175', 'Religion'=>'207', 'Ethnic'=>'218', 'DeathIndicator' => '0'], 'Country'=>'325', 'Race'=>'175', 'Religion'=>'207', 'Ethnic'=>'218', 'DeathIndicator' => '0'],
[ 'InternalPID'=>2, 'PatientID'=>'SMAJ2', 'NameFirst'=>'Dummy', 'NameLast' => 'Patient F', 'Gender'=>'2', 'BirthDate'=>'1997-02-02', 'Street_1'=>'Manila', 'EmailAddress1'=>'smaj2@5panda.id', [ 'InternalPID'=>2, 'PatientID'=>'SMAJ2', 'NameFirst'=>'Dummy', 'NameLast' => 'Patient F', 'Gender'=>'2', 'BirthDate'=>'1997-02-02', 'Street_1'=>'Manila', 'EmailAddress1'=>'smaj2@5panda.id',
'Country'=>'325', 'Race'=>'176', 'Religion'=>'206', 'Ethnic'=>'219', 'DeathIndicator' => '0'] 'Country'=>'325', 'Race'=>'176', 'Religion'=>'206', 'Ethnic'=>'219', 'DeathIndicator' => '0'],
[ 'InternalPID'=>3, 'PatientID'=>'SMAJ3', 'NameFirst'=>'Dummy', 'NameLast' => 'Patient L', 'Gender'=>'2', 'BirthDate'=>'1997-02-02', 'Street_1'=>'Manila', 'EmailAddress1'=>'smaj3@5panda.id',
'Country'=>'325', 'Race'=>'176', 'Religion'=>'206', 'Ethnic'=>'219', 'DeathIndicator' => '0']
]; ];
$this->db->table('patient')->insertBatch($data); $this->db->table('patient')->insertBatch($data);
$data = [ $data = [
[ 'InternalPID'=>1, 'IdentifierType'=>'KTP', 'Identifier'=>'9901' ], [ 'InternalPID'=>1, 'IdentifierType'=>'KTP', 'Identifier'=>'9901' ],
[ 'InternalPID'=>2, 'IdentifierType'=>'KTP', 'Identifier'=>'9902' ] [ 'InternalPID'=>2, 'IdentifierType'=>'KTP', 'Identifier'=>'9902' ],
[ 'InternalPID'=>3, 'IdentifierType'=>'KTP', 'Identifier'=>'9903' ]
]; ];
$this->db->table('patidt')->insertBatch($data); $this->db->table('patidt')->insertBatch($data);
} }

View File

@ -8,7 +8,7 @@ use CodeIgniter\Database\RawSql;
class PatientModel extends Model { class PatientModel extends Model {
protected $table = 'patient'; protected $table = 'patient';
protected $primaryKey = 'InternalPID'; protected $primaryKey = 'InternalPID';
protected $allowedFields = ['PatientID', 'AlternatePID', 'Prefix', 'NameFirst', 'NameMiddle', 'NameMaiden', 'NameLast', 'Suffix', 'NameAlias', 'Gender', 'PlaceOfBirth', 'Street_1', 'Street_2', 'Street_3', protected $allowedFields = ['PatientID', 'AlternatePID', 'Prefix', 'NameFirst', 'NameMiddle', 'NameMaiden', 'NameLast', 'Suffix', 'NameAlias', 'Gender', 'Birthdate', 'PlaceOfBirth', 'Street_1', 'Street_2', 'Street_3',
'City', 'Province', 'ZIP', 'EmailAddress1', 'EmailAddress2', 'Phone', 'MobilePhone', 'Custodian', 'AccountNumber', 'Country', 'Race', 'MaritalStatus', 'Religion', 'Ethnic', 'Citizenship', 'City', 'Province', 'ZIP', 'EmailAddress1', 'EmailAddress2', 'Phone', 'MobilePhone', 'Custodian', 'AccountNumber', 'Country', 'Race', 'MaritalStatus', 'Religion', 'Ethnic', 'Citizenship',
'DeathIndicator', 'DeathDateTime', 'LinkTo' ]; 'DeathIndicator', 'DeathDateTime', 'LinkTo' ];
@ -43,12 +43,19 @@ class PatientModel extends Model {
->select(" ->select("
p.*, p.*,
country.VDesc as Country, country.VDesc as Country,
country.VID as CountryVID,
race.VDesc as Race, race.VDesc as Race,
race.VID as RaceVID,
religion.VDesc as Religion, religion.VDesc as Religion,
religion.VID as ReligionVID,
ethnic.VDesc as Ethnic, ethnic.VDesc as Ethnic,
ethnic.VID as EthnicVID,
gender.VDesc as Gender, gender.VDesc as Gender,
gender.VID as GenderVID,
deathindicator.VDesc as DeathIndicator, deathindicator.VDesc as DeathIndicator,
deathindicator.VID as DeathIndicatorVID,
maritalstatus.VDesc as MaritalStatus, maritalstatus.VDesc as MaritalStatus,
maritalstatus.VID as MaritalStatusVID,
patcom.Comment as Comment, patcom.Comment as Comment,
patidt.IdentifierType, patidt.IdentifierType,
patidt.Identifier, patidt.Identifier,
@ -74,11 +81,13 @@ class PatientModel extends Model {
unset($patient['Address']); unset($patient['Address']);
unset($patient['IdentifierType']); unset($patient['IdentifierType']);
unset($patient['Identifier']); unset($patient['Identifier']);
unset($patient['Comment']);
if (method_exists($this, 'transformPatientData')) { $patient = $this->transformPatientData($patient); } if (method_exists($this, 'transformPatientData')) { $patient = $this->transformPatientData($patient); }
// Default nested structures // Default nested structures
$patient['PatIdt'] = null; $patient['PatIdt'] = null;
$patient['PatAtt'] = []; $patient['PatAtt'] = [];
$patient['PatCom'] = [];
foreach ($rows as $row) { foreach ($rows as $row) {
if ($row['IdentifierType'] && $row['Identifier'] && !$patient['PatIdt']) { if ($row['IdentifierType'] && $row['Identifier'] && !$patient['PatIdt']) {
@ -88,6 +97,10 @@ class PatientModel extends Model {
]; ];
} }
if ($row['Comment']) {
$patient['PatCom'][] = ['Comment' => $row['Comment']];
}
if ($row['Address']) { if ($row['Address']) {
$patient['PatAtt'][] = ['Address' => $row['Address']]; $patient['PatAtt'][] = ['Address' => $row['Address']];
} }
@ -103,7 +116,9 @@ class PatientModel extends Model {
$db = \Config\Database::connect(); $db = \Config\Database::connect();
$patidt = $input['PatIdt'] ?? []; $patidt = $input['PatIdt'] ?? [];
$patatt = $input['PatAtt'] ?? []; $patatt = $input['PatAtt'] ?? [];
$patcom['Comment'] = $input['Comment'] ?? []; $patcom = $input['PatCom'] ?? [];
$input['LinkTo'] = empty($input['LinkTo']) ? null : $input['LinkTo'];
try { try {
$db->transStart(); $db->transStart();
@ -115,7 +130,7 @@ class PatientModel extends Model {
$db->table('patidt')->insert($patidt); $db->table('patidt')->insert($patidt);
} }
if (!empty($patcom['Comment'])) { if (!empty($patcom)) {
$patcom['InternalPID'] = $newInternalPID; $patcom['InternalPID'] = $newInternalPID;
$db->table('patcom')->insert($patcom); $db->table('patcom')->insert($patcom);
} }
@ -145,13 +160,16 @@ class PatientModel extends Model {
$db = \Config\Database::connect(); $db = \Config\Database::connect();
$patidt = $input['PatIdt'] ?? []; $patidt = $input['PatIdt'] ?? [];
$patatt = $input['PatAtt'] ?? []; $patatt = $input['PatAtt'] ?? [];
$patcom['Comment'] = $input['Comment'] ?? []; $patcom = $input['PatCom'] ?? [];
$input['LinkTo'] = empty($input['LinkTo']) ? null : $input['LinkTo'];
try { try {
$db->transStart(); $db->transStart();
$InternalPID = $input['InternalPID']; $InternalPID = $input['InternalPID'];
$this->where('InternalPID',$InternalPID)->set($input)->update(); $this->where('InternalPID',$InternalPID)->set($input)->update();
$now = date('Y-m-d H:i:s');
if (!empty($patidt)) { if (!empty($patidt)) {
$exists = $db->table('patidt')->where('InternalPID', $InternalPID)->get()->getRowArray(); $exists = $db->table('patidt')->where('InternalPID', $InternalPID)->get()->getRowArray();
if ($exists) { if ($exists) {
@ -176,7 +194,6 @@ class PatientModel extends Model {
$db->table('patcom')->where('InternalPID', $InternalPID)->delete(); $db->table('patcom')->where('InternalPID', $InternalPID)->delete();
} }
$now = date('Y-m-d H:i:s');
if (!empty($patatt)) { if (!empty($patatt)) {
// Ambil daftar address aktif (DelDate IS NULL) di DB // Ambil daftar address aktif (DelDate IS NULL) di DB
$oldActive = $db->table('patatt') $oldActive = $db->table('patatt')
@ -250,7 +267,7 @@ class PatientModel extends Model {
} }
private function transformPatientData(array $patient): array { private function transformPatientData(array $patient): array {
$patient["Age"] = $this->calculateAgeFromBirthdate($patient["Birthdate"]); $patient["Age"] = $this->calculateAgeFromBirthdate($patient["Birthdate"], $patient["DeathDateTime"]);
$patient["Birthdate"] = $this->formatedDate($patient["Birthdate"]); $patient["Birthdate"] = $this->formatedDate($patient["Birthdate"]);
$patient["CreateDate"] = $this->formatedDate($patient["CreateDate"]); $patient["CreateDate"] = $this->formatedDate($patient["CreateDate"]);
$patient["DelDate"] = $this->formatedDate($patient["DelDate"]); $patient["DelDate"] = $this->formatedDate($patient["DelDate"]);
@ -287,11 +304,18 @@ class PatientModel extends Model {
} }
// Conversion to (Years Months Days) // Conversion to (Years Months Days)
private function calculateAgeFromBirthdate($birthdate) { private function calculateAgeFromBirthdate($birthdate, $deathdatetime) {
$dob = new \DateTime($birthdate); $dob = new \DateTime($birthdate);
$today = new \DateTime();
$diff = $today->diff($dob);
// Cek DeathTime
if ($deathdatetime == null) {
$today = new \DateTime();
} else {
$deathdatetime = new \DateTime($deathdatetime);
$today = $deathdatetime;
}
$diff = $today->diff($dob);
$formattedAge = ""; $formattedAge = "";
if ($diff->y > 0){ if ($diff->y > 0){
$formattedAge .= "{$diff->y} Years "; $formattedAge .= "{$diff->y} Years ";