public void WebForms_Sheets_ParseDateWebForms_AllCulturesWithManyDelimiters() { StringBuilder strBld = new StringBuilder(); //These are currently unsupported cultures. No customers currently have their webformspreference.CultureName set to these. List <string> listUnsupportedCultureNames = new List <string>() { "ar", "ar-SA", "fa", "fa-IR", "ku-Arab-IR", "lrc", "lrc-IR", "mzn", "mzn-IR", "prs", "prs-AF", "ps", "ps-AF", "th", "th-TH", "uz-Arab", "uz-Arab-AF" }; foreach (CultureInfo culture in CultureInfo.GetCultures(CultureTypes.AllCultures) .Where(x => !x.Name.In(listUnsupportedCultureNames) && !string.IsNullOrWhiteSpace(x.Name))) { DateTime dateExpected = new DateTime(2019, 12, 31); //Use a date that would cause problems if MM and d are mismatched. string format = GetDateFormatLikeWebFormsDb(culture.Name, out string delimiterWeb); //The format WebForms will use, and its delimiter. foreach (string delimiter in new string[] { ".", "/", "\\", " ", "-", "random nonsense" }) { //Test this date, using the various delimiters patients might use, plus some that make no sense. string strDate = System.Text.RegularExpressions.Regex.Replace(dateExpected.ToString(format), delimiterWeb, delimiter); DateTime dateActual = WebForms_Sheets.ParseDateWebForms(strDate, culture.Name); Assert.AreEqual(dateExpected.ToShortDateString(), dateActual.ToShortDateString() , $"date: {strDate}, format: {format}, culture: {culture.Name}"); } } //We don't support this format currently. Make sure ParseDateWebForms returns MinValue. DateTime failDate = WebForms_Sheets.ParseDateWebForms("January 26,2006", "en-US"); Assert.AreEqual(DateTime.MinValue.ToShortDateString(), failDate.ToShortDateString()); //If the user typed complete nonsense in a birthdate field. Make sure ParseDateWebForms returns MinValue. failDate = WebForms_Sheets.ParseDateWebForms("chicken", "en-US"); Assert.AreEqual(DateTime.MinValue.ToShortDateString(), failDate.ToShortDateString()); failDate = WebForms_Sheets.ParseDateWebForms("01/01/00", "en-US"); Assert.AreEqual(DateTime.MinValue.ToShortDateString(), failDate.ToShortDateString()); Assert.IsTrue(string.IsNullOrWhiteSpace(strBld.ToString()), strBld.ToString()); }
public void WebForms_Sheets_FindSheetsForPat_Matching() { WebForms_Sheet sheetNoPhones = WebForms_SheetT.CreateWebFormSheet("Bob", "Bobby", new DateTime(2018, 1, 1), "*****@*****.**", new List <string>()); WebForms_Sheet sheetNoPhonesMatching = WebForms_SheetT.CreateWebFormSheet("Bob", "Bobby", new DateTime(2018, 1, 1), "*****@*****.**", new List <string>()); WebForms_Sheet sheetCloseMatch = WebForms_SheetT.CreateWebFormSheet("Bob", "Bobby", new DateTime(2018, 1, 2), "*****@*****.**", new List <string>()); WebForms_Sheet sheetPhoneNumber = WebForms_SheetT.CreateWebFormSheet("Bob", "Bobby", new DateTime(2018, 1, 2), "*****@*****.**", new List <string> { "5555555555" }); WebForms_Sheet sheetPhoneNumberMatching = WebForms_SheetT.CreateWebFormSheet("Bob", "Bobby", new DateTime(2018, 1, 2), "*****@*****.**", new List <string> { "5555555555" }); WebForms_Sheet sheetTooManyPhones = WebForms_SheetT.CreateWebFormSheet("Bob", "Bobby", new DateTime(2018, 1, 2), "*****@*****.**", new List <string> { "5555555555", "4444444444" }); WebForms_Sheet sheetDifferentName = WebForms_SheetT.CreateWebFormSheet("Bobby", "Bobby", new DateTime(2018, 1, 1), "*****@*****.**", new List <string>()); //Exact Match. Assert.AreEqual(1, WebForms_Sheets.FindSheetsForPat(sheetNoPhones, new List <WebForms_Sheet> { sheetNoPhonesMatching }, "en-us").Count); //Close except different birthday. Assert.AreEqual(0, WebForms_Sheets.FindSheetsForPat(sheetNoPhones, new List <WebForms_Sheet> { sheetCloseMatch }, "en-us").Count); //Exact Match. Assert.AreEqual(1, WebForms_Sheets.FindSheetsForPat(sheetPhoneNumber, new List <WebForms_Sheet> { sheetPhoneNumberMatching }, "en-us").Count); //One form has more phone numbers. Assert.AreEqual(0, WebForms_Sheets.FindSheetsForPat(sheetPhoneNumber, new List <WebForms_Sheet> { sheetTooManyPhones }, "en-us").Count); //No match. Different name. Assert.AreEqual(0, WebForms_Sheets.FindSheetsForPat(sheetTooManyPhones, new List <WebForms_Sheet> { sheetDifferentName }, "en-us").Count); //A sheet will always match on itself. Assert.AreEqual(1, WebForms_Sheets.FindSheetsForPat(sheetDifferentName, new List <WebForms_Sheet> { sheetDifferentName }, "en-us").Count); }
///<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); }
public static string RetrieveAndSaveData(string cultureName) { string strMsg = ""; #region CEMT Patient Transfers //Now get the patients that were transferred from the CEMT tool. These sheets will have a PatNum=0; List <Sheet> listSheetsFromCemtTool = Sheets.GetTransferSheets(); List <long> listCemtSheetsToDelete = new List <long>(); foreach (Sheet cemtSheet in listSheetsFromCemtTool) { try { //continue if the SheetNum is either marked as skipped or is going to be deleted. if (cemtSheet.SheetNum.In(listCemtSheetsToDelete)) { continue; } if (!DidImportSheet(null, cemtSheet, null, listSheetsFromCemtTool, System.Globalization.CultureInfo.CurrentCulture.Name, ref listCemtSheetsToDelete)) { //user wants to cancel import. return(strMsg); } } catch (Exception e) { strMsg += e.Message + "\r\n"; } } foreach (long sheetNum in listCemtSheetsToDelete) { Sheets.Delete(sheetNum); //Does not delete the sheet but sets the Sheet.IsDeleted=true. } #endregion #region WebForms try { SheetsSynchProxy.TimeoutOverride = 300000; //5 minutes. Default is 100000 (1.66667 minutes). if (WebUtils.GetDentalOfficeID() == 0) { strMsg = Lan.g("FormWebForms", "Either the registration key provided by the dental office is incorrect or the Host Server Address cannot be found."); return(strMsg); } List <WebForms_Sheet> listWebFormSheets; List <long> listSheetsSeen = new List <long>(); int iterations = 0; do { if (WebForms_Sheets.TryGetSheets(out listWebFormSheets)) { //if we are not in HQ, filter out non-HQ sheets that don't match our current clinic listWebFormSheets = listWebFormSheets.FindAll(x => x.ClinicNum == 0 || Clinics.ClinicNum == 0 || x.ClinicNum == Clinics.ClinicNum); } iterations++; List <long> listSheetIdsForDeletion = new List <long>(); listWebFormSheets.RemoveAll(x => listSheetsSeen.Contains(x.SheetID)); //Remove all sheets that we've already seen. if (listWebFormSheets.Count == 0) { if (iterations == 1 && listSheetsFromCemtTool.Count == 0) { strMsg = Lan.g("FormWebForms", "No Patient forms retrieved from server"); } else { strMsg = Lan.g("FormWebForms", "All Patient forms retrieved from server"); } return(strMsg); } listSheetsSeen.AddRange(listWebFormSheets.Select(x => x.SheetID)); //loop through all incoming sheets foreach (WebForms_Sheet webFormsSheet in listWebFormSheets) { try { //this try catch is put so that a defective downloaded sheet does not stop other sheets from being downloaded. if (listSheetIdsForDeletion.Contains(webFormsSheet.SheetID)) { continue; //Marked for deletion already. Next. } if (!DidImportSheet(webFormsSheet, null, listWebFormSheets, null, cultureName, ref listSheetIdsForDeletion)) { //user wants to cancel import. return(strMsg); } } catch (Exception e) { strMsg += e.Message + "\r\n"; } } // end of for loop if (!WebForms_Sheets.DeleteSheetData(listSheetIdsForDeletion.Distinct().ToList())) { break; //If any error happens, stop retrieving forms. } } while(listWebFormSheets.Count > 0); } catch (Exception e) { strMsg += e.Message; return(strMsg); } #endregion return(strMsg); }