|
@@ -120,8 +120,185 @@ if(!function_exists('drug_allergy_info')) {
|
|
|
if(!function_exists('drug_drug_interaction_info')) {
|
|
|
function drug_drug_interaction_info($_drugs) {
|
|
|
|
|
|
+ if(count($_drugs) < 2) return "";
|
|
|
+
|
|
|
+ $leftIndex = 0;
|
|
|
+
|
|
|
+ $output = [];
|
|
|
+
|
|
|
+ for ($i=$leftIndex; $i<count($_drugs) - 1; $i++) {
|
|
|
+ for ($j=$i + 1; $j<count($_drugs); $j++) {
|
|
|
+ $output[] = drugDrugInteractionSinglePair($_drugs[$i], $_drugs[$j]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ $output = array_filter($output, function($_x) {
|
|
|
+ return !!$_x;
|
|
|
+ });
|
|
|
+
|
|
|
+ return implode("<br>", $output);
|
|
|
}
|
|
|
}
|
|
|
+if(!function_exists('drugDrugInteractionSinglePair')) {
|
|
|
+ function drugDrugInteractionSinglePair($_rx1, $_rx2)
|
|
|
+ {
|
|
|
+
|
|
|
+ $output = [];
|
|
|
+
|
|
|
+ // get active ingredient DDI_CODEX values for drug 1 and 2
|
|
|
+ $rx1ActiveDdiCodex = getActiveDdiCodexFromGcnSeqNo($_rx1->data->gcnSeqno);
|
|
|
+ $rx2ActiveDdiCodex = getActiveDdiCodexFromGcnSeqNo($_rx2->data->gcnSeqno);
|
|
|
+ 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 = getNdcFromMedId($_rx1->data->medId);
|
|
|
+ $rx2Ndc = getNdcFromMedId($_rx2->data->medId);
|
|
|
+
|
|
|
+ // dump($rx1Ndc);
|
|
|
+ // dump($rx2Ndc);
|
|
|
+
|
|
|
+ $rx1InactiveDdiCodex = getInactiveDdiCodexFromNdc($rx1Ndc);
|
|
|
+ $rx2InactiveDdiCodex = getInactiveDdiCodexFromNdc($rx2Ndc);
|
|
|
+ // if(!$rx1InactiveDdiCodex || !$rx2InactiveDdiCodex || !count($rx1InactiveDdiCodex) || !count($rx2InactiveDdiCodex)) return "";
|
|
|
+
|
|
|
+ // dump($rx1InactiveDdiCodex);
|
|
|
+ // dump($rx2InactiveDdiCodex);
|
|
|
+
|
|
|
+ // get ddi codex - monox pairs for drug 1 & 2
|
|
|
+ $rx1ActiveDdiCodexMonoxPairs = getDdiCodexMonoxPairs($rx1ActiveDdiCodex);
|
|
|
+ $rx1InactiveDdiCodexMonoxPairs = getDdiCodexMonoxPairs($rx1InactiveDdiCodex);
|
|
|
+ $rx2ActiveDdiCodexMonoxPairs = getDdiCodexMonoxPairs($rx2ActiveDdiCodex);
|
|
|
+ $rx2InactiveDdiCodexMonoxPairs = 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->data->name}</b> interacts with one or more active ingredients in <b>{$_rx1->data->name}</b>.";
|
|
|
+ }
|
|
|
+ if (count($inactiveCatches)) {
|
|
|
+ $output[] = "<b>{$_rx2->data->name}</b> interacts with one or more inactive ingredients in <b>{$_rx1->data->name}</b>.";
|
|
|
+ }
|
|
|
+
|
|
|
+ // TODO: find out and show the names of the actual ingredients causing interaction
|
|
|
+
|
|
|
+ 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('getActiveDdiCodexFromGcnSeqNo')) {
|
|
|
+ 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;
|
|
|
+ }
|
|
|
+}
|
|
|
+if(!function_exists('getNdcFromMedId')) {
|
|
|
+ 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;
|
|
|
+ }
|
|
|
+}
|
|
|
+if(!function_exists('getInactiveDdiCodexFromNdc')) {
|
|
|
+ function getInactiveDdiCodexFromNdc($_ndc)
|
|
|
+ {
|
|
|
+ $ddiCodexArray = [];
|
|
|
+ if(!count($_ndc)) return $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;
|
|
|
+ }
|
|
|
+}
|
|
|
+if(!function_exists('getDdiCodexMonoxPairs')) {
|
|
|
+ function getDdiCodexMonoxPairs($_ddiCodexArray)
|
|
|
+ {
|
|
|
+ $ddiCodexMonoxPairsArray = [];
|
|
|
+ if(!count($_ddiCodexArray)) return $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;
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
|
|
|
if(!function_exists('duplicate_therapy_info')) {
|
|
|
function duplicate_therapy_info($_drugs) {
|
|
@@ -184,6 +361,8 @@ if (!function_exists('compareDPTs')) {
|
|
|
if(!function_exists('coadministration_info')) {
|
|
|
function coadministration_info($_drugs) {
|
|
|
|
|
|
+ if(count($_drugs) < 2) return "";
|
|
|
+
|
|
|
// collect gcn-seq-nos
|
|
|
$gcnSeqNos = [];
|
|
|
$rxMap = [];
|