/** * Set the default options based on episode and injection status for the patient. * * (non-PHPdoc) * * @see parent::setElementOptions($action) */ protected function setElementOptions($action) { parent::setElementOptions($action); if ($action != 'create') { return; } // set any calculated defaults on the elements $therapy_api = Yii::app()->moduleAPI->get('OphCoTherapyapplication'); $injection_api = Yii::app()->moduleAPI->get('OphTrIntravitrealinjection'); $exam_api = Yii::app()->moduleAPI->get('OphCiExamination'); $default_eye = Eye::BOTH; $default_left_drug = null; $default_right_drug = null; $since = new DateTime(); $since->setTime(0, 0, 0); if ($this->episode && $exam_api && ($imc = $exam_api->getLatestInjectionManagementComplex($this->episode, $since))) { if ($side = $imc->getInjectionSide()) { $default_eye = $side; $default_left_drug = $imc->left_treatment; $default_right_drug = $imc->right_treatment; } } elseif ($this->episode && $therapy_api && ($side = $therapy_api->getLatestApplicationSide($this->patient, $this->episode))) { $default_eye = $side; } elseif ($this->episode && $this->episode->eye_id) { $default_eye = $this->episode->eye_id; } // if we haven't got the default drug from the imc, try therapy application if ($therapy_api) { if ($default_eye != Eye::RIGHT && !$default_left_drug) { $default_left_drug = $therapy_api->getLatestApplicationDrug($this->patient, $this->episode, 'left'); } if ($default_eye != Eye::LEFT && !$default_right_drug) { $default_right_drug = $therapy_api->getLatestApplicationDrug($this->patient, $this->episode, 'right'); } } // set up the values for the potentially allergy restricted drugs in treatment $pre_skin_default = OphTrIntravitrealinjection_SkinDrug::getDefault(); $pre_anti_default = OphTrIntravitrealinjection_AntiSepticDrug::getDefault(); if ($pre_skin_default) { foreach ($pre_skin_default->allergies as $allergy) { if ($this->patient->hasAllergy($allergy)) { $pre_skin_default = null; } } } if ($pre_anti_default) { foreach ($pre_anti_default->allergies as $allergy) { if ($this->patient->hasAllergy($allergy)) { $pre_anti_default = null; } } } foreach ($this->open_elements as $element) { if ($element->hasAttribute('eye_id')) { $element->eye_id = $default_eye; } if (get_class($element) == 'Element_OphTrIntravitrealinjection_Treatment') { if ($therapy_api) { // get the latest drug that has been applied for and set it as default (for the appropriate eye) if ($default_left_drug) { $element->left_drug_id = $default_left_drug->id; $previous = $injection_api->previousInjections($this->patient, $this->episode, 'left', $default_left_drug); $element->left_number = count($previous) + 1; } if ($default_right_drug) { $element->right_drug_id = $default_right_drug->id; $previous = $injection_api->previousInjections($this->patient, $this->episode, 'right', $default_right_drug); $element->right_number = count($previous) + 1; } } $element->left_pre_skin_drug_id = $pre_skin_default ? $pre_skin_default->id : null; $element->right_pre_skin_drug_id = $pre_skin_default ? $pre_skin_default->id : null; $element->left_pre_antisept_drug_id = $pre_anti_default ? $pre_anti_default->id : null; $element->right_pre_antisept_drug_id = $pre_anti_default ? $pre_anti_default->id : null; $element->left_injection_given_by_id = Yii::app()->user->id; $element->right_injection_given_by_id = Yii::app()->user->id; } if (get_class($element) == 'Element_OphTrIntravitrealinjection_Site') { $element->site_id = $this->selectedSiteId; } } }