Ejemplo n.º 1
0
        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.");
        }
Ejemplo n.º 2
0
 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;
 }