Ejemplo n.º 1
0
 public function actionAdd()
 {
     $model = new Test();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->render('ok');
     }
     return $this->render('add', ['model' => $model]);
 }
 /**
  * Creates a new Test model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Test();
     if ($model->load(\Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'id' => (string) $model->id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
Ejemplo n.º 3
0
 /**
 * Creates a new Test model.
 * If creation is successful, the browser will be redirected to the 'view' page.
 * @return mixed
 */
 public function actionCreate()
 {
     $model = new Test();
     $model->createDate = date("Y-m-d H:i:s");
     $model->userCreate = Yii::$app->user->id;
     $model->userUpdate = Yii::$app->user->id;
     if ($model->loadWithFiles(Yii::$app->request->post()) && $model->save()) {
         Yii::$app->session->setFlash('success', 'Well done! successfully to save data!  ');
         return $this->redirect(['index']);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
Ejemplo n.º 4
0
 public function actionInsert()
 {
     //Test->实例obj对象->save方法转化为数据->db
     $test = new Test();
     $test->id = 'bbbb';
     $test->title = "*****@*****.**";
     $test->validate();
     if ($test->hasErrors()) {
         echo 'error';
         die;
     }
     $test->save();
 }
Ejemplo n.º 5
0
 public function actionInit()
 {
     $request = Yii::$app->request;
     if (!$request->post('initialize')) {
         return ['error' => 'wrong parameters passed'];
     } else {
         $user = Users::findByUsername($request->post('username'));
         if ($user_id = $user->getId()) {
             $test = new Test();
             $test->user_id = $user_id;
             $test->save();
             return ['testId' => $test->id];
         } else {
             return ['error' => 'error initializing test'];
         }
     }
 }
Ejemplo n.º 6
0
 public function actionTest()
 {
     $user = new User();
     $ret = \Yii::$app->request->get();
     if ($user->load($ret)) {
         if ($user->save()) {
             //                echo 3;die;
             $test = new Test();
             //              var_dump($test->load($ret));die;
             if ($test->load($ret)) {
                 $test->save();
             } else {
                 echo 4;
             }
         }
     } else {
         echo 2;
     }
 }
Ejemplo n.º 7
0
 private function sessionSet()
 {
     $session = Yii::$app->session;
     $request = Yii::$app->request;
     if (!$session->isActive) {
         $session->open();
     }
     $session->remove('test');
     if (!Yii::$app->user->isGuest) {
         $test_model = new Test();
         $test_model->user_id = Yii::$app->user->id;
         $test_model->created_at = date('Y-m-d H:i:s');
         $test_model->save();
         $number_of_all_tests = Test::find()->where(['user_id' => Yii::$app->user->id])->count();
         $session->set('test', ['status' => 'db', 'active_test_id' => $test_model->id, 'answered' => null, 'test_data' => $test_model, 'created_at' => $test_model->created_at, 'number_of_all_tests' => $number_of_all_tests]);
     } else {
         $session->set('test', ['status' => 'no_db', 'active_test_id' => 1, 'answered' => null, 'created_at' => date('Y-m-d H:i:s')]);
     }
 }
Ejemplo n.º 8
0
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     $ch = array('a', 'b', 'c', 'd');
     \App\Models\Test::truncate();
     $faker = \Faker\Factory::create('zh_TW');
     foreach (range(1, 10) as $number) {
         //建立隨機變數數值
         //        \App\Models\Test::create([
         //            'data'=>'seeder 輸入的',
         //            'YesNo'     =>rand(0,1),
         //            '數字'       =>$number,
         //            '內容'       =>$faker->name,
         //            '日期'       =>Carbon::now()->addDays($number)//用套件顯示日期,add是增加日期天數
         //
         //        ]);
         $test = new Test();
         $test->data = '物件化 輸入 with namespace';
         $test->save();
     }
 }
Ejemplo n.º 9
0
 public function startTestByAssigner(Requests\Client\Assigners\Show $request, Assigner $Assigner)
 {
     $Prototype = $Assigner->prototype;
     $Test = new Test();
     $Test->fill(['user_id' => $Assigner->user_id, 'prototype_id' => $Prototype->id]);
     $Questions = $Assigner->prototype->questions;
     if ($Prototype->qount_questions === 0) {
         $count_question = $Questions->count();
     } else {
         if ($Questions->count() >= $Prototype->count_questions) {
             $count_question = $Prototype->count_questions;
         } else {
             $count_question = $Questions->count();
         }
     }
     $ids = array_rand($Questions->toArray(), $count_question);
     $Test->save();
     $Assigner->test()->associate($Test);
     $Assigner->save();
     foreach ($ids as $id) {
         $Test->questions()->attach($Questions[$id]->id);
     }
     return redirect(route('client.test', $Test));
 }
Ejemplo n.º 10
0
 public function actionPublish()
 {
     $model = new Publish();
     if ($model->load(Yii::$app->request->post()) && $model->validate()) {
         $session = Yii::$app->session;
         if (!$session->isActive) {
             $session->open();
         }
         if (!isset($session['user'])) {
             $this->redirect('?r=login');
         }
         $author = $session['user']['name'];
         $author_id = $session['user']['userid'];
         $query = Login::find()->where('id=:id', [':id' => $author_id])->one();
         $author_img = $query->image;
         $content = $model->content;
         $publishtime = date('Y-m-d H:i:s', time());
         $savemodel = new Test();
         $model->img = UploadedFile::getInstance($model, 'img');
         if ($model->img != null) {
             $name = $model->img->name;
             $arr = explode('.', $name);
             $filename = hash('sha256', time() . $author) . '.' . $arr[count($arr) - 1];
             echo "filename:" . $filename;
             $model->img->saveAs('./img/' . $filename);
             $savemodel->bodyimg = './img/' . $filename;
         } else {
             $savemodel->bodyimg = "";
         }
         $savemodel->author = $author;
         $savemodel->author_img = $author_img;
         $savemodel->describe = $content;
         $savemodel->publishtime = $publishtime;
         $savemodel->save();
         //            var_dump($savemodel);
         return $this->redirect('r=test');
     }
     return $this->render('publish', ['model' => $model]);
 }
Ejemplo n.º 11
0
 public function process($labRequest)
 {
     //First: Check if patient exists, if true dont save again
     $patient = Patient::where('external_patient_number', '=', $labRequest->PatientNumber)->get();
     if (!$patient->first()) {
         $patient = new Patient();
         $patient->external_patient_number = $labRequest->PatientNumber;
         $patient->patient_number = $labRequest->PatientNumber;
         $patient->name = $labRequest->FullNames;
         $gender = array('M' => Patient::MALE, 'F' => Patient::FEMALE, 'U' => Patient::UNKNOWN);
         $patient->gender = $gender[$labRequest->Sex];
         $patient->dob = $this->getDobFromAge($labRequest->Age);
         $patient->address = $labRequest->PoBox;
         $patient->phone_number = $labRequest->PatientsContact;
         $patient->created_by = User::EXTERNAL_SYSTEM_USER;
     } else {
         $patient = $patient->first();
     }
     //We check if the test exists in our system if not we just save the request in stagingTable
     $testTypeId = TestType::getTestTypeIdByTestName($labRequest->investigation);
     if (is_null($testTypeId) && $labRequest->parentLabNo == '0') {
         $this->saveToExternalDump($labRequest, ExternalDump::TEST_NOT_FOUND);
         return;
     }
     //Check if visit exists, if true dont save again
     $visit = Visit::where('visit_number', '=', $labRequest->RevisitNumber)->get();
     if (!$visit->first()) {
         $visit = new Visit();
         $visit->visit_type = 'Out-patient';
         // We'll save Visit in a transaction a little bit below
     } else {
         $visit = $visit->first();
     }
     $test = null;
     //Check via the labno, if this is a duplicate request and we already saved the test
     $test = Test::where('external_id', '=', $labRequest->RequestID)->get();
     if (!$test->first()) {
         //Specimen
         $specimen = new Specimen();
         $specimen->specimen_type_id = TestType::find($testTypeId)->specimenTypes->lists('id')[0];
         // We'll save the Specimen in a transaction a little bit below
         $test = new Test();
         $test->test_type_id = $testTypeId;
         $test->test_status_id = Test::NOT_RECEIVED;
         $test->created_by = User::EXTERNAL_SYSTEM_USER;
         //Created by external system 0
         $test->requested_by = $labRequest->DoctorRequesting;
         $test->external_id = $labRequest->RequestID;
         DB::transaction(function () use($visit, $specimen, $test, $patient) {
             $patient->save();
             $visit->patient_id = $patient->id;
             $visit->visit_number = Visit::orderBy('id', 'desc')->first()->id + 1;
             //$labRequest->RevisitNumber;
             $visit->save();
             $specimen->save();
             $test->visit_id = $visit->id;
             $test->specimen_id = $specimen->id;
             $test->save();
         });
         $this->saveToExternalDump($labRequest, $test->id);
         return;
     }
     $this->saveToExternalDump($labRequest, null);
     mssql_close($connection);
 }
Ejemplo n.º 12
0
 /**
  * Save a new Test.
  *
  * @return Response
  */
 public function saveNewTest(TestRequest $request)
 {
     //Create New Test
     $visitType = ['Out-patient', 'In-patient'];
     $activeTest = array();
     /*
      * - Create a visit
      * - Fields required: visit_type, patient_id
      */
     $visit = new Visit();
     $visit->patient_id = $request->patient_id;
     $visit->visit_type = $visitType[$request->visit_type];
     $visit->save();
     /*
      * - Create tests requested
      * - Fields required: visit_id, test_type_id, specimen_id, test_status_id, created_by, requested_by
      */
     $testTypes = $request->testtypes;
     if (is_array($testTypes)) {
         foreach ($testTypes as $value) {
             $testTypeID = (int) $value;
             // Create Specimen - specimen_type_id, accepted_by, referred_from, referred_to
             $specimen = new Specimen();
             $specimen->specimen_type_id = TestType::find($testTypeID)->specimenTypes->lists('id')[0];
             $specimen->accepted_by = Auth::user()->id;
             $specimen->save();
             $test = new Test();
             $test->visit_id = $visit->id;
             $test->test_type_id = $testTypeID;
             $test->specimen_id = $specimen->id;
             $test->test_status_id = Test::PENDING;
             $test->created_by = Auth::user()->id;
             $test->requested_by = Input::get('physician');
             $test->save();
             $activeTest[] = $test->id;
         }
     }
     $url = session('SOURCE_URL');
     return redirect()->to($url)->with('message', trans('messages.record-successfully-saved'))->with('active_test', $test->id);
 }
Ejemplo n.º 13
0
 /**
  * Function for processing the requests we receive from the external system
  * and putting the data into our system.
  *
  * @var array lab_requests
  */
 public function process($labRequest)
 {
     //First: Check if patient exists, if true dont save again
     $patient = Patient::where('external_patient_number', '=', $labRequest->patient->id)->get();
     if (!$patient->first()) {
         $patient = new Patient();
         $patient->external_patient_number = $labRequest->patient->id;
         $patient->patient_number = $labRequest->patient->id;
         $patient->name = $labRequest->patient->fullName;
         $gender = array('Male' => Patient::MALE, 'Female' => Patient::FEMALE);
         $patient->gender = $gender[$labRequest->patient->gender];
         $patient->dob = $labRequest->patient->dateOfBirth;
         $patient->address = $labRequest->address->address;
         $patient->phone_number = $labRequest->address->phoneNumber;
         $patient->created_by = User::EXTERNAL_SYSTEM_USER;
         $patient->save();
     } else {
         $patient = $patient->first();
     }
     //We check if the test exists in our system if not we just save the request in stagingTable
     if ($labRequest->parentLabNo == '0') {
         $testTypeId = TestType::getTestTypeIdByTestName($labRequest->investigation);
     } else {
         $testTypeId = null;
     }
     if (is_null($testTypeId) && $labRequest->parentLabNo == '0') {
         $this->saveToExternalDump($labRequest, ExternalDump::TEST_NOT_FOUND);
         return;
     }
     //Check if visit exists, if true dont save again
     $visitType = array('ip' => 'In-patient', 'op' => 'Out-patient');
     //Should be a constant
     $visit = Visit::where('visit_number', '=', $labRequest->patientVisitNumber)->where('visit_type', '=', $visitType[$labRequest->orderStage])->get();
     if (!$visit->first()) {
         $visit = new Visit();
         $visit->patient_id = $patient->id;
         $visit->visit_type = $visitType[$labRequest->orderStage];
         $visit->visit_number = $labRequest->patientVisitNumber;
         // We'll save Visit in a transaction a little bit below
     } else {
         $visit = $visit->first();
         if (strcmp($visitType[$labRequest->orderStage], $visit->visit_type) != 0) {
             $visit = new Visit();
             $visit->patient_id = $patient->id;
             $visit->visit_type = $visitType[$labRequest->orderStage];
             $visit->visit_number = $labRequest->patientVisitNumber;
         }
     }
     $test = null;
     //Check if parentLabNO is 0 thus its the main test and not a measure
     if ($labRequest->parentLabNo == '0') {
         //Check via the labno, if this is a duplicate request and we already saved the test
         $test = Test::where('external_id', '=', $labRequest->labNo)->get();
         if (!$test->first()) {
             //Specimen
             $specimen = new Specimen();
             $specimen->specimen_type_id = TestType::find($testTypeId)->specimenTypes->lists('id')[0];
             // We'll save the Specimen in a transaction a little bit below
             $test = new Test();
             $test->test_type_id = $testTypeId;
             $test->test_status_id = Test::NOT_RECEIVED;
             $test->created_by = User::EXTERNAL_SYSTEM_USER;
             //Created by external system 0
             $test->requested_by = $labRequest->requestingClinician;
             $test->external_id = $labRequest->labNo;
             DB::transaction(function () use($visit, $specimen, $test) {
                 $visit->save();
                 $specimen->save();
                 $test->visit_id = $visit->id;
                 $test->specimen_id = $specimen->id;
                 $test->save();
             });
             $this->saveToExternalDump($labRequest, $test->id);
             return;
         }
     }
     $this->saveToExternalDump($labRequest, null);
 }