Browse Source

Rx wizard - show fdb info on med selection

Vijayakrishnan 3 years ago
parent
commit
f759399496

+ 57 - 1
app/Helpers/fdb.php

@@ -150,7 +150,11 @@ if(!function_exists('drug_allergy_info')) {
             }
         }
 
-        return implode("<br>", $output);
+        if(!count($output)) return '';
+
+        return "<ol class='pl-0 ml-3 mb-0'>" . implode("", array_map(function ($_x) {
+                return "<li class='mb-1'>" . $_x . "</li>";
+            }, $output)) . "</ol>";
     }
 }
 if(!function_exists('drugAllergyIngredientAllergenVsSingleRx')) {
@@ -307,6 +311,31 @@ if(!function_exists('drug_drug_interaction_info')) {
         return implode("<br>", $output);
     }
 }
+if(!function_exists('drug_drug_interaction_info_with_pivot')) {
+    function drug_drug_interaction_info_with_pivot($_pivot, $_drugs) {
+
+        if(!count($_drugs)) return "";
+
+        $leftIndex = 0;
+
+        $output = [];
+
+        for ($i=0; $i<count($_drugs); $i++) {
+            $output[] = drugDrugInteractionSinglePair($_pivot, $_drugs[$i]);
+        }
+
+        if(!count($output)) return '';
+
+        $output = array_filter($output, function($_x) {
+            return !!$_x;
+        });
+
+        return "<ol class='pl-0 ml-3 mb-0'>" . implode("", array_map(function ($_x) {
+                return "<li class='mb-1'>" . $_x . "</li>";
+            }, $output)) . "</ol>";
+
+    }
+}
 if(!function_exists('drugDrugInteractionSinglePair')) {
     function drugDrugInteractionSinglePair($_rx1, $_rx2)
     {
@@ -492,6 +521,33 @@ if(!function_exists('duplicate_therapy_info')) {
     }
 }
 
+if(!function_exists('duplicate_therapy_info_with_pivot')) {
+    function duplicate_therapy_info_with_pivot($_pivot, $_drugs) {
+
+        $_pivot->dpt = getDptClassFromGcnSeqNo($_pivot->data->gcnSeqno);
+
+        $dptClasses = [];
+        foreach ($_drugs as $drug) {
+            $drug->dpt = getDptClassFromGcnSeqNo($drug->data->gcnSeqno);
+        }
+
+        $leftIndex = 0;
+        $matches = [];
+        for ($i = 0; $i < count($_drugs); $i++) {
+            $compareResult = compareDPTs($_pivot->dpt, $_drugs[$i]->dpt);
+            foreach ($compareResult as $c) {
+                $matches[] = "<b>{$_pivot->data->name}</b> and <b>{$_drugs[$i]->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)
     {

+ 18 - 7
app/Http/Controllers/FDBPGController.php

@@ -2,6 +2,7 @@
 
 namespace App\Http\Controllers;
 
+use App\Models\Client;
 use Illuminate\Http\Request;
 use Illuminate\Support\Facades\DB;
 
@@ -699,21 +700,21 @@ WHERE r1.side_a_gcn_seqno in ($gcnSeqnos) AND r1.side_b_gcn_seqno in ($gcnSeqnos
     }
 
         private function getDptClassFromGcnSeqNo($_gcnSeqNo) {
-            return DB::connection('pgsql_fdb')->select("
+        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]
-            );
-        }
+            ['gcnSeqNo' => $_gcnSeqNo]
+        );
+    }
 
         private 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) {
+        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
@@ -723,4 +724,14 @@ WHERE r1.side_a_gcn_seqno in ($gcnSeqnos) AND r1.side_b_gcn_seqno in ($gcnSeqnos
         }
         return $output;
     }
+
+    public function rxVigilance(Request $request, Client $patient) {
+        return view('app.fdb-pg.rx-vigilance', compact('patient'));
+    }
+    public function dxVigilance(Request $request, Client $patient) {
+        return view('app.fdb-pg.dx-vigilance', compact('patient'));
+    }
+    public function allergyVigilance(Request $request, Client $patient) {
+        return view('app.fdb-pg.allergy-vigilance', compact('patient'));
+    }
 }

+ 3 - 0
public/css/style.css

@@ -1961,6 +1961,9 @@ table.dashboard-stats-table th {
 .min-height-300px {
     min-height: 300px;
 }
+.max-height-400px {
+    max-height: 400px;
+}
 .min-height-500px {
     min-height: 500px;
 }

+ 0 - 0
resources/views/app/fdb-pg/allergy-vigilance.blade.php


+ 0 - 0
resources/views/app/fdb-pg/dx-vigilance.blade.php


+ 133 - 0
resources/views/app/fdb-pg/rx-vigilance.blade.php

@@ -0,0 +1,133 @@
+<?php
+
+// info from patient chart
+$drugs = \App\Models\Point::getPointsOfCategory($patient, "MEDICATION");
+$allergies = \App\Models\Point::getPointsOfCategory($patient, "ALLERGY");
+$problems = \App\Models\Point::getPointsOfCategory($patient, "PROBLEMS");
+
+// filter out drugs without fdb info on them
+$drugs = $drugs->filter(function ($_drug) {
+    return @$_drug->data &&
+        $_drug->data->name &&
+        $_drug->data->medId &&
+        $_drug->data->routedMedId &&
+        $_drug->data->routedDosageFormMedId &&
+        $_drug->data->gcnSeqno;
+});
+
+// filter out allergies without fdb info on them
+$allergies = $allergies->filter(function ($_allergy) {
+    return @$_allergy->data &&
+        $_allergy->data->name &&
+        $_allergy->data->damConceptId &&
+        $_allergy->data->damConceptIdType;
+});
+
+// filter out problems without fdb info on them
+$problems = $problems->filter(function ($_problem) {
+    return @$_problem->data &&
+        $_problem->data->name &&
+        $_problem->data->dxid;
+});
+
+// get pivot drug
+$pivotRx = json_decode(json_encode([
+    "data" => [
+        "name" => request()->input('name'),
+        "medId" => request()->input('medId'),
+        "routedMedId" => request()->input('routedMedId'),
+        "routedDosageFormMedId" => request()->input('routedDosageFormMedId'),
+        "gcnSeqno" => request()->input('gcnSeqno'),
+    ]
+]));
+
+// other drugs
+$otherDrugs = $drugs->filter(function ($_drug) {
+    return $_drug->data->medId !== request()->input('medId') ||
+        $_drug->data->gcnSeqno !== request()->input('gcnSeqno');
+});
+
+// side effects
+$sideeffects = side_effects_info([$pivotRx]);
+
+// contraindications
+// TODO: check against patient's dx
+$contraindications = contraindications_info([$pivotRx], $problems);
+
+// dpt
+// TODO: check against patient's other drugs
+$dptInfo = duplicate_therapy_info_with_pivot($pivotRx, $otherDrugs);
+
+// ddi
+// TODO: check against patient's other drugs
+$ddi = drug_drug_interaction_info_with_pivot($pivotRx, $otherDrugs);
+
+// dam
+$dam = drug_allergy_info([$pivotRx], $allergies);
+
+?>
+
+
+
+
+
+@if(!!$dptInfo)
+    <div class="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">
+            {!! $dptInfo !!}
+        </div>
+    </div>
+@endif
+
+@if(!!$dam)
+    <div class="p-3 mb-3 mt-2 border bg-white mr-0">
+        <p class="font-weight-bold m-0 font-size-14 text-info">Drug Allergy Notes</p>
+        <div class="mt-3">
+            {!! $dam !!}
+        </div>
+    </div>
+@endif
+
+@if(!!$ddi)
+    </div>
+    <div class="p-3 mb-3 mt-2 border bg-white mr-0">
+        <p class="font-weight-bold m-0 font-size-14 text-info">Drug-Drug Interaction Notes</p>
+        <div class="mt-3">
+            {!! $ddi !!}
+        </div>
+    </div>
+@endif
+
+@if(count($sideeffects))
+    <div class="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">
+                <p class="font-weight-bold mb-2">{{$drug}}</p>
+                <div class="flex-grow-1 d-inline-flex flex-wrap">
+                    @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="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">
+                <p class="font-weight-bold mb-2">{{$drug}}</p>
+                <div class="flex-grow-1 d-inline-flex flex-wrap">
+                    @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
+

+ 17 - 3
resources/views/app/patient/medications-center.blade.php

@@ -317,7 +317,7 @@ $medications = $points;
         </table>
 
         <div class="d-flex align-items-center">
-            <div class="mt-1 w-100 border p-2 bg-aliceblue border-info rounded">
+            <div class="mt-1 w-100 border p-3 bg-aliceblue border-info rounded">
                 <!--<a href="#" start show class="btn btn-sm btn btn-outline-primary">+ Add new medication, prescribed during this visit</a>-->
                 <form action="/api/visitPoint/addTopLevel" class="mcp-theme-1 w-100" id="frm-add-medication">
                     <input type="hidden" name="noteUid" value="<?= $note->uid ?>">
@@ -329,10 +329,9 @@ $medications = $points;
                     <input type="hidden" data-name="routedDosageFormMedId">
                     <input type="hidden" data-name="gcnSeqno">
 
-                    <p class="mb-2"><b>Add Medication</b></p>
-
                     <div class="row">
                         <div class="col-7">
+                            <p class="mb-2"><b>Add Medication</b></p>
                             <div class="mb-2">
                                 <label class="text-sm mb-0">Name</label>
                                 <input type="text"
@@ -427,7 +426,9 @@ $medications = $points;
                             </div>
                         </div>
                         <div class="col-5 border-left">
+                            <div class="fdb-rx-vigilance max-height-400px overflow-auto">
 
+                            </div>
                         </div>
                     </div>
 
@@ -507,6 +508,19 @@ $medications = $points;
                     $(_input).closest('form').find('input[data-name="routedDosageFormMedId"]').val(_data.routed_dosage_form_med_id);
                     $(_input).closest('form').find('input[data-name="gcnSeqno"]').val(_data.gcn_seqno);
                     $(_input).closest('form').find('input[data-name="medId"]').val(_data.medid);
+
+                    $('.fdb-rx-vigilance').html('<span class="text-secondary font-italic">Please wait ...</span>');
+                    $.post('/fdb-rx-vigilance/{{$patient->uid}}', {
+                        _token: '{{csrf_token()}}',
+                        medId: _data.medid,
+                        routedMedId: _data.routed_med_id,
+                        routedDosageFormMedId: _data.routed_dosage_form_med_id,
+                        gcnSeqno: _data.gcn_seqno,
+                        name: _input.val(),
+                    }, _data => {
+                        $('.fdb-rx-vigilance').html(_data);
+                    });
+
                     return false;
                 });
 

+ 4 - 0
routes/web.php

@@ -489,6 +489,10 @@ Route::middleware('pro.auth')->group(function () {
     Route::any('/fdb-drug-coadministration', 'FDBPGController@drugCoadministration');
     Route::any('/fdb-duplicate-therapy', 'FDBPGController@duplicateTherapy');
 
+    Route::any('/fdb-rx-vigilance/{patient}', 'FDBPGController@rxVigilance');
+    Route::any('/fdb-dx-vigilance/{patient}', 'FDBPGController@dxVigilance');
+    Route::any('/fdb-allergy-vigilance/{patient}', 'FDBPGController@allergyVigilance');
+
     Route::get('/search-payer/json', 'PayerController@searchPayerV2JSON')->name('searchPayerV2JSON');
     Route::get('/search-facility/json', 'HomeController@facilitySuggestJSON')->name('facilitySuggestJSON');