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