/** * Store a newly created resource in storage. * * @return Response */ public function store() { $action = Input::get('action'); $user_id = Auth::user()->id; $test = Input::get('test'); $organism = Input::get('organism'); $drug = Input::get('drug'); $zone = Input::get('zone'); $interpretation = Input::get('interpretation'); for ($i = 0; $i < count($test); $i++) { $sensitivity = Susceptibility::getDrugSusceptibility($test[$i], $organism[$i], $drug[$i]); if (count($sensitivity) > 0) { $drugSusceptibility = Susceptibility::find($sensitivity->id); $drugSusceptibility->user_id = $user_id; $drugSusceptibility->test_id = $test[$i]; $drugSusceptibility->organism_id = $organism[$i]; $drugSusceptibility->drug_id = $drug[$i]; $drugSusceptibility->zone = $zone[$i]; $drugSusceptibility->interpretation = $interpretation[$i]; $drugSusceptibility->save(); } else { $drugSusceptibility = new Susceptibility(); $drugSusceptibility->user_id = $user_id; $drugSusceptibility->test_id = $test[$i]; $drugSusceptibility->organism_id = $organism[$i]; $drugSusceptibility->drug_id = $drug[$i]; $drugSusceptibility->zone = $zone[$i]; $drugSusceptibility->interpretation = $interpretation[$i]; $drugSusceptibility->save(); } } if ($action == "results") { $test_id = Input::get('testId'); $organism_id = Input::get('organismId'); $susceptibility = Susceptibility::where('test_id', $test_id)->where('organism_id', $organism_id)->where('zone', '!=', 0)->get(); foreach ($susceptibility as $drugSusceptibility) { $drugSusceptibility->drugName = Drug::find($drugSusceptibility->drug_id)->name; $drugSusceptibility->pathogen = Organism::find($drugSusceptibility->organism_id)->name; if ($drugSusceptibility->interpretation == 'I') { $drugSusceptibility->sensitivity = 'Intermediate'; } else { if ($drugSusceptibility->interpretation == 'R') { $drugSusceptibility->sensitivity = 'Resistant'; } else { if ($drugSusceptibility->interpretation == 'S') { $drugSusceptibility->sensitivity = 'Sestitive'; } } } } return json_encode($susceptibility); } }
/** * Tests the update function in the OrganismController * @param void * @return void */ public function testUpdate() { Input::replace($this->organismData); $organism = new OrganismController(); $organism->store(); $organismStored = Organism::orderBy('id', 'desc')->take(1)->get()->toArray(); Input::replace($this->organismDataUpdate); $organism->update($organismStored[0]['id']); $organismSavedUpdated = Organism::find($organismStored[0]['id']); $this->assertEquals($organismSavedUpdated->name, $this->organismDataUpdate['name']); $this->assertEquals($organismSavedUpdated->description, $this->organismDataUpdate['description']); //Getting the drugs related to the organism /*$organismDrugUpdated = Organism::find($organismStored[0]['id'])->drugs->toArray(); $this->assertEquals(12, $this->organismDataUpdate['drugs'][0]);*/ }
/** * Remove the specified resource from storage (soft delete). * * @param int $id * @return Response */ public function delete($id) { //Soft delete the organism $organism = Organism::find($id); /*$testCategoryInUse = TestType::where('test_category_id', '=', $id)->first(); if (empty($testCategoryInUse)) { // The test category is not in use $testcategory->delete(); } else { // The test category is in use $url = Session::get('SOURCE_URL'); return Redirect::to($url) ->with('message', trans('messages.failure-test-category-in-use')); }*/ // redirect $url = Session::get('SOURCE_URL'); return Redirect::to($url)->with('message', trans('messages.success-deleting-organism')); }