Click here to Skip to main content
15,501,747 members
Articles / Web Development / ASP.NET
Posted 7 May 2013

Tagged as


21 bookmarked

Real time detection of medication interaction using VB.NET

, ,
Rate me:
Please Sign up or sign in to vote.
4.94/5 (31 votes)
7 May 2013CPOL5 min read
Documented mortalities and morbidities related to drug interactions were addressed years ago in clinical informatics. This application uses VB.NET to detect and warn users about interactions. It has the advantage of "Localization", customization, and the ability to integrate with open-source CPOE.


Drug–drug interaction (DDI) is defined as a change in the clinical effect of a given drug because of the interference of another drug. Drug Interactions can occur between drugs, between drugs and food, herbs or supplements. They can be classified into three types: pharmacokinetic, pharmacodynamic and pharmaceutical. (Scripture CD, 2006)

Drug interactions present a profound and a serious problem especially with the emergence of newer agents every day which makes it harder to manage optimum prescribing and dispensing of combination therapies. It also presents an opportunity, but a challenging arena, for pharmacists to employ their knowledge of drug mechanisms and interactions for the welfare of patients.

Drug–drug interactions (DDI) can be the cause of treatment failure or side effects. The resulting adverse drug reactions (ADR) are major causes of mortality and morbidity. One of the leading causes of death in hospitalized patients is fatal ADRs. (J. Lazarou, 1998) Five to 6.5 % of hospitalizations are caused by ADRs, of these 2.5-4% are due to DDIs. (L. Guedon-Moreau, 2003). In the general population 20 to 30% of the ADRs are caused by DDIs. (Kohler GI, 2000)

It is very hard for physicians and pharmacists to remember and understand all DDIs and the situation is even worse in large specialized practices where the healthcare team is more focused on the specialty used medication with less knowledge about the medications used in other specialties and their associated interactions and precautions.

In diseases like cancer, a multidisciplinary treatment approach is adapted to meet the patients’ complex needs. The risk for DDIs, in this case, is even higher than in the general settings due to the fact of concomitant administration of multiple drugs. The literature confirms this high prevalence which leads to considerable adverse events. (Kohler GI, 2000) In fact 4% of cancer related deaths are drug related. (Buajordet I, 2001) A literature review of drug interaction in oncology settings revealed that, depending on the type of study population, the frequency of potential DDIs varied from 12% to 63%. (Riechelmann RP, 2009)

The seriousness of DDIs consequences was the driving force for the available drug interactions checking software which pharmacists and physicians rely on worldwide. In spite of the fact that most of these softwares work nicely, their integration with open-source or in-house built computerized physician order entry (CPOE) was not feasible. This made us think of building a customizable DDI checker which can be easily updated and tuned to avoid "alert fatigue" which is the main complaint of most of the clinical decision support systems users.

Using the Code

Using the application involves two simple steps: Step (1) is to fill the array "DrugList" sequentially with the prescribed drugs, and, Step (2) which compares item combinations in the array against the reference table "Interactions". The array that will store the selected medications is defined first.

Imports System.IO
Imports System.Web.Hosting
Partial Class _Default
    Inherits System.Web.UI.Page
    ' Define a new array "druglist"
    Dim drugList As New ArrayList  

The search box consumes an auto-complete function that "find-as-you-type" in the medication database. In this application, medication names are stored in a text file stored at the application root. The data can also be stored in Microsoft Excel, Microsoft Access, XML file or SQL database.

Image 1

Once the medication is selected and the user clicks "add to List", the array "druglist" will carry one more medication and the array become stored in the session "drugs".

