Esempio n. 1
0
 public function actionAddEvent()
 {
     $data = $_POST;
     $model = new Event();
     $model->u_id = $data['uid'];
     $model->lat = $data['lat'];
     $model->lng = $data['lng'];
     $model->address = $data['address'];
     $model->message = $data['message'];
     $model->status = 0;
     if ($model->save()) {
         $e_id = $model->primaryKey;
         $model = new EventMedia();
         foreach (explode(",", $data['files'], -1) as $id) {
             $model->updateByPk($id, array("e_id" => $e_id));
         }
         $tids = explode(",", $data['tid']);
         foreach ($tids as $tid) {
             $model = new EventType();
             $model->event = $e_id;
             $model->node = $tid;
             $model->save();
         }
         echo 1;
     } else {
         echo 0;
     }
 }
Esempio n. 2
0
 public function postIndex()
 {
     $event_id = Input::get('event_id');
     $latlng = Input::get('search_location_hidden');
     $food_type = Input::get("search_food");
     $param = "";
     if (!empty($_POST['check_list'])) {
         // Loop to store and display values of individual checked checkbox.
         foreach ($_POST['check_list'] as $selected) {
             //echo $selected."</br>";
             if ($param != "") {
                 $param = $param . "," . $selected;
             } else {
                 $param = $selected;
             }
         }
     }
     $typeFood = new EventType();
     $typeFood->event_id = $event_id;
     $typeFood->user_id = Auth::user()->id;
     $typeFood->latlng = $latlng;
     $typeFood->type = $food_type;
     $typeFood->parameters = $param;
     $typeFood->save();
     $userdata = ActiveEvent::whereRaw("event_id = ? and user_id = ?", array($event_id, Auth::user()->id))->first();
     $userdata->is_submitted = "true";
     $userdata->save();
     return Redirect::to('/result?event_id=' . $event_id);
 }
Esempio n. 3
0
 public function setUp()
 {
     parent::setUp();
     $this->orig_modules = Yii::app()->getModules();
     Yii::app()->setModules(array('TestModule' => array('class' => 'ModuleAPITestNS\\TestModule')));
     Yii::setPathOfAlias('ModuleAPITestNS', __DIR__ . '/ModuleAPITest');
     Yii::setPathOfAlias('application.modules.TestModule.components', __DIR__ . '/ModuleAPITest/components');
     // create temporary event type for testing
     $event_type = new EventType();
     $event_type->name = 'Test Module';
     $event_type->class_name = 'TestModule';
     $event_type->event_group_id = 1;
     $event_type->noVersion()->save();
     $this->test_event_type = $event_type;
 }
Esempio n. 4
0
 /**
  * @return \EventType
  */
 protected function getEventType()
 {
     if (!isset($this->event_type)) {
         $this->event_type = \EventType::model()->findByAttributes(array('class_name' => 'OphCoCvi'));
     }
     return $this->event_type;
 }
Esempio n. 5
0
 public static function GetByID($id)
 {
     $query = "SELECT * FROM phpmmo_event_types WHERE event_type_id = " . $id;
     $result = mysql_query($query);
     $values = mysql_fetch_assoc($result);
     return EventType::GetByAssoc($values);
 }
 /**
  * The EventType class for this module
  *
  * @return EventType
  */
 public function getEvent_type()
 {
     if (!$this->_event_type) {
         $this->_event_type = EventType::model()->find('class_name=?', array($this->getModule()->name));
     }
     return $this->_event_type;
 }
Esempio n. 7
0
 /**
  * @param $moduleName
  * @return BaseAPI|bool
  */
 public function get($moduleName)
 {
     if ($module = Yii::app()->getModule($moduleName)) {
         if ($et = EventType::model()->find('class_name = ?', array($moduleName))) {
             // if the module has been inherited from, and has its own API, should return that instead
             if ($child = EventType::model()->find('parent_event_type_id = ?', array($et->id))) {
                 if ($child_api = self::get($child->class_name)) {
                     return $child_api;
                 }
             }
         }
         if (file_exists(Yii::getPathOfAlias("application.modules.{$moduleName}.components") . DIRECTORY_SEPARATOR . "{$moduleName}_API.php")) {
             $APIClass_prefix = '';
             $ns_components = explode('\\', get_class($module));
             if (count($ns_components) > 1) {
                 // we're namespaced so the class for the api will also be namespaced.
                 $APIClass_prefix = implode('\\', array_slice($ns_components, 0, count($ns_components) - 1)) . '\\components\\';
             }
             $APIClass = $APIClass_prefix . $moduleName . '_API';
             if (class_exists($APIClass)) {
                 return new $APIClass();
             }
         }
     }
     return false;
 }
Esempio n. 8
0
 public static function getAll()
 {
     $module_admin = array();
     $module_classes = array();
     foreach (EventType::model()->findAll(array('order' => 'name')) as $event_type) {
         foreach (Yii::app()->params['admin_menu'] as $item => $uri) {
             if (is_array($uri)) {
                 foreach ($uri as $key => $value) {
                     if ($event_type->class_name == 'OphCiExamination') {
                         $module_admin[$event_type->name][$item] = $value;
                     }
                 }
             } else {
                 if (preg_match('/^\\/' . $event_type->class_name . '\\//', $uri)) {
                     $module_admin[$event_type->name][$item] = $uri;
                 }
             }
         }
         $module_classes[] = $event_type->class_name;
     }
     foreach (Yii::app()->modules as $module => $stuff) {
         if (!in_array($module, $module_classes)) {
             foreach (Yii::app()->params['admin_menu'] as $item => $uri) {
                 if (!is_array($uri)) {
                     if (preg_match('/^\\/' . $module . '\\//', $uri)) {
                         $module_admin[$module][$item] = $uri;
                     }
                 }
             }
         }
     }
     return $module_admin;
 }
Esempio n. 9
0
 /**
  * Edits or adds a snippets.
  *
  * @param bool|int $id
  *
  * @throws CHttpException
  */
 public function actionEdit($id = false)
 {
     if ($id) {
         $this->admin->setModelId($id);
     }
     $this->admin->setEditFields(array('site_id' => array('widget' => 'DropDownList', 'options' => CHtml::listData(Institution::model()->getCurrent()->sites, 'id', 'short_name'), 'default' => Yii::app()->request->getParam('site_id'), 'htmlOptions' => null, 'hidden' => false, 'layoutColumns' => null), 'letter_string_group_id' => array('widget' => 'DropDownList', 'options' => CHtml::listData(LetterStringGroup::model()->findAll(), 'id', 'name'), 'default' => Yii::app()->request->getParam('group_id'), 'htmlOptions' => null, 'hidden' => false, 'layoutColumns' => null), 'name' => 'text', 'body' => array('widget' => 'CustomView', 'viewName' => '//admin/generic/shortcodeText', 'viewArguments' => array('model' => $this->admin->getModel())), 'event_type' => array('widget' => 'DropDownList', 'options' => CHtml::listData(EventType::model()->findAll(), 'class_name', 'name'), 'htmlOptions' => array('empty' => '- Select -'), 'hidden' => false, 'layoutColumns' => null), 'element_type' => array('widget' => 'DropDownList', 'options' => CHtml::listData(ElementType::model()->findAll(), 'class_name', 'name'), 'htmlOptions' => array('empty' => '- Select -'), 'hidden' => false, 'layoutColumns' => null)));
     $this->admin->editModel();
 }
