/** * @covers DrugSet::search */ public function testSearch() { $this->model->setAttributes($this->drugsets('drugset1')->getAttributes()); $results = $this->model->search(); $data = $results->getData(); $expectedKeys = array('drugset1'); $expectedResults = array(); if (!empty($expectedKeys)) { foreach ($expectedKeys as $key) { $expectedResults[] = $this->drugsets($key); } } $this->assertEquals(1, $results->getItemCount()); $this->assertEquals($expectedResults, $data); }
/** * Ajax function to get drug set for admin page (we do not have patient_id there), and we also load the * name and subspecialty here. * * @param $key * @param $set_id * * @throws CException */ public function actionSetFormAdmin($key, $set_id) { $drugset = DrugSet::model()->findByPk($set_id); $returnData = array(); $returnData['drugsetName'] = $drugset->name; $returnData['drugsetSubspecialtyId'] = $drugset->subspecialty_id; $returnData['tableRows'] = ''; // the HTML content for the prescription items table $key = (int) $key; $drug_set_items = DrugSetItem::model()->findAllByAttributes(array('drug_set_id' => $set_id)); foreach ($drug_set_items as $drug_set_item) { $returnData['tableRows'] .= $this->renderPrescriptionItem($key, $drug_set_item); ++$key; } echo json_encode($returnData); }
/** * Get all drug sets for admin page. * * @return mixed */ public function drugSetsAll() { $drugSets = DrugSet::model()->findAll(array('with' => 'subspecialty', 'order' => 't.name')); /* foreach ($drugSets as $drugSet) { $drugSet->name = $drugSet->name . " - " . $drugSet->subspecialty->name; } */ return $drugSets; }
/** * Save drug set data from the admin interface. */ public function actionSaveDrugSet() { // we need to decide if it's a new set or modification $drugSet = Yii::app()->request->getParam('DrugSet'); $prescriptionItem = Yii::app()->request->getParam('prescription_item'); if (isset($drugSet['id'])) { $drugSetId = $drugSet['id']; } if ($drugSetId > 0) { $drugset = DrugSet::model()->findByPk($drugSetId); } else { $drugset = new DrugSet(); } $drugset->name = $drugSet['name']; $drugset->subspecialty_id = $drugSet['subspecialty']; $drugset->active = $drugSet['active']; if ($drugset->save()) { // we delete previous tapers and items, and insert the new ones $currentDrugRows = DrugSetItem::model()->findAll(new CDbCriteria(array('condition' => "drug_set_id = '" . $drugset->id . "'"))); foreach ($currentDrugRows as $currentDrugRow) { DrugSetItemTaper::model()->deleteAll(new CDbCriteria(array('condition' => "item_id = '" . $currentDrugRow->id . "'"))); $currentDrugRow->delete(); } if (isset($prescriptionItem) && is_array($prescriptionItem)) { foreach ($prescriptionItem as $item) { $item_model = new DrugSetItem(); $item_model->drug_set_id = $drugset->id; $item_model->attributes = $item; $item_model->save(); // we need an id to save tapers if (isset($item['taper'])) { $tapers = array(); foreach ($item['taper'] as $taper) { $taper_model = new DrugSetItemTaper(); $taper_model->attributes = $taper; $taper_model->item_id = $item_model->id; $taper_model->save(); $tapers[] = $taper_model; } //$item_model->tapers = $tapers; } //$items[] = $item_model; //$item_model->save(); } Yii::app()->user->setFlash('info.save_message', 'Save successful.'); } else { Yii::app()->user->setFlash('info.save_message', 'Unable to save drugs, please add at least one drug to the set. Set name and subspecialty saved.'); } $this->redirect('/OphDrPrescription/DrugSetAdmin/DrugSets'); } else { // TODO: maybe more error handling need to be added here!! if ($drugSetId > 0) { $admin = $this->initAdmin($drugSetId); } else { $admin = $this->initAdmin(false); } $this->render('//admin/generic/edit', array('admin' => $admin, 'errors' => $drugset->getErrors())); } }
/** * Set prescription item defaults when creating. * * @param BaseEventTypeElement $element * @param string $action */ protected function setElementDefaultOptions($element, $action) { parent::setElementDefaultOptions($element, $action); if ($action == 'create' && get_class($element) == 'Element_OphDrPrescription_Details') { // Prepopulate prescription with set by episode status // FIXME: It's brittle relying on the set name matching the status $items = array(); $status_name = $this->episode->status->name; $subspecialty_id = $this->firm->getSubspecialtyID(); $params = array(':subspecialty_id' => $subspecialty_id, ':status_name' => $status_name); $set = DrugSet::model()->find(array('condition' => 'subspecialty_id = :subspecialty_id AND name = :status_name', 'params' => $params)); if ($set) { foreach ($set->items as $item) { $item_model = new OphDrPrescription_Item(); $item_model->drug_id = $item->drug_id; $item_model->loadDefaults(); $items[] = $item_model; } } $element->items = $items; } }