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;
|
2026-03-16 07:24:50 +07:00
|
|
|
|
2026-03-16 15:58:56 +07:00
|
|
|
class PatVisitDeleteTest 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: Delete patient visit successfully (soft delete)
|
|
|
|
|
*/
|
|
|
|
|
public function testDeletePatientVisitSuccess()
|
|
|
|
|
{
|
|
|
|
|
// Create a visit first to delete
|
2026-03-16 15:58:56 +07:00
|
|
|
$createPayload = [
|
|
|
|
|
"InternalPID"=> $this->createTestPatient(),
|
2026-03-16 07:24:50 +07:00
|
|
|
"EpisodeID"=> "TEST001",
|
|
|
|
|
"PatVisitADT"=> [
|
|
|
|
|
"ADTCode"=> "A01",
|
|
|
|
|
"LocationID"=> "1"
|
|
|
|
|
]
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
$createResponse = $this->withBodyFormat('json')->call('post', $this->endpoint, $createPayload);
|
|
|
|
|
$createResponse->assertStatus(201);
|
|
|
|
|
|
|
|
|
|
$json = json_decode($createResponse->getJSON(), true);
|
|
|
|
|
$internalPVID = $json['data']['InternalPVID'];
|
|
|
|
|
|
|
|
|
|
// Now delete it
|
|
|
|
|
$deletePayload = [
|
|
|
|
|
'InternalPVID' => $internalPVID
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
$response = $this->withBodyFormat('json')->call('delete', $this->endpoint, $deletePayload);
|
|
|
|
|
|
|
|
|
|
$response->assertStatus(200);
|
|
|
|
|
$response->assertJSONFragment([
|
|
|
|
|
'status' => 'success',
|
|
|
|
|
'message' => 'Data deleted successfully'
|
|
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Test: Delete patient visit with missing ID
|
|
|
|
|
*/
|
|
|
|
|
public function testDeletePatientVisitMissingId()
|
|
|
|
|
{
|
|
|
|
|
$payload = [];
|
|
|
|
|
|
|
|
|
|
$response = $this->withBodyFormat('json')->call('delete', $this->endpoint, $payload);
|
|
|
|
|
$response->assertStatus(400);
|
|
|
|
|
$response->assertJSONFragment([
|
|
|
|
|
'status' => 'error',
|
|
|
|
|
'message' => 'Invalid or missing ID'
|
|
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Test: Delete patient visit with invalid ID (non-numeric)
|
|
|
|
|
*/
|
|
|
|
|
public function testDeletePatientVisitInvalidId()
|
|
|
|
|
{
|
|
|
|
|
$payload = [
|
|
|
|
|
'InternalPVID' => 'invalid'
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
$response = $this->withBodyFormat('json')->call('delete', $this->endpoint, $payload);
|
|
|
|
|
$response->assertStatus(400);
|
|
|
|
|
$response->assertJSONFragment([
|
|
|
|
|
'status' => 'error',
|
|
|
|
|
'message' => 'Invalid or missing ID'
|
|
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Test: Delete patient visit with non-existent ID
|
|
|
|
|
*/
|
|
|
|
|
public function testDeletePatientVisitNotFound()
|
|
|
|
|
{
|
|
|
|
|
$payload = [
|
|
|
|
|
'InternalPVID' => 999999 // Non-existent visit
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
$response = $this->withBodyFormat('json')->call('delete', $this->endpoint, $payload);
|
|
|
|
|
$response->assertStatus(404);
|
|
|
|
|
$response->assertJSONFragment([
|
|
|
|
|
'status' => 'error',
|
|
|
|
|
'message' => 'Visit not found'
|
|
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|