Esempio n. 10
0
 /**
  * gets the event type for the api instance
  *
  * @return EventType $event_type
  */
 protected function getEventType()
 {
     $module_class = $this->getModuleClass();
     if (!($event_type = EventType::model()->find('class_name=?', array($module_class)))) {
         throw new Exception("Module is not migrated: {$module_class}");
     }
     return $event_type;
 }
 public function up()
 {
     $event_type = \EventType::model()->find('name=?', array('Examination'));
     // Insert element types (in order of display)
     $element_types = array('OEModule\\OphCiExamination\\models\\Element_OphCiExamination_HistoryRisk' => array('name' => 'Risk', 'parent_element_type_id' => 'OEModule\\OphCiExamination\\models\\Element_OphCiExamination_History', 'display_order' => 30, 'default' => 0));
     $this->insertOEElementType($element_types, $event_type->id);
     $this->createOETable('et_ophciexamination_examinationrisk', array('id' => 'pk', 'event_id' => 'int(10) unsigned NOT NULL', 'anticoagulant' => 'tinyint(1) unsigned not null', 'alphablocker' => 'tinyint(1) unsigned not null', 'KEY `et_ophciexamination_examinationrisk_ev_fk` (`event_id`)', 'CONSTRAINT `et_ophciexamination_examinationrisk_ev_fk` FOREIGN KEY (`event_id`) REFERENCES `event` (`id`)'), true);
 }
Esempio n. 12
0
 public function getOpnoteWithCataractElementInCurrentEpisode($patient)
 {
     if ($episode = $patient->getEpisodeForCurrentSubspecialty()) {
         $event_type = EventType::model()->find('class_name=?', array('OphTrOperationnote'));
         $criteria = new CDbCriteria();
         $criteria->compare('episode_id', $episode->id);
         $criteria->compare('event_type_id', $event_type->id);
         return Element_OphTrOperationnote_Cataract::model()->with('event')->find($criteria);
     }
 }
 public static function search_list(Inputter $inputter, JSONOutputter $outputter)
 {
     //	Search string
     //
     $search_string = $inputter->additional_uri_arguments[0];
     $user_error = null;
     if (!is_string($search_string)) {
         // Throw error, search string is not a string
         //
         $error = Error::withDomain(PRIVATE_EVENTS_REST_CONTROLLER_ERROR_DOMAIN, PRIVATE_EVENTS_REST_CONTROLLER_ERROR_CODE_INPUT_UNCONFORMING, 'Search string is not a string.');
         $outputter->print_error($error);
     }
     //  Query
     //
     $client = new Everyman\Neo4j\Client('events.sb04.stations.graphenedb.com', 24789);
     $client->getTransport()->setAuth('Events', '3TP9LHROhv8LIcGmbYzq');
     //      Users
     //
     $query_string_search_users = 'MATCH (foundUser:CreatingUser) ' . 'WHERE (foundUser.' . CREATINGUSER_KEY_FIRST_NAME . ' + " " + foundUser.' . CREATINGUSER_KEY_SURNAME . ') =~ "(?i)' . $search_string . '.*" OR foundUser.' . CREATINGUSER_KEY_NAME . ' =~ "(?i)' . $search_string . '.*" OR foundUser.' . USER_KEY_EMAIL . ' =~ "(?i)' . $search_string . '" ' . 'RETURN foundUser';
     $query_search_users = new Everyman\Neo4j\Cypher\Query($client, $query_string_search_users);
     $result_search_users = $query_search_users->getResultSet();
     //      Events in scope
     //
     $query_string_search_events = 'MATCH (foundCreator:CreatingUser)-[:creator]-(foundEvent:Event)-[:type]-(foundEventType:EventType), (foundOccurrence:EventSpaceTimeOccurrence)-[:occurrence]-(foundEvent) ' . 'WHERE foundEvent.privacy = 1 AND ANY(label IN labels(foundEventType) WHERE label =~ "(?i).*' . $search_string . '.*") ' . 'RETURN foundEvent, foundEventType, foundCreator, collect(foundOccurrence) as foundEventOccurrences';
     $query_search_events = new Everyman\Neo4j\Cypher\Query($client, $query_string_search_events);
     $result_search_events = $query_search_events->getResultSet();
     //	Output
     //
     //      Users
     //
     $print_users = array();
     foreach ($result_search_users as $row) {
         array_push($print_users, AttendingUser::printer_dictionary($row['foundUser']));
     }
     //      Events in scope
     //
     $print_events = array();
     foreach ($result_search_events as $row) {
         $event_dictionary = array();
         if ($event_dictionary != Event::printer_dictionary($row['foundEvent'])) {
             $event_dictionary = Event::printer_dictionary($row['foundEvent']);
             $event_dictionary[EVENT_RELATIONSHIP_NAME_TYPE] = EventType::printer_dictionary($row['foundEventType']);
             $event_dictionary[EVENT_RELATIONSHIP_NAME_OCCURRENCE] = array();
         }
         foreach ($row['foundEventOccurrences'] as $occurrence) {
             array_push($event_dictionary[EVENT_RELATIONSHIP_NAME_OCCURRENCE], EventSpaceTimeOccurrence::printer_dictionary($occurrence));
         }
         if ($event_dictionary != Event::printer_dictionary($row['foundEvent'])) {
             array_push($print_events, $event_dictionary);
         }
     }
     //	Print data
     //
     $outputter->print_data(array(array("users" => $print_users, "events" => $print_events)));
 }
 /**
  * Collate the data and persist it to the table.
  *
  * @param $id
  *
  * @throws CHttpException
  * @throws Exception
  */
 public function loadData($id)
 {
     $booking = Element_OphTrOperationbooking_Operation::model()->find('event_id=?', array($id));
     $eye = Eye::model()->findByPk($booking->eye_id);
     if ($eye->name === 'Both') {
         throw new CHttpException(400, 'Can\'t display whiteboard for dual eye bookings');
     }
     $eyeLabel = strtolower($eye->name);
     $event = Event::model()->findByPk($id);
     $episode = Episode::model()->findByPk($event->episode_id);
     $patient = Patient::model()->findByPk($episode->patient_id);
     $contact = Contact::model()->findByPk($patient->contact_id);
     $biometryCriteria = new CDbCriteria();
     $biometryCriteria->addCondition('patient_id = :patient_id');
     $biometryCriteria->params = array('patient_id' => $patient->id);
     $biometryCriteria->order = 'last_modified_date DESC';
     $biometryCriteria->limit = 1;
     $biometry = Element_OphTrOperationnote_Biometry::model()->find($biometryCriteria);
     $examination = $event->getPreviousInEpisode(EventType::model()->findByAttributes(array('name' => 'Examination'))->id);
     //$management = new \OEModule\OphCiExamination\models\Element_OphCiExamination_Management();
     //$anterior = new \OEModule\OphCiExamination\models\Element_OphCiExamination_AnteriorSegment();
     $risks = new \OEModule\OphCiExamination\models\Element_OphCiExamination_HistoryRisk();
     if ($examination) {
         //$management = $management->findByAttributes(array('event_id' => $examination->id));
         //$anterior = $anterior->findByAttributes(array('event_id' => $examination->id));
         $risks = $risks->findByAttributes(array('event_id' => $examination->id));
     }
     $labResult = Element_OphInLabResults_Inr::model()->findPatientResultByType($patient->id, '1');
     $allergies = Yii::app()->db->createCommand()->select('a.name as name')->from('patient_allergy_assignment pas')->leftJoin('allergy a', 'pas.allergy_id = a.id')->where("pas.patient_id = {$episode->patient_id}")->order('a.name')->queryAll();
     $allergyString = 'None';
     if ($allergies) {
         $allergyString = implode(',', array_column($allergies, 'name'));
     }
     $operation = Yii::app()->db->createCommand()->select('proc.term as term')->from('et_ophtroperationbooking_operation op')->leftJoin('ophtroperationbooking_operation_procedures_procedures opp', 'opp.element_id = op.id')->leftJoin('proc', 'opp.proc_id = proc.id')->where("op.event_id = {$id}")->queryAll();
     $this->event_id = $id;
     $this->booking = $booking;
     $this->eye_id = $eye->id;
     $this->eye = $eye;
     $this->predicted_additional_equipment = $booking->special_equipment_details;
     $this->comments = '';
     $this->patient_name = $contact['title'] . ' ' . $contact['first_name'] . ' ' . $contact['last_name'];
     $this->date_of_birth = $patient['dob'];
     $this->hos_num = $patient['hos_num'];
     $this->procedure = implode(',', array_column($operation, 'term'));
     $this->allergies = $allergyString;
     $this->iol_model = $biometry ? $biometry->attributes['lens_description_' . $eyeLabel] : 'Unknown';
     $this->iol_power = $biometry ? $biometry->attributes['iol_power_' . $eyeLabel] : 'none';
     $this->predicted_refractive_outcome = $biometry ? $biometry->attributes['predicted_refraction_' . $eyeLabel] : 'Unknown';
     $this->alpha_blockers = $patient->hasRisk('Alpha blockers');
     $this->anticoagulants = $patient->hasRisk('Anticoagulants');
     $this->alpha_blocker_name = $risks ? $risks->alpha_blocker_name : '';
     $this->anticoagulant_name = $risks ? $risks->anticoagulant_name : '';
     $this->inr = $labResult ? $labResult : 'None';
     $this->save();
 }
