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();
try {
if (!empty($input['ContactID'])) {
$ContactID = $input['ContactID'];
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'); }
}
$result = $detailModel->syncDetails($ContactID, $input['Details']);
if ($result['status'] !== 'success') {
throw new \RuntimeException('Failed to sync details: ' . $result['message']);
if(isset($input['Details'])) {
$result = $detailModel->syncDetails($ContactID, $input['Details']);
if ($result['status'] !== 'success') {
throw new \RuntimeException('Failed to sync details: ' . $result['message']);
}
}
$db->transComplete();

View File

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

View File

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

View File

@ -15,25 +15,17 @@ class PatVisitModel extends Model {
protected $deletedField = 'EndDate';
public function show($PVID) {
$rows = $this->join('patdiag pd', 'pd.InternalPVID=pv.InternalPVID', 'left')
->join('patvisitadt pva', 'pd.InternalPVID=pva.InternalPVID', 'left')
->where('PVID',$PVID)->get()->getResultArray();
$rows = $this->join('patdiag pd', 'pd.InternalPVID=patvisit.InternalPVID', 'left')
->join('patvisitadt pva', 'pva.InternalPVID=patvisit.InternalPVID', 'left')
->where('patvisit.PVID',$PVID)->get()->getResultArray();
return $rows;
}
public function use($CounterID) {
$row = $this->where('CounterID',$CounterID)->get()->getResultArray();
$cValue = $row[0]['CounterValue'];
$cStart = $row[0]['CounterStart'];
$cEnd = $row[0]['CounterEnd'];
$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;
public function showByPatient($InternalPID) {
$rows = $this->join('patdiag pd', 'pd.InternalPVID=patvisit.InternalPVID', 'left')
->join('patvisitadt pva', 'pd.InternalPVID=pva.InternalPVID', 'left')
->where('patvisit.InternalPID',$InternalPID)->get()->getResultArray();
return $rows;
}
}

View File

@ -56,9 +56,9 @@
<const name="PUBLICPATH" value="./public/"/>
<!-- Database configuration -->
<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.password" value=""/>
<env name="database.tests.password" value="adminsakti"/>
<env name="database.tests.DBDriver" value="MySQLi"/>
<!-- <env name="database.tests.DBPrefix" value="tests_"/> -->
</php>

View File

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