Ejemplo n.º 1
0
 /**
  * @covers ElementType::search
  */
 public function testSearch()
 {
     $this->model->setAttributes($this->elementtypes('history')->getAttributes());
     $results = $this->model->search();
     $data = $results->getData();
     $expectedKeys = array('history', 'pasthistory');
     $expectedResults = array();
     if (!empty($expectedKeys)) {
         foreach ($expectedKeys as $key) {
             $expectedResults[] = $this->elementtypes($key);
         }
     }
     $this->assertEquals($expectedResults, $data);
 }
Ejemplo n.º 2
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();
 }
 /**
  * Edits or adds a Procedure.
  *
  * @param bool|int $id
  *
  * @throws CHttpException
  */
 public function actionEdit($id = false)
 {
     $admin = new Admin(OEModule\OphCiExamination\models\OphCiExamination_Attribute::model(), $this);
     $admin->setCustomSaveURL('/oeadmin/ExaminationElementAttributes/update');
     if ($id) {
         $admin->setModelId($id);
     }
     $admin->setModelDisplayName('Element Attributes');
     $admin->setEditFields(array('id' => 'label', 'name' => 'text', 'label' => 'text', 'attribute_elements' => array('widget' => 'DropDownList', 'options' => CHtml::listData(ElementType::model()->findAll(), 'id', 'name'), 'htmlOptions' => null, 'hidden' => false, 'layoutColumns' => null)));
     $admin->editModel();
 }
Ejemplo n.º 4
0
 /**
  * Find Elements answers for an ElementType
  * @param ElementType $type
  * @param array $paramters list of any other ElementAnswer parameters to include
  * @param mixed $limit limit results to this many
  * @return array
  */
 public function findByType(ElementType $type, array $parameters = array(), $limit = false)
 {
     $queryBuilder = $this->_em->createQueryBuilder();
     $queryBuilder->add('select', 'ea')->from('Jazzee\\Entity\\ElementAnswer', 'ea');
     $queryBuilder->where('ea.element IN (SELECT e.id FROM Jazzee\\Entity\\Element as e WHERE e.type = :typeId)');
     $queryBuilder->setParameter('typeId', $type->getId());
     $possibleParameters = array('position', 'eShortString', 'eText', 'eDate', 'eInteger', 'eDecimal', 'eBlob');
     foreach ($possibleParameters as $name) {
         if (array_key_exists($name, $parameters)) {
             if ($parameters[$name] === null) {
                 $queryBuilder->andWhere("ea.{$name} IS NULL");
             } else {
                 $queryBuilder->andWhere("ea.{$name} = :{$name}");
                 $queryBuilder->setParameter($name, $parameters[$name]);
             }
         }
     }
     if ($limit) {
         $queryBuilder->setMaxResults($limit);
     }
     return $queryBuilder->getQuery()->getResult();
 }
Ejemplo n.º 5
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();
 }
