fix patvisit
This commit is contained in:
parent
bf5b5cb0ea
commit
2df524c890
@ -6,7 +6,7 @@ use App\Models\BaseModel;
|
||||
class PatDiagModel extends BaseModel {
|
||||
protected $table = 'patdiag';
|
||||
protected $primaryKey = 'InternalPVID';
|
||||
protected $allowedFields = ['InternalPID', 'DiagCode', 'Diagnosis', 'CreateDate', 'EndDate', 'ArchivedDate', 'DelDate'];
|
||||
protected $allowedFields = ['InternalPVID','InternalPID', 'DiagCode', 'Diagnosis', 'CreateDate', 'EndDate', 'ArchivedDate', 'DelDate'];
|
||||
protected $visnum_prefix;
|
||||
|
||||
protected $useTimestamps = true;
|
||||
|
||||
@ -21,7 +21,7 @@ class PatVisitModel extends BaseModel {
|
||||
|
||||
public function show($PVID) {
|
||||
$rows = $this->select("*, patvisit.CreateDate as PVCreateDate, patdiag.CreateDate as PDCreateDate, patvisitadt.CreateDate as PVACreateDate")
|
||||
->join('patdiag', 'patdiag.InternalPVID=patvisit.InternalPVID', 'left')
|
||||
->join('patdiag', 'patdiag.InternalPVID=patvisit.InternalPVID and patdiag.DelDate is null', 'left')
|
||||
->join('patvisitadt', 'patvisitadt.InternalPVID=patvisit.InternalPVID', 'left')
|
||||
->where('patvisit.PVID',$PVID)->findAll();
|
||||
return $rows;
|
||||
@ -29,7 +29,7 @@ class PatVisitModel extends BaseModel {
|
||||
|
||||
public function showByPatient($InternalPID) {
|
||||
$rows = $this->select("*, patvisit.CreateDate as PVCreateDate, patdiag.CreateDate as PDCreateDate, patvisitadt.CreateDate as PVACreateDate")
|
||||
->join('patdiag', 'patdiag.InternalPVID=patvisit.InternalPVID', 'left')
|
||||
->join('patdiag', 'patdiag.InternalPVID=patvisit.InternalPVID and patdiag.DelDate is null', 'left')
|
||||
->join('patvisitadt', 'patvisitadt.InternalPVID=patvisit.InternalPVID', 'left')
|
||||
->join('location', 'location.LocationID=patvisitadt.LocationID', 'left')
|
||||
->where('patvisit.InternalPID',$InternalPID)->findAll();
|
||||
@ -37,75 +37,99 @@ class PatVisitModel extends BaseModel {
|
||||
}
|
||||
|
||||
public function createPatVisit($input) {
|
||||
$db = \Config\Database::connect();
|
||||
$db = $this->db;
|
||||
$modelPD = new PatDiagModel();
|
||||
$modelPVA = new PatVisitADTModel();
|
||||
$db->transBegin();
|
||||
try{
|
||||
$db->transStart();
|
||||
|
||||
if (!isset($input['PVID']) || $input['PVID']=='') {
|
||||
$modelCounter = new CounterModel();
|
||||
$input['PVID'] = $this->visnum_prefix .$modelCounter->use(2);
|
||||
}
|
||||
|
||||
$InternalPVID = $this->insert($input, true);
|
||||
|
||||
if(!empty($input['PatDiag'])) {
|
||||
if($InternalPVID === false) { throw new \Exception("Failed to insert main PatVisit record."); }
|
||||
if( !empty($input['PatDiag']) && ( !empty($input['PatDiag']['DiagCode']) || !empty($input['PatDiag']['Diagnosis']) ) ) {
|
||||
$input['PatDiag']['InternalPVID'] = $InternalPVID;
|
||||
//$db->table('patdiag')->insert($input['PatDiag']);
|
||||
$modelPD->insert($input['PatDiag']);
|
||||
$tmp = $modelPD->insert($input['PatDiag']);
|
||||
if ($tmp === false) { throw new \Exception("Failed to insert PatDiag record."); }
|
||||
}
|
||||
if(!empty($input['PatVisitADT'])) {
|
||||
if( !empty($input['PatVisitADT']) ) {
|
||||
$input['PatVisitADT']['InternalPVID'] = $InternalPVID;
|
||||
//$db->table('patvisitadt')->insert($input['PatVisitADT']);
|
||||
$modelPVA->insert($input['PatVisitADT']);
|
||||
$tmp = $modelPVA->insert($input['PatVisitADT']);
|
||||
if ($tmp === false) {
|
||||
throw new \Exception("Failed to insert PatVisitADT record.");
|
||||
}
|
||||
}
|
||||
|
||||
$db->transComplete();
|
||||
$data = [ "PVID"=>$input['PVID'], "InternalPVID"=>$InternalPVID ];
|
||||
return $data;
|
||||
|
||||
} catch (\Exception $e) {
|
||||
$db->transRollback();
|
||||
if ($db->transStatus() === FALSE) {
|
||||
$db->transRollback();
|
||||
return false;
|
||||
} else {
|
||||
$db->transCommit();
|
||||
$data = [ "PVID" => $input['PVID'], "InternalPVID" => $InternalPVID ];
|
||||
return $data;
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
$db->transRollback();
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function updatePatVisit($input) {
|
||||
$InternalPVID = $input['InternalPVID'];
|
||||
$modelPD = new PatDiagModel();
|
||||
$modelPVA = new PatVisitADTModel();
|
||||
|
||||
$db = $this->db;
|
||||
$db->transBegin();
|
||||
try{
|
||||
$this->db->transStart();
|
||||
$this->where('InternalPVID',$InternalPVID)->set($input)->update();
|
||||
|
||||
// patdiag
|
||||
$exist = $this->db->table('patdiag')->where('InternalPVID',$InternalPVID)->get()->getRow();
|
||||
$exist = $modelPD->where('InternalPVID',$InternalPVID)->find();
|
||||
$tmp = '';
|
||||
if($exist) {
|
||||
if(!empty($input['PatDiag'])) {
|
||||
$input['PatDiag']['InternalPVID'] = $InternalPVID;
|
||||
$this->db->table('patdiag')->where('InternalPVID',$InternalPVID)->set($input['PatDiag'])->update();
|
||||
} else { $this->db->table('patdiag')->where('InternalPVID',$InternalPVID)->delete(); }
|
||||
if( !empty($input['PatDiag']) && ( !empty($input['PatDiag']['DiagCode']) || !empty($input['PatDiag']['Diagnosis']) ) ) {
|
||||
$tmp = $modelPD->where('InternalPVID',$InternalPVID)->set($input['PatDiag'])->update();
|
||||
} else { $tmp = $modelPD->delete($InternalPVID); }
|
||||
} else {
|
||||
if(!empty($input['PatDiag'])) {
|
||||
if( !empty($input['PatDiag']) && ( !empty($input['PatDiag']['DiagCode']) || !empty($input['PatDiag']['Diagnosis']) ) ) {
|
||||
$input['PatDiag']['InternalPVID'] = $InternalPVID;
|
||||
$this->db->table('patdiag')->insert($input['PatDiag']);
|
||||
$tmp = $modelPD->insert($input['PatDiag']);
|
||||
}
|
||||
}
|
||||
if ($tmp === false) {
|
||||
$error = $db->error();
|
||||
throw new \Exception("Failed to update PatDiag record. ". $error['message']);
|
||||
}
|
||||
|
||||
// patvisitadt
|
||||
$exist = $this->db->table('patvisitadt')->where('InternalPVID',$InternalPVID)->get()->getRow();
|
||||
$exist = $modelPVA->where('InternalPVID',$InternalPVID)->find();
|
||||
if($exist) {
|
||||
if(!empty($input['PatVisitADT'])) {
|
||||
$input['PatVisitADT']['InternalPVID'] = $InternalPVID;
|
||||
$this->db->table('patvisitadt')->where('InternalPVID',$InternalPVID)->set($input['PatVisitADT'])->update();
|
||||
} else { $this->db->table('patvisitadt')->where('InternalPVID',$InternalPVID)->delete(); }
|
||||
$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;
|
||||
$this->db->table('patvisitadt')->insert($input['PatVisitADT']);
|
||||
$tmp = $modelPVA->insert($input['PatVisitADT']);
|
||||
}
|
||||
}
|
||||
if ($tmp === false) {
|
||||
$error = $db->error();
|
||||
throw new \Exception("Failed to update PatVisitADT record. ". $error['message']);
|
||||
}
|
||||
|
||||
$this->db->transComplete();
|
||||
return $input['PVID'];
|
||||
if ($db->transStatus() === FALSE) {
|
||||
$db->transRollback();
|
||||
return false;
|
||||
} else {
|
||||
$db->transCommit();
|
||||
$data = [ "PVID" => $input['PVID'], "InternalPVID" => $InternalPVID ];
|
||||
return $data;
|
||||
}
|
||||
|
||||
} catch (\Exception $e) {
|
||||
$this->db->transRollback();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user