GuestController.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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 == 'CANCELLED', 404, 'Appointment has been cancelled');
  51. abort_if($appointment->status == 'COMPLETED', 404, 'Appointment has been completed');
  52. abort_if($appointment->status == 'ABANDONED', 404, 'Appointment has been abandoned');
  53. return view('app.guest.appointment-confirmation', compact('appointment'));
  54. }
  55. public function processAppointmentConfirmation(Request $request){
  56. $appointmentUid = $request->get('appointment_uid');
  57. $appointment = Appointment::where('uid', $appointmentUid)->first();
  58. abort_if(!count($appointment->confirmationRequests), 404, 'No confirmation requests on this appointment.');
  59. abort_if(!$appointment, 404, 'Invalid url');
  60. abort_if($appointment->status == 'CANCELLED', 404, 'Appointment has been cancelled');
  61. abort_if($appointment->status == 'COMPLETED', 404, 'Appointment has been completed');
  62. abort_if($appointment->status == 'ABANDONED', 404, 'Appointment has been abandoned');
  63. $decision = $request->get('decision');
  64. $memo = $request->get('memo');
  65. $response = null;
  66. $data = [
  67. 'uid' => $appointment->uid,
  68. 'memo' => $memo
  69. ];
  70. $url = '/appointment/confirmationDecisionAccept';
  71. if($decision == 'REJECT'){
  72. $url = '/appointment/confirmationDecisionReject';
  73. }
  74. $response = $this->calljava($request, $url, $data);
  75. if($response['success']){
  76. return redirect()->back()->with('success', true);
  77. }
  78. return redirect()->back()->with('error', true);
  79. }
  80. // TODO move to utility
  81. private function callJava($request, $endPoint, $data)
  82. {
  83. $url = config('stag.backendUrl') . $endPoint;
  84. $response = Http::asForm()
  85. ->withHeaders([
  86. 'secret' => 'superman'
  87. ])
  88. ->post($url, $data)
  89. ->json();
  90. return $response;
  91. }
  92. }