private bool IsValid() { int index = listRestriction.SelectedIndex; if (index != 3) //Not LabResult { textLabValue.Text = ""; } if (index == 4) { textCompareString.Text = ""; } switch (index) { case 0: //Birthdate------------------------------------------------------------------------------------------------------------ try { Convert.ToInt32(textCompareString.Text); //used intead of PIn so that an empty string is not evaluated as 0 } catch { MsgBox.Show(this, "Please enter a valid age."); return(false); } break; case 1: //Disease-------------------------------------------------------------------------------------------------------------- if (textCompareString.Text == "" && textSNOMED.Text == "") { MsgBox.Show(this, "Please enter a valid SNOMED or ICD9 code."); return(false); } if (textCompareString.Text != "") { if (ICD9s.GetByCode(textCompareString.Text) == null) { MsgBox.Show(this, "ICD9 code does not exist in database, pick from list."); return(false); } } if (textSNOMED.Text != "") { if (Snomeds.GetByCode(textSNOMED.Text) == null) { MsgBox.Show(this, "SNOMED code does not exist in database, pick from list."); return(false); } } if (textDateStart.errorProvider1.GetError(textDateStart) != "" || textDateStop.errorProvider1.GetError(textDateStop) != "" ) { MessageBox.Show(Lan.g(this, "Please fix date entry errors.")); return(false); } break; case 2: //Medication----------------------------------------------------------------------------------------------------------- if (textCompareString.Text == "") { MsgBox.Show(this, "Please enter a valid medication."); return(false); } if (Medications.GetMedicationFromDbByName(textCompareString.Text) == null) { MsgBox.Show(this, "Medication does not exist in database, pick from list."); return(false); } if (textDateStart.errorProvider1.GetError(textDateStart) != "" || textDateStop.errorProvider1.GetError(textDateStop) != "" ) { MessageBox.Show(Lan.g(this, "Please fix date entry errors.")); return(false); } break; case 3: //LabResult------------------------------------------------------------------------------------------------------------ if (textCompareString.Text == "") { MsgBox.Show(this, "Please select a valid LOINC Code."); return(false); } if (LOINCs.GetByCode(textCompareString.Text) == null) { MsgBox.Show(this, "LOINC code does not exist in database, pick from list."); return(false); } if (textDateStart.errorProvider1.GetError(textDateStart) != "" || textDateStop.errorProvider1.GetError(textDateStop) != "" ) { MessageBox.Show(Lan.g(this, "Please fix date entry errors.")); return(false); } break; case 4: //Gender--------------------------------------------------------------------------------------------------------------- break; case 5: //CommPref------------------------------------------------------------------------------------------------------------- if (textCompareString.Text == "") { MsgBox.Show(this, "Please enter a communication preference."); return(false); } if (LOINCs.GetByCode(textCompareString.Text) == null) { MsgBox.Show(this, "Communication preference not defined, pick from list."); return(false); } break; case 6: //Allergy-------------------------------------------------------------------------------------------------------------- if (textCompareString.Text == "") { MsgBox.Show(this, "Please enter a valid allergy."); return(false); } if (AllergyDefs.GetByDescription(textCompareString.Text) == null) { MsgBox.Show(this, "Allergy does not exist in database, pick from list."); return(false); } if (textDateStart.errorProvider1.GetError(textDateStart) != "" || textDateStop.errorProvider1.GetError(textDateStop) != "" ) { MessageBox.Show(Lan.g(this, "Please fix date entry errors.")); return(false); } break; } return(true); }