Exemplo n.º 1
0
 private void FillProvInfo()
 {
     textOrderingProvIdentifier.Text = EhrLabCur.OrderingProviderID;
     textOrderingProvLastName.Text   = EhrLabCur.OrderingProviderLName;
     textOrderingProvFirstName.Text  = EhrLabCur.OrderingProviderFName;
     textOrderingProvMiddleName.Text = EhrLabCur.OrderingProviderMiddleNames;
     textOrderingProvSuffix.Text     = EhrLabCur.OrderingProviderSuffix;
     textOrderingProvPrefix.Text     = EhrLabCur.OrderingProviderPrefix;
     textOrderingProvAANID.Text      = EhrLabCur.OrderingProviderAssigningAuthorityNamespaceID;
     textOrderingProvAAUID.Text      = EhrLabCur.OrderingProviderAssigningAuthorityUniversalID;
     textOrderingProvAAUIDType.Text  = EhrLabCur.OrderingProviderAssigningAuthorityIDType;
     #region Name Type
     comboOrderingProvNameType.Items.Clear();
     comboOrderingProvNameType.BeginUpdate();
     //Fill medical director name combo with HL70200 enum.  Not sure if blank is acceptable.
     List <string> listOrderingProvNameType = EhrLabResults.GetHL70200Descriptions();
     comboOrderingProvNameType.Items.AddRange(listOrderingProvNameType.ToArray());
     comboOrderingProvNameType.EndUpdate();
     comboOrderingProvNameType.SelectedIndex = (int)Enum.Parse(typeof(HL70200), EhrLabCur.OrderingProviderNameTypeCode.ToString(), true) + 1;
     #endregion
     #region Identifier Type
     comboOrderingProvIdType.Items.Clear();
     comboOrderingProvIdType.BeginUpdate();
     //Fill medical director type combo with HL70203 enum.  Not sure if blank is acceptable.
     List <string> listOrderingProvIdType = EhrLabs.GetHL70203Descriptions();
     comboOrderingProvIdType.Items.AddRange(listOrderingProvIdType.ToArray());
     comboOrderingProvIdType.EndUpdate();
     comboOrderingProvIdType.SelectedIndex = (int)Enum.Parse(typeof(HL70203), EhrLabCur.OrderingProviderIdentifierTypeCode.ToString(), true) + 1;
     #endregion
 }
Exemplo n.º 2
0
        private void FillGrid()
        {
            gridMain.BeginUpdate();
            gridMain.ListGridColumns.Clear();
            GridColumn col;

            col = new GridColumn("Date Time", 80, HorizontalAlignment.Center);        //Formatted yyyyMMdd
            col.SortingStrategy = GridSortingStrategy.DateParse;
            gridMain.ListGridColumns.Add(col);
            col = new GridColumn("Placer Order Number", 130, HorizontalAlignment.Center); //Should be PK but might not be. Instead use Placer Order Num.
            gridMain.ListGridColumns.Add(col);
            col = new GridColumn("Filler Order Number", 130, HorizontalAlignment.Center); //Should be PK but might not be. Instead use Placer Order Num.
            gridMain.ListGridColumns.Add(col);
            col = new GridColumn("Test Performed", 430);                                  //Should be PK but might not be. Instead use Placer Order Num.
            gridMain.ListGridColumns.Add(col);
            col = new GridColumn("Results In", 80, HorizontalAlignment.Center);           //Or date of latest result? or both?
            gridMain.ListGridColumns.Add(col);
            ListEhrLabs = EhrLabs.GetAllForPat(PatCur.PatNum);
            gridMain.ListGridRows.Clear();
            GridRow row;

            for (int i = 0; i < ListEhrLabs.Count; i++)
            {
                row = new GridRow();
                string   dateSt = ListEhrLabs[i].ResultDateTime.PadRight(8, '0').Substring(0, 8); //stored in DB as yyyyMMddhhmmss-zzzz
                DateTime dateT  = PIn.Date(dateSt.Substring(4, 2) + "/" + dateSt.Substring(6, 2) + "/" + dateSt.Substring(0, 4));
                row.Cells.Add(dateT.ToShortDateString());                                         //date only
                row.Cells.Add(ListEhrLabs[i].PlacerOrderNum);
                row.Cells.Add(ListEhrLabs[i].FillerOrderNum);
                row.Cells.Add(ListEhrLabs[i].UsiText);
                row.Cells.Add(ListEhrLabs[i].ListEhrLabResults.Count.ToString());
                gridMain.ListGridRows.Add(row);
            }
            gridMain.EndUpdate();
        }
Exemplo n.º 3
0
 private void butDelete_Click(object sender, EventArgs e)
 {
     if (!MsgBox.Show(this, MsgBoxButtons.OKCancel, "This will delete the entire lab order and all attached lab results. This cannot be undone. Would you like to continue?"))
     {
         return;
     }
     EhrLabs.Delete(EhrLabCur.EhrLabNum);
     DialogResult = DialogResult.OK;
 }
Exemplo n.º 4
0
        private void FillComboSpecimenActionCode()
        {
            comboSpecimenActionCode.Items.Clear();
            comboSpecimenActionCode.BeginUpdate();
            List <string> listSpecActionCodes = EhrLabs.GetHL70065Descriptions();

            comboSpecimenActionCode.Items.AddRange(listSpecActionCodes.ToArray());
            comboSpecimenActionCode.EndUpdate();
            comboSpecimenActionCode.SelectedIndex = (int)Enum.Parse(typeof(HL70065), EhrLabCur.SpecimenActionCode.ToString(), true) + 1;
        }
Exemplo n.º 5
0
        private void FillComboResultStatus()
        {
            comboResultStatus.Items.Clear();
            comboResultStatus.BeginUpdate();
            List <string> listResStatCodes = EhrLabs.GetHL70123Descriptions();

            comboResultStatus.Items.AddRange(listResStatCodes.ToArray());
            comboResultStatus.EndUpdate();
            comboResultStatus.SelectedIndex = (int)Enum.Parse(typeof(HL70123), EhrLabCur.ResultStatus.ToString(), true) + 1;
        }
Exemplo n.º 6
0
 private void butSave_Click(object sender, EventArgs e)
 {
     if (PatCur == null)
     {
         MsgBox.Show(this, "Please attach to patient first.");
         return;
     }
     //Check lab dates to see if these labs already exist.
     for (int i = 0; i < ListEhrLabs.Count; i++)
     {
         EhrLab tempLab = null;              //lab from DB if it exists.
         tempLab = EhrLabs.GetByGUID(ListEhrLabs[i].PlacerOrderUniversalID, ListEhrLabs[i].PlacerOrderNum);
         if (tempLab == null)
         {
             tempLab = EhrLabs.GetByGUID(ListEhrLabs[i].FillerOrderUniversalID, ListEhrLabs[i].FillerOrderNum);
         }
         if (tempLab != null)
         {
             //validate Date of Lab and attached patient.
             //Date
             if (tempLab.ResultDateTime.CompareTo(ListEhrLabs[i].ResultDateTime) < 0)                   //string compare dates will return 1+ if tempLab Date is greater.
             {
                 MsgBox.Show(this, "This lab already exists in the database and has a more recent timestamp.");
                 continue;
             }
             if (PatCur.PatNum != tempLab.PatNum)
             {
                 //do nothing. We are importing an updated lab result and the previous lab result was attached to the wrong patient.
                 //or do something. later maybe.
             }
         }
         ListEhrLabs[i].PatNum = PatCur.PatNum;
         Provider prov = Providers.GetProv(Security.CurUser.ProvNum);
         if (Security.CurUser.ProvNum != 0 && EhrProvKeys.GetKeysByFLName(prov.LName, prov.FName).Count > 0)            //The user who is currently logged in is a provider and has a valid EHR key.
         {
             ListEhrLabs[i].IsCpoe = true;
         }
         ListEhrLabs[i] = EhrLabs.SaveToDB(ListEhrLabs[i]);               //SAVE
         for (int j = 0; j < ListEhrLabs[i].ListEhrLabResults.Count; j++) //EHR TRIGGER
         {
             if (CDSPermissions.GetForUser(Security.CurUser.UserNum).ShowCDS&& CDSPermissions.GetForUser(Security.CurUser.UserNum).LabTestCDS)
             {
                 FormCDSIntervention FormCDSI = new FormCDSIntervention();
                 FormCDSI.ListCDSI = EhrTriggers.TriggerMatch(ListEhrLabs[i].ListEhrLabResults[j], PatCur);
                 FormCDSI.ShowIfRequired(false);
             }
         }
     }
     DialogResult = DialogResult.OK;
     //Done!
 }
