Beispiel #1
0
 public function showChart()
 {
     $testID = Input::get('test');
     $test = Test::find($testID)->name;
     $data = array('test' => $test);
     return View::make('chart', $data);
 }
 function delete_delete($data)
 {
     $sql = Test::find($data->id);
     $retorno = $sql->to_json();
     $sql->delete();
     return '{"result": [' . $retorno . ']}';
 }
 /**
  * Show the form for editing the specified resource.
  * GET /medications/{id}/edit
  *
  * @param  int  $id
  * @return Response
  */
 public function edit($id)
 {
     $test_items = Billing::select('id', 'item')->where('type', '=', 'Laboratory Test')->get();
     $prescription_items = Billing::select('id', 'item')->where('type', '=', 'Medication')->get();
     $medication = Medication::find($id);
     $test = Test::find($id);
     return View::make('medications.edit', compact('medication', 'test_items', 'prescription_items', 'test'));
 }
 function test_find_all_returns_array()
 {
     # create two test entries to be found
     Test::create(array("dummy" => "Test 1"), array("dummy" => "Test 2"));
     $result = Test::find_all(array("conditions" => "id = 1"));
     $this->assertTrue(is_array($result));
     $this->assertEqual(count($result), 1);
     $result = Test::find("all", array("conditions" => array("id = ?", 2)));
     $this->assertTrue(is_array($result));
     $this->assertEqual(count($result), 1);
 }
 function test_has_many_with_preloaded_data()
 {
     setup_sqlite_test_db();
     preload_sqlite_data();
     $test1 = Test::find(1);
     $results1 = $test1->test_results;
     $this->assertEqual(count($results1), 1);
     $test2 = Test::find(2);
     $results2 = $test2->test_results;
     $this->assertEqual(count($results2), 2);
 }
Beispiel #6
0
 public function delete_destroy($id)
 {
     $test = Test::find($id);
     if (!$test) {
         return Response::error('404');
     } else {
         if ($test->destroy_if_user_can(Auth::user()->id)) {
             return Redirect::to_route('test_list')->with('success', 'Test deleted.');
         } else {
             return Response::error('403');
         }
     }
 }
Beispiel #7
0
 /**
  * Display one result
  *
  * @param $id
  * @param $rid
  */
 public function showAction($id, $rid)
 {
     $test = Test::find($id);
     if (is_null($test)) {
         return Redirect::route('tests.index')->with('error', 'Incorrect test id');
     }
     $single = Result::find($rid);
     if (is_null($single) || $single->test_id != $id) {
         return Redirect::route('tests.index')->with('error', 'Невозможно найти результаты');
     }
     $results = Result::where('test_id', $id)->where('token', $single->token)->orderBy('question_id', 'asc')->get();
     if (!count($results)) {
         return Redirect::route('tests.index')->with('error', 'Отсутствуют результаты теста');
     }
     $score = 0;
     $max = 0;
     foreach ($results as $result) {
         $score += $result->weight;
         if ($max < $result->created_at->format('U')) {
             $max = $result->created_at->format('U');
         }
     }
     $weights = [];
     $tw = 0;
     foreach ($test->questions as $q) {
         $weights[$q->id] = 0;
         foreach ($q->answers as $a) {
             if (!$a->is_correct) {
                 continue;
             }
             $weights[$q->id] += $a->weight;
             $tw += $a->weight;
         }
         if ($q->type == Question::TYPE_STRING) {
             $weights[$q->id] += 1;
             $tw += 1;
         }
     }
     $token = Token::where('token', $result->token)->get();
     $ends = $max - $token[0]->start;
     $min = (int) ($ends / 60);
     $sec = $ends - $min * 60;
     $ends = ($min < 10 ? '0' . $min : $min) . ':' . ($sec < 10 ? '0' . $sec : $sec);
     return View::make('tests.results_show', ['token' => Token::where('token', $single->token)->get()[0], 'test' => $test, 'total_questions' => count($test->questions), 'total_weight' => $tw, 'results' => $results, 'weights' => $weights, 'score' => $score, 'duration' => $ends]);
 }
 function test_create()
 {
     setup_sqlite_test_db();
     # Create a dummy test entry, ensure it is of correct type and got its
     # parameters correctly saved
     $dummy = Test::create(array("dummy" => "Test456"));
     $this->assertEqual(strtolower(get_class($dummy)), "test");
     $this->assertEqual($dummy->_base_class, "Test");
     $this->assertEqual($dummy->dummy, "Test456");
     $this->assertTrue($dummy->id > 0);
     # Now create two test entries at once
     $dummys = Test::create(array("dummy" => "Test567"), array("dummy" => "Test678"));
     $this->assertEqual(count($dummys), 2);
     # Return the complete table and check there is exactly one row
     $all_rows = Test::find("all");
     $this->assertEqual(count($all_rows), 3);
     # Return the first row and check it still matches our first dummy test entry
     $first = Test::find("first");
     $this->assertEqual($first->dummy, "Test456");
     $this->assertTrue($first->id > 0);
 }
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store()
 {
     $action = Input::get('action');
     $workUp = new Culture();
     $workUp->user_id = Input::get('userId');
     $workUp->test_id = Input::get('testId');
     $workUp->observation = Input::get('obs');
     if ($action == 'add') {
         $workUp->save();
         return 0;
     } else {
         if ($action == 'draw') {
             $obsv = Test::find($workUp->test_id)->culture;
             foreach ($obsv as $observation) {
                 $observation->user = User::find($observation->user_id)->name;
                 $observation->timeStamp = Culture::showTimeAgo($observation->created_at);
             }
             return json_encode($obsv);
         }
     }
 }
