model() public static method

Returns the static model of the specified AR class.
public static model ( $className = __CLASS__ ) : Allergy
return Allergy the static model class
 /**
  * @covers BaseActiveRecord::save
  * @todo   Implement testSave().
  */
 public function testSave()
 {
     //using allergy model to test the active record
     $testmodel = new Allergy();
     $testmodel->setAttributes($this->testattributes);
     $testmodel->save();
     $result = Allergy::model()->findByAttributes(array('name' => 'allergy test'))->getAttributes();
     $expected = $this->testattributes;
     $this->assertEquals($expected['name'], $result['name'], 'attribute match');
 }
 /**
  * Edits or adds a Procedure.
  *
  * @param bool|int $id
  *
  * @throws CHttpException
  */
 public function actionEdit($id = false)
 {
     $admin = new Admin(FormularyDrugs::model(), $this);
     if ($id) {
         $admin->setModelId($id);
     }
     $admin->setModelDisplayName('Formulary Drugs');
     $criteria = new CDbCriteria();
     $admin->setEditFields(array('id' => 'label', 'name' => 'text', 'type_id' => array('widget' => 'DropDownList', 'options' => CHtml::listData(DrugType::model()->findAll(), 'id', 'name'), 'htmlOptions' => null, 'hidden' => false, 'layoutColumns' => null), 'aliases' => 'text', 'tallman' => 'text', 'form_id' => array('widget' => 'DropDownList', 'options' => CHtml::listData(DrugForm::model()->findAll(), 'id', 'name'), 'htmlOptions' => null, 'hidden' => false, 'layoutColumns' => null), 'dose_unit' => 'text', 'default_dose' => 'text', 'default_route_id' => array('widget' => 'DropDownList', 'options' => CHtml::listData(DrugRoute::model()->findAll(), 'id', 'name'), 'htmlOptions' => array('empty' => '-- Please select --'), 'hidden' => false, 'layoutColumns' => null), 'default_frequency_id' => array('widget' => 'DropDownList', 'options' => CHtml::listData(DrugFrequency::model()->findAll(), 'id', 'name'), 'htmlOptions' => array('empty' => '-- Please select --'), 'hidden' => false, 'layoutColumns' => null), 'default_duration_id' => array('widget' => 'DropDownList', 'options' => CHtml::listData(DrugDuration::model()->findAll(), 'id', 'name'), 'htmlOptions' => array('empty' => '-- Please select --'), 'hidden' => false, 'layoutColumns' => null), 'preservative_free' => 'checkbox', 'active' => 'checkbox', 'allergy_warnings' => array('widget' => 'MultiSelectList', 'relation_field_id' => 'id', 'label' => 'Allergy Warnings', 'options' => CHtml::encodeArray(CHtml::listData(Allergy::model()->findAll($criteria->condition = "name != 'Other'"), 'id', 'name')))));
     $admin->editModel();
 }
Beispiel #3
0
echo $form->textField($drug, 'tallman', array('autocomplete' => Yii::app()->params['html_autocomplete'], 'disabled' => true));
?>
	<?php 
echo $form->textField($drug, 'aliases', array('autocomplete' => Yii::app()->params['html_autocomplete']));
?>
	<?php 
echo $form->dropDownList($drug, 'type_id', 'DrugType');
?>
	<?php 
echo $form->textField($drug, 'default_dose', array('autocomplete' => Yii::app()->params['html_autocomplete']));
?>
	<?php 
echo $form->textField($drug, 'dose_unit', array('autocomplete' => Yii::app()->params['html_autocomplete']));
?>
	<?php 
echo $form->dropDownList($drug, 'default_frequency_id', 'DrugFrequency', array('empty' => ''));
?>
	<?php 
echo $form->dropDownList($drug, 'default_duration_id', 'DrugDuration', array('empty' => ''));
?>
	<?php 
echo $form->multiSelectList($drug, 'allergies', 'allergies', 'id', CHtml::listData(Allergy::model()->active()->findAll(array('order' => 'name')), 'id', 'name'), null, array('empty' => '', 'label' => 'Allergies'));
?>
	<?php 
echo $form->formActions(array('cancel-uri' => '/admin/drugs'));
?>
	<?php 
