BaseEventTypeController is the base controller for modules managing events within OpenEyes. It implements a standardised design pattern to provide the general CRUD interface for module events. The controller is designed to be stateful. When an action is called, the state of the controller is determined from the POST and GET attributes of the request. Properties on the controller are populated through a series of methods, and the response is rendered based on these values, and returned to the user. The rationale behind this is that each of the methods provide discrete hooks which can be overridden in module controllers to redefine what the controller properties should be set to. The primary property of the controller to be manipulated is the {@link open_elements} which defines the elements of the event to be displayed in whatever action is being performed. An abstract class in all but name, it should be used for all event based modules. Specific methods can be implemented in module level controllers that will be called automatically by this base controller. Specifically setting defaults on elements and setting complex attributes on individual elements can be handled in specific methods, as defined by
  • {@link setElementDefaultOptions}
  • {@link setElementComplexAttributesFromData}
  • {@link saveElementComplexAttributesFromData}
It's worth noting that at the moment there is no class for Events at the module level. As a result, the controller tends to contain certain business logic that should really be part of the event. Such behaviour should be written in a way that it can be easily extracted into a separate class. The intention in the future is that this would be abstracted into (at a minimum) a helper class, or ideally into an actual event class that would contain all business logic for manipulating the event and its elements. Furthermore no $_POST, $_GET or session data should be utilised within the element models. Data should be extracted by controllers and passed to methods on the element models. In the future, models may be instantiated in different context where these globals would not be available.
Inheritance: extends BaseModuleController
Esempio n. 1
0
 /**
  * Extend the parent method to set event issue data based on user selection.
  */
 protected function updateEventInfo()
 {
     parent::updateEventInfo();
     $this->updateEventIssues();
 }
Esempio n. 2
0
 /**
  * Custom validation for Treatment child elements.
  *
  * @param array $data
  *
  * @return array $errors
  */
 protected function setAndValidateElementsFromData($data)
 {
     $errors = parent::setAndValidateElementsFromData($data);
     foreach ($this->open_elements as $element) {
         if ($element->elementTypeName == 'Treatment') {
             break;
         }
     }
     foreach ($this->getChildElements($element->elementType) as $child) {
         if ($child->hasRight() && !$element->hasRight()) {
             $errors[$child->elementTypeName][] = "Can't have right side without procedures on right eye";
         }
         if ($child->hasLeft() && !$element->hasLeft()) {
             $errors[$child->elementTypeName][] = "Can't have left side without procedures on left eye";
         }
     }
     return $errors;
 }
Esempio n. 3
0
 public function actionPDFPrint($id)
 {
     if (@$_GET['all']) {
         $this->pdf_print_suffix = 'all';
         $letter = ElementLetter::model()->find('event_id=?', array($id));
         $this->pdf_print_documents = 2 + count($letter->getCcTargets());
     }
     return parent::actionPDFPrint($id);
 }
 /**
  * Get all the elements for a the current module's event type
  *
  * @param $event_type_id
  * @return array
  */
 public function getDefaultElements($action, $event_type_id = false, $event = false)
 {
     $etc = new BaseEventTypeController(1);
     $etc->event = $event;
     return $etc->getDefaultElements($action, $event_type_id);
 }
Esempio n. 5
0
 /**
  * Override to support the fact that users might not have permission to edit specific event elements.
  *
  * @param \ElementType $element_type
  * @param $data
  * @return array
  * @throws \Exception
  */
 protected function getElementsForElementType(\ElementType $element_type, $data)
 {
     $cls = $element_type->class_name;
     $map = array('OEModule\\OphCoCvi\\models\\Element_OphCoCvi_ClinicalInfo' => 'Clinical', 'OEModule\\OphCoCvi\\models\\Element_OphCoCvi_ClericalInfo' => 'Clerical');
     if (array_key_exists($cls, $map)) {
         $id = $map[$cls];
         $override = $this->{"getElementsFor{$id}"}();
         if ($override !== false) {
             return $override;
         }
     }
     return parent::getElementsForElementType($element_type, $data);
 }
Esempio n. 6
0
 /**
  * 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;
         }
     }
 }
Esempio n. 7
0
 protected function initActionUpdate()
 {
     parent::initActionUpdate();
     $this->registerEditScripts();
 }
Esempio n. 8
0
 public function actionPDFPrint($id)
 {
     if (@$_GET['vi']) {
         $this->pdf_print_suffix = 'vi';
     }
     return parent::actionPDFPrint($id);
 }
Esempio n. 9
0
 /**
  * Is this element required in the UI? (Prevents the user from being able
  * to remove the element.).
  *
  * @param BaseEventTypeElement $element
  *
  * @return bool
  */
 public function isRequiredInUI(\BaseEventTypeElement $element)
 {
     if (isset($this->mandatoryElements)) {
         foreach ($this->mandatoryElements as $mandatoryElement) {
             if (get_class($element) === $mandatoryElement->class_name) {
                 return true;
             }
         }
     }
     return parent::isRequiredInUI($element);
 }
Esempio n. 10
0
 protected function afterCreateElements($event)
 {
     parent::afterCreateElements($event);
     $this->persistPcrRisk();
 }
Esempio n. 11
0
 public function actionPrint($id)
 {
     parent::actionPrint($id);
 }
 public function redirectToPatientEpisodes()
 {
     parent::redirectToPatientEpisodes();
 }
Esempio n. 13
0
 public function actionPDFPrint($id)
 {
     $this->pdf_print_suffix = Site::model()->findByPk(Yii::app()->session['selected_site_id'])->id;
     $this->pdf_print_documents = 3;
     return parent::actionPDFPrint($id);
 }
 protected function beforeAction($action)
 {
     Yii::app()->clientScript->registerScriptFile($this->assetPath . '/js/module.js');
     return parent::beforeAction($action);
 }
Esempio n. 15
0
 /**
  * use the split event type javascript and styling.
  *
  * @param CAction $action
  *
  * @return bool
  */
 protected function beforeAction($action)
 {
     Yii::app()->assetManager->registerScriptFile('js/spliteventtype.js', null, null, AssetManager::OUTPUT_SCREEN);
     return parent::beforeAction($action);
 }
Esempio n. 16
0
 /**
  * If a partially completed form is submitted, some of the required elements might not be present in the submission
  * this extension resolves this.
  *
  * @param array $data
  *
  * @return array
  */
 protected function setAndValidateElementsFromData($data)
 {
     $errors = parent::setAndValidateElementsFromData($data);
     if (!empty($errors)) {
         $all = $this->event_type->getDefaultElements();
         $curr = $this->open_elements;
         $update = array();
         foreach ($all as $del) {
             if (count($curr) && get_class($curr[0]) == get_class($del)) {
                 $update[] = array_shift($curr);
             } else {
                 $update[] = $del;
             }
         }
         $this->open_elements = $update;
     }
     return $errors;
 }