GuestController.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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. abort_if($section->note->is_signed_by_hcp, 401, 'Note is already signed.');
  27. $patient = $section->note->client;
  28. }else{
  29. $patient = $section->client;
  30. }
  31. return view('app.guest.section', compact('patient','section', 'guestAccessCode'));
  32. }
  33. public function handout(Request $request, $handoutClientUid )
  34. {
  35. $handoutClient = HandoutClient::where('uid', $handoutClientUid)->first();
  36. abort_if((!$handoutClient || !$handoutClient->is_active), 404, 'Invalid access code');
  37. $handout = Handout::where('id', $handoutClient->handout_id)->first();
  38. abort_if((!$handout || !$handout->is_active), 404, 'Invalid access code');
  39. return Response::download(
  40. $handout->pdf_file_path,
  41. $handout->internal_name . '.pdf',
  42. ['Content-Type: application/pdf']
  43. );
  44. }
  45. public function appointmentConfirmation(Request $request, $appointmentUid )
  46. {
  47. $appointment = Appointment::where('uid', $appointmentUid)->first();
  48. abort_if(!count($appointment->confirmationRequests), 404, 'No confirmation requests on this appointment.');
  49. abort_if(!$appointment, 404, 'Invalid url');
  50. abort_if($appointment->status == 'COMPLETED', 404, 'Appointment has been completed');
  51. return view('app.guest.appointment-confirmation', compact('appointment'));
  52. }
  53. public function processAppointmentConfirmation(Request $request){
  54. $appointmentUid = $request->get('appointment_uid');
  55. $appointment = Appointment::where('uid', $appointmentUid)->first();
  56. abort_if(!count($appointment->confirmationRequests), 404, 'No confirmation requests on this appointment.');
  57. abort_if(!$appointment, 404, 'Invalid url');
  58. abort_if($appointment->status == 'COMPLETED', 404, 'Appointment has been completed');
  59. $decision = $request->get('decision');
  60. $memo = $request->get('memo');
  61. $response = null;
  62. $data = [
  63. 'uid' => $appointment->uid,
  64. 'memo' => $memo,
  65. 'confirmationDecisionEnum' => ($decision == 'REJECT' ? 'CANCELLED' : 'CONFIRMED')
  66. ];
  67. $url = '/appointment/putConfirmationDecision';
  68. $response = $this->calljava($request, $url, $data);
  69. if($response['success']){
  70. return redirect()->back()->with('success', true);
  71. }
  72. return redirect()->back()->with('error', true);
  73. }
  74. // TODO move to utility
  75. private function callJava($request, $endPoint, $data)
  76. {
  77. $url = config('stag.backendUrl') . $endPoint;
  78. $response = Http::asForm()
  79. ->withHeaders([
  80. 'secret' => 'superman'
  81. ])
  82. ->post($url, $data)
  83. ->json();
  84. return $response;
  85. }
  86. }