Kaynağa Gözat

FDB Playground - drud-drug-interaction (wip)

Vijayakrishnan 3 yıl önce
ebeveyn
işleme
015392e1ed

+ 184 - 0
app/Http/Controllers/FDBPGController.php

@@ -339,6 +339,190 @@ INTERSECT
         return !!count($matches);
     }
 
+    public function drugDrugInteraction(Request $request) {
+
+        if($request->input('test')) {
+            // override
+            $rx = json_decode(json_encode([
+                [
+                    "gcn_seqno" => "45190",
+                    "med_name_id" => "18604",
+                    "medid" => "234539",
+                    "routed_dosage_form_med_id" => "95130",
+                    "routed_med_id" => "19876",
+                    "rx" => "Zyprexa Zydis",
+                ],
+                [
+                    "gcn_seqno" => "49853",
+                    "med_name_id" => "26164",
+                    "medid" => "400058",
+                    "routed_dosage_form_med_id" => "36194",
+                    "routed_med_id" => "32562",
+                    "rx" => "Orfadin",
+                ],
+            ]));
+        }
+        else {
+            $input = json_decode($request->input('data'));
+            $rx = $input->rx;
+        }
+
+        if(count($rx) < 2) return "";
+
+        $leftIndex = 0;
+
+        $output = [];
+
+        for ($i=$leftIndex; $i<count($rx) - 1; $i++) {
+            for ($j=$leftIndex + 1; $j<count($rx); $j++) {
+                $output[] = $this->drugDrugInteractionSinglePair($rx[$i], $rx[$j]);
+            }
+        }
+
+        return implode("<br>", $output);
+    }
+
+    private function drugDrugInteractionSinglePair($_rx1, $_rx2) {
+
+        $output = [];
+
+        // get active ingredient DDI_CODEX values for drug 1 and 2
+        $rx1ActiveDdiCodex = $this->getActiveDdiCodexFromGcnSeqNo($_rx1->gcn_seqno);
+        $rx2ActiveDdiCodex = $this->getActiveDdiCodexFromGcnSeqNo($_rx2->gcn_seqno);
+        if(!$rx1ActiveDdiCodex || !$rx2ActiveDdiCodex || !count($rx1ActiveDdiCodex) || !count($rx2ActiveDdiCodex)) return "";
+
+//        dump($rx1_DDI_CODEX);
+//        dump($rx2_DDI_CODEX);
+
+        // get inactive ingredient DDI_CODEX values for drug 1 and 2
+        // to get this we need to first get the NDCs of the drugs
+        $rx1Ndc = $this->getNdcFromMedId($_rx1->medid);
+        $rx2Ndc = $this->getNdcFromMedId($_rx2->medid);
+
+//        dump($rx1Ndc);
+//        dump($rx2Ndc);
+
+        $rx1InactiveDdiCodex = $this->getInactiveDdiCodexFromNdc($rx1Ndc);
+        $rx2InactiveDdiCodex = $this->getInactiveDdiCodexFromNdc($rx2Ndc);
+        // if(!$rx1InactiveDdiCodex || !$rx2InactiveDdiCodex || !count($rx1InactiveDdiCodex) || !count($rx2InactiveDdiCodex)) return "";
+
+//        dump($rx1InactiveDdiCodex);
+//        dump($rx2InactiveDdiCodex);
+
+        // get ddi codex - monox pairs for drug 1 & 2
+        $rx1ActiveDdiCodexMonoxPairs = $this->getDdiCodexMonoxPairs($rx1ActiveDdiCodex);
+        $rx1InactiveDdiCodexMonoxPairs = $this->getDdiCodexMonoxPairs($rx1InactiveDdiCodex);
+        $rx2ActiveDdiCodexMonoxPairs = $this->getDdiCodexMonoxPairs($rx2ActiveDdiCodex);
+        $rx2InactiveDdiCodexMonoxPairs = $this->getDdiCodexMonoxPairs($rx2InactiveDdiCodex);
+
+//        dump($rx1ActiveDdiCodexMonoxPairs);
+//        dump($rx1InactiveDdiCodexMonoxPairs);
+//        dump($rx2ActiveDdiCodexMonoxPairs);
+//        dump($rx2InactiveDdiCodexMonoxPairs);
+
+        // compare 1-active to 2-active and 2-inactive
+        $activeCatches = [];
+        foreach ($rx1ActiveDdiCodexMonoxPairs as $compareLeft) {
+            foreach ($rx2ActiveDdiCodexMonoxPairs as $compareRight) {
+                if($compareLeft->ddi_monox == $compareRight->ddi_monox && $compareLeft->ddi_codex != $compareRight->ddi_codex) {
+                    $activeCatches[] = $compareLeft->ddi_codex;
+                }
+            }
+            foreach ($rx2InactiveDdiCodexMonoxPairs as $compareRight) {
+                if($compareLeft->ddi_monox == $compareRight->ddi_monox && $compareLeft->ddi_codex != $compareRight->ddi_codex) {
+                    $activeCatches[] = $compareLeft->ddi_codex;
+                }
+            }
+        }
+
+        // compare 1-inactive to 2-active and 2-inactive
+        $inactiveCatches = [];
+        foreach ($rx1InactiveDdiCodexMonoxPairs as $compareLeft) {
+            foreach ($rx2ActiveDdiCodexMonoxPairs as $compareRight) {
+                if($compareLeft->ddi_monox == $compareRight->ddi_monox && $compareLeft->ddi_codex != $compareRight->ddi_codex) {
+                    $inactiveCatches[] = $compareLeft->ddi_codex;
+                }
+            }
+            foreach ($rx2InactiveDdiCodexMonoxPairs as $compareRight) {
+                if($compareLeft->ddi_monox == $compareRight->ddi_monox && $compareLeft->ddi_codex != $compareRight->ddi_codex) {
+                    $inactiveCatches[] = $compareLeft->ddi_codex;
+                }
+            }
+        }
+
+        if(count($activeCatches)) {
+            $output[] = "<b>{$_rx2->rx}</b> interacts with one or more active ingredients in <b>{$_rx1->rx}</b>.";
+        }
+        if(count($inactiveCatches)) {
+            $output[] = "<b>{$_rx2->rx}</b> interacts with one or more inactive ingredients in <b>{$_rx1->rx}</b>.";
+        }
+
+        // TODO: find out and show the names of the actual ingredients causing interaction
+
+        return implode("<br>", $output);
+    }
+
+    private function getActiveDdiCodexFromGcnSeqNo($_gcnSeqNo) {
+        $ddiCodexArray = [];
+        $query = DB::connection('pgsql_fdb')->select("
+SELECT r1.ddi_codex
+FROM RADIMGC4_GCNSEQNO_LINK r1 
+WHERE r1.gcn_seqno = :gcnSeqNo
+            ",
+            ['gcnSeqNo' => $_gcnSeqNo]
+        );
+        if(count($query)) {
+            $ddiCodexArray = array_map(function($_x) {
+                return $_x->ddi_codex;
+            }, $query);
+        }
+        return $ddiCodexArray;
+    }
+
+    private function getNdcFromMedId($_medId) {
+        $ndcArray = [];
+        $query = DB::connection('pgsql_fdb')->select("
+select ndc from rmindc1_ndc_medid where medid = :medId
+            ",
+            ['medId' => $_medId]
+        );
+        if(count($query)) {
+            $ndcArray = array_map(function($_x) {
+                return $_x->ndc;
+            }, $query);
+        }
+        return $ndcArray;
+    }
+
+    private function getInactiveDdiCodexFromNdc($_ndc) {
+        $ddiCodexArray = [];
+        $query = DB::connection('pgsql_fdb')->select("
+SELECT distinct r1.ddi_codex
+FROM RDDIMIN0_NDC_INACTV_DDIM_LINK r1 
+WHERE r1.ddi_ndc IN (" . implode(',', array_map(function($_x) {return "'" . $_x . "'";}, $_ndc)) . ")
+            "
+        );
+        if(count($query)) {
+            $ddiCodexArray = array_map(function($_x) {
+                return $_x->ddi_codex;
+            }, $query);
+        }
+        return $ddiCodexArray;
+    }
+
+    private function getDdiCodexMonoxPairs($_ddiCodexArray) {
+        $ddiCodexMonoxPairsArray = [];
+        if(count($_ddiCodexArray)) {
+            $ddiCodexMonoxPairsArray = DB::connection('pgsql_fdb')->select("
+SELECT r1.ddi_codex, r1.ddi_monox
+FROM RADIMMA5_MSTR r1 
+WHERE r1.ddi_codex IN (" . implode(',', array_map(function($_x) {return "'" . $_x . "'";}, $_ddiCodexArray)) . ")
+            "
+            );
+        }
+        return $ddiCodexMonoxPairsArray;
+    }
+
     public function drugCoadministration(Request $request) {
         $gcnSeqnos = $request->input('gcn-seqnos') ? trim($request->input('gcn-seqnos')) : '';
         if (empty($gcnSeqnos)) return '';

+ 15 - 1
resources/views/app/fdb-pg/fdb-rx.blade.php

@@ -145,6 +145,7 @@
                         <div class="d-flex align-items-baseline mb-2">
                             <span class="font-size-14 font-weight-bold">Drug Drug Interaction Notes</span>
                         </div>
+                        <div class="drug-drug-interaction"></div>
                     </div>
                 </div>
                 <div class="col-4 pl-0">
@@ -330,7 +331,7 @@
                         },
                         showDrugAllergyNotes: function() {
                             $('.drug-allergies').html('');
-                            if(this.allergies && this.allergies.length) {
+                            if(this.allergies && this.allergies.length && this.rx && this.rx.length) {
                                 $.get('/fdb-drug-allergies', {
                                     data: JSON.stringify({
                                         allergies: this.allergies,
@@ -341,6 +342,18 @@
                                 });
                             }
                         },
+                        showDrugDrugInteractionNotes: function() {
+                            $('.drug-drug-interaction').html('');
+                            if(this.rx && this.rx.length > 1) {
+                                $.get('/fdb-drug-drug-interaction', {
+                                    data: JSON.stringify({
+                                        rx: this.rx
+                                    })
+                                }, _data => {
+                                    $('.drug-drug-interaction').html(_data);
+                                });
+                            }
+                        },
                         showDrugCoadministrationNotes: function() {
                             $('.drug-coadministration').html('');
                             if(this.rx && this.rx.length > 1) {
@@ -612,6 +625,7 @@
                             fillContraindications($(this).attr('fdb-suggest-group'), routedMedID);
 
                             vueApp.showDrugAllergyNotes();
+                            vueApp.showDrugDrugInteractionNotes();
                             vueApp.showDrugCoadministrationNotes();
                         });
 

+ 1 - 0
routes/web.php

@@ -335,6 +335,7 @@ Route::middleware('pro.auth')->group(function () {
     Route::get('/fdb-dx-suggest', 'FDBPGController@dxSuggest');
     Route::get('/fdb-allergy-suggest', 'FDBPGController@allergySuggest');
     Route::any('/fdb-drug-allergies', 'FDBPGController@drugAllergies');
+    Route::any('/fdb-drug-drug-interaction', 'FDBPGController@drugDrugInteraction');
     Route::any('/fdb-drug-coadministration', 'FDBPGController@drugCoadministration');
 });