NoteController.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. <?php
  2. namespace App\Http\Controllers;
  3. use Illuminate\Http\Request;
  4. use Illuminate\Support\Facades\Http;
  5. use App\HttpModels\ClientLobbyModel;
  6. use App\HttpModels\MeetingModel;
  7. use App\Models\AppSession;
  8. use Cookie;
  9. use App\Models\Note;
  10. use App\Models\Client;
  11. use App\Models\Section;
  12. use App\Models\SectionTemplate;
  13. class NoteController extends Controller
  14. {
  15. public function renderNote($noteUid, Request $request)
  16. {
  17. $note = Note::where('uid', $noteUid)->first();
  18. $client = Client::where('id', $note->client_id)->first();
  19. return view('client/note', compact('note', 'client'));
  20. }
  21. public function sectionCreateForm($note_uid, $section_template_uid, Request $request)
  22. {
  23. $note = Note::where('uid', $note_uid)->first();
  24. $sectionTemplate = SectionTemplate::where('uid', $section_template_uid)->first();
  25. $section = null; // convenience
  26. include(storage_path('sections/' . $sectionTemplate->internal_name . '/form.blade.php'));
  27. }
  28. public function sectionUpdateForm($section_uid, Request $request)
  29. {
  30. $section = Section::where('uid', $section_uid)->first();
  31. $note = Note::where('id', $section->note_id)->first();
  32. $sectionTemplate = SectionTemplate::where('id', $section->section_template_id)->first();
  33. include(storage_path('sections/' . $sectionTemplate->internal_name . '/form.blade.php'));
  34. }
  35. public function processFormSubmit(Request $request)
  36. {
  37. // for CREATE
  38. $note_uid = $request->note_uid;
  39. $section_template_uid = $request->section_template_uid;
  40. // for UPDATE
  41. $section_uid = $request->section_uid;
  42. $section = $section_uid ? Section::where('uid', $section_uid)->first() : null;
  43. $note = null;
  44. $sectionTemplate = null;
  45. if($section == null){
  46. $note = Note::where('uid', $note_uid)->first();
  47. $sectionTemplate = SectionTemplate::where('uid', $section_template_uid)->first();
  48. } else {
  49. $note = Note::where('id', $section->note_id)->first();
  50. $sectionTemplate = SectionTemplate::where('id', $section->section_template_id)->first();
  51. }
  52. $newContentData = [];
  53. // we wish to pass THESE arguments into this include:
  54. // if CREATE, $note and $sectionTemplate, and $request
  55. // if UPDATE, $section, and $request
  56. include(storage_path('sections/' . $sectionTemplate->internal_name . '/processor.php'));
  57. // now, create summaryHtml appropriate
  58. ob_start();
  59. include(storage_path('sections/' . $sectionTemplate->internal_name . '/summary.php'));
  60. $newSummaryHtml = ob_get_contents();
  61. ob_end_clean();
  62. if($section){
  63. // call Java to update section
  64. $data = [
  65. 'uid' => $section->uid,
  66. 'contentData' => json_encode($newContentData),
  67. 'summaryHtml' => $newSummaryHtml
  68. ];
  69. $response = $this->calljava($request, '/section/update', $data);
  70. //TODO: handle if response->success == false
  71. }else{
  72. // call Java to create section
  73. $data = [
  74. 'noteUid' => $note->uid,
  75. 'sectionTemplateUid' => $sectionTemplate->uid,
  76. 'contentData' => json_encode($newContentData),
  77. 'summaryHtml' => $newSummaryHtml
  78. ];
  79. $response = $this->callJava($request, '/section/create', $data);
  80. //TODO: handle if response->success == false
  81. }
  82. return redirect(route('patients.view.notes',$note->client->uid));
  83. }
  84. private function callJava($request, $endPoint, $data){
  85. $url = env('BACKEND_URL', 'http://localhost:8080') . $endPoint;
  86. $response = Http::asForm()
  87. ->withHeaders(['sessionKey'=>$request->cookie('sessionKey')])
  88. ->post($url, $data)
  89. ->json();
  90. return $response;
  91. }
  92. }