Beispiel #10
0
 function testTableMethods()
 {
     $id = $this->addRow();
     $updatedRow = array('name' => 'test updated', 'id' => $id);
     $this->assert(Test::update($updatedRow) === $id, "Update failed");
     $this->assert(Test::find($id)->export() == $updatedRow, "Test::find failed");
     $s = Test::findAll();
     $sc = $s->count();
     $this->assert($s->count() == 1, "Test::findAll(NO ARGUMENTS) failed (incorrect count {$sc})");
     $sf = $s->export()->fetch(PDO::FETCH_ASSOC);
     $this->assert($s->export()->fetch(PDO::FETCH_ASSOC) == $updatedRow, "Test::findAll(NO ARGUMENTS) failed (incorrect row " . var_export($sf, 1) . ")");
     $s = Test::findAll(array('name = ?' => $updatedRow['name']));
     $sc = $s->count();
     $this->assert($s->count() == 1, "Test::findAll(EXISTING_ROW) failed (incorrect count {$sc})");
     $sf = $s->export()->fetch(PDO::FETCH_ASSOC);
     $this->assert($sf == $updatedRow, "Test::findAll(EXISTING_ROW) failed (incorrect row " . var_export($sf, 1) . ")");
     $s = Test::findAll(array('name = ?' => $updatedRow['non-existing']));
     $sc = $s->count();
     $this->assert($s->count() == 0, "Test::findAll(NON_EXISTING_ROW) failed (incorrect count {$sc})");
     $sf = $s->export()->fetch(PDO::FETCH_ASSOC);
     $this->assert($sf == false, "Test::findAll(NON_EXISTING_ROW) failed (incorrect row " . var_export($sf, 1) . ")");
 }
