NoteController.php 4.3 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. // JAVA ONLY
  37. public function getDefaultValueForSection($patientID, $sectionTemplateID)
  38. {
  39. $contentData = [];
  40. $summaryHtml = '';
  41. $patient = Client::where('id', $patientID)->first();
  42. $sectionTemplate = SectionTemplate::where('id', $sectionTemplateID)->first();
  43. if (file_exists(storage_path('sections/' . $sectionTemplate->internal_name . '/default.php'))) {
  44. // default should simply assign to $contentData and $summaryHtml as needed
  45. include(storage_path('sections/' . $sectionTemplate->internal_name . '/default.php'));
  46. }
  47. return [
  48. 'contentData' => $contentData,
  49. 'summaryHtml' => $summaryHtml
  50. ];
  51. }
  52. public function processFormSubmit(Request $request)
  53. {
  54. // TODO require
  55. $section_uid = $request->get('section_uid');
  56. $section = Section::where('uid', $section_uid)->first();
  57. $note = Note::where('id', $section->note_id)->first();
  58. $sectionTemplate = SectionTemplate::where('id', $section->section_template_id)->first();
  59. $newContentData = [];
  60. $newSummaryHtml = "";
  61. $sectionInternalName = $sectionTemplate->internal_name;
  62. if ($sectionTemplate->is_canvas) {
  63. if (file_exists("app.patient.canvas-sections.{$sectionInternalName}.processor")) {
  64. include("app.patient.canvas-sections.{$sectionInternalName}.processor");
  65. } else {
  66. $newContentData = json_decode($request->get('data'), true);
  67. }
  68. ob_start();
  69. include("app.patient.canvas-sections.{$sectionInternalName}.summary");
  70. $newSummaryHtml = ob_get_contents();
  71. ob_end_clean();
  72. } elseif (file_exists(storage_path('sections/' . $sectionTemplate->internal_name . '/form.blade.php'))) {
  73. include(storage_path('sections/' . $sectionTemplate->internal_name . '/processor.php'));
  74. ob_start();
  75. include(storage_path('sections/' . $sectionTemplate->internal_name . '/summary.php'));
  76. $newSummaryHtml = ob_get_contents();
  77. ob_end_clean();
  78. } else {
  79. $newContentData = json_decode($request->get('data'), true);
  80. if (isset($newContentData['value'])) {
  81. $newSummaryHtml = $newContentData['value'];
  82. }
  83. }
  84. $response = null;
  85. $data = [
  86. 'uid' => $section->uid,
  87. 'contentData' => json_encode($newContentData),
  88. 'summaryHtml' => $newSummaryHtml
  89. ];
  90. $response = $this->calljava($request, '/section/update', $data);
  91. return [
  92. 'success' => $response['success'],
  93. 'newSummaryHtml' => $newSummaryHtml
  94. ];
  95. }
  96. // TODO move to utility
  97. private function callJava($request, $endPoint, $data)
  98. {
  99. $url = config('stag.backendUrl') . $endPoint;
  100. $response = Http::asForm()
  101. ->withHeaders(['sessionKey' => $request->cookie('sessionKey')])
  102. ->post($url, $data)
  103. ->json();
  104. return $response;
  105. }
  106. }