Explorar o código

Vitals graph UI - months filter

Vijayakrishnan %!s(int64=4) %!d(string=hai) anos
pai
achega
22054674cb
Modificáronse 1 ficheiros con 31 adicións e 18 borrados
  1. 31 18
      resources/views/app/patient/vitals-graph.blade.php

+ 31 - 18
resources/views/app/patient/vitals-graph.blade.php

@@ -5,32 +5,45 @@
     <script src="/c3/d3.v5.min.js" charset="utf-8"></script>
     <script src="/c3/c3.min.js"></script>
 
+    <div class="d-flex align-items-center">
+        <h4 class="font-weight-bold mb-0 text-secondary font-size-16">Vitals Graph</h4>
+        <?php
+        $months = [];
+        $monthNames = [];
+        for ($i=6; $i>=0; $i--) {
+            $m = date_sub(date_create(), date_interval_create_from_date_string($i . " month" . ($i === 1 ? '' : 's')));
+            $monthNames[] = date_format($m, "M, Y");
+            $months[] = date_format($m, "Y-m-01");
+        }
+        $current = $filter ? $filter : $months[count($months) - 1];
+        ?>
+        <select class="ml-auto max-width-200px form-control form-control-sm"
+                onchange="fastLoad('/patients/view/{{$patient->uid}}/vitals-graph/' + this.value, true, false, false)">
+            <?php for ($i=count($months) - 1; $i>=0; $i--): ?>
+            <option value="{{$months[$i]}}" {{ $current === $months[$i] ? 'selected' : '' }}>{{$monthNames[$i]}}</option>
+            <?php endfor; ?>
+        </select>
+    </div>
+
+    <hr class="m-neg-4">
+
     <div id="vitalsGraphComponent" class="stag-chart">
-        <h4 class="font-weight-bold mb-3 text-secondary font-size-16">Blood Pressure</h4>
+        <h4 class="font-weight-bold mb-3 text-secondary font-size-14 text-center">Blood Pressure</h4>
         <div id="bp-chart" class="mb-4">BP Graph</div>
         <hr class="m-neg-4">
-        <h4 class="font-weight-bold mb-3 text-secondary font-size-16">Weight</h4>
+        <h4 class="font-weight-bold mb-3 text-secondary font-size-14 text-center">Weight</h4>
         <div id="weight-chart">Weight Graph</div>
     </div>
 
     <?php
     $dates = [];
-    for ($i=30; $i>=0; $i--) { // todo get from filter
-        $d = date_sub(date_create(), date_interval_create_from_date_string($i . " day" . ($i === 1 ? '' : 's')));
-        $dates[] = date_format($d, "Y-m-d");
-    }
+    $startDate = $current;
+    $nextMonthFirstDay = date_format(date_add(date_create($startDate), date_interval_create_from_date_string("1 month")), 'Y-m-d');
 
-    function getMeasurementOfTypeForDate($allMeasurements, $category, $date) {
-        if(!$allMeasurements) return null;
-        $filtered = array_filter($allMeasurements, function($_measurement) use ($category, $date) {
-            $measurementDate = date('Y-m-d', strtotime($_measurement['effective_date']));
-            return $_measurement['label'] === $category && $measurementDate === $date;
-        });
-        if($filtered && count($filtered)) {
-            $filtered = array_values($filtered);
-            return $filtered[count($filtered) - 1]; // return last measurement taken on a day [TEMP]
-        }
-        return null;
+    $nextDay = $startDate;
+    while ($nextDay !== $nextMonthFirstDay) {
+        $dates[] = $nextDay;
+        $nextDay = date_format(date_add(date_create($nextDay), date_interval_create_from_date_string('1 day')), 'Y-m-d');
     }
 
     $allMeasurements = $patient->measurements->toArray();
@@ -184,7 +197,7 @@
                         },
                     },
                     regions: [
-                        {axis: 'y', start: 125, end: 140, class: 'safe-region', label: 'Safe Weight: 100 to 140 lbs'},
+                        {axis: 'y', start: 100, end: 140, class: 'safe-region', label: 'Safe Weight: 100 to 140 lbs'},
                     ]
                 });
             }