Exemplo n.º 7
0
 private void FormEhrLabOrders_Load(object sender, EventArgs e)
 {
     ListEhrLabs = EhrLabs.ProcessHl7Message(Hl7LabMessage, true);
     AttachPatientHelper();
     FillPatientPicker();
     FillPatientInfo();
     FillGrid();
     for (int i = 0; i < ListEhrLabs.Count; i++)      //check for existing labs in DB.
     {
         if (EhrLabs.GetByGUID(ListEhrLabs[i].PlacerOrderUniversalID, ListEhrLabs[i].PlacerOrderNum) != null ||
             EhrLabs.GetByGUID(ListEhrLabs[i].FillerOrderUniversalID, ListEhrLabs[i].FillerOrderNum) != null)
         {
             labelExistingLab.Visible = true;
             break;
         }
     }
 }
Exemplo n.º 8
0
        private void butViewParent_Click(object sender, EventArgs e)
        {
            EhrLab ehrLabParent = null;

            ehrLabParent = EhrLabs.GetByGUID(EhrLabCur.ParentPlacerOrderUniversalID, EhrLabCur.ParentPlacerOrderNum);
            if (ehrLabParent == null)
            {
                ehrLabParent = EhrLabs.GetByGUID(EhrLabCur.ParentFillerOrderUniversalID, EhrLabCur.ParentFillerOrderNum);
            }
            if (ehrLabParent == null)
            {
                return;
            }
            FormEhrLabOrderEdit2014 FormELOE = new FormEhrLabOrderEdit2014();

            FormELOE.EhrLabCur  = ehrLabParent;
            FormELOE.IsViewOnly = true;
            FormELOE.Text       = Lan.g(this, "Parent Lab Order - READ ONLY");
            FormELOE.ShowDialog();
        }
Exemplo n.º 9
0
        private void AttachPatientHelper()
        {
            Patient patAttach = EhrLabs.FindAttachedPatient(Hl7LabMessage);

            if (patAttach == null)
            {
                return;                //no reccomended patient
            }
            else if (PatCur == null)
            {
                PatCur = patAttach;
            }
            else if (PatCur.PatNum != patAttach.PatNum)
            {
                MsgBox.Show(this, "Patient mismatch. Selected patient does not match detected patient.");               //will only happen if we set PatCur from somewhere else. Probably wont ever happen.
                PatCur = patAttach;
            }
            else
            {
                //I dunno what to put here; maybe a little picture of a dog wearing a fireman costume?
            }
        }
Exemplo n.º 10
0
        private void butAdd_Click(object sender, EventArgs e)
        {
            FormEhrLabOrderEdit2014 FormLOE = new FormEhrLabOrderEdit2014();

            FormLOE.EhrLabCur        = new EhrLab();
            FormLOE.EhrLabCur.PatNum = PatCur.PatNum;
            FormLOE.IsNew            = true;
            FormLOE.ShowDialog();
            if (FormLOE.DialogResult != DialogResult.OK)
            {
                return;
            }
            EhrMeasureEvent newMeasureEvent = new EhrMeasureEvent();

            newMeasureEvent.DateTEvent = DateTime.Now;
            newMeasureEvent.EventType  = EhrMeasureEventType.CPOE_LabOrdered;         //default
            Loinc loinc = Loincs.GetByCode(FormLOE.EhrLabCur.UsiID);

            if (loinc != null && loinc.ClassType == "RAD")         //short circuit logic
            {
                newMeasureEvent.EventType = EhrMeasureEventType.CPOE_RadOrdered;
            }
            newMeasureEvent.PatNum   = FormLOE.EhrLabCur.PatNum;
            newMeasureEvent.MoreInfo = "";
            newMeasureEvent.FKey     = FormLOE.EhrLabCur.EhrLabNum;
            EhrMeasureEvents.Insert(newMeasureEvent);
            EhrLabs.SaveToDB(FormLOE.EhrLabCur);
            for (int i = 0; i < FormLOE.EhrLabCur.ListEhrLabResults.Count; i++)
            {
                if (CDSPermissions.GetForUser(Security.CurUser.UserNum).ShowCDS&& CDSPermissions.GetForUser(Security.CurUser.UserNum).LabTestCDS)
                {
                    FormCDSIntervention FormCDSI = new FormCDSIntervention();
                    FormCDSI.ListCDSI = EhrTriggers.TriggerMatch(FormLOE.EhrLabCur.ListEhrLabResults[i], PatCur);
                    FormCDSI.ShowIfRequired(false);
                }
            }
            FillGrid();
        }
Exemplo n.º 11
0
        private void butImport_Click(object sender, EventArgs e)
        {
            MsgBoxCopyPaste MBCP = new MsgBoxCopyPaste("Paste HL7 Lab Message Text Here.");

            MBCP.textMain.SelectAll();
            MBCP.ShowDialog();
            if (MBCP.DialogResult != DialogResult.OK)
            {
                return;
            }
            List <EhrLab> listEhrLabs;

            try {
                listEhrLabs = EhrLabs.ProcessHl7Message(MBCP.textMain.Text); //Not a typical use of the msg box copy paste
                if (listEhrLabs[0].PatNum == PatCur.PatNum)                  //only need to check the first lab.
                //nothing to do here. Imported lab matches the current patient.
                {
                }
                else                 //does not match current patient, redirect to import form which displays patient information and is build for importing.
                {
                    FormEhrLabOrderImport FormLOI = new FormEhrLabOrderImport();
                    FormLOI.PatCur        = PatCur;
                    FormLOI.Hl7LabMessage = MBCP.textMain.Text;
                    FormLOI.ShowDialog();
                    FillGrid();
                    return;
                }
                //else if(listEhrLabs[0].PatNum==0) {
                //	if(MessageBox.Show("Lab patient does not match current patient. Lab patient name is "
                //		+MBCP.textMain.Text.Split(new string[] { "\r\n" },StringSplitOptions.RemoveEmptyEntries)[1].Split('|')[5].Split('~')[0].Split('^')[1]+" "//first name
                //		+MBCP.textMain.Text.Split(new string[] { "\r\n" },StringSplitOptions.RemoveEmptyEntries)[1].Split('|')[5].Split('~')[0].Split('^')[1]+" "//last name
                //		+"\r\nWould you like to import lab for the current patient?","",MessageBoxButtons.OKCancel)!=DialogResult.OK)
                //	{
                //		return;
                //	}
                //	//User agreed to import current lab(s) for current patient.
                //	for(int i=0;i<listEhrLabs.Count;i++) {
                //		listEhrLabs[i].PatNum=PatCur.PatNum;
                //		//TODO: Import external OIDs and PatIDs so that we can identify this patient next time.
                //	}
                //}
                //else {//Patnum is already associated with another patient.
                //	MessageBox.Show("This lab contains patient information for a different patient. Lab patient name is "
                //		+MBCP.textMain.Text.Split(new string[] { "\r\n" },StringSplitOptions.RemoveEmptyEntries)[1].Split('|')[5].Split('~')[0].Split('^')[1]+" "//first name
                //		+MBCP.textMain.Text.Split(new string[] { "\r\n" },StringSplitOptions.RemoveEmptyEntries)[1].Split('|')[5].Split('~')[0].Split('^')[1]);
                //	return;
                //}
            }
            catch (Exception Ex) {
                MessageBox.Show(this, "Unable to import lab.\r\n" + Ex.Message);
                return;
            }
            for (int i = 0; i < listEhrLabs.Count; i++)
            {
                EhrLab tempLab = null;              //lab from DB if it exists.
                tempLab = EhrLabs.GetByGUID(listEhrLabs[i].PlacerOrderUniversalID, listEhrLabs[i].PlacerOrderNum);
                if (tempLab == null)
                {
                    tempLab = EhrLabs.GetByGUID(listEhrLabs[i].FillerOrderUniversalID, listEhrLabs[i].FillerOrderNum);
                }
                if (tempLab != null)
                {
                    //Date validation.
                    //if(tempLab.ResultDateTime.CompareTo(listEhrLabs[i].ResultDateTime)<=0) {//string compare dates will return 1+ if tempLab Date is greater.
                    //	MsgBox.Show(this,"This lab already exists in the database and has a more recent timestamp.");
                    //	continue;
                    //}
                    //TODO: The code above works, but ignores more recent lab results. Although the lab order my be unchanged there may be updated lab results.
                    //It would be better to check for updated results, unfortunately results have no unique identifiers.
                }
                Provider prov = Providers.GetProv(Security.CurUser.ProvNum);
                if (Security.CurUser.ProvNum != 0 && EhrProvKeys.GetKeysByFLName(prov.LName, prov.FName).Count > 0)            //The user who is currently logged in is a provider and has a valid EHR key.
                {
                    ListEhrLabs[i].IsCpoe = true;
                }
                listEhrLabs[i] = EhrLabs.SaveToDB(listEhrLabs[i]);               //SAVE
                for (int j = 0; j < listEhrLabs[i].ListEhrLabResults.Count; j++) //EHR TRIGGER
                {
                    if (CDSPermissions.GetForUser(Security.CurUser.UserNum).ShowCDS&& CDSPermissions.GetForUser(Security.CurUser.UserNum).LabTestCDS)
                    {
                        FormCDSIntervention FormCDSI = new FormCDSIntervention();
                        FormCDSI.ListCDSI = EhrTriggers.TriggerMatch(listEhrLabs[i].ListEhrLabResults[j], PatCur);
                        FormCDSI.ShowIfRequired(false);
                    }
                }
            }
            FillGrid();
        }
