private void FetchValuesFromWebServer() { try { String WebHostSynchServerURL = PrefC.GetString(PrefName.WebHostSynchServerURL); textboxWebHostAddress.Text = WebHostSynchServerURL; butSave.Enabled = false; //#if DEBUG // ignore the certificate errors for the staging machine and development machine if ((WebHostSynchServerURL == SynchUrlStaging) || (WebHostSynchServerURL == SynchUrlDev)) { IgnoreCertificateErrors(); } //#endif Cursor = Cursors.WaitCursor; if (!TestWebServiceExists()) { Cursor = Cursors.Default; MsgBox.Show(this, "Either the web service is not available or the WebHostSynch URL is incorrect"); return; } DentalOfficeID = wh.GetDentalOfficeID(RegistrationKey); if (wh.GetDentalOfficeID(RegistrationKey) == 0) { Cursor = Cursors.Default; MsgBox.Show(this, "Registration key provided by the dental office is incorrect"); return; } OpenDental.WebSheets.webforms_preference PrefObj = wh.GetPreferences(RegistrationKey); if (PrefObj == null) { Cursor = Cursors.Default; MsgBox.Show(this, "There has been an error retrieving values from the server"); } butWebformBorderColor.BackColor = Color.FromArgb(PrefObj.ColorBorder); SheetDefAddress = wh.GetSheetDefAddress(RegistrationKey); //dennis: the below if statement is for backward compatibility only April 14 2011 and can be removed later. if (String.IsNullOrEmpty(PrefObj.CultureName)) { PrefObj.CultureName = System.Globalization.CultureInfo.CurrentCulture.Name; wh.SetPreferencesV2(RegistrationKey, PrefObj); } } catch (Exception ex) { Cursor = Cursors.Default; MessageBox.Show(ex.Message); } FillGrid(); //Also gets sheet def list from server Cursor = Cursors.Default; }
private void RetrieveAndSaveData() { try { #if DEBUG //IgnoreCertificateErrors();// used with faulty certificates only while debugging. #endif WebSheets.Sheets wh = new WebSheets.Sheets(); wh.Url = PrefC.GetString(PrefName.WebHostSynchServerURL); string RegistrationKey = PrefC.GetString(PrefName.RegistrationKey); if (wh.GetDentalOfficeID(RegistrationKey) == 0) { MsgBox.Show(this, "Registration key provided by the dental office is incorrect"); return; } OpenDental.WebSheets.SheetAndSheetField[] arraySheets = wh.GetSheets(RegistrationKey); List <long> SheetsForDeletion = new List <long>(); if (arraySheets.Count() == 0) { MsgBox.Show(this, "No Patient forms retrieved from server"); return; } //loop through all incoming sheets for (int i = 0; i < arraySheets.Length; i++) { try { //this try catch is put so that a defective downloaded sheet does not stop other sheets from being downloaded. long patNum = 0; string lName = ""; string fName = ""; DateTime bDate = DateTime.MinValue; //loop through each field in this sheet to find First name, last name, and DOB for (int j = 0; j < arraySheets[i].web_sheetfieldlist.Count(); j++) { if (arraySheets[i].web_sheetfieldlist[j].FieldName.ToLower().Contains("lname") || arraySheets[i].web_sheetfieldlist[j].FieldName.ToLower().Contains("lastname")) { lName = arraySheets[i].web_sheetfieldlist[j].FieldValue; } if (arraySheets[i].web_sheetfieldlist[j].FieldName.ToLower().Contains("fname") || arraySheets[i].web_sheetfieldlist[j].FieldName.ToLower().Contains("firstname")) { fName = arraySheets[i].web_sheetfieldlist[j].FieldValue; } if (arraySheets[i].web_sheetfieldlist[j].FieldName.ToLower().Contains("bdate") || arraySheets[i].web_sheetfieldlist[j].FieldName.ToLower().Contains("birthdate")) { bDate = PIn.Date(arraySheets[i].web_sheetfieldlist[j].FieldValue); } } if (bDate.Year < 1880) { //log invalid birth date format. Shouldn't happen, though. } patNum = Patients.GetPatNumByNameAndBirthday(lName, fName, bDate); if (patNum == 0) { FormPatientPickWebForm FormPpw = new FormPatientPickWebForm(); FormPpw.LnameEntered = lName; FormPpw.FnameEntered = fName; FormPpw.BdateEntered = bDate; FormPpw.ShowDialog(); if (FormPpw.DialogResult != DialogResult.OK) { break; //out of loop } patNum = FormPpw.SelectedPatNum; //might be zero to indicate new patient } else //A match was found so make a log entry what the match was. { Patient pat = Patients.GetPat(patNum); //Security log for OD automatically importing a sheet into a patient. SecurityLogs.MakeLogEntry(Permissions.SheetEdit, patNum, "Web form import from: " + lName + ", " + fName + " " + bDate.ToShortDateString() + "\r\nAuto imported into: " + pat.LName + ", " + pat.FName + " " + pat.Birthdate.ToShortDateString()); } if (patNum == 0) { Patient newPat = CreatePatient(lName, fName, bDate, arraySheets[i]); patNum = newPat.PatNum; //Security log for user creating a new patient. SecurityLogs.MakeLogEntry(Permissions.SheetEdit, patNum, "Web form import from: " + lName + ", " + fName + " " + bDate.ToShortDateString() + "\r\nUser created new pat: " + newPat.LName + ", " + newPat.FName + " " + newPat.Birthdate.ToShortDateString()); } Sheet newSheet = CreateSheet(patNum, arraySheets[i]); if (DataExistsInDb(newSheet)) { SheetsForDeletion.Add(arraySheets[i].web_sheet.SheetID); } } catch (Exception e) { MessageBox.Show(e.Message); } } // end of for loop wh.DeleteSheetData(RegistrationKey, SheetsForDeletion.ToArray()); } catch (Exception e) { MessageBox.Show(e.Message); } }
private void RetrieveAndSaveData() { try { #if DEBUG //IgnoreCertificateErrors();// used with faulty certificates only while debugging. #endif WebSheets.Sheets wh = new WebSheets.Sheets(); wh.Timeout = 300000; //5 minutes. Default is 100000 (1.66667 minutes). wh.Url = PrefC.GetString(PrefName.WebHostSynchServerURL); string RegistrationKey = PrefC.GetString(PrefName.RegistrationKey); if (wh.GetDentalOfficeID(RegistrationKey) == 0) { MsgBox.Show(this, "Registration key provided by the dental office is incorrect"); return; } List <WebSheets.SheetAndSheetField> listSheets; List <long> listSkippedSheets = new List <long>(); int iterations = 0; do //Because WebSheets are only downloaded 20 at a time, we need to get the sheets within a loop to download them all. { listSheets = wh.GetSheets(RegistrationKey) //Only gets the first 20 sheets. //if we are not in HQ, filter out non-HQ sheets that don't match our current clinic .Where(x => x.web_sheet.ClinicNum == 0 || Clinics.ClinicNum == 0 || x.web_sheet.ClinicNum == Clinics.ClinicNum).ToList(); iterations++; List <long> SheetsForDeletion = new List <long>(); listSheets.RemoveAll(x => listSkippedSheets.Contains(x.web_sheet.SheetID)); //Remove all sheets that the user has already skipped. if (listSheets.Count == 0) { if (iterations == 1) { MsgBox.Show(this, "No Patient forms retrieved from server"); } else { MsgBox.Show(this, "All Patient forms retrieved from server"); } return; } //loop through all incoming sheets for (int i = 0; i < listSheets.Count; i++) { try { //this try catch is put so that a defective downloaded sheet does not stop other sheets from being downloaded. long patNum = 0; string lName = ""; string fName = ""; List <string> listPhoneNumbers = new List <string>(); string email = ""; DateTime bDate = DateTime.MinValue; //loop through each field in this sheet to find First name, last name, and DOB for (int j = 0; j < listSheets[i].web_sheetfieldlist.Count(); j++) { if (listSheets[i].web_sheetfieldlist[j].FieldName.ToLower().Contains("lname") || listSheets[i].web_sheetfieldlist[j].FieldName.ToLower().Contains("lastname")) { lName = listSheets[i].web_sheetfieldlist[j].FieldValue; } if (listSheets[i].web_sheetfieldlist[j].FieldName.ToLower().Contains("fname") || listSheets[i].web_sheetfieldlist[j].FieldName.ToLower().Contains("firstname")) { fName = listSheets[i].web_sheetfieldlist[j].FieldValue; } if (listSheets[i].web_sheetfieldlist[j].FieldName.ToLower().Contains("bdate") || listSheets[i].web_sheetfieldlist[j].FieldName.ToLower().Contains("birthdate")) { bDate = PIn.Date(listSheets[i].web_sheetfieldlist[j].FieldValue); } if (listSheets[i].web_sheetfieldlist[j].FieldName.ToLower().In("hmphone", "wkphone", "wirelessphone") && listSheets[i].web_sheetfieldlist[j].FieldValue != "") { listPhoneNumbers.Add(listSheets[i].web_sheetfieldlist[j].FieldValue); } if (listSheets[i].web_sheetfieldlist[j].FieldName.ToLower() == "email") { email = listSheets[i].web_sheetfieldlist[j].FieldValue; } } if (bDate.Year < 1880) { //log invalid birth date format. Shouldn't happen, though. } List <long> listMatchingPats = Patients.GetPatNumsByNameBirthdayEmailAndPhone(lName, fName, bDate, email, listPhoneNumbers); FormPatientPickWebForm FormPpw = new FormPatientPickWebForm(listSheets[i]); FormPpw.LnameEntered = lName; FormPpw.FnameEntered = fName; FormPpw.BdateEntered = bDate; if (listMatchingPats.Count == 0) { FormPpw.HasMoreThanOneMatch = false; FormPpw.ShowDialog(); if (FormPpw.DialogResult == DialogResult.Cancel) { //user wants to stop importing altogether //we will pick up where we left off here next time wh.DeleteSheetData(RegistrationKey, SheetsForDeletion.ToArray()); return; } else if (FormPpw.DialogResult == DialogResult.Ignore) { //user wants to skip this patient import only listSkippedSheets.Add(listSheets[i].web_sheet.SheetID); continue; //future feature suggestion... 4th state = discard //mark this patient's import sheet for delete go to the next patient //SheetsForDeletion.Add(listSheets[i].web_sheet.SheetID); //continue } patNum = FormPpw.SelectedPatNum; //might be zero to indicate new patient } else if (listMatchingPats.Count > 1) { FormPpw.HasMoreThanOneMatch = true; FormPpw.ShowDialog(); if (FormPpw.DialogResult == DialogResult.Cancel) { //user wants to stop importing altogether //we will pick up where we left off here next time wh.DeleteSheetData(RegistrationKey, SheetsForDeletion.ToArray()); return; } else if (FormPpw.DialogResult == DialogResult.Ignore) { //user wants to skip this patient import only listSkippedSheets.Add(listSheets[i].web_sheet.SheetID); continue; } 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]; Patient pat = Patients.GetPat(patNum); //Security log for OD automatically importing a sheet into a patient. SecurityLogs.MakeLogEntry(Permissions.SheetEdit, patNum, Lan.g(this, "Web form import from:") + " " + lName + ", " + fName + " " + bDate.ToShortDateString() + "\r\n" + Lan.g(this, "Auto imported into:") + " " + pat.LName + ", " + pat.FName + " " + pat.Birthdate.ToShortDateString()); } if (patNum == 0) { Patient newPat = CreatePatient(lName, fName, bDate, listSheets[i]); patNum = newPat.PatNum; //Security log for user creating a new patient. SecurityLogs.MakeLogEntry(Permissions.SheetEdit, patNum, Lan.g(this, "Web form import from:") + " " + lName + ", " + fName + " " + bDate.ToShortDateString() + "\r\n" + Lan.g(this, "User created new pat:") + " " + newPat.LName + ", " + newPat.FName + " " + newPat.Birthdate.ToShortDateString()); } //We should probably make a security log entry for a manually selected patient. Sheet newSheet = SheetUtil.CreateSheetFromWebSheet(patNum, listSheets[i]); Sheets.SaveNewSheet(newSheet); if (DataExistsInDb(newSheet)) { SheetsForDeletion.Add(listSheets[i].web_sheet.SheetID); } } catch (Exception e) { MessageBox.Show(e.Message); } } // end of for loop wh.DeleteSheetData(RegistrationKey, SheetsForDeletion.ToArray()); } while(listSheets.Count > 0); } catch (Exception e) { MessageBox.Show(e.Message); return; } }