model() public static méthode

Returns the static model of the specified AR class.
public static model ( $className = __CLASS__ ) : EventType
Résultat EventType the static model class
 /**
  * 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;
 }
 /**
  * @return \EventType
  */
 protected function getEventType()
 {
     if (!isset($this->event_type)) {
         $this->event_type = \EventType::model()->findByAttributes(array('class_name' => 'OphCoCvi'));
     }
     return $this->event_type;
 }
 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;
 }
Exemple #4
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;
 }
 /**
  * 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();
 }
Exemple #6
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);
 }
 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);
     }
 }
 /**
  * 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();
 }
 /**
  * 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();
 }
 /**
  * @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());
 }
 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";
     }
 }
 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;
 }
Exemple #14
0
 /**
  * get list data of all the currently active event types
  *
  * @return array
  */
 public function getActiveList()
 {
     $criteria = new CDbCriteria();
     $criteria->distinct = true;
     $criteria->select = 'event_type_id';
     $event_type_ids = array();
     foreach (Event::model()->findAll($criteria) as $event) {
         $event_type_ids[] = $event->event_type_id;
     }
     $criteria = new CDbCriteria();
     $criteria->addInCondition('id', $event_type_ids);
     $criteria->order = 'name asc';
     return CHtml::listData(EventType::model()->findAll($criteria), 'id', 'name');
 }
Exemple #15
0
$this->widget('zii.widgets.jui.CJuiAutoComplete', array('id' => 'user', 'name' => 'user', 'value' => '', 'sourceUrl' => array('audit/users'), 'options' => array('minLength' => '3'), 'htmlOptions' => array('placeholder' => 'Type to search for users...')));
?>
									</td>
									<td>
										<?php 
echo CHtml::dropDownList('action', @$_POST['action'], CHtml::listData(AuditAction::model()->findAll(array('order' => 'name')), 'id', 'name'), array('empty' => 'All actions'));
?>
									</td>
									<td>
										<?php 
echo CHtml::dropDownList('target_type', @$_POST['target_type'], CHtml::listData(AuditType::model()->findAll(array('order' => 'name')), 'id', 'name'), array('empty' => 'All targets'));
?>
									</td>
									<td>
										<?php 
echo CHtml::dropDownList('event_type_id', @$_POST['event_type_id'], EventType::model()->getEventTypeInUseList(), array('empty' => 'All event types'));
?>
									</td>
								</tr>
							</tbody>
						</table>
					</div>
				</div>

				<div class="row">
					<div class="large-10 column">
						<div class="search-filters-extra audit-filters clearfix">
							<fieldset class="inline highlight">
								<label class="inline" for="date_from">From:</label>
								<?php 