Ejemplo n.º 6
0
 /**
  * Edits or adds a Procedure.
  *
  * @param bool|int $id
  *
  * @throws CHttpException
  */
 public function actionEdit($id = false)
 {
     $admin = new Admin(Procedure::model(), $this);
     if ($id) {
         $admin->setModelId($id);
     }
     $admin->setEditFields(array('term' => 'text', 'short_format' => 'text', 'default_duration' => 'text', 'snomed_code' => 'text', 'snomed_term' => 'text', 'aliases' => 'text', 'unbooked' => 'checkbox', 'active' => 'checkbox', 'opcsCodes' => array('widget' => 'MultiSelectList', 'relation_field_id' => 'id', 'label' => 'OPCS Code', 'options' => CHtml::encodeArray(CHtml::listData(OPCSCode::model()->findAll(), 'id', function ($model) {
         return $model->name . ': ' . $model->description;
     }))), 'benefits' => array('widget' => 'MultiSelectList', 'relation_field_id' => 'id', 'label' => 'Benefit', 'options' => CHtml::encodeArray(CHtml::listData(Benefit::model()->findAll(), 'id', 'name'))), 'complications' => array('widget' => 'MultiSelectList', 'relation_field_id' => 'id', 'label' => 'Complication', 'options' => CHtml::encodeArray(CHtml::listData(Complication::model()->findAll(), 'id', 'name')))));
     if (isset($admin->getModel()->operationNotes)) {
         $admin->setEditFields(array_merge($admin->getEditFields(), array('operationNotes' => array('widget' => 'MultiSelectList', 'relation_field_id' => 'id', 'label' => 'Operation Note Element', 'options' => CHtml::encodeArray(CHtml::listData(ElementType::model()->findAllByAttributes(array(), 'event_type_id in (select id from event_type where name = "Operation Note")'), 'id', 'name'))))));
     }
     $admin->editModel();
 }
    /**
     * Fetches all the attributes for an element_type filtered by subspecialty
     * Options are stashed in attribute_options property for easy iteration.
     *
     * @param int  $element_type_id
     * @param int  $subspecialty_id
     * @param bool $include_descendents
     *
     * @return OphCiExamination_Attribute[]
     */
    public function findAllByElementAndSubspecialty($element_type_id, $subspecialty_id = null, $include_descendents = true)
    {
        $criteria = new \CDbCriteria();
        $criteria->select = 't.*';
        $criteria->distinct = true;
        $element_type_ids = array($element_type_id);
        if ($include_descendents) {
            $element_type = \ElementType::model()->findByPk($element_type_id);
            foreach ($element_type->getDescendents() as $descendent) {
                $element_type_ids[] = $descendent->id;
            }
        }
        $criteria->addInCondition('attribute_element.element_type_id', $element_type_ids);
        if ($subspecialty_id) {
            $criteria->addCondition('subspecialty_id = :subspecialty_id OR subspecialty_id IS NULL');
            $criteria->params[':subspecialty_id'] = $subspecialty_id;
        } else {
            $criteria->addCondition('subspecialty_id IS NULL');
        }
        $criteria->join = 'JOIN ophciexamination_attribute_element attribute_element ON attribute_element.id = t.attribute_element_id
							JOIN ophciexamination_attribute attribute ON attribute_element.attribute_id = attribute.id';
        $criteria->order = 'attribute.display_order,attribute_element.attribute_id,t.display_order,t.id';
        $all_attribute_options = OphCiExamination_AttributeOption::model()->findAll($criteria);
        $attributes = array();
        $attribute = null;
        $attribute_options = array();
        foreach ($all_attribute_options as $attribute_option) {
            if (!$attribute || $attribute->id != $attribute_option->attribute_element->attribute_id) {
                if ($attribute) {
                    $attribute->attribute_options = array_values($attribute_options);
                    $attribute_options = array();
                    $attributes[] = $attribute;
                }
                $attribute = $attribute_option->attribute_element->attribute;
            }
            $attribute_options[] = $attribute_option;
        }
        if ($attribute) {
            $attribute->attribute_options = array_values($attribute_options);
            $attributes[] = $attribute;
        }
        return $attributes;
    }
Ejemplo n.º 8
0
 /**
  * Get all the element types that are defined for this event type
  *
  * @return BaseEventTypeElement[]
  */
 public function getAllElementTypes()
 {
     $criteria = new CDbCriteria();
     $ids = array($this->id);
     foreach ($this->getParentEventTypes() as $parent) {
         $ids[] = $parent->id;
     }
     $criteria->addInCondition('event_type_id', $ids);
     $criteria->order = 'display_order asc';
     return ElementType::model()->findAll($criteria);
 }
 protected function loadSetting($key)
 {
     $element_type = ElementType::model()->find('class_name=?', array(get_class($this)));
     if (!($metadata = SettingMetadata::model()->find('element_type_id=? and `key`=?', array($element_type->id, $key)))) {
         return false;
     }
     if ($setting = SettingUser::model()->find('user_id=? and element_type_id=? and `key`=?', array(Yii::app()->session['user']->id, $element_type->id, $key))) {
         return $this->parseSetting($setting, $metadata);
     }
     $firm = Firm::model()->findByPk(Yii::app()->session['selected_firm_id']);
     if ($setting = SettingFirm::model()->find('firm_id=? and element_type_id=? and `key`=?', array($firm->id, $element_type->id, $key))) {
         return $this->parseSetting($setting, $metadata);
     }
     if ($subspecialty_id = $firm->getSubspecialtyID()) {
         if ($setting = SettingSubspecialty::model()->find('subspecialty_id=? and element_type_id=? and `key`=?', array($subspecialty_id, $element_type->id, $key))) {
             return $this->parseSetting($setting, $metadata);
         }
     }
     if ($specialty = $firm->getSpecialty()) {
         if ($setting = SettingSpecialty::model()->find('specialty_id=? and element_type_id=? and `key`=?', array($specialty->id, $element_type->id, $key))) {
             return $this->parseSetting($setting, $metadata);
         }
     }
     $site = Site::model()->findByPk(Yii::app()->session['selected_site_id']);
     if ($setting = SettingSite::model()->find('site_id=? and element_type_id=? and `key`=?', array($site->id, $element_type->id, $key))) {
         return $this->parseSetting($setting, $metadata);
     }
     if ($setting = SettingInstitution::model()->find('institution_id=? and element_type_id=? and `key`=?', array($site->institution_id, $element_type->id, $key))) {
         return $this->parseSetting($setting, $metadata);
     }
     if ($setting = SettingInstallation::model()->find('element_type_id=? and `key`=?', array($element_type->id, $key))) {
         return $this->parseSetting($setting, $metadata);
     }
     return $metadata->default_value;
 }