Protected Sub addbtn_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles addbtn.Click
'this code to avoid adding "" to the array
        If txtSearch.Text = "" Then
            Exit Sub
        End If

        ' this code to avoid adding medication names not stored in the database to the array

        Dim spath As String = Path.Combine(HostingEnvironment.ApplicationPhysicalPath, "drugs.txt")

        Dim Testdrugs() As String = File.ReadAllLines(spath, Encoding.Default)
        If Testdrugs.Contains(txtSearch.Text) Then

            'this code here to count the medication added to the array. this is of value for the pharmacist to make sure all items in the presciption are added to the application
            If lblDrugCounter.Text = "" Then lblDrugCounter.Text = 0
            lblDrugCounter.Text = lblDrugCounter.Text + 1
            Dim myLabel As New Label
            myLabel.Text = txtSearch.Text

            'with each click of the button "Add to List", the array "druglist" (defined earlier) will carry one more medication and stored in a session "drugs"
            Session("drugs") = drugList
            txtSearch.Text = ""

            Response.Write("not in built-in medication list")

            Exit Sub

        End If

End Sub

After adding the prescribed medications one by one, the user interface looks like the following:

Image 2

The count of medications added to the array is of value for the pharmacist to make sure all items in the prescription are added to the application. After the medication selection is complete, the user clicks the button "Check", which then calls the sub checkinteractions().

Protected Sub chkbtn_Click(ByVal sender As Object, _
                  ByVal e As System.EventArgs) Handles chkbtn.Click
End Sub 

The sub checkinteractions() runs a dynamically created query on the table "Interactions" which contains the documented Drug-Drug Interactions. This table contains two fields for Medication Names "A" and "B". The Field "Grade" stores the severity of the interaction between "A" and "B" while the field "Summary" contains the mechanism of interaction.

Image 3

After running the query, there are two possibilities: If Interaction exists, then the sub "checkinteractions" will display the color coded warning according to the severity of the interaction. If no interaction exists, a custom message can be placed.

Public Sub checkinteractions()
        Dim Item1, Item2 As String

        For Each a In drugList
            For Each b In drugList
                Item1 = a
                Item2 = b
                If Item1 <> Item2 Then 'using this condition to avoid waste of resources in comparing one drug against itself

                    InteractionDs.SelectCommand = "SELECT [A], [B], [Grade], [Summary] FROM [Interactions] WHERE [A]='" + a + "' and [B]='" + b + "';"
                    Dim mygrid As New GridView
                    mygrid.DataSource = InteractionDs

                    'if drug-drug interaction exist, display the warning according to severity of interaction 
                        If mygrid.Rows.Count > 0 Then ' if the row count is > 0, this means that an interaction exists between the medication "A" and medication "B"
                            Session("ddiexist") = "true"
                            Dim alertlbl As New Label
                            alertlbl.Text = mygrid.Rows(0).Cells(0).Text.ToString + " interacts with " + mygrid.Rows(0).Cells(1).Text.ToString + "  -- degree of interaction is -- " + mygrid.Rows(0).Cells(2).Text.ToString
                            If mygrid.Rows(0).Cells(2).Text.ToString = "Serious - Use Alternative" Then
                                alertlbl.BackColor = Drawing.Color.Orange
                            ElseIf mygrid.Rows(0).Cells(2).Text.ToString = "Contraindicated" Then
                                alertlbl.BackColor = Drawing.Color.Pink
                            ElseIf mygrid.Rows(0).Cells(2).Text.ToString = "Significant - Monitor Closely" Then
                                alertlbl.BackColor = Drawing.Color.Yellow

                            End If
                            'add the colored warning label and the summary of interaction mechanism

                            alertlbl.Font.Bold = True
                            AppPlaceHolder.Controls.Add(New LiteralControl("<br />"))
                            AppPlaceHolder.Controls.Add(New LiteralControl("<br />"))
                            Dim comments As New Label
                            comments.Font.Italic = True

                            comments.Text = mygrid.Rows(0).Cells(3).Text.ToString
                            AppPlaceHolder.Controls.Add(New LiteralControl("<hr>"))

                        End If                        

                    Catch ex As Exception

                    End Try
                End If

        'case no DDI
        If Session("ddiexist") = "" Then
            Dim noddi As New Label ' noddi = no drug drug interaction
            noddi.Font.Bold = True
            noddi.Text = "No Interaction Found !"
            noddi.BackColor = Drawing.Color.LightGreen

        End If

