model() public static method

Returns the static model of the specified AR class.
public static model ( $className = __CLASS__ ) : Institution
return Institution the static model class
 /**
  * Edits or adds a Procedure.
  *
  * @param bool|int $id
  *
  * @throws CHttpException
  */
 public function actionEdit($id = false)
 {
     if ($id) {
         $this->admin->setModelId($id);
     }
     $this->admin->setEditFields(array('name' => 'text', 'siteLetterStrings' => array('widget' => 'RelationList', 'relation' => 'siteLetterStrings', 'action' => 'OphCoCorrespondence/oeadmin/snippet', 'search' => array('site_id' => array('type' => 'dropdown', 'options' => CHtml::listData(Institution::model()->getCurrent()->sites, 'id', 'short_name'), 'default' => Yii::app()->session['selected_site_id'])), 'listFields' => array('display_order', 'name', 'body', 'element_type.name', 'eventTypeName'))));
     $this->admin->editModel();
 }
Example #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();
 }
 public function actionEditContact()
 {
     if (!($patient = Patient::model()->findByPk(@$_POST['patient_id']))) {
         throw new Exception("Patient not found: " . @$_POST['patient_id']);
     }
     if (!($contact = Contact::model()->findByPk(@$_POST['contact_id']))) {
         throw new Exception("Contact not found: " . @$_POST['contact_id']);
     }
     if (@$_POST['site_id']) {
         if (!($site = Site::model()->findByPk(@$_POST['site_id']))) {
             throw new Exception("Site not found: " . @$_POST['site_id']);
         }
         if (!($cl = ContactLocation::model()->find('contact_id=? and site_id=?', array($contact->id, $site->id)))) {
             $cl = new ContactLocation();
             $cl->contact_id = $contact->id;
             $cl->site_id = $site->id;
             if (!$cl->save()) {
                 throw new Exception("Unable to save contact location: " . print_r($cl->getErrors(), true));
             }
         }
     } else {
         if (!($institution = Institution::model()->findByPk(@$_POST['institution_id']))) {
             throw new Exception("Institution not found: " . @$_POST['institution_id']);
         }
         if (!($cl = ContactLocation::model()->find('contact_id=? and institution_id=?', array($contact->id, $institution->id)))) {
             $cl = new ContactLocation();
             $cl->contact_id = $contact->id;
             $cl->institution_id = $institution->id;
             if (!$cl->save()) {
                 throw new Exception("Unable to save contact location: " . print_r($cl->getErrors(), true));
             }
         }
     }
     if (!($pca = PatientContactAssignment::model()->findByPk(@$_POST['pca_id']))) {
         throw new Exception("PCA not found: " . @$_POST['pca_id']);
     }
     $pca->location_id = $cl->id;
     if (!$pca->save()) {
         throw new Exception("Unable to save patient contact assignment: " . print_r($pca->getErrors(), true));
     }
     $this->redirect(array('/patient/view/' . $patient->id));
 }
 /**
  * Displays the login page
  */
 public function actionLogin()
 {
     if (!Yii::app()->user->isGuest) {
         $this->redirect('/');
         Yii::app()->end();
     }
     if (Yii::app()->params['required_user_agent'] && !preg_match(Yii::app()->params['required_user_agent'], @$_SERVER['HTTP_USER_AGENT'])) {
         if (!Yii::app()->params['required_user_agent_message']) {
             throw new Exception('You must define the required_user_agent_message parameter.');
         }
         return $this->render('login_wrong_browser');
     }
     $model = new LoginForm();
     // collect user input data
     if (isset($_POST['LoginForm'])) {
         $model->attributes = $_POST['LoginForm'];
         // validate user input and redirect to the previous page if valid
         if ($model->validate() && $model->login()) {
             // Flag site for confirmation
             Yii::app()->session['confirm_site_and_firm'] = true;
             $this->redirect(Yii::app()->user->returnUrl);
         }
     }
     $institution = Institution::model()->getCurrent();
     $criteria = new CDbCriteria();
     $criteria->compare('institution_id', $institution->id);
     $criteria->order = 'short_name asc';
     // display the login form
     $this->render('login', array('model' => $model));
 }
 public function actionConformance()
 {
     $statement = new \services\FhirConformanceStatement(array('publisher' => Institution::model()->getCurrent()->name, 'date' => new \services\Date(), 'description' => 'OpenEyes at ' . Institution::model()->getCurrent()->short_name, 'url' => $this->createAbsoluteUrl('api/'), 'fhir_version' => self::FHIR_VERSION, 'accept_unknown' => true, 'profiles' => Yii::app()->service->listFhirSupportedProfiles(), 'server_resources' => Yii::app()->service->describeFhirServerResources()));
     $this->sendResource($statement);
 }
 public function actionDeleteDataSources()
 {
     if (!empty($_POST['source'])) {
         foreach ($_POST['source'] as $source_id) {
             if (Institution::model()->find('source_id=?', array($source_id))) {
                 echo "0";
                 return;
             }
             if (Site::model()->find('source_id=?', array($source_id))) {
                 echo "0";
                 return;
             }
             if (Person::model()->find('source_id=?', array($source_id))) {
                 echo "0";
                 return;
             }
         }
         foreach ($_POST['source'] as $source_id) {
             if ($source = ImportSource::model()->findByPk($source_id)) {
                 if (!$source->delete()) {
                     throw new Exception("Unable to delete import source: " . print_r($source->getErrors(), true));
                 }
             }
         }
         Audit::add('admin-DataSource', 'delete');
     }
     echo "1";
 }