Ejemplo n.º 10
0
 public function addElementType(ElementType $e)
 {
     $this->elementTypes[$e->getCode()] = $e;
 }
Ejemplo n.º 11
0
 public function getSetting($key)
 {
     $setting = SettingMetadata::model()->getSetting($key, ElementType::model()->find('class_name=?', array(get_class($this))));
     if (!$setting) {
         $setting = SettingMetadata::model()->getSetting($key, ElementType::model()->find('class_name=?', array(get_parent_class($this))));
     }
     return $setting;
 }
Ejemplo n.º 12
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));
 }
 /**
  *
  * returns all the elements from the most recent examination of the patient in the given episode
  *
  * @param \Patient $patient
  * @param \Episode $episode
  * @return \ElementType[] - array of various different element type objects
  */
 public function getElementsForLatestEventInEpisode($patient, $episode)
 {
     $element_types = array();
     $event_type = $this->getEventType();
     if ($event_type && ($event = $this->getMostRecentEventInEpisode($episode->id, $event_type->id))) {
         $criteria = new \CDbCriteria();
         $criteria->compare('event_type_id', $event_type->id);
         $criteria->order = 'display_order';
         foreach (\ElementType::model()->findAll($criteria) as $element_type) {
             $class = $element_type->class_name;
             if ($element = $class::model()->find('event_id=?', array($event->id))) {
                 if (method_exists($element, 'getLetter_string')) {
                     $element_types[] = $element_type;
                 }
             }
         }
     }
     return $element_types;
 }
Ejemplo n.º 14
0
 /**
  * @return array
  */
 protected function cataractProcedures()
 {
     $cataractProcedures = array();
     $cataractElement = \ElementType::model()->findByAttributes(array('name' => 'Cataract'));
     if ($cataractElement) {
         $procedure = new \Procedure();
         $cataractProcedures = $procedure->getProceduresByOpNote($cataractElement['id']);
     }
     return $cataractProcedures;
 }
Ejemplo n.º 15
0
 public function getElementTypeName()
 {
     $elementType = ElementType::model()->findByAttributes(array('class_name' => $this->element_type));
     if ($elementType) {
         return $elementType->name;
     }
     return '';
 }
Ejemplo n.º 16
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';
 }
Ejemplo n.º 17
0
    $event_type_id = $_GET['event_type_id'];
} else {
    $event_type_id = @$_REQUEST['EventTypeModuleEventType'];
}
?>
<div class="giiElementContainer" style="margin-bottom: 10px;">
	<div class="giiElement" style="background:#eee;border:1px solid #999;padding:5px;">
		<label>Select the element to add fields to</label>
		<h4 style="margin-bottom: 0;">
			<select class="elementToAddFieldsTo" name="elementId<?php 
echo $element_num;
?>
">
				<option value="">- Please select -</option>
				<?php 