Beispiel #11
0
 public function surveylistAction()
 {
     $manager = $this->session->get("Manager");
     $tests = Test::find(array("school_id = :school_id:", "bind" => array("school_id" => $manager["school_id"]), "sort" => "id desc"));
     $now = date("Y-m-d H:i:s");
     $list = array();
     foreach ($tests as $index => $test) {
         /*
          * status
          * 0: 测试未开始
          * 1: 测试正在进行中
          * 2: 测试已经过期
          */
         $import = Student::count(array("test_id= :test_id:", "bind" => array("test_id" => $test->t_id)));
         $status = 0;
         if ($now >= $test->begin_time && $now <= $test->end_time) {
             $status = 1;
         } else {
             if ($now > $test->end_time) {
                 $status = 2;
             }
         }
         $item = array("test_id" => $test->t_id, "people" => $test->people, "begin" => substr($test->begin_time, 0, strlen($test->begin_time) - 3), "end" => substr($test->end_time, 0, strlen($test->end_time) - 3), "description" => $test->description, "status" => $status, "import" => $import);
         $list[$index] = $item;
     }
     $this->view->setVar("tests", $list);
     // 设置url
     $url = $this->makeurl();
     $this->view->setVar("url", $url);
     $this->view->setRenderLevel(\Phalcon\Mvc\View::LEVEL_ACTION_VIEW);
 }
 /**
  * Retrieves the results and creates a JSON string
  *
  * @param testId the id of the test to send
  * @param 
  */
 public function createJsonString($testId)
 {
     //if($comments==null or $comments==''){$comments = 'No Comments';
     //We use curl to send the requests
     $httpCurl = curl_init(Config::get('kblis.sanitas-url'));
     curl_setopt($httpCurl, CURLOPT_RETURNTRANSFER, true);
     curl_setopt($httpCurl, CURLOPT_POST, true);
     //If testID is null we cannot handle this test as we cannot know the results
     if ($testId == null) {
         return null;
     }
     //Get the test and results
     $test = Test::find($testId);
     $testResults = $test->testResults;
     //Measures
     $testTypeId = $test->testType()->get()->lists('id')[0];
     $testType = TestType::find($testTypeId);
     $testMeasures = $testType->measures;
     //Get external requests and all its children
     $externalDump = new ExternalDump();
     $externRequest = ExternalDump::where('test_id', '=', $testId)->get();
     if (!$externRequest->first()) {
         //Not a request we can send back
         return null;
     }
     $labNo = $externRequest->lists('lab_no')[0];
     $externlabRequestTree = $externalDump->getLabRequestAndMeasures($labNo);
     $interpretation = "";
     //IF the test has no children prepend the status to the result
     if ($externlabRequestTree->isEmpty()) {
         if ($test->test_status_id == Test::COMPLETED) {
             $interpretation = "Done: " . $test->interpretation;
         } elseif ($test->test_status_id == Test::VERIFIED) {
             $interpretation = "Tested and verified: " . $test->interpretation;
         }
     } else {
         if ($test->test_status_id == Test::COMPLETED) {
             $interpretation = "Done " . $test->interpretation;
         } elseif ($test->test_status_id == Test::VERIFIED) {
             $interpretation = "Tested and verified " . $test->interpretation;
         }
     }
     //TestedBy
     $tested_by = ExternalUser::where('internal_user_id', '=', $test->tested_by)->get()->first();
     if ($tested_by == null) {
         $tested_by = "59";
     } else {
         if ($tested_by->external_user_id == null) {
             $tested_by = "59";
         } else {
             $tested_by = $tested_by->external_user_id;
         }
     }
     if ($test->verified_by == 0 || $test->verified_by == null) {
         $verified_by = "59";
     } else {
         $verified_by = ExternalUser::where('internal_user_id', '=', $test->verified_by)->get()->first();
         if ($verified_by == null) {
             $verified_by = "59";
         } else {
             if ($verified_by->external_user_id == null) {
                 $verified_by = "59";
             } else {
                 $verified_by = $verified_by->external_user_id;
             }
         }
     }
     //TODO - relate measure to test-result
     $range = Measure::getRange($test->visit->patient, $testResults->first()->measure_id);
     $unit = Measure::find($testResults->first()->measure_id)->unit;
     $result = $testResults->first()->result . " " . $range . " " . $unit;
     $jsonResponseString = sprintf('{"labNo": "%s","requestingClinician": "%s", "result": "%s", "verifiedby": "%s", "techniciancomment": "%s"}', $labNo, $tested_by, $result, $verified_by, trim($interpretation));
     $this->sendRequest($httpCurl, urlencode($jsonResponseString), $labNo);
     //loop through labRequests and foreach of them get the result and put in an array
     foreach ($externlabRequestTree as $key => $externlabRequest) {
         $mKey = array_search($externlabRequest->investigation, $testMeasures->lists('name'));
         if ($mKey === false) {
             Log::error("MEASURE NOT FOUND: Measure {$externlabRequest->investigation} not found in our system");
         } else {
             $measureId = $testMeasures->get($mKey)->id;
             $rKey = array_search($measureId, $testResults->lists('measure_id'));
             $matchingResult = $testResults->get($rKey);
             $range = Measure::getRange($test->visit->patient, $measureId);
             $unit = Measure::find($measureId)->unit;
             $result = $matchingResult->result . " " . $range . " " . $unit;
             $jsonResponseString = sprintf('{"labNo": "%s","requestingClinician": "%s", "result": "%s", "verifiedby": "%s", "techniciancomment": "%s"}', $externlabRequest->lab_no, $tested_by, $result, $verified_by, "");
             $this->sendRequest($httpCurl, urlencode($jsonResponseString), $externlabRequest->lab_no);
         }
     }
     curl_close($httpCurl);
 }
 public function getDelete($id)
 {
     $row = Test::find($id);
     $row->delete();
     return Redirect::to('/tests')->with('success', 'Deleted Successfully');
 }