$this->endWidget();
?>
</div>
 /**
  * List of allergies
  */
 public function allergyList()
 {
     $allergy_ids = array();
     foreach ($this->patient->allergies as $allergy) {
         $allergy_ids[] = $allergy->id;
     }
     $criteria = new CDbCriteria();
     !empty($allergy_ids) && $criteria->addNotInCondition('id', $allergy_ids);
     $criteria->order = 'name asc';
     return Allergy::model()->active()->findAll($criteria);
 }
 public function testsaveOnlyIfDirty()
 {
     $dirty_allergy_name = 'test allergy modified';
     // make sure this attribute is not in our DB
     Allergy::model()->deleteAllByAttributes($this->testattributes);
     Allergy::model()->deleteAllByAttributes(array('name' => $dirty_allergy_name));
     /* New Model **/
     $allergy = new Allergy();
     $allergy->setAttributes($this->testattributes);
     // test to save a new model
     if (!$allergy->saveOnlyIfDirty()->save()) {
         $this->fail('Saving new model fails on saveOnlyIfDirty()');
     }
     //check if the record really saved in the DB
     $allergy = Allergy::model()->findByAttributes($this->testattributes);
     $this->assertNotNull($allergy);
     $this->assertEquals($this->testattributes['name'], $allergy->name);
     /* Clean Model **/
     $allergyAttributes = $allergy->getAttributes();
     //Perform a save without modifing the attributes
     if (!$allergy->saveOnlyIfDirty()->save()) {
         $this->fail('Updating model fails on saveOnlyIfDirty()');
     }
     // compare attributes before and after, as no database action was required
     //we except the attributes are the same (e.g.: last_modified_date)
     // Retrive the model again to see what is it in the DB
     $allergy = Allergy::model()->findByAttributes($this->testattributes);
     $this->assertEquals($allergyAttributes['id'], $allergy->id);
     $this->assertEquals($allergyAttributes['name'], $allergy->name);
     $this->assertEquals($allergyAttributes['last_modified_user_id'], $allergy->last_modified_user_id);
     $this->assertEquals($allergyAttributes['last_modified_date'], $allergy->last_modified_date);
     $this->assertEquals($allergyAttributes['created_user_id'], $allergy->created_user_id);
     $this->assertEquals($allergyAttributes['created_date'], $allergy->created_date);
     $this->assertEquals($allergyAttributes['active'], $allergy->active);
     $this->assertEquals($allergyAttributes['display_order'], $allergy->display_order);
     /* Dirty Model **/
     //let's modify the model
     $allergy->name = $dirty_allergy_name;
     $allergy->last_modified_date = date('Y-m-d H:i:s');
     if (!$allergy->saveOnlyIfDirty()->save()) {
         $this->fail('Updating modified model fails on saveOnlyIfDirty()');
     }
     $allergy = Allergy::model()->findByAttributes(array('name' => $dirty_allergy_name));
     $this->assertNotNull($allergy);
     $this->assertEquals($allergyAttributes['id'], $allergy->id);
     $this->assertEquals($dirty_allergy_name, $allergy->name);
     Allergy::model()->deleteAllByAttributes(array('name' => $dirty_allergy_name));
     Allergy::model()->deleteAllByAttributes($this->testattributes);
 }
 /**
  * @covers Allergy::model
  */
 public function testModel()
 {
     $this->assertEquals('Allergy', get_class(Allergy::model()), 'Class name should match model.');
 }
    ?>
" />

					<div class="row field-row allergy_field">
						<div class="<?php 
    echo $form->columns('label');
    ?>
">
							<label for="allergy_id">Add allergy:</label>
						</div>
						<div class="<?php 
    echo $form->columns('field');
    ?>
">
							<?php 
    $allAllergies = \Allergy::model()->findAll(array('order' => 'display_order', 'condition' => 'active=1'));
    echo CHtml::dropDownList('allergy_id', null, CHtml::listData($allAllergies, 'id', 'name'), array('empty' => '-- Select --'));
    ?>
						</div>
					</div>
					<div id="allergy_other" class="row field-row hidden">
						<div class="<?php 
    echo $form->columns('label');
    ?>
">
							<label for="allergy_id">Other allergy:</label>
						</div>
						<div class="<?php 
    echo $form->columns('field');
    ?>
">
 /**
  * List of allergies
  */
 public function allergyList($patient_id)
 {
     $patient = Patient::model()->findByPk((int) $patient_id);
     $allergy_ids = array();
     foreach ($patient->allergies as $allergy) {
         if ($allergy->name != 'Other') {
             $allergy_ids[] = $allergy->id;
         }
     }
     $criteria = new CDbCriteria();
     !empty($allergy_ids) && $criteria->addNotInCondition('id', $allergy_ids);
     $criteria->order = 'display_order';
     return Allergy::model()->active()->findAll($criteria);
 }
 /**
  * Save allergies - because it's part of the History element it need to be saved from that element.
  *
  * @param $element
  * @param $data
  * @param $index
  */
 protected function saveComplexAttributes_Element_OphCiExamination_History($element, $data, $index)
 {
     $patient = \Patient::model()->findByPk($this->patient->id);
     // we remove all current allergy data
     if (!empty($data['deleted_allergies'])) {
         foreach ($data['deleted_allergies'] as $i => $assignment_id) {
             if ($assignment_id > 0) {
                 $allergyToDel = \PatientAllergyAssignment::model()->findByPk($assignment_id);
                 if ($allergyToDel) {
                     $allergyToDel->delete();
                 }
             }
         }
     }
     if (isset($data['no_allergies']) && $data['no_allergies']) {
         $patient->setNoAllergies();
     } else {
         if (!empty($data['selected_allergies'])) {
             foreach ($data['selected_allergies'] as $i => $allergy_id) {
                 $allergyObject = \Allergy::model()->findByPk($allergy_id);
                 if ($data['other_names'][$i] == 'undefined') {
                     $data['other_names'][$i] = '';
                 }
                 $patient->addAllergy($allergyObject, $data['other_names'][$i], $data['allergy_comments'][$i], false, $this->event->id);
             }
         }
     }
 }