Browse Source

cc_hpi => pro-scoped change updates

Vijayakrishnan 4 years ago
parent
commit
aaabd94d1e

+ 27 - 6
app/Http/Controllers/NoteController.php

@@ -77,6 +77,7 @@ class NoteController extends Controller
     }
 
     // JAVA ONLY
+    // ... if hcpProId is passed, get from request
     public function getDefaultValueForSection($patientID, $sectionTemplateID)
     {
         $contentData = [];
@@ -87,10 +88,10 @@ class NoteController extends Controller
         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 sectionProUid
-                $sectionPro = null;
-                if(\request()->input('sectionProUid')) {
-                    $sectionPro = Pro::where('uid', \request()->input('sectionProUid'))->first();
+                // for canvas section where we have pro mapped data, use hcpProId
+                $hcpPro = null;
+                if(\request()->input('hcpProId')) {
+                    $hcpPro = Pro::where('id', \request()->input('hcpProId'))->first();
                 }
 
                 // default should simply assign to $contentData
@@ -115,6 +116,9 @@ class NoteController extends Controller
 
     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){
@@ -148,11 +152,28 @@ class NoteController extends Controller
         $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,
-                'key' => $sectionTemplate->internal_name,
-                'data' => $request->get('data')
+                'key' => $key,
+                'data' => $newCanvasNodeData
             ];
 
             $response = $this->calljava($request, '/client/updateCanvasData', $data, $guestAccessCode);

+ 11 - 12
resources/views/app/patient/canvas-sections/cc_hpi/default.php

@@ -1,15 +1,15 @@
 <?php
 
-/** @var \App\Models\Pro $sectionPro */
+/** @var \App\Models\Pro $hcpPro */
 /** @var \App\Models\Pro $pro */
 /** @var \App\Models\Note $note */
 
-if(!@$sectionPro) {
+if(!@$hcpPro) {
     if(@$note) {
-        $sectionPro = $note->hcpPro;
+        $hcpPro = $note->hcpPro;
     }
     else {
-        $sectionPro = $pro; // should never get here
+        $hcpPro = $pro; // should never get here
     }
 }
 
@@ -19,16 +19,15 @@ if ($patient->canvas_data) {
     $canvasData = json_decode($patient->canvas_data, true);
 
     if(!isset($canvasData["cc_hpi"])) $canvasData["cc_hpi"] = [];
+    if(!isset($canvasData["cc_hpi"][$hcpPro->id])) {
+        $canvasData["cc_hpi"][$hcpPro->id] = [];
+    }
 
     // if next_fu->next_cc available, prefill with that
-    if (isset($canvasData["next_fu"]) && isset($canvasData["next_fu"][$sectionPro->uid])) {
+    if (isset($canvasData["next_fu"]) && isset($canvasData["next_fu"][$hcpPro->id])) {
 
-        $nextFU = $canvasData["next_fu"][$sectionPro->uid];
+        $nextFU = $canvasData["next_fu"][$hcpPro->id];
         if(isset($nextFU['next_cc']) && isset($nextFU['next_cc']['list']) && count($nextFU['next_cc']['list'])) {
-
-            if(!isset($canvasData["cc_hpi"][$sectionPro->uid])) {
-                $canvasData["cc_hpi"][$sectionPro->uid] = [];
-            }
             $prefillData = array_map(function($_x) {
                 if(!isset($_x['icd'])) $_x['icd'] = '';
                 if(!isset($_x['memo'])) $_x['memo'] = '';
@@ -37,12 +36,12 @@ if ($patient->canvas_data) {
                 ];
                 return $_x;
             }, $nextFU['next_cc']['list']);
-            $canvasData["cc_hpi"][$sectionPro->uid]['current_cch'] = [
+            $canvasData["cc_hpi"][$hcpPro->id]['current_cch'] = [
                 'list' => $prefillData
             ];
         }
     }
-    $canvasData = $canvasData['cc_hpi'];
+    $canvasData = $canvasData['cc_hpi'][$hcpPro->id];
 
 }
 $contentData = $canvasData;

+ 12 - 21
resources/views/app/patient/canvas-sections/cc_hpi/form.blade.php

@@ -1,22 +1,13 @@
 <?php
-/** @var \App\Models\Pro $sectionPro */
-/** @var \App\Models\Pro $pro */
-/** @var \App\Models\Note $note */
 
-if(!@$sectionPro) {
-    if(@$note) {
-        $sectionPro = $note->hcpPro;
-    }
-    else {
-        $sectionPro = $pro; // should never get here
-    }
-}
+// $contentData is already pro-scoped by this point!
 
 if(!$contentData) $contentData = [];
-if( !isset($contentData[$sectionPro->uid]) ||
-    !isset($contentData[$sectionPro->uid]['current_cch']) ||
-    !count($contentData[$sectionPro->uid]['current_cch']['list'])) {
-    $contentData[$sectionPro->uid] = [
+if( !isset($contentData) ||
+    !isset($contentData['current_cch']) ||
+    !isset($contentData['current_cch']['list']) ||
+    !count($contentData['current_cch']['list'])) {
+    $contentData = [
         "current_cch" => [
             "list" => [
                 [
@@ -62,11 +53,11 @@ $formID = rand(0, 100000);
             <th class="px-2 text-secondary border-bottom-0">Title</th>
             <th class="px-2 text-secondary border-bottom-0">ICD</th>
             <th class="px-2 text-secondary border-bottom-0 w-35">Memo</th>
-            <th v-if="data['{{$sectionPro->uid}}']['current_cch']['list'].length > 1" class="px-2 text-secondary border-bottom-0"></th>
+            <th v-if="data['current_cch']['list'].length > 1" class="px-2 text-secondary border-bottom-0"></th>
         </tr>
         </thead>
         <tbody>
-        <tr v-for="(item, index) in data['{{$sectionPro->uid}}']['current_cch']['list']">
+        <tr v-for="(item, index) in data['current_cch']['list']">
             <td class="px-2 pt-2 text-center text-sm font-weight-bold">@{{ index + 1 }}</td>
             <td>
                 <select class="form-control form-control-sm" v-model="item.category" required>
@@ -91,7 +82,7 @@ $formID = rand(0, 100000);
                        class="form-control form-control-sm"
                        v-model="item.memo">
             </td>
-            <td v-if="data['{{$sectionPro->uid}}']['current_cch']['list'].length > 1" class="px-2 text-nowrap">
+            <td v-if="data['current_cch']['list'].length > 1" class="px-2 text-nowrap">
                 <a href="#" v-on:click.prevent="removeItem(index)"
                    class="on-hover-opaque text-danger mt-1 d-inline-block">
                     <i class="fa fa-trash-alt"></i>
@@ -111,7 +102,7 @@ $formID = rand(0, 100000);
         </tr>
         </thead>
         <tbody>
-        <tr v-for="(item, index) in data['{{$sectionPro->uid}}']['current_cch']['list']">
+        <tr v-for="(item, index) in data['current_cch']['list']">
             <td class="align-middle px-2">
                 @{{ item.category }}@{{ item.name ? ' / ' + item.name : '' }}@{{ item.icd ? ' / ' + item.icd : '' }}
             </td>
@@ -147,7 +138,7 @@ $formID = rand(0, 100000);
                 },
                 methods: {
                     addItem: function() {
-                        this.data['{{$sectionPro->uid}}']['current_cch']['list'].push({
+                        this.data['current_cch']['list'].push({
                             "category": '',
                             "name": '',
                             "icd": '',
@@ -158,7 +149,7 @@ $formID = rand(0, 100000);
                         });
                     },
                     removeItem: function(_index) {
-                        this.data['{{$sectionPro->uid}}']['current_cch']['list'].splice(_index, 1);
+                        this.data['current_cch']['list'].splice(_index, 1);
                     },
                     cleanArray: function(_source) {
                         let plItems = [], plObject = {};

+ 19 - 16
resources/views/app/patient/canvas-sections/cc_hpi/summary.php

@@ -1,36 +1,39 @@
 <?php
 
-/** @var \App\Models\Pro $sectionPro */
-/** @var \App\Models\Pro $pro */
-/** @var \App\Models\Note $note */
+// HUMONGOUS FIX! This CRITICAL "if" was never there till now!
+if(!@$contentData) {
 
-if(!@$sectionPro) {
-    if(@$note) {
-        $sectionPro = $note->hcpPro;
-    }
-    else {
-        $sectionPro = $pro; // should never get here
+    /** @var \App\Models\Pro $hcpPro */
+    /** @var \App\Models\Pro $pro */
+    /** @var \App\Models\Note $note */
+
+    if(!@$hcpPro) {
+        if(@$note) {
+            $hcpPro = $note->hcpPro;
+        }
+        else {
+            $hcpPro = $pro; // should never get here
+        }
     }
-}
 
-// HUMONGOUS FIX! This CRITICAL "if" was never there till now!
-if(!@$contentData) {
     $contentData = false;
     if ($patient->canvas_data) {
         $canvasData = json_decode($patient->canvas_data, true);
-        if(isset($canvasData["cc_hpi"])) {
-            $contentData = $canvasData["cc_hpi"];
+        if(isset($canvasData["cc_hpi"]) && isset($canvasData["cc_hpi"][$hcpPro->id])) {
+            $contentData = $canvasData["cc_hpi"][$hcpPro->id];
         }
     }
 }
 
-if($contentData === false || !isset($contentData[$sectionPro->uid])) {
+// $contentData (if not null) is already pro-scoped by this point!
+
+if($contentData === false) {
     ?>
     <div class="text-secondary">No data in this section yet</div>
     <?php
 }
 else {
-    $lines = $contentData[$sectionPro->uid]['current_cch']['list'];
+    $lines = $contentData['current_cch']['list'];
     ?>
     <p class="font-weight-bold mb-2">CC</p>
     <table class="table table-sm table-bordered mb-2 table-edit-sheet">