public function actionList() { $admin = new AdminListAutocomplete(SiteSubspecialtyDrug::model(), $this); $admin->setListFields(array('id', 'drugs.name', 'drugs.dose_unit')); $admin->setCustomDeleteURL('/OphDrPrescription/admin/commondrugsdelete'); $admin->setCustomSaveURL('/OphDrPrescription/admin/commondrugsadd'); $admin->setModelDisplayName('Common Drugs List'); $admin->setFilterFields(array(array('label' => 'Site', 'dropDownName' => 'site_id', 'defaultValue' => Yii::app()->session['selected_site_id'], 'listModel' => Site::model(), 'listIdField' => 'id', 'listDisplayField' => 'short_name'), array('label' => 'Subspecialty', 'dropDownName' => 'subspecialty_id', 'defaultValue' => Firm::model()->findByPk(Yii::app()->session['selected_firm_id'])->serviceSubspecialtyAssignment->subspecialty_id, 'listModel' => Subspecialty::model(), 'listIdField' => 'id', 'listDisplayField' => 'name'))); // we set default search options if ($this->request->getParam('search') == '') { $admin->getSearch()->initSearch(array('filterid' => array('site_id' => Yii::app()->session['selected_site_id'], 'subspecialty_id' => Firm::model()->findByPk(Yii::app()->session['selected_firm_id'])->serviceSubspecialtyAssignment->subspecialty_id))); } $admin->setAutocompleteField(array('fieldName' => 'drug_id', 'jsonURL' => '/OphDrPrescription/default/DrugList', 'placeholder' => 'search for drugs')); //$admin->searchAll(); $admin->listModel(); }
/** * Get the drug list for a specified site and subspecialty. * * @param $site_id * @param $subspecialty_id * * @return SiteSubspecialtyDrug[] */ public function commonDrugsBySiteAndSpec($site_id, $subspecialty_id) { $params = array(':subSpecialtyId' => $subspecialty_id, ':siteId' => $site_id); return SiteSubspecialtyDrug::model()->with('drugs')->findAll(array('condition' => 't.subspecialty_id = :subSpecialtyId AND t.site_id = :siteId', 'order' => 'name', 'params' => $params)); }
/** * @description Adds new drug into the site_subspecialty_drug table - AJAX call only * * @return string */ public function actionCommonDrugsAdd() { $drugId = $this->request->getParam('drug_id'); $siteId = $this->request->getParam('site_id'); $subspecialtyId = $this->request->getParam('subspecialty_id'); if (!Yii::app()->request->isAjaxRequest) { $this->render('errorpage', array('errormessage' => 'notajaxcall')); } else { if (!is_numeric($drugId) || !is_numeric($siteId) || !is_numeric($subspecialtyId)) { echo 'error'; } else { $newSSD = new SiteSubspecialtyDrug(); $newSSD->site_id = $siteId; $newSSD->subspecialty_id = $subspecialtyId; $newSSD->drug_id = $drugId; if ($newSSD->save()) { echo 'success'; } else { echo 'error'; } } } }