Procházet zdrojové kódy

updated canvas to sections to use pages

= před 3 roky
rodič
revize
483cb4580b
33 změnil soubory, kde provedl 723 přidání a 406 odebrání
  1. 1 0
      app/Http/Controllers/NoteController.php
  2. 14 6
      resources/views/app/patient/canvas-sections/allergies/default.php
  3. 16 6
      resources/views/app/patient/canvas-sections/allergies/summary.php
  4. 3 0
      resources/views/app/patient/canvas-sections/canvas-editor-modal.blade.php
  5. 14 6
      resources/views/app/patient/canvas-sections/care-team/default.php
  6. 14 4
      resources/views/app/patient/canvas-sections/care-team/summary.php
  7. 38 27
      resources/views/app/patient/canvas-sections/cc_hpi/default.php
  8. 12 4
      resources/views/app/patient/canvas-sections/cc_hpi/summary.php
  9. 29 9
      resources/views/app/patient/canvas-sections/cc_may21/default.php
  10. 15 6
      resources/views/app/patient/canvas-sections/cc_may21/summary.php
  11. 20 11
      resources/views/app/patient/canvas-sections/dx/default.php
  12. 17 6
      resources/views/app/patient/canvas-sections/dx/summary.php
  13. 13 6
      resources/views/app/patient/canvas-sections/fhx/default.php
  14. 16 6
      resources/views/app/patient/canvas-sections/fhx/summary.php
  15. 113 104
      resources/views/app/patient/canvas-sections/lifestyle_rx_review/default.php
  16. 107 95
      resources/views/app/patient/canvas-sections/lifestyle_rx_review/summary.php
  17. 19 7
      resources/views/app/patient/canvas-sections/lifestyle_rx_update/default.php
  18. 14 4
      resources/views/app/patient/canvas-sections/lifestyle_rx_update/summary.php
  19. 18 7
      resources/views/app/patient/canvas-sections/next_fu/default.php
  20. 15 4
      resources/views/app/patient/canvas-sections/next_fu/summary.php
  21. 15 6
      resources/views/app/patient/canvas-sections/pmhx/default.php
  22. 18 7
      resources/views/app/patient/canvas-sections/pmhx/summary.php
  23. 14 6
      resources/views/app/patient/canvas-sections/pshx/default.php
  24. 21 9
      resources/views/app/patient/canvas-sections/pshx/summary.php
  25. 17 7
      resources/views/app/patient/canvas-sections/ros/summary.php
  26. 15 6
      resources/views/app/patient/canvas-sections/rx/default.php
  27. 13 9
      resources/views/app/patient/canvas-sections/rx/summary.php
  28. 15 6
      resources/views/app/patient/canvas-sections/sochx/default.php
  29. 17 7
      resources/views/app/patient/canvas-sections/sochx/summary.php
  30. 16 6
      resources/views/app/patient/canvas-sections/vitals/default.php
  31. 23 13
      resources/views/app/patient/canvas-sections/vitals/summary.php
  32. 14 6
      resources/views/app/patient/canvas-sections/vitals_may21/default.php
  33. 17 0
      resources/views/app/patient/canvas-sections/vitals_may21/summary.php

+ 1 - 0
app/Http/Controllers/NoteController.php

@@ -183,6 +183,7 @@ class NoteController extends Controller
             $response = null;
             $data = [
                 'uid' => $client->uid,
+                'noteUid'=> $note?$note->uid:null,
                 'key' => $key,
                 'data' => $newCanvasNodeData
             ];

+ 14 - 6
resources/views/app/patient/canvas-sections/allergies/default.php

@@ -1,10 +1,18 @@
 <?php
 
