model() публичный статический Метод

Returns the static model of the specified AR class.
public static model ( $className = __CLASS__ ) : Drug
Результат Drug the static model class
 public function actionFindDrug()
 {
     $return = array();
     if (isset($_GET['term']) && ($term = $_GET['term'])) {
         $criteria = new CDbCriteria();
         $criteria->compare('LOWER(name)', strtolower($term), true, 'OR');
         $criteria->compare('LOWER(aliases)', strtolower($term), true, 'OR');
         foreach (Drug::model()->active()->findAll($criteria) as $drug) {
             $return[] = array('label' => $drug->tallmanlabel, 'value' => $drug->id);
         }
     }
     echo json_encode($return);
 }
Пример #2
0
 public function actionEditDrug($id)
 {
     return;
     //disabled OE-4474
     if (!($drug = Drug::model()->findByPk($id))) {
         throw new Exception("Drug not found: {$id}");
     }
     $drug->scenario = 'update';
     if (!empty($_POST)) {
         $drug->attributes = $_POST['Drug'];
         if (!$drug->validate()) {
             $errors = $drug->getErrors();
         } else {
             if (!$drug->save()) {
                 throw new Exception("Unable to save drug: " . print_r($drug->getErrors(), true));
             }
             $posted_allergy_ids = array();
             if (isset($_POST['allergies'])) {
                 $posted_allergy_ids = $_POST['allergies'];
             }
             $criteria = new CDbCriteria();
             $criteria->compare('drug_id', $drug->id);
             $allergy_assignments = DrugAllergyAssignment::model()->findAll($criteria);
             $allergy_assignment_ids = array();
             foreach ($allergy_assignments as $allergy_assignment) {
                 $allergy_assignment_ids[] = $allergy_assignment->allergy_id;
             }
             $allergy_assignment_ids_to_delete = array_diff($allergy_assignment_ids, $posted_allergy_ids);
             $posted_allergy_ids_to_assign = array_diff($posted_allergy_ids, $allergy_assignment_ids);
             //add new allergy mappings
             foreach ($posted_allergy_ids_to_assign as $asign) {
                 $allergy_assignment = new DrugAllergyAssignment();
                 $allergy_assignment->drug_id = $drug->id;
                 $allergy_assignment->allergy_id = $asign;
                 $allergy_assignment->save();
             }
             //delete redundant allergy mappings
             foreach ($allergy_assignments as $asigned) {
                 if (in_array($asigned->allergy_id, $allergy_assignment_ids_to_delete)) {
                     $asigned->delete();
                 }
             }
             $this->redirect('/admin/drugs/' . ceil($drug->id / $this->items_per_page));
         }
     }
     $this->render('/admin/editdrug', array('drug' => $drug, 'errors' => @$errors));
 }
 /**
  * Searches across MedicationDrug and Drug models for the given term. If the term only matches
  * on an alias, the alias will be included in the returned label for that entry.
  *
  * Distinguishes between the data types to ensure relationship defined correctly.
  */
 public function actionFindDrug()
 {
     $return = array();
     if (isset($_GET['term']) && ($term = strtolower($_GET['term']))) {
         $criteria = new CDbCriteria();
         $criteria->compare('LOWER(name)', $term, true, 'OR');
         $criteria->compare('LOWER(aliases)', $term, true, 'OR');
         foreach (MedicationDrug::model()->findAll($criteria) as $md) {
             $label = $md->name;
             if (strpos(strtolower($md->name), $term) === false) {
                 $label .= " (" . $md->aliases . ")";
             }
             $return[] = array('name' => $md->name, 'label' => $label, 'value' => $md->id, 'type' => 'md');
         }
         foreach (Drug::model()->active()->findAll($criteria) as $drug) {
             $label = $drug->tallmanlabel;
             if (strpos(strtolower($drug->name), $term) === false) {
                 $label .= " (" . $drug->aliases . ")";
             }
             $return[] = array('name' => $drug->tallmanlabel, 'label' => $label, 'value' => $drug->id, 'type' => 'd');
         }
     }
     echo json_encode($return);
 }
Пример #4
0
 /**
  * @param integer $drug_id
  * @return boolean Is patient allergic?
  */
 public function hasDrugAllergy($drug_id = null)
 {
     if ($drug_id) {
         if ($this->allergies) {
             $criteria = new CDbCriteria();
             $criteria->select = 't.id';
             $criteria->condition = 'paa.patient_id = :patient_id';
             $join = array();
             $join[] = 'JOIN drug_allergy_assignment daa ON daa.drug_id = t.id';
             $join[] = 'JOIN patient_allergy_assignment paa ON paa.allergy_id = daa.allergy_id';
             $criteria->join = implode(' ', $join);
             $criteria->params = array(':patient_id' => $this->id);
             return (bool) Drug::model()->findByPk($drug_id, $criteria);
         } else {
             return false;
         }
     } else {
         return (bool) $this->allergies;
     }
 }
Пример #5
0
echo $form->columns('field');
?>
">

			<input type="hidden" name="drug_id" value="<?php 
echo $medication->drug_id;
?>
"/>
			<div class="field-row data-value" id="medication_drug_name"><?php 