Esempio n. 15
0
 /**
  * Edits or adds a Type.
  *
  * @param bool|int $id
  *
  * @throws CHttpException
  */
 public function actionEdit($id = false)
 {
     if ($id) {
         $this->admin->setModelId($id);
     }
     $eventType = EventType::model()->findByAttributes(array('name' => 'Lab Results'));
     if ($eventType) {
         $options = CHtml::listData(ElementType::model()->findAllByAttributes(array('event_type_id' => $eventType->id)), 'id', 'name');
     } else {
         $options = CHtml::listData(ElementType::model()->findAll(), 'id', 'name');
     }
     $this->admin->setEditFields(array('type' => 'text', 'result_element_id' => array('widget' => 'DropDownList', 'options' => $options, 'htmlOptions' => null, 'hidden' => false, 'layoutColumns' => null)));
     $this->admin->editModel();
 }
Esempio n. 16
0
 private static function GetByAssoc($values)
 {
     $event = new Event();
     $event->ID = $values["event_id"];
     $event->Name = $values["event_name"];
     $event->Title = $values["event_title"];
     $event->Description = $values["event_description"];
     $event->Content = $values["event_content"];
     $event->BeginDateTime = $values["event_date_begin"];
     $event->EndDateTime = $values["event_date_end"];
     $event->BeginDate = $values["event_date_begin_date"];
     $event->EndDate = $values["event_date_end_date"];
     $event->Type = EventType::GetByID($values["event_type"]);
     return $event;
 }
 public function getCMSFields()
 {
     $fields = parent::getCMSFields();
     $eventTypeSource = EventType::get()->map()->toArray();
     $countrySource = Country::get()->map()->toArray();
     $fields->addFieldsToTab('Root.Main', array(TextField::create('LocationName', 'Location Name'), TextareaField::create('LocationAddress', 'Location Address'), $startDate = DatetimeField::create('StartTime', 'Start'), $endDate = DatetimeField::create('EndTime', 'End'), TextareaField::create('Price', 'Price'), DropdownField::create('EventTypeID', 'Type', $eventTypeSource), DropdownField::create('CountryID', 'Country', $countrySource), UploadField::create('Image', 'Image')));
     $date = Date('Y-m-d', time());
     $time = Date('H:i:s', time());
     $startDate->getDateField()->setConfig('showcalendar', true);
     $startDate->getDateField()->setValue($date);
     $startDate->getTimeField()->setValue($time);
     $endDate->getDateField()->setConfig('showcalendar', true);
     $endDate->getDateField()->setValue($date);
     $endDate->getTimeField()->setValue($time);
     return $fields;
 }
Esempio n. 18
0
 /**
  * @depends testInitialiseData
  */
 public function testInitialiseDataTestdata()
 {
     $eventTypeResultSet = EventType::model()->findAll('id >= 1000');
     Yii::app()->db->createCommand("delete from episode_summary")->query();
     Yii::app()->db->createCommand("delete from episode_summary_item")->query();
     Yii::app()->db->createCommand("delete from event_type where id >= 1009")->query();
     $this->oeMigration->setTestData(true);
     $this->assertNull($this->oeMigration->getCsvFiles());
     ob_start();
     $this->oeMigration->initialiseData($this->fixturePath, null, 'oeMigrationData');
     ob_end_clean();
     $this->compareFixtureWithResultSet($this->event_type, $eventTypeResultSet);
     EventType::model()->deleteAll('id >= 1000');
     $this->assertGreaterThan(0, $this->oeMigration->getCsvFiles());
     $expectedCsvArrayInTestMode = array($this->fixturePath . DIRECTORY_SEPARATOR . 'testdata' . DIRECTORY_SEPARATOR . 'oeMigrationData' . DIRECTORY_SEPARATOR . '01_episode.csv', $this->fixturePath . DIRECTORY_SEPARATOR . 'testdata' . DIRECTORY_SEPARATOR . 'oeMigrationData' . DIRECTORY_SEPARATOR . '01_event_type.csv', $this->fixturePath . DIRECTORY_SEPARATOR . 'testdata' . DIRECTORY_SEPARATOR . 'oeMigrationData' . DIRECTORY_SEPARATOR . '01_user.csv');
     $this->assertEquals($expectedCsvArrayInTestMode, $this->oeMigration->getCsvFiles());
 }