-$canvasData = [];
-if ($patient->canvas_data) {
-    $canvasData = json_decode($patient->canvas_data, true);
-    if (isset($canvasData["allergies"])) {
-        $canvasData = $canvasData["allergies"];
+use App\Models\Page;
+
+$page = Page::where('client_id', $patient->id)->where('category', 'CANVAS')->where('key', 'allergies')->first();
+
+$contentData = [];
+
+if($page){
+    $contentData = json_decode($page->data, true);
+}else{
+    if ($patient->canvas_data) {
+        $canvasData = json_decode($patient->canvas_data, true);
+        if (isset($canvasData["allergies"])) {
+            $contentData = $canvasData["allergies"];
+        }
     }
 }
-$contentData = $canvasData;

+ 16 - 6
resources/views/app/patient/canvas-sections/allergies/summary.php

@@ -1,18 +1,28 @@
 <?php
 
+use App\Models\Page;
+
+$page = Page::where('client_id', $patient->id)->where('category', 'CANVAS')->where('key', 'allergies')->first();
+
 $contentData = [
     "items" => []
 ];
-if($patient->canvas_data) {
-    $canvasData = json_decode($patient->canvas_data, true);
-    if(isset($canvasData["allergies"])) {
-        $contentData = $canvasData["allergies"];
-        if(!isset($contentData['items'])){
-            $contentData['items'] = [];
+
+if($page){
+    $contentData = json_decode($page->data, true);
+}else{
+    if($patient->canvas_data) {
+        $canvasData = json_decode($patient->canvas_data, true);
+        if(isset($canvasData["allergies"])) {
+            $contentData = $canvasData["allergies"];
+            if(!isset($contentData['items'])){
+                $contentData['items'] = [];
+            }
         }
     }
 }
 
+
 if(count($contentData['items'])) {
     for ($i = 0; $i < count($contentData['items']); $i++) {
         $item = $contentData['items'][$i];

+ 3 - 0
resources/views/app/patient/canvas-sections/canvas-editor-modal.blade.php

@@ -14,6 +14,9 @@
     <form method="POST" action="/api/client/updateCanvasData">
         <input type="hidden" name="uid" value="{{$patient->uid}}">
         <input type="hidden" name="key" value="{{$key}}">
+        @if(isset($note))
+        <input type="hidden" name="noteUid" value="{{$note->uid}}">
+        @endif
 
         @include("app.patient.canvas-sections.{$key}.form")
 

+ 14 - 6
resources/views/app/patient/canvas-sections/care-team/default.php

@@ -1,10 +1,18 @@
 <?php
 
-$canvasData = [];
-if ($patient->canvas_data) {
-    $canvasData = json_decode($patient->canvas_data, true);
-    if (isset($canvasData["care-team"])) {
-        $canvasData = $canvasData["care-team"];
+use App\Models\Page;
+
+$page = Page::where('client_id', $patient->id)->where('category', 'CANVAS')->where('key', 'care-team')->first();
+
+$contentData = [];
+
+if($page){
+    $contentData = json_decode($page->data, true);
+}else{
+    if ($patient->canvas_data) {
+        $canvasData = json_decode($patient->canvas_data, true);
+        if (isset($canvasData["care-team"])) {
+            $contentData = $canvasData["care-team"];
+        }
     }
 }
-$contentData = $canvasData;

+ 14 - 4
resources/views/app/patient/canvas-sections/care-team/summary.php

@@ -1,15 +1,25 @@
 <?php
 
+use App\Models\Page;
+
+$page = Page::where('client_id', $patient->id)->where('category', 'CANVAS')->where('key', 'care-team')->first();
+
 $contentData = [
     "items" => []
 ];
-if($patient->canvas_data) {
-    $canvasData = json_decode($patient->canvas_data, true);
-    if(isset($canvasData["care-team"])) {
-        $contentData = $canvasData["care-team"];
+
+if($page){
+    $contentData = json_decode($page->data, true);
+}else{
+    if($patient->canvas_data) {
+        $canvasData = json_decode($patient->canvas_data, true);
+        if(isset($canvasData["care-team"])) {
+            $contentData = $canvasData["care-team"];
+        }
     }
 }
 
+
 if(count($contentData['items'])) {
     for ($i = 0; $i < count($contentData['items']); $i++) {
         $item = $contentData['items'][$i];

+ 38 - 27
resources/views/app/patient/canvas-sections/cc_hpi/default.php

@@ -1,4 +1,9 @@
-<?php
+<?php 
+
+use App\Models\Page;
+
+$page = Page::where('client_id', $patient->id)->where('category', 'CANVAS')->where('key', 'cc_hpi')->first();
+
 
 /** @var \App\Models\Pro $hcpPro */
 /** @var \App\Models\Pro $pro */
@@ -14,34 +19,40 @@ if(!@$hcpPro) {
 }
 
 
-$canvasData = [];
-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] = [];
-    }
+$contentData = [];
 
-    // if next_fu->next_cc available, prefill with that
-    if (isset($canvasData["next_fu"]) && isset($canvasData["next_fu"][$hcpPro->id])) {
-
-        $nextFU = $canvasData["next_fu"][$hcpPro->id];
-        if(isset($nextFU['next_cc']) && isset($nextFU['next_cc']['list']) && count($nextFU['next_cc']['list'])) {
-            $prefillData = array_map(function($_x) {
-                if(!isset($_x['icd'])) $_x['icd'] = '';
-                if(!isset($_x['memo'])) $_x['memo'] = '';
-                $_x['hpi'] = [
-                    'free_text' => ''
+if($page){
+    $contentData = json_decode($page->data, true);
+}else{
+    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"][$hcpPro->id])) {
+    
+            $nextFU = $canvasData["next_fu"][$hcpPro->id];
+            if(isset($nextFU['next_cc']) && isset($nextFU['next_cc']['list']) && count($nextFU['next_cc']['list'])) {
+                $prefillData = array_map(function($_x) {
+                    if(!isset($_x['icd'])) $_x['icd'] = '';
+                    if(!isset($_x['memo'])) $_x['memo'] = '';
+                    $_x['hpi'] = [
+                        'free_text' => ''
+                    ];
+                    return $_x;
+                }, $nextFU['next_cc']['list']);
+                $canvasData["cc_hpi"][$hcpPro->id]['current_cch'] = [
+                    'list' => $prefillData
                 ];
-                return $_x;
-            }, $nextFU['next_cc']['list']);
-            $canvasData["cc_hpi"][$hcpPro->id]['current_cch'] = [
-                'list' => $prefillData
-            ];
+            }
         }
+        $canvasData = $canvasData['cc_hpi'][$hcpPro->id];
+    
     }
-    $canvasData = $canvasData['cc_hpi'][$hcpPro->id];
-
+    $contentData = $canvasData;
 }
-$contentData = $canvasData;
+

+ 12 - 4
resources/views/app/patient/canvas-sections/cc_hpi/summary.php

@@ -1,5 +1,9 @@
 <?php
 
+use App\Models\Page;
+
+$page = Page::where('client_id', $patient->id)->where('category', 'CANVAS')->where('key', 'cc_hpi')->first();
+
 // HUMONGOUS FIX! This CRITICAL "if" was never there till now!
 if(!@$contentData) {
 
@@ -17,10 +21,14 @@ if(!@$contentData) {
     }
 
     $contentData = false;
-    if ($patient->canvas_data) {
-        $canvasData = json_decode($patient->canvas_data, true);
-        if(isset($canvasData["cc_hpi"]) && isset($canvasData["cc_hpi"][$hcpPro->id])) {
-            $contentData = $canvasData["cc_hpi"][$hcpPro->id];
+    if($page){
+        $contentData = json_decode($page->data, true);
+    }else{
+        if ($patient->canvas_data) {
+            $canvasData = json_decode($patient->canvas_data, true);
+            if(isset($canvasData["cc_hpi"]) && isset($canvasData["cc_hpi"][$hcpPro->id])) {
+                $contentData = $canvasData["cc_hpi"][$hcpPro->id];
+            }
         }
     }
 }

+ 29 - 9
resources/views/app/patient/canvas-sections/cc_may21/default.php

@@ -1,30 +1,50 @@
 <?php
 
+
 use App\Models\Client;
 use App\Models\Note;
 
 /** @var Client $patient */
 /** @var Note $note */
 
-$canvasData = [
+
+use App\Models\Page;
+
+$page = Page::where('client_id', $patient->id)->where('category', 'CANVAS')->where('key', 'cc_may21')->first();
+
+$dxPage = Page::where('client_id', $patient->id)->where('category', 'CANVAS')->where('key', 'dx')->first();
+
+$contentData =[
     "text" => '',
     "was_confirmed" => false,
     "note_uid" => '',
 ];
 
+
 $patientDx = null;
 
-if ($patient->canvas_data) {
-    $canvasData = json_decode($patient->canvas_data, true);
-    if (isset($canvasData["dx"])) {
-        $patientDx = $canvasData["dx"];
-    }
-    if (isset($canvasData["cc_may21"])) {
-        $canvasData = $canvasData["cc_may21"];
+if($page){
+    $contentData = json_decode($page->data, true);
+}else{
+    if ($patient->canvas_data) {
+        $canvasData = json_decode($patient->canvas_data, true);
+        if (isset($canvasData["cc_may21"])) {
+            $contentData = $canvasData["cc_may21"];
+        }
     }
 }
-$contentData = $canvasData;
 
+if($dxPage){
+    $patientDx = json_decode($dxPage->data, true);
+}else{
+    if ($patient->canvas_data) {
+        $canvasData = json_decode($patient->canvas_data, true);
+        if (isset($canvasData["dx"])) {
+            $patientDx = $canvasData["dx"];
+        }
+    }
+}
+ 
 if (!isset($contentData['note_uid']) || $contentData['note_uid'] !== @$note->uid) {
     $prefix = $patient->name_prefix ?: '';
     if (!$prefix) {

+ 15 - 6
resources/views/app/patient/canvas-sections/cc_may21/summary.php

@@ -3,6 +3,10 @@
 use App\Models\Client;
 use App\Models\Note;
 
+use App\Models\Page;
+
+$page = Page::where('client_id', $patient->id)->where('category', 'CANVAS')->where('key', 'cc_may21')->first();
+
 /** @var Client $patient */
 /** @var Note $note */
 
@@ -12,12 +16,17 @@ if(!@$contentData) {
         "was_confirmed" => false,
         "note_uid" => (@$note ? $note->uid : '')
     ];
-    if ($patient->canvas_data) {
-        $canvasData = json_decode($patient->canvas_data, true);
-        if (isset($canvasData["cc_may21"])) {
-            $contentData = $canvasData["cc_may21"];
-            if (!isset($contentData['text'])) $contentData['text'] = '';
-            if (!isset($contentData['was_confirmed'])) $contentData['was_confirmed'] = false;
+
+    if($page){
+        $contentData = json_decode($page->data, true);
+    }else{
+        if ($patient->canvas_data) {
+            $canvasData = json_decode($patient->canvas_data, true);
+            if (isset($canvasData["cc_may21"])) {
+                $contentData = $canvasData["cc_may21"];
+                if (!isset($contentData['text'])) $contentData['text'] = '';
+                if (!isset($contentData['was_confirmed'])) $contentData['was_confirmed'] = false;
+            }
         }
     }
 }

+ 20 - 11
resources/views/app/patient/canvas-sections/dx/default.php

@@ -1,17 +1,26 @@
 <?php
-$canvasData = [
+use App\Models\Page;
+
+$page = Page::where('client_id', $patient->id)->where('category', 'CANVAS')->where('key', 'dx')->first();
+
+$contentData = [
     "items" => []
 ];
-if ($patient->canvas_data) {
-    $canvasData = json_decode($patient->canvas_data, true);
-    if (isset($canvasData["dx"])) {
-        $canvasData = $canvasData["dx"];
-        if(!isset($canvasData["items"])) {
-            $canvasData["items"] = [];
-        }
-        for ($i = 0; $i < count($canvasData["items"]); $i++) {
-            $canvasData["items"][$i]["included"] = 1;
+
+if($page){
+    $contentData = json_decode($page->data, true);
+}else {
+    if ($patient->canvas_data) {
+        $canvasData = json_decode($patient->canvas_data, true);
+        if (isset($canvasData["dx"])) {
+            $contentData = $canvasData["dx"];
+            if(!isset($contentData["items"])) {
+                $contentData["items"] = [];
+            }
+            for ($i = 0; $i < count($contentData["items"]); $i++) {
+                $contentData["items"][$i]["included"] = 1;
+            }
         }
     }
 }
-$contentData = $canvasData;
+

+ 17 - 6
resources/views/app/patient/canvas-sections/dx/summary.php

@@ -1,17 +1,28 @@
 <?php
 
+use App\Models\Page;
+
+$page = Page::where('client_id', $patient->id)->where('category', 'CANVAS')->where('key', 'dx')->first();
+
+
 $contentData = [
     "items" => []
 ];
-if($patient->canvas_data) {
-    $canvasData = json_decode($patient->canvas_data, true);
-    if(isset($canvasData["dx"])) {
-        $contentData = $canvasData["dx"];
 
-        if(!isset($contentData['items'])){
-            $contentData['items'] = [];
+if($page){
+    $contentData = json_decode($page->data, true);
+}else{
+    if($patient->canvas_data) {
+        $canvasData = json_decode($patient->canvas_data, true);
+        if(isset($canvasData["dx"])) {
+            $contentData = $canvasData["dx"];
+    
+            if(!isset($contentData['items'])){
+                $contentData['items'] = [];
+            }
         }
     }
+    
 }
 
 if(count($contentData['items'])) {

+ 13 - 6
resources/views/app/patient/canvas-sections/fhx/default.php

@@ -1,10 +1,17 @@
 <?php
 
+use App\Models\Page;
+
+$page = Page::where('client_id', $patient->id)->where('category', 'CANVAS')->where('key', 'fhx')->first();
+
 $canvasData = [];
-if ($patient->canvas_data) {
-    $canvasData = json_decode($patient->canvas_data, true);
-    if (isset($canvasData["fhx"])) {
-        $canvasData = $canvasData["fhx"];
-    }
+if($page){
+    $contentData = json_decode($page->data, true);
+}else{
+    if ($patient->canvas_data) {
+        $canvasData = json_decode($patient->canvas_data, true);
+        if (isset($canvasData["fhx"])) {
+            $contentData = $canvasData["fhx"];
+        }
+    }    
 }
-$contentData = $canvasData;

+ 16 - 6
resources/views/app/patient/canvas-sections/fhx/summary.php

@@ -1,20 +1,30 @@
 <?php
 
+use App\Models\Page;
+
+$page = Page::where('client_id', $patient->id)->where('category', 'CANVAS')->where('key', 'fhx')->first();
+
 $contentData = [
     "count" => 0,
     "unknown" => false,
     "items" => []
 ];
-if($patient->canvas_data) {
-    $canvasData = json_decode($patient->canvas_data, true);
-    if(isset($canvasData["fhx"])) {
-        $contentData = $canvasData["fhx"];
-        if(!isset($contentData['items'])){
-            $contentData['items'] = [];
+
+if($page) {
+    $contentData = json_decode($page->data, true);
+}else{
+    if($patient->canvas_data) {
+        $canvasData = json_decode($patient->canvas_data, true);
+        if(isset($canvasData["fhx"])) {
+            $contentData = $canvasData["fhx"];
+            if(!isset($contentData['items'])){
+                $contentData['items'] = [];
+            }
         }
     }
 }
 
+
 $labels = [
     'general_no_health_concern' => 'No health concern',
     'general_arthritis' => 'Arthritis',

+ 113 - 104
resources/views/app/patient/canvas-sections/lifestyle_rx_review/default.php

@@ -4,6 +4,10 @@
 /** @var \App\Models\Pro $pro */
 /** @var \App\Models\Note $note */
 
+use App\Models\Page;
+
+$page = Page::where('client_id', $patient->id)->where('category', 'CANVAS')->where('key', 'lifestyle_rx_review')->first();
+
 if(!@$hcpPro) {
     if(@$note) {
         $hcpPro = $note->hcpPro;
@@ -13,134 +17,139 @@ if(!@$hcpPro) {
     }
 }
 
-$canvasData = [];
-if ($patient->canvas_data) {
-    $canvasData = json_decode($patient->canvas_data, true);
-    if(!isset($canvasData["lifestyle_rx_review"])) $canvasData["lifestyle_rx_review"] = [];
-    if(!isset($canvasData["lifestyle_rx_review"][$hcpPro->id])) {
-        $canvasData["lifestyle_rx_review"][$hcpPro->id] = [
-            'physical_activity' => [
-                'type' => '',
-                'frequency' => '',
-                'time' => '',
-                'intensity' => '',
-                'enjoyment' => '',
+$contentData = [];
+if($Page){
+    $contentData = json_decode($page->data, true);
+}else{
+    if ($patient->canvas_data) {
+        $canvasData = json_decode($patient->canvas_data, true);
+        if(!isset($canvasData["lifestyle_rx_review"])) $canvasData["lifestyle_rx_review"] = [];    
+        $contentData = $canvasData["lifestyle_rx_review"];
+    }
+}
+
+
+if(!isset($contentData[$hcpPro->id])) {
+    $canvasData["lifestyle_rx_review"][$hcpPro->id] = [
+        'physical_activity' => [
+            'type' => '',
+            'frequency' => '',
+            'time' => '',
+            'intensity' => '',
+            'enjoyment' => '',
+        ],
+        'barriers' => '',   // free text
+        'assessment' => '', // Inactive, Insufficiently Active, Active, Highly Active
+        'adherence' => [
+            'seated' => [
+                'active' => false,
+                'memo' => '',
+                'adherence' => '',
+                'adherence_memo' => '',
+            ],
+            'arm' => [
+                'active' => false,
+                'memo' => '',
+                'adherence' => '',
+                'adherence_memo' => '',
             ],
-            'barriers' => '',   // free text
-            'assessment' => '', // Inactive, Insufficiently Active, Active, Highly Active
-            'adherence' => [
-                'seated' => [
+            'aquatic' => [
+                'active' => false,
+                'memo' => '',
+                'adherence' => '',
+                'adherence_memo' => '',
+            ],
+            'aerobic' => [
+                'active' => false,
+                'walk' => [
                     'active' => false,
+                    'days_per_week' => '',
+                    'minutes_per_day' => '',
+                    'intensity' => '', // Light, Moderate, Vigorous
                     'memo' => '',
                     'adherence' => '',
                     'adherence_memo' => '',
                 ],
-                'arm' => [
+                'jog' => [
                     'active' => false,
+                    'days_per_week' => '',
+                    'minutes_per_day' => '',
+                    'intensity' => '', // Light, Moderate, Vigorous
                     'memo' => '',
                     'adherence' => '',
                     'adherence_memo' => '',
                 ],
-                'aquatic' => [
+                'elliptical' => [
                     'active' => false,
+                    'days_per_week' => '',
+                    'minutes_per_day' => '',
+                    'intensity' => '', // Light, Moderate, Vigorous
                     'memo' => '',
                     'adherence' => '',
                     'adherence_memo' => '',
                 ],
-                'aerobic' => [
+                'swim' => [
                     'active' => false,
-                    'walk' => [
-                        'active' => false,
-                        'days_per_week' => '',
-                        'minutes_per_day' => '',
-                        'intensity' => '', // Light, Moderate, Vigorous
-                        'memo' => '',
-                        'adherence' => '',
-                        'adherence_memo' => '',
-                    ],
-                    'jog' => [
-                        'active' => false,
-                        'days_per_week' => '',
-                        'minutes_per_day' => '',
-                        'intensity' => '', // Light, Moderate, Vigorous
-                        'memo' => '',
-                        'adherence' => '',
-                        'adherence_memo' => '',
-                    ],
-                    'elliptical' => [
-                        'active' => false,
-                        'days_per_week' => '',
-                        'minutes_per_day' => '',
-                        'intensity' => '', // Light, Moderate, Vigorous
-                        'memo' => '',
-                        'adherence' => '',
-                        'adherence_memo' => '',
-                    ],
-                    'swim' => [
-                        'active' => false,
-                        'days_per_week' => '',
-                        'minutes_per_day' => '',
-                        'intensity' => '', // Light, Moderate, Vigorous
-                        'memo' => '',
-                        'adherence' => '',
-                        'adherence_memo' => '',
-                    ],
-                    'bike' => [
-                        'active' => false,
+                    'days_per_week' => '',
+                    'minutes_per_day' => '',
+                    'intensity' => '', // Light, Moderate, Vigorous
+                    'memo' => '',
+                    'adherence' => '',
+                    'adherence_memo' => '',
+                ],
+                'bike' => [
+                    'active' => false,
+                    'days_per_week' => '',
+                    'minutes_per_day' => '',
+                    'intensity' => '', // Light, Moderate, Vigorous
+                    'memo' => '',
+                    'adherence' => '',
+                    'adherence_memo' => '',
+                ],
+            ],
+            'strength' => [
+                'active' => false,
+                'exercises' => [
+                    [
+                        'name' => '',
                         'days_per_week' => '',
-                        'minutes_per_day' => '',
+                        'reps' => '',
                         'intensity' => '', // Light, Moderate, Vigorous
                         'memo' => '',
                         'adherence' => '',
                         'adherence_memo' => '',
-                    ],
-                ],
-                'strength' => [
-                    'active' => false,
-                    'exercises' => [
-                        [
-                            'name' => '',
-                            'days_per_week' => '',
-                            'reps' => '',
-                            'intensity' => '', // Light, Moderate, Vigorous
-                            'memo' => '',
-                            'adherence' => '',
-                            'adherence_memo' => '',
-                        ]
-                    ]
-                ],
-                'neat' => [
-                    'active' => false,
-                    'recommendations' => [
-                        'park_farther' => false,
-                        'park_farther_adherence' => '',
-                        'park_farther_adherence_memo' => '',
-                        'steps_instead_of_elevator' => false,
-                        'steps_instead_of_elevator_adherence' => '',
-                        'steps_instead_of_elevator_adherence_memo' => '',
-                        'stand_instead_of_sit' => false,
-                        'stand_instead_of_sit_adherence' => '',
-                        'stand_instead_of_sit_adherence_memo' => '',
-                        'steps_goal_per_day' => '',
-                        'steps_goal_per_day_adherence' => '',
-                        'steps_goal_per_day_adherence_memo' => '',
-                        'other' => '',
-                        'other_adherence' => '',
-                        'other_adherence_memo' => '',
                     ]
                 ]
+            ],
+            'neat' => [
+                'active' => false,
+                'recommendations' => [
+                    'park_farther' => false,
+                    'park_farther_adherence' => '',
+                    'park_farther_adherence_memo' => '',
+                    'steps_instead_of_elevator' => false,
+                    'steps_instead_of_elevator_adherence' => '',
+                    'steps_instead_of_elevator_adherence_memo' => '',
+                    'stand_instead_of_sit' => false,
+                    'stand_instead_of_sit_adherence' => '',
+                    'stand_instead_of_sit_adherence_memo' => '',
+                    'steps_goal_per_day' => '',
+                    'steps_goal_per_day_adherence' => '',
+                    'steps_goal_per_day_adherence_memo' => '',
+                    'other' => '',
+                    'other_adherence' => '',
+                    'other_adherence_memo' => '',
+                ]
             ]
-        ];
-    }
-
-    // if lifestyle_rx_update available, prefill with that
-    if (isset($canvasData["lifestyle_rx_update"]) &&
-        isset($canvasData["lifestyle_rx_update"][$hcpPro->id]) &&
-        isset($canvasData["lifestyle_rx_update"][$hcpPro->id]['prescription'])) {
-        $canvasData["lifestyle_rx_review"][$hcpPro->id]['adherence'] = $canvasData["lifestyle_rx_update"][$hcpPro->id]['prescription'];
-    }
-
-    $canvasData = $canvasData['lifestyle_rx_review'][$hcpPro->id];
+        ]
+    ];
+}
 
+// if lifestyle_rx_update available, prefill with that
+if (isset($contentData) &&
+    isset($$contentData[$hcpPro->id]) &&
+    isset($$contentData[$hcpPro->id]['prescription'])) {
+    $contentData[$hcpPro->id]['adherence'] =$contentData[$hcpPro->id]['prescription'];
 }
-$contentData = $canvasData;
+
+$contentData = $contentData[$hcpPro->id];

+ 107 - 95
resources/views/app/patient/canvas-sections/lifestyle_rx_review/summary.php

@@ -1,5 +1,10 @@
 <?php
 
+use App\Models\Page;
+
+$page = Page::where('client_id', $patient->id)->where('category', 'CANVAS')->where('key', 'lifestyle_rx_review')->first();
+
+
 // HUMONGOUS FIX! This CRITICAL "if" was never there till now!
 if(!@$contentData) {
     /** @var \App\Models\Pro $hcpPro */
@@ -16,126 +21,133 @@ if(!@$contentData) {
     }
 
     $contentData = false;
-    if ($patient->canvas_data) {
-        $canvasData = json_decode($patient->canvas_data, true);
-        if(isset($canvasData["lifestyle_rx_review"]) && isset($canvasData["lifestyle_rx_review"][$hcpPro->id])) {
-            $contentData = $canvasData["lifestyle_rx_review"][$hcpPro->id];
-        }
-        else { // default data structure
-            $contentData = [
-                'physical_activity' => [
-                    'type' => '',
-                    'frequency' => '',
-                    'time' => '',
-                    'intensity' => '',
-                    'enjoyment' => '',
+
+    if($page){
+        $contentData = json_decode($page->data, true);
+    }else{
+        if ($patient->canvas_data) {
+            $canvasData = json_decode($patient->canvas_data, true);
+            $contentData = $canvasData["lifestyle_rx_review"];
+        }    
+    }
+
+    
+    if(isset($contentData) && isset($contentData[$hcpPro->id])) {
+        $contentData = $canvasData["lifestyle_rx_review"][$hcpPro->id];
+    }else { // default data structure
+        $contentData = [
+            'physical_activity' => [
+                'type' => '',
+                'frequency' => '',
+                'time' => '',
+                'intensity' => '',
+                'enjoyment' => '',
+            ],
+            'barriers' => '',   // free text
+            'assessment' => '', // Inactive, Insufficiently Active, Active, Highly Active
+            'adherence' => [
+                'seated' => [
+                    'active' => false,
+                    'memo' => '',
+                    'adherence' => '',
+                    'adherence_memo' => '',
+                ],
+                'arm' => [
+                    'active' => false,
+                    'memo' => '',
+                    'adherence' => '',
+                    'adherence_memo' => '',
+                ],
+                'aquatic' => [
+                    'active' => false,
+                    'memo' => '',
+                    'adherence' => '',
+                    'adherence_memo' => '',
                 ],
-                'barriers' => '',   // free text
-                'assessment' => '', // Inactive, Insufficiently Active, Active, Highly Active
-                'adherence' => [
-                    'seated' => [
+                'aerobic' => [
+                    'active' => false,
+                    'walk' => [
                         'active' => false,
+                        'days_per_week' => '',
+                        'minutes_per_day' => '',
+                        'intensity' => '', // Light, Moderate, Vigorous
                         'memo' => '',
                         'adherence' => '',
                         'adherence_memo' => '',
                     ],
-                    'arm' => [
+                    'jog' => [
                         'active' => false,
+                        'days_per_week' => '',
+                        'minutes_per_day' => '',
+                        'intensity' => '', // Light, Moderate, Vigorous
                         'memo' => '',
                         'adherence' => '',
                         'adherence_memo' => '',
                     ],
-                    'aquatic' => [
+                    'elliptical' => [
                         'active' => false,
+                        'days_per_week' => '',
+                        'minutes_per_day' => '',
+                        'intensity' => '', // Light, Moderate, Vigorous
                         'memo' => '',
                         'adherence' => '',
                         'adherence_memo' => '',
                     ],
-                    'aerobic' => [
+                    'swim' => [
                         'active' => false,
-                        'walk' => [
-                            'active' => false,
-                            'days_per_week' => '',
-                            'minutes_per_day' => '',
-                            'intensity' => '', // Light, Moderate, Vigorous
-                            'memo' => '',
-                            'adherence' => '',
-                            'adherence_memo' => '',
-                        ],
-                        'jog' => [
-                            'active' => false,
-                            'days_per_week' => '',
-                            'minutes_per_day' => '',
-                            'intensity' => '', // Light, Moderate, Vigorous
-                            'memo' => '',
-                            'adherence' => '',
-                            'adherence_memo' => '',
-                        ],
-                        'elliptical' => [
-                            'active' => false,
-                            'days_per_week' => '',
-                            'minutes_per_day' => '',
-                            'intensity' => '', // Light, Moderate, Vigorous
-                            'memo' => '',
-                            'adherence' => '',
-                            'adherence_memo' => '',
-                        ],
-                        'swim' => [
-                            'active' => false,
-                            'days_per_week' => '',
-                            'minutes_per_day' => '',
-                            'intensity' => '', // Light, Moderate, Vigorous
-                            'memo' => '',
-                            'adherence' => '',
-                            'adherence_memo' => '',
-                        ],
-                        'bike' => [
-                            'active' => false,
+                        'days_per_week' => '',
+                        'minutes_per_day' => '',
+                        'intensity' => '', // Light, Moderate, Vigorous
+                        'memo' => '',
+                        'adherence' => '',
+                        'adherence_memo' => '',
+                    ],
+                    'bike' => [
+                        'active' => false,
+                        'days_per_week' => '',
+                        'minutes_per_day' => '',
+                        'intensity' => '', // Light, Moderate, Vigorous
+                        'memo' => '',
+                        'adherence' => '',
+                        'adherence_memo' => '',
+                    ],
+                ],
+                'strength' => [
+                    'active' => false,
+                    'exercises' => [
+                        [
+                            'name' => '',
                             'days_per_week' => '',
-                            'minutes_per_day' => '',
+                            'reps' => '',
                             'intensity' => '', // Light, Moderate, Vigorous
                             'memo' => '',
                             'adherence' => '',
                             'adherence_memo' => '',
-                        ],
-                    ],
-                    'strength' => [
-                        'active' => false,
-                        'exercises' => [
-                            [
-                                'name' => '',
-                                'days_per_week' => '',
-                                'reps' => '',
-                                'intensity' => '', // Light, Moderate, Vigorous
-                                'memo' => '',
-                                'adherence' => '',
-                                'adherence_memo' => '',
-                            ]
-                        ]
-                    ],
-                    'neat' => [
-                        'active' => false,
-                        'recommendations' => [
-                            'park_farther' => false,
-                            'park_farther_adherence' => '',
-                            'park_farther_adherence_memo' => '',
-                            'steps_instead_of_elevator' => false,
-                            'steps_instead_of_elevator_adherence' => '',
-                            'steps_instead_of_elevator_adherence_memo' => '',
-                            'stand_instead_of_sit' => false,
-                            'stand_instead_of_sit_adherence' => '',
-                            'stand_instead_of_sit_adherence_memo' => '',
-                            'steps_goal_per_day' => '',
-                            'steps_goal_per_day_adherence' => '',
-                            'steps_goal_per_day_adherence_memo' => '',
-                            'other' => '',
-                            'other_adherence' => '',
-                            'other_adherence_memo' => '',
                         ]
                     ]
+                ],
+                'neat' => [
+                    'active' => false,
+                    'recommendations' => [
+                        'park_farther' => false,
+                        'park_farther_adherence' => '',
+                        'park_farther_adherence_memo' => '',
+                        'steps_instead_of_elevator' => false,
+                        'steps_instead_of_elevator_adherence' => '',
+                        'steps_instead_of_elevator_adherence_memo' => '',
+                        'stand_instead_of_sit' => false,
+                        'stand_instead_of_sit_adherence' => '',
+                        'stand_instead_of_sit_adherence_memo' => '',
+                        'steps_goal_per_day' => '',
+                        'steps_goal_per_day_adherence' => '',
+                        'steps_goal_per_day_adherence_memo' => '',
+                        'other' => '',
+                        'other_adherence' => '',
+                        'other_adherence_memo' => '',
+                    ]
                 ]
-            ];
-        }
+            ]
+        ];
     }
 }
 

+ 19 - 7
resources/views/app/patient/canvas-sections/lifestyle_rx_update/default.php

@@ -1,5 +1,9 @@
 <?php
 
+use App\Models\Page;
+
+$page = Page::where('client_id', $patient->id)->where('category', 'CANVAS')->where('key', 'lifestyle_rx_update')->first();
+
 /** @var \App\Models\Pro $hcpPro */
 /** @var \App\Models\Pro $pro */
 /** @var \App\Models\Note $note */
@@ -13,11 +17,19 @@ if(!@$hcpPro) {
     }
 }
 
-$canvasData = [];
-if ($patient->canvas_data) {
-    $canvasData = json_decode($patient->canvas_data, true);
-    if(!isset($canvasData["lifestyle_rx_update"])) $canvasData["lifestyle_rx_update"] = [];
-    if(!isset($canvasData["lifestyle_rx_update"][$hcpPro->id])) $canvasData["lifestyle_rx_update"][$hcpPro->id] = [];
-    $canvasData = $canvasData['lifestyle_rx_update'][$hcpPro->id];
+$contentData = [];
+
+if($page) {
+    $contentData = json_decode($page->data, true);
+}else{
+    if ($patient->canvas_data) {
+        $canvasData = json_decode($patient->canvas_data, true);
+        $contentData = $canvasData["lifestyle_rx_update"];
+        if(!isset($canvasData["lifestyle_rx_update"])) $contentData = [];
+    }
+    
+    if(!isset($contentData[$hcpPro->id])) $contentData[$hcpPro->id] = [];
+    $contentData = $contentData[$hcpPro->id];
 }
-$contentData = $canvasData;
+
+

+ 14 - 4
resources/views/app/patient/canvas-sections/lifestyle_rx_update/summary.php

@@ -1,5 +1,10 @@
 <?php
 
+
+use App\Models\Page;
+
+$page = Page::where('client_id', $patient->id)->where('category', 'CANVAS')->where('key', 'lifestyle_rx_update')->first();
+
 // HUMONGOUS FIX! This CRITICAL "if" was never there till now!
 if(!@$contentData) {
     /** @var \App\Models\Pro $hcpPro */
@@ -16,12 +21,17 @@ if(!@$contentData) {
     }
 
     $contentData = false;
-    if ($patient->canvas_data) {
-        $canvasData = json_decode($patient->canvas_data, true);
-        if(isset($canvasData["lifestyle_rx_update"]) && isset($canvasData["lifestyle_rx_update"][$hcpPro->id])) {
-            $contentData = $canvasData["lifestyle_rx_update"][$hcpPro->id];
+    if($page) {
+        $contentData = json_decode($page->data, true);
+    }else{
+        if ($patient->canvas_data) {
+            $canvasData = json_decode($patient->canvas_data, true);
+            $contentData = $canvasData["lifestyle_rx_update"];
+            if(!isset($canvasData["lifestyle_rx_update"])) $contentData = [];
         }
     }
+    if(!isset($contentData[$hcpPro->id])) $contentData[$hcpPro->id] = [];
+    $contentData = $contentData[$hcpPro->id];    
 }
 
 if($contentData === false) {

+ 18 - 7
resources/views/app/patient/canvas-sections/next_fu/default.php

@@ -1,5 +1,10 @@
 <?php
 
+
+use App\Models\Page;
+
+$page = Page::where('client_id', $patient->id)->where('category', 'CANVAS')->where('key', 'next_fu')->first();
+
 /** @var \App\Models\Pro $hcpPro */
 /** @var \App\Models\Pro $pro */
 /** @var \App\Models\Note $note */
@@ -13,11 +18,17 @@ if(!@$hcpPro) {
     }
 }
 
-$canvasData = [];
-if ($patient->canvas_data) {
-    $canvasData = json_decode($patient->canvas_data, true);
-    if(!isset($canvasData["next_fu"])) $canvasData["next_fu"] = [];
-    if(!isset($canvasData["next_fu"][$hcpPro->id])) $canvasData["next_fu"][$hcpPro->id] = [];
-    $canvasData = $canvasData['next_fu'][$hcpPro->id];
+$contentData = [];
+
+if($page){
+    $contentData = json_decode($page->data, true);
+}else{
+    if ($patient->canvas_data) {
+        $canvasData = json_decode($patient->canvas_data, true);
+        if(!isset($canvasData["next_fu"])) $canvasData["next_fu"] = [];
+        $contentData = $canvasData['next_fu'];
+    }
 }
-$contentData = $canvasData;
+
+if(!isset($contentData[$hcpPro->id])) $contentData[$hcpPro->id] = [];
+$contentData = $canvasData['next_fu'][$hcpPro->id];

+ 15 - 4
resources/views/app/patient/canvas-sections/next_fu/summary.php

@@ -1,5 +1,9 @@
 <?php
 
+use App\Models\Page;
+
+$page = Page::where('client_id', $patient->id)->where('category', 'CANVAS')->where('key', 'next_fu')->first();
+
 // HUMONGOUS FIX! This CRITICAL "if" was never there till now!
 if(!@$contentData) {
 
@@ -17,13 +21,20 @@ if(!@$contentData) {
     }
 
     $contentData = false;
-    if ($patient->canvas_data) {
-        $canvasData = json_decode($patient->canvas_data, true);
-        if(isset($canvasData["next_fu"]) && isset($canvasData["next_fu"][$hcpPro->id])) {
-            $contentData = $canvasData["next_fu"][$hcpPro->id];
+
+    if($page){
+
+    }else{
+        if ($patient->canvas_data) {
+            $canvasData = json_decode($patient->canvas_data, true);
+            if(!isset($canvasData["next_fu"])) $canvasData["next_fu"] = [];
+            $contentData = $canvasData['next_fu'];
         }
     }
 
+    if(!isset($contentData[$hcpPro->id])) $contentData[$hcpPro->id] = [];
+    $contentData = $canvasData['next_fu'][$hcpPro->id];
+
 }
 
 if($contentData === false) {

+ 15 - 6
resources/views/app/patient/canvas-sections/pmhx/default.php

@@ -1,10 +1,19 @@
 <?php
 
-$canvasData = [];
-if ($patient->canvas_data) {
-    $canvasData = json_decode($patient->canvas_data, true);
-    if (isset($canvasData["pmhx"])) {
-        $canvasData = $canvasData["pmhx"];
+
+use App\Models\Page;
+
+$page = Page::where('client_id', $patient->id)->where('category', 'CANVAS')->where('key', 'pmhx')->first();
+
+$contentData = [];
+
+if($page){
+    $contentData = json_decode($page->data, true);
+}else{
+    if ($patient->canvas_data) {
+        $canvasData = json_decode($patient->canvas_data, true);
+        if (isset($canvasData["pmhx"])) {
+            $contentData = $canvasData["pmhx"];
+        }
     }
 }
-$contentData = $canvasData;

+ 18 - 7
resources/views/app/patient/canvas-sections/pmhx/summary.php

@@ -1,4 +1,9 @@
 <?php
+
+use App\Models\Page;
+
+$page = Page::where('client_id', $patient->id)->where('category', 'CANVAS')->where('key', 'pmhx')->first();
+
 $fields = [
     [
         "Head" => ["Trauma"],
@@ -34,18 +39,24 @@ $contentData = [
     "comments" => "",
 ];
 $isempty = false;
-if ($patient->canvas_data) {
-    $canvasData = json_decode($patient->canvas_data, true);
-    if (isset($canvasData["pmhx"])) {
-        $contentData = $canvasData["pmhx"];
+
+if($page){
+    $contentData = json_decode($page->data, true);
+}else{
+    if ($patient->canvas_data) {
+        $canvasData = json_decode($patient->canvas_data, true);
+        if (isset($canvasData["pmhx"])) {
+            $contentData = $canvasData["pmhx"];
+        }
+        else {
+            $isempty = true;
+        }
     }
     else {
         $isempty = true;
     }
 }
-else {
-    $isempty = true;
-}
+
 
 if($isempty) {
     echo '<span class="text-secondary">No medical history in the system</span>';

+ 14 - 6
resources/views/app/patient/canvas-sections/pshx/default.php

@@ -1,10 +1,18 @@
 <?php
 
-$canvasData = [];
-if ($patient->canvas_data) {
-    $canvasData = json_decode($patient->canvas_data, true);
-    if (isset($canvasData["pshx"])) {
-        $canvasData = $canvasData["pshx"];
+use App\Models\Page;
+
+$page = Page::where('client_id', $patient->id)->where('category', 'CANVAS')->where('key', 'pshx')->first();
+
+$contentData = [];
+
+if($page){
+    $contentData = json_decode($page->data, true);
+}else{
+    if ($patient->canvas_data) {
+        $canvasData = json_decode($patient->canvas_data, true);
+        if (isset($canvasData["pshx"])) {
+            $contentData = $canvasData["pshx"];
+        }
     }
 }
-$contentData = $canvasData;

+ 21 - 9
resources/views/app/patient/canvas-sections/pshx/summary.php

@@ -1,4 +1,9 @@
 <?php
+
+use App\Models\Page;
+
+$page = Page::where('client_id', $patient->id)->where('category', 'CANVAS')->where('key', 'pshx')->first();
+
 $fields = [
     [
         "" => ["Aneurysm repair", "Appendectomy", "Back surgery", "Bariatric surgery/gastric bypass", "Bilateral tubal ligation", "Breast resection/mastectomy", "CABG", "Carotid endarterectomy/stent", "Carpal tunnel release surgery",]
@@ -20,21 +25,28 @@ $contentData = [
     "comments" => "",
 ];
 $isempty = false;
-if ($patient->canvas_data) {
-    $canvasData = json_decode($patient->canvas_data, true);
-    if (isset($canvasData["pshx"])) {
-        $contentData = $canvasData["pshx"];
-        if(!isset($contentData['customFields'])){
-            $contentData['customFields'] = [];
+
+if($page){
+    $contentData = json_decode($page->data, true);
+}else{
+    if ($patient->canvas_data) {
+        $canvasData = json_decode($patient->canvas_data, true);
+        if (isset($canvasData["pshx"])) {
+            $contentData = $canvasData["pshx"];
+            if(!isset($contentData['customFields'])){
+                $contentData['customFields'] = [];
+            }
+        }
+        else {
+            $isempty = true;
         }
     }
     else {
         $isempty = true;
     }
 }
-else {
-    $isempty = true;
-}
+
+
 
 if($isempty) {
     echo '<span class="text-secondary">No surgical history in the system</span>';

+ 17 - 7
resources/views/app/patient/canvas-sections/ros/summary.php

@@ -1,20 +1,30 @@
 <?php 
+
+use App\Models\Page;
+
+$page = Page::where('client_id', $patient->id)->where('category', 'CANVAS')->where('key', 'ros')->first();
+
 $contentData = [
     'value'=>''
 ];
 $isempty = false;
-if ($patient->canvas_data) {
-    $canvasData = json_decode($patient->canvas_data, true);
-    if (isset($canvasData["ros"])) {
-        $contentData = $canvasData["ros"];
+
+if($page){
+    $contentData = json_decode($page, true);
+}else {
+    if ($patient->canvas_data) {
+        $canvasData = json_decode($patient->canvas_data, true);
+        if (isset($canvasData["ros"])) {
+            $contentData = $canvasData["ros"];
+        }
+        else {
+            $isempty = true;
+        }
     }
     else {
         $isempty = true;
     }
 }
-else {
-    $isempty = true;
-}
 
 if($isempty) {
     echo '<span class="text-secondary">No ROS data</span>';

+ 15 - 6
resources/views/app/patient/canvas-sections/rx/default.php

@@ -1,10 +1,19 @@
 <?php
 
-$canvasData = [];
-if ($patient->canvas_data) {
-    $canvasData = json_decode($patient->canvas_data, true);
-    if (isset($canvasData["rx"])) {
-        $canvasData = $canvasData["rx"];
+
+use App\Models\Page;
+
+$page = Page::where('client_id', $patient->id)->where('category', 'CANVAS')->where('key', 'rx')->first();
+
+$contentData = [];
+
+if($page){
+    $contentData = json_decode($page->data, true);
+}else{
+    if ($patient->canvas_data) {
+        $canvasData = json_decode($patient->canvas_data, true);
+        if (isset($canvasData["rx"])) {
+            $contentData = $canvasData["rx"];
+        }
     }
 }
-$contentData = $canvasData;

+ 13 - 9
resources/views/app/patient/canvas-sections/rx/summary.php

@@ -1,14 +1,18 @@
 <?php
 
-$contentData = [
-    "items" => []
-];
-if($patient->canvas_data) {
-    $canvasData = json_decode($patient->canvas_data, true);
-    if(isset($canvasData["rx"])) {
-        $contentData = $canvasData["rx"];
-        if(!isset($contentData['items'])){
-            $contentData['items'] = [];
+use App\Models\Page;
+
+$page = Page::where('client_id', $patient->id)->where('category', 'CANVAS')->where('key', 'rx')->first();
+
+$contentData = [];
+
+if($page){
+    $contentData = json_decode($page->data, true);
+}else{
+    if ($patient->canvas_data) {
+        $canvasData = json_decode($patient->canvas_data, true);
+        if (isset($canvasData["rx"])) {
+            $contentData = $canvasData["rx"];
         }
     }
 }

+ 15 - 6
resources/views/app/patient/canvas-sections/sochx/default.php

@@ -1,10 +1,19 @@
 <?php
 
-$canvasData = [];
-if ($patient->canvas_data) {
-    $canvasData = json_decode($patient->canvas_data, true);
-    if (isset($canvasData["sochx"])) {
-        $canvasData = $canvasData["sochx"];
+use App\Models\Page;
+
+$page = Page::where('client_id', $patient->id)->where('category', 'CANVAS')->where('key', 'sochx')->first();
+
+$contentData = [];
+
+if($page){
+    $contentData = json_decode($page->data, true);
+}else{
+    if ($patient->canvas_data) {
+        $canvasData = json_decode($patient->canvas_data, true);
+        if (isset($canvasData["sochx"])) {
+            $contentData = $canvasData["sochx"];
+        }
     }
 }
-$contentData = $canvasData;
+

+ 17 - 7
resources/views/app/patient/canvas-sections/sochx/summary.php

@@ -1,4 +1,9 @@
 <?php
+
+use App\Models\Page;
+
+$page = Page::where('client_id', $patient->id)->where('category', 'CANVAS')->where('key', 'sochx')->first();
+
 $fields = [
     [
         "Tobacco" => ["Current every day smoker", "Current some day smoker", "Former smoker", "Heavy tobacco smoker", "Light tobacco smoker", "Never smoker", "Smoker, current status unknown", "Unknown if ever smoked "],
@@ -23,18 +28,23 @@ $contentData = [
     "comments" => "",
 ];
 $isempty = false;
-if ($patient->canvas_data) {
-    $canvasData = json_decode($patient->canvas_data, true);
-    if (isset($canvasData["sochx"])) {
-        $contentData = $canvasData["sochx"];
+
+if($page){
+    $contentData = json_decode($page->data, true);
+}else{
+    if ($patient->canvas_data) {
+        $canvasData = json_decode($patient->canvas_data, true);
+        if (isset($canvasData["sochx"])) {
+            $contentData = $canvasData["sochx"];
+        }
+        else {
+            $isempty = true;
+        }
     }
     else {
         $isempty = true;
     }
 }
-else {
-    $isempty = true;
-}
 
 if($isempty) {
     echo '<span class="text-secondary">No social history in the system</span>';

+ 16 - 6
resources/views/app/patient/canvas-sections/vitals/default.php

@@ -1,10 +1,20 @@
 <?php
 
-$canvasData = [];
-if ($patient->canvas_data) {
-    $canvasData = json_decode($patient->canvas_data, true);
-    if (isset($canvasData["vitals"])) {
-        $canvasData = $canvasData["vitals"];
+
+use App\Models\Page;
+
+$page = Page::where('client_id', $patient->id)->where('category', 'CANVAS')->where('key', 'vitals')->first();
+
+$contentData = [];
+
+if($page){
+    $contentData = json_decode($page->data, true);
+}else{
+    if ($patient->canvas_data) {
+        $canvasData = json_decode($patient->canvas_data, true);
+        if (isset($canvasData["vitals"])) {
+            $contentData = $canvasData["vitals"];
+        }
     }
 }
-$contentData = $canvasData;
+

+ 23 - 13
resources/views/app/patient/canvas-sections/vitals/summary.php

@@ -1,4 +1,9 @@
 <?php
+
+use App\Models\Page;
+
+$page = Page::where('client_id', $patient->id)->where('category', 'CANVAS')->where('key', 'vitals')->first();
+
 $vitalLabels = [
     "heightInInches" => "Ht. (in.)",
     "weightPounds" => "Wt. (lbs.)",
@@ -64,21 +69,26 @@ $contentData = [
     ],
 ];
 
-if($patient->canvas_data) {
-    $canvasData = json_decode($patient->canvas_data, true);
-    if(isset($canvasData["vitals"])) {
-        $contentData = $canvasData["vitals"];
-        // ensure $contentData has all the expected vitals and correct labels!
-        foreach ($vitalLabels as $k => $v) {
-            if(!isset($contentData[$k])) {
-                $contentData[$k] = [
-                    "label" => $v,
-                    "value" => "",
-                    "date" => "",
-                ];
-            }
+
+if($page){
+    $contentData = json_decode($page->data, true);
+}else{
+    if($patient->canvas_data) {
+        $canvasData = json_decode($patient->canvas_data, true);
+        if(isset($canvasData["vitals"])) {
+            $contentData = $canvasData["vitals"];
+            // ensure $contentData has all the expected vitals and correct labels!
         }
+    }    
+}
 
+foreach ($vitalLabels as $k => $v) {
+    if(!isset($contentData[$k])) {
+        $contentData[$k] = [
+            "label" => $v,
+            "value" => "",
+            "date" => "",
+        ];
     }
 }
 

+ 14 - 6
resources/views/app/patient/canvas-sections/vitals_may21/default.php

@@ -1,10 +1,18 @@
 <?php
 
-$canvasData = [];
-if ($patient->canvas_data) {
-    $canvasData = json_decode($patient->canvas_data, true);
-    if (isset($canvasData["vitals_may21"])) {
-        $canvasData = $canvasData["vitals_may21"];
+use App\Models\Page;
+
+$page = Page::where('client_id', $patient->id)->where('category', 'CANVAS')->where('key', 'vitals_may21')->first();
+
+$contentData = [];
+
+if($page){
+    $contentData = json_decode($page->data, true);
+}else{
+    if ($patient->canvas_data) {
+        $canvasData = json_decode($patient->canvas_data, true);
+        if (isset($canvasData["vitals_may21"])) {
+            $contentData = $canvasData["vitals_may21"];
+        }
     }
 }
-$contentData = $canvasData;

+ 17 - 0
resources/views/app/patient/canvas-sections/vitals_may21/summary.php

@@ -1,6 +1,12 @@
 <?php
+
 use App\Models\Note;
 use App\Models\Client;
+
+use App\Models\Page;
+
+$page = Page::where('client_id', $patient->id)->where('category', 'CANVAS')->where('key', 'vitals_may21')->first();
+
 /** @var Note $note */
 /** @var Client $patient */
 if(!@$contentData) {
@@ -80,6 +86,17 @@ if(!@$contentData) {
             }
         }
     }
+
+    if($page){
+        $contentData = json_decode($page->data, true);
+    }else{
+        if($patient->canvas_data) {
+            $canvasData = json_decode($patient->canvas_data, true);
+            if (isset($canvasData["vitals_may21"]["note_uid"]) && $canvasData["vitals_may21"]["note_uid"] === @$note->uid) {
+                $contentData = $canvasData["vitals_may21"];
+            }
+        }    
+    }
 }
 ?>
 <table class="table table-sm table-bordered mb-2">