/** * @param $patientId * @param $side * @param $element * @return array */ public function getPCRData($patientId, $side, $element) { $pcr = array(); $this->patient = \Patient::model()->findByPk((int) $patientId); $patientAge = $this->patient->getAge(); $ageGroup = 0; if ($patientAge < 60) { $ageGroup = 1; } elseif ($patientAge >= 60 && $patientAge < 70) { $ageGroup = 2; } elseif ($patientAge >= 70 && $patientAge < 80) { $ageGroup = 3; } elseif ($patientAge >= 80 && $patientAge < 90) { $ageGroup = 4; } elseif ($patientAge >= 90) { $ageGroup = 5; } $gender = ucfirst($this->patient->getGenderString()); $is_diabetic = 'N'; if ($this->patient->getDiabetes()) { $is_diabetic = 'Y'; } $is_glaucoma = 'N'; if (strpos($this->patient->getSdl(), 'glaucoma') !== false) { $is_glaucoma = 'Y'; } $risk = \PatientRiskAssignment::model()->findByAttributes(array("patient_id" => $patientId)); $user = Yii::app()->session['user']; $user_id = $user->id; if (strpos(get_class($element), 'OphTrOperationnote') !== false) { $user_id = $this->getOperationNoteSurgeonId($patientId); } $user_data = \User::model()->findByPk($user_id); $doctor_grade_id = $user_data['originalAttributes']['doctor_grade_id']; $pcr['patient_id'] = $patientId; $pcr['side'] = $side; $pcr['age_group'] = $ageGroup; $pcr['gender'] = $gender; $pcr['diabetic'] = $is_diabetic; $pcr['glaucoma'] = $is_glaucoma; $pcr['lie_flat'] = $this->getCannotLieFlat($patientId); $no_view = 'N'; $no_view_data = $this->getOpticDisc($patientId, $side); if (count($no_view_data) >= 1) { $no_view = 'Y'; } $pcr['noview'] = $no_view; $pcr['allod'] = $this->getOpticDisc($patientId, $side, true); $pcr['anteriorsegment'] = $this->getPatientAnteriorSegment($patientId, $side); $pcr['doctor_grade_id'] = $doctor_grade_id; $pcr['axial_length_group'] = $this->getAxialLength($patientId, $side); return $pcr; }
/** * adds a risk to the patient * * @param Risk $risk * @param string $other * @throws Exception */ public function addRisk(Risk $risk, $other = null, $comments = null) { if ($risk->name == 'Other') { if (!$other) { throw new Exception("No 'other' risk specified"); } } else { if (PatientRiskAssignment::model()->exists('patient_id=? and risk_id=?', array($this->id, $risk->id))) { throw new Exception("Patient is already assigned risk '{$risk->name}'"); } } $transaction = Yii::app()->db->beginTransaction(); try { $pra = new PatientRiskAssignment(); $pra->patient_id = $this->id; $pra->risk_id = $risk->id; $pra->comments = $comments; $pra->other = $other; if (!$pra->save()) { throw new Exception('Unable to add patient risk assignment: ' . print_r($pra->getErrors(), true)); } $this->audit('patient', 'add-risk'); if ($this->no_risks_date) { $this->no_risks_date = null; if (!$this->save()) { throw new Exception('Could not remove no risk flag: ' . print_r($this->getErrors(), true)); } } $this->audit('patient', 'remove-noriskdate'); $transaction->commit(); } catch (Exception $e) { $transaction->rollback(); throw $e; } }
/** * Updating Patient Risk details. * * @param type $risk_name * @param type $risk_value */ protected function updateRisk($risk_name, $risk_value) { $risk_check = $risk_name === 'anticoagulant' ? 'Anticoagulants' : 'Alpha blockers'; $risk = \Risk::model()->find('name=?', array($risk_check)); $criteria = new \CDbCriteria(); $criteria->compare('risk_id', $risk['id']); $criteria->compare('patient_id', $this->patient->id); $patient_risk = \PatientRiskAssignment::model()->find($criteria); if ($risk_value === '1') { $patient_risk = !$patient_risk ? new \PatientRiskAssignment() : $patient_risk; $patient_risk->risk_id = $risk['id']; $patient_risk->patient_id = $this->patient->id; $patient_risk->save(); } elseif ($patient_risk && $risk_value === '2') { \PatientRiskAssignment::model()->deleteByPk($patient_risk->id); } }
/** * Remove patient/allergy assignment. * * @throws Exception */ public function actionRemoveRisk() { PatientRiskAssignment::model()->deleteByPk(@$_GET['assignment_id']); echo 'success'; }