Exemplo n.º 12
0
        private void butOk_Click(object sender, EventArgs e)
        {
            if (IsImport || IsViewOnly)
            {
                DialogResult = DialogResult.OK;
                return;
            }
            if (!EntriesAreValid())
            {
                return;
            }
            if (Security.CurUser.ProvNum != 0 && Providers.GetProv(Security.CurUser.ProvNum).EhrKey != "")         //The user who is currently logged in is a provider and has a valid EHR key.
            {
                EhrLabCur.IsCpoe = true;
            }
            if (EhrLabCur.PatNum == 0 && PatCurNum != null)
            {
                EhrLabCur.PatNum = PatCurNum;
            }
            //EhrLabCur.OrderControlCode=((HL70119)comb);//TODO:UI and this value.
            if (checkAutoID.Checked)
            {
                EhrLabCur.PlacerOrderNum             = EhrLabs.GetNextOrderNum().ToString();
                EhrLabCur.PlacerOrderNamespace       = "";
                EhrLabCur.PlacerOrderUniversalID     = OIDInternals.GetForType(IdentifierType.LabOrder).IDRoot;
                EhrLabCur.PlacerOrderUniversalIDType = "ISO";
            }
            else
            {
                EhrLabCur.PlacerOrderNum             = textPlacerOrderNum.Text;
                EhrLabCur.PlacerOrderNamespace       = textPlacerOrderNamespace.Text;
                EhrLabCur.PlacerOrderUniversalID     = textPlacerOrderUniversalID.Text;
                EhrLabCur.PlacerOrderUniversalIDType = textPlacerOrderUniversalIDType.Text;
            }
            EhrLabCur.FillerOrderNum              = textFillerOrderNum.Text;
            EhrLabCur.FillerOrderNamespace        = textFillerOrderNamespace.Text;
            EhrLabCur.FillerOrderUniversalID      = textFillerOrderUniversalID.Text;
            EhrLabCur.FillerOrderUniversalIDType  = textFillerOrderUniversalIDType.Text;
            EhrLabCur.PlacerGroupNum              = textPlacerGroupNum.Text;
            EhrLabCur.PlacerGroupNamespace        = textPlacerGroupNamespace.Text;
            EhrLabCur.PlacerGroupUniversalID      = textPlacerGroupUniversalID.Text;
            EhrLabCur.PlacerGroupUniversalIDType  = textPlacerGroupUniversalIDType.Text;
            EhrLabCur.OrderingProviderID          = textOrderingProvIdentifier.Text;
            EhrLabCur.OrderingProviderLName       = textOrderingProvLastName.Text;
            EhrLabCur.OrderingProviderFName       = textOrderingProvFirstName.Text;
            EhrLabCur.OrderingProviderMiddleNames = textOrderingProvMiddleName.Text;
            EhrLabCur.OrderingProviderSuffix      = textOrderingProvSuffix.Text;
            EhrLabCur.OrderingProviderPrefix      = textOrderingProvPrefix.Text;
            EhrLabCur.OrderingProviderAssigningAuthorityNamespaceID = textOrderingProvAANID.Text;
            EhrLabCur.OrderingProviderAssigningAuthorityUniversalID = textOrderingProvAAUID.Text;
            EhrLabCur.OrderingProviderAssigningAuthorityIDType      = textOrderingProvAAUIDType.Text;
            EhrLabCur.OrderingProviderNameTypeCode       = ((HL70200)comboOrderingProvNameType.SelectedIndex - 1);
            EhrLabCur.OrderingProviderIdentifierTypeCode = ((HL70203)comboOrderingProvIdType.SelectedIndex - 1);
            //EhrLabCur.SetIdOBR=PIn.Long("");//TODO: UI and Save
            EhrLabCur.UsiID                    = textUsiID.Text;
            EhrLabCur.UsiText                  = textUsiText.Text;
            EhrLabCur.UsiCodeSystemName        = textUsiCodeSystemName.Text;
            EhrLabCur.UsiIDAlt                 = textUsiIDAlt.Text;
            EhrLabCur.UsiTextAlt               = textUsiTextAlt.Text;
            EhrLabCur.UsiCodeSystemNameAlt     = textUsiCodeSystemNameAlt.Text;
            EhrLabCur.UsiTextOriginal          = textUsiTextOriginal.Text;
            EhrLabCur.ObservationDateTimeStart = EhrLab.formatDateToHL7(textObservationDateTimeStart.Text.Trim());
            EhrLabCur.ObservationDateTimeEnd   = EhrLab.formatDateToHL7(textObservationDateTimeEnd.Text.Trim());
            EhrLabCur.SpecimenActionCode       = ((HL70065)comboSpecimenActionCode.SelectedIndex - 1);
            EhrLabCur.ResultDateTime           = EhrLab.formatDateToHL7(textResultDateTime.Text.Trim());//upper right hand corner of form.
            EhrLabCur.ResultStatus             = ((HL70123)comboResultStatus.SelectedIndex - 1);
            //TODO: parent result.

            /*
             * EhrLabCur.ParentObservationID=
             * EhrLabCur.ParentObservationText=
             * EhrLabCur.ParentObservationCodeSystemName=
             * EhrLabCur.ParentObservationIDAlt=
             * EhrLabCur.ParentObservationTextAlt=
             * EhrLabCur.ParentObservationCodeSystemNameAlt=
             * EhrLabCur.ParentObservationTextOriginal=
             * EhrLabCur.ParentObservationSubID=
             * EhrLabCur.ParentPlacerOrderNum=
             * EhrLabCur.ParentPlacerOrderNamespace=
             * EhrLabCur.ParentPlacerOrderUniversalID=
             * EhrLabCur.ParentPlacerOrderUniversalIDType=
             * EhrLabCur.ParentFillerOrderNum=
             * EhrLabCur.ParentFillerOrderNamespace=
             * EhrLabCur.ParentFillerOrderUniversalID=
             * EhrLabCur.ParentFillerOrderUniversalIDType=
             */
            EhrLabCur.ListEhrLabResultsHandlingF = checkResultsHandlingF.Checked;
            EhrLabCur.ListEhrLabResultsHandlingN = checkResultsHandlingN.Checked;
            //EhrLabCur.TQ1SetId=//TODO:this
            EhrLabCur.TQ1DateTimeStart = EhrLab.formatDateToHL7(textTQ1Start.Text);
            EhrLabCur.TQ1DateTimeEnd   = EhrLab.formatDateToHL7(textTQ1Stop.Text);
            EhrLabs.SaveToDB(EhrLabCur);
            Patient patCur = Patients.GetPat(EhrLabCur.PatNum);

            for (int i = 0; i < EhrLabCur.ListEhrLabResults.Count; i++)
            {
                if (CDSPermissions.GetForUser(Security.CurUser.UserNum).ShowCDS&& CDSPermissions.GetForUser(Security.CurUser.UserNum).LabTestCDS)
                {
                    FormCDSIntervention FormCDSI = new FormCDSIntervention();
                    FormCDSI.ListCDSI = EhrTriggers.TriggerMatch(EhrLabCur.ListEhrLabResults[i], patCur);
                    FormCDSI.ShowIfRequired(false);
                }
            }
            DialogResult = DialogResult.OK;
        }
