2026-03-16 07:24:50 +07:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace Tests\Feature\PatVisit;
|
|
|
|
|
|
2026-03-16 15:58:56 +07:00
|
|
|
use CodeIgniter\Test\FeatureTestTrait;
|
|
|
|
|
use CodeIgniter\Test\CIUnitTestCase;
|
|
|
|
|
use Tests\Support\Traits\CreatesPatients;
|
|
|
|
|
|
|
|
|
|
class PatVisitCreateTest extends CIUnitTestCase
|
|
|
|
|
{
|
|
|
|
|
use FeatureTestTrait;
|
|
|
|
|
use CreatesPatients;
|
|
|
|
|
|
|
|
|
|
protected $endpoint = 'api/patvisit';
|
|
|
|
|
|
|
|
|
|
protected function setUp(): void
|
|
|
|
|
{
|
|
|
|
|
parent::setUp();
|
|
|
|
|
}
|
2026-03-16 07:24:50 +07:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Test: Create patient visit with valid data
|
|
|
|
|
*/
|
|
|
|
|
public function testCreatePatientVisitSuccess()
|
|
|
|
|
{
|
2026-03-16 15:58:56 +07:00
|
|
|
$payload = [
|
|
|
|
|
"InternalPID"=> $this->createTestPatient(),
|
2026-03-16 07:24:50 +07:00
|
|
|
"EpisodeID"=> null,
|
|
|
|
|
"PatDiag"=> [
|
|
|
|
|
"DiagCode"=> null,
|
|
|
|
|
"Diagnosis"=> null
|
|
|
|
|
],
|
|
|
|
|
"PatVisitADT"=> [
|
|
|
|
|
"ADTCode"=> "A01",
|
|
|
|
|
"LocationID"=> "1",
|
|
|
|
|
"AttDoc"=> "1",
|
|
|
|
|
"RefDoc"=> "1",
|
|
|
|
|
"AdmDoc"=> "1",
|
|
|
|
|
"CnsDoc"=> "1"
|
|
|
|
|
],
|
|
|
|
|
"PatAtt"=> []
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
$response = $this->withBodyFormat('json')->call('post', $this->endpoint, $payload);
|
|
|
|
|
|
|
|
|
|
// Pastikan status 201 (created)
|
|
|
|
|
$response->assertStatus(201);
|
|
|
|
|
|
|
|
|
|
// Pastikan JSON mengandung status success dan message yang benar
|
|
|
|
|
$response->assertJSONFragment([
|
|
|
|
|
'status' => 'success',
|
|
|
|
|
'message' => 'Data created successfully'
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$json = json_decode($response->getJSON(), true);
|
|
|
|
|
|
|
|
|
|
// Pastikan struktur data yang dikembalikan benar
|
|
|
|
|
$this->assertArrayHasKey('data', $json);
|
|
|
|
|
$this->assertArrayHasKey('PVID', $json['data']);
|
|
|
|
|
$this->assertArrayHasKey('InternalPVID', $json['data']);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Test: Create patient visit with invalid (empty) data - missing InternalPID
|
|
|
|
|
*/
|
|
|
|
|
public function testCreatePatientVisitInvalidInput()
|
|
|
|
|
{
|
|
|
|
|
$payload = [];
|
|
|
|
|
// Kirim data kosong
|
|
|
|
|
$response = $this->withBodyFormat('json')->call('post', $this->endpoint, $payload);
|
|
|
|
|
|
|
|
|
|
$response->assertStatus(400);
|
|
|
|
|
$response->assertJSONFragment([
|
|
|
|
|
'status' => 'error',
|
|
|
|
|
'message' => 'InternalPID is required and must be numeric'
|
|
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Test: Create patient visit with non-existent patient
|
|
|
|
|
*/
|
|
|
|
|
public function testCreatePatientVisitPatientNotFound()
|
|
|
|
|
{
|
|
|
|
|
$payload = [
|
|
|
|
|
'InternalPID' => 999999, // Non-existent patient
|
|
|
|
|
'EpisodeID' => 'EPI001'
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
$response = $this->withBodyFormat('json')->call('post', $this->endpoint, $payload);
|
|
|
|
|
|
|
|
|
|
$response->assertStatus(404);
|
|
|
|
|
$response->assertJSONFragment([
|
|
|
|
|
'status' => 'error',
|
|
|
|
|
'message' => 'Patient not found'
|
|
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Test: Create patient visit with invalid InternalPID (non-numeric)
|
|
|
|
|
*/
|
|
|
|
|
public function testCreatePatientVisitInvalidInternalPID()
|
|
|
|
|
{
|
|
|
|
|
$payload = [
|
|
|
|
|
'InternalPID' => 'invalid',
|
|
|
|
|
'EpisodeID' => 'EPI001'
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
$response = $this->withBodyFormat('json')->call('post', $this->endpoint, $payload);
|
|
|
|
|
|
|
|
|
|
$response->assertStatus(400);
|
|
|
|
|
$response->assertJSONFragment([
|
|
|
|
|
'status' => 'error',
|
|
|
|
|
'message' => 'InternalPID is required and must be numeric'
|
|
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|