Update Perbaikan Patient Show, Create dan Update dan penambahan Seeders
This commit is contained in:
parent
ba1661ff78
commit
7844450d88
@ -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',
|
||||
'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',
|
||||
'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);
|
||||
$data = [
|
||||
[ '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);
|
||||
}
|
||||
|
||||
@ -8,7 +8,7 @@ use CodeIgniter\Database\RawSql;
|
||||
class PatientModel extends Model {
|
||||
protected $table = 'patient';
|
||||
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',
|
||||
'DeathIndicator', 'DeathDateTime', 'LinkTo' ];
|
||||
|
||||
@ -43,12 +43,19 @@ class PatientModel extends Model {
|
||||
->select("
|
||||
p.*,
|
||||
country.VDesc as Country,
|
||||
country.VID as CountryVID,
|
||||
race.VDesc as Race,
|
||||
race.VID as RaceVID,
|
||||
religion.VDesc as Religion,
|
||||
religion.VID as ReligionVID,
|
||||
ethnic.VDesc as Ethnic,
|
||||
ethnic.VID as EthnicVID,
|
||||
gender.VDesc as Gender,
|
||||
gender.VID as GenderVID,
|
||||
deathindicator.VDesc as DeathIndicator,
|
||||
deathindicator.VID as DeathIndicatorVID,
|
||||
maritalstatus.VDesc as MaritalStatus,
|
||||
maritalstatus.VID as MaritalStatusVID,
|
||||
patcom.Comment as Comment,
|
||||
patidt.IdentifierType,
|
||||
patidt.Identifier,
|
||||
@ -74,11 +81,13 @@ class PatientModel extends Model {
|
||||
unset($patient['Address']);
|
||||
unset($patient['IdentifierType']);
|
||||
unset($patient['Identifier']);
|
||||
unset($patient['Comment']);
|
||||
if (method_exists($this, 'transformPatientData')) { $patient = $this->transformPatientData($patient); }
|
||||
|
||||
// Default nested structures
|
||||
$patient['PatIdt'] = null;
|
||||
$patient['PatAtt'] = [];
|
||||
$patient['PatCom'] = [];
|
||||
|
||||
foreach ($rows as $row) {
|
||||
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']) {
|
||||
$patient['PatAtt'][] = ['Address' => $row['Address']];
|
||||
}
|
||||
@ -103,7 +116,9 @@ class PatientModel extends Model {
|
||||
$db = \Config\Database::connect();
|
||||
$patidt = $input['PatIdt'] ?? [];
|
||||
$patatt = $input['PatAtt'] ?? [];
|
||||
$patcom['Comment'] = $input['Comment'] ?? [];
|
||||
$patcom = $input['PatCom'] ?? [];
|
||||
$input['LinkTo'] = empty($input['LinkTo']) ? null : $input['LinkTo'];
|
||||
|
||||
try {
|
||||
$db->transStart();
|
||||
|
||||
@ -115,7 +130,7 @@ class PatientModel extends Model {
|
||||
$db->table('patidt')->insert($patidt);
|
||||
}
|
||||
|
||||
if (!empty($patcom['Comment'])) {
|
||||
if (!empty($patcom)) {
|
||||
$patcom['InternalPID'] = $newInternalPID;
|
||||
$db->table('patcom')->insert($patcom);
|
||||
}
|
||||
@ -145,13 +160,16 @@ class PatientModel extends Model {
|
||||
$db = \Config\Database::connect();
|
||||
$patidt = $input['PatIdt'] ?? [];
|
||||
$patatt = $input['PatAtt'] ?? [];
|
||||
$patcom['Comment'] = $input['Comment'] ?? [];
|
||||
$patcom = $input['PatCom'] ?? [];
|
||||
$input['LinkTo'] = empty($input['LinkTo']) ? null : $input['LinkTo'];
|
||||
|
||||
try {
|
||||
$db->transStart();
|
||||
$InternalPID = $input['InternalPID'];
|
||||
$this->where('InternalPID',$InternalPID)->set($input)->update();
|
||||
|
||||
$now = date('Y-m-d H:i:s');
|
||||
|
||||
if (!empty($patidt)) {
|
||||
$exists = $db->table('patidt')->where('InternalPID', $InternalPID)->get()->getRowArray();
|
||||
if ($exists) {
|
||||
@ -176,7 +194,6 @@ class PatientModel extends Model {
|
||||
$db->table('patcom')->where('InternalPID', $InternalPID)->delete();
|
||||
}
|
||||
|
||||
$now = date('Y-m-d H:i:s');
|
||||
if (!empty($patatt)) {
|
||||
// Ambil daftar address aktif (DelDate IS NULL) di DB
|
||||
$oldActive = $db->table('patatt')
|
||||
@ -250,7 +267,7 @@ class PatientModel extends Model {
|
||||
}
|
||||
|
||||
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["CreateDate"] = $this->formatedDate($patient["CreateDate"]);
|
||||
$patient["DelDate"] = $this->formatedDate($patient["DelDate"]);
|
||||
@ -287,11 +304,18 @@ class PatientModel extends Model {
|
||||
}
|
||||
|
||||
// Conversion to (Years Months Days)
|
||||
private function calculateAgeFromBirthdate($birthdate) {
|
||||
private function calculateAgeFromBirthdate($birthdate, $deathdatetime) {
|
||||
$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 = "";
|
||||
if ($diff->y > 0){
|
||||
$formattedAge .= "{$diff->y} Years ";
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user