fix contact creation wo detail

This commit is contained in:
mahdahar 2025-09-26 15:03:11 +07:00
parent c73d09fe52
commit e15a2d98db
6 changed files with 26 additions and 39 deletions

View File

@ -94,7 +94,6 @@ class Contact extends Controller {
$db->transStart(); $db->transStart();
try { try {
if (!empty($input['ContactID'])) { if (!empty($input['ContactID'])) {
$ContactID = $input['ContactID']; $ContactID = $input['ContactID'];
if (!$contactModel->update($ContactID, $input)) { throw new \RuntimeException('Failed to update contact'); } if (!$contactModel->update($ContactID, $input)) { throw new \RuntimeException('Failed to update contact'); }
@ -103,12 +102,12 @@ class Contact extends Controller {
if (!$ContactID) { throw new \RuntimeException('Failed to insert contact'); } if (!$ContactID) { throw new \RuntimeException('Failed to insert contact'); }
} }
if(isset($input['Details'])) {
$result = $detailModel->syncDetails($ContactID, $input['Details']); $result = $detailModel->syncDetails($ContactID, $input['Details']);
if ($result['status'] !== 'success') { if ($result['status'] !== 'success') {
throw new \RuntimeException('Failed to sync details: ' . $result['message']); throw new \RuntimeException('Failed to sync details: ' . $result['message']);
}
} }
$db->transComplete(); $db->transComplete();

View File

@ -21,8 +21,8 @@ class PatVisit extends Controller {
public function show($PVID = null) { public function show($PVID = null) {
try { try {
$row = new PatVisitModel()->show($PVID); $model = new PatVisitModel();
$row = $model->show($PVID);
return $this->respond([ return $this->respond([
'status' => 'success', 'status' => 'success',
'message'=> "data found", 'message'=> "data found",
@ -35,11 +35,8 @@ class PatVisit extends Controller {
public function showByPatient($InternalPID = null) { public function showByPatient($InternalPID = null) {
try { try {
$row = $this->db->table('patvisit pv') $model = new PatVisitModel();
->join('patdiag pd', 'pd.InternalPVID=pv.InternalPVID', 'left') $row = $model->showByPatient($InternalPID);
->join('patvisitadt pva', 'pd.InternalPVID=pva.InternalPVID', 'left')
->get()->getResultArray();
return $this->respond([ return $this->respond([
'status' => 'success', 'status' => 'success',
'message'=> "data found", 'message'=> "data found",
@ -51,8 +48,9 @@ class PatVisit extends Controller {
} }
public function update() { public function update() {
$input = $this->request->getJSON(true);
try { try {
$input = $this->request->getJSON(true);
if (!$input) { return $this->respond(['status' => 'error', 'message' => 'Invalid JSON input'], 400); } if (!$input) { return $this->respond(['status' => 'error', 'message' => 'Invalid JSON input'], 400); }
if (!$input["InternalPVID"] || !is_numeric($input["InternalPVID"])) { return $this->respond(['status' => 'error', 'message' => 'Invalid or missing ID'], 400); } if (!$input["InternalPVID"] || !is_numeric($input["InternalPVID"])) { return $this->respond(['status' => 'error', 'message' => 'Invalid or missing ID'], 400); }
@ -94,7 +92,7 @@ class PatVisit extends Controller {
if($input['PVID'] =='' || !isset($input['PVID'])) { if($input['PVID'] =='' || !isset($input['PVID'])) {
$model = new CounterModel(); $model = new CounterModel();
$input['PVID'] = $this->visnum_prefix .$model->use(2); $input['PVID'] = $this->visnum_prefix .$model->use(2);
//$input['PVID'] = $this->preparePVID(); //$input['PVID'] = $this->preparePVID();
} }

View File

@ -21,9 +21,9 @@ class CreateContactTable extends Migration {
'MobilePhone2' => [ 'type' => 'VARCHAR', 'constraint' => 50, 'null' => true ], 'MobilePhone2' => [ 'type' => 'VARCHAR', 'constraint' => 50, 'null' => true ],
'Specialty' => [ 'type' => 'VARCHAR', 'constraint' => 100, 'null' => true ], 'Specialty' => [ 'type' => 'VARCHAR', 'constraint' => 100, 'null' => true ],
'SubSpecialty' => [ 'type' => 'VARCHAR', 'constraint' => 100, 'null' => true ], 'SubSpecialty' => [ 'type' => 'VARCHAR', 'constraint' => 100, 'null' => true ],
'CreateDate DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP',
'EndDate' => [ 'type' => 'DATETIME', 'null' => true ], 'EndDate' => [ 'type' => 'DATETIME', 'null' => true ],
]); ]);
$this->forge->addField('CreateDate DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP');
$this->forge->addKey('ContactID', true); $this->forge->addKey('ContactID', true);
$this->forge->createTable('contact'); $this->forge->createTable('contact');
@ -38,7 +38,7 @@ class CreateContactTable extends Migration {
'JobTitle' => [ 'type' => 'VARCHAR', 'constraint' => 100, 'null' => true ], 'JobTitle' => [ 'type' => 'VARCHAR', 'constraint' => 100, 'null' => true ],
'Department' => [ 'type' => 'VARCHAR', 'constraint' => 100, 'null' => true ], 'Department' => [ 'type' => 'VARCHAR', 'constraint' => 100, 'null' => true ],
'ContactStartDate' => [ 'type' => 'DATETIME', 'null' => true ], 'ContactStartDate' => [ 'type' => 'DATETIME', 'null' => true ],
'ContactEndDate' => [ 'type' => 'DATETIME', 'null' => true ], 'ContactEndDate' => [ 'type' => 'DATETIME ', 'null' => true ],
]); ]);
$this->forge->addKey('ContactDetID', true); $this->forge->addKey('ContactDetID', true);
$this->forge->addUniqueKey(['SiteID','ContactID']); $this->forge->addUniqueKey(['SiteID','ContactID']);

View File

@ -15,25 +15,17 @@ class PatVisitModel extends Model {
protected $deletedField = 'EndDate'; protected $deletedField = 'EndDate';
public function show($PVID) { public function show($PVID) {
$rows = $this->join('patdiag pd', 'pd.InternalPVID=pv.InternalPVID', 'left') $rows = $this->join('patdiag pd', 'pd.InternalPVID=patvisit.InternalPVID', 'left')
->join('patvisitadt pva', 'pd.InternalPVID=pva.InternalPVID', 'left') ->join('patvisitadt pva', 'pva.InternalPVID=patvisit.InternalPVID', 'left')
->where('PVID',$PVID)->get()->getResultArray(); ->where('patvisit.PVID',$PVID)->get()->getResultArray();
return $rows; return $rows;
} }
public function use($CounterID) { public function showByPatient($InternalPID) {
$row = $this->where('CounterID',$CounterID)->get()->getResultArray(); $rows = $this->join('patdiag pd', 'pd.InternalPVID=patvisit.InternalPVID', 'left')
$cValue = $row[0]['CounterValue']; ->join('patvisitadt pva', 'pd.InternalPVID=pva.InternalPVID', 'left')
$cStart = $row[0]['CounterStart']; ->where('patvisit.InternalPID',$InternalPID)->get()->getResultArray();
$cEnd = $row[0]['CounterEnd']; return $rows;
$cReset = $row[0]['CounterReset'];
$cPad = strlen((string)$cEnd);
// next value > end, back to start
if($cValue > $cEnd) { $cValue = $cStart; }
$cnum = str_pad($cValue, $cPad, "0", STR_PAD_LEFT);
$cValue_next = $cValue+1;
$this->set('CounterValue', $cValue_next)->where('CounterID',$CounterID)->update();
return $cnum;
} }
} }

View File

@ -56,9 +56,9 @@
<const name="PUBLICPATH" value="./public/"/> <const name="PUBLICPATH" value="./public/"/>
<!-- Database configuration --> <!-- Database configuration -->
<env name="database.tests.hostname" value="localhost"/> <env name="database.tests.hostname" value="localhost"/>
<env name="database.tests.database" value="clqm01"/> <env name="database.tests.database" value="clqms01"/>
<env name="database.tests.username" value="root"/> <env name="database.tests.username" value="root"/>
<env name="database.tests.password" value=""/> <env name="database.tests.password" value="adminsakti"/>
<env name="database.tests.DBDriver" value="MySQLi"/> <env name="database.tests.DBDriver" value="MySQLi"/>
<!-- <env name="database.tests.DBPrefix" value="tests_"/> --> <!-- <env name="database.tests.DBPrefix" value="tests_"/> -->
</php> </php>

View File

@ -10,8 +10,7 @@ class PatientCreateTest extends CIUnitTestCase
use FeatureTestTrait; use FeatureTestTrait;
protected $endpoint = 'api/patient'; protected $endpoint = 'api/patient';
public function testCreatePatientValidationFail() public function testCreatePatientValidationFail() {
{
// error 400 yg diharapkan // error 400 yg diharapkan
$payload = ['Name' => 'Ngawur']; $payload = ['Name' => 'Ngawur'];
$result = $this->withBodyFormat('json') $result = $this->withBodyFormat('json')
@ -45,8 +44,7 @@ class PatientCreateTest extends CIUnitTestCase
} }
// Wajib Diganti ya payloadnya kalau mau dijalankan // Wajib Diganti ya payloadnya kalau mau dijalankan
public function testCreatePatientSuccess() public function testCreatePatientSuccess() {
{
$payload = [ $payload = [
"PatientID"=> "SMAJ6", //Wajib Ganti "PatientID"=> "SMAJ6", //Wajib Ganti
"AlternatePID"=> "P0234", "AlternatePID"=> "P0234",