foreach (ElementType::model()->findAll('event_type_id=?', array($event_type_id)) as $element_type) {
    ?>
					<option value="<?php 
    echo $element_type->id;
    ?>
"<?php 
    if (@$_POST['elementId' . $element_num] == $element_type->id) {
        ?>
 selected="selected"<?php 
    }
    ?>
><?php 
    echo $element_type->name;
    ?>
</option>
				<?php 
Ejemplo n.º 18
0
    public function actionCreateNewBlock(){
        $model = new LectureElement();

        $idType = Yii::app()->request->getPost('type');
        $htmlBlock = Yii::app()->request->getPost('newTextBlock');
        $model->id_lecture = Yii::app()->request->getPost('idLecture');
        $model->block_order = Yii::app()->request->getPost('order');

        switch ($idType){
            case '2':
                 //if we want to load video, we finding video link
                $tempArray = explode(" ", $htmlBlock);
                for ($i = count($tempArray)-1; $i > 0; $i--) {
                    if ($this->startsWith($tempArray[$i], 'src="')) {
                        $link = substr($tempArray[$i], 5, strlen($tempArray[$i]) - 1);
                        $model->html_block = $link;
                    }
                }
                break;
            case '9':
                $tempArray = explode(" ", $htmlBlock);
                for ($i = count($tempArray)-1; $i > 0; $i--) {
                    if ($this->startsWith($tempArray[$i], 'src="')) {
                        $link = substr($tempArray[$i], 5, strlen($tempArray[$i]) - 6);
                        $model->html_block = $link;
                    }
                }
                break;
            default:
                $model->html_block = $htmlBlock;
        }

        $model->id_type = $idType;
        $model->type = ElementType::model()->findByPk($idType)->type;

        $model->save();
        $this->redirect(Yii::app()->request->urlReferrer);
    }
Ejemplo n.º 19
0
 /**
  * Processes provided form data to create 1 or more elements of the provided type.
  *
  * @param ElementType $element_type
  * @param $data
  * @return array
  * @throws Exception
  */
 protected function getElementsForElementType(ElementType $element_type, $data)
 {
     $elements = array();
     $el_cls_name = $element_type->class_name;
     $f_key = CHtml::modelName($el_cls_name);
     if (isset($data[$f_key])) {
         $keys = array_keys($data[$f_key]);
         if (is_array($data[$f_key][$keys[0]]) && !count(array_filter(array_keys($data[$f_key]), 'is_string'))) {
             // there is more than one element of this type
             $pk_field = $el_cls_name::model()->tableSchema->primaryKey;
             foreach ($data[$f_key] as $i => $attrs) {
                 if (!$this->event->isNewRecord && !isset($attrs[$pk_field])) {
                     throw new Exception('missing primary key field for multiple elements for editing an event');
                 }
                 if ($pk = @$attrs[$pk_field]) {
                     $element = $el_cls_name::model()->findByPk($pk);
                 } else {
                     $element = $element_type->getInstance();
                 }
                 $element->attributes = Helper::convertNHS2MySQL($attrs);
                 $this->setElementComplexAttributesFromData($element, $data, $i);
                 $element->event = $this->event;
                 $elements[] = $element;
             }
         } else {
             if ($this->event->isNewRecord || !($element = $el_cls_name::model()->find('event_id=?', array($this->event->id)))) {
                 $element = $element_type->getInstance();
             }
             $element->attributes = Helper::convertNHS2MySQL($data[$f_key]);
             $this->setElementComplexAttributesFromData($element, $data);
             $element->event = $this->event;
             $elements[] = $element;
         }
     }
     return $elements;
 }
 /**
  * Ensure a principal diagnosis is set for the episode.
  *
  */
 public function afterValidate()
 {
     if (count($this->diagnoses)) {
         $principal = false;
         foreach ($this->diagnoses as $diagnosis) {
             if ($diagnosis->principal) {
                 $principal = true;
             }
         }
         if (!$principal) {
             $this->addError('diagnoses', 'Principal diagnosis required.');
         }
     }
     // This isn't very nice but there isn't a clean alternative at the moment
     $controller = \Yii::app()->getController();
     if ($controller instanceof \BaseEventTypeController) {
         $et_diagnoses = \ElementType::model()->find('class_name=?', array('OEModule\\OphCiExamination\\models\\Element_OphCiExamination_Diagnoses'));
         $children = $controller->getChildElements($et_diagnoses);
         $have_further_findings = false;
         foreach ($controller->getChildElements($et_diagnoses) as $element) {
             if (\CHtml::modelName($element) == 'OEModule_OphCiExamination_models_Element_OphCiExamination_FurtherFindings') {
                 $have_further_findings = true;
             }
         }
         if (!$have_further_findings && !$this->diagnoses) {
             $this->addError('diagnoses', 'Please select at least one diagnosis.');
         }
     }
     parent::afterValidate();
 }
Ejemplo n.º 21
0
 /**
  * returns true if the passed procedure id requires the selection of 'left' or 'right' eye.
  *
  * @param $procedure_id
  *
  * @return bool
  */
 public function procedure_requires_eye($procedure_id)
 {
     foreach ($this->getProcedureSpecificElements($procedure_id) as $plpa) {
         $element_type = ElementType::model()->findByPk($plpa->element_type_id);
         if (in_array($element_type->class_name, array('Element_OphTrOperationnote_Cataract', 'Element_OphTrOperationnote_Buckle', 'Element_OphTrOperationnote_Vitrectomy'))) {
             return true;
         }
     }
     return false;
 }
 /**
  * Ajax method for viewing previous elements
  * @param integer $element_type_id
  * @param integer $patient_id
  * @throws CHttpException
  */
 public function actionViewPreviousElements($element_type_id, $patient_id)
 {
     $element_type = ElementType::model()->findByPk($element_type_id);
     if (!$element_type) {
         throw new CHttpException(404, 'Unknown ElementType');
     }
     $this->patient = Patient::model()->findByPk($patient_id);
     if (!$this->patient) {
         throw new CHttpException(404, 'Unknown Patient');
     }
     // Clear script requirements as all the base css and js will already be on the page
     Yii::app()->assetManager->reset();
     $this->episode = $this->getEpisode();
     $elements = $this->episode->getElementsOfType($element_type);
     $this->renderPartial('_previous', array('elements' => $elements), false, true);
 }
 public function setDefaultOptions()
 {
     $element_type = \ElementType::model()->find('class_name=?', array(get_class($this)));
     $defaults = \SettingMetadata::model()->findAll('element_type_id=? ', array($element_type->id));
     foreach ($defaults as $default) {
         $this->{$default->key} = $default->default_value;
     }
 }
Ejemplo n.º 24
0
 /**
  * Use the examination API to retrieve findings for the patient and element type.
  *
  * @param $patient_id
  * @param $element_type_id
  *
  * @return mixed
  *
  * @throws Exception
  */
 public function process_examination_findings($patient_id, $element_type_id)
 {
     if ($api = Yii::app()->moduleAPI->get('OphCiExamination')) {
         if (!($patient = Patient::model()->findByPk($patient_id))) {
             throw new Exception('Unable to find patient: ' . $patient_id);
         }
         if (!($element_type = ElementType::model()->findByPk($element_type_id))) {
             throw new Exception("Unknown element type: {$element_type_id}");
         }
         if (!($episode = $patient->getEpisodeForCurrentSubspecialty())) {
             throw new Exception('No Episode available for patient: ' . $patient_id);
         }
         return $api->getLetterStringForModel($patient, $episode, $element_type_id);
     }
 }
    public function getMandatoryElementTypes()
    {
        $mandatoryElementTypes = \ElementType::model()->findAll(array('condition' => "event_type.class_name = 'OphCiExamination' AND\n\t\t\t\t\t ophciexamination_element_set_item.is_mandatory = 1", 'join' => 'JOIN event_type ON event_type.id = t.event_type_id
					LEFT JOIN ophciexamination_element_set_item ON (ophciexamination_element_set_item.element_type_id = t.id
					AND ophciexamination_element_set_item.set_id = :set_id)', 'params' => array(':set_id' => $this->id)));
        return $mandatoryElementTypes;
    }
Ejemplo n.º 26
0
 public function handleModuleNameChange($current_class, $target_class)
 {
     @rename(Yii::app()->basePath . '/modules/' . $current_class, Yii::app()->basePath . '/modules/' . $target_class);
     $this->event_type->name = $_POST['EventTypeModuleCode']['moduleSuffix'];
     $this->event_type->class_name = $target_class;
     Yii::app()->db->createCommand()->update("event_type", array('name' => $this->event_type->name, 'class_name' => $target_class, 'event_group_id' => $this->event_group->id), "id = :id", array(":id" => $this->event_type->id));
     foreach (ElementType::model()->findAll('event_type_id=:eventTypeId', array(':eventTypeId' => $this->event_type->id)) as $element_type) {
         $element_class_name = 'Element_' . $target_class . '_' . preg_replace("/ /", "", ucwords(strtolower($element_type->name)));
         Yii::app()->db->createCommand()->update("element_type", array('class_name' => $element_class_name), 'id = :id', array(':id' => $element_type->id));
     }
     foreach (Yii::app()->db->createCommand()->select('version')->from('tbl_migration')->where("version like :current_class", array(':current_class' => '%_$current_class'))->queryAll() as $tbl_migration) {
         $version = str_replace($current_class, $target_class, $tbl_migration['version']);
         Yii::app()->db->createCommand()->update('tbl_migration', array('version' => $version), 'version = :v', array(':v' => $tbl_migration['version']));
     }
     $this->changeAllInstancesOfString(Yii::app()->basePath . '/modules/' . $target_class, $current_class, $target_class);
     $from_table_prefix = 'et_' . strtolower($current_class) . '_';
     $to_table_prefix = 'et_' . strtolower($target_class) . '_';
     $this->changeAllInstancesOfString(Yii::app()->basePath . '/modules/' . $target_class, $from_table_prefix, $to_table_prefix);
     // introspect the database and fix all table, index and foreign key names
     foreach (Yii::app()->getDb()->getSchema()->getTables() as $table_name => $table) {
         if (strncmp($table_name, $from_table_prefix, strlen($from_table_prefix)) == 0) {
             $foreign_keys = $this->getTableForeignKeys($table_name);
             foreach ($foreign_keys as $foreign_key) {
                 if (strncmp($foreign_key['name'], $from_table_prefix, strlen($from_table_prefix)) == 0) {
                     $new_key_name = str_replace($from_table_prefix, $to_table_prefix, $foreign_key['name']);
                     Yii::app()->db->createCommand("ALTER TABLE " . mysql_escape_string($table_name) . " DROP FOREIGN KEY " . mysql_escape_string($foreign_key['name']) . ";")->execute();
                     Yii::app()->db->createCommand("DROP INDEX " . mysql_escape_string($foreign_key['name']) . " ON " . mysql_escape_string($table_name) . ";")->execute();
                     Yii::app()->db->createCommand("CREATE INDEX " . mysql_escape_string($new_key_name) . " ON " . mysql_escape_string($table_name) . " (" . mysql_escape_string($foreign_key['field']) . ")")->execute();
                     Yii::app()->db->createCommand("ALTER TABLE " . mysql_escape_string($table_name) . " ADD FOREIGN KEY " . mysql_escape_string($new_key_name) . " (" . mysql_escape_string($foreign_key['field']) . ") REFERENCES " . mysql_escape_string($foreign_key['remote_table']) . " (" . mysql_escape_string($foreign_key['remote_field']) . ");")->execute();
                 }
             }
             $new_table_name = str_replace($from_table_prefix, $to_table_prefix, $table_name);
             Yii::app()->db->createCommand("RENAME TABLE " . mysql_escape_string($table_name) . " TO " . mysql_escape_string($new_table_name) . ";");
         }
     }
     // update the event_type name in the migrations
     $path = Yii::app()->basePath . '/modules/' . $target_class . '/migrations';
     $dh = opendir($path);
     while ($file = readdir($dh)) {
         if (!preg_match('/^\\.\\.?$/', $file)) {
             $data = file_get_contents($path . "/" . $file);
             if (preg_match_all('/\\$event_type[\\s\\t]*=[\\s\\t]*.*?->queryRow\\(\\);/', $data, $m)) {
                 foreach ($m[0] as $blob) {
                     if (preg_match('/\\(\':name\'[\\s\\t]*=>[\\s\\t]*\'.*?\'\\)/', $blob, $b)) {
                         $newblob = str_replace($b[0], "(':name'=>'{$this->event_type->name}')", $blob);
                         $data = str_replace($blob, $newblob, $data);
                         file_put_contents($path . "/" . $file, $data);
                     }
                 }
             }
         }
     }
     closedir($dh);
     $this->initialise(array('moduleID' => $target_class, 'eventGroupName' => $this->event_group->name));
 }
 /**
  * Customises eye options for this element.
  *
  * @FIXME: Shouldn't be touching the session stuff here if we can help it. Can we operate of the episode firm?
  *
  * @param $table
  *
  * @return array
  */
 public function getEyeOptions()
 {
     $event_type = EventType::model()->find('class_name=?', array('OphTrOperationnote'));
     $element_type = ElementType::model()->find('event_type_id=? and class_name=?', array($event_type->id, 'Element_OphTrOperationnote_ProcedureList'));
     $criteria = new CDbCriteria();
     $criteria->order = 't.display_order asc';
     if (!in_array(Firm::model()->findByPk(Yii::app()->session['selected_firm_id'])->serviceSubspecialtyAssignment->subspecialty->name, array('Adnexal', 'Strabismus'))) {
         $criteria->addCondition('t.id != :three');
         $criteria->params[':three'] = 3;
     }
     return CHtml::listData(Eye::model()->findAll($criteria), 'id', 'name');
 }