User: sakhtar Date: 16/09/2014 Time: 17:03
Inheritance: extends Eloquent
 /**
  * @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');
 }
Esempio n. 2
0
 function test_getAllergy_129()
 {
     //Arrange
     $test_allergy = new Allergy();
     $score = 129;
     //Act
     $result = $test_allergy->getAllergy($score);
     //assert
     $this->assertEquals(array("cats", "eggs"), $result);
 }
 function test_returnAllergens()
 {
     //arrange
     $test_Allergy = new Allergy();
     $input = "10010000";
     //act
     $result = $test_Allergy->returnAllergens($input);
     //assert
     $this->assertEquals(array("eggs" => true, "peanuts" => false, "shellfish" => false, "strawberries" => true, "tomatoes" => false, "chocolate" => false, "pollen" => false, "cats" => false), $result);
 }
Esempio n. 4
0
 /**
  * @dataProvider dataProvider_Search
  */
 public function testSearch_WithValidTerms_ReturnsExpectedResults($searchTerms, $numResults, $expectedKeys)
 {
     $allergy = new Allergy();
     $allergy->setAttributes($searchTerms);
     $allergyresults = $allergy->search();
     $allergydata = $allergyresults->getData();
     $expectedResults = array();
     if (!empty($expectedKeys)) {
         foreach ($expectedKeys as $key) {
             $expectedResults[] = $this->allergy($key);
         }
     }
     $this->assertEquals($numResults, $allergyresults->getItemCount());
     $this->assertEquals($expectedResults, $allergydata);
 }
 /**
  * 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();
 }
Esempio n. 6
0
 public static function set_panel($f3, $ingredientId = null)
 {
     $has_allergy = $f3->get('has_allergy_orm');
     $results = Allergy::map_to_id($f3);
     $ingAllergies = array();
     $allergyString = "";
     // Get selected allergies from db
     if ($ingredientId) {
         $arr_has_allergy = $has_allergy->find(array('ingredient_id = ?', $ingredientId));
         foreach ($arr_has_allergy as $value) {
             $ingAllergies[] = $value->allergy_id;
         }
     }
     $allergyString = implode(",", $ingAllergies);
     $f3->set('allergies', $results);
     $f3->set('inputAllergyValue', $allergyString);
 }
 /**
  * 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);
 }
Esempio n. 8
0
 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);
 }
    ?>
" />

					<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');
    ?>
">
Esempio n. 10
0
 function post_edit_ingredient($f3)
 {
     $ing = $f3->get('ingredient_orm');
     $id = $f3->get('PARAMS.id');
     $allergies = $f3->get('POST.allergies');
     $ing->load(array('id=?', $id));
     $ing->copyfrom('POST', function ($val) {
         return array_intersect_key($val, array_flip(array('name', 'info', 'other_allergies', 'producer')));
     });
     if (trim($ing->name) == '') {
         $f3->reroute("/ainesosa/{$id}");
     }
     Allergy::add_allergies($f3, $id, $allergies);
     AlertControl::message_info("Ainesosaa on muokattu");
     $ing->save();
     $f3->reroute("/ainesosa/listaa");
 }
 /**
  * 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);
 }
Esempio n. 12
0
 /**
  * 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);
             }
         }
     }
 }
<?php

require_once __DIR__ . "/../vendor/autoload.php";
require_once __DIR__ . "/../src/Allergy.php";
$app = new Silex\Application();
$app->register(new Silex\Provider\TwigServiceProvider(), array('twig.path' => __DIR__ . '/../views'));
$app->get("/", function () use($app) {
    return $app['twig']->render('index.html.twig');
});
$app->get("/return_results", function () use($app) {
    $my_allergy = new Allergy();
    $results = $my_allergy->returnAllergens($_GET['allergy_code']);
    return $app['twig']->render('index.html.twig', array('results' => $results));
});
return $app;
Esempio n. 14
0
 function get_allergies($f3)
 {
     Allergy::api_call($f3);
 }
Esempio n. 15
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>
Esempio n. 16
0
 function edit_food($f3, $params)
 {
     $category = new DB\SQL\Mapper($f3->get('DB'), 'CATEGORY');
     $menu = new DB\SQL\Mapper($f3->get('DB'), 'MENU');
     $meal = $f3->get('meal_orm');
     $id = $f3->get('PARAMS.id');
     $mealInst = $meal->load(array("id=?", $id));
     if ($meal->dry()) {
         $f3->reroute("/annos/luo");
     }
     $m_list = $menu->find();
     $c_list = $category->find();
     $a_list = Allergy::map_to_id($f3);
     $f3->set("meal", $mealInst);
     $f3->set("allergies", $a_list);
     $f3->set("categories", $c_list);
     $f3->set("menus", $m_list);
     $f3->set("id", $id);
     $f3->set("title", $mealInst->name);
     $f3->set('content', 'food_form.htm');
     echo Template::instance()->render('layout.htm');
 }
Esempio n. 17
0
# DATABASE RELATION-MAPPERS
$f3->set('DB', new DB\SQL('mysql:host=localhost;dbname=MealDB', 'root', ''));
$DB = $f3->get('DB');
$f3->set('meal_orm', new DB\SQL\Mapper($DB, 'MEAL'));
$f3->set('ingredient_orm', new DB\SQL\Mapper($DB, 'INGREDIENT'));
$f3->set('menu_orm', new DB\SQL\Mapper($DB, 'MENU'));
$f3->set('has_ingredient_orm', new DB\SQL\Mapper($DB, 'HAS_INGREDIENT'));
$f3->set('allergy_orm', new DB\SQL\Mapper($DB, 'ALLERGY'));
$f3->set('has_allergy_orm', new DB\SQL\Mapper($DB, 'HAS_ALLERGY'));
# ORM VIEWS
$f3->set('meal_overview_orm', new DB\SQL\Mapper($DB, 'MEAL_OVERVIEW'));
$f3->set('meal_ingredients_orm', new DB\SQL\Mapper($DB, 'MEAL_INGREDIENTS'));
$f3->set('ingredient_overview_orm', new DB\SQL\Mapper($DB, 'INGREDIENT_OVERVIEW'));
# GLOBAL VALUES
$f3->set('g_menus', $f3->get('menu_orm')->find());
$f3->set('g_allergies', Allergy::map_to_id($f3));
$f3->set('g_meal_name', 'annos');
#PÄÄAUKEAMA
$f3->route('GET /', function ($f3) {
    $auth = $_SERVER['PHP_AUTH_USER'];
    if (!isset($auth)) {
        $f3->reroute("/login");
    }
    $f3->set("title", "Ateriajärjestelmä");
    $f3->set("content", "main.htm");
    echo Template::instance()->render("layout.htm");
});
$f3->route('GET /asetukset', function () {
    echo 'Tänne asetukset';
});
# MENU
Esempio n. 18
0
 /**
  * Remove the specified allergy from storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function destroy($id)
 {
     Allergy::destroy($id);
     return Redirect::route('allergies.index');
 }