echo $medication->drug_id ? CHtml::encode($medication->drug->label) : "";
?>
</div>

			<div class="field-row">
				<?php 
echo CHtml::dropDownList('drug_select', '', Drug::model()->listBySubspecialty($firm->getSubspecialtyID()), array('empty' => '- Select -'));
?>
			</div>

			<div class="field-row">
				<div class="label"></div>
				<?php 
$this->widget('zii.widgets.jui.CJuiAutoComplete', array('name' => 'drug_autocomplete', 'source' => new CJavaScriptExpression('function (req, res) { $.getJSON(' . json_encode($this->createUrl('medication/finddrug')) . ', req, res); }'), 'options' => array('minLength' => 3, 'focus' => "js:function(e,ui) {\n\t\t\t\t\t\t\t\t\$('#drug_autocomplete').val(ui.item.label);\n\t\t\t\t\t\t\t\te.preventDefault();\n\t\t\t\t\t\t\t}"), 'htmlOptions' => array('placeholder' => 'or search formulary')));
?>
			</div>
		</div>
	</div>

	<?php 
$form->widget('application.widgets.TextField', array('element' => $medication, 'field' => 'dose', 'name' => 'dose'));
?>
Пример #6
0
 /**
  *	@covers	Drug::model
  *	@todo Implement testModel().
  */
 public function testModel()
 {
     $this->assertEquals('Drug', get_class(Drug::model()), 'Class name should match model.');
 }
 /**
  * Get the common drugs for session firm.
  *
  * @TODO: move this out of the model - it's not the right place for it as it's relying on session information
  *
  * @return Drug[]
  */
 public function commonDrugs()
 {
     $firm = Firm::model()->findByPk(Yii::app()->session['selected_firm_id']);
     $subspecialty_id = $firm->serviceSubspecialtyAssignment->subspecialty_id;
     $site_id = Yii::app()->session['selected_site_id'];
     $params = array(':subSpecialtyId' => $subspecialty_id, ':siteId' => $site_id);
     return Drug::model()->active()->findAll(array('condition' => 'ssd.subspecialty_id = :subSpecialtyId AND ssd.site_id = :siteId', 'join' => 'JOIN site_subspecialty_drug ssd ON ssd.drug_id = t.id', 'order' => 'name', 'params' => $params));
 }
 public function testPositionalParams()
 {
     Drug::model()->updateAll(array('name' => 'foo'), 'id = ?', array(1));
     $this->assertEquals('foo', Drug::model()->findByPk(1)->name);
 }
Пример #9
0
 public function listBySubspecialty($subspecialty_id)
 {
     $criteria = new CDbCriteria();
     $criteria->compare('subspecialty_id', $subspecialty_id);
     return CHtml::listData(Drug::model()->with('subspecialtyAssignments')->findAll($criteria), 'id', 'label');
 }
Пример #10
0
 /**
  * @param $subspecialty_id
  * @return array
  */
 public function listBySubspecialtyWithCommonMedications($subspecialty_id)
 {
     $criteria = new CDbCriteria();
     $criteria->compare('subspecialty_id', $subspecialty_id);
     $drugs = Drug::model()->with('subspecialtyAssignments')->findAll($criteria);
     $common_medication_drugs = CommonMedications::model()->with('medication_drug')->findAll();
     $return = array();
     foreach ($drugs as $drug) {
         $return[] = array('label' => $drug->name, 'value' => $drug->name, 'id' => $drug->id);
     }
     foreach ($common_medication_drugs as $common_medication_drug) {
         $return[] = array('label' => $common_medication_drug->medication_drug->name, 'value' => $common_medication_drug->medication_drug->name, 'id' => $common_medication_drug->medication_drug->id . '@@M');
     }
     asort($return);
     return CHtml::listData($return, 'id', 'label');
 }
Пример #11
0
 /**
  * Ajax action to search for drugs.
  */
 public function actionDrugList()
 {
     if (Yii::app()->request->isAjaxRequest) {
         $criteria = new CDbCriteria();
         if (isset($_GET['term']) && strlen($term = $_GET['term']) > 0) {
             $criteria->addCondition(array('LOWER(name) LIKE :term', 'LOWER(aliases) LIKE :term'), 'OR');
             $params[':term'] = '%' . strtolower(strtr($term, array('%' => '\\%'))) . '%';
         }
         if (isset($_GET['type_id']) && ($type_id = $_GET['type_id'])) {
             $criteria->addCondition('type_id = :type_id');
             $params[':type_id'] = $type_id;
         }
         if (isset($_GET['preservative_free']) && ($preservative_free = $_GET['preservative_free'])) {
             $criteria->addCondition('preservative_free = 1');
         }
         $criteria->order = 'name';
         // we don't need 'select *' here
         $criteria->select = 'id, tallman, preservative_free';
         $criteria->params = $params;
         $drugs = Drug::model()->active()->findAll($criteria);
         $return = array();
         foreach ($drugs as $drug) {
             $return[] = array('label' => $drug->tallmanlabel, 'value' => $drug->tallman, 'id' => $drug->id);
         }
         echo CJSON::encode($return);
     }
 }