/**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     DB::table('visits')->delete();
     $visit = new Visit(['docId' => '2001', 'patId' => '4001', 'month' => '12', 'day' => '7', 'hour' => '12']);
     $visit->save();
     $visit = new Visit(['docId' => '2001', 'patId' => '4001', 'month' => '12', 'day' => '7', 'hour' => '14']);
     $visit->save();
     $visit = new Visit(['docId' => '2001', 'patId' => '4001', 'month' => '12', 'day' => '7', 'hour' => '16']);
     $visit->save();
     $visit = new Visit(['docId' => '2002', 'patId' => '4002', 'month' => '12', 'day' => '7', 'hour' => '6']);
     $visit->save();
     $visit = new Visit(['docId' => '2002', 'patId' => '4002', 'month' => '12', 'day' => '7', 'hour' => '10']);
     $visit->save();
     $visit = new Visit(['docId' => '2002', 'patId' => '4002', 'month' => '12', 'day' => '7', 'hour' => '14']);
     $visit->save();
     $visit = new Visit(['docId' => '2003', 'patId' => '4003', 'month' => '12', 'day' => '7', 'hour' => '10']);
     $visit->save();
     $visit = new Visit(['docId' => '2003', 'patId' => '4003', 'month' => '12', 'day' => '7', 'hour' => '11']);
     $visit->save();
     $visit = new Visit(['docId' => '2003', 'patId' => '4003', 'month' => '12', 'day' => '7', 'hour' => '12']);
     $visit->save();
     $visit = new Visit(['docId' => '2004', 'patId' => '4004', 'month' => '12', 'day' => '7', 'hour' => '6']);
     $visit->save();
     $visit = new Visit(['docId' => '2004', 'patId' => '4004', 'month' => '12', 'day' => '7', 'hour' => '9']);
     $visit->save();
     $visit = new Visit(['docId' => '2004', 'patId' => '4004', 'month' => '12', 'day' => '7', 'hour' => '12']);
     $visit->save();
 }
 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(NewVisitRequest $request)
 {
     $visit = new Visit($request->all());
     $visit->save();
     flash()->overlay('new visit record added!', 'notice');
     return redirect('visit');
 }
 /**
  * Handle an incoming request.
  *
  * @param  Request  $request
  * @param  \Closure  $next
  * @return mixed
  */
 public function handle(Request $request, Closure $next)
 {
     if (!$request->ajax()) {
         $visit = new Visit();
         $visit->page = parse_url($request->fullUrl(), PHP_URL_PATH);
         $visit->ip = $request->ip();
         $visit->host = $request->getHost();
         $visit->user_agent = Agent::browser() . ' ' . Agent::version(Agent::browser());
         $visit->save();
     }
     return $next($request);
 }
