///<summary>Returns true if the import was successful. Imports either a webform or a sheet that was transferred using the CEMT tool. ///Tries to find a matching patient using LName,FName,and DOB. If no matching patient is found automatically, it will allow the user to either ///create a new patient, select an existing patient,delete, or skip the sheet. Call using a try/catch.</summary> private static bool DidImportSheet(WebForms_Sheet webFormsSheet, Sheet sheet, List <WebForms_Sheet> listWebSheets, List <Sheet> listSheets, string cultureName, ref List <long> listSheetIdsForDeletion) { bool isWebForms = webFormsSheet != null && listWebSheets != null; long patNum = 0; string lName = ""; string fName = ""; List <string> listPhoneNumbers = new List <string>(); string email = ""; DateTime bDate = DateTime.MinValue; if (isWebForms) { WebForms_Sheets.ParseWebFormSheet(webFormsSheet, cultureName, out lName, out fName, out bDate, out listPhoneNumbers, out email); } else { Sheets.ParseTransferSheet(sheet, out lName, out fName, out bDate, out listPhoneNumbers, out email); } List <long> listMatchingPats = Patients.GetPatNumsByNameBirthdayEmailAndPhone(lName, fName, bDate, email, listPhoneNumbers); Patient pat = null; if (listMatchingPats.IsNullOrEmpty() || listMatchingPats.Count > 1) //0 or > 1 { List <long> listWebSheetNumsForPat = new List <long>(); if (isWebForms) { List <long> listSheetsToDelete = listSheetIdsForDeletion; listWebSheetNumsForPat = WebForms_Sheets.FindSheetsForPat(webFormsSheet, listWebSheets, cultureName) //Only include web sheets that have not already been imported .Where(x => !listSheetsToDelete.Contains(x)).ToList(); } else //Cemt Import { listWebSheetNumsForPat = Sheets.FindSheetsForPat(sheet, listSheets); } FormPatientPickWebForm FormPpw = new FormPatientPickWebForm(webFormsSheet, listWebSheetNumsForPat.Count, sheet); FormPpw.LnameEntered = lName; FormPpw.FnameEntered = fName; FormPpw.BdateEntered = bDate; FormPpw.HasMoreThanOneMatch = (listMatchingPats.Count > 1); FormPpw.ShowDialog(); if (FormPpw.DialogResult == DialogResult.Cancel) { if (isWebForms) { //user wants to stop importing altogether //we will pick up where we left off here next time WebForms_Sheets.DeleteSheetData(listSheetIdsForDeletion.Distinct().ToList()); } return(false); // only false when user wants to stop importing } else if (FormPpw.DialogResult == DialogResult.Ignore) { if (FormPpw.IsDiscardAll) { //user wants to delete all webforms for this patient. Mark them for deletion. listSheetIdsForDeletion.AddRange(listWebSheetNumsForPat); } return(true); //continue on to the next one } patNum = FormPpw.SelectedPatNum; //might be zero to indicate new patient } else //Exactly one match was found so make a log entry what the match was. { patNum = listMatchingPats[0]; pat = Patients.GetPat(patNum); //Security log for OD automatically importing a sheet into a patient. string logText; if (isWebForms) { logText = Lan.g("FormWebForms", "Web form import from:"); } else { logText = Lan.g("FormWebForms", "CEMT patient transfer import from:"); } logText += " " + lName + ", " + fName + " " + bDate.ToShortDateString() + "\r\n" + Lan.g("FormWebForms", "Auto imported into:") + " " + pat.LName + ", " + pat.FName + " " + pat.Birthdate.ToShortDateString(); SecurityLogs.MakeLogEntry(Permissions.SheetEdit, patNum, logText); } if (patNum == 0) { pat = CreatePatient(lName, fName, bDate, webFormsSheet, sheet, cultureName); patNum = pat.PatNum; //Security log for user creating a new patient. string logText; if (isWebForms) { logText = Lan.g("FormWebForms", "Web form import from:"); } else { logText = Lan.g("FormWebForms", "CEMT patient transfer import from:"); } logText += " " + lName + ", " + fName + " " + bDate.ToShortDateString() + "\r\n" + Lan.g("FormWebForms", "User created new pat:") + " " + pat.LName + ", " + pat.FName + " " + pat.Birthdate.ToShortDateString(); SecurityLogs.MakeLogEntry(Permissions.SheetEdit, patNum, logText); } else if (pat == null) { pat = Patients.GetPat(patNum); } //We should probably make a security log entry for a manually selected patient. if (isWebForms) { Sheet newSheet = SheetUtil.CreateSheetFromWebSheet(patNum, webFormsSheet); Sheets.SaveNewSheet(newSheet); if (DataExistsInDb(newSheet)) { listSheetIdsForDeletion.Add(webFormsSheet.SheetID); } } else //CEMT Patient Transfer //Sheet is ready to get updated with the patient. { sheet.PatNum = patNum; sheet.DateTimeSheet = MiscData.GetNowDateTime(); if (PrefC.HasClinicsEnabled) { sheet.ClinicNum = pat.ClinicNum; } sheet.IsWebForm = true; //This is so the sheet shows up in gridmain in this form. Sheets.Update(sheet); } return(true); }