first(); abort_if(!$section, 404, 'Invalid access code'); abort_if(!$section->is_active, 404, 'Invalid access code'); abort_if($section->guest_access_level == 'NONE', 401, 'Invalid access code'); $patient = null; if($section->note){ abort_if($section->note->is_signed_by_hcp, 401, 'Note is already signed.'); $patient = $section->note->client; }else{ $patient = $section->client; } return view('app.guest.section', compact('patient','section', 'guestAccessCode')); } public function handout(Request $request, $handoutClientUid ) { $handoutClient = HandoutClient::where('uid', $handoutClientUid)->first(); abort_if((!$handoutClient || !$handoutClient->is_active), 404, 'Invalid access code'); $handout = Handout::where('id', $handoutClient->handout_id)->first(); abort_if((!$handout || !$handout->is_active), 404, 'Invalid access code'); return Response::download( $handout->pdf_file_path, $handout->internal_name . '.pdf', ['Content-Type: application/pdf'] ); } public function appointmentConfirmation(Request $request, $appointmentUid ) { $appointment = Appointment::where('uid', $appointmentUid)->first(); abort_if(!count($appointment->confirmationRequests), 404, 'No confirmation requests on this appointment.'); abort_if(!$appointment, 404, 'Invalid url'); abort_if($appointment->status == 'COMPLETED', 404, 'Appointment has been completed'); return view('app.guest.appointment-confirmation', compact('appointment')); } public function processAppointmentConfirmation(Request $request){ $appointmentUid = $request->get('appointment_uid'); $appointment = Appointment::where('uid', $appointmentUid)->first(); abort_if(!count($appointment->confirmationRequests), 404, 'No confirmation requests on this appointment.'); abort_if(!$appointment, 404, 'Invalid url'); abort_if($appointment->status == 'COMPLETED', 404, 'Appointment has been completed'); $decision = $request->get('decision'); $memo = $request->get('memo'); $response = null; $data = [ 'uid' => $appointment->uid, 'memo' => $memo, 'confirmationDecisionEnum' => ($decision == 'REJECT' ? 'CANCELLED' : 'CONFIRMED') ]; $url = '/appointment/putConfirmationDecision'; $response = $this->calljava($request, $url, $data); if($response['success']){ return redirect()->back()->with('success', true); } return redirect()->back()->with('error', true); } // TODO move to utility private function callJava($request, $endPoint, $data) { $url = config('stag.backendUrl') . $endPoint; $response = Http::asForm() ->withHeaders([ 'secret' => 'superman' ]) ->post($url, $data) ->json(); return $response; } public function viewSurveyForm(Request $request, $accessKey){ $survey = Survey::where('access_key', $accessKey)->where('is_accessible_to_target', true)->where('is_active', true)->first(); if(!$survey) abort(404); $surveyFormPath = resource_path(Survey::FORM_PATH . '/' . $survey->internal_name . '.blade.php'); if(!file_exists($surveyFormPath)) abort(404); $entity = null; if($survey->entity_type === 'Client'){ $entity = Client::where('uid', $survey->entity_uid)->first(); } if(!$entity) abort(404); $layout = 'app.patient.surveys.partials.form-layout'; return view('app.patient.surveys.forms.form', compact('entity', 'survey', 'layout')); } public function viewSurveyFormSubmit(Request $request, $accessKey){ $survey = Survey::where('access_key', $accessKey)->where('is_accessible_to_target', true)->where('is_active', true)->first(); if(!$survey) abort(404); $formData = [ 'uid' => $survey->uid, 'surveyDataJson' => $request->get('data'), 'surveyHTML' => $survey->surveyhtml, ]; $url = '/survey/submitData'; $response = $this->calljava($request, $url, $formData); if($response['success']){ return redirect()->back()->with('success', 'Information saved!'); } return redirect()->back()->with('error', $response['message']); } public function viewSurveyFormAutoSubmit(Request $request, $accessKey){ $survey = Survey::where('access_key', $accessKey)->where('is_accessible_to_target', true)->where('is_active', true)->first(); if(!$survey) return $this->fail('Invalid survey access key!'); $formData = [ 'uid' => $survey->uid, 'surveyDataJson' => $request->get('dataJson'), ]; $url = '/survey/submitData'; $response = $this->calljava($request, $url, $formData); if($response['success']){ return $this->pass(); } return $this->fail($response['message']); } public function viewSurveyFormGetData(Request $request, $accessKey){ $survey = Survey::where('access_key', $accessKey)->where('is_accessible_to_target', true)->where('is_active', true)->first(); return $this->pass($survey); } public function surveyTemplatePreview(Request $request, $internalName){ $surveyService = new SurveyService($internalName); $defaultHtml = $surveyService->defaultHTML; if(!$defaultHtml) return 'No default HTML template found for ' . $internalName; $entityType = $request->get('entityType'); $entityUid = $request->get('entityUid'); $initializedData = $surveyService->getInitializedData($entityType, $entityUid); $survey = new Survey; $survey->surveyhtml = $defaultHtml; $survey->survey_data = json_encode($initializedData); return $survey; } }