$this->widget('zii.widgets.jui.CJuiDatePicker', array('name' => 'date_from', 'id' => 'date_from', 'options' => array('showAnim' => 'fold', 'dateFormat' => Helper::NHS_DATE_FORMAT_JS), 'value' => @$_POST['date_from'], 'htmlOptions' => array('class' => 'small fixed-width')));
			<?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());
}
		<?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 actionImport($importDir, $archiveDir, $errorDir, $dupDir, $interval = 'PT45M', $pasImport = false)
 {
     $this->importDir = $this->checkSeparator($importDir);
     $this->archiveDir = $this->checkSeparator($archiveDir);
     $this->errorDir = $this->checkSeparator($errorDir);
     $this->dupDir = $this->checkSeparator($dupDir);
     $this->interval = $interval;
     $fhirMarshal = Yii::app()->fhirMarshal;
     $eventType = EventType::model()->find('class_name=:class_name', array(':class_name' => 'OphInVisualfields'));
     if (!$eventType) {
         echo 'Cannot find OphInVisualfields event type, cannot continue' . PHP_EOL;
         die;
     }
     echo 'Processing FMES files...' . PHP_EOL;
     $filenames = glob($this->importDir . '/*.fmes');
     echo count($filenames) . " files to process\n";
     foreach ($filenames as $file) {
         try {
             $basename = basename($file);
             echo $basename . PHP_EOL;
             // First check the file has not already been imported:
             $field = file_get_contents($file);
             $fieldObject = $fhirMarshal->parseXml($field);
             if ($protected_file = ProtectedFile::model()->find('name=:name', array(':name' => $fieldObject->file_reference))) {
                 echo '- ProtectedFile exists (' . $protected_file->id . ')' . PHP_EOL;
                 $this->move($this->dupDir, $file);
                 continue;
             }
             // Extract the patient number
             $matches = array();
             preg_match('/__OE_PATIENT_ID_([0-9]*)__/', $field, $matches);
             if (count($matches) < 2) {
                 echo '- Failed to extract patient ID' . PHP_EOL;
                 $this->move($this->errorDir, $file);
                 continue;
             }
             $match = str_pad($matches[1], 7, '0', STR_PAD_LEFT);
             // Fetch the patient
             if ($pasImport) {
                 $model = new Patient(null);
                 $model->hos_num = $match;
                 $results = $model->search()->getData();
                 $patient = reset($results);
             } else {
                 $patient = Patient::model()->find('hos_num=:hos_num', array(':hos_num' => $match));
             }
             if (!$patient) {
                 echo "- Failed to find patient ({$match})" . PHP_EOL;
                 $this->move($this->errorDir, $file);
                 continue;
             }
             $pid = $patient->id;
             $field = preg_replace('/__OE_PATIENT_ID_([0-9]*)__/', $pid, $field);
             // Convert to measurement
             $resource_type = 'MeasurementVisualFieldHumphrey';
             $service = Yii::app()->service->getService($resource_type);
             $fieldObject = $fhirMarshal->parseXml($field);
             $tx = Yii::app()->db->beginTransaction();
             $ref = $service->fhirCreate($fieldObject);
             $tx->commit();
             $refId = $ref->getId();
             $measurement = OphInVisualfields_Field_Measurement::model()->findByPk($refId);
             $study_datetime = $measurement->study_datetime;
             // Check for existing legacy events
             if (!($episode = Episode::model()->find('legacy = 1 AND patient_id = :patient_id', array(':patient_id' => $pid)))) {
                 echo '- No legacy episode found, creating...';
                 $episode = new Episode();
                 $episode->legacy = 1;
                 $episode->patient_id = $pid;
                 $episode->save();
                 echo 'done' . PHP_EOL;
                 // As there are no previous legacy events, we can create a new event
                 $this->newEvent($episode, $eventType, $measurement);
                 $this->move($this->archiveDir, $file);
             } else {
                 // There is a legacy episode, so there may be unmatched legacy field events
                 $criteria = new CdbCriteria();
                 $criteria->condition = 'event_type_id = :event_type_id and t.deleted = 0 and ep.deleted = 0 and ep.legacy = 1 and ep.patient_id = :patient_id';
                 $criteria->join = 'join episode ep on ep.id = t.episode_id';
                 $criteria->order = 't.event_date desc';
                 $criteria->params = array(':patient_id' => $pid, ':event_type_id' => $eventType->id);
                 if ($this->interval) {
                     // we're looking for all events that are bound to a legacy episode,
                     // for the given patient, looking for the last created test -
                     // this accounts for multiple tests per eye - the implication
                     // being that the newest test overrides the last test for the same eye
                     // (e.g. when a mistake is made and the test is re-ran):
                     // Base time on interval defined by user, a narrow time slot that the test falls within
                     $startCreatedTime = new DateTime($study_datetime);
                     $endCreatedTime = new DateTime($study_datetime);
                     $startCreatedTime->sub(new DateInterval($this->interval));
                     $endCreatedTime->add(new DateInterval($this->interval));
                     $criteria->condition .= ' AND t.event_date >= STR_TO_DATE("' . $startCreatedTime->format('Y-m-d H:i:s') . '", "%Y-%m-%d %H:%i:%s") AND t.event_date <= STR_TO_DATE("' . $endCreatedTime->format('Y-m-d H:i:s') . '", "%Y-%m-%d %H:%i:%s")';
                 }
                 // Of events, there can only be one or none:
                 // FIXME: This can return multiple events, so how do we choose?
                 $events = Event::model()->findAll($criteria);
                 if (count($events) == 1) {
                     echo '- Found existing event (' . $events[0]->id . ')' . PHP_EOL;
                     $element = Element_OphInVisualfields_Image::model()->find('event_id = :event_id', array(':event_id' => $events[0]->id));
                     $side = strtolower($measurement->eye->name);
                     if ($existing = $element->{"{$side}_field"}) {
                         if ($measurement->study_datetime > $existing->study_datetime) {
                             echo "Newer than existing measurement on {$side}, overwriting\n";
                             $element->{"{$side}_field_id"} = $measurement->id;
                             $unattached = $existing;
                         } else {
                             echo "Older than existing measurement on {$side}, ignoring\n";
                             $unattached = $measurement;
                         }
                         // Add dummy reference for the unattached measurement
                         $ref = new MeasurementReference();
                         $ref->patient_measurement_id = $unattached->getPatientMeasurement()->id;
                         $ref->save();
                     } else {
                         echo "No existing measurement on {$side}, adding\n";
                         $element->{"{$side}_field_id"} = $measurement->id;
                     }
                     $element->save();
                     $this->move($this->archiveDir, $file);
                 } elseif (count($events) > 1) {
                     echo '- Found more than one matching event, cannot attach' . PHP_EOL;
                     $this->move($this->errorDir, $file);
                 } else {
                     // No events in match window, so we create a new one
                     $this->newEvent($episode, $eventType, $measurement);
                     $this->move($this->archiveDir, $file);
                 }
             }
         } catch (Exception $ex) {
             echo $ex . PHP_EOL;
             if (@$tx && $tx->active) {
                 echo '- rolling back tx' . PHP_EOL;
                 $tx->rollback();
             }
             $this->move($this->errorDir, $file);
         }
     }
 }
