fix pvadt

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

View File

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