123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140 |
- <?php
- namespace App\Http\Controllers;
- use App\Models\Pro;
- use Illuminate\Http\Request;
- use Illuminate\Support\Collection;
- use Illuminate\Support\Facades\Http;
- use App\Models\Note;
- use App\Models\Client;
- use App\Models\Section;
- use App\Models\SectionTemplate;
- class NoteController extends Controller
- {
- public function dashboard(Request $request, Client $patient, Note $note )
- {
- $pros = Pro::all();
- $noteSections = $note->sections;
- $allSections = SectionTemplate::where('is_active', true)->get();
- foreach ($allSections as $section) {
- $section->used = false;
- foreach ($noteSections as $noteSection) {
- if($noteSection->sectionTemplate->id === $section->id) {
- $section->used = true;
- $section->section_uid = $noteSection->uid;
- break;
- }
- }
- }
- return view('app.patient.note.dashboard', compact('patient', 'note', 'pros', 'allSections'));
- }
- public function renderNote($noteUid, Request $request)
- {
- $note = Note::where('uid', $noteUid)->first();
- $client = Client::where('id', $note->client_id)->first();
- return view('client/note', compact('note', 'client'));
- }
- public function sectionCreateForm($note_uid, $section_template_uid, Request $request)
- {
- $note = Note::where('uid', $note_uid)->first();
- $sectionTemplate = SectionTemplate::where('uid', $section_template_uid)->first();
- $section = null; // convenience
- include(storage_path('sections/' . $sectionTemplate->internal_name . '/form.blade.php'));
- }
- public function sectionUpdateForm($section_uid, Request $request)
- {
- $section = Section::where('uid', $section_uid)->first();
- $note = Note::where('id', $section->note_id)->first();
- $sectionTemplate = SectionTemplate::where('id', $section->section_template_id)->first();
- include(storage_path('sections/' . $sectionTemplate->internal_name . '/form.blade.php'));
- }
- public function getDefaultValueForSection($section, $patient_uid) {
- $defaultData = [
- "summary" => "",
- "value" => ""
- ];
- $patient = Client::where('uid', $patient_uid)->first();
- if(file_exists(storage_path('sections/' . $section . '/default.php'))) {
- include(storage_path('sections/' . $section . '/default.php'));
- }
- return json_encode($defaultData);
- }
- public function processFormSubmit(Request $request)
- {
- // for CREATE
- $note_uid = $request->note_uid;
- $section_template_uid = $request->section_template_uid;
- // for UPDATE
- $section_uid = $request->section_uid;
- $section = $section_uid ? Section::where('uid', $section_uid)->first() : null;
- $note = null;
- $sectionTemplate = null;
- if($section == null){
- $note = Note::where('uid', $note_uid)->first();
- $sectionTemplate = SectionTemplate::where('uid', $section_template_uid)->first();
- } else {
- $note = Note::where('id', $section->note_id)->first();
- $sectionTemplate = SectionTemplate::where('id', $section->section_template_id)->first();
- }
- $newContentData = [];
- // we wish to pass THESE arguments into this include:
- // if CREATE, $note and $sectionTemplate, and $request
- // if UPDATE, $section, and $request
- include(storage_path('sections/' . $sectionTemplate->internal_name . '/processor.php'));
- // now, create summaryHtml appropriate
- ob_start();
- include(storage_path('sections/' . $sectionTemplate->internal_name . '/summary.php'));
- $newSummaryHtml = ob_get_contents();
- ob_end_clean();
- if($section){
- // call Java to update section
- $data = [
- 'uid' => $section->uid,
- 'contentData' => json_encode($newContentData),
- 'summaryHtml' => $newSummaryHtml
- ];
- $response = $this->calljava($request, '/section/update', $data);
- //TODO: handle if response->success == false
- }else{
- // call Java to create section
- $data = [
- 'noteUid' => $note->uid,
- 'sectionTemplateUid' => $sectionTemplate->uid,
- 'contentData' => json_encode($newContentData),
- 'summaryHtml' => $newSummaryHtml
- ];
- $response = $this->callJava($request, '/section/create', $data);
- //TODO: handle if response->success == false
- }
- // return redirect(route('patients.view.notes',$note->client->uid));
- return "";
- }
- private function callJava($request, $endPoint, $data){
- $url = env('BACKEND_URL', 'http://localhost:8080/api') . $endPoint;
- $response = Http::asForm()
- ->withHeaders(['sessionKey'=>$request->cookie('sessionKey')])
- ->post($url, $data)
- ->json();
- return $response;
- }
- }
|