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