Esempio n. 19
0
 public function run($args)
 {
     $event_type_id = EventType::model()->find('class_name = :classname', array(':classname' => 'OphInVisualfields'))->id;
     $patient_ids = Yii::app()->db->createCommand()->selectDistinct('patient_id')->from('measurement_reference mr')->join('patient_measurement pm', 'pm.id = mr.patient_measurement_id')->queryColumn();
     foreach ($patient_ids as $patient_id) {
         $criteria = new CDbCriteria();
         $criteria->condition = 'event_type_id = :event_type_id AND patient_id = :patient_id';
         $criteria->join = 'join episode ep on ep.id = t.episode_id';
         $criteria->order = 'event_date desc';
         $criteria->limit = '3';
         $criteria->params = array(':patient_id' => $patient_id, ':event_type_id' => $event_type_id);
         $events = Event::model()->findAll($criteria);
         foreach ($events as $event) {
             echo ' - ' . $event->id . "\n";
             MeasurementReference::model()->deleteAll('event_id = ?', array($event->id));
             $event->deleted = 1;
             $event->save();
         }
         echo "{$patient_id}\n";
     }
 }
 private function ReportEvent(Event &$event)
 {
     $report = '';
     $type = $event->GetType();
     /*
     if (//EventType::USER_MSG() != $type ||
         //EventType::PASS_MSG() != $type ||
         EventType::FAIL_MSG() == $type)
     {
       $report .= 'Reason: ' . $event->GetReason() . PHP_EOL;
     }
     */
     if (EventType::FAIL() == $type || EventType::ERROR() == $type) {
         $report .= "\tFailed Message: " . $event->GetMessage() . "\tSee detail" . PHP_EOL . "\tActual Type: " . $event->GetActualType() . "\tValue: " . $event->GetActualValue() . PHP_EOL . "\tComparison Type: " . $event->GetComparisonType() . "\tValue: " . $event->GetComparisonValue() . PHP_EOL . "\tFile: " . $event->GetFile() . " Line: " . $event->GetLine() . PHP_EOL;
     } else {
         if (EventType::EXCEPTION_THROWN() == $type) {
             $report .= "\tException: " . $event->GetReason() . PHP_EOL;
             $report .= "\t  " . $event->GetMessage() . PHP_EOL;
         }
     }
     return $report;
 }
Esempio n. 21
0
 public static function getAll()
 {
     $reports = array();
     $module_classes = array();
     foreach (EventType::model()->findAll(array('order' => 'name')) as $event_type) {
         foreach (Yii::app()->params['reports'] as $item => $uri) {
             if (preg_match('/^\\/' . $event_type->class_name . '\\//', $uri)) {
                 $reports[$event_type->name][$item] = $uri;
             }
         }
         $module_classes[] = $event_type->class_name;
     }
     foreach (Yii::app()->modules as $module => $stuff) {
         if (!in_array($module, $module_classes)) {
             foreach (Yii::app()->params['reports'] as $item => $uri) {
                 if (preg_match('/^\\/' . $module . '\\//', $uri)) {
                     $reports[$module][$item] = $uri;
                 }
             }
         }
     }
     return $reports;
 }
 private function ReportEvent(Event &$event)
 {
     $report = '        <type>' . htmlentities($event->GetTypeAsString()) . "</type>\n";
     $report .= '        <time>' . htmlentities($event->GetTime()) . "</time>\n";
     $type = $event->GetType();
     if (EventType::START_SETUP() == $type || EventType::END_SETUP() == $type || EventType::START_RUN() == $type || EventType::END_RUN() == $type || EventType::START_TEAR_DOWN() == $type || EventType::END_TEAR_DOWN() == $type) {
         return $report;
     }
     if (EventType::USER_MSG() != $type || EventType::PASS_MSG() != $type || EventType::FAIL_MSG() != $type) {
         $report .= '        <reason>' . htmlentities($event->GetReason()) . "</reason>\n";
     }
     if (EventType::SYS_MSG() != $type) {
         $report .= '        <message>' . htmlentities($event->GetMessage()) . "</message>\n";
     }
     if (EventType::SYS_MSG() != $type && EventType::USER_MSG() != $type && EventType::FAIL_MSG() != $type && EventType::PASS_MSG() != $type && EventType::EXCEPTION_THROWN() != $type) {
         $report .= "        <actual>\n" . '          <type>' . htmlentities($event->GetActualType()) . "</type>\n" . '          <value>' . htmlentities($event->GetActualValue()) . "</value></actual>\n";
         $report .= "        <comparison>\n" . '          <type>' . htmlentities($event->GetComparisonType()) . "</type>\n" . '          <value>' . htmlentities($event->GetComparisonValue()) . "</value></comparison>\n";
     }
     if (EventType::SYS_MSG() != $type) {
         $report .= '        <file>' . htmlentities($event->GetFile()) . "</file>\n";
         $report .= '        <line>' . htmlentities($event->GetLine()) . "</line>\n";
     }
     return $report;
 }
 /**
  * checks if an element short name exists
  *
  * We use the short name to define table names, so here we check for the table
  * being defined in the db based off the current event.
  *
  * Only works for updates.
  * @since future
  */
 public function elementShortNameExists($name)
 {
     if ($this->mode == 'update') {
         // TODO: work out what the table name would be for the element based off the current event
         /*
          * get the elements that would be used to create the element table name - speciality, group, and event type
          * concatanate these, and then try and get the table
          */
         $tname = strtolower('et_' . EventType::model()->findByPk(@$_POST['EventTypeModuleEventType'])->class_name . '_' . $name);
         return Yii::app()->db->schema->getTable($tname);
     }
     return false;
 }
Esempio n. 24
0
 public function getIndex()
 {
     $event_id = Input::get('event_id');
     $bypass = Input::get('bypass');
     $all_user = ActiveEvent::where('event_id', "=", $event_id)->get();
     $not_submitted_user = array();
     $submitted_user = array();
     foreach ($all_user as $key => $value) {
         echo $value->is_submitted;
         if ($value->is_submitted != "true") {
             $not_submitted_user[$value->user_id] = array();
             $user = User::find($value->user_id);
             array_push($not_submitted_user[$value->user_id], $user->name);
         } else {
             array_push($submitted_user, $value->user_id);
         }
     }
     if (empty($not_submitted_user) || $bypass == 'true') {
         $all_participants = EventType::where('event_id', "=", $event_id)->get();
         // TODO: Show map with results
         $yelp_api = new YelpAPI();
         //$yelp_data = $yelp_api->query_api("pizza","Montreal","45.495518,-73.581662");
         $temp_user_store = array();
         $compare_data = array();
         echo count($submitted_user);
         foreach ($submitted_user as $key) {
             $event_type_user = EventType::whereRaw("event_id = ? and user_id = ?", array($event_id, $key))->first();
             $type_food = explode(",", $event_type_user->type);
             $yelp_data = $yelp_api->query_api($type_food[0], "Montreal", $event_type_user->latlng, "1", "16093");
             $all_business = $yelp_data['businesses'];
             array_push($temp_user_store, $event_type_user);
             foreach ($all_business as $key => $data) {
                 // print_r($data['image_url']);
                 if (!array_key_exists($data['image_url'], $compare_data)) {
                     $compare_data[$data['image_url']] = $data;
                 }
             }
         }
         // print_r(count($compare_data));
         $distance = array();
         foreach ($compare_data as $key => $value) {
             $lat_res = $value['location']['coordinate']['latitude'];
             $lng_res = $value['location']['coordinate']['longitude'];
             foreach ($temp_user_store as $usr) {
                 $latlng = $usr->latlng;
                 $latlng_array = explode(",", $latlng);
                 $utility = new Utility();
                 $dis_km = $utility->finddistance($latlng_array[0], $latlng_array[1], $lat_res, $lng_res, "K");
                 $dis_km = intval($dis_km);
                 if (!array_key_exists($dis_km, $distance)) {
                     $distance[$dis_km] = array();
                 }
                 array_push($distance[$dis_km], $key);
             }
         }
         ksort($distance);
         $all_business = array();
         $checking_array = array();
         foreach ($distance as $key => $value) {
             //print_r($value);
             print_r("</br>");
             //print_r("</br>");
             print_r("</br>");
             print_r("</br>");
             print_r("</br>");
             foreach ($value as $data) {
                 if (!array_key_exists($data, $checking_array)) {
                     array_push($all_business, $compare_data[$data]);
                     $checking_array[$data] = true;
                 }
             }
         }
         foreach ($all_business as $key) {
             //  print_r($key['rating_img_url']);
             // print_r("</br>");
             //  print_r("</br>");
             //  print_r("</br>");
             //  print_r("</br>");
         }
         return View::make('main.resultpage')->with(array('all_business' => $all_business, 'all_participants' => $all_participants));
     } else {
         return Redirect::to('/pending?event_id=' . $event_id);
     }
 }
