fix pvadt

This commit is contained in:
mahdahar 2025-10-27 10:37:44 +07:00
parent d5c8cac5ec
commit d4c92af9e4

View File

@ -104,21 +104,17 @@ class PatVisitModel extends BaseModel {
throw new \Exception("Failed to update PatDiag record. ". $error['message']); throw new \Exception("Failed to update PatDiag record. ". $error['message']);
} }
// patvisitadt if(!empty($input['PatVisitADT'])) {
$exist = $modelPVA->where('InternalPVID',$InternalPVID)->find(); $adtList = $input['PatVisitADT'];
if($exist) { usort($adtList, fn($a, $b) => $a['sequence'] <=> $b['sequence']);
if(!empty($input['PatVisitADT'])) { foreach ($adtList as $adt) {
$tmp = $modelPVA->where('InternalPVID',$InternalPVID)->set($input['PatVisitADT'])->update(); $adt['InternalPVID'] = $InternalPVID;
} else { $tmp = $modelPVA->where('InternalPVID',$InternalPVID)->delete(); } $tmp = $modelPVA->insert($adt);
} else { if ($tmp === false) {
if(!empty($input['PatVisitADT'])) { $error = $db->error();
$input['PatVisitADT']['InternalPVID'] = $InternalPVID; throw new \Exception("Failed to update PatVisitADT record. ". $error['message']);
$tmp = $modelPVA->insert($input['PatVisitADT']); }
} }
}
if ($tmp === false) {
$error = $db->error();
throw new \Exception("Failed to update PatVisitADT record. ". $error['message']);
} }
if ($db->transStatus() === FALSE) { if ($db->transStatus() === FALSE) {