NoteController.php 4.0 KB

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