Esempio n. 25
0
 public function actionUpdateepisode($id)
 {
     if (!($this->episode = Episode::model()->findByPk($id))) {
         throw new SystemException('Episode not found: ' . $id);
     }
     if (!$this->checkAccess('OprnEditEpisode', $this->firm, $this->episode) || isset($_POST['episode_cancel'])) {
         $this->redirect(array('patient/episode/' . $this->episode->id));
         return;
     }
     if (!empty($_POST)) {
         if (@$_POST['eye_id'] && !@$_POST['DiagnosisSelection']['disorder_id']) {
             $error = "Please select a disorder for the principal diagnosis";
         } elseif (!@$_POST['eye_id'] && @$_POST['DiagnosisSelection']['disorder_id']) {
             $error = "Please select an eye for the principal diagnosis";
         } else {
             if (@$_POST['eye_id'] && @$_POST['DiagnosisSelection']['disorder_id']) {
                 if ($_POST['eye_id'] != $this->episode->eye_id || $_POST['DiagnosisSelection']['disorder_id'] != $this->episode->disorder_id) {
                     $this->episode->setPrincipalDiagnosis($_POST['DiagnosisSelection']['disorder_id'], $_POST['eye_id']);
                 }
             }
             if ($_POST['episode_status_id'] != $this->episode->episode_status_id) {
                 $this->episode->episode_status_id = $_POST['episode_status_id'];
                 if (!$this->episode->save()) {
                     throw new Exception('Unable to update status for episode ' . $this->episode->id . ' ' . print_r($this->episode->getErrors(), true));
                 }
             }
             $this->redirect(array('patient/episode/' . $this->episode->id));
         }
     }
     $this->patient = $this->episode->patient;
     $this->layout = '//layouts/events_and_episodes';
     $episodes = $this->patient->episodes;
     // TODO: verify if ordered_episodes complete supercedes need for unordered $episodes
     $ordered_episodes = $this->patient->getOrderedEpisodes();
     $legacyepisodes = $this->patient->legacyepisodes;
     $supportserviceepisodes = $this->patient->supportserviceepisodes;
     $site = Site::model()->findByPk(Yii::app()->session['selected_site_id']);
     $this->title = 'Episode summary';
     $this->event_tabs = array(array('label' => 'View', 'href' => Yii::app()->createUrl('/patient/episode/' . $this->episode->id)), array('label' => 'Edit', 'active' => true));
     $status = Yii::app()->session['episode_hide_status'];
     $status[$id] = true;
     Yii::app()->session['episode_hide_status'] = $status;
     $this->editing = true;
     $this->render('episodes', array('title' => empty($episodes) ? '' : 'Episode summary', 'episodes' => $episodes, 'ordered_episodes' => $ordered_episodes, 'legacyepisodes' => $legacyepisodes, 'supportserviceepisodes' => $supportserviceepisodes, 'eventTypes' => EventType::model()->getEventTypeModules(), 'site' => $site, 'current_episode' => $this->episode, 'error' => @$error));
 }
Esempio n. 26
0
			<?php 
echo $form->textArea($element, 're', array('rows' => 2, 'label' => false, 'nowrapper' => true), empty($_POST) ? strlen($element->re) == 0 : strlen(@$_POST['ElementLetter']['re']) == 0, array('class' => 'address'));
?>
		</div>
	</div>


	<div class="row field-row">
		<div class="large-<?php 
echo $layoutColumns['label'];
?>
 column">
			<?php 
$firm = Firm::model()->with('serviceSubspecialtyAssignment')->findByPk(Yii::app()->session['selected_firm_id']);
$event_types = array();
foreach (EventType::model()->with('elementTypes')->findAll() as $event_type) {
    $event_types[$event_type->class_name] = array();
    foreach ($event_type->elementTypes as $elementType) {
        $event_types[$event_type->class_name][] = $elementType->class_name;
    }
}
if (isset($_GET['patient_id'])) {
    $patient = Patient::model()->findByPk($_GET['patient_id']);
} else {
    $patient = Yii::app()->getController()->patient;
}
$with = array('firmLetterStrings' => array('condition' => 'firm_id is null or firm_id = :firm_id', 'params' => array(':firm_id' => $firm->id), 'order' => 'firmLetterStrings.display_order asc'), 'subspecialtyLetterStrings' => array('condition' => 'subspecialty_id is null', 'order' => 'subspecialtyLetterStrings.display_order asc'), 'siteLetterStrings' => array('condition' => 'site_id is null or site_id = :site_id', 'params' => array(':site_id' => Yii::app()->session['selected_site_id']), 'order' => 'siteLetterStrings.display_order'));
if ($firm->getSubspecialtyID()) {
    $with['subspecialtyLetterStrings']['condition'] = 'subspecialty_id is null or subspecialty_id = :subspecialty_id';
    $with['subspecialtyLetterStrings']['params'] = array(':subspecialty_id' => $firm->getSubspecialtyID());
}
Esempio n. 27
0
 public function __construct()
 {
     $data = Ensure::Input(func_get_args(), Converter::toArray(json_decode(file_get_contents("php://input"))));
     parent::_init($data, new Call());
 }
