pros; $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; } } } // load tickets created on note->effective_date for patient $ticketsOnNote = Ticket::where('client_id', $patient->id) ->where('is_entry_error', false) ->where('note_id', $note->id) ->get(); // other open tickets as of today $otherOpenTickets = Ticket::where('client_id', $patient->id) ->where('is_entry_error', false) ->where('is_open', true) ->where(function ($query) use ($note) { $query->where('note_id', '<>', $note->id)->orWhereNull('note_id'); // weird, but just the <> isn't working! }) ->get(); // load supplyOrders created on note->effective_date for patient $supplyOrdersOnNote = SupplyOrder::where('client_id', $patient->id) ->where('is_cancelled', false) ->where('note_id', $note->id) ->get(); // other open supplyOrders as of today $otherOpenSupplyOrders = SupplyOrder::where('client_id', $patient->id) ->where('is_cancelled', false) ->get(); return view('app.patient.note.dashboard', compact('patient', 'note', 'allSections', 'ticketsOnNote', 'otherOpenTickets', 'supplyOrdersOnNote', 'otherOpenSupplyOrders')); } 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 sectionView(Request $request, Client $patient, Note $note, Section $section, $form, Page $page = null) { return view("app.patient.page-sections." . $section->sectionTemplate->internal_name . "." . $form, compact('patient', 'note', 'section', 'page')); } public function getHtmlForSegment($segmentUid, $sessionKey){ $performer = AppSession::where('session_key', $sessionKey)->first(); if(!$performer || !$performer->is_active){ return response()->json([ 'success'=>false, 'message'=>'Invalid session key' ]); } $pro = $performer->pro; $segment = Segment::where('uid', $segmentUid)->first(); $segmentTemplate = $segment->segmentTemplate; $note = $segment->note; $patient = $note->client; $data = compact('performer', 'pro', 'segment', 'segmentTemplate', 'note', 'patient'); //try { $summaryHtml = view('app.patient.segment-templates.' . $segmentTemplate->internal_name . '/summary', $data)->render(); $editHtml = view('app.patient.segment-templates.' . $segmentTemplate->internal_name . '/edit', $data)->render(); // } catch (\Throwable $e) { // return response()->json([ // 'success'=>false, // 'message'=>$e->getMessage() // ]); // } return response()->json([ 'success'=>true, 'summaryHtml' => $summaryHtml, 'editHtml' => $editHtml ]); } // JAVA ONLY // ... if hcpProId is passed, get from request public function getDefaultValueForSection($patientID, $sectionTemplateID) { $contentData = []; $summaryHtml = ''; $patient = Client::where('id', $patientID)->first(); $sectionTemplate = SectionTemplate::where('id', $sectionTemplateID)->first(); if ($sectionTemplate->is_canvas) { if (file_exists(resource_path('views/app/patient/canvas-sections/' . $sectionTemplate->internal_name . '/default.php'))) { // for canvas section where we have pro mapped data, use hcpProId $hcpPro = null; if(\request()->input('hcpProUid')) { $hcpPro = Pro::where('uid', \request()->input('hcpProUid'))->first(); } $note = null; if(\request()->input('noteUid')) { $note = Note::where('uid', \request()->input('noteUid'))->first(); } // default should simply assign to $contentData include(resource_path('views/app/patient/canvas-sections/' . $sectionTemplate->internal_name . '/default.php')); ob_start(); include(resource_path('views/app/patient/canvas-sections/' . $sectionTemplate->internal_name . '/summary.php')); $summaryHtml = ob_get_contents(); ob_end_clean(); } } else { if (file_exists(storage_path('sections/' . $sectionTemplate->internal_name . '/default.php'))) { // default should simply assign to $contentData and $summaryHtml as needed include(storage_path('sections/' . $sectionTemplate->internal_name . '/default.php')); } } return [ 'contentData' => $contentData, 'summaryHtml' => $summaryHtml ]; } public function processFormSubmit(Request $request) { // guest_access_code, section_uid, data // REMEMBER, if this is an hcp scoped canvas section, data will not be the ENTIRE node... // ... it will only be the hcp scope within that node $guestAccessCode = $request->get('guest_access_code'); if($guestAccessCode){ //its from guest $sectionForToken = Section::where('guest_access_code', $guestAccessCode)->first(); abort_if(!$sectionForToken, 401, 'Unauthorized'); }else{ //its not from guest so require performer abort_if(!$this->performer, 401, 'Unauthorized'); abort_if(!$this->performer->is_active, 401, 'Unauthorized'); } // TODO require $section_uid = $request->get('section_uid'); $section = Section::where('uid', $section_uid)->first(); $note = Note::where('id', $section->note_id)->first(); $client = null; if($note){ $client = Client::where('id', $note->client_id)->first(); }else{ $client = Client::where('id', $section->client_id)->first(); } $patient = $client; $sectionTemplate = SectionTemplate::where('id', $section->section_template_id)->first(); $newContentData = []; $newSummaryHtml = ""; $sectionInternalName = $sectionTemplate->internal_name; if ($sectionTemplate->is_canvas) { $key = $sectionTemplate->internal_name; // Because sectionTemplate is_canvas, any update to the section will require updating the canvas. // ... there are TWO possibilities. // ...... 1) if !is_hcp_scoped, then what comes in from the section simply swaps out the entire node // ...... 2) if is_hcp_scoped, then what comes in from the section is incoprorated into that scope in the node $newCanvasNodeData = null; if($sectionTemplate->is_hcp_scoped){ $currentCanvasData = json_decode($client->canvas_data, true); $currentCanvasDataNode = isset($currentCanvasData[$key]) ? $currentCanvasData[$key] : []; $currentCanvasDataNode[$note->hcpPro->id] = json_decode($request->get('data'), true); $newCanvasNodeData = json_encode($currentCanvasDataNode); }else{ $newCanvasNodeData = $request->get('data'); } $response = null; $data = [ 'uid' => $client->uid, 'noteUid'=> $note?$note->uid:null, 'key' => $key, 'data' => $newCanvasNodeData ]; $response = $this->calljava($request, '/client/updateCanvasData', $data, $guestAccessCode); //TODO: handle $response->success == false if($note){ $client = Client::where('id', $note->client_id)->first(); }else{ $client = Client::where('id', $section->client_id)->first(); } $patient = $client; if (file_exists(resource_path("views/app/patient/canvas-sections/{$sectionInternalName}/processor.php"))) { include(resource_path("views/app/patient/canvas-sections/{$sectionInternalName}/processor.php")); } else { $newContentData = json_decode($request->get('data'), true); } ob_start(); include(resource_path("views/app/patient/canvas-sections/{$sectionInternalName}/summary.php")); $newSummaryHtml = ob_get_contents(); ob_end_clean(); // TODO call Java to update the canvas } elseif (file_exists(storage_path('sections/' . $sectionTemplate->internal_name . '/form.blade.php'))) { include(storage_path('sections/' . $sectionTemplate->internal_name . '/processor.php')); ob_start(); include(storage_path('sections/' . $sectionTemplate->internal_name . '/summary.php')); $newSummaryHtml = ob_get_contents(); ob_end_clean(); } else { $newContentData = json_decode($request->get('data'), true); if (isset($newContentData['value'])) { $newSummaryHtml = $newContentData['value']; } } $response = null; $data = [ 'uid' => $section->uid, 'contentData' => json_encode($newContentData), 'summaryHtml' => $newSummaryHtml ]; $response = $this->calljava($request, '/section/update', $data, $guestAccessCode); return [ 'success' => $response['success'], 'newSummaryHtml' => $newSummaryHtml ]; } // TODO move to utility private function callJava($request, $endPoint, $data, $guestAccessCode = null) { $url = config('stag.backendUrl') . $endPoint; $response = Http::asForm() ->withHeaders([ 'sessionKey' => $request->cookie('sessionKey'), 'guestAccessCode' => $guestAccessCode ]) ->post($url, $data) ->json(); return $response; } }