Exemplo n.º 13
0
 private void FormLabResultEdit_Load(object sender, EventArgs e)
 {
     if (IsImport || IsViewOnly)
     {
         foreach (Control c in this.Controls)
         {
             c.Enabled = false;
         }
         butCancel.Enabled = true;
         butCancel.Text    = "Close";
         gridNotes.Enabled = true;
         //butAddNote.Enabled=false;
         //butObsIdLoinc.Enabled=false;
         //butCodedElementSnomed.Enabled=false;
         //butUnitOfMeasureUCUM.Enabled=false;
         //butOk.Enabled=false;
         //combos
     }
     //textObsDateTime.Text=EhrLab.formatDateFromHL7(EhrLabResultCur.ObservationDateTime);
     //textAnalysisDateTime.Text=EhrLab.formatDateFromHL7(EhrLabResultCur.AnalysisDateTime);
     #region Observation Identifier (LOINC Codes)
     textObsIDCodeSystemName.Text = EhrLabResultCur.ObservationIdentifierCodeSystemName;
     textObsID.Text     = EhrLabResultCur.ObservationIdentifierID;
     textObsIDText.Text = EhrLabResultCur.ObservationIdentifierText;
     textObsIDCodeSystemNameAlt.Text = EhrLabResultCur.ObservationIdentifierCodeSystemNameAlt;
     textObsIDAlt.Text      = EhrLabResultCur.ObservationIdentifierIDAlt;
     textObsIDTextAlt.Text  = EhrLabResultCur.ObservationIdentifierTextAlt;
     textObsIDOrigText.Text = EhrLabResultCur.ObservationIdentifierTextOriginal;
     textObsSub.Text        = EhrLabResultCur.ObservationIdentifierSub;
     #endregion
     #region Abnormal Flags
     listAbnormalFlags.Items.Clear();
     listAbnormalFlags.BeginUpdate();
     List <string> listAbnormalFlagsStr = EhrLabResults.GetHL70078Descriptions();
     listAbnormalFlags.Items.AddRange(listAbnormalFlagsStr.ToArray());
     listAbnormalFlags.EndUpdate();
     string[] abnormalFlags = EhrLabResultCur.AbnormalFlags.Split(',');
     for (int i = 0; i < abnormalFlags.Length; i++)
     {
         if (abnormalFlags[i] == "")
         {
             continue;
         }
         listAbnormalFlags.SetSelected((int)Enum.Parse(typeof(HL70078), abnormalFlags[i], true), true);
     }
     #endregion
     #region Observation Value
     textObsDateTime.Text      = EhrLab.formatDateFromHL7(EhrLabResultCur.ObservationDateTime);
     textAnalysisDateTime.Text = EhrLab.formatDateFromHL7(EhrLabResultCur.AnalysisDateTime);
     #region Observation Status
     comboObsStatus.Items.Clear();
     comboObsStatus.BeginUpdate();
     //Fill obs status combo with HL70085 enum.  Not sure if blank is acceptable.
     List <string> listObsStatus = EhrLabResults.GetHL70085Descriptions();
     comboObsStatus.Items.AddRange(listObsStatus.ToArray());
     comboObsStatus.EndUpdate();
     comboObsStatus.SelectedIndex = (int)Enum.Parse(typeof(HL70085), EhrLabResultCur.ObservationResultStatus.ToString(), true) + 1;
     #endregion
     #region Value Type
     comboObsValueType.Items.Clear();
     comboObsValueType.BeginUpdate();
     //Fill obs value type combo with HL70125 enum.  Not sure if blank is acceptable.
     List <string> listObsValueType = EhrLabResults.GetHL70125Descriptions();
     comboObsValueType.Items.AddRange(listObsValueType.ToArray());
     comboObsValueType.EndUpdate();
     comboObsValueType.SelectedIndex = (int)Enum.Parse(typeof(HL70125), EhrLabResultCur.ValueType.ToString(), true) + 1;
     #endregion
     textObsValue.Text = GetObservationText();
     #region Coded Elements
     textObsElementCodeSystem.Text    = EhrLabResultCur.ObservationValueCodedElementCodeSystemName;
     textObsElementID.Text            = EhrLabResultCur.ObservationValueCodedElementID;
     textObsElementText.Text          = EhrLabResultCur.ObservationValueCodedElementText;
     textObsElementCodeSystemAlt.Text = EhrLabResultCur.ObservationValueCodedElementCodeSystemNameAlt;
     textObsElementIDAlt.Text         = EhrLabResultCur.ObservationValueCodedElementIDAlt;
     textObsElementTextAlt.Text       = EhrLabResultCur.ObservationValueCodedElementTextAlt;
     textObsElementOrigText.Text      = EhrLabResultCur.ObservationValueCodedElementTextOriginal;
     #endregion
     #region Structured Numeric
     textStructNumComp.Text      = EhrLabResultCur.ObservationValueComparator;
     textStructNumFirst.Text     = EhrLabResultCur.ObservationValueNumber1.ToString();
     textStructNumSeparator.Text = EhrLabResultCur.ObservationValueSeparatorOrSuffix;
     textStructNumSecond.Text    = EhrLabResultCur.ObservationValueNumber2.ToString();
     #endregion
     #region Unit of Measure
     textObsUnitsCodeSystem.Text    = EhrLabResultCur.UnitsCodeSystemName;
     textObsUnitsID.Text            = EhrLabResultCur.UnitsID;
     textObsUnitsText.Text          = EhrLabResultCur.UnitsText;
     textObsUnitsCodeSystemAlt.Text = EhrLabResultCur.UnitsCodeSystemNameAlt;
     textObsUnitsIDAlt.Text         = EhrLabResultCur.UnitsIDAlt;
     textObsUnitsTextAlt.Text       = EhrLabResultCur.UnitsTextAlt;
     textObsUnitsTextOrig.Text      = EhrLabResultCur.UnitsTextOriginal;
     #endregion
     #endregion
     #region Performing Organization
     #region Name
     textPerfOrgName.Text = EhrLabResultCur.PerformingOrganizationName;
     #region Identifier Type
     comboPerfOrgIdType.Items.Clear();
     comboPerfOrgIdType.BeginUpdate();
     //Fill identifier type combo with HL70203 enum.  Not sure if blank is acceptable.
     List <string> listPerfOrgIdType = EhrLabs.GetHL70203Descriptions();
     comboPerfOrgIdType.Items.AddRange(listPerfOrgIdType.ToArray());
     comboPerfOrgIdType.EndUpdate();
     comboPerfOrgIdType.SelectedIndex = (int)Enum.Parse(typeof(HL70203), EhrLabResultCur.PerformingOrganizationIdentifierTypeCode.ToString(), true) + 1;
     #endregion
     textPerfOrgIdentifier.Text = EhrLabResultCur.PerformingOrganizationIdentifier;
     #region Assigning Authority
     textPerfOrgAssignIdType.Text = EhrLabResultCur.PerformingOrganizationNameAssigningAuthorityUniversalIdType;
     textPerfOrgNamespaceID.Text  = EhrLabResultCur.PerformingOrganizationNameAssigningAuthorityNamespaceId;
     textPerfOrgUniversalID.Text  = EhrLabResultCur.PerformingOrganizationNameAssigningAuthorityUniversalId;
     #endregion
     #endregion
     #region Address
     #region Address Type
     comboPerfOrgAddressType.Items.Clear();
     comboPerfOrgAddressType.BeginUpdate();
     //Fill address type combo with HL70190 enum.  Not sure if blank is acceptable.
     List <string> listPerfOrgAddressType = EhrLabResults.GetHL70190Descriptions();
     comboPerfOrgAddressType.Items.AddRange(listPerfOrgAddressType.ToArray());
     comboPerfOrgAddressType.EndUpdate();
     comboPerfOrgAddressType.SelectedIndex = (int)Enum.Parse(typeof(HL70190), EhrLabResultCur.PerformingOrganizationAddressAddressType.ToString(), true) + 1;
     #endregion
     textPerfOrgStreet.Text           = EhrLabResultCur.PerformingOrganizationAddressStreet;
     textPerfOrgOtherDesignation.Text = EhrLabResultCur.PerformingOrganizationAddressOtherDesignation;
     textPerfOrgCity.Text             = EhrLabResultCur.PerformingOrganizationAddressCity;
     #region State or Province
     comboPerfOrgState.Items.Clear();
     comboPerfOrgState.BeginUpdate();
     //Fill state combo with USPSAlphaStateCode enum.  Not sure if blank is acceptable.
     List <string> listPerfOrgState = EhrLabResults.GetUSPSAlphaStateCodeDescriptions();
     comboPerfOrgState.Items.AddRange(listPerfOrgState.ToArray());
     comboPerfOrgState.EndUpdate();
     comboPerfOrgState.SelectedIndex = (int)Enum.Parse(typeof(USPSAlphaStateCode), EhrLabResultCur.PerformingOrganizationAddressStateOrProvince.ToString(), true) + 1;
     #endregion
     textPerfOrgZip.Text     = EhrLabResultCur.PerformingOrganizationAddressZipOrPostalCode;
     textPerfOrgCountry.Text = EhrLabResultCur.PerformingOrganizationAddressCountryCode;
     textPerfOrgCounty.Text  = EhrLabResultCur.PerformingOrganizationAddressCountyOrParishCode;
     #endregion
     #region Medical Director
     #region Identifier Type
     comboMedDirIdType.Items.Clear();
     comboMedDirIdType.BeginUpdate();
     //Fill medical director type combo with HL70203 enum.  Not sure if blank is acceptable.
     List <string> listMedDirIdType = EhrLabs.GetHL70203Descriptions();
     comboMedDirIdType.Items.AddRange(listMedDirIdType.ToArray());
     comboMedDirIdType.EndUpdate();
     comboMedDirIdType.SelectedIndex = (int)Enum.Parse(typeof(HL70203), EhrLabResultCur.MedicalDirectorIdentifierTypeCode.ToString(), true) + 1;
     #endregion
     textMedDirIdentifier.Text = EhrLabResultCur.MedicalDirectorID;
     #region Name Type
     comboMedDirNameType.Items.Clear();
     comboMedDirNameType.BeginUpdate();
     //Fill medical director name combo with HL70200 enum.  Not sure if blank is acceptable.
     List <string> listMedDirNameType = EhrLabResults.GetHL70200Descriptions();
     comboMedDirNameType.Items.AddRange(listMedDirIdType.ToArray());
     comboMedDirNameType.EndUpdate();
     comboMedDirNameType.SelectedIndex = (int)Enum.Parse(typeof(HL70200), EhrLabResultCur.MedicalDirectorNameTypeCode.ToString(), true) + 1;
     #endregion
     textMedDirLastName.Text   = EhrLabResultCur.MedicalDirectorLName;
     textMedDirFirstName.Text  = EhrLabResultCur.MedicalDirectorFName;
     textMedDirMiddleName.Text = EhrLabResultCur.MedicalDirectorMiddleNames;
     textMedDirSuffix.Text     = EhrLabResultCur.MedicalDirectorSuffix;
     textMedDirPrefix.Text     = EhrLabResultCur.MedicalDirectorPrefix;
     #region Assigning Authority
     textMedDirAssignIdType.Text = EhrLabResultCur.MedicalDirectorAssigningAuthorityIDType;
     textMedDirNamespaceID.Text  = EhrLabResultCur.MedicalDirectorAssigningAuthorityNamespaceID;
     textMedDirUniversalID.Text  = EhrLabResultCur.MedicalDirectorAssigningAuthorityUniversalID;
     #endregion
     #endregion
     #endregion
     textReferenceRange.Text = EhrLabResultCur.referenceRange;
     FillGridNotes();
 }