Esempio n. 28
0
 public function run($args)
 {
     Yii::import('application.modules.Reports.models.*');
     if (!($query_type_events = ReportQueryType::model()->find('name=?', array('Events')))) {
         $query_type_events = new ReportQueryType();
         $query_type_events->name = 'Events';
         $query_type_events->display_order = 1;
         if (!$query_type_events->save()) {
             print_r($query_type_events->getErrors(), true);
             exit;
         }
     }
     if (!($query_type_patients = ReportQueryType::model()->find('name=?', array('Patients')))) {
         $query_type_patients = new ReportQueryType();
         $query_type_patients->name = 'Patients';
         $query_type_patients->display_order = 1;
         if (!$query_type_patients->save()) {
             print_r($query_type_patients->getErrors(), true);
             exit;
         }
     }
     /* input data types */
     $ridt_number = ReportInputDataType::add('number', 1);
     $ridt_dropdown_from_table = ReportInputDataType::add('dropdown_from_table', 2);
     $ridt_date = ReportInputDataType::add('date', 3);
     $ridt_diagnoses = ReportInputDataType::add('diagnoses', 4);
     $ridt_checkbox = ReportInputDataType::add('checkbox', 5);
     $ridt_checkbox_optional_match = ReportInputDataType::add('checkbox_optional_match', 6);
     /* report item data types */
     $rimt_total = ReportItemDataType::add('total');
     $rimt_mean_and_range = ReportItemDataType::add('mean_and_range');
     $rimt_number_and_percentage = ReportItemDataType::add('number_and_percentage');
     $rimt_number_and_percentage_pair = ReportItemDataType::add('number_and_percentage_pair');
     $rimt_list = ReportItemDataType::add('list');
     $rimt_string = ReportItemDataType::add('string');
     $rimt_date = ReportItemDataType::add('date');
     $rimt_nhsdate = ReportItemDataType::add('NHSDate');
     $rimt_conditional = ReportItemDataType::add('conditional');
     $rimt_list_from_element_relation = ReportItemDataType::add('list_from_element_relation');
     $rimt_element_relation = ReportItemDataType::add('element_relation');
     $rimt_number = ReportItemDataType::add('number');
     /* rule types */
     $rule_one_of = ReportValidationRuleType::add('One of');
     /* Cataract Outcomes */
     Yii::import('application.modules.OphTrOperationnote.models.*');
     $opnote = EventType::model()->find('class_name=?', array('OphTrOperationnote'));
     $element_proclist = ElementType::model()->find('event_type_id=? and class_name=?', array($opnote->id, 'ElementProcedureList'));
     $element_surgeon = ElementType::model()->find('event_type_id=? and class_name=?', array($opnote->id, 'ElementSurgeon'));
     $element_cataract = ElementType::model()->find('event_type_id=? and class_name=?', array($opnote->id, 'ElementCataract'));
     $report = Report::add(array('query_type_id' => $query_type_events->id, 'subspecialty_id' => 4, 'name' => 'Cataract outcomes', 'description' => 'Cataract outcomes report', 'icon' => 'treatment_operation', 'display_order' => 1, 'can_print' => 1, 'can_download' => 1));
     $dataset1 = $report->addDataset('dataset1');
     $el_proclist = $dataset1->addElement($element_proclist->id);
     $el_proclist->addField('eye_id');
     $el_surgeon = $dataset1->addElement($element_surgeon->id);
     $el_surgeon->addField('surgeon_id');
     $el_surgeon->addField('assistant_id');
     $el_surgeon->addField('supervising_surgeon_id');
     $el_cataract = $dataset1->addElement($element_cataract->id);
     $dataset1->addInput(array('data_type_id' => $ridt_dropdown_from_table->id, 'data_type_param1' => 'Firm', 'data_type_param2' => 'getCataractList', 'name' => 'firm_id', 'description' => 'Firm', 'display_order' => 1));
     $dataset1->addInput(array('data_type_id' => $ridt_dropdown_from_table->id, 'data_type_param1' => 'User', 'data_type_param2' => 'getListSurgeons', 'name' => 'surgeon_id', 'description' => 'Surgeon', 'display_order' => 2, 'or_id' => 1));
     $dataset1->addInput(array('data_type_id' => $ridt_dropdown_from_table->id, 'data_type_param1' => 'User', 'data_type_param2' => 'getListSurgeons', 'name' => 'assistant_id', 'description' => 'Assistant surgeon', 'display_order' => 3, 'or_id' => 1));
     $dataset1->addInput(array('data_type_id' => $ridt_dropdown_from_table->id, 'data_type_param1' => 'User', 'data_type_param2' => 'getListSurgeons', 'name' => 'supervising_surgeon_id', 'description' => 'Supervising surgeon', 'display_order' => 4, 'or_id' => 1));
     $dataset1->addInput(array('data_type_id' => $ridt_date->id, 'name' => 'date_from', 'description' => 'Date from', 'default_value' => '-12 months', 'display_order' => 5, 'required' => 1));
     $dataset1->addInput(array('data_type_id' => $ridt_date->id, 'name' => 'date_to', 'description' => 'Date to', 'default_value' => 'now', 'display_order' => 6, 'required' => 1));
     $dataset1->addItem(array('data_type_id' => $rimt_total->id, 'name' => 'Cataracts', 'data_field' => 'cataracts', 'subtitle' => 'Number of cataracts performed', 'display_order' => 1));
     $dataset1->addItem(array('data_type_id' => $rimt_mean_and_range->id, 'name' => 'Age', 'data_field' => 'age', 'data_input_field' => 'age', 'subtitle' => 'Age of patients', 'display_order' => 2));
     $item = $dataset1->addItem(array('data_type_id' => $rimt_number_and_percentage_pair->id, 'name' => 'Eyes', 'data_field' => 'eyes', 'subtitle' => 'Eyes', 'display_order' => 3));
     $item->addPairField(array('name' => 'left', 'field' => 'eye_id', 'value' => '1'));
     $item->addPairField(array('name' => 'right', 'field' => 'eye_id', 'value' => '2'));
     $dataset1->addItem(array('data_type_id' => $rimt_mean_and_range->id, 'name' => 'Final visual acuity', 'data_field' => 'final_visual_acuity', 'subtitle' => 'Final visual acuity', 'display_order' => 4));
     $pc_rupture = CataractComplications::model()->find('name=?', array('PC rupture'));
     $pc_ruptures = $dataset1->addItem(array('data_type_id' => $rimt_number_and_percentage->id, 'name' => 'PC ruptures', 'data_field' => 'pc_ruptures', 'subtitle' => 'PC ruptures', 'display_order' => 5, 'element_id' => $el_cataract->id, 'element_relation' => 'complications', 'element_relation_field' => 'complication_id', 'element_relation_value' => $pc_rupture->id));
     $complications = $dataset1->addItem(array('data_type_id' => $rimt_number_and_percentage->id, 'name' => 'Complications', 'data_field' => 'complications', 'subtitle' => 'All complications', 'display_order' => 7, 'element_id' => $el_cataract->id, 'element_relation' => 'complications'));
     $dataset2 = $report->addDataset('dataset2');
     $el_cataract = $dataset2->addElement($element_cataract->id);
     $avg_pc_ruptures = $dataset2->addItem(array('data_type_id' => $rimt_number_and_percentage->id, 'name' => 'Average', 'data_field' => 'pc_rupture_average', 'subtitle' => 'Average', 'display_order' => 6, 'element_id' => $el_cataract->id, 'element_relation' => 'complications', 'element_relation_field' => 'complication_id', 'element_relation_value' => $pc_rupture->id, 'display' => 0));
     $avg_complications = $dataset2->addItem(array('data_type_id' => $rimt_number_and_percentage->id, 'name' => 'Average', 'data_field' => 'complication_average', 'subtitle' => 'Average', 'display_order' => 8, 'element_id' => $el_cataract->id, 'element_relation' => 'complications', 'display' => 0));
     $graph = $report->addGraph('Cataract complication rate', 1);
     $graph->addItem(array('report_item_id' => $pc_ruptures->id, 'name' => 'PC rupture rate', 'subtitle' => 'percentage', 'range' => 10, 'display_order' => 1, 'show_scale' => 0));
     $graph->addItem(array('report_item_id' => $avg_pc_ruptures->id, 'name' => 'Average rate', 'subtitle' => 'institution average', 'range' => 10, 'display_order' => 2));
     $graph->addItem(array('report_item_id' => $complications->id, 'name' => 'Complication rate', 'subtitle' => 'percentage', 'range' => 10, 'display_order' => 3, 'show_scale' => 0));
     $graph->addItem(array('report_item_id' => $avg_complications->id, 'name' => 'Average rate', 'subtitle' => 'institution average', 'range' => 10, 'display_order' => 4));
     /* Operations */
     $report = Report::add(array('query_type_id' => $query_type_events->id, 'subspecialty_id' => null, 'name' => 'Operations', 'description' => 'Operations', 'icon' => 'treatment_operation', 'display_order' => 3, 'can_print' => 1, 'can_download' => 1));
     $dataset1 = $report->addDataset('dataset1');
     $el_proclist = $dataset1->addElement($element_proclist->id);
     $el_proclist->addField('eye_id');
     $el_proclist->addJoin(array('join_table' => 'eye', 'join_clause' => 'eye_id = eye.id', 'join_select' => 'eye.name as eye'));
     $el_surgeon = $dataset1->addElement($element_surgeon->id);
     $el_surgeon->addField('surgeon_id');
     $el_surgeon->addField('assistant_id');
     $el_surgeon->addField('supervising_surgeon_id');
     $el_cataract = $dataset1->addElement($element_cataract->id, 1);
     $surgeon_id = $dataset1->addInput(array('data_type_id' => $ridt_dropdown_from_table->id, 'data_type_param1' => 'User', 'data_type_param2' => 'getListSurgeons', 'name' => 'surgeon_id', 'description' => 'Surgeon', 'display_order' => 1, 'required' => 1, 'include' => 0));
     $dataset1->addInput(array('data_type_id' => $ridt_checkbox_optional_match->id, 'name' => 'match_surgeon', 'default_value' => 1, 'description' => 'Match surgeon', 'display_order' => 2, 'data_type_param1' => 'surgeon_id', 'data_type_param2' => 'surgeon_id', 'or_id' => 1));
     $dataset1->addInput(array('data_type_id' => $ridt_checkbox_optional_match->id, 'name' => 'match_assistant_surgeon', 'default_value' => 1, 'description' => 'Match assistant surgeon', 'display_order' => 3, 'data_type_param1' => 'surgeon_id', 'data_type_param2' => 'assistant_id', 'or_id' => 1));
     $dataset1->addInput(array('data_type_id' => $ridt_checkbox_optional_match->id, 'name' => 'match_supervising_surgeon', 'default_value' => 1, 'description' => 'Match supervising surgeon', 'display_order' => 4, 'data_type_param1' => 'surgeon_id', 'data_type_param2' => 'supervising_surgeon_id', 'or_id' => 1));
     $dataset1->addInput(array('data_type_id' => $ridt_date->id, 'name' => 'date_from', 'description' => 'Date from', 'default_value' => '-12 months', 'display_order' => 5, 'required' => 1));
     $dataset1->addInput(array('data_type_id' => $ridt_date->id, 'name' => 'date_to', 'description' => 'Date to', 'default_value' => 'now', 'display_order' => 6, 'required' => 1));
     $operations = $dataset1->addItem(array('data_type_id' => $rimt_list->id, 'name' => 'Operations', 'data_field' => 'operations', 'subtitle' => 'Operations', 'display_order' => 1));
     $operations->addListItem(array('data_type_id' => $rimt_number->id, 'name' => 'Patient ID', 'data_field' => 'patient_id', 'subtitle' => 'Patient ID', 'display' => 0));
     $operations->addListItem(array('data_type_id' => $rimt_nhsdate->id, 'name' => 'Date', 'data_field' => 'datetime', 'subtitle' => 'Date', 'display_order' => 1));
     $operations->addListItem(array('data_type_id' => $rimt_string->id, 'name' => 'Hospital no', 'data_field' => 'hos_num', 'subtitle' => 'Patient hospital number', 'display_order' => 2, 'link' => '/patient/episodes/{patient_id}'));
     $operations->addListItem(array('data_type_id' => $rimt_string->id, 'name' => 'First name', 'data_field' => 'first_name', 'subtitle' => 'Patient first name', 'display_order' => 3));
     $operations->addListItem(array('data_type_id' => $rimt_string->id, 'name' => 'Last name', 'data_field' => 'last_name', 'subtitle' => 'Patient last name', 'display_order' => 4));
     $procedures = $operations->addListItem(array('data_type_id' => $rimt_list_from_element_relation->id, 'name' => 'Procedures', 'data_field' => 'procedures', 'subtitle' => 'Procedures', 'display_order' => 5, 'element_id' => $el_proclist->id, 'element_relation' => 'procedures'));
     $procedures->addListItem(array('data_type_id' => $rimt_element_relation->id, 'name' => 'procedure', 'data_field' => 'term'));
     $procedures->addListItem(array('data_type_id' => $rimt_element_relation->id, 'name' => 'procedure', 'data_field' => 'term'));
     $complications = $operations->addListItem(array('data_type_id' => $rimt_list_from_element_relation->id, 'name' => 'Complications', 'data_field' => 'complications', 'subtitle' => 'Complications', 'display_order' => 6, 'element_id' => $el_cataract->id, 'element_relation' => 'complications'));
     $complications->addListItem(array('data_type_id' => $rimt_element_relation->id, 'name' => 'name', 'data_field' => 'name'));
     $role = $operations->addListItem(array('data_type_id' => $rimt_conditional->id, 'name' => 'Role', 'data_field' => 'role', 'subtitle' => 'Role', 'display_order' => 7));
     $role->addConditional(array('input_id' => $surgeon_id->id, 'match_field' => 'surgeon_id', 'result' => 'Surgeon', 'display_order' => 1));
     $role->addConditional(array('input_id' => $surgeon_id->id, 'match_field' => 'assistant_id', 'result' => 'Assistant surgeon', 'display_order' => 2));
     $role->addConditional(array('input_id' => $surgeon_id->id, 'match_field' => 'supervising_surgeon_id', 'result' => 'Supervising surgeon', 'display_order' => 3));
     $report->addRule(array('rule_type_id' => $rule_one_of->id, 'rule' => 'match_surgeon,match_assistant_surgeon,match_supervising_surgeon', 'message' => 'At least one of the surgeon checkboxes must be selected'));
     /* Patient diagnoses */
     $report = Report::add(array('query_type_id' => $query_type_patients->id, 'name' => 'Patient diagnoses', 'description' => 'Patient diagnoses report', 'icon' => 'treatment_operation', 'display_order' => 2, 'can_print' => 1, 'can_download' => 0));
     $dataset1 = $report->addDataset('dataset1');
     $disorders = $dataset1->addRelatedEntity('diagnoses');
     $principal = $disorders->addRelatedEntityType('principal');
     $secondary = $disorders->addRelatedEntityType('secondary');
     $episode = $disorders->addRelatedEntityTable(array('entity_type_id' => $principal->id, 'table_name' => 'episode', 'table_related_field' => 'patient_id', 'table_query_field' => 'disorder_id', 'table_date_field' => 'last_modified_date'));
     $episode->addRelation(array('local_field' => 'disorder_id', 'related_table' => 'disorder', 'select_field' => 'term', 'select_field_as' => 'diagnosis'));
     $episode->addRelation(array('local_field' => 'eye_id', 'related_table' => 'eye', 'select_field' => 'name', 'select_field_as' => 'eye'));
     $secondary_diagnosis = $disorders->addRelatedEntityTable(array('entity_type_id' => $secondary->id, 'table_name' => 'secondary_diagnosis', 'table_related_field' => 'patient_id', 'table_query_field' => 'disorder_id', 'table_date_field' => 'last_modified_date'));
     $secondary_diagnosis->addRelation(array('local_field' => 'disorder_id', 'related_table' => 'disorder', 'select_field' => 'term', 'select_field_as' => 'diagnosis'));
     $secondary_diagnosis->addRelation(array('local_field' => 'eye_id', 'related_table' => 'eye', 'select_field' => 'name', 'select_field_as' => 'eye'));
     $dataset1->addInput(array('data_type_id' => $ridt_date->id, 'name' => 'date_from', 'description' => 'Start date', 'default_value' => '-12 months', 'display_order' => 1, 'required' => 1));
     $dataset1->addInput(array('data_type_id' => $ridt_date->id, 'name' => 'date_to', 'description' => 'End date', 'default_value' => 'now', 'display_order' => 2, 'required' => 1));
     $dataset1->addInput(array('data_type_id' => $ridt_diagnoses->id, 'related_entity_id' => $disorders->id, 'name' => 'diagnoses', 'description' => 'Diagnoses', 'display_order' => 3));
     $patients = $dataset1->addItem(array('data_type_id' => $rimt_list->id, 'name' => 'Patients', 'data_field' => 'patients', 'subtitle' => 'Patient diagnoses', 'display_order' => 1));
     $patients->addListItem(array('data_type_id' => $rimt_nhsdate->id, 'name' => 'Date', 'data_field' => 'date', 'subtitle' => 'Date', 'display_order' => 1));
     $patients->addListItem(array('data_type_id' => $rimt_string->id, 'name' => 'Hospital no', 'data_field' => 'hos_num', 'subtitle' => 'Patient hospital number', 'display_order' => 2, 'link' => '/patient/episodes/{patient_id}'));
     $patients->addListItem(array('data_type_id' => $rimt_string->id, 'name' => 'First name', 'data_field' => 'first_name', 'subtitle' => 'Patient first name', 'display_order' => 3));
     $patients->addListItem(array('data_type_id' => $rimt_string->id, 'name' => 'Last name', 'data_field' => 'last_name', 'subtitle' => 'Patient last name', 'display_order' => 4));
     $patients->addListItem(array('data_type_id' => $rimt_number->id, 'name' => 'Patient ID', 'data_field' => 'patient_id', 'subtitle' => 'Patient ID', 'display' => 0));
     $diagnoses = $patients->addListItem(array('data_type_id' => $rimt_list->id, 'name' => 'Diagnoses', 'data_field' => 'diagnoses', 'subtitle' => 'Diagnoses', 'display_order' => 5));
     $diagnoses->addListItem(array('data_type_id' => $rimt_string->id, 'name' => 'Eye', 'data_field' => 'eye', 'subtitle' => 'Eye', 'display_order' => 1));
     $diagnoses->addListItem(array('data_type_id' => $rimt_string->id, 'name' => 'Diagnosis', 'data_field' => 'diagnosis', 'subtitle' => 'Diagnosis', 'display_order' => 2));
 }
		<?php 