Beispiel #14
0
 /**
  * Update the answers
  */
 public function updateAction()
 {
     $data = Input::all();
     $num = (int) $data['number_of_answers'];
     $test = Test::find($data['test_id']);
     $question = Question::find($data['id']);
     if (is_null($test) || is_null($question) || $test->id != $question->test->id) {
         return Redirect::route('tests.index')->with('error', 'Incorrect id');
     }
     $validation = Validator::make(['text' => $data['text']], Question::$rules);
     if (!$validation->passes()) {
         return Redirect::route('question.edit', ['id' => $question->id])->withInput()->withErrors($validation)->with('message', 'There were validation errors.');
     }
     $oldType = $question->type;
     $question->text = $data['text'];
     $question->number = $data['number'];
     $question->type = $data['type'] ? $data['type'] : Question::TYPE_STRING;
     $question->save();
     /**
      * Erase all old answers
      */
     DB::table('answer')->where('question_id', $question->id)->delete();
     /**
      * Create answers
      */
     for ($i = 1; $i <= $num; $i++) {
         if (!isset($data['a_' . $i . '_text']) || !trim($data['a_' . $i . '_text'])) {
             continue;
         }
         $answer = new Answer();
         $answer->question_id = $question->id;
         $answer->text = trim($data['a_' . $i . '_text']);
         $answer->weight = (int) $data['a_' . $i . '_weight'];
         if ($question->type == Question::TYPE_CHECKBOX) {
             $answer->is_correct = isset($data['a_' . $i . '_correct']) ? true : false;
         } elseif ($question->type == Question::TYPE_RADIO) {
             $answer->is_correct = isset($data['a_0_correct']) && $data['a_0_correct'] == $i ? true : false;
         }
         if ($answer->is_correct && !$answer->weight) {
             $answer->weight = 1;
         }
         if (!$answer->is_correct) {
             $answer->weight = 0;
         }
         $answer->save();
     }
     return Redirect::route('tests.show', $test->id);
 }
Beispiel #15
0
<?php

echo json_encode(Test::find('tests'));
Beispiel #16
0
 /**
  * Create token for the test
  *
  * @param $id
  */
 public function createAction($id)
 {
     if (!Auth::user()) {
         return Redirect::route('admin');
     }
     $test = Test::find($id);
     if (is_null($test)) {
         return Redirect::route('info')->with('message', 'Тест не найден');
     }
     $token = new Token();
     $token->token = $token->generate($test->name);
     $token->test_id = $id;
     $token->save();
     return View::make('test.token', ['token' => $token->token]);
 }
 /**
  * Results are formatted like Measure:result Measure:result 
  * for each of the measure of the test
  */
 public function getFormattedResults($testId)
 {
     $testResults = Test::find($testId)->TestResults;
     $formattedResults = '';
     foreach ($testResults as $testResult) {
         $measureName = $testResult->measure->name;
         $formattedResults .= $measureName . ' : ' . $testResult->result;
     }
     return $formattedResults;
 }
