NoteController.php 4.5 KB

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