if ($this->target_class) {
    ?>
			<input type="hidden" id="target_event_class" value="<?php 
    echo $this->target_class;
    ?>
" />
		<?php 
}
?>
		<h3>Select an event type:</h3>
		<select class="EventTypeModuleEventType" name="EventTypeModuleEventType">
			<option value="">- Please select -</option>
			<?php 
foreach (EventType::model()->findAll(array('order' => 'name asc')) as $event_type) {
    ?>
				<option value="<?php 
    echo $event_type->id;
    ?>
"<?php 
    if (@$_POST['EventTypeModuleEventType'] == $event_type->id) {
        ?>
 selected="selected"<?php 
    }
    ?>
><?php 
    echo $event_type->name;
    ?>
</option>
			<?php 
}
 public function joinLetters($type, $data, &$select, &$where_clauses, &$where_params, $where_operator)
 {
     $et = $type == 'Correspondence' ? EventType::model()->find('class_name=?', array('OphCoCorrespondence')) : EventType::model()->find('class_name=?', array('OphLeEpatientletter'));
     $letter_table = $type == 'Correspondence' ? array('et_ophcocorrespondence_letter', 'l') : array('et_ophleepatientletter_epatientletter', 'l2');
     $text_field = $type == 'Correspondence' ? 'body' : 'letter_html';
     $data->leftJoin("{$letter_table[0]} {$letter_table[1]}", "{$letter_table[1]}.event_id = e.id");
     $clause = "({$letter_table[1]}.id is not null and e.event_type_id = :et_{$letter_table[1]}_id ";
     $where_params[":et_{$letter_table[1]}_id"] = $et->id;
     if ($this->phrases) {
         $clause .= ' and (';
         foreach ($this->phrases as $i => $phrase) {
             $where_params[":body{$letter_table[1]}" . $i] = '%' . strtolower($phrase) . '%';
             if ($i > 0) {
                 $clause .= $where_operator;
             }
             $clause .= " lower({$letter_table[1]}.{$text_field}) like :body{$letter_table[1]}{$i}";
         }
         $clause .= ' )';
     }
     if ($this->author_id) {
         if (!($author = User::model()->findByPk($this->author_id))) {
             throw new Exception("User not found: {$this->author_id}");
         }
         if ($type == 'Correspondence') {
             $clause .= " AND {$letter_table[1]}.created_user_id = :authorID";
             $where_params[':authorID'] = $this->author_id;
             $clause .= " OR lower({$letter_table[1]}.footer) LIKE :authorName";
             $where_params[':authorName'] = '%' . strtolower($author->fullName) . '%';
         } else {
             $clause .= " and lower({$letter_table[1]}.{$text_field}) like :authorName";
             $where_params[':authorName'] = '%' . strtolower($author->fullName) . '%';
         }
     }
     $where_clauses[] = $clause . ' )';
     $select[] = "{$letter_table[1]}.id as {$letter_table[1]}id";
     if ($type == 'Correspondence') {
         $select[] = "{$letter_table[1]}.event_id";
     } else {
         $select[] = "{$letter_table[1]}.event_id as l2_event_id";
     }
 }