Ejemplo n.º 1
0
 public function search($params)
 {
     $query = Test::find();
     $dataProvider = new RestDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'status' => $this->status]);
     $query->andFilterWhere(['like', 'name', $this->name]);
     return $dataProvider;
 }
Ejemplo n.º 2
0
 /**
  * Display test report and its audit
  *
  * @return Response
  */
 public function viewTestAuditReport($testId)
 {
     $test = Test::find($testId);
     if (Input::has('word')) {
         $date = date("Ymdhi");
         $fileName = "testauditreport_" . $testId . "_" . $date . ".doc";
         $headers = array("Content-type" => "text/html", "Content-Disposition" => "attachment;Filename=" . $fileName);
         $content = view('reports.audit.exportAudit')->with('test', $test);
         return Response::make($content, 200, $headers);
     } else {
         return view('reports.audit.testAudit')->with('test', $test);
     }
 }
Ejemplo n.º 3
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Test::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'age' => $this->age]);
     $query->andFilterWhere(['like', 'name', $this->name]);
     return $dataProvider;
 }
Ejemplo n.º 4
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Test::find();
     // add conditions that should always apply here
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     // grid filtering conditions
     $query->andFilterWhere(['id' => $this->id, 'date_standard' => $this->date_standard, 'date_new' => $this->date_new]);
     $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'text', $this->text]);
     return $dataProvider;
 }
Ejemplo n.º 5
0
 public function actionModel()
 {
     //查询数据 and sql 注入
     // $sql="select * from test where id=1"." or 1=1";
     // $results=Test::findBySql($sql)->all();
     //占位符->预处理preparement
     // $sql="select * from test where id=:id";
     // $results=Test::findBySql($sql,array(":id"=>1))->all();
     //数组的方式
     //$results = Test::find()->where(['id'=>2])->all();
     //$results=Test::find()->where(['>','id','1'])->all();
     //$results=Test::find()->where(['between','id','1','2'])->all();
     //降低内存消耗第1种方式:对象在内存中的存储大,数组在内存中存储小一点,结果由对象转化为数组
     //$results = Test::find()->where(['like','title','fdfd'])->asArray()->all();//asArray()转化为数组
     //第2种方式:batch方式,批量查询
     foreach (Test::find()->batch(2) as $tests) {
         print_r(count($tests));
     }
     //print_r($results);
 }
Ejemplo n.º 6
0
 public function actionRank()
 {
     $result = Test::find()->orderBy('totalcomment DESC')->offset(0)->limit(10)->all();
     return $this->render('rank', ['data' => $result]);
 }
Ejemplo n.º 7
0
 public function actionSample()
 {
     //$objPHPExcel = new \PHPExcel();
     $template = Util::templateExcel();
     $model = new Test();
     $date = date('YmdHis');
     $name = $date . 'Test';
     //$attributes = $model->attributeLabels();
     $models = Test::find()->all();
     $excelChar = Util::excelChar();
     $not = Util::excelNot();
     foreach ($model->attributeLabels() as $k => $v) {
         if (!in_array($k, $not)) {
             $attributes[$k] = $v;
         }
     }
     $objReader = \PHPExcel_IOFactory::createReader('Excel5');
     $objPHPExcel = $objReader->load(Yii::getAlias($template));
     return $this->render('sample', ['models' => $models, 'attributes' => $attributes, 'excelChar' => $excelChar, 'not' => $not, 'name' => $name, 'objPHPExcel' => $objPHPExcel]);
 }
Ejemplo n.º 8
0
 /**
  * Return a array with all answers for questions: [1] => [],[],[]
  *                                                [2] => [],[],[]
  * @param $id
  * @return array
  */
 public function getAllAnswersToTest($id)
 {
     $answers = [];
     $test = Test::find($id);
     $questions = $test->questions()->get();
     foreach ($questions as $question) {
         $answers[$question->id] = $question->answers()->get()->toArray();
     }
     return $answers;
 }
Ejemplo n.º 9
0
 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);
     }
 }
Ejemplo n.º 10
0
 public function actionResults()
 {
     $session = Yii::$app->session;
     $request = Yii::$app->request;
     if (!$session->isActive) {
         $session->open();
     }
     if (!isset($session['test'])) {
         $this->redirect('new');
         exit;
     }
     if (!Yii::$app->user->isGuest) {
         $questions = Question::find()->joinWith(['testUserQuestionAnswers', 'answers'])->leftJoin('test', 'test.id = test_user_question_answer.test_id')->where(['test_user_question_answer.test_id' => $request->get('test_id'), 'test_user_question_answer.user_id' => Yii::$app->user->id])->orderBy('test_user_question_answer.created_at ASC')->all();
     } else {
     }
     $question_number = $this->getQuestionNumber();
     if ($request->get('test_id') == 0) {
         $question_answered_number = $this->getSessionQuestionAnsweredNumber();
         $answered_correctly = isset($session['test']['answered_correctly']) ? $session['test']['answered_correctly'] : 0;
         if ($answered_correctly != 0) {
             $number_of_correct_answers = count(explode(',', $answered_correctly));
         } else {
             $number_of_correct_answers = 0;
         }
         $percent_of_correct_answers = $answered_correctly > 0 ? count(explode(',', $answered_correctly)) / count(explode(',', $session['test']['answered'])) * 100 : 0;
         $percent_of_correct_answers = Yii::$app->formatter->asDecimal($percent_of_correct_answers, 1);
         $date_of_start = $session['test']['created_at'];
         $date_of_end = date('Y-m-d H:i:s');
     } else {
         $question_answered_number = $this->getQuestionAnsweredNumber();
         $answers = TestUserQuestionAnswer::find()->with('question')->where(['test_user_question_answer.test_id' => $request->get('test_id'), 'test_user_question_answer.user_id' => Yii::$app->user->id])->all();
         $number_of_correct_answers = 0;
         foreach ($answers as $v) {
             if ($v->question->correct_answer_id == $v->answer_id) {
                 $number_of_correct_answers++;
             }
         }
         if ($question_answered_number > 0) {
             $percent_of_correct_answers = $number_of_correct_answers / $question_answered_number * 100;
         } else {
             $percent_of_correct_answers = 0;
         }
         $percent_of_correct_answers = Yii::$app->formatter->asDecimal($percent_of_correct_answers, 1);
         $date_of_start = Test::find()->where(['id' => $request->get('test_id')])->one()->created_at;
         $date_of_end = Test::find()->where(['id' => $request->get('test_id')])->one()->ended_at;
         if ($date_of_end == null) {
             $date_of_end = date('Y-m-d H:i:s');
         }
     }
     $datetime1 = new DateTime($date_of_start);
     $datetime2 = new DateTime($date_of_end);
     $interval = $datetime1->diff($datetime2);
     $diff = $interval->format('%adni %hh %Im');
     return $this->render('results', ['questions' => $questions, 'question_number' => $question_number, 'question_answered_number' => $question_answered_number, 'time_spent' => $diff, 'number_of_correct_answers' => $number_of_correct_answers, 'percent_of_correct_answers' => $percent_of_correct_answers]);
 }
Ejemplo n.º 11
0
 /**
  * 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;
 }
Ejemplo n.º 12
0
 /**
  * Lists all Test models.
  * @return mixed
  */
 public function actionIndex()
 {
     $dataProvider = new ActiveDataProvider(['query' => Test::find()]);
     return $this->render('index', ['dataProvider' => $dataProvider]);
 }
Ejemplo n.º 13
0
 /**
  * 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('test.viewDetails', compact('test'));
 }
Ejemplo n.º 14
0
 /**
  * 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('blis.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);
 }