(C) Moorfields Eye Hospital NHS Foundation Trust, 2008-2011 (C) OpenEyes Foundation, 2011-2013 This file is part of OpenEyes. OpenEyes is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. OpenEyes is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenEyes in a file titled COPYING. If not, see .
저자: OpenEyes (info@openeyes.org.uk)
 /**
  * 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']));
 }
예제 #2
0
 public function testUpdateSystemicDiagnoses()
 {
     $mergeHandler = new PatientMerge();
     $primaryPatient = $this->patients('patient7');
     $secondaryPatient = $this->patients('patient8');
     $secondaryDiagnoses8 = $this->secondary_diagnosis('secondaryDiagnoses8');
     $secondaryDiagnoses8->patient_id = 8;
     $secondaryDiagnoses8->disorder_id = 5;
     $secondaryDiagnoses8->save();
     $secondaryDiagnoses8->refresh();
     // Befor we update the Ophthalmic Diagnoses we check if the patient id is equals to the secondary patient id
     $this->assertEquals(8, $secondaryDiagnoses8->patient_id);
     $this->assertEquals(5, $secondaryDiagnoses8->disorder_id);
     $secondaryPatient->refresh();
     $this->assertTrue(is_array($secondaryPatient->systemicDiagnoses));
     $this->assertEquals(1, count($secondaryPatient->systemicDiagnoses));
     $mergeHandler->updateOphthalmicDiagnoses($primaryPatient, $secondaryPatient->systemicDiagnoses);
     $secondaryDiagnoses8->refresh();
     $this->assertEquals(7, $secondaryDiagnoses8->patient_id);
     $this->assertEquals(0, count($secondaryPatient->systemicDiagnoses));
     $this->assertEquals(1, count($primaryPatient->systemicDiagnoses));
 }