GuestController.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. <?php
  2. namespace App\Http\Controllers;
  3. use App\Models\Appointment;
  4. use App\Models\CareMonth;
  5. use App\Models\CareMonthEntry;
  6. use App\Models\Client;
  7. use App\Models\Handout;
  8. use App\Models\HandoutClient;
  9. use App\Models\Pro;
  10. use App\Models\Section;
  11. use App\Models\SectionTemplate;
  12. use Illuminate\Http\Request;
  13. use Illuminate\Support\Facades\File;
  14. use Illuminate\Support\Facades\Http;
  15. use Illuminate\Support\Facades\Response;
  16. class GuestController extends Controller
  17. {
  18. public function section(Request $request, $guestAccessCode )
  19. {
  20. $section = Section::where('guest_access_code', $guestAccessCode)->first();
  21. abort_if(!$section, 404, 'Invalid access code');
  22. abort_if(!$section->is_active, 404, 'Invalid access code');
  23. abort_if($section->guest_access_level == 'NONE', 401, 'Invalid access code');
  24. $patient = null;
  25. if($section->note){
  26. $patient = $section->note->client;
  27. }else{
  28. $patient = $section->client;
  29. }
  30. return view('app.guest.section', compact('patient','section', 'guestAccessCode'));
  31. }
  32. public function handout(Request $request, $handoutClientUid )
  33. {
  34. $handoutClient = HandoutClient::where('uid', $handoutClientUid)->first();
  35. abort_if((!$handoutClient || !$handoutClient->is_active), 404, 'Invalid access code');
  36. $handout = Handout::where('id', $handoutClient->handout_id)->first();
  37. abort_if((!$handout || !$handout->is_active), 404, 'Invalid access code');
  38. return Response::download(
  39. $handout->pdf_file_path,
  40. $handout->internal_name . '.pdf',
  41. ['Content-Type: application/pdf']
  42. );
  43. }
  44. public function appointmentConfirmation(Request $request, $appointmentUid )
  45. {
  46. $appointment = Appointment::where('uid', $appointmentUid)->first();
  47. abort_if(!count($appointment->confirmationRequests), 404, 'No confirmation requests on this appointment.');
  48. abort_if(!$appointment, 404, 'Invalid url');
  49. abort_if($appointment->status == 'CANCELLED', 404, 'Appointment has been cancelled');
  50. abort_if($appointment->status == 'COMPLETED', 404, 'Appointment has been completed');
  51. abort_if($appointment->status == 'ABANDONED', 404, 'Appointment has been abandoned');
  52. return view('app.guest.appointment-confirmation', compact('appointment'));
  53. }
  54. public function processAppointmentConfirmation(Request $request){
  55. $appointmentUid = $request->get('appointment_uid');
  56. $appointment = Appointment::where('uid', $appointmentUid)->first();
  57. abort_if(!count($appointment->confirmationRequests), 404, 'No confirmation requests on this appointment.');
  58. abort_if(!$appointment, 404, 'Invalid url');
  59. abort_if($appointment->status == 'CANCELLED', 404, 'Appointment has been cancelled');
  60. abort_if($appointment->status == 'COMPLETED', 404, 'Appointment has been completed');
  61. abort_if($appointment->status == 'ABANDONED', 404, 'Appointment has been abandoned');
  62. $decision = $request->get('decision');
  63. $memo = $request->get('memo');
  64. $response = null;
  65. $data = [
  66. 'uid' => $appointment->uid,
  67. 'memo' => $memo
  68. ];
  69. $url = '/appointment/confirmationDecisionAccept';
  70. if($decision == 'REJECT'){
  71. $url = '/appointment/confirmationDecisionReject';
  72. }
  73. $response = $this->calljava($request, $url, $data);
  74. if($response['success']){
  75. return redirect()->back()->with('success', true);
  76. }
  77. return redirect()->back()->with('error', true);
  78. }
  79. // TODO move to utility
  80. private function callJava($request, $endPoint, $data)
  81. {
  82. $url = config('stag.backendUrl') . $endPoint;
  83. $response = Http::asForm()
  84. ->withHeaders([
  85. 'secret' => 'superman'
  86. ])
  87. ->post($url, $data)
  88. ->json();
  89. return $response;
  90. }
  91. }