private void butIntervention_Click(object sender, EventArgs e)
        {
            if (comboInterventionCode.SelectedIndex < 0)
            {
                MsgBox.Show(this, "You must select an intervention code.");
                return;
            }
            EhrCode  iCodeCur = _listInterventionCodes[comboInterventionCode.SelectedIndex];
            DateTime dateCur  = PIn.Date(textDateIntervention.Text);

            if (iCodeCur.CodeSystem == "RXNORM" && !checkPatientDeclined.Checked)           //if patient declines the medication, enter as a declined intervention
            //codeVal will be RxCui of medication, see if it already exists in Medication table
            {
                Medication medCur = Medications.GetMedicationFromDbByRxCui(PIn.Long(iCodeCur.CodeValue));
                if (medCur == null)               //no med with this RxCui, create one
                {
                    medCur = new Medication();
                    Medications.Insert(medCur);                    //so that we will have the primary key
                    medCur.GenericNum = medCur.MedicationNum;
                    medCur.RxCui      = PIn.Long(iCodeCur.CodeValue);
                    medCur.MedName    = RxNorms.GetDescByRxCui(iCodeCur.CodeValue);
                    Medications.Update(medCur);
                    Medications.RefreshCache();                    //refresh cache to include new medication
                }
                MedicationPat medPatCur = new MedicationPat();
                medPatCur.PatNum        = PatCur.PatNum;
                medPatCur.ProvNum       = PatCur.PriProv;
                medPatCur.MedicationNum = medCur.MedicationNum;
                medPatCur.RxCui         = medCur.RxCui;
                medPatCur.DateStart     = dateCur;
                FormMedPat FormMP = new FormMedPat();
                FormMP.MedicationPatCur = medPatCur;
                FormMP.IsNew            = true;
                FormMP.ShowDialog();
                if (FormMP.DialogResult != DialogResult.OK)
                {
                    return;
                }
                if (FormMP.MedicationPatCur.DateStart.Date < dateCur.AddMonths(-6).Date || FormMP.MedicationPatCur.DateStart.Date > dateCur.Date)
                {
                    MsgBox.Show(this, "The medication order just entered is not within the 6 months prior to the date of this intervention.  You can modify the "
                                + "date of the medication order in the patient's medical history section.");
                }
            }
            else
            {
                Intervention iCur = new Intervention();
                iCur.PatNum        = PatCur.PatNum;
                iCur.ProvNum       = PatCur.PriProv;
                iCur.DateEntry     = dateCur;
                iCur.CodeValue     = iCodeCur.CodeValue;
                iCur.CodeSystem    = iCodeCur.CodeSystem;
                iCur.CodeSet       = InterventionCodeSet.TobaccoCessation;
                iCur.IsPatDeclined = checkPatientDeclined.Checked;
                Interventions.Insert(iCur);
            }
            comboInterventionCode.SelectedIndex = -1;
            FillGridInterventions();
        }
        private void butOK_Click(object sender, EventArgs e)
        {
            if (_listMedicationPatReconcile.Count == 0)
            {
                if (!MsgBox.Show(this, true, "The reconcile list is empty which will cause all existing medications to be removed.  Continue?"))
                {
                    return;
                }
            }
            MedicationPat medP;
            bool          isActive;

            //Discontinue any current medications that are not present in the reconcile list.
            for (int i = 0; i < _listMedicationPatCur.Count; i++)       //Start looping through all current medications
            {
                isActive = false;
                medP     = _listMedicationPatCur[i];
                for (int j = 0; j < _listMedicationPatReconcile.Count; j++)                                                                                                             //Compare each reconcile medication to the current medication
                {
                    if (medP.RxCui > 0 && medP.RxCui == _listMedicationPatReconcile[j].RxCui && _listMedicationPatReconcile[j].MedicationNum == _listMedicationPatCur[i].MedicationNum) //Has an RxNorm code and they are equal
                    {
                        isActive = true;
                        break;
                    }
                }
                if (!isActive)                                        //Update current medications.
                {
                    _listMedicationPatCur[i].DateStop = DateTime.Now; //Set the current DateStop to today (to set the medication as discontinued)
                    MedicationPats.Update(_listMedicationPatCur[i]);
                }
            }
            //Always update every current medication for the patient so that DateTStamp reflects the last reconcile date.
            if (_listMedicationPatCur.Count > 0)
            {
                MedicationPats.ResetTimeStamps(_patCur.PatNum, true);
            }
            Medication med;
            int        index;

            for (int j = 0; j < _listMedicationPatReconcile.Count; j++)
            {
                index = ListMedicationPatNew.IndexOf(_listMedicationPatReconcile[j]);
                if (index < 0)
                {
                    continue;
                }
                if (_listMedicationPatReconcile[j] == ListMedicationPatNew[index])
                {
                    med = Medications.GetMedicationFromDbByRxCui(_listMedicationPatReconcile[j].RxCui);
                    if (med == null)
                    {
                        med         = new Medication();
                        med.MedName = ListMedicationPatNew[index].MedDescript;
                        med.RxCui   = ListMedicationPatNew[index].RxCui;
                        ListMedicationPatNew[index].MedicationNum = Medications.Insert(med);
                        med.GenericNum = med.MedicationNum;
                        Medications.Update(med);
                    }
                    else
                    {
                        ListMedicationPatNew[index].MedicationNum = med.MedicationNum;
                    }
                    ListMedicationPatNew[index].ProvNum = 0;                  //Since imported, set provnum to 0 so it does not affect CPOE.
                    MedicationPats.Insert(ListMedicationPatNew[index]);
                }
            }
            EhrMeasureEvent newMeasureEvent = new EhrMeasureEvent();

            newMeasureEvent.DateTEvent = DateTime.Now;
            newMeasureEvent.EventType  = EhrMeasureEventType.MedicationReconcile;
            newMeasureEvent.PatNum     = _patCur.PatNum;
            newMeasureEvent.MoreInfo   = "";
            EhrMeasureEvents.Insert(newMeasureEvent);
            for (int inter = 0; inter < _listMedicationPatReconcile.Count; inter++)
            {
                if (CDSPermissions.GetForUser(Security.CurUser.UserNum).ShowCDS&& CDSPermissions.GetForUser(Security.CurUser.UserNum).MedicationCDS)
                {
                    Medication          medInter = Medications.GetMedicationFromDbByRxCui(_listMedicationPatReconcile[inter].RxCui);
                    FormCDSIntervention FormCDSI = new FormCDSIntervention();
                    FormCDSI.ListCDSI = EhrTriggers.TriggerMatch(medInter, _patCur);
                    FormCDSI.ShowIfRequired(false);
                }
            }
            DialogResult = DialogResult.OK;
        }
