Ver código fonte

Patients list > aquisition chart

Vijayakrishnan 4 anos atrás
pai
commit
97a64cf445

+ 16 - 1
app/Http/Controllers/HomeController.php

@@ -589,7 +589,22 @@ WHERE measurement.label NOT IN ('SBP', 'DBP')
                 break;
         }
         $patients = $query->orderBy('id', 'desc')->paginate(50);
-        return view('app/patients', compact('patients', 'filter'));
+
+        // patient acquisition chart (admin only)
+        $patientAcquisitionData = null;
+        if($performer->pro->pro_type === 'ADMIN') {
+            $startDate = date_sub(date_create(), date_interval_create_from_date_string("1 month"));
+            $startDate = date_format($startDate, "Y-m-d");
+            $patientAcquisitionData = DB::select(DB::raw(
+                "SELECT count(id) as count, DATE(created_at) as date " .
+                "FROM client " .
+                // "WHERE DATE(created_at) >= '$startDate' " .
+                "GROUP BY DATE(created_at) " .
+                "ORDER BY DATE(created_at) DESC " .
+                "LIMIT 30"));
+        }
+
+        return view('app/patients', compact('patients', 'filter', 'patientAcquisitionData'));
 
     }
 

+ 53 - 0
resources/views/app/patients.blade.php

@@ -2,6 +2,12 @@
 
 @section('content')
 
+    @if($pro->pro_type === 'ADMIN')
+    <link href="/c3/c3.min.css" rel="stylesheet">
+    <script src="/c3/d3.v5.min.js" charset="utf-8"></script>
+    <script src="/c3/c3.min.js"></script>
+    @endif
+
     <?php
     $showProgramsColumn = false;
     foreach($patients as $patient) {
@@ -44,6 +50,13 @@
                 </select>
             </div>
         </div>
+
+        @if($pro->pro_type === 'ADMIN')
+        <div class="card-header px-3 py-4 d-flex align-items-center bg-white justify-content-center">
+            <div id="patientAcquisitionChart" class="w-75"></div>
+        </div>
+        @endif
+
         <div class="card-body p-0">
             <table class="table table-condensed p-0 m-0">
                 <thead class="bg-light">
@@ -232,7 +245,47 @@
                 }
                 $('#patients-search').off('submit').on('submit', submit);
                 $('#patients-filter').off('change').on('change', submit);
+
+                @if($pro->pro_type === 'ADMIN')
+                    patientAcquisitionChart();
+                @endif
             }
+
+            @if($pro->pro_type === 'ADMIN')
+            <?php
+            $dates = [];
+            $acquisitions = [];
+            for ($i = count($patientAcquisitionData) - 1; $i >= 0; $i--) {
+                $dates[] = $patientAcquisitionData[$i]->date;
+                $acquisitions[] = $patientAcquisitionData[$i]->count;
+            }
+            ?>
+            function patientAcquisitionChart() {
+                var chart = c3.generate({
+                    bindto: '#patientAcquisitionChart',
+                    data: {
+                        x: 'x',
+                        // xFormat: '%Y%m%d', // 'xFormat' can be used as custom format of 'x'
+                        columns: [
+                            ['x', <?= implode(", ", array_map(function($_x) { return "'" . $_x . "'"; }, $dates)) ?>],
+                            ['Patient Aquisition', <?= implode(", ", array_map(function($_x) { return "'" . $_x . "'"; }, $acquisitions)) ?>],
+                        ]
+                    },
+                    axis: {
+                        x: {
+                            type: 'timeseries',
+                            tick: {
+                                format: '%Y-%m-%d',
+                                multiline: true,
+                                fit: true,
+                                rotate: -45
+                            },
+                        },
+                    }
+                });
+            }
+            @endif
+
             addMCInitializer('patients-list', init, '#patients-list');
         }).call(window);
     </script>