Exemple #19
0
 /**
  * @return \CActiveRecord
  *
  * @throws \CDbException
  */
 protected function getEventType()
 {
     $eventType = \EventType::model()->findByAttributes(array('class_name' => 'OphCoMessaging'));
     if (!$eventType) {
         throw new \CDbException('Event Type for messaging not found');
     }
     return $eventType;
 }
 /**
  * Returns the Opertion notes belongs to a patient.
  *
  * @return array list of op notes
  */
 public function getOperationNoteList()
 {
     $patient_id = \Yii::app()->request->getParam('patient_id');
     if (!$patient_id) {
         $patient_id = $this->event->episode->patient->id;
     }
     $response = array();
     if ($patient_id) {
         $short_format = array();
         $event_type = \EventType::model()->find("name = 'Operation Note'");
         $criteria = new \CDbCriteria();
         $event = new \Event();
         $criteria->addCondition('patient_id = :patient_id');
         $criteria->addCondition('event_type_id = :event_type_id');
         $criteria->params['patient_id'] = $patient_id;
         $criteria->params['event_type_id'] = $event_type->id;
         $criteria->order = 't.created_date DESC';
         $eventLists = $event->with('episode')->findAll($criteria);
         foreach ($eventLists as $event) {
             $procedureListModel = new \Element_OphTrOperationnote_ProcedureList();
             $criteria = new \CDbCriteria();
             $criteria->addCondition('event_id = :event_id');
             $criteria->params['event_id'] = $event->id;
             $procedureList = $procedureListModel->findAll($criteria);
             $date = new \DateTime($event->created_date);
             $name = $date->format('d M Y') . ' ';
             $short_format = array();
             foreach ($procedureList as $procesdures) {
                 $name .= ($procesdures->eye_id != \Eye::BOTH ? $procesdures->eye->name : '') . ' ';
                 foreach ($procesdures->procedures as $procesdure) {
                     $short_format[] = $procesdure->short_format;
                 }
                 $name .= implode(' + ', $short_format);
                 if (strlen($name) > 60) {
                     $name = substr($name, 0, 57);
                     $name .= '...';
                 }
             }
             $response[$event->id] = $name;
         }
     }
     return $response;
 }
>
									<span class="icon-button-small-plus-sign"></span>
									Add event
								</button>

								<?php 
                $ssa = $episode->firm ? $episode->firm->serviceSubspecialtyAssignment : null;
                $subspecialty_data = $ssa ? array_intersect_key($ssa->subspecialty->attributes, array_flip(array('id', 'name'))) : array();
                if ($enabled) {
                    ?>
									<script type="text/html" id="add-new-event-template" data-specialty='<?php 
                    echo json_encode($subspecialty_data);
                    ?>
'>
										<?php 
                    $this->renderPartial('//patient/add_new_event', array('episode' => $episode, 'subspecialty' => @$ssa->subspecialty, 'patient' => $this->patient, 'eventTypes' => EventType::model()->getEventTypeModules()));
                    ?>
									</script>
								<?php 
                }
                ?>
							<?php 
            }
            ?>

							<ol class="events">
								<?php 
            foreach ($episode->events as $event) {
                $highlight = false;
                if (isset($this->event) && $this->event->id == $event->id) {
                    $highlight = TRUE;
Exemple #22
0
 public function actionAddElementTypeToWorkflowStep()
 {
     $et_exam = \EventType::model()->find('class_name=?', array('OphCiExamination'));
     if (!($element_type = \ElementType::model()->find('event_type_id = ? and id = ?', array($et_exam->id, @$_POST['element_type_id'])))) {
         throw new \Exception('Unknown examination element type: ' . @$_POST['element_type_id']);
     }
     if (!($step = models\OphCiExamination_ElementSet::model()->findByPk(@$_POST['step_id']))) {
         throw new \Exception('Unknown element set: ' . @$_POST['step_id']);
     }
     if (!models\OphCiExamination_ElementSetItem::model()->find('set_id=? and element_type_id=?', array($step->id, $element_type->id))) {
         $item = new models\OphCiExamination_ElementSetItem();
         $item->set_id = $step->id;
         $item->element_type_id = $element_type->id;
         if (!$item->save()) {
             throw new \Exception('Unable to save element set item: ' . print_r($item->getErrors(), true));
         }
     }
     echo '1';
 }
 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";
     }
 }
