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 butConvertGeneric_Click(object sender, EventArgs e) { if (gridMissing.SelectedIndices.Length == 0) { MsgBox.Show(this, "Please select an item from the list before attempting to convert."); return; } List <MedicationPat> listMedPats = (List <MedicationPat>)gridMissing.Rows[gridMissing.SelectedIndices[0]].Tag; List <Medication> listRxCuiMeds = null; Medication medGeneric = null; if (listMedPats[0].RxCui != 0) { listRxCuiMeds = Medications.GetAllMedsByRxCui(listMedPats[0].RxCui); medGeneric = listRxCuiMeds.FirstOrDefault(x => x.MedicationNum == x.GenericNum); if (medGeneric == null && listRxCuiMeds.FirstOrDefault(x => x.MedicationNum != x.GenericNum) != null) //A Brand Medication exists with matching RxCui. { MsgBox.Show(this, "A brand medication matching the RxNorm of the selected medication already exists in the medication list. " + "You cannot create a generic for the selected medication. Use the Convert to Brand button instead."); return; } } if (listRxCuiMeds == null || listRxCuiMeds.Count == 0) //No medications found matching the RxCui { medGeneric = new Medication(); medGeneric.MedName = listMedPats[0].MedDescript; medGeneric.RxCui = listMedPats[0].RxCui; Medications.Insert(medGeneric); //To get primary key. medGeneric.GenericNum = medGeneric.MedicationNum; Medications.Update(medGeneric); //Now that we have primary key, flag the medication as a generic. FormMedicationEdit FormME = new FormMedicationEdit(); FormME.MedicationCur = medGeneric; FormME.IsNew = true; FormME.ShowDialog(); //This window refreshes the Medication cache if the user clicked OK. if (FormME.DialogResult != DialogResult.OK) { return; //User canceled. } } else if (medGeneric != null && !MsgBox.Show(this, true, "A generic medication matching the RxNorm of the selected medication already exists in the medication list. " + "Click OK to use the existing medication as the generic for the selected medication, or click Cancel to abort.")) { return; } Cursor = Cursors.WaitCursor; MedicationPats.UpdateMedicationNumForMany(medGeneric.MedicationNum, listMedPats.Select(x => x.MedicationPatNum).ToList()); FillTab(); Cursor = Cursors.Default; MsgBox.Show(this, "Done."); }
private void butOK_Click(object sender, System.EventArgs e) { //generic num already handled MedicationCur.MedName = textMedName.Text; if (MedicationCur.MedicationNum == MedicationCur.GenericNum) { MedicationCur.Notes = textNotes.Text; } else { MedicationCur.Notes = ""; } Medications.Update(MedicationCur); DialogResult = DialogResult.OK; }
private void butOK_Click(object sender, System.EventArgs e) { //generic num already handled MedicationCur.MedName = textMedName.Text; if (MedicationCur.MedicationNum == MedicationCur.GenericNum) { MedicationCur.Notes = textNotes.Text; } else { MedicationCur.Notes = ""; } //MedicationCur has its RxCui set when the butRxNormSelect button is pressed. Medications.Update(MedicationCur); DialogResult = DialogResult.OK; }
///<summary>Inserts the given medNew. ///Given medGennamePair is a medication that we are checking and the given generic name if set. ///ListMedsExisting is used to identify the GenericNum for medNew.</summary> private static void InsertNewMed(ODTuple <Medication, string> medGenNamePair, List <Medication> listMedsExisting) { Medication medNew = medGenNamePair.Item1; string genericName = medGenNamePair.Item2; long genNum = listMedsExisting.FirstOrDefault(x => x.MedName == genericName)?.MedicationNum ?? 0; if (genNum != 0) //Found a match. { medNew.GenericNum = genNum; } Medications.Insert(medNew); //Assigns new primary key. if (genNum == 0) //Found no match initially, assume given medication is the generic. { medNew.GenericNum = medNew.MedicationNum; Medications.Update(medNew); } listMedsExisting.Add(medNew); //Keep in memory list and database in sync. }
private void butOK_Click(object sender, System.EventArgs e) { //generic num already handled MedicationCur.MedName = textMedName.Text; if (MedicationCur.MedName == "") { MsgBox.Show(this, "Not allowed to save a medication without a Drug Name."); return; } if (CultureInfo.CurrentCulture.Name.EndsWith("US")) //United States { if (MedicationCur.RxCui == 0 && !MsgBox.Show(this, true, "Warning: RxNorm was not picked. " + "RxNorm uniquely identifies drugs in the United States and helps you keep your medications organized. " + "RxNorm is used to send information to and from eRx if you are using or plan to use eRx.\r\n" + "Click OK to continue without an RxNorm, or click Cancel to stay in this window.")) { return; } else if (MedicationCur.RxCui != 0) { List <Medication> listExistingMeds = Medications.GetAllMedsByRxCui(MedicationCur.RxCui); if (listExistingMeds.FindAll(x => x.MedicationNum != MedicationCur.MedicationNum).Count > 0) { MsgBox.Show(this, "A medication in the medication list is already using the selected RxNorm.\r\n" + "Please select a different RxNorm or use the other medication instead."); return; } } } if (MedicationCur.MedicationNum == MedicationCur.GenericNum) { MedicationCur.Notes = textNotes.Text; } else { MedicationCur.Notes = ""; } //MedicationCur has its RxCui set when the butRxNormSelect button is pressed. //The following behavior must match what happens when the user clicks the RxNorm column in FormMedications to pick RxCui. Medications.Update(MedicationCur); MedicationPats.UpdateRxCuiForMedication(MedicationCur.MedicationNum, MedicationCur.RxCui); DataValid.SetInvalid(InvalidType.Medications); DialogResult = DialogResult.OK; }
private void gridAllMedications_CellClick(object sender, ODGridClickEventArgs e) { Medication med = (Medication)gridAllMedications.Rows[e.Row].Tag; if (CultureInfo.CurrentCulture.Name.EndsWith("US") && e.Col == 3) //United States RxNorm Column { FormRxNorms formRxNorm = new FormRxNorms(); formRxNorm.IsSelectionMode = true; formRxNorm.InitSearchCodeOrDescript = med.MedName; formRxNorm.ShowDialog(); if (formRxNorm.DialogResult == DialogResult.OK) { med.RxCui = PIn.Long(formRxNorm.SelectedRxNorm.RxCui); //The following behavior mimics FormMedicationEdit OK click. Medications.Update(med); MedicationPats.UpdateRxCuiForMedication(med.MedicationNum, med.RxCui); DataValid.SetInvalid(InvalidType.Medications); } FillTab(); } }
private void butOK_Click(object sender, System.EventArgs e) { //generic num already handled MedicationCur.MedName = textMedName.Text; if (MedicationCur.MedName == "") { MsgBox.Show(this, "Not allowed to save a medication without a Drug Name."); return; } if (MedicationCur.MedicationNum == MedicationCur.GenericNum) { MedicationCur.Notes = textNotes.Text; } else { MedicationCur.Notes = ""; } //MedicationCur has its RxCui set when the butRxNormSelect button is pressed. Medications.Update(MedicationCur); MedicationPats.UpdateRxCuiForMedication(MedicationCur.MedicationNum, MedicationCur.RxCui); DialogResult = DialogResult.OK; }
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; }
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; }