ソースを参照

Visit UI - medrisk vigilance v1 (wip)

Vijayakrishnan 3 年 前
コミット
1cde38340f

+ 217 - 0
app/Helpers/fdb.php

@@ -0,0 +1,217 @@
+<?php
+
+use Illuminate\Http\Request;
+use Illuminate\Support\Facades\DB;
+
+if(!function_exists('side_effects_info')) {
+    function side_effects_info($_drugs) {
+
+        $result = [];
+
+        // collect gcn-seq-nos
+        $gcnSeqNos = [];
+        $rxMap = [];
+        foreach ($_drugs as $drug) {
+            if(@$drug->data && $drug->data->gcnSeqno) {
+                $gcnSeqNos[] = $drug->data->gcnSeqno;
+                $rxMap[$drug->data->gcnSeqno] = $drug->data->name;
+            }
+        }
+        if(!count($gcnSeqNos)) return $result;
+
+        $gcnSeqNos = implode(',', array_map(function($_x) {
+            return "'" . $_x . "'";
+        }, $gcnSeqNos));
+
+        $sides = DB::connection('pgsql_fdb')->select("
+SELECT r1.gcn_seqno, r1.side, sm.side_freq, sm.side_sev, sm.dxid, dx.dxid_desc56
+FROM rsidegc0_gcnseqno_link r1
+    JOIN rsidema3_mstr sm ON r1.side = sm.side
+    JOIN rfmldx0_dxid dx ON sm.dxid = dx.dxid
+WHERE r1.gcn_seqno IN (" . $gcnSeqNos . ")
+ORDER BY r1.gcn_seqno, sm.side_sev DESC, sm.side_freq ASC
+            "
+        );
+
+        $seMap = [];
+
+        foreach ($sides as $se) {
+
+            if(!isset($seMap[$rxMap[$se->gcn_seqno]])) {
+                $seMap[$rxMap[$se->gcn_seqno]] = [];
+            }
+
+            $seMap[$rxMap[$se->gcn_seqno]][] = [
+                "gcn_seqno" => $se->gcn_seqno,
+                "side_freq" => $se->side_freq,
+                "side_sev" => $se->side_sev,
+                "dxid_desc56" => $se->dxid_desc56,
+            ];
+        }
+
+        $result = $seMap;
+
+        return $result;
+    }
+}
+
+if(!function_exists('precautions_info')) {
+    function precautions_info($_drugs) {
+
+    }
+}
+
+if(!function_exists('contraindications_info')) {
+    function contraindications_info($_drugs) {
+
+        $result = [];
+
+        // collect routed med ids
+        $routedMedIds = [];
+        $rxMap = [];
+        foreach ($_drugs as $drug) {
+            if(@$drug->data && $drug->data->routedMedId) {
+                $routedMedIds[] = $drug->data->routedMedId;
+                $rxMap[$drug->data->routedMedId] = $drug->data->name;
+            }
+        }
+        if(!count($routedMedIds)) return $result;
+
+        $routedMedIds = implode(',', array_map(function($_x) {
+            return "'" . $_x . "'";
+        }, $routedMedIds));
+
+        $contraindications = DB::connection('pgsql_fdb')->select("
+SELECT r1.routed_med_id, r1.ddxcn, r2.dxid, r2.ddxcn_sl, r3.dxid_desc56
+FROM rddcmrm0_routed_med_link r1
+    JOIN rddcmma1_contra_mstr r2 ON r1.ddxcn = r2.ddxcn
+    JOIN rfmldx0_dxid r3 ON r2.dxid = r3.dxid
+WHERE r1.routed_med_id IN (" . $routedMedIds . ")
+ORDER BY r1.routed_med_id, r3.dxid_desc56, r2.ddxcn_sl
+            "
+        );
+
+        $ciMap = [];
+
+        foreach ($contraindications as $ci) {
+
+            if(!isset($ciMap[$rxMap[$ci->routed_med_id]])) {
+                $ciMap[$rxMap[$ci->routed_med_id]] = [];
+            }
+
+            $ciMap[$rxMap[$ci->routed_med_id]][] = [
+                "dxid_desc56" => $ci->dxid_desc56,
+            ];
+        }
+
+        $result = $ciMap;
+
+        return $result;
+
+    }
+}
+
+if(!function_exists('drug_allergy_info')) {
+    function drug_allergy_info($_drugs, $_allergies) {
+
+    }
+}
+
+if(!function_exists('drug_drug_interaction_info')) {
+    function drug_drug_interaction_info($_drugs) {
+
+    }
+}
+
+if(!function_exists('duplicate_therapy_info')) {
+    function duplicate_therapy_info($_drugs) {
+
+        $dptClasses = [];
+        foreach ($_drugs as $drug) {
+            $drug->dpt = getDptClassFromGcnSeqNo($drug->data->gcnSeqno);
+        }
+
+        $leftIndex = 0;
+        $matches = [];
+        for ($i = $leftIndex; $i < count($_drugs) - 1; $i++) {
+            for ($j = $i + 1; $j < count($_drugs); $j++) {
+                $compareResult = compareDPTs($_drugs[$i]->dpt, $_drugs[$j]->dpt);
+                foreach ($compareResult as $c) {
+                    $matches[] = "<b>{$_drugs[$i]->data->name}</b> and <b>{$_drugs[$j]->data->name}</b> both participate in the duplicate therapy class <b>{$c->dpt_class_desc}</b> (duplicates allowed: {$c->dpt_allowance})";
+                }
+            }
+        }
+
+        if(!count($matches)) return '';
+
+        return "<ol class='pl-0 ml-3 mb-0'>" . implode("", array_map(function ($_x) {
+                return "<li class='mb-1'>" . $_x . "</li>";
+            }, $matches)) . "</ol>";
+    }
+}
+
+if (!function_exists('getDptClassFromGcnSeqNo')) {
+    function getDptClassFromGcnSeqNo($_gcnSeqNo)
+    {
+        return DB::connection('pgsql_fdb')->select("
+    SELECT distinct r1.dpt_class_id, r2.dpt_allowance, r2.dpt_class_desc
+    FROM RDPTGC0_GCNSEQNO_LINK r1
+    JOIN RDPTCL0_CLASS_ID r2 on r1.dpt_class_id = r2.dpt_class_id
+    WHERE r1.gcn_seqno = :gcnSeqNo
+                ",
+            ['gcnSeqNo' => $_gcnSeqNo]
+        );
+    }
+}
+if (!function_exists('compareDPTs')) {
+    function compareDPTs($_dptArray1, $_dptArray2)
+    {
+        $output = [];
+        for ($i = 0; $i < count($_dptArray1); $i++) {
+            for ($j = 0; $j < count($_dptArray2); $j++) {
+                if ($_dptArray1[$i]->dpt_class_id == $_dptArray2[$j]->dpt_class_id) {
+                    $output[] = json_decode(json_encode([
+                        "dpt_allowance" => $_dptArray1[$i]->dpt_allowance,
+                        "dpt_class_desc" => $_dptArray1[$i]->dpt_class_desc
+                    ]));
+                }
+            }
+        }
+        return $output;
+    }
+}
+
+if(!function_exists('coadministration_info')) {
+    function coadministration_info($_drugs) {
+
+        // collect gcn-seq-nos
+        $gcnSeqNos = [];
+        $rxMap = [];
+        foreach ($_drugs as $drug) {
+            if(@$drug->data && $drug->data->gcnSeqno) {
+                $gcnSeqNos[] = $drug->data->gcnSeqno;
+                $rxMap[$drug->data->gcnSeqno] = $drug->data->name;
+            }
+        }
+        if(!count($gcnSeqNos)) return $result;
+
+        $gcnSeqNos = implode(',', array_map(function($_x) {
+            return "'" . $_x . "'";
+        }, $gcnSeqNos));
+
+        $coadministration = DB::connection('pgsql_fdb')->select("
+SELECT distinct r1.coadmin_dosing_text
+FROM radige0_ddi_gcnseqno_except r1
+WHERE r1.side_a_gcn_seqno in ($gcnSeqNos) AND r1.side_b_gcn_seqno in ($gcnSeqNos)
+            "
+        );
+
+        if(!$coadministration || !count($coadministration)) return '';
+
+        return "<ol class='pl-0 ml-3 mb-0'>" . implode("", array_map(function ($_x) {
+                return "<li class='mb-1'>" . $_x->coadmin_dosing_text . "</li>";
+            }, $coadministration)) . "</ol>";
+
+        return $coadministration;
+    }
+}