End Sub 

The resulting Report of Drug-Drug interaction after submission of the prescribed medications list will look like this:

Image 4

If no interaction exists, a custom message can be placed in the label "noddi" in checkinteractions().

Image 5

The code described below is employed to clear the medication list and reset session content of the previous medication interaction check through (clearbtn_Click), and to maintain the application throughout the page life-cycle (Page_Load and Page_PreInit).

Protected Sub clearbtn_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles clearbtn.Click
     'to start adding a new medication set in a new prescription, this code clears the content in the array "druglist" and, consequently the stored session
        Session("ddiexist") = "" ' reset session content of last drug interaction check
        Session("drugs") = drugList
End Sub 

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    'store the empty array "druglist" in the session "drugs"
    If Not IsPostBack Then
        Session("drugs") = drugList
    End If
End Sub   
Protected Sub Page_PreInit(sender As Object, e As System.EventArgs) Handles Me.PreInit
    'retrieve the array from the session
    If IsPostBack Then
            'now the array "druglist" restores its content stored in the session "drugs"
            drugList = Session("drugs")
            For Each a In drugList
                ' each medication stored in the array will be displayed in a label
                Dim mylabel As New Label
                mylabel.Text = a & "<br/>"
        Catch ex As Exception
        End Try
    End If
End Sub


  • Buajordet I, Ebbesen J,Erikssen J, et al. Fatal adverse drug events: the paradox of drug treatment. J Intern Med 2001;250:327-341.
  • J. Lazarou, B. P. (1998). Incidence of adverse drug reactions in hospitalized patients: a meta-analysis of prospective studies. Journal of American Medical Association , 1200-1205.
  • Kohler GI, B.-B. S. (2000). Drug-drug interactions in medical patients: effects of in-hospital. Int J Clin Pharmacol Ther , 504-513.
  • L. Guedon-Moreau, D. D. (2003). Absolute contraindications in relation to potential drug interactions in outpatient prescriptions: analysis of the first five million prescriptions in 1999. European Journal of Clinical Pharmacology , 689–695.
  • Riechelmann RP, Del Giglio A. Drug interactions in oncology: how common are they? Annals of Oncology 2009,20: 1907–1912
  • Scripture CD, Figg WD. Drug interactions in cancer therapy. Nat Rev Cancer 2006;6:546-558.


The interaction data used in this article is for demonstration purposes only. It might be inaccurate or outdated. The live application will use an accredited database from a reliable source, so please DO NOT use the data presented in this article as a reference for your clinical decision.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Written By
Team Leader
Egypt Egypt
Clinical Pharmacy AND Programming were, and still are, my life's passion. Children suffering from cancer has been my cause since 1998. I chose to "focus" on Children with Brain Tumors, as it is -till this day- one of the most challenging pediatric malignancies. Throughout my professional career, i learnt a lot of stuff to help me help children with cancer. Working with those under privileged kids also required me to have a deeper knowledge of Pediatric Oncology, Patient Education and cancer supportive care. I got training in different fields -not only- Clinical Pharmacy, but also Fundraising, Clinical Informatics and Web Development !

Written By
Team Leader
Egypt Egypt
Physician and web developer studying Master Degrees in Statistics and Clinical Research Administration.

My passion is in Clinical Data Management and Biostatistics, and I am curious about exploring different programming languages and statistical packages.

Written By
Team Leader CCHE
Egypt Egypt
Omneya has 15 years of professional experience in Healthcare field. In her pursuit to enhance her knowledge and skills and move to specialty area in Pediatric Oncology; She gained her Board Certificate in Oncology Pharmacy from the American Board of Pharmaceutical Specialties 2007. She also acquired her Master Degree of Clinical Pharmacy-Oncology Specialty 2010. In 2016, Omneya completed her Master's Degree in Pharmaco-epidemiology.