Exemple #4
0
 /**
  * Store a newly created resource in storage.
  *
  * @return \Illuminate\Http\Response
  */
 public function store(HandleVisitRequest $request)
 {
     // Make sure this is a valid stage
     $stage = Stage::where('id', '=', $request->stage);
     if ($stage->count() > 0) {
         $stage = $stage->first();
     } else {
         return response()->json(['status' => 'failure', 'message' => sprintf('Stage with ID %s does not exist', $request->stage)], 422);
     }
     // Make sure the destination is valid.
     if ($request->destination !== "__checkout__") {
         $destination = Stage::where('id', '=', $request->destination);
         if ($destination->count() == 0) {
             return response()->json(['status' => 'failure', 'message' => sprintf('Destination stage [ID: %s] does not exist', $request->destination)]);
         }
     }
     // Check if the visit has been created yet
     $visit;
     if (is_null($request->visit) || strlen($request->visit) == 0) {
         // Create a new visit
         $visit = new Visit();
         $visit->patients = array_keys($request->patients);
         $visit->stage = $request->stage;
         $saved = $visit->save();
         if (!$saved) {
             return response()->json(['status' => 'failure', 'message' => 'Failed to save new visit record.'], 422);
         }
     } else {
         // Check if the visit exists
         $visit = Visit::where('id', '=', $request->visit);
         if ($visit->count() > 0) {
             $visit = $visit->first();
         } else {
             return response()->json(['status' => 'failure', 'message' => sprintf('Visit with ID %s does not exist.', $request->visit)]);
         }
     }
     $errors = [];
     // Loop through patients, add a new row to the respective Stage for each patient
     foreach ($request->patients as $patientID => $patientData) {
         // Setup data array
         $data = array();
         // Make sure all the values in the patientData array are valid stage columns
         foreach ($patientData as $key => $value) {
             if (array_key_exists($key, $stage->fields)) {
                 // Check if we should mutate the data (i.e. multiselect)
                 switch ($stage->fields[$key]["type"]) {
                     case "file":
                     case "pharmacy":
                     case "multiselect":
                         // Value is an array, convert to string
                         $data[$key] = json_encode($value);
                         break;
                     default:
                         $data[$key] = $value;
                         break;
                 }
             } else {
                 \Log::debug(sprintf('Attemped to update stage [%s], column [%s], but this column is not valid', $stage->id, $key));
             }
         }
         // Make sure this patient record exists
         $patient = Patient::where('id', '=', $patientID);
         // If the patient exists...
         if ($patient->count() > 0) {
             // Grab patient record
             $patient = $patient->first();
             // Update patient record as necessary
             if ($stage->root) {
                 // All data is relative to Patient record
                 $data['concrete'] = true;
                 $data['current_visit'] = $visit->id;
                 // Add this visit ID to patient all-time visits array
                 // (we're at the root stage so this hasnt been done yet)
                 $thisPatientVisits = $patient->visits;
                 $thisPatientVisits[] = $visit->id;
                 $data['visits'] = $thisPatientVisits;
                 \Log::debug("Updating patient record at root stage with data:");
                 \Log::debug($data);
                 // Update patient record.
                 $patient->update($data);
             } else {
                 // Set visit_id and patient_id for reference in this stage
                 $data["visit_id"] = $visit->id;
                 $data["patient_id"] = $patientID;
                 // Insert data into this stage's table
                 DB::table($stage->tableName)->insert($data);
             }
             // If the destination is checkout, remove "current visit" from patient
             if ($request->destination == "__checkout__") {
                 \Log::debug("Destination for patient " . $patient->id . " in visit " . $visit->id . " is " . $request->destination);
                 $patient->current_visit = null;
                 $patient->save();
             }
         } else {
             $error = sprintf("Could not locate patient record [id: %s]", $patientID);
             $errors[] = $error;
             \Log::debug($error);
         }
     }
     // Patient data has been stored, update Visit record
     $visit->stage = $request->destination;
     if ($visit->save()) {
         return response()->json(['status' => 'success', 'message' => 'Visit moved successfully.', 'toStage' => $request->destination, 'visitID' => $visit->id, 'errors' => $errors]);
     } else {
         return response()->json(['status' => 'failure', 'message' => 'Failed to save visit record.', 'errors' => $errors]);
     }
 }
 /**
  * Check the member in
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function checkin($did, $mid)
 {
     $device = CheckInDevice::find($did);
     $member = Member::find($mid);
     if (NULL == $device || NULL == $member) {
         return response()->json("", 404);
     } else {
         $active = Visit::where('memberID', $mid)->where('deviceID', $did)->where('checkOut', NULL)->get();
         if (0 < $active->count()) {
             // member is checked in, return a 400 failure
             return response()->json("", 400);
         } else {
             $visit = new Visit();
             $visit->memberID = $mid;
             $visit->deviceID = $did;
             $visit->checkout = NULL;
             $visit->checkin = date("Y-m-d H:i:s");
             $visit->save();
             return response()->json("", 200);
         }
     }
 }