Exemple #24
0
 public function getEventTypeName()
 {
     $eventType = EventType::model()->findByAttributes(array('class_name' => $this->event_type));
     if ($eventType) {
         return $eventType->name;
     }
     return '';
 }
 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));
 }
 /**
  * Save Risks - because it's part of the History Risk element it need to be saved from that element.
  *
  * @param $element
  * @param $data
  * @param $index
  */
 protected function saveComplexAttributes_Element_OphCiExamination_HistoryRisk($element, $data, $index)
 {
     $event_type = \EventType::model()->find('name=?', array('Examination'));
     $event = $this->episode->getMostRecentEventByType($event_type->id);
     if ($event->id === $this->event->id && (array_key_exists('anticoagulant', $element->attributes) || array_key_exists('alphablocker', $element->attributes))) {
         foreach ($element->attributes as $risk_name => $risk_value) {
             if ($risk_name === 'anticoagulant' || $risk_name === 'alphablocker') {
                 $this->updateRisk($risk_name, $risk_value);
             }
         }
     }
 }
 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));
 }
Exemple #28
0
 public static function add($target, $action, $data = null, $log_message = null, $properties = array())
 {
     if (!($_target = AuditType::model()->find('name=?', array($target)))) {
         $_target = new AuditType();
         $_target->name = $target;
         if (!$_target->save()) {
             throw new Exception("Unable to save audit target: " . print_r($_target->getErrors(), true));
         }
     }
     if (!($_action = AuditAction::model()->find('name=?', array($action)))) {
         $_action = new AuditAction();
         $_action->name = $action;
         if (!$_action->save()) {
             throw new Exception("Unable to save audit action: " . print_r($_action->getErrors(), true));
         }
     }
     $audit = new Audit();
     $audit->type_id = $_target->id;
     $audit->action_id = $_action->id;
     $audit->data = $data;
     if (!isset($properties['user_id'])) {
         if (Yii::app()->session['user']) {
             $properties['user_id'] = Yii::app()->session['user']->id;
         }
     }
     if (isset($properties['module'])) {
         if ($et = EventType::model()->find('class_name=?', array($properties['module']))) {
             $properties['event_type_id'] = $et->id;
         } else {
             if (!($module = AuditModule::model()->find('name=?', array($properties['module'])))) {
                 $module = new AuditModule();
                 $module->name = $properties['module'];
                 if (!$module->save()) {
                     throw new Exception("Unable to create audit_module: " . print_r($module->getErrors(), true));
                 }
             }
             $properties['module_id'] = $module->id;
         }
         unset($properties['module']);
     }
     if (isset($properties['model'])) {
         if (!($model = AuditModel::model()->find('name=?', array($properties['model'])))) {
             $model = new AuditModel();
             $model->name = $properties['model'];
             if (!$model->save()) {
                 throw new Exception("Unable to save audit_model: " . print_r($model->getErrors(), true));
             }
         }
         $properties['model_id'] = $model->id;
         unset($properties['model']);
     }
     foreach ($properties as $key => $value) {
         $audit->{$key} = $value;
     }
     if (!$audit->save()) {
         throw new Exception("Failed to save audit entry: " . print_r($audit->getErrors(), true));
     }
     if (isset($properties['user_id'])) {
         $username = User::model()->findByPk($properties['user_id'])->username;
     }
     $log_message && OELog::log($log_message, @$username);
     return $audit;
 }
 /**
  * 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;
 }
 protected function getApplicationEventTypeID()
 {
     if (!$this->_application_event_type_id) {
         $this->_application_event_type_id = EventType::model()->findByAttributes(array('class_name' => 'OphCoTherapyapplication'))->id;
     }
     return $this->_application_event_type_id;
 }