// ==UserScript==
// @name Interactions
// @namespace Phcscript
// @include *oscarRx/choosePatient.do*
// @description Shows drug interactions
// @version 2.2
// @grant none
// ==/UserScript==
//=====Get Parameters============
var params = {};
if (location.search) {
var parts = location.search.substring(1).split('&');
for (var i = 0; i < parts.length; i++) {
var nv = parts[i].split('=');
if (!nv[0]) continue;
params[nv[0]] = nv[1] || true;
}
}
var URL = window.location.toString()
//alert(URL)
//========Get Path============
var elements = (window.location.pathname.split('/', 2))
firstElement = (elements.slice(1))
//alert(firstElement)
vPath = ("https://" + location.host + "/" + firstElement + "/")
//alert(vPath)
if (URL.indexOf("oscarRx/choosePatient") > -1) {
//========Buttons============
var input1 = document.createElement("input");
input1.type = "button";
input1.value = "Drug Interactions";
input1.onclick = ButtonFunction1;
input1.setAttribute("style", "font-size:12px;position:fixed;top:30px;right:0px;color:white;background-color:#007bff;border-color:#007bff;border-radius: 4px;padding: 3px !important;");
document.body.appendChild(input1);
function ButtonFunction1() {
let alldrugs = assembleRxDrugs();
console.log("All drugs:"+alldrugs);
getInteractions(alldrugs);
}
function assembleRxDrugs() {
//iterate through the generic names and assemble the array
var druglist = []
var atag = document.getElementsByTagName('a');
for (var i = 0; i < atag.length; i++) {
if ((atag[i].innerText.indexOf("Ingredient") > -1) || atag[i].outerHTML.indexOf("query=") > -1) {
y = atag[i].innerText.replace(/ /g, ' ').trim();
if (atag[i].innerText.indexOf("Ingredient") > -1) {
y = atag[i].innerText.substring(12)
}
y = y.split("/");
for (j = 0; j < y.length; j++) {
y[j] = y[j].trim();
//take the first word or the first word in each word/word combo
newwordA = y[j].match(/(?:^|(?:\.\s))(\w+)/);
if (newwordA){
console.log(newwordA[0]);
druglist.push(newwordA[0]);
}
}
}
}
console.log("Searching the following drugs for interactions:"+druglist)
return druglist;
}
async function getInteractions(drugs) {
let drugsStr = drugs.toString().replace(/,/gi,', ');
if (drugs.length < 1) { alert("You must have some Rx set to perscribe prior to checking"); return; }
let alertlist= ""+ drugsStr +" interactions are:
";
getRxcui(drugs).then(
async function(rxcuis) {
const response = await fetch('https://rxnav.nlm.nih.gov/REST/interaction/list?rxcuis='+rxcuis);
const str = await response.text();
parser = new DOMParser();
xmlDoc = parser.parseFromString(str, 'text/xml');
y = xmlDoc.getElementsByTagName("description").length
for (x = 0; x < y; x++) {
z = (xmlDoc.getElementsByTagName("description")[x].childNodes[0].nodeValue);
alertlist = alertlist + "
" + z } if (y <1 ) { alertlist="No interactions found with " + drugsStr +"
Use this service with discretion! This product uses publicly available data from the U.S. National Library of Medicine (NLM), National Institutes of Health, Department of Health and Human Services; NLM is not responsible for the product and does not endorse or recommend this or any other product"; } //append document.getElementById('interactionsRxMyD').innerHTML += '
' } ) } async function getRxcui(names) { // we have to get RxCUI let responses = ""; for (let name of names){ const response = await fetch('https://rxnav.nlm.nih.gov/REST/rxcui.json?name='+name); const json = await response.json(); console.log(name+json.idGroup.rxnormId); if (json.hasOwnProperty('idGroup')){ if (json.idGroup.hasOwnProperty('rxnormId')){ responses += json.idGroup.rxnormId ; responses += "+"; } } } console.log("Rxcui found:"+responses); return responses; } }