The followings are the available columns in table 'patient_allergy_assignment':
Inheritance: extends BaseEventTypeElement
Exemple #1
0
 /**
  * marks the patient as having no allergies as of now
  *
  * @throws Exception
  */
 public function setNoAllergies()
 {
     $transaction = Yii::app()->db->beginTransaction();
     try {
         foreach (PatientAllergyAssignment::model()->findAll('patient_id = ?', array($this->id)) as $paa) {
             if (!$paa->delete()) {
                 throw new Exception('Unable to delete patient allergy assignment: ' . print_r($paa->getErrors(), true));
             }
             $this->audit('patient', 'remove-allergy');
         }
         $this->no_allergies_date = date('Y-m-d H:i:s');
         if (!$this->save()) {
             throw new Exception('Unable to set no allergy date:' . print_r($this->getErrors(), true));
         }
         $this->audit('patient', 'set-noallergydate');
         $transaction->commit();
     } catch (Exception $e) {
         $transaction->rollback();
         throw $e;
     }
 }
 /**
  * Save allergies - because it's part of the History element it need to be saved from that element.
  *
  * @param $element
  * @param $data
  * @param $index
  */
 protected function saveComplexAttributes_Element_OphCiExamination_History($element, $data, $index)
 {
     $patient = \Patient::model()->findByPk($this->patient->id);
     // we remove all current allergy data
     if (!empty($data['deleted_allergies'])) {
         foreach ($data['deleted_allergies'] as $i => $assignment_id) {
             if ($assignment_id > 0) {
                 $allergyToDel = \PatientAllergyAssignment::model()->findByPk($assignment_id);
                 if ($allergyToDel) {
                     $allergyToDel->delete();
                 }
             }
         }
     }
     if (isset($data['no_allergies']) && $data['no_allergies']) {
         $patient->setNoAllergies();
     } else {
         if (!empty($data['selected_allergies'])) {
             foreach ($data['selected_allergies'] as $i => $allergy_id) {
                 $allergyObject = \Allergy::model()->findByPk($allergy_id);
                 if ($data['other_names'][$i] == 'undefined') {
                     $data['other_names'][$i] = '';
                 }
                 $patient->addAllergy($allergyObject, $data['other_names'][$i], $data['allergy_comments'][$i], false, $this->event->id);
             }
         }
     }
 }
Exemple #3
0
 /**
  * adds an allergy to the patient
  *
  * @param Allergy $allergy
  * @param string $other
  * @throws Exception
  */
 public function addAllergy(Allergy $allergy, $other = null, $comments = null, $startTransaction = true)
 {
     if ($allergy->name == 'Other') {
         if (!$other) {
             throw new Exception("No 'other' allergy specified");
         }
     } else {
         if (PatientAllergyAssignment::model()->exists('patient_id=? and allergy_id=?', array($this->id, $allergy->id))) {
             throw new Exception("Patient is already assigned allergy '{$allergy->name}'");
         }
     }
     if ($startTransaction) {
         $transaction = Yii::app()->db->beginTransaction();
     }
     try {
         $paa = new PatientAllergyAssignment();
         $paa->patient_id = $this->id;
         $paa->allergy_id = $allergy->id;
         $paa->comments = $comments;
         $paa->other = $other;
         if (!$paa->save()) {
             throw new Exception('Unable to add patient allergy assignment: ' . print_r($paa->getErrors(), true));
         }
         $this->audit('patient', 'add-allergy');
         if ($this->no_allergies_date) {
             $this->no_allergies_date = null;
             if (!$this->save()) {
                 throw new Exception('Could not remove no allergy flag: ' . print_r($this->getErrors(), true));
             }
         }
         $this->audit('patient', 'remove-noallergydate');
         if ($startTransaction) {
             $transaction->commit();
         }
     } catch (Exception $e) {
         if ($startTransaction) {
             $transaction->rollback();
         }
         throw $e;
     }
 }
 /**
  * List of allergies - changed to a wrap function to be able to use a common function from the model.
  */
 public function allergyList()
 {
     return PatientAllergyAssignment::model()->allergyList($this->patient->id);
 }