Example #7
0
 public function getNotSelectedSiteList()
 {
     $site_ids = array();
     foreach ($this->siteSelections as $site) {
         $site_ids[] = $site->id;
     }
     $criteria = new CDbCriteria();
     $criteria->compare('institution_id', Institution::model()->getCurrent()->id);
     $criteria->compare('active', 1);
     $criteria->addNotInCondition('id', $site_ids);
     $criteria->order = 'name asc';
     return Site::model()->findAll($criteria);
 }
 public function actionAddSite()
 {
     if (@$_POST['site_id'] == 'all') {
         $sites = Institution::model()->getCurrent()->sites;
     } else {
         $sites = Site::model()->findAllByPk(@$_POST['site_id']);
     }
     foreach ($sites as $site) {
         if (!($us = UserSite::model()->find('site_id=? and user_id=?', array($site->id, Yii::app()->user->id)))) {
             $us = new UserSite();
             $us->site_id = $site->id;
             $us->user_id = Yii::app()->user->id;
             if (!$us->save()) {
                 throw new Exception("Unable to save UserSite: " . print_r($us->getErrors(), true));
             }
         }
     }
     echo "1";
 }
							</div>
						</div>

						<div class="row field-row">
							<div class="<?php 
    echo $form->columns('label');
    ?>
">
								<div class="label">Institution:</div>
							</div>
							<div class="<?php 
    echo $form->columns('field');
    ?>
">
								<?php 
    echo CHtml::dropDownList('institution_id', '', CHtml::listData(Institution::model()->active()->findAll(array('order' => 'name')), 'id', 'name'), array('empty' => '- Select -'));
    ?>
							</div>
						</div>

						<div class="row field-row siteID">
							<div class="<?php 
    echo $form->columns('label');
    ?>
">
								<div class="label">Site:</div>
							</div>
							<div class="<?php 
    echo $form->columns('field');
    ?>
