fdb.php 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561
  1. <?php
  2. use Illuminate\Http\Request;
  3. use Illuminate\Support\Facades\DB;
  4. if(!function_exists('side_effects_info')) {
  5. function side_effects_info($_drugs) {
  6. $result = [];
  7. // collect gcn-seq-nos
  8. $gcnSeqNos = [];
  9. $rxMap = [];
  10. foreach ($_drugs as $drug) {
  11. if(@$drug->data && $drug->data->gcnSeqno) {
  12. $gcnSeqNos[] = $drug->data->gcnSeqno;
  13. $rxMap[$drug->data->gcnSeqno] = $drug->data->name;
  14. }
  15. }
  16. if(!count($gcnSeqNos)) return $result;
  17. $gcnSeqNos = implode(',', array_map(function($_x) {
  18. return "'" . $_x . "'";
  19. }, $gcnSeqNos));
  20. $sides = DB::connection('pgsql_fdb')->select("
  21. SELECT r1.gcn_seqno, r1.side, sm.side_freq, sm.side_sev, sm.dxid, dx.dxid_desc56
  22. FROM rsidegc0_gcnseqno_link r1
  23. JOIN rsidema3_mstr sm ON r1.side = sm.side
  24. JOIN rfmldx0_dxid dx ON sm.dxid = dx.dxid
  25. WHERE r1.gcn_seqno IN (" . $gcnSeqNos . ")
  26. ORDER BY r1.gcn_seqno, sm.side_sev DESC, sm.side_freq ASC
  27. "
  28. );
  29. $seMap = [];
  30. foreach ($sides as $se) {
  31. if(!isset($seMap[$rxMap[$se->gcn_seqno]])) {
  32. $seMap[$rxMap[$se->gcn_seqno]] = [];
  33. }
  34. $seMap[$rxMap[$se->gcn_seqno]][] = [
  35. "gcn_seqno" => $se->gcn_seqno,
  36. "side_freq" => $se->side_freq,
  37. "side_sev" => $se->side_sev,
  38. "dxid_desc56" => $se->dxid_desc56,
  39. ];
  40. }
  41. $result = $seMap;
  42. return $result;
  43. }
  44. }
  45. if(!function_exists('precautions_info')) {
  46. function precautions_info($_drugs) {
  47. }
  48. }
  49. if(!function_exists('contraindications_info')) {
  50. function contraindications_info($_drugs) {
  51. $result = [];
  52. // collect routed med ids
  53. $routedMedIds = [];
  54. $rxMap = [];
  55. foreach ($_drugs as $drug) {
  56. if(@$drug->data && $drug->data->routedMedId) {
  57. $routedMedIds[] = $drug->data->routedMedId;
  58. $rxMap[$drug->data->routedMedId] = $drug->data->name;
  59. }
  60. }
  61. if(!count($routedMedIds)) return $result;
  62. $routedMedIds = implode(',', array_map(function($_x) {
  63. return "'" . $_x . "'";
  64. }, $routedMedIds));
  65. $contraindications = DB::connection('pgsql_fdb')->select("
  66. SELECT r1.routed_med_id, r1.ddxcn, r2.dxid, r2.ddxcn_sl, r3.dxid_desc56
  67. FROM rddcmrm0_routed_med_link r1
  68. JOIN rddcmma1_contra_mstr r2 ON r1.ddxcn = r2.ddxcn
  69. JOIN rfmldx0_dxid r3 ON r2.dxid = r3.dxid
  70. WHERE r1.routed_med_id IN (" . $routedMedIds . ")
  71. ORDER BY r1.routed_med_id, r3.dxid_desc56, r2.ddxcn_sl
  72. "
  73. );
  74. $ciMap = [];
  75. foreach ($contraindications as $ci) {
  76. if(!isset($ciMap[$rxMap[$ci->routed_med_id]])) {
  77. $ciMap[$rxMap[$ci->routed_med_id]] = [];
  78. }
  79. $ciMap[$rxMap[$ci->routed_med_id]][] = [
  80. "dxid_desc56" => $ci->dxid_desc56,
  81. ];
  82. }
  83. $result = $ciMap;
  84. return $result;
  85. }
  86. }
  87. if(!function_exists('drug_allergy_info')) {
  88. function drug_allergy_info($_drugs, $_allergies) {
  89. $output = [];
  90. /*
  91. for each allergy
  92. if damConceptIdType = 1 // allergen-group-id
  93. // https://docs.fdbhealth.com/display/MKDOCUS/Screening+an+NDC+for+a+DAM_ALRGN_GRP+Allergen+-+Illustration+of+Scenario+C
  94. ...
  95. elseif damConceptIdType = 2 // medication-name-id
  96. // https://docs.fdbhealth.com/display/MKDOCUS/Screening+an+NDC+for+a+MED_NAME_ID+Allergen+-+Illustration+of+Scenario+B
  97. ...
  98. elseif damConceptIdType = 6 // base-ingredient-id
  99. // https://docs.fdbhealth.com/display/MKDOCUS/Screening+an+NDC+for+an+Ingredient+Allergen+-+Illustration+of+Scenario+A
  100. ...
  101. endif
  102. endfor
  103. */
  104. foreach ($_allergies as $allergy) {
  105. foreach ($_drugs as $rxItem) {
  106. if($allergy->data->damConceptIdType == 6) { // ingredient
  107. if (drugAllergyIngredientAllergenVsSingleRx($allergy, $rxItem)) {
  108. $output[] = "<b>{$rxItem->data->name}</b> can cause allergic reactions since the patient is allergic to <b>{$allergy->data->name}</b>.";
  109. }
  110. }
  111. else if($allergy->data->damConceptIdType == 2) { // medication
  112. if (drugAllergyMedicationAllergenVsSingleRx($allergy, $rxItem)) {
  113. $output[] = "<b>{$rxItem->data->name}</b> can cause allergic reactions since the patient is allergic to <b>{$allergy->data->name}</b>.";
  114. }
  115. }
  116. else if($allergy->data->damConceptIdType == 1) { // allergen group
  117. if (drugAllergyGroupAllergenVsSingleRx($allergy, $rxItem)) {
  118. $output[] = "<b>{$rxItem->data->name}</b> can cause allergic reactions since the patient is allergic to <b>{$allergy->data->name}</b>.";
  119. }
  120. }
  121. }
  122. }
  123. return implode("<br>", $output);
  124. }
  125. }
  126. if(!function_exists('drugAllergyIngredientAllergenVsSingleRx')) {
  127. function drugAllergyIngredientAllergenVsSingleRx($_allergen, $_rx)
  128. {
  129. $matches = DB::connection('pgsql_fdb')->select("
  130. (
  131. -- ingredients from medication
  132. SELECT R1.related_hic_seqn as hic_seqn, R2.hic_desc
  133. FROM RHICHCR0_HIC_HIC_LINK R1
  134. JOIN RHICD5_HIC_DESC R2 ON R1.related_hic_seqn = R2.hic_seqn
  135. WHERE R1.hic_seqn IN (
  136. SELECT S2.dam_alrgn_hic_seqn
  137. FROM RMEDMHL0_MED_HICLSEQNO_LINK S1
  138. JOIN RDAMHHA0_HIC_HICL_ALG_LINK S2 ON S1.hicl_seqno = S2.hicl_seqno
  139. WHERE S1.med_concept_id = :medid
  140. AND S1.med_concept_id_typ = 3
  141. )
  142. )
  143. INTERSECT
  144. (
  145. -- all ingredients directly and related from allergens
  146. (
  147. SELECT R1.related_hic_seqn as hic_seqn, R2.hic_desc
  148. FROM RHICHCR0_HIC_HIC_LINK R1
  149. JOIN RHICD5_HIC_DESC R2 ON R1.related_hic_seqn = R2.hic_seqn
  150. WHERE R1.hic_seqn = :allergenConceptID
  151. )
  152. UNION
  153. -- all ingredients via related dam allergen groups
  154. (
  155. SELECT r3.hic_seqn, r4.hic_desc
  156. FROM RDAMGHC0_HIC_ALRGN_GRP_LINK R1
  157. JOIN rdamagd1_alrgn_grp_desc R2 on R1.dam_alrgn_grp = R2.dam_alrgn_grp
  158. JOIN RDAMGHC0_HIC_ALRGN_GRP_LINK R3 on R1.dam_alrgn_grp = R3.dam_alrgn_grp
  159. JOIN RHICD5_HIC_DESC R4 on r3.hic_seqn = r4.hic_seqn
  160. WHERE R1.hic_seqn = :allergenConceptID
  161. AND R2.dam_alrgn_grp_status_cd = 0
  162. ORDER BY r3.hic_seqn
  163. )
  164. )
  165. ",
  166. ['medid' => $_rx->data->medId, 'allergenConceptID' => $_allergen->data->damConceptId]
  167. );
  168. return !!count($matches);
  169. }
  170. }
  171. if(!function_exists('drugAllergyMedicationAllergenVsSingleRx')) {
  172. function drugAllergyMedicationAllergenVsSingleRx($_allergen, $_rx)
  173. {
  174. $matches = DB::connection('pgsql_fdb')->select("
  175. (
  176. -- ingredients from medication
  177. SELECT R1.related_hic_seqn as hic_seqn
  178. FROM RHICHCR0_HIC_HIC_LINK R1
  179. JOIN RHICD5_HIC_DESC R2 ON R1.related_hic_seqn = R2.hic_seqn
  180. WHERE R1.hic_seqn IN (
  181. SELECT S2.dam_alrgn_hic_seqn
  182. FROM RMEDMHL0_MED_HICLSEQNO_LINK S1
  183. JOIN RDAMHHA0_HIC_HICL_ALG_LINK S2 ON S1.hicl_seqno = S2.hicl_seqno
  184. WHERE S1.med_concept_id = :medid
  185. AND S1.med_concept_id_typ = 3
  186. )
  187. )
  188. INTERSECT
  189. (
  190. -- all ingredients directly and related from allergens
  191. SELECT R1.dam_alrgn_hic_seqn as hic_seqn
  192. FROM RDAMHHA0_HIC_HICL_ALG_LINK R1
  193. WHERE R1.hicl_seqno IN (
  194. SELECT R1.hicl_seqno
  195. FROM RMEDMHL0_MED_HICLSEQNO_LINK R1
  196. WHERE R1.med_concept_id_typ = 1
  197. AND R1.med_concept_id = :allergenConceptID
  198. AND MED_CONCEPT_HICL_SRC_CD = 0
  199. )
  200. )
  201. ",
  202. ['medid' => $_rx->data->medId, 'allergenConceptID' => $_allergen->data->damConceptId]
  203. );
  204. return !!count($matches);
  205. }
  206. }
  207. if(!function_exists('drugAllergyGroupAllergenVsSingleRx')) {
  208. function drugAllergyGroupAllergenVsSingleRx($_allergen, $_rx)
  209. {
  210. $matches = DB::connection('pgsql_fdb')->select("
  211. (
  212. -- ingredients from medication
  213. SELECT R1.related_hic_seqn as hic_seqn
  214. FROM RHICHCR0_HIC_HIC_LINK R1
  215. JOIN RHICD5_HIC_DESC R2 ON R1.related_hic_seqn = R2.hic_seqn
  216. WHERE R1.hic_seqn IN (
  217. SELECT S2.dam_alrgn_hic_seqn
  218. FROM RMEDMHL0_MED_HICLSEQNO_LINK S1
  219. JOIN RDAMHHA0_HIC_HICL_ALG_LINK S2 ON S1.hicl_seqno = S2.hicl_seqno
  220. WHERE S1.med_concept_id = :medid
  221. AND S1.med_concept_id_typ = 3
  222. )
  223. )
  224. INTERSECT
  225. (
  226. -- ingredients from medication allergen
  227. (
  228. SELECT R1.hic_seqn as hic_seqn
  229. FROM RDAMGHC0_HIC_ALRGN_GRP_LINK R1
  230. WHERE R1.DAM_ALRGN_GRP = :allergenConceptID
  231. )
  232. UNION
  233. (
  234. SELECT distinct s1.hic_seqn
  235. FROM RDAMXHC0_HIC_ALRGN_XSENSE_LINK S1
  236. WHERE S1.dam_alrgn_xsense IN (
  237. SELECT R1.dam_alrgn_xsense
  238. FROM RDAMGX0_ALRGN_GRP_XSENSE_LINK R1
  239. JOIN RDAMCSD1_XSENSIT_ALLERGY_DESC R2 on R1.dam_alrgn_xsense = R2.dam_alrgn_xsense
  240. WHERE R1.dam_alrgn_grp = :allergenConceptID
  241. AND R2.dam_alrgn_xsense_status_cd = 0
  242. )
  243. )
  244. )
  245. ",
  246. ['medid' => $_rx->data->medId, 'allergenConceptID' => $_allergen->data->damConceptId]
  247. );
  248. return !!count($matches);
  249. }
  250. }
  251. if(!function_exists('drug_drug_interaction_info')) {
  252. function drug_drug_interaction_info($_drugs) {
  253. if(count($_drugs) < 2) return "";
  254. $leftIndex = 0;
  255. $output = [];
  256. for ($i=$leftIndex; $i<count($_drugs) - 1; $i++) {
  257. for ($j=$i + 1; $j<count($_drugs); $j++) {
  258. $output[] = drugDrugInteractionSinglePair($_drugs[$i], $_drugs[$j]);
  259. }
  260. }
  261. $output = array_filter($output, function($_x) {
  262. return !!$_x;
  263. });
  264. return implode("<br>", $output);
  265. }
  266. }
  267. if(!function_exists('drugDrugInteractionSinglePair')) {
  268. function drugDrugInteractionSinglePair($_rx1, $_rx2)
  269. {
  270. $output = [];
  271. // get active ingredient DDI_CODEX values for drug 1 and 2
  272. $rx1ActiveDdiCodex = getActiveDdiCodexFromGcnSeqNo($_rx1->data->gcnSeqno);
  273. $rx2ActiveDdiCodex = getActiveDdiCodexFromGcnSeqNo($_rx2->data->gcnSeqno);
  274. if (!$rx1ActiveDdiCodex || !$rx2ActiveDdiCodex || !count($rx1ActiveDdiCodex) || !count($rx2ActiveDdiCodex)) return "";
  275. // dump($rx1_DDI_CODEX);
  276. // dump($rx2_DDI_CODEX);
  277. // get inactive ingredient DDI_CODEX values for drug 1 and 2
  278. // to get this we need to first get the NDCs of the drugs
  279. $rx1Ndc = getNdcFromMedId($_rx1->data->medId);
  280. $rx2Ndc = getNdcFromMedId($_rx2->data->medId);
  281. // dump($rx1Ndc);
  282. // dump($rx2Ndc);
  283. $rx1InactiveDdiCodex = getInactiveDdiCodexFromNdc($rx1Ndc);
  284. $rx2InactiveDdiCodex = getInactiveDdiCodexFromNdc($rx2Ndc);
  285. // if(!$rx1InactiveDdiCodex || !$rx2InactiveDdiCodex || !count($rx1InactiveDdiCodex) || !count($rx2InactiveDdiCodex)) return "";
  286. // dump($rx1InactiveDdiCodex);
  287. // dump($rx2InactiveDdiCodex);
  288. // get ddi codex - monox pairs for drug 1 & 2
  289. $rx1ActiveDdiCodexMonoxPairs = getDdiCodexMonoxPairs($rx1ActiveDdiCodex);
  290. $rx1InactiveDdiCodexMonoxPairs = getDdiCodexMonoxPairs($rx1InactiveDdiCodex);
  291. $rx2ActiveDdiCodexMonoxPairs = getDdiCodexMonoxPairs($rx2ActiveDdiCodex);
  292. $rx2InactiveDdiCodexMonoxPairs = getDdiCodexMonoxPairs($rx2InactiveDdiCodex);
  293. // dump($rx1ActiveDdiCodexMonoxPairs);
  294. // dump($rx1InactiveDdiCodexMonoxPairs);
  295. // dump($rx2ActiveDdiCodexMonoxPairs);
  296. // dump($rx2InactiveDdiCodexMonoxPairs);
  297. // compare 1-active to 2-active and 2-inactive
  298. $activeCatches = [];
  299. foreach ($rx1ActiveDdiCodexMonoxPairs as $compareLeft) {
  300. foreach ($rx2ActiveDdiCodexMonoxPairs as $compareRight) {
  301. if ($compareLeft->ddi_monox == $compareRight->ddi_monox && $compareLeft->ddi_codex != $compareRight->ddi_codex) {
  302. $activeCatches[] = $compareLeft->ddi_codex;
  303. }
  304. }
  305. foreach ($rx2InactiveDdiCodexMonoxPairs as $compareRight) {
  306. if ($compareLeft->ddi_monox == $compareRight->ddi_monox && $compareLeft->ddi_codex != $compareRight->ddi_codex) {
  307. $activeCatches[] = $compareLeft->ddi_codex;
  308. }
  309. }
  310. }
  311. // compare 1-inactive to 2-active and 2-inactive
  312. $inactiveCatches = [];
  313. foreach ($rx1InactiveDdiCodexMonoxPairs as $compareLeft) {
  314. foreach ($rx2ActiveDdiCodexMonoxPairs as $compareRight) {
  315. if ($compareLeft->ddi_monox == $compareRight->ddi_monox && $compareLeft->ddi_codex != $compareRight->ddi_codex) {
  316. $inactiveCatches[] = $compareLeft->ddi_codex;
  317. }
  318. }
  319. foreach ($rx2InactiveDdiCodexMonoxPairs as $compareRight) {
  320. if ($compareLeft->ddi_monox == $compareRight->ddi_monox && $compareLeft->ddi_codex != $compareRight->ddi_codex) {
  321. $inactiveCatches[] = $compareLeft->ddi_codex;
  322. }
  323. }
  324. }
  325. if (count($activeCatches)) {
  326. $output[] = "<b>{$_rx2->data->name}</b> interacts with one or more active ingredients in <b>{$_rx1->data->name}</b>.";
  327. }
  328. if (count($inactiveCatches)) {
  329. $output[] = "<b>{$_rx2->data->name}</b> interacts with one or more inactive ingredients in <b>{$_rx1->data->name}</b>.";
  330. }
  331. // TODO: find out and show the names of the actual ingredients causing interaction
  332. return implode("<br>", $output);
  333. }
  334. }
  335. if(!function_exists('getActiveDdiCodexFromGcnSeqNo')) {
  336. function getActiveDdiCodexFromGcnSeqNo($_gcnSeqNo)
  337. {
  338. $ddiCodexArray = [];
  339. $query = DB::connection('pgsql_fdb')->select("
  340. SELECT r1.ddi_codex
  341. FROM RADIMGC4_GCNSEQNO_LINK r1
  342. WHERE r1.gcn_seqno = :gcnSeqNo
  343. ",
  344. ['gcnSeqNo' => $_gcnSeqNo]
  345. );
  346. if (count($query)) {
  347. $ddiCodexArray = array_map(function ($_x) {
  348. return $_x->ddi_codex;
  349. }, $query);
  350. }
  351. return $ddiCodexArray;
  352. }
  353. }
  354. if(!function_exists('getNdcFromMedId')) {
  355. function getNdcFromMedId($_medId)
  356. {
  357. $ndcArray = [];
  358. $query = DB::connection('pgsql_fdb')->select("
  359. select ndc from rmindc1_ndc_medid where medid = :medId
  360. ",
  361. ['medId' => $_medId]
  362. );
  363. if (count($query)) {
  364. $ndcArray = array_map(function ($_x) {
  365. return $_x->ndc;
  366. }, $query);
  367. }
  368. return $ndcArray;
  369. }
  370. }
  371. if(!function_exists('getInactiveDdiCodexFromNdc')) {
  372. function getInactiveDdiCodexFromNdc($_ndc)
  373. {
  374. $ddiCodexArray = [];
  375. if(!count($_ndc)) return $ddiCodexArray;
  376. $query = DB::connection('pgsql_fdb')->select("
  377. SELECT distinct r1.ddi_codex
  378. FROM RDDIMIN0_NDC_INACTV_DDIM_LINK r1
  379. WHERE r1.ddi_ndc IN (" . implode(',', array_map(function ($_x) {
  380. return "'" . $_x . "'";
  381. }, $_ndc)) . ")
  382. "
  383. );
  384. if (count($query)) {
  385. $ddiCodexArray = array_map(function ($_x) {
  386. return $_x->ddi_codex;
  387. }, $query);
  388. }
  389. return $ddiCodexArray;
  390. }
  391. }
  392. if(!function_exists('getDdiCodexMonoxPairs')) {
  393. function getDdiCodexMonoxPairs($_ddiCodexArray)
  394. {
  395. $ddiCodexMonoxPairsArray = [];
  396. if(!count($_ddiCodexArray)) return $ddiCodexMonoxPairsArray;
  397. if (count($_ddiCodexArray)) {
  398. $ddiCodexMonoxPairsArray = DB::connection('pgsql_fdb')->select("
  399. SELECT r1.ddi_codex, r1.ddi_monox
  400. FROM RADIMMA5_MSTR r1
  401. WHERE r1.ddi_codex IN (" . implode(',', array_map(function ($_x) {
  402. return "'" . $_x . "'";
  403. }, $_ddiCodexArray)) . ")
  404. "
  405. );
  406. }
  407. return $ddiCodexMonoxPairsArray;
  408. }
  409. }
  410. if(!function_exists('duplicate_therapy_info')) {
  411. function duplicate_therapy_info($_drugs) {
  412. $dptClasses = [];
  413. foreach ($_drugs as $drug) {
  414. $drug->dpt = getDptClassFromGcnSeqNo($drug->data->gcnSeqno);
  415. }
  416. $leftIndex = 0;
  417. $matches = [];
  418. for ($i = $leftIndex; $i < count($_drugs) - 1; $i++) {
  419. for ($j = $i + 1; $j < count($_drugs); $j++) {
  420. $compareResult = compareDPTs($_drugs[$i]->dpt, $_drugs[$j]->dpt);
  421. foreach ($compareResult as $c) {
  422. $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})";
  423. }
  424. }
  425. }
  426. if(!count($matches)) return '';
  427. return "<ol class='pl-0 ml-3 mb-0'>" . implode("", array_map(function ($_x) {
  428. return "<li class='mb-1'>" . $_x . "</li>";
  429. }, $matches)) . "</ol>";
  430. }
  431. }
  432. if (!function_exists('getDptClassFromGcnSeqNo')) {
  433. function getDptClassFromGcnSeqNo($_gcnSeqNo)
  434. {
  435. return DB::connection('pgsql_fdb')->select("
  436. SELECT distinct r1.dpt_class_id, r2.dpt_allowance, r2.dpt_class_desc
  437. FROM RDPTGC0_GCNSEQNO_LINK r1
  438. JOIN RDPTCL0_CLASS_ID r2 on r1.dpt_class_id = r2.dpt_class_id
  439. WHERE r1.gcn_seqno = :gcnSeqNo
  440. ",
  441. ['gcnSeqNo' => $_gcnSeqNo]
  442. );
  443. }
  444. }
  445. if (!function_exists('compareDPTs')) {
  446. function compareDPTs($_dptArray1, $_dptArray2)
  447. {
  448. $output = [];
  449. for ($i = 0; $i < count($_dptArray1); $i++) {
  450. for ($j = 0; $j < count($_dptArray2); $j++) {
  451. if ($_dptArray1[$i]->dpt_class_id == $_dptArray2[$j]->dpt_class_id) {
  452. $output[] = json_decode(json_encode([
  453. "dpt_allowance" => $_dptArray1[$i]->dpt_allowance,
  454. "dpt_class_desc" => $_dptArray1[$i]->dpt_class_desc
  455. ]));
  456. }
  457. }
  458. }
  459. return $output;
  460. }
  461. }
  462. if(!function_exists('coadministration_info')) {
  463. function coadministration_info($_drugs) {
  464. if(count($_drugs) < 2) return "";
  465. // collect gcn-seq-nos
  466. $gcnSeqNos = [];
  467. $rxMap = [];
  468. foreach ($_drugs as $drug) {
  469. if(@$drug->data && $drug->data->gcnSeqno) {
  470. $gcnSeqNos[] = $drug->data->gcnSeqno;
  471. $rxMap[$drug->data->gcnSeqno] = $drug->data->name;
  472. }
  473. }
  474. if(!count($gcnSeqNos)) return $result;
  475. $gcnSeqNos = implode(',', array_map(function($_x) {
  476. return "'" . $_x . "'";
  477. }, $gcnSeqNos));
  478. $coadministration = DB::connection('pgsql_fdb')->select("
  479. SELECT distinct r1.coadmin_dosing_text
  480. FROM radige0_ddi_gcnseqno_except r1
  481. WHERE r1.side_a_gcn_seqno in ($gcnSeqNos) AND r1.side_b_gcn_seqno in ($gcnSeqNos)
  482. "
  483. );
  484. if(!$coadministration || !count($coadministration)) return '';
  485. return "<ol class='pl-0 ml-3 mb-0'>" . implode("", array_map(function ($_x) {
  486. return "<li class='mb-1'>" . $_x->coadmin_dosing_text . "</li>";
  487. }, $coadministration)) . "</ol>";
  488. return $coadministration;
  489. }
  490. }