Exemplo n.º 14
0
        ///<summary>This is the first step of automation, this checks to see if the new object matches one of the trigger conditions. </summary>
        /// <param name="triggerObject">Can be DiseaseDef, ICD9, Icd10, Snomed, Medication, RxNorm, Cvx, AllerfyDef, EHRLabResult, Patient, or VitalSign.</param>
        /// <param name="PatCur">Triggers and intervention are currently always dependant on current patient. </param>
        /// <returns>Returns a dictionary keyed on triggers and a list of all the objects that the trigger matched on. Should be used to generate CDS intervention message and later be passed to FormInfobutton for knowledge request.</returns>
        public static List <CDSIntervention> TriggerMatch(object triggerObject, Patient PatCur)
        {
            if (RemotingClient.RemotingRole == RemotingRole.ClientWeb)
            {
                return(Meth.GetObject <List <CDSIntervention> >(MethodBase.GetCurrentMethod(), triggerObject, PatCur));
            }
            //Dictionary<string,List<object>> retVal=new Dictionary<string,List<object>>();
            List <CDSIntervention> retVal = new List <CDSIntervention>();
            //Define objects to be used in matching triggers.
            DiseaseDef   diseaseDef;
            ICD9         icd9;
            Icd10        icd10;
            Snomed       snomed;
            Medication   medication;
            RxNorm       rxNorm;
            Cvx          cvx;
            AllergyDef   allergyDef;
            EhrLabResult ehrLabResult;
            Patient      pat;
            Vitalsign    vitalsign;
            string       triggerObjectMessage = "";
            string       command = "";

            switch (triggerObject.GetType().Name)
            {
            case "DiseaseDef":
                diseaseDef = (DiseaseDef)triggerObject;
                command    = "SELECT * FROM ehrtrigger"
                             + " WHERE ProblemDefNumList LIKE '% " + POut.String(diseaseDef.DiseaseDefNum.ToString()) + " %'";      // '% <code> %' so that we can get exact matches.
                if (diseaseDef.ICD9Code != "")
                {
                    command += " OR ProblemIcd9List LIKE '% " + POut.String(diseaseDef.ICD9Code) + " %'";
                    triggerObjectMessage += "  -" + diseaseDef.ICD9Code + "(Icd9)  " + ICD9s.GetByCode(diseaseDef.ICD9Code).Description + "\r\n";
                }
                if (diseaseDef.Icd10Code != "")
                {
                    command += " OR ProblemIcd10List LIKE '% " + POut.String(diseaseDef.Icd10Code) + " %'";
                    triggerObjectMessage += "  -" + diseaseDef.Icd10Code + "(Icd10)  " + Icd10s.GetByCode(diseaseDef.Icd10Code).Description + "\r\n";
                }
                if (diseaseDef.SnomedCode != "")
                {
                    command += " OR ProblemSnomedList LIKE '% " + POut.String(diseaseDef.SnomedCode) + " %'";
                    triggerObjectMessage += "  -" + diseaseDef.SnomedCode + "(Snomed)  " + Snomeds.GetByCode(diseaseDef.SnomedCode).Description + "\r\n";
                }
                break;

            case "ICD9":
                icd9 = (ICD9)triggerObject;
                //TODO: TriggerObjectMessage
                command = "SELECT * FROM ehrtrigger"
                          + " WHERE Icd9List LIKE '% " + POut.String(icd9.ICD9Code) + " %'";         // '% <code> %' so that we can get exact matches.
                break;

            case "Icd10":
                icd10 = (Icd10)triggerObject;
                //TODO: TriggerObjectMessage
                command = "SELECT * FROM ehrtrigger"
                          + " WHERE Icd10List LIKE '% " + POut.String(icd10.Icd10Code) + " %'";         // '% <code> %' so that we can get exact matches.
                break;

            case "Snomed":
                snomed = (Snomed)triggerObject;
                //TODO: TriggerObjectMessage
                command = "SELECT * FROM ehrtrigger"
                          + " WHERE SnomedList LIKE '% " + POut.String(snomed.SnomedCode) + " %'";         // '% <code> %' so that we can get exact matches.
                break;

            case "Medication":
                medication           = (Medication)triggerObject;
                triggerObjectMessage = "  - " + medication.MedName + (medication.RxCui == 0?"":" (RxCui:" + RxNorms.GetByRxCUI(medication.RxCui.ToString()).RxCui + ")") + "\r\n";
                command = "SELECT * FROM ehrtrigger"
                          + " WHERE MedicationNumList LIKE '% " + POut.String(medication.MedicationNum.ToString()) + " %'";         // '% <code> %' so that we can get exact matches.
                if (medication.RxCui != 0)
                {
                    command += " OR RxCuiList LIKE '% " + POut.String(medication.RxCui.ToString()) + " %'";                      // '% <code> %' so that we can get exact matches.
                }
                break;

            case "RxNorm":
                rxNorm = (RxNorm)triggerObject;
                triggerObjectMessage = "  - " + rxNorm.Description + "(RxCui:" + rxNorm.RxCui + ")\r\n";
                command = "SELECT * FROM ehrtrigger"
                          + " WHERE RxCuiList LIKE '% " + POut.String(rxNorm.RxCui) + " %'";         // '% <code> %' so that we can get exact matches.
                break;

            case "Cvx":
                cvx = (Cvx)triggerObject;
                //TODO: TriggerObjectMessage
                command = "SELECT * FROM ehrtrigger"
                          + " WHERE CvxList LIKE '% " + POut.String(cvx.CvxCode) + " %'";         // '% <code> %' so that we can get exact matches.
                break;

            case "AllergyDef":
                allergyDef = (AllergyDef)triggerObject;
                //TODO: TriggerObjectMessage
                command = "SELECT * FROM ehrtrigger"
                          + " WHERE AllergyDefNumList LIKE '% " + POut.String(allergyDef.AllergyDefNum.ToString()) + " %'";         // '% <code> %' so that we can get exact matches.
                break;

            case "EhrLabResult":                    //match loinc only, no longer
                ehrLabResult = (EhrLabResult)triggerObject;
                //TODO: TriggerObjectMessage
                command = "SELECT * FROM ehrtrigger WHERE "
                          + "(LabLoincList LIKE '% " + ehrLabResult.ObservationIdentifierID + " %'"                  //LOINC may be in one of two fields
                          + "OR LabLoincList LIKE '% " + ehrLabResult.ObservationIdentifierIDAlt + " %')";           //LOINC may be in one of two fields
                break;

            case "Patient":
                pat = (Patient)triggerObject;
                List <string> triggerNums = new List <string>();
                //TODO: TriggerObjectMessage
                command = "SELECT * FROM ehrtrigger WHERE DemographicsList !=''";
                List <EhrTrigger> triggers = Crud.EhrTriggerCrud.SelectMany(command);
                for (int i = 0; i < triggers.Count; i++)
                {
                    string[] arrayDemoItems = triggers[i].DemographicsList.Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries);
                    for (int j = 0; j < arrayDemoItems.Length; j++)
                    {
                        switch (arrayDemoItems[j].Split(',')[0])
                        {
                        case "age":
                            int val = PIn.Int(Regex.Match(arrayDemoItems[j], @"\d+").Value);
                            if (arrayDemoItems[j].Contains("="))                                             //=, >=, or <=
                            {
                                if (val == pat.Age)
                                {
                                    triggerNums.Add(triggers[i].EhrTriggerNum.ToString());
                                    break;
                                }
                            }
                            if (arrayDemoItems[j].Contains("<"))
                            {
                                if (pat.Age < val)
                                {
                                    triggerNums.Add(triggers[i].EhrTriggerNum.ToString());
                                    break;
                                }
                            }
                            if (arrayDemoItems[j].Contains(">"))
                            {
                                if (pat.Age > val)
                                {
                                    triggerNums.Add(triggers[i].EhrTriggerNum.ToString());
                                    break;
                                }
                            }
                            //should never happen, age element didn't contain a comparator
                            break;

                        case "gender":
                            if (arrayDemoItems[j].Split(',')[0].StartsWith(pat.Gender.ToString()))
                            {
                                triggerNums.Add(triggers[i].EhrTriggerNum.ToString());
                            }
                            break;

                        default:
                            break;                                            //should never happen
                        }
                    }
                }
                triggerNums.Add("-1");                        //to ensure the querry is valid.
                command = "SELECT * FROM ehrTrigger WHERE EhrTriggerNum IN (" + String.Join(",", triggerNums) + ")";
                break;

            case "Vitalsign":
                List <string> trigNums = new List <string>();
                vitalsign = (Vitalsign)triggerObject;
                command   = "SELECT * FROM ehrtrigger WHERE VitalLoincList !=''";
                List <EhrTrigger> triggersVit = Crud.EhrTriggerCrud.SelectMany(command);
                for (int i = 0; i < triggersVit.Count; i++)
                {
                    string[] arrayVitalItems = triggersVit[i].VitalLoincList.Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries);
                    for (int j = 0; j < arrayVitalItems.Length; j++)
                    {
                        double val = PIn.Double(Regex.Match(arrayVitalItems[j], @"\d+(.(\d+))*").Value);                             //decimal value w or w/o decimal.
                        switch (arrayVitalItems[j].Split(',')[0])
                        {
                        case "height":
                            if (arrayVitalItems[j].Contains("="))                                             //=, >=, or <=
                            {
                                if (vitalsign.Height == val)
                                {
                                    trigNums.Add(triggersVit[i].EhrTriggerNum.ToString());
                                    break;
                                }
                            }
                            if (arrayVitalItems[j].Contains("<"))
                            {
                                if (vitalsign.Height < val)
                                {
                                    trigNums.Add(triggersVit[i].EhrTriggerNum.ToString());
                                    break;
                                }
                            }
                            if (arrayVitalItems[j].Contains(">"))
                            {
                                if (vitalsign.Height > val)
                                {
                                    trigNums.Add(triggersVit[i].EhrTriggerNum.ToString());
                                    break;
                                }
                            }
                            //should never happen, Height element didn't contain a comparator
                            break;

                        case "weight":
                            if (arrayVitalItems[j].Contains("="))                                             //=, >=, or <=
                            {
                                if (vitalsign.Weight == val)
                                {
                                    trigNums.Add(triggersVit[i].EhrTriggerNum.ToString());
                                    break;
                                }
                            }
                            if (arrayVitalItems[j].Contains("<"))
                            {
                                if (vitalsign.Weight < val)
                                {
                                    trigNums.Add(triggersVit[i].EhrTriggerNum.ToString());
                                    break;
                                }
                            }
                            if (arrayVitalItems[j].Contains(">"))
                            {
                                if (vitalsign.Weight > val)
                                {
                                    trigNums.Add(triggersVit[i].EhrTriggerNum.ToString());
                                    break;
                                }
                            }
                            break;

                        case "BMI":
                            float BMI = Vitalsigns.CalcBMI(vitalsign.Weight, vitalsign.Height);
                            if (arrayVitalItems[j].Contains("="))                                             //=, >=, or <=
                            {
                                if (BMI == val)
                                {
                                    trigNums.Add(triggersVit[i].EhrTriggerNum.ToString());
                                    break;
                                }
                            }
                            if (arrayVitalItems[j].Contains("<"))
                            {
                                if (BMI < val)
                                {
                                    trigNums.Add(triggersVit[i].EhrTriggerNum.ToString());
                                    break;
                                }
                            }
                            if (arrayVitalItems[j].Contains(">"))
                            {
                                if (BMI > val)
                                {
                                    trigNums.Add(triggersVit[i].EhrTriggerNum.ToString());
                                    break;
                                }
                            }
                            break;

                        case "BP":
                            //TODO
                            break;
                        }                //end switch
                    }
                }                        //End Triggers Vit
                trigNums.Add("-1");      //to ensure the querry is valid.
                command = "SELECT * FROM ehrTrigger WHERE EhrTriggerNum IN (" + String.Join(",", trigNums) + ")";
                break;

            default:
                //command="SELECT * FROM ehrtrigger WHERE false";//should not return any results.
                return(null);

                                        #if DEBUG
                throw new Exception(triggerObject.GetType().ToString() + " object not implemented as intervention trigger yet. Add to the list above to handle.");
                                        #endif
                //break;
            }
            List <EhrTrigger> listEhrTriggers = Crud.EhrTriggerCrud.SelectMany(command);
            if (listEhrTriggers.Count == 0)
            {
                return(null);               //no triggers matched.
            }
            //Check for MatchCardinality.One type triggers.----------------------------------------------------------------------------
            for (int i = 0; i < listEhrTriggers.Count; i++)
            {
                if (listEhrTriggers[i].Cardinality != MatchCardinality.One)
                {
                    continue;
                }
                string triggerMessage = listEhrTriggers[i].Description + ":\r\n"; //Example:"Patient over 55:\r\n"
                triggerMessage += triggerObjectMessage;                           //Example:"  -Patient Age 67\r\n"
                List <object> ListObjectMatches = new List <object>();
                ListObjectMatches.Add(triggerObject);
                CDSIntervention cdsi = new CDSIntervention();
                cdsi.EhrTrigger          = listEhrTriggers[i];
                cdsi.InterventionMessage = triggerMessage;
                cdsi.TriggerObjects      = ListObjectMatches;
                retVal.Add(cdsi);
            }
            //Fill object lists to be checked-------------------------------------------------------------------------------------------------
            List <Allergy>    ListAllergy    = Allergies.GetAll(PatCur.PatNum, false);
            List <Disease>    ListDisease    = Diseases.Refresh(PatCur.PatNum, true);
            List <DiseaseDef> ListDiseaseDef = new List <DiseaseDef>();
            List <EhrLab>     ListEhrLab     = EhrLabs.GetAllForPat(PatCur.PatNum);
            //List<EhrLabResult> ListEhrLabResults=null;//Lab results are stored in a list in the EhrLab object.
            List <MedicationPat> ListMedicationPat = MedicationPats.Refresh(PatCur.PatNum, false);
            List <AllergyDef>    ListAllergyDef    = new List <AllergyDef>();
            for (int i = 0; i < ListAllergy.Count; i++)
            {
                ListAllergyDef.Add(AllergyDefs.GetOne(ListAllergy[i].AllergyDefNum));
            }
            for (int i = 0; i < ListDisease.Count; i++)
            {
                ListDiseaseDef.Add(DiseaseDefs.GetItem(ListDisease[i].DiseaseDefNum));
            }
            for (int i = 0; i < listEhrTriggers.Count; i++)
            {
                if (listEhrTriggers[i].Cardinality == MatchCardinality.One)
                {
                    continue;                    //we handled these above.
                }
                string triggerMessage = listEhrTriggers[i].Description + ":\r\n";
                triggerMessage += triggerObjectMessage;
                List <object> ListObjectMatches = new List <object>();            //Allergy, Disease, LabPanels, MedicationPat, Patient, VaccinePat
                ListObjectMatches.Add(triggerObject);
                //Allergy-----------------------------------------------------------------------------------------------------------------------
                //allergy.snomedreaction
                //allergy.AllergyDefNum>>AllergyDef.SnomedType
                //allergy.AllergyDefNum>>AllergyDef.SnomedAllergyTo
                //allergy.AllergyDefNum>>AllergyDef.MedicationNum>>Medication.RxCui
                //Disease-----------------------------------------------------------------------------------------------------------------------
                //Disease.DiseaseDefNum>>DiseaseDef.ICD9Code
                //Disease.DiseaseDefNum>>DiseaseDef.SnomedCode
                //Disease.DiseaseDefNum>>DiseaseDef.Icd10Code
                //LabPanels---------------------------------------------------------------------------------------------------------------------
                //LabPanel.LabPanelNum<<LabResult.TestId (Loinc)
                //LabPanel.LabPanelNum<<LabResult.ObsValue (Loinc)
                //LabPanel.LabPanelNum<<LabResult.ObsRange (Loinc)
                //MedicationPat-----------------------------------------------------------------------------------------------------------------
                //MedicationPat.RxCui
                //MedicationPat.MedicationNum>>Medication.RxCui
                //Patient>>Demographics---------------------------------------------------------------------------------------------------------
                //Patient.Gender
                //Patient.Birthdate (Loinc age?)
                //Patient.SmokingSnoMed
                //RxPat-------------------------------------------------------------------------------------------------------------------------
                //Do not check RxPat. It is useless.
                //VaccinePat--------------------------------------------------------------------------------------------------------------------
                //VaccinePat.VaccineDefNum>>VaccineDef.CVXCode
                //VitalSign---------------------------------------------------------------------------------------------------------------------
                //VitalSign.Height (Loinc)
                //VitalSign.Weight (Loinc)
                //VitalSign.BpSystolic (Loinc)
                //VitalSign.BpDiastolic (Loinc)
                //VitalSign.WeightCode (Snomed)
                //VitalSign.PregDiseaseNum (Snomed)
                //Use object matches to check if required conditions are met-------------------------------------------------------------------------------
                switch (listEhrTriggers[i].Cardinality)
                {
                case MatchCardinality.One:
                    //should never get here, handled above.
                    continue;

                case MatchCardinality.OneOfEachCategory:                        //falls through to two or more, but then branches at the end of the case statement.
                case MatchCardinality.TwoOrMore:
                    //if(ListObjectMatches.Count<2) {
                    //	continue;//Must match at least two objects for this category.
                    //}
                    //Medication
                    for (int m = 0; m < ListMedicationPat.Count; m++)
                    {
                        if (listEhrTriggers[i].MedicationNumList.Contains(" " + ListMedicationPat[m].MedicationNum + " "))
                        {
                            ListObjectMatches.Add(ListMedicationPat[m]);
                            continue;
                        }
                        if (ListMedicationPat[m].RxCui != 0 &&
                            listEhrTriggers[i].RxCuiList.Contains(" " + ListMedicationPat[m].RxCui + " "))
                        {
                            ListObjectMatches.Add(ListMedicationPat[m]);
                            continue;
                        }
                    }
                    //Allergy
                    for (int a = 0; a < ListAllergy.Count; a++)
                    {
                        if (listEhrTriggers[i].AllergyDefNumList.Contains(" " + ListAllergy[a].AllergyDefNum + " "))
                        {
                            ListObjectMatches.Add(AllergyDefs.GetOne(ListAllergy[a].AllergyDefNum));
                            triggerMessage += "  -(Allergy) " + AllergyDefs.GetOne(ListAllergy[a].AllergyDefNum).Description + "\r\n";
                            continue;
                        }
                    }
                    //Problem
                    for (int d = 0; d < ListDiseaseDef.Count; d++)
                    {
                        if (ListDiseaseDef[d].ICD9Code != "" &&
                            listEhrTriggers[i].ProblemIcd9List.Contains(" " + ListDiseaseDef[d].ICD9Code + " "))
                        {
                            ListObjectMatches.Add(ListDiseaseDef[d]);
                            triggerMessage += "  -(ICD9) " + ICD9s.GetByCode(ListDiseaseDef[d].ICD9Code).Description + "\r\n";
                            continue;
                        }
                        if (ListDiseaseDef[d].Icd10Code != "" &&
                            listEhrTriggers[i].ProblemIcd10List.Contains(" " + ListDiseaseDef[d].Icd10Code + " "))
                        {
                            ListObjectMatches.Add(ListDiseaseDef[d]);
                            triggerMessage += "  -(Icd10) " + Icd10s.GetByCode(ListDiseaseDef[d].Icd10Code).Description + "\r\n";
                            continue;
                        }
                        if (ListDiseaseDef[d].SnomedCode != "" &&
                            listEhrTriggers[i].ProblemSnomedList.Contains(" " + ListDiseaseDef[d].SnomedCode + " "))
                        {
                            ListObjectMatches.Add(ListDiseaseDef[d]);
                            triggerMessage += "  -(Snomed) " + Snomeds.GetByCode(ListDiseaseDef[d].SnomedCode).Description + "\r\n";
                            continue;
                        }
                        if (listEhrTriggers[i].ProblemDefNumList.Contains(" " + ListDiseaseDef[d].DiseaseDefNum + " "))
                        {
                            ListObjectMatches.Add(ListDiseaseDef[d]);
                            triggerMessage += "  -(Problem Def) " + ListDiseaseDef[d].DiseaseName + "\r\n";
                            continue;
                        }
                    }
                    //Vital
                    //TODO
                    //Age
                    //TODO
                    //Gender
                    //TODO
                    //Lab Result
                    for (int l = 0; l < ListEhrLab.Count; l++)
                    {
                        for (int r = 0; r < ListEhrLab[l].ListEhrLabResults.Count; r++)
                        {
                            if (listEhrTriggers[i].LabLoincList.Contains(" " + ListEhrLab[l].ListEhrLabResults[r].ObservationIdentifierID + " ") ||
                                listEhrTriggers[i].LabLoincList.Contains(" " + ListEhrLab[l].ListEhrLabResults[r].ObservationIdentifierIDAlt + " "))
                            {
                                ListObjectMatches.Add(ListEhrLab[l].ListEhrLabResults[r]);
                                if (ListEhrLab[l].ListEhrLabResults[r].ObservationIdentifierID != "")                                       //should almost always be the case.
                                {
                                    triggerMessage += "  -(LOINC) " + Loincs.GetByCode(ListEhrLab[l].ListEhrLabResults[r].ObservationIdentifierID).NameShort + "\r\n";
                                }
                                else if (ListEhrLab[l].ListEhrLabResults[r].ObservationIdentifierID != "")
                                {
                                    triggerMessage += "  -(LOINC) " + Loincs.GetByCode(ListEhrLab[l].ListEhrLabResults[r].ObservationIdentifierIDAlt).NameShort + "\r\n";
                                }
                                else if (ListEhrLab[l].ListEhrLabResults[r].ObservationIdentifierText != "")
                                {
                                    triggerMessage += "  -(LOINC) " + ListEhrLab[l].ListEhrLabResults[r].ObservationIdentifierText + "\r\n";
                                }
                                else if (ListEhrLab[l].ListEhrLabResults[r].ObservationIdentifierTextAlt != "")
                                {
                                    triggerMessage += "  -(LOINC) " + ListEhrLab[l].ListEhrLabResults[r].ObservationIdentifierTextAlt + "\r\n";
                                }
                                else if (ListEhrLab[l].ListEhrLabResults[r].ObservationIdentifierID != "")
                                {
                                    triggerMessage += "  -(LOINC) " + ListEhrLab[l].ListEhrLabResults[r].ObservationIdentifierID + "\r\n";
                                }
                                else if (ListEhrLab[l].ListEhrLabResults[r].ObservationIdentifierIDAlt != "")
                                {
                                    triggerMessage += "  -(LOINC) " + ListEhrLab[l].ListEhrLabResults[r].ObservationIdentifierIDAlt + "\r\n";
                                }
                                else if (ListEhrLab[l].ListEhrLabResults[r].ObservationIdentifierTextOriginal != "")
                                {
                                    triggerMessage += "  -(LOINC) " + ListEhrLab[l].ListEhrLabResults[r].ObservationIdentifierTextOriginal + "\r\n";
                                }
                                else
                                {
                                    triggerMessage += "  -(LOINC) Unknown code.\r\n";                                          //should never happen.
                                }
                                continue;
                            }
                        }
                    }
                    ListObjectMatches = RemoveDuplicateObjectsHelper(ListObjectMatches);
                    if (listEhrTriggers[i].Cardinality == MatchCardinality.TwoOrMore && ListObjectMatches.Count < 2)
                    {
                        continue;                                //next trigger, do not add to retVal
                    }
                    if (listEhrTriggers[i].Cardinality == MatchCardinality.OneOfEachCategory && !OneOfEachCategoryHelper(listEhrTriggers[i], ListObjectMatches))
                    {
                        continue;
                    }
                    break;

                case MatchCardinality.All:
                    bool          allConditionsMet = true;
                    List <string> MatchedCodes     = getCodesFromListHelper(ListObjectMatches);                     //new List<string>();
                    //Match all Icd9Codes-------------------------------------------------------------------------------------------------------------------------------------------------
                    string[] arrayIcd9Codes = listEhrTriggers[i].ProblemIcd9List.Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries);
                    for (int c = 0; c < arrayIcd9Codes.Length; c++)
                    {
                        if (MatchedCodes.Contains(arrayIcd9Codes[i]))
                        {
                            continue;                                    //found required code
                        }
                        //required code not found, set allConditionsMet to false and continue to next trigger
                        allConditionsMet = false;
                        break;
                    }
                    if (!allConditionsMet)
                    {
                        continue;                                //next trigger
                    }
                    //Match all Icd10Codes------------------------------------------------------------------------------------------------------------------------------------------------
                    string[] arrayIcd10Codes = listEhrTriggers[i].ProblemIcd10List.Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries);
                    for (int c = 0; c < arrayIcd10Codes.Length; c++)
                    {
                        if (MatchedCodes.Contains(arrayIcd10Codes[i]))
                        {
                            continue;                                    //found required code
                        }
                        //required code not found, set allConditionsMet to false and continue to next trigger
                        allConditionsMet = false;
                        break;
                    }
                    if (!allConditionsMet)
                    {
                        continue;                                //next trigger
                    }
                    //Match all SnomedCodes-----------------------------------------------------------------------------------------------------------------------------------------------
                    string[] arraySnomedCodes = listEhrTriggers[i].ProblemSnomedList.Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries);
                    for (int c = 0; c < arraySnomedCodes.Length; c++)
                    {
                        if (MatchedCodes.Contains(arraySnomedCodes[i]))
                        {
                            continue;                                    //found required code
                        }
                        //required code not found, set allConditionsMet to false and continue to next trigger
                        allConditionsMet = false;
                        break;
                    }
                    if (!allConditionsMet)
                    {
                        continue;                                //next trigger
                    }
                    //Match all CvxCodes--------------------------------------------------------------------------------------------------------------------------------------------------
                    string[] arrayCvxCodes = listEhrTriggers[i].CvxList.Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries);
                    for (int c = 0; c < arrayCvxCodes.Length; c++)
                    {
                        if (MatchedCodes.Contains(arrayCvxCodes[i]))
                        {
                            continue;                                    //found required code
                        }
                        //required code not found, set allConditionsMet to false and continue to next trigger
                        allConditionsMet = false;
                        break;
                    }
                    if (!allConditionsMet)
                    {
                        continue;                                //next trigger, do not add to retval
                    }
                    //Match all LoincCodes------------------------------------------------------------------------------------------------------------------------------------------------
                    string[] arrayLoincCodes = listEhrTriggers[i].LabLoincList.Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries);
                    for (int c = 0; c < arrayLoincCodes.Length; c++)
                    {
                        if (MatchedCodes.Contains(arrayLoincCodes[i]))
                        {
                            continue;                                    //found required code
                        }
                        //required code not found, set allConditionsMet to false and continue to next trigger
                        allConditionsMet = false;
                        break;
                    }
                    if (!allConditionsMet)
                    {
                        continue;                                //next trigger, do not add to retval
                    }
                    //TODO:with values
                    //Match all Vitals----------------------------------------------------------------------------------------------------------------------------------------------------
                    //TODO:with values
                    //Match all Demographics---------------------------------------------------------------------------------------------------------------------------------------------
                    //if(listEhrTriggers[i].DemographicAgeGreaterThan!=0){
                    //	if(PatCur.Birthdate.Year>1880 && PatCur.Birthdate.AddYears(listEhrTriggers[i].DemographicAgeGreaterThan)>DateTime.Now){//patient too young
                    //		continue;//next trigger
                    //	}
                    //}
                    //if(listEhrTriggers[i].DemographicAgeLessThan!=0){
                    //	if(PatCur.Birthdate.Year>1880 && PatCur.Birthdate.AddYears(listEhrTriggers[i].DemographicAgeGreaterThan)<DateTime.Now){//patient too old
                    //		continue;//next trigger
                    //	}
                    //}
                    //if(listEhrTriggers[i].DemographicGender!=""){
                    //	if(!listEhrTriggers[i].DemographicGender.Contains(PatCur.Gender.ToString())){//Patient Gender not in gender list of trigger
                    //		continue;//next trigger
                    //	}
                    //}
                    //TODO: construct trigger message using all the codes in the trigger.
                    break;
                }                //end switch trigger cardinality
                //retVal.Add(triggerMessage,ListObjectMatches);
                CDSIntervention cdsi = new CDSIntervention();
                cdsi.EhrTrigger          = listEhrTriggers[i];
                cdsi.InterventionMessage = triggerMessage;
                cdsi.TriggerObjects      = ListObjectMatches;
                retVal.Add(cdsi);
            }            //end triggers
            return(retVal);
        }