">
Example #10
0
 /**
  * @expectedException Exception
  * @expectedExceptionMessage Institution with code 'bar' not found
  */
 public function testGetCurrent_NotFound()
 {
     Yii::app()->params['institution_code'] = 'bar';
     Institution::model()->getCurrent();
 }
 public function run()
 {
     $model = new SiteAndFirmForm();
     $user = User::model()->findByPk(Yii::app()->user->id);
     if (isset($_POST['SiteAndFirmForm'])) {
         $model->attributes = $_POST['SiteAndFirmForm'];
         if ($model->validate()) {
             $user->changeFirm($model->firm_id);
             $user->last_site_id = $model->site_id;
             if (!$user->save(false)) {
                 throw new CException('Error saving user');
             }
             $user->audit('user', 'change-firm', $user->last_firm_id);
             Yii::app()->session['selected_site_id'] = $model->site_id;
             $this->controller->selectedSiteId = $model->site_id;
             Yii::app()->session['selected_firm_id'] = $model->firm_id;
             $this->controller->selectedFirmId = $model->firm_id;
             Yii::app()->session['confirm_site_and_firm'] = false;
             Yii::app()->event->dispatch('firm_changed', array('firm_id' => $model->firm_id));
             $firm = Firm::model()->findByPk($model->firm_id);
             $subspecialty_id = $firm->serviceSubspecialtyAssignment ? $firm->serviceSubspecialtyAssignment->subspecialty_id : null;
             if ($this->patient && ($episode = $this->patient->getOpenEpisodeOfSubspecialty($subspecialty_id))) {
                 Yii::app()->session['episode_hide_status'] = array($episode->id => 1);
             }
             // Redirect browser to clear POST
             $this->controller->redirect($this->returnUrl);
             Yii::app()->end();
         }
     } else {
         $model->firm_id = Yii::app()->session['selected_firm_id'];
         $model->site_id = Yii::app()->session['selected_site_id'];
     }
     if (!($sites = $user->siteSelections)) {
         $sites = Institution::model()->getCurrent()->sites;
     }
     $user_firm_ids = array();
     if (Yii::app()->params['profile_user_can_edit']) {
         // firm selections only apply when the user is able to change them.
         // if firms should be restricted then this should be done through UserFirmRights
         foreach ($user->firmSelections as $firm) {
             $user_firm_ids[] = $firm->id;
         }
     }
     $firms = array();
     if ($preferred_firms = $user->preferred_firms) {
         foreach ($preferred_firms as $preferred_firm) {
             if ($preferred_firm->active && (count($user_firm_ids) === 0 || in_array($preferred_firm->id, $user_firm_ids)) && (!$this->subspecialty || $preferred_firm->serviceSubspecialtyAssignment && $this->subspecialty->id == $preferred_firm->serviceSubspecialtyAssignment->subspecialty_id)) {
                 if ($preferred_firm->serviceSubspecialtyAssignment) {
                     $firms['Recent'][$preferred_firm->id] = "{$preferred_firm->name} ({$preferred_firm->serviceSubspecialtyAssignment->subspecialty->name})";
                 } else {
                     $firms['Recent'][$preferred_firm->id] = "{$preferred_firm->name}";
                 }
             }
         }
     }
     foreach ($this->controller->firms as $firm_id => $firm_label) {
         if ((count($user_firm_ids) === 0 || in_array($firm_id, $user_firm_ids)) && !isset($firms['Recent'][$firm_id])) {
             $firm = Firm::model()->findByPk($firm_id);
             if ($firm->active && (!$this->subspecialty || $firm->serviceSubspecialtyAssignment && $firm->serviceSubspecialtyAssignment->subspecialty_id == $this->subspecialty->id)) {
                 if ($preferred_firms) {
                     $firms['Other'][$firm_id] = $firm_label;
                 } else {
                     $firms[$firm_id] = $firm_label;
                 }
             }
         }
     }
     $this->render('SiteAndFirmWidget', array('model' => $model, 'firms' => $firms, 'sites' => CHtml::listData($sites, 'id', 'short_name')));
 }
Example #12
0
 public function getLongListForCurrentInstitution()
 {
     $institution = Institution::model()->getCurrent();
     $result = array();
     foreach ($institution->sites as $site) {
         $site_name = '';
         if ($institution->short_name && $site->name != 'Unknown') {
             $site_name = $institution->short_name . ' at ';
         }
         $site_name .= $site->name;
         if ($site->location) {
             $site_name .= ', ' . $site->location;
         }
         $result[$site->id] = $site_name;
     }
     return $result;
 }
Example #13
0
 /**
  * Element based name and value pair.
  *
  * @param \Event $event
  * @return array
  */
 protected function getStructuredDataForPrintPDF($event)
 {
     $data = array();
     $elements_array = array('Clinical', 'Clerical', 'ConsentSignature', 'Demographics');
     foreach ($elements_array as $el_name) {
         $element = $this->{"get{$el_name}ElementForEvent"}($event);
         if (method_exists($element, 'getStructuredDataForPrint')) {
             $data = array_merge($data, $element->getStructuredDataForPrint());
         }
     }
     $address = \Institution::model()->getCurrent()->getLetterAddress(array('include_name' => false, 'delimiter' => '\\n'));
     $data['hospitalAddress'] = \Helper::lineLimit($address, 2, 1, '\\n');
     $data['hospitalAddressMultiline'] = \Helper::lineLimit($address, 4, 1, '\\n');
     $data['hospitalNumber'] = $event->episode->patient->hos_num;
     return $data;
 }
Example #14
0
 public function getLongListForCurrentInstitution()
 {
     $institution = Institution::model()->getCurrent();
     $display_query = SettingMetadata::model()->findByAttributes(array('key' => 'display_institution_name'));
     $display_institution = $display_query->getSettingName();
     $result = array();
     foreach ($institution->sites as $site) {
         $site_name = '';
         if ($institution->short_name && $site->name != 'Unknown') {
             if ($display_institution) {
                 $site_name = $institution->short_name . ' at ';
             }
         }
         $site_name .= $site->name;
         if ($site->location) {
             $site_name .= ', ' . $site->location;
         }
         $result[$site->id] = $site_name;
     }
     return $result;
 }