+ 2 - 1
composer.json

@@ -47,7 +47,8 @@
             "database/factories"
         ],
         "files": [
-            "app/Helpers/helpers.php"
+            "app/Helpers/helpers.php",
+            "app/Helpers/fdb.php"
         ]
     },
     "autoload-dev": {

+ 4 - 0
public/css/style.css

@@ -384,6 +384,10 @@ body>nav.navbar {
 .ql-editor ul > li::before {
     content: '';
 }
+.m-neg-3 {
+    margin-left: -1rem;
+    margin-right: -1rem;
+}
 .m-neg-4 {
     margin-left: -1.25rem;
     margin-right: -1.25rem;

+ 77 - 1
resources/views/app/patient/segment-templates/medrisk_vigilence/summary.blade.php

@@ -1 +1,77 @@
-<h1>Summary for medrisk_vigilence</h1>
+<?php
+
+// info from patient chart
+$drugs = \App\Models\Point::getPointsOfCategory($patient, "MEDICATION");
+
+// side effects
+$sideeffects = side_effects_info($drugs);
+
+// contraindications
+$contraindications = contraindications_info($drugs);
+
+// dpt
+$dptInfo = duplicate_therapy_info($drugs);
+
+// coadministration notes
+$coadministration = coadministration_info($drugs);
+
+?>
+
+@if(!!$dptInfo)
+
+    <div class="m-neg-3 p-3 mb-3 mt-2 border bg-white mr-0">
+        <p class="font-weight-bold m-0 font-size-14 text-info">Duplicate Therapy Notes</p>
+        <div class="mt-3 ml-3">
+            {!! $dptInfo !!}
+        </div>
+    </div>
+
+@endif
+
+@if(!!$coadministration)
+
+    <div class="m-neg-3 p-3 mb-3 mt-2 border bg-white mr-0">
+        <p class="font-weight-bold m-0 font-size-14 text-info">Coadministration Notes</p>
+        <div class="mt-3 ml-3">
+            {!! $coadministration !!}
+        </div>
+    </div>
+
+@endif
+
+@if(count($sideeffects))
+
+    <div class="m-neg-3 p-3 mb-3 mt-2 border bg-white mr-0">
+        <p class="font-weight-bold m-0 font-size-14 text-info">Side Effects</p>
+        @foreach($sideeffects as $drug => $sideeffect)
+            <div class="mt-3 ml-3">
+                <p class="font-weight-bold mb-2">{{$drug}}</p>
+                <div class="flex-grow-1 d-inline-flex flex-wrap ml-3">
+                    @foreach($sideeffect as $se)
+                        <span class="mr-2 px-2 py-0 border bg-light mb-1">{{$se['dxid_desc56']}}</span>
+                    @endforeach
+                </div>
+            </div>
+        @endforeach
+    </div>
+
+@endif
+
+@if(count($contraindications))
+
+    <div class="m-neg-3 p-3 mb-3 mt-2 border bg-white mr-0">
+        <p class="font-weight-bold m-0 font-size-14 text-info">Contraindications</p>
+        @foreach($contraindications as $drug => $contraindication)
+            <div class="mt-3 ml-3">
+                <p class="font-weight-bold mb-2">{{$drug}}</p>
+                <div class="flex-grow-1 d-inline-flex flex-wrap ml-3">
+                    @foreach($contraindication as $ci)
+                        <span class="mr-2 px-2 py-0 border bg-light mb-1">{{$ci['dxid_desc56']}}</span>
+                    @endforeach
+                </div>
+            </div>
+        @endforeach
+    </div>
+
+@endif
+