Comments and Discussions

QuestionCode Pin
Member 1475144521-Feb-20 2:10
MemberMember 1475144521-Feb-20 2:10 
QuestionCode Pin
Wardiman Hasbi22-Feb-17 20:58
MemberWardiman Hasbi22-Feb-17 20:58 
QuestionHow to Contact the Author MohamedKamalPharm Pin
Omage femi22-Aug-15 9:42
MemberOmage femi22-Aug-15 9:42 
QuestionHere's My 5 Pin
SkinnyGlass29-Jan-14 14:57
professionalSkinnyGlass29-Jan-14 14:57 
AnswerRe: Here's My 5 Pin
MohamedKamalPharm29-Jan-14 20:52
MemberMohamedKamalPharm29-Jan-14 20:52 
GeneralMy vote of 5 Pin
Gun Gun Febrianza6-Sep-13 23:52
Member Gun Gun Febrianza6-Sep-13 23:52 
GeneralRe: My vote of 5 Pin
MohamedKamalPharm7-Sep-13 2:34
MemberMohamedKamalPharm7-Sep-13 2:34 
GeneralRe: My vote of 5 Pin
Gun Gun Febrianza7-Sep-13 18:01
Member Gun Gun Febrianza7-Sep-13 18:01 
QuestionSecure Emaildata base Pin
elistxs0822-Jul-13 1:49
Memberelistxs0822-Jul-13 1:49 
QuestionCode Pin
odeddror24-Jun-13 17:39
Memberodeddror24-Jun-13 17:39 
AnswerRe: Code Pin
MohamedKamalPharm25-Jun-13 0:28
MemberMohamedKamalPharm25-Jun-13 0:28 
GeneralRe: Code Pin
odeddror25-Jun-13 3:34
Memberodeddror25-Jun-13 3:34 

GeneralRe: Code Pin
Aras Noori20-Jun-15 13:36
MemberAras Noori20-Jun-15 13:36 
GeneralRe: Code Pin
MohamedKamalPharm20-Jun-15 23:43
MemberMohamedKamalPharm20-Jun-15 23:43 
GeneralRe: Code Pin
Aras Noori21-Jun-15 1:22
MemberAras Noori21-Jun-15 1:22 
QuestionNice work .. Keep it up Pin
Member 1011726524-Jun-13 8:28
MemberMember 1011726524-Jun-13 8:28 
AnswerRe: Nice work .. Keep it up Pin
MohamedKamalPharm24-Jun-13 8:42
MemberMohamedKamalPharm24-Jun-13 8:42 
GeneralMy vote of 5 Pin
Ștefan-Mihai MOGA13-Jun-13 21:51
professionalȘtefan-Mihai MOGA13-Jun-13 21:51 
GeneralRe: My vote of 5 Pin
MohamedKamalPharm13-Jun-13 22:34
MemberMohamedKamalPharm13-Jun-13 22:34 
GeneralMy vote of 5 Pin
Monjurul Habib12-Jun-13 10:56
professionalMonjurul Habib12-Jun-13 10:56 
GeneralRe: My vote of 5 Pin
MohamedKamalPharm12-Jun-13 13:37
MemberMohamedKamalPharm12-Jun-13 13:37 
GeneralMy vote of 1 Pin
Enver Maroshi17-May-13 23:46
MemberEnver Maroshi17-May-13 23:46 
GeneralRe: My vote of 1 Pin
MohamedSabryBakry18-May-13 1:08
MemberMohamedSabryBakry18-May-13 1:08 
GeneralMy vote of 5 Pin
medmuseum15-May-13 22:29
Membermedmuseum15-May-13 22:29 
GeneralRe: My vote of 5 Pin
MohamedKamalPharm15-May-13 23:15
MemberMohamedKamalPharm15-May-13 23:15 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.