'; html+=hits.map(function(h){ var s=SEV[h.sev]; var drug=h.x.kind==='Medication'?h.x:h.y, other=drug===h.x?h.y:h.x; return '
'+s.label+''+esc(other.name)+' + '+esc(drug.name)+'
'+ '
'+fill(h.what,h)+'
What to do: '+fill(h.todo,h)+'
'; }).join(''); if(clean.length){ html+='
No interaction listed in our chart'+(clean.length>1?' for these '+clean.length+' combinations':'')+':'+clean.map(function(c){return '- '+esc(c)+'
'}).join('')+'
This doesn\'t guarantee safety — check the full product information.
'; } if(drugPairs){ html+='
ⓘ '+drugPairs+' medication + medication combination'+(drugPairs>1?'s were':' was')+' skipped — this tool covers interactions with herbs, nutrients, supplements and foods only. Ask a pharmacist to check drug–drug interactions.
'; } if(!checked&&drugPairs){html='
Add a herb, nutrient, supplement or foodThis checker looks at medications against natural products and foods.
'+html.slice(html.indexOf('
'))} $res.innerHTML=html; lastText='Interaction check: '+items.map(function(i){return i.name}).join(', ')+'\n\n'+hits.map(function(h){ return '['+SEV[h.sev].label.toUpperCase()+'] '+h.x.name+' + '+h.y.name+'\n'+fillPlain(h.what,h)+'\nWhat to do: '+fillPlain(h.todo,h); }).join('\n\n')+(clean.length?'\n\nNo listed interaction: '+clean.join('; '):'')+'\n\nReference only — confirm with the prescriber or pharmacist.'; } function render(){renderChips();renderResults()} /* ================= EVENTS ================= */ $q.addEventListener('input',function(){active=-1;renderList()}); $q.addEventListener('focus',renderList); $q.addEventListener('keydown',function(e){ if($list.hidden&&e.key!=='Backspace')return; if(e.key==='ArrowDown'){e.preventDefault();active=Math.min(current.length-1,active+1);renderList();scrollActive()} else if(e.key==='ArrowUp'){e.preventDefault();active=Math.max(0,active-1);renderList();scrollActive()} else if(e.key==='Enter'){e.preventDefault();var r=current[active>-1?active:0];if(r)add(r.it.id,r.via)} else if(e.key==='Escape'){$list.hidden=true} else if(e.key==='Backspace'&&!$q.value&&sel.length){remove(sel[sel.length-1].id)} }); function scrollActive(){var el=$list.querySelector('.is-active');if(el)el.scrollIntoView({block:'nearest'})} $list.addEventListener('mousedown',function(e){e.preventDefault()}); $list.addEventListener('click',function(e){var b=e.target.closest('[data-i]');if(!b)return;var r=current[+b.dataset.i];if(r){add(r.it.id,r.via);$q.focus()}}); document.addEventListener('click',function(e){if(!e.target.closest('#nhc-dni .dni-searchwrap'))$list.hidden=true}); $chips.addEventListener('click',function(e){var b=e.target.closest('[data-rm]');if(b)remove(b.dataset.rm)}); $clear.addEventListener('click',function(){sel=[];render();$q.focus()}); $res.addEventListener('click',function(e){ var a=e.target.closest('[data-add]');if(a){add(a.dataset.add);return} var c=e.target.closest('[data-copy]'); if(c&&lastText){ var done=function(){c.textContent='Copied ✓';setTimeout(function(){c.textContent='Copy results'},1800)}; if(navigator.clipboard&&navigator.clipboard.writeText){navigator.clipboard.writeText(lastText).then(done,function(){fallbackCopy(lastText);done()})}else{fallbackCopy(lastText);done()} } }); function fallbackCopy(t){var ta=document.createElement('textarea');ta.value=t;ta.style.position='fixed';ta.style.opacity='0';document.body.appendChild(ta);ta.select();try{document.execCommand('copy')}catch(e){}document.body.removeChild(ta)} // Example combos: [item name, brand used] var EXAMPLES=[ {label:"Zoloft + St John's wort + 5-HTP",items:[["Sertraline","Zoloft"],["St John's wort"],["5-HTP"]]}, {label:"Warfarin + fish oil + turmeric + kale",items:[["Warfarin","Coumadin"],["Fish oil / omega-3"],["Turmeric / curcumin"],["Leafy greens (vitamin K foods)"]]}, {label:"Eltroxin + iron + coffee",items:[["Levothyroxine","Eltroxin"],["Iron"],["Coffee"]]}, {label:"Diabex + berberine + alcohol",items:[["Metformin","Diabex"],["Berberine"],["Alcohol"]]}, {label:"Doryx + magnesium + dairy",items:[["Doxycycline","Doryx"],["Magnesium"],["Milk & dairy"]]} ]; EXAMPLES.forEach(function(ex){ var b=document.createElement('button');b.type='button';b.className='dni-ex';b.textContent=ex.label; b.addEventListener('click',function(){ sel=[];ex.items.forEach(function(p){var it=ITEMS.filter(function(i){return i.name===p[0]})[0];if(it)sel.push({id:it.id,via:p[1]||null})});render(); }); $ex.appendChild(b); }); render(); })();