feat(patvisit): enrich AttDoc fields in patient visit response
Add AttDocFirstName, AttDocLastName, and AttDocContactCode to showByPatient via joins to contact and site-scoped contactdetail. Keep existing AttDoc ID field unchanged for backward compatibility. Update PatientVisit OpenAPI schema, regenerate bundled docs, and extend PatVisitByPatientTest assertions for new fields.
This commit is contained in:
parent
4aad7d331a
commit
2053ab4596
@ -30,7 +30,7 @@ class PatVisitModel extends BaseModel {
|
||||
}
|
||||
|
||||
public function showByPatient($InternalPID) {
|
||||
$rows = $this->select("*, patvisit.InternalPID, patvisit.CreateDate as PVCreateDate, patdiag.CreateDate as PDCreateDate, patvisitadt.CreateDate as PVACreateDate")
|
||||
$rows = $this->select("*, patvisit.InternalPID, patvisit.CreateDate as PVCreateDate, patdiag.CreateDate as PDCreateDate, patvisitadt.CreateDate as PVACreateDate, attDoc.NameFirst as AttDocFirstName, attDoc.NameLast as AttDocLastName, attDocDetail.ContactCode as AttDocContactCode")
|
||||
->join('patdiag', 'patdiag.InternalPVID=patvisit.InternalPVID and patdiag.DelDate is null', 'left')
|
||||
->join('(SELECT a1.*
|
||||
FROM patvisitadt a1
|
||||
@ -43,6 +43,8 @@ class PatVisitModel extends BaseModel {
|
||||
'patvisitadt.InternalPVID = patvisit.InternalPVID',
|
||||
'left')
|
||||
->join('location', 'location.LocationID=patvisitadt.LocationID', 'left')
|
||||
->join('contact attDoc', 'attDoc.ContactID = patvisitadt.AttDoc', 'left')
|
||||
->join('contactdetail attDocDetail', 'attDocDetail.ContactID = attDoc.ContactID AND attDocDetail.SiteID = patvisit.SiteID', 'left')
|
||||
->where('patvisit.InternalPID',$InternalPID)
|
||||
->where('patvisit.EndDate IS NULL') // Exclude soft deleted
|
||||
->findAll();
|
||||
@ -107,27 +109,27 @@ class PatVisitModel extends BaseModel {
|
||||
throw new \Exception("Visit not found or has been deleted.");
|
||||
}
|
||||
|
||||
$visitData = array_intersect_key($input, array_flip($this->allowedFields));
|
||||
if (!empty($visitData)) {
|
||||
$this->where('InternalPVID', $InternalPVID)->set($visitData)->update();
|
||||
}
|
||||
|
||||
// patdiag
|
||||
if (array_key_exists('PatDiag', $input)) {
|
||||
$exist = $modelPD->where('InternalPVID', $InternalPVID)->find();
|
||||
if ($exist) {
|
||||
if (!empty($input['PatDiag']) && (!empty($input['PatDiag']['DiagCode']) || !empty($input['PatDiag']['Diagnosis']))) {
|
||||
$tmp = $modelPD->where('InternalPVID', $InternalPVID)->set($input['PatDiag'])->update();
|
||||
} else {
|
||||
$tmp = $modelPD->delete($InternalPVID);
|
||||
}
|
||||
} else {
|
||||
if (!empty($input['PatDiag']) && (!empty($input['PatDiag']['DiagCode']) || !empty($input['PatDiag']['Diagnosis']))) {
|
||||
$input['PatDiag']['InternalPVID'] = $InternalPVID;
|
||||
$tmp = $modelPD->insert($input['PatDiag']);
|
||||
}
|
||||
}
|
||||
}
|
||||
$visitData = array_intersect_key($input, array_flip($this->allowedFields));
|
||||
if (!empty($visitData)) {
|
||||
$this->where('InternalPVID', $InternalPVID)->set($visitData)->update();
|
||||
}
|
||||
|
||||
// patdiag
|
||||
if (array_key_exists('PatDiag', $input)) {
|
||||
$exist = $modelPD->where('InternalPVID', $InternalPVID)->find();
|
||||
if ($exist) {
|
||||
if (!empty($input['PatDiag']) && (!empty($input['PatDiag']['DiagCode']) || !empty($input['PatDiag']['Diagnosis']))) {
|
||||
$tmp = $modelPD->where('InternalPVID', $InternalPVID)->set($input['PatDiag'])->update();
|
||||
} else {
|
||||
$tmp = $modelPD->delete($InternalPVID);
|
||||
}
|
||||
} else {
|
||||
if (!empty($input['PatDiag']) && (!empty($input['PatDiag']['DiagCode']) || !empty($input['PatDiag']['Diagnosis']))) {
|
||||
$input['PatDiag']['InternalPVID'] = $InternalPVID;
|
||||
$tmp = $modelPD->insert($input['PatDiag']);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (isset($tmp) && $tmp === false) {
|
||||
$error = $db->error();
|
||||
throw new \Exception("Failed to update PatDiag record. ". $error['message']);
|
||||
@ -148,9 +150,9 @@ class PatVisitModel extends BaseModel {
|
||||
return false;
|
||||
} else {
|
||||
$db->transCommit();
|
||||
$data = [ "PVID" => $input['PVID'] ?? $visit['PVID'], "InternalPVID" => $InternalPVID ];
|
||||
return $data;
|
||||
}
|
||||
$data = [ "PVID" => $input['PVID'] ?? $visit['PVID'], "InternalPVID" => $InternalPVID ];
|
||||
return $data;
|
||||
}
|
||||
|
||||
} catch (\Exception $e) {
|
||||
$this->db->transRollback();
|
||||
|
||||
@ -6734,6 +6734,18 @@ components:
|
||||
LastLocation:
|
||||
type: string
|
||||
description: Full name of the last/current location from patvisitadt
|
||||
AttDocFirstName:
|
||||
type: string
|
||||
nullable: true
|
||||
description: Attending doctor first name (from contact)
|
||||
AttDocLastName:
|
||||
type: string
|
||||
nullable: true
|
||||
description: Attending doctor last name (from contact)
|
||||
AttDocContactCode:
|
||||
type: string
|
||||
nullable: true
|
||||
description: Attending doctor contact code for visit SiteID (from contactdetail)
|
||||
CreateDate:
|
||||
type: string
|
||||
format: date-time
|
||||
|
||||
@ -19,6 +19,18 @@ PatientVisit:
|
||||
LastLocation:
|
||||
type: string
|
||||
description: Full name of the last/current location from patvisitadt
|
||||
AttDocFirstName:
|
||||
type: string
|
||||
nullable: true
|
||||
description: Attending doctor first name (from contact)
|
||||
AttDocLastName:
|
||||
type: string
|
||||
nullable: true
|
||||
description: Attending doctor last name (from contact)
|
||||
AttDocContactCode:
|
||||
type: string
|
||||
nullable: true
|
||||
description: Attending doctor contact code for visit SiteID (from contactdetail)
|
||||
CreateDate:
|
||||
type: string
|
||||
format: date-time
|
||||
|
||||
@ -5,16 +5,16 @@ namespace Tests\Feature\PatVisit;
|
||||
use CodeIgniter\Test\FeatureTestTrait;
|
||||
use CodeIgniter\Test\CIUnitTestCase;
|
||||
|
||||
class PatVisitByPatientTest extends CIUnitTestCase
|
||||
{
|
||||
use FeatureTestTrait;
|
||||
|
||||
protected $endpoint = 'api/patvisit/patient';
|
||||
|
||||
class PatVisitByPatientTest extends CIUnitTestCase
|
||||
{
|
||||
use FeatureTestTrait;
|
||||
|
||||
protected $endpoint = 'api/patvisit/patient';
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test: Show all visits by valid InternalPID
|
||||
@ -37,6 +37,13 @@ class PatVisitByPatientTest extends CIUnitTestCase
|
||||
// Pastikan 'data' ada
|
||||
$this->assertArrayHasKey('data', $json);
|
||||
$this->assertIsArray($json['data']);
|
||||
|
||||
if (!empty($json['data'])) {
|
||||
$this->assertArrayHasKey('AttDoc', $json['data'][0]);
|
||||
$this->assertArrayHasKey('AttDocFirstName', $json['data'][0]);
|
||||
$this->assertArrayHasKey('AttDocLastName', $json['data'][0]);
|
||||
$this->assertArrayHasKey('AttDocContactCode', $json['data'][0]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user