123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106 |
- <?php
- namespace App\Http\Controllers;
- use App\Models\Appointment;
- use App\Models\CareMonth;
- use App\Models\CareMonthEntry;
- use App\Models\Client;
- use App\Models\Handout;
- use App\Models\HandoutClient;
- use App\Models\Pro;
- use App\Models\Section;
- use App\Models\SectionTemplate;
- use Illuminate\Http\Request;
- use Illuminate\Support\Facades\File;
- use Illuminate\Support\Facades\Http;
- use Illuminate\Support\Facades\Response;
- class GuestController extends Controller
- {
- public function section(Request $request, $guestAccessCode )
- {
- $section = Section::where('guest_access_code', $guestAccessCode)->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;
- }
- }
|