Beispiel #18
0
 /**
  * Remove the specified resource from storage.
  * DELETE /tests/{id}
  *
  * @param  int  $id
  * @return Response
  */
 public function destroy($id)
 {
     $test = Test::find($id);
     Test::destroy($id);
     return Redirect::route('patient-chart-get', $test->patient_id)->with('global', "Test successfully deleted");
 }
 /**
  * Culture worksheet for Test
  *
  * @param
  * @return
  */
 public function culture()
 {
     $test = Test::find(Input::get('testID'));
     $test->test_status_id = Test::VERIFIED;
     $test->time_verified = date('Y-m-d H:i:s');
     $test->verified_by = Auth::user()->id;
     $test->save();
     //Fire of entry verified event
     Event::fire('test.verified', array($testID));
     return View::make('test.viewDetails')->with('test', $test);
 }
Beispiel #20
0
				@elseif($selectedReport == 3 || $selectedReport == 4) <!-- Tests Registry Report-->
					<thead>
						<tr>
							<th>{{Lang::choice('messages.test-id',1)}}</th>
							<th>{{Lang::choice('messages.test-type',1)}}</th>
							<th>{{Lang::choice('messages.patient-number',1)}}</th>
							<th>{{Lang::choice('messages.patient',1)}}</th>
							<th>{{Lang::choice('messages.specimen-id',1)}}</th>
							<th>{{Lang::choice('messages.registration-date',1)}}</th>
						</tr>
					</thead>
					<tbody>
						@forelse($reportData as $row)
							<?php 
$test = Test::find($row->id);
?>
							<tr>
								<td>{{$test->id}}</td>
								<td>{{$test->testType->name}}</td>
								<td>{{$test->visit->patient->patient_number}}</td>
								<td>{{$test->visit->patient->name}}</td>
								<td>{{$test->specimen->id}}</td>
								<td>{{$test->time_completed}}</td>
							</tr>
						@empty
							<tr>
								<td colspan='6'>{{Lang::choice('messages.no-data-found',1)}}</td>
							</tr>
						@endforelse
					</tbody>
Beispiel #21
0
 /**
  * Delete the test
  *
  * @param $id
  */
 public function deleteAction($id)
 {
     $test = Test::find($id);
     if (is_null($test)) {
         return Redirect::route('tests.index')->with('error', 'Incorrect test id');
     }
     /**
      * Get the list of answers
      */
     $questions = Question::where('test_id', $id)->get();
     foreach ($questions as $q) {
         DB::table('answer')->where('question_id', $q->id)->delete();
     }
     DB::table('token')->where('test_id', $id)->delete();
     DB::table('result')->where('test_id', $id)->delete();
     DB::table('question')->where('test_id', $id)->delete();
     DB::table('test')->where('id', $id)->delete();
     return Redirect::route('tests.index');
 }
 public function testGetTurnAroundTime()
 {
     $testIDs = Test::where('test_status_id', '=', Test::COMPLETED)->orWhere('test_status_id', '=', Test::VERIFIED)->lists('id');
     if (count($testIDs) == 0) {
         $this->assertTrue(false);
     }
     foreach ($testIDs as $id) {
         $test = Test::find($id);
         $this->assertTrue($test->getTurnaroundTime() >= 0);
     }
 }
 /**
  * Display the specified resource.
  *
  * @param  int  $id
  * @return Response
  */
 public function show($id)
 {
     $test = Test::find($id);
     $cats = $test->category;
     $resp = array('test' => $test->toArray(), 'categories' => $cats);
     return $this->respond($test->toArray());
 }