Beispiel #3
0
        private void butOK_Click(object sender, EventArgs e)
        {
            //validate--------------------------------------
            DateTime date;

            if (textDate.Text == "")
            {
                MsgBox.Show(this, "Please enter a date.");
                return;
            }
            try {
                date = DateTime.Parse(textDate.Text);
            }
            catch {
                MsgBox.Show(this, "Please fix date first.");
                return;
            }
            string codeVal = "";
            string codeSys = "";

            if (gridMain.GetSelectedIndex() == -1)           //no intervention code selected
            {
                MsgBox.Show(this, "You must select a code for this intervention.");
                return;
            }
            else
            {
                codeVal = listCodes[gridMain.GetSelectedIndex()].CodeValue;
                codeSys = listCodes[gridMain.GetSelectedIndex()].CodeSystem;
            }
            //save--------------------------------------
            //Intervention grid may contain medications, have to insert a new med if necessary and load FormMedPat for user to input data
            if (codeSys == "RXNORM" && !checkPatientDeclined.Checked)
            {
                //codeVal will be RxCui of medication, see if it already exists in Medication table
                Medication medCur = Medications.GetMedicationFromDbByRxCui(PIn.Long(codeVal));
                if (medCur == null)               //no med with this RxCui, create one
                {
                    medCur = new Medication();
                    Medications.Insert(medCur);                    //so that we will have the primary key
                    medCur.GenericNum = medCur.MedicationNum;
                    medCur.RxCui      = PIn.Long(codeVal);
                    medCur.MedName    = RxNorms.GetDescByRxCui(codeVal);
                    Medications.Update(medCur);
                    Medications.RefreshCache();                    //refresh cache to include new medication
                }
                MedicationPat medPatCur = new MedicationPat();
                medPatCur.PatNum        = InterventionCur.PatNum;
                medPatCur.ProvNum       = InterventionCur.ProvNum;
                medPatCur.MedicationNum = medCur.MedicationNum;
                medPatCur.RxCui         = medCur.RxCui;
                medPatCur.DateStart     = date;
                FormMedPat FormMP = new FormMedPat();
                FormMP.MedicationPatCur = medPatCur;
                FormMP.IsNew            = true;
                FormMP.ShowDialog();
                if (FormMP.DialogResult != DialogResult.OK)
                {
                    return;
                }
                if (FormMP.MedicationPatCur.DateStart.Date < InterventionCur.DateEntry.AddMonths(-6).Date || FormMP.MedicationPatCur.DateStart.Date > InterventionCur.DateEntry.Date)
                {
                    MsgBox.Show(this, "The medication order just entered is not within the 6 months prior to the date of this intervention.  You can modify the date of the medication order in the patient's medical history section.");
                }
                DialogResult = DialogResult.OK;
                return;
            }
            InterventionCur.DateEntry     = date;
            InterventionCur.CodeValue     = codeVal;
            InterventionCur.CodeSystem    = codeSys;
            InterventionCur.Note          = textNote.Text;
            InterventionCur.IsPatDeclined = checkPatientDeclined.Checked;
            string selectedCodeSet = comboCodeSet.SelectedItem.ToString().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)[0];

            if (IsAllTypes)                   //CodeSet will be set by calling function unless showing all types, in which case we need to determine which InterventionCodeSet to assign
            {
                if (selectedCodeSet == "All") //All types showing and set to All, have to determine which InterventionCodeSet this code belongs to
                {
                    List <string> listVSFound = new List <string>();
                    foreach (KeyValuePair <string, string> kvp in dictValueCodeSets)
                    {
                        List <EhrCode> listCodes = EhrCodes.GetForValueSetOIDs(new List <string> {
                            kvp.Value
                        }, true);
                        for (int i = 0; i < listCodes.Count; i++)
                        {
                            if (listCodes[i].CodeValue == codeVal)
                            {
                                listVSFound.Add(kvp.Key);
                                break;
                            }
                        }
                    }
                    if (listVSFound.Count > 1)                   //Selected code found in more than one value set, ask the user which InterventionCodeSet to assign to this intervention
                    {
                        InputBox chooseSet = new InputBox(Lan.g(this, "The selected code belongs to more than one intervention code set.  Select the code set to assign to this intervention from the list below."), listVSFound);
                        if (chooseSet.ShowDialog() != DialogResult.OK)
                        {
                            return;
                        }
                        if (chooseSet.comboSelection.SelectedIndex == -1)
                        {
                            MsgBox.Show(this, "You must select an intervention code set for the selected code.");
                            return;
                        }
                        selectedCodeSet = chooseSet.comboSelection.SelectedItem.ToString().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)[0];
                    }
                    else                      //the code must belong to at least one value set, since count in listVSFound is not greater than 1, it must be a code from exactly one set, use that for the InterventionCodeSet
                    {
                        selectedCodeSet = listVSFound[0].Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)[0];
                    }
                }
                InterventionCur.CodeSet = (InterventionCodeSet)Enum.Parse(typeof(InterventionCodeSet), selectedCodeSet);
            }
            //Nutrition is used for both nutrition and physical activity counseling for children, we have to determine which set this code belongs to
            else if (InterventionCur.CodeSet == InterventionCodeSet.Nutrition && selectedCodeSet != "Nutrition") //Nutrition set by calling form, user is showing all or physical activity codes only
            {
                if (selectedCodeSet == "All")                                                                    //showing all codes from Nutrition and PhysicalActivity interventions, determine which set it belongs to
                //No codes exist in both code sets, so if it is not in the PhysicalActivity code set, we can safely assume this is a Nutrition intervention
                {
                    List <EhrCode> listCodes = EhrCodes.GetForValueSetOIDs(new List <string> {
                        dictValueCodeSets[InterventionCodeSet.PhysicalActivity.ToString() + " Counseling"]
                    }, true);
                    for (int i = 0; i < listCodes.Count; i++)
                    {
                        if (listCodes[i].CodeValue == codeVal)
                        {
                            InterventionCur.CodeSet = InterventionCodeSet.PhysicalActivity;
                            break;
                        }
                    }
                }
                else
                {
                    InterventionCur.CodeSet = InterventionCodeSet.PhysicalActivity;
                }
            }
            else
            {
                //if not all types, and not Nutrition with All or PhysicalActivity selected in combo box, the code set sent in by calling form will remain the code set for this intervention
            }
            if (InterventionCur.IsNew)
            {
                Interventions.Insert(InterventionCur);
            }
            else
            {
                Interventions.Update(InterventionCur);
            }
            DialogResult = DialogResult.OK;
        }