/**
  * Performs the work of inserting or updating the row in the database.
  *
  * If the object is new, it inserts it; otherwise an update is performed.
  * All related objects are also updated in this method.
  *
  * @param      PropelPDO $con
  * @return     int The number of rows affected by this insert/update and any referring fk objects' save() operations.
  * @throws     PropelException
  * @see        save()
  */
 protected function doSave(PropelPDO $con)
 {
     $affectedRows = 0;
     // initialize var to track total num of affected rows
     if (!$this->alreadyInSave) {
         $this->alreadyInSave = true;
         // We call the save method on the following object(s) if they
         // were passed to this object by their coresponding set
         // method.  This object relates to these object(s) by a
         // foreign key reference.
         if ($this->aPatient !== null) {
             if ($this->aPatient->isModified() || $this->aPatient->isNew()) {
                 $affectedRows += $this->aPatient->save($con);
             }
             $this->setPatient($this->aPatient);
         }
         if ($this->aVisit !== null) {
             if ($this->aVisit->isModified() || $this->aVisit->isNew()) {
                 $affectedRows += $this->aVisit->save($con);
             }
             $this->setVisit($this->aVisit);
         }
         if ($this->aPharma !== null) {
             if ($this->aPharma->isModified() || $this->aPharma->isNew()) {
                 $affectedRows += $this->aPharma->save($con);
             }
             $this->setPharma($this->aPharma);
         }
         if ($this->aDosage !== null) {
             if ($this->aDosage->isModified() || $this->aDosage->isNew()) {
                 $affectedRows += $this->aDosage->save($con);
             }
             $this->setDosage($this->aDosage);
         }
         if ($this->isNew()) {
             $this->modifiedColumns[] = VisitMedicinePeer::ID;
         }
         // If this object has been modified, then save it to the database.
         if ($this->isModified()) {
             if ($this->isNew()) {
                 $pk = VisitMedicinePeer::doInsert($this, $con);
                 $affectedRows += 1;
                 // we are assuming that there is only 1 row per doInsert() which
                 // should always be true here (even though technically
                 // BasePeer::doInsert() can insert multiple rows).
                 $this->setId($pk);
                 //[IMV] update autoincrement primary key
                 $this->setNew(false);
             } else {
                 $affectedRows += VisitMedicinePeer::doUpdate($this, $con);
             }
             $this->resetModified();
             // [HL] After being saved an object is no longer 'modified'
         }
         $this->alreadyInSave = false;
     }
     return $affectedRows;
 }
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new Visit();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['Visit'])) {
         $model->attributes = $_POST['Visit'];
         if ($model->save()) {
             $this->redirect(array('view', 'id' => $model->visit_id));
         }
     }
     $this->render('create', array('model' => $model));
 }
Example #3
0
 public function _visit($uid, $data)
 {
     $uid = intval($uid);
     $info = Visit::findFirst("uid={$uid}");
     if (!$info) {
         $info = new Visit();
         $info->addtime = time();
     }
     $info->uptime = time();
     $result = $info->save($data);
     if (!$result) {
         $this->outputErrors($info);
         return false;
     }
     return true;
 }
Example #4
0
 /**
  * 用户信息
  */
 public function actionUserinfo()
 {
     //   $this->layout = '//layouts/main';
     $user_id = $_GET["user_id"];
     $model = User::model()->findByPk($user_id);
     $privArray = unserialize($model->priv);
     $visitPriv = $privArray['visit_priv'];
     $countArray = unserialize($model->visit_count);
     $visitCount = $countArray['visit_count'] ? $countArray['visit_count'] : 0;
     $refuseCount = $countArray['refuse_count'] ? $countArray['refuse_count'] : 0;
     $followeesArray = $model->followees == "" ? array() : explode(",", trim($model->followees));
     if (!Yii::app()->user->isGuest && Yii::app()->user->id != $user_id && ($visitPriv == 2 || $visitPriv == 1 && in_array(Yii::app()->user->id, $followeesArray))) {
         $count = Visit::model()->count("is_visit=0 and from_user = "******" and to_user = "******"visit_count" => serialize($visitArray)));
         } else {
             $time = strtotime(date("Y-m-d", time()));
             $oldCount = Visit::model()->count("is_visit=0 and from_user = "******" and to_user = "******" and create_time > " . $time);
             if ($oldCount == 0) {
                 $visitArray = array('visit_count' => $visitCount + 1, 'refuse_count' => $refuseCount + 1);
                 User::model()->updateByPk($user_id, array("visit_count" => serialize($visitArray)));
             }
             $oldVist = Visit::model()->find("is_visit=0 and from_user = "******" and to_user = "******"visit_count" => serialize($visitArray)));
             }
             throw new CHttpException(404, '你没有访问TA空间的权限!');
         } else {
             if (Yii::app()->user->isGuest) {
                 if (!isset($_GET['type'])) {
                     $visitArray = array('visit_count' => $visitCount + 1, 'refuse_count' => $refuseCount);
                     User::model()->updateByPk($user_id, array("visit_count" => serialize($visitArray)));
                 }
             } else {
                 if (Yii::app()->user->id != $user_id) {
                     $count = Visit::model()->count("is_visit=1 and from_user = "******" and to_user = "******"visit_count" => serialize($visitArray)));
                     } else {
                         $time = strtotime(date("Y-m-d", time()));
                         $oldCount = Visit::model()->count("is_visit=1 and from_user = "******" and to_user = "******" and create_time > " . $time);
                         if ($oldCount == 0) {
                             $visitArray = array('visit_count' => $visitCount + 1, 'refuse_count' => $refuseCount);
                             User::model()->updateByPk($user_id, array("visit_count" => serialize($visitArray)));
                         }
                         $oldVist = Visit::model()->find("is_visit=1 and from_user = "******" and to_user = "******"pk_id"])) {
                 if (Notification::model()->findByPk($_GET["pk_id"])->remind_flag == 0) {
                     Notification::model()->updateByPk($_GET["pk_id"], array("remind_flag" => 1));
                 }
             }
             $modelComment = new Comment();
             $criteria = new CDbCriteria();
             $criteria->addCondition("publish=1 and create_user="******"user_id" => $user_id, 'dataProvider' => $dataProvider, 'modelComment' => $modelComment, "model" => $model));
         }
     }
 }
 /**
  * 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);
 }
Example #6
0
 public function postVisitAdd()
 {
     $branch_id = Input::get('branch_id');
     $branch = Branch::find($branch_id);
     $validator = Validator::make(Input::all(), Visit::$rules);
     if ($validator->fails()) {
         return Redirect::to('branch/visit-add/' . $branch_id)->withErrors($validator)->withInput();
     }
     $visit = new Visit();
     $visit->branch_id = $branch_id;
     $visit->user_id = $branch->user_id;
     $visit->comment = Input::get('comment');
     $visit->visit_at = $this->__time();
     $visit->check = '0';
     $visit->save();
     // 重置最后回访时间
     //
     $branch->last_visit_at = $visit->visit_at;
     $branch->save();
     return Redirect::to('branch')->with('success', '回访添加成功!');
 }
Example #7
0
 public function executeVisitAdd(sfWebRequest $request)
 {
     if ($request->isMethod('POST')) {
         $visit = new Visit();
         $visit->setPatientId($this->getRequestParameter('patient_id'));
         if ($this->getRequestParameter('doctor_id')) {
             $visit->setDoctorId($this->getRequestParameter('doctor_id'));
         }
         if ($this->getRequestParameter('ward_doc_id')) {
             $visit->setWardDocId($this->getRequestParameter('ward_doc_id'));
         }
         if ($this->getRequestParameter('ward_bed_id')) {
             $visit->setWardBedId($this->getRequestParameter('ward_bed_id'));
         }
         if ($this->getRequestParameter('room_id')) {
             $visit->setRoomId($this->getRequestParameter('room_id'));
         }
         if ($this->getRequestParameter('admit_date')) {
             $visit->setAdmitDate($this->getRequestParameter('admit_date'));
         }
         $visit->setVisitDate($this->getRequestParameter('visit_date'));
         $visit->setTime($this->getRequestParameter('time'));
         $visit->setVisitType($this->getRequestParameter('visit_type'));
         $visit->setStatus(Constant::VISIT_PENDING);
         $visit->save();
         $this->getUser()->setFlash('SUCCESS_MESSAGE', 'Visit to Doctor added Successfully.');
         $this->redirect('FrontDesk/visitList');
     } else {
         $this->patient = PatientPeer::retrieveByPk(Utility::DecryptQueryString($request->getParameter('patient')));
     }
 }
Example #8
0
 /**
  *	@fn log_visit
  *	@short Filter method that saves a Visit object for current request.
  */
 protected function log_visit()
 {
     if (self::LOG_VISITS) {
         $visit = new Visit();
         $visit->save();
     }
 }
 /**
  * Save a new Test.
  *
  * @return Response
  */
 public function saveNewTest()
 {
     //Create New Test
     $rules = array('visit_type' => 'required', 'physician' => 'required', 'testtypes' => 'required');
     $validator = Validator::make(Input::all(), $rules);
     // process the login
     if ($validator->fails()) {
         return Redirect::route('test.create', array(Input::get('patient_id')))->withInput()->withErrors($validator);
     } else {
         $visitType = ['Out-patient', 'In-patient'];
         $activeTest = array();
         /*
          * - Create a visit
          * - Fields required: visit_type, patient_id
          */
         $visit = new Visit();
         $visit->patient_id = Input::get('patient_id');
         $visit->visit_type = $visitType[Input::get('visit_type')];
         $visit->save();
         /*
          * - Create tests requested
          * - Fields required: visit_id, test_type_id, specimen_id, test_status_id, created_by, requested_by
          */
         $testTypes = Input::get('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::get('SOURCE_URL');
         return Redirect::to($url)->with('message', 'messages.success-creating-test')->with('activeTest', $activeTest);
     }
 }
Example #10
0
 /**
  * Saving visit
  */
 public function save()
 {
     $visit = new \Visit($this->to_array());
     return $visit->save();
 }
Example #11
0
 public function findEmptyCommentsVisitAssociated()
 {
     $visits_to_make = [];
     $comments = Comment::withTrashed()->whereBody('')->where('commentable_type', '=', 'Spot')->orWhereNull('body')->get()->each(function ($item) use(&$visits_to_make) {
         // do we have a visit ?
         $visit = Visit::withTrashed()->where('user_id', '=', $item->user_id)->where('spot_id', '=', $item->commentable_id)->get();
         if ($visit->count() == 0) {
             array_push($visits_to_make, (object) ['user_id' => $item->user_id, 'spot_id' => $item->commentable_id, 'timestamp' => $item->created_at]);
         }
     });
     foreach ($visits_to_make as $make) {
         $user = User::find($make->user_id);
         $spot = Spot::find($make->spot_id);
         if ($user && $spot) {
             $visit = new Visit();
             $visit->timestamps = false;
             $visit->user()->associate($user);
             $visit->spot()->associate($spot);
             $visit->created_at = $visit->updated_at = $make->timestamp;
             $visit->save();
             $visit->timestamps = true;
             $visit->fireActivityEvent();
         }
     }
     $comments->each(function ($item) {
         $item->forceDelete();
     });
     return [$visits_to_make, $comments];
 }