///<summary>Converts a DataTable to a list of objects.</summary>
        public static List <WebForms_Sheet> TableToList(DataTable table)
        {
            List <WebForms_Sheet> retVal = new List <WebForms_Sheet>();
            WebForms_Sheet        webForms_Sheet;

            for (int i = 0; i < table.Rows.Count; i++)
            {
                webForms_Sheet                 = new WebForms_Sheet();
                webForms_Sheet.SheetID         = PIn.Long(table.Rows[i]["SheetID"].ToString());
                webForms_Sheet.DentalOfficeID  = PIn.Long(table.Rows[i]["DentalOfficeID"].ToString());
                webForms_Sheet.Description     = PIn.String(table.Rows[i]["Description"].ToString());
                webForms_Sheet.SheetType       = (OpenDentBusiness.SheetFieldType)PIn.Int(table.Rows[i]["SheetType"].ToString());
                webForms_Sheet.DateTimeSheet   = PIn.DateT(table.Rows[i]["DateTimeSheet"].ToString());
                webForms_Sheet.FontSize        = PIn.Float(table.Rows[i]["FontSize"].ToString());
                webForms_Sheet.FontName        = PIn.String(table.Rows[i]["FontName"].ToString());
                webForms_Sheet.Width           = PIn.Int(table.Rows[i]["Width"].ToString());
                webForms_Sheet.Height          = PIn.Int(table.Rows[i]["Height"].ToString());
                webForms_Sheet.IsLandscape     = PIn.Bool(table.Rows[i]["IsLandscape"].ToString());
                webForms_Sheet.ClinicNum       = PIn.Long(table.Rows[i]["ClinicNum"].ToString());
                webForms_Sheet.HasMobileLayout = PIn.Bool(table.Rows[i]["HasMobileLayout"].ToString());
                webForms_Sheet.SheetDefNum     = PIn.Long(table.Rows[i]["SheetDefNum"].ToString());
                retVal.Add(webForms_Sheet);
            }
            return(retVal);
        }
Exemple #2
0
        ///<summary>Creates a given sheet for the following information.</summary>
        public static WebForms_Sheet CreateWebFormSheet(string lName, string fName, DateTime birthdate, string email, List <string> listPhoneNumbers)
        {
            WebForms_Sheet sheet = new WebForms_Sheet();

            sheet.SheetFields = new List <WebForms_SheetField>();
            WebForms_SheetField field = new WebForms_SheetField();

            field.FieldName  = "lname";
            field.FieldValue = lName;
            sheet.SheetFields.Add(field);
            field            = new WebForms_SheetField();
            field.FieldName  = "fname";
            field.FieldValue = fName;
            sheet.SheetFields.Add(field);
            field            = new WebForms_SheetField();
            field.FieldName  = "bdate";
            field.FieldValue = birthdate.ToShortDateString();
            sheet.SheetFields.Add(field);
            field            = new WebForms_SheetField();
            field.FieldName  = "email";
            field.FieldValue = email;
            sheet.SheetFields.Add(field);
            foreach (string phoneNumber in listPhoneNumbers)
            {
                field            = new WebForms_SheetField();
                field.FieldName  = "hmphone";             //home, work, cell all treated the same.
                field.FieldValue = phoneNumber;
                sheet.SheetFields.Add(field);
            }
            return(sheet);
        }
 public FormPatientPickWebForm(WebForms_Sheet sheetAndSheetField, int countMatchingSheets, Sheet sheetCemt = null)
 {
     InitializeComponent();
     Lan.F(this);
     _webFormsSheet       = sheetAndSheetField;
     _sheetCemt           = sheetCemt;
     _isWebForm           = _webFormsSheet != null;
     _countMatchingSheets = countMatchingSheets;
 }
Exemple #4
0
        /// <summary>
        /// </summary>
        private Sheet CreateSheet(long PatNum, WebForms_Sheet webFormSheet)
        {
            Sheet newSheet = null;

            try{
                SheetDef sheetDef = new SheetDef((SheetTypeEnum)webFormSheet.SheetType);
                newSheet = SheetUtil.CreateSheet(sheetDef, PatNum);
                SheetParameter.SetParameter(newSheet, "PatNum", PatNum);
                newSheet.DateTimeSheet = webFormSheet.DateTimeSheet;
                newSheet.Description   = webFormSheet.Description;
                newSheet.Height        = webFormSheet.Height;
                newSheet.Width         = webFormSheet.Width;
                newSheet.FontName      = webFormSheet.FontName;
                newSheet.FontSize      = webFormSheet.FontSize;
                newSheet.SheetType     = (SheetTypeEnum)webFormSheet.SheetType;
                newSheet.IsLandscape   = webFormSheet.IsLandscape;
                newSheet.InternalNote  = "";
                newSheet.IsWebForm     = true;
                //loop through each variable in a single sheetfield
                foreach (WebForms_SheetField field in webFormSheet.SheetFields)
                {
                    SheetField sheetfield = new SheetField();
                    sheetfield.FieldName        = field.FieldName;
                    sheetfield.FieldType        = field.FieldType;
                    sheetfield.FontIsBold       = field.FontIsBold;
                    sheetfield.FontName         = field.FontName;
                    sheetfield.FontSize         = field.FontSize;
                    sheetfield.Height           = field.Height;
                    sheetfield.Width            = field.Width;
                    sheetfield.XPos             = field.XPos;
                    sheetfield.YPos             = field.YPos;
                    sheetfield.IsRequired       = field.IsRequired;
                    sheetfield.TabOrder         = field.TabOrder;
                    sheetfield.ReportableName   = field.ReportableName;
                    sheetfield.RadioButtonGroup = field.RadioButtonGroup;
                    sheetfield.RadioButtonValue = field.RadioButtonValue;
                    sheetfield.GrowthBehavior   = field.GrowthBehavior;
                    sheetfield.FieldValue       = field.FieldValue;
                    sheetfield.TextAlign        = field.TextAlign;
                    sheetfield.ItemColor        = field.ItemColor;
                    newSheet.SheetFields.Add(sheetfield);
                }                        // end of j loop
                Sheets.SaveNewSheet(newSheet);
                return(newSheet);
            }
            catch (Exception e) {
                gridMain.EndUpdate();
                MessageBox.Show(e.Message);
            }
            return(newSheet);
        }
Exemple #5
0
        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>Updates one WebForms_Sheet in the database.</summary>
        public static void Update(WebForms_Sheet webForms_Sheet)
        {
            string command = "UPDATE webforms_sheet SET "
                             + "DentalOfficeID =  " + POut.Long(webForms_Sheet.DentalOfficeID) + ", "
                             + "Description    = '" + POut.String(webForms_Sheet.Description) + "', "
                             + "SheetType      =  " + POut.Int((int)webForms_Sheet.SheetType) + ", "
                             + "DateTimeSheet  =  " + POut.DateT(webForms_Sheet.DateTimeSheet) + ", "
                             + "FontSize       =  " + POut.Float(webForms_Sheet.FontSize) + ", "
                             + "FontName       = '" + POut.String(webForms_Sheet.FontName) + "', "
                             + "Width          =  " + POut.Int(webForms_Sheet.Width) + ", "
                             + "Height         =  " + POut.Int(webForms_Sheet.Height) + ", "
                             + "IsLandscape    =  " + POut.Bool(webForms_Sheet.IsLandscape) + ", "
                             + "ClinicNum      =  " + POut.Long(webForms_Sheet.ClinicNum) + ", "
                             + "HasMobileLayout=  " + POut.Bool(webForms_Sheet.HasMobileLayout) + ", "
                             + "SheetDefNum    =  " + POut.Long(webForms_Sheet.SheetDefNum) + " "
                             + "WHERE SheetID = " + POut.Long(webForms_Sheet.SheetID);

            DataCore.NonQ(command);
        }
        ///<summary>Inserts one WebForms_Sheet into the database.  Provides option to use the existing priKey.</summary>
        public static long Insert(WebForms_Sheet webForms_Sheet, bool useExistingPK)
        {
            string command = "INSERT INTO webforms_sheet (";

            if (useExistingPK)
            {
                command += "SheetID,";
            }
            command += "DentalOfficeID,Description,SheetType,DateTimeSheet,FontSize,FontName,Width,Height,IsLandscape,ClinicNum,HasMobileLayout,SheetDefNum) VALUES(";
            if (useExistingPK)
            {
                command += POut.Long(webForms_Sheet.SheetID) + ",";
            }
            command +=
                POut.Long(webForms_Sheet.DentalOfficeID) + ","
                + "'" + POut.String(webForms_Sheet.Description) + "',"
                + POut.Int((int)webForms_Sheet.SheetType) + ","
                + POut.DateT(webForms_Sheet.DateTimeSheet) + ","
                + POut.Float(webForms_Sheet.FontSize) + ","
                + "'" + POut.String(webForms_Sheet.FontName) + "',"
                + POut.Int(webForms_Sheet.Width) + ","
                + POut.Int(webForms_Sheet.Height) + ","
                + POut.Bool(webForms_Sheet.IsLandscape) + ","
                + POut.Long(webForms_Sheet.ClinicNum) + ","
                + POut.Bool(webForms_Sheet.HasMobileLayout) + ","
                + POut.Long(webForms_Sheet.SheetDefNum) + ")";
            if (useExistingPK)
            {
                DataCore.NonQ(command);
            }
            else
            {
                webForms_Sheet.SheetID = DataCore.NonQ(command, true);
            }
            return(webForms_Sheet.SheetID);
        }
        ///<summary>Updates one WebForms_Sheet in the database.  Uses an old object to compare to, and only alters changed fields.  This prevents collisions and concurrency problems in heavily used tables.  Returns true if an update occurred.</summary>
        public static bool Update(WebForms_Sheet webForms_Sheet, WebForms_Sheet oldWebForms_Sheet)
        {
            string command = "";

            if (webForms_Sheet.DentalOfficeID != oldWebForms_Sheet.DentalOfficeID)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "DentalOfficeID = " + POut.Long(webForms_Sheet.DentalOfficeID) + "";
            }
            if (webForms_Sheet.Description != oldWebForms_Sheet.Description)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "Description = '" + POut.String(webForms_Sheet.Description) + "'";
            }
            if (webForms_Sheet.SheetType != oldWebForms_Sheet.SheetType)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "SheetType = " + POut.Int((int)webForms_Sheet.SheetType) + "";
            }
            if (webForms_Sheet.DateTimeSheet != oldWebForms_Sheet.DateTimeSheet)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "DateTimeSheet = " + POut.DateT(webForms_Sheet.DateTimeSheet) + "";
            }
            if (webForms_Sheet.FontSize != oldWebForms_Sheet.FontSize)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "FontSize = " + POut.Float(webForms_Sheet.FontSize) + "";
            }
            if (webForms_Sheet.FontName != oldWebForms_Sheet.FontName)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "FontName = '" + POut.String(webForms_Sheet.FontName) + "'";
            }
            if (webForms_Sheet.Width != oldWebForms_Sheet.Width)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "Width = " + POut.Int(webForms_Sheet.Width) + "";
            }
            if (webForms_Sheet.Height != oldWebForms_Sheet.Height)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "Height = " + POut.Int(webForms_Sheet.Height) + "";
            }
            if (webForms_Sheet.IsLandscape != oldWebForms_Sheet.IsLandscape)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "IsLandscape = " + POut.Bool(webForms_Sheet.IsLandscape) + "";
            }
            if (webForms_Sheet.ClinicNum != oldWebForms_Sheet.ClinicNum)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "ClinicNum = " + POut.Long(webForms_Sheet.ClinicNum) + "";
            }
            if (webForms_Sheet.HasMobileLayout != oldWebForms_Sheet.HasMobileLayout)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "HasMobileLayout = " + POut.Bool(webForms_Sheet.HasMobileLayout) + "";
            }
            if (webForms_Sheet.SheetDefNum != oldWebForms_Sheet.SheetDefNum)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "SheetDefNum = " + POut.Long(webForms_Sheet.SheetDefNum) + "";
            }
            if (command == "")
            {
                return(false);
            }
            command = "UPDATE webforms_sheet SET " + command
                      + " WHERE SheetID = " + POut.Long(webForms_Sheet.SheetID);
            DataCore.NonQ(command);
            return(true);
        }
        ///<summary>Inserts many WebForms_Sheets into the database.  Provides option to use the existing priKey.</summary>
        public static void InsertMany(List <WebForms_Sheet> listWebForms_Sheets, bool useExistingPK)
        {
            StringBuilder sbCommands = null;
            int           index      = 0;
            int           countRows  = 0;

            while (index < listWebForms_Sheets.Count)
            {
                WebForms_Sheet webForms_Sheet = listWebForms_Sheets[index];
                StringBuilder  sbRow          = new StringBuilder("(");
                bool           hasComma       = false;
                if (sbCommands == null)
                {
                    sbCommands = new StringBuilder();
                    sbCommands.Append("INSERT INTO webforms_sheet (");
                    if (useExistingPK)
                    {
                        sbCommands.Append("SheetID,");
                    }
                    sbCommands.Append("DentalOfficeID,Description,SheetType,DateTimeSheet,FontSize,FontName,Width,Height,IsLandscape,ClinicNum,HasMobileLayout,SheetDefNum) VALUES ");
                    countRows = 0;
                }
                else
                {
                    hasComma = true;
                }
                if (useExistingPK)
                {
                    sbRow.Append(POut.Long(webForms_Sheet.SheetID)); sbRow.Append(",");
                }
                sbRow.Append(POut.Long(webForms_Sheet.DentalOfficeID)); sbRow.Append(",");
                sbRow.Append("'" + POut.String(webForms_Sheet.Description) + "'"); sbRow.Append(",");
                sbRow.Append(POut.Int((int)webForms_Sheet.SheetType)); sbRow.Append(",");
                sbRow.Append(POut.DateT(webForms_Sheet.DateTimeSheet)); sbRow.Append(",");
                sbRow.Append(POut.Float(webForms_Sheet.FontSize)); sbRow.Append(",");
                sbRow.Append("'" + POut.String(webForms_Sheet.FontName) + "'"); sbRow.Append(",");
                sbRow.Append(POut.Int(webForms_Sheet.Width)); sbRow.Append(",");
                sbRow.Append(POut.Int(webForms_Sheet.Height)); sbRow.Append(",");
                sbRow.Append(POut.Bool(webForms_Sheet.IsLandscape)); sbRow.Append(",");
                sbRow.Append(POut.Long(webForms_Sheet.ClinicNum)); sbRow.Append(",");
                sbRow.Append(POut.Bool(webForms_Sheet.HasMobileLayout)); sbRow.Append(",");
                sbRow.Append(POut.Long(webForms_Sheet.SheetDefNum)); sbRow.Append(")");
                if (sbCommands.Length + sbRow.Length + 1 > TableBase.MaxAllowedPacketCount && countRows > 0)
                {
                    DataCore.NonQ(sbCommands.ToString());
                    sbCommands = null;
                }
                else
                {
                    if (hasComma)
                    {
                        sbCommands.Append(",");
                    }
                    sbCommands.Append(sbRow.ToString());
                    countRows++;
                    if (index == listWebForms_Sheets.Count - 1)
                    {
                        DataCore.NonQ(sbCommands.ToString());
                    }
                    index++;
                }
            }
        }
 ///<summary>Inserts one WebForms_Sheet into the database.  Returns the new priKey.</summary>
 public static long Insert(WebForms_Sheet webForms_Sheet)
 {
     return(Insert(webForms_Sheet, false));
 }
Exemple #11
0
        /// <summary>
        private static Patient CreatePatient(String LastName, String FirstName, DateTime birthDate, WebForms_Sheet webFormSheet, Sheet sheet, string cultureName)
        {
            bool    isWebForm = webFormSheet != null;
            Patient newPat    = new Patient();

            newPat.LName     = LastName;
            newPat.FName     = FirstName;
            newPat.Birthdate = birthDate;
            if (isWebForm)
            {
                newPat.ClinicNum = webFormSheet.ClinicNum;
            }
            else
            {
                newPat.ClinicNum = sheet.ClinicNum;
            }
            if (!PrefC.HasClinicsEnabled)
            {
                //Set the patients primary provider to the practice default provider.
                newPat.PriProv = Providers.GetDefaultProvider().ProvNum;
            }
            else              //Using clinics.
            //Set the patients primary provider to the clinic default provider.
            {
                newPat.PriProv = Providers.GetDefaultProvider(Clinics.ClinicNum).ProvNum;
            }
            Type t = newPat.GetType();

            FieldInfo[] fi = t.GetFields();
            foreach (FieldInfo field in fi)
            {
                // find match for fields in Patients in the SheetFields
                if (isWebForm)
                {
                    List <WebForms_SheetField> listWebFormsSheetFields = webFormSheet.SheetFields.FindAll(x => x.FieldName.ToLower() == field.Name.ToLower());
                    if (listWebFormsSheetFields.Count() > 0)
                    {
                        // this loop is used to fill a field that may generate mutiple values for a single field in the patient.
                        //for example the field gender has 2 eqivalent sheet fields in the SheetFields
                        foreach (WebForms_SheetField webFormsSheetField in listWebFormsSheetFields)
                        {
                            FillPatientFields(newPat, field, webFormsSheetField.FieldValue, webFormsSheetField.RadioButtonValue, cultureName, isWebForm, false);
                        }
                    }
                }
                else
                {
                    List <SheetField> listSheetFields = sheet.SheetFields.FindAll(x => x.FieldName.ToLower() == field.Name.ToLower());
                    if (listSheetFields.Count() > 0)
                    {
                        // this loop is used to fill a field that may generate mutiple values for a single field in the patient.
                        //for example the field gender has 2 eqivalent sheet fields in the SheetFields
                        foreach (SheetField sheetField in listSheetFields)
                        {
                            FillPatientFields(newPat, field, sheetField.FieldValue, sheetField.RadioButtonValue, "", isWebForm, sheet.IsCemtTransfer);
                        }
                    }
                }
            }
            try {
                Patients.Insert(newPat, false);
                SecurityLogs.MakeLogEntry(Permissions.PatientCreate, newPat.PatNum, isWebForm ? "Created from Web Forms." : "Created from CEMT transfer.");
                //set Guarantor field the same as PatNum
                Patient patOld = newPat.Copy();
                newPat.Guarantor = newPat.PatNum;
                Patients.Update(newPat, patOld);
                //If there is an existing HL7 def enabled, send an ADT message if there is an outbound ADT message defined
                if (HL7Defs.IsExistingHL7Enabled())
                {
                    MessageHL7 messageHL7 = MessageConstructor.GenerateADT(newPat, newPat, EventTypeHL7.A04);                //patient is guarantor
                    //Will be null if there is no outbound ADT message defined, so do nothing
                    if (messageHL7 != null)
                    {
                        HL7Msg hl7Msg = new HL7Msg();
                        hl7Msg.AptNum    = 0;
                        hl7Msg.HL7Status = HL7MessageStatus.OutPending;                      //it will be marked outSent by the HL7 service.
                        hl7Msg.MsgText   = messageHL7.ToString();
                        hl7Msg.PatNum    = newPat.PatNum;
                        HL7Msgs.Insert(hl7Msg);
#if DEBUG
                        MessageBox.Show("FormWebForms", messageHL7.ToString());
#endif
                    }
                }
            }
            catch (Exception e) {
                MessageBox.Show(e.Message);
            }
            return(newPat);
        }
Exemple #12
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);
        }