Compare data in the patient table.
public comparePatientDetails ( Patient $primary, Patient $secondary ) : array | ||
$primary | Patient | |
$secondary | Patient | |
Результат | array |
public function testComparePatientDetails() { $mergeHandler = new PatientMerge(); $primaryPatient = $this->patients('patient7'); $secondaryPatient = $this->patients('patient8'); $result = $mergeHandler->comparePatientDetails($primaryPatient, $secondaryPatient); $this->assertTrue(is_array($result)); $this->assertFalse($result['isConflict'], 'Personal details should be the same at this point.'); $this->assertEmpty($result['details']); // Change the dob and gender $primaryPatient->gender = 'M'; $primaryPatient->dob = '1981-12-21'; $primaryPatient->save(); $result = $mergeHandler->comparePatientDetails($primaryPatient, $secondaryPatient); $this->assertTrue($result['isConflict'], 'Personal details should NOT be the same. Both DOB and Gender are different at this point.'); $this->assertEquals($result['details'][0]['column'], 'dob'); $this->assertEquals($result['details'][0]['primary'], '1981-12-21'); $this->assertEquals($result['details'][0]['secondary'], '1977-01-01'); $this->assertEquals($result['details'][1]['column'], 'gender'); $this->assertEquals($result['details'][1]['primary'], 'M'); $this->assertEquals($result['details'][1]['secondary'], 'F'); }
/** * Merging patients. * * @param int $id the ID of the model to be displayed */ public function actionMerge($id) { $mergeRequest = $this->loadModel($id); //if the model already merged we just redirect to the index page if ($mergeRequest->status == PatientMergeRequest::STATUS_MERGED) { $this->redirect(array('index')); } $mergeHandler = new PatientMerge(); // if the personal details are conflictng (DOB and Gender at the moment) we need extra confirmation $personalDetailsConflictConfirm = $mergeHandler->comparePatientDetails($mergeRequest->primaryPatient, $mergeRequest->secondaryPatient); if ($personalDetailsConflictConfirm && $personalDetailsConflictConfirm['isConflict'] == true) { foreach ($personalDetailsConflictConfirm['details'] as $conflict) { Yii::app()->user->setFlash('warning.merge_error_' . $conflict['column'], 'Patients have different personal details : ' . $conflict['column']); } } if (isset($_POST['PatientMergeRequest']) && isset($_POST['PatientMergeRequest']['confirm']) && Yii::app()->user->checkAccess('Patient Merge')) { // if personal details are not conflictin than its fine, // but if there is a conflict we need the extra confirmation if (!$personalDetailsConflictConfirm['isConflict'] || $personalDetailsConflictConfirm['isConflict'] && isset($_POST['PatientMergeRequest']['personalDetailsConflictConfirm'])) { // Load data from PatientMergeRequest AR record $mergeHandler->load($mergeRequest); if ($mergeHandler->merge()) { $msg = 'Merge Request ' . $mergeRequest->secondaryPatient->hos_num . ' INTO ' . $mergeRequest->primaryPatient->hos_num . '(hos_num) successfully done.'; $mergeHandler->addLog($msg); $mergeRequest->status = $mergeRequest::STATUS_MERGED; $mergeRequest->merge_json = json_encode(array('log' => $mergeHandler->getLog())); $mergeRequest->save(); Audit::add('Patient Merge', $msg); $this->redirect(array('log', 'id' => $mergeRequest->id)); } else { $msg = 'Merge Request ' . $mergeRequest->secondaryPatient->hos_num . ' INTO ' . $mergeRequest->primaryPatient->hos_num . ' FAILED.'; $mergeHandler->addLog($msg); $mergeRequest->status = $mergeRequest::STATUS_CONFLICT; $mergeRequest->merge_json = json_encode(array('log' => $mergeHandler->getLog())); $mergeRequest->save(); Yii::app()->user->setFlash('warning.search_error', 'Merge failed.'); $this->redirect(array('index')); } } } $primary = Patient::model()->findByPk($mergeRequest->primary_id); $secondary = Patient::model()->findByPk($mergeRequest->secondary_id); $this->render('//patientmergerequest/merge', array('model' => $mergeRequest, 'personalDetailsConflictConfirm' => $personalDetailsConflictConfirm['isConflict'])); }