예제 #1
0
        ///<summary>Generates all the xml up to the point where the first statement would go.</summary>
        public static void GeneratePracticeInfo(XmlWriter writer, long clinicNum)
        {
            Clinic clinic      = Clinics.GetClinic(clinicNum);
            Ebill  eBillClinic = Ebills.GetForClinic(clinicNum);

            if (eBillClinic == null)           //Clinic specific Ebill doesn't exist, use the defaults.
            {
                eBillClinic = Ebills.GetForClinic(0);
            }
            writer.WriteProcessingInstruction("xml", "version = \"1.0\" standalone=\"yes\"");
            writer.WriteStartElement("StatementFile");
            //sender address----------------------------------------------------------
            writer.WriteStartElement("SenderAddress");
            if (clinic == null)
            {
                writer.WriteElementString("Name", PrefC.GetString(PrefName.PracticeTitle));
            }
            else
            {
                writer.WriteElementString("Name", clinic.Description);
            }
            WriteAddress(writer, eBillClinic.PracticeAddress, clinic);
            writer.WriteEndElement();            //SenderAddress
            writer.WriteStartElement("Statements");
        }
예제 #2
0
        ///<summary>Gets up to 30 days of open time slots for New Patient Appointments based on the timePattern passed in.
        ///Open time slots are found by looping through the passed in operatories and finding openings that can hold the entire appointment.
        ///Passing in a clinicNum of 0 will only consider unassigned operatories.
        ///The timeslots on and between the Start and End dates passed in will be considered and potentially returned as available.
        ///Optionally pass in an appt type def num which will only consider operatories with the corresponding appointment type.
        ///defNumApptType is required and will ONLY consider operatories that are associated to the def's corresponding appointment type.
        ///The time pattern and procedures on the appointment will be determined via the appointment type as well.
        ///Throws exceptions.</summary>
        public static List <TimeSlot> GetAvailableNewPatApptTimeSlots(DateTime dateStart, DateTime dateEnd, long clinicNum, long defNumApptType)
        {
            //No need to check RemotingRole; no call to db.
            //Get the appointment type that is associated to the def passed in.  This is required for New Pat Appts.
            AppointmentType appointmentType = AppointmentTypes.GetWebSchedNewPatApptTypeByDef(defNumApptType);

            if (appointmentType == null)
            {
                //This message will typically show to a patient and we want them to call in OR to refresh the web app which should no longer show the reason.
                throw new ODException(Lans.g("WebSched", "The reason for your appointment is no longer available.") + "\r\n"
                                      + Lans.g("WebSched", "Please call us to schedule your appointment."));
            }
            //Now we need to find all operatories that are associated to the aforementioned appointment type.
            List <Operatory> listOperatories = Operatories.GetOpsForWebSchedNewPatApptDef(defNumApptType);

            if (listOperatories.Count < 1)             //This is very possible for offices that aren't set up the way that we expect them to be.
            {
                return(new List <TimeSlot>());         //Don't throw an exception here to the patient, they can just select another reason.
            }
            //Set the timePattern from the appointment type passed in.
            string          timePattern   = AppointmentTypes.GetTimePatternForAppointmentType(appointmentType);
            List <Provider> listProviders = Providers.GetProvidersForWebSchedNewPatAppt();
            Clinic          clinic        = Clinics.GetClinic(clinicNum);
            List <long>     listProvNums  = listProviders.Select(x => x.ProvNum).Distinct().ToList();
            List <Schedule> listSchedules = Schedules.GetSchedulesAndBlockoutsForWebSched(listProvNums, dateStart, dateEnd, false, clinicNum);

            return(GetTimeSlotsForRange(dateStart, dateEnd, timePattern, listProvNums, listOperatories, listSchedules, clinic, defNumApptType));
        }
예제 #3
0
        ///<summary>This is used separately from the SelectedClinicNum setter in order to internally set to -2 without an exception.  But this doesn't work for -1.</summary>
        private void SetSelectedClinicNum(long value)
        {
            int idx = _listClinics.FindIndex(x => x.ClinicNum == value);

            if (idx == -1)
            {
                if (value == -2)
                {
                    //user tried to set All, but that option is not available.
                    //Don't do anything
                }
                else
                {
                    //this user does not have permission for the selected clinic
                    _selectedIndex       = -1;
                    _listSelectedIndices = new List <int>();
                    if (IsTestModeNoDb)
                    {
                        _selectedClinicNoPermission = new Clinic {
                            Abbr = value.ToString(), Description = value.ToString(), ClinicNum = value
                        };
                    }
                    else
                    {
                        _selectedClinicNoPermission = Clinics.GetClinic(value);
                        //could still possibly be null in a corrupted db.  In that case, we still need to be able to return what was set.
                        if (_selectedClinicNoPermission == null)
                        {
                            _selectedClinicNoPermission = new Clinic {
                                Abbr = value.ToString(), Description = value.ToString(), ClinicNum = value
                            };
                        }
                    }
                }
            }
            else
            {
                _selectedClinicNoPermission = null;
                _selectedIndex       = idx;
                _listSelectedIndices = new List <int>()
                {
                    idx
                };
            }
            OnSelectedIndexChanged(this, new EventArgs());
            Invalidate();
        }
예제 #4
0
        public void EmailPreviewControl_ReplaceTemplateFields_AreAllReplacementStringsReplaced()
        {
            string  suffix = MethodBase.GetCurrentMethod().Name;
            Patient pat    = PatientT.CreatePatient(suffix);

            ReferralT.CreateReferral(pat.PatNum);                              //LoadTemplate(...) will use this referral.
            RecallT.CreateRecall(pat.PatNum, 0, DateTime.Now, new Interval()); //LoadTemplate(...) will use this recall.
            string             subject  = "";
            MessageReplaceType typesAll = (MessageReplaceType)Enum.GetValues(typeof(MessageReplaceType)).OfType <MessageReplaceType>().Sum(x => (int)x);

            foreach (FormMessageReplacements.ReplacementField field in FormMessageReplacements.GetReplacementFieldList(true, typesAll))
            {
                if (field.IsSupported)
                {
                    subject += field.FieldName;
                }
            }
            subject = EmailPreviewControl.ReplaceTemplateFields(subject, pat, null, Clinics.GetClinic(pat.ClinicNum));
            Assert.IsFalse(subject.Any(x => x == ']' || x == '['));
        }
예제 #5
0
        private void InitializeVariables()
        {
            Provider provFacility = Providers.GetProv(PrefC.GetInt(PrefName.PracticeDefaultProv));

            _sendingFacilityNpi      = provFacility.NationalProvID;
            _sendingFacilityName     = PrefC.GetString(PrefName.PracticeTitle);
            _sendingFacilityAddress1 = PrefC.GetString(PrefName.PracticeAddress);
            _sendingFacilityAddress2 = PrefC.GetString(PrefName.PracticeAddress2);
            _sendingFacilityCity     = PrefC.GetString(PrefName.PracticeCity);
            _sendingFacilityState    = PrefC.GetString(PrefName.PracticeST);
            _sendingFacilityZip      = PrefC.GetString(PrefName.PracticeZip);
            if (PrefC.HasClinicsEnabled && _appt.ClinicNum != 0)           //Using clinics and a clinic is assigned.
            {
                Clinic clinic = Clinics.GetClinic(_appt.ClinicNum);
                _sendingFacilityName     = clinic.Description;
                _sendingFacilityAddress1 = clinic.Address;
                _sendingFacilityAddress2 = clinic.Address2;
                _sendingFacilityCity     = clinic.City;
                _sendingFacilityState    = clinic.State;
                _sendingFacilityZip      = clinic.Zip;
            }
        }
예제 #6
0
        //these are temporary:
        //private static string vendorID="68";
        //private static string vendorPMScode="144";
        //private static string clientAccountNumber="8011";//the dental office number set by EHG
        //private static string creditCardChoices="MC,D,V,A";//MasterCard,Discover,Visa,AmericanExpress
        //private static string userName="";
        //private static string password="";

        ///<summary>Returns empty list if no errors.  Otherwise returns a list with error messages.</summary>
        public static List <string> Validate(long clinicNum)
        {
            List <string> listErrors   = new List <string>();
            Clinic        clinic       = Clinics.GetClinic(clinicNum);
            Ebill         eBillClinic  = Ebills.GetForClinic(clinicNum);
            Ebill         eBillDefault = Ebills.GetForClinic(0);
            EHG_Address   addressRemit = null;

            if (eBillClinic == null)
            {
                addressRemit = GetAddress(eBillDefault.RemitAddress, clinic);
            }
            else
            {
                addressRemit = GetAddress(eBillClinic.RemitAddress, clinic);
            }
            if (addressRemit.Address1.Trim().Length == 0 || addressRemit.City.Trim().Length == 0 ||
                addressRemit.State.Trim().Length == 0 || addressRemit.Zip.Trim().Length == 0)
            {
                listErrors.Add(Lan.g("EHG_Statements", "invalid") + " " + Lan.g("EHG_Statements", addressRemit.Source));
            }
            return(listErrors);
        }
예제 #7
0
        ///<summary>Determines if the Task is in the Clinic's region.</summary>
        private bool IsTaskInRegionAndUnrestricted(Task task, Userod user)
        {
            bool        retVal             = false;
            Clinic      clinic             = Clinics.GetClinic(user.ClinicNum);
            List <long> listUserClinicNums = Clinics.GetAllForUserod(user).Select(x => x.ClinicNum).ToList();

            switch (task.ObjectType)
            {
            case TaskObjectType.Appointment:
                Appointment appt       = Appointments.GetOneApt(task.KeyNum);
                Clinic      clinicAppt = Clinics.GetClinic(appt.ClinicNum);
                //Is Appointment's clinic in the same region as passed in clinic, and user has permission to view the clinicAppt?
                //0 Region also allowed.
                if (clinicAppt.Region == 0 || (clinicAppt.Region == clinic.Region && listUserClinicNums.Any(x => x == clinicAppt.ClinicNum)))
                {
                    retVal = true;
                }
                break;

            case TaskObjectType.Patient:
                Patient pat       = Patients.GetPat(task.KeyNum);
                Clinic  clinicPat = Clinics.GetClinic(pat.ClinicNum);
                //Is Appointment's clinic in the same region as passed in clinic, and user has permission to view the clinicPat?
                //0 Region also allowed.
                if (clinicPat.Region == 0 || (clinicPat.Region == clinic.Region && listUserClinicNums.Any(x => x == clinicPat.ClinicNum)))
                {
                    retVal = true;
                }
                break;

            case TaskObjectType.None:
                retVal = true;
                break;
            }
            return(retVal);
        }
예제 #8
0
        public static string Validate(Appointment appt)
        {
            StringBuilder sb           = new StringBuilder();
            Provider      provFacility = Providers.GetProv(PrefC.GetInt(PrefName.PracticeDefaultProv));

            if (!Regex.IsMatch(provFacility.NationalProvID, "^(80840)?[0-9]{10}$"))
            {
                WriteError(sb, "Invalid NPI for provider '" + provFacility.Abbr + "'");
            }
            if (PrefC.HasClinicsEnabled && appt.ClinicNum != 0)           //Using clinics and a clinic is assigned.
            {
                Clinic clinic = Clinics.GetClinic(appt.ClinicNum);
                if (clinic.Description == "")
                {
                    WriteError(sb, "Missing clinic description for clinic attached to appointment.");
                }
            }
            else              //Not using clinics for this patient
            {
                if (PrefC.GetString(PrefName.PracticeTitle) == "")
                {
                    WriteError(sb, "Missing practice title.");
                }
            }
            Patient pat = Patients.GetPat(appt.PatNum);

            if (pat.PatStatus == PatientStatus.Deceased && pat.DateTimeDeceased.Year < 1880)
            {
                WriteError(sb, "Missing date time deceased.");
            }
            List <EhrAptObs> listObservations = EhrAptObses.Refresh(appt.AptNum);

            if (listObservations.Count == 0)
            {
                WriteError(sb, "Missing observation.");
            }
            for (int i = 0; i < listObservations.Count; i++)
            {
                EhrAptObs obs = listObservations[i];
                if (obs.ValType == EhrAptObsType.Coded)
                {
                    if (obs.ValCodeSystem.Trim().ToUpper() == "LOINC")
                    {
                        Loinc loincVal = Loincs.GetByCode(obs.ValReported);
                        if (loincVal == null)
                        {
                            WriteError(sb, "Loinc code not found '" + loincVal.LoincCode + "'.  Please add by going to Setup | Chart | EHR.");
                        }
                    }
                    else if (obs.ValCodeSystem.Trim().ToUpper() == "SNOMEDCT")
                    {
                        Snomed snomedVal = Snomeds.GetByCode(obs.ValReported);
                        if (snomedVal == null)
                        {
                            WriteError(sb, "Snomed code not found '" + snomedVal.SnomedCode + "'.  Please add by going to Setup | Chart | EHR.");
                        }
                    }
                    else if (obs.ValCodeSystem.Trim().ToUpper() == "ICD9")
                    {
                        ICD9 icd9Val = ICD9s.GetByCode(obs.ValReported);
                        if (icd9Val == null)
                        {
                            WriteError(sb, "ICD9 code not found '" + icd9Val.ICD9Code + "'.  Please add by going to Setup | Chart | EHR.");
                        }
                    }
                    else if (obs.ValCodeSystem.Trim().ToUpper() == "ICD10")
                    {
                        Icd10 icd10Val = Icd10s.GetByCode(obs.ValReported);
                        if (icd10Val == null)
                        {
                            WriteError(sb, "ICD10 code not found '" + icd10Val.Icd10Code + "'.  Please add by going to Setup | Chart | EHR.");
                        }
                    }
                }
                else if (obs.ValType == EhrAptObsType.Numeric && obs.UcumCode != "")             //We only validate the ucum code if it will be sent out.  Blank units allowed.
                {
                    Ucum ucum = Ucums.GetByCode(obs.UcumCode);
                    if (ucum == null)
                    {
                        WriteError(sb, "Invalid unit code '" + obs.UcumCode + "' for observation (must be UCUM code).");
                    }
                }
            }
            return(sb.ToString());
        }
예제 #9
0
        ///<summary>Adds the xml for one statement.</summary>
        public static void GenerateOneStatement(XmlWriter writer, Statement stmt, Patient pat, Family fam, DataSet dataSet)
        {
            Patient guar = fam.ListPats[0];

            writer.WriteStartElement("Statement");
            //writer.WriteAttributeString("CreditCardChoice",PrefC.GetString(PrefName.BillingElectCreditCardChoices"));
            //remit address----------------------------------------------------------
            writer.WriteStartElement("RemitAddress");
            if (!PrefC.GetBool(PrefName.EasyNoClinics) && Clinics.List.Length > 0 &&       //if using clinics
                Clinics.GetClinic(guar.ClinicNum) != null)                 //and this guar is assigned to a clinic
            {
                Clinic clinic = Clinics.GetClinic(guar.ClinicNum);
                writer.WriteElementString("Name", clinic.Description);
                writer.WriteElementString("Address", clinic.Address);
                writer.WriteElementString("Address2", clinic.Address2);
                writer.WriteElementString("City", clinic.City);
                writer.WriteElementString("State", clinic.State);
                writer.WriteElementString("Zip", clinic.Zip);
                string phone = "";
                if (clinic.Phone.Length == 10)
                {
                    phone = "(" + clinic.Phone.Substring(0, 3) + ")" + clinic.Phone.Substring(3, 3) + "-" + clinic.Phone.Substring(6);
                }
                writer.WriteElementString("Phone", phone);
            }
            else             //not using clinics
            {
                writer.WriteElementString("Name", PrefC.GetString(PrefName.PracticeTitle));
                writer.WriteElementString("Address", PrefC.GetString(PrefName.PracticeAddress));
                writer.WriteElementString("Address2", PrefC.GetString(PrefName.PracticeAddress2));
                writer.WriteElementString("City", PrefC.GetString(PrefName.PracticeCity));
                writer.WriteElementString("State", PrefC.GetString(PrefName.PracticeST));
                writer.WriteElementString("Zip", PrefC.GetString(PrefName.PracticeZip));
                writer.WriteElementString("Phone", PrefC.GetString(PrefName.PracticePhone));
            }
            writer.WriteEndElement();            //RemitAddress
            //Patient-------------------------------------------------------------------------------
            writer.WriteStartElement("Patient");
            writer.WriteElementString("Name", guar.GetNameFLFormal());
            writer.WriteElementString("AccountNum", guar.PatNum.ToString());
            writer.WriteElementString("Address", guar.Address);
            writer.WriteElementString("Address2", guar.Address2);
            writer.WriteElementString("City", guar.City);
            writer.WriteElementString("State", guar.State);
            writer.WriteElementString("Zip", guar.Zip);
            writer.WriteEndElement();            //Patient
            //Account summary-----------------------------------------------------------------------
            writer.WriteStartElement("AccountSummary");
            if (PrefC.GetLong(PrefName.StatementsCalcDueDate) == -1)
            {
                writer.WriteElementString("DueDate", Lan.g("FormRpStatement", "Upon Receipt"));
            }
            else
            {
                DateTime dueDate = DateTime.Today.AddDays(PrefC.GetLong(PrefName.StatementsCalcDueDate));
                writer.WriteElementString("DueDate", dueDate.ToString("MM/dd/yyyy"));
            }
            writer.WriteElementString("StatementDate", stmt.DateSent.ToString("MM/dd/yyyy"));
            DataTable tableAccount = null;

            for (int i = 0; i < dataSet.Tables.Count; i++)
            {
                if (dataSet.Tables[i].TableName.StartsWith("account"))
                {
                    tableAccount = dataSet.Tables[i];
                }
            }
            //on a regular printed statement, the amount due at the top might be different from the balance at the middle right.
            //This is because of payment plan balances.
            //But in e-bills, there is only one amount due.
            //Insurance estimate is already subtracted, and payment plan balance is already added.
            double amountDue = guar.BalTotal;

            //add payplan due amt:
            for (int m = 0; m < dataSet.Tables["misc"].Rows.Count; m++)
            {
                if (dataSet.Tables["misc"].Rows[m]["descript"].ToString() == "payPlanDue")
                {
                    amountDue += PIn.Double(dataSet.Tables["misc"].Rows[m]["value"].ToString());
                }
            }
            if (PrefC.GetBool(PrefName.BalancesDontSubtractIns))
            {
                writer.WriteElementString("EstInsPayments", "");                         //optional.
            }
            else                                                                         //this is typical
            {
                writer.WriteElementString("EstInsPayments", guar.InsEst.ToString("F2")); //optional.
                amountDue -= guar.InsEst;
            }
            InstallmentPlan installPlan = InstallmentPlans.GetOneForFam(guar.PatNum);

            if (installPlan != null)
            {
                //show lesser of normal total balance or the monthly payment amount.
                if (installPlan.MonthlyPayment < amountDue)
                {
                    amountDue = installPlan.MonthlyPayment;
                }
            }
            writer.WriteElementString("AmountDue", amountDue.ToString("F2"));
            writer.WriteElementString("Bal_0_30", guar.Bal_0_30.ToString("F2"));
            writer.WriteElementString("Bal_31_60", guar.Bal_31_60.ToString("F2"));
            writer.WriteElementString("Bal_61_90", guar.Bal_61_90.ToString("F2"));
            writer.WriteElementString("BalOver90", guar.BalOver90.ToString("F2"));
            writer.WriteEndElement();            //AccountSummary
            //Notes-----------------------------------------------------------------------------------
            writer.WriteStartElement("Notes");
            if (stmt.NoteBold != "")
            {
                writer.WriteStartElement("Note");
                writer.WriteAttributeString("FgColor", ColorToHexString(Color.DarkRed));
                writer.WriteCData(stmt.NoteBold);
                writer.WriteEndElement();                //Note
            }
            if (stmt.Note != "")
            {
                writer.WriteStartElement("Note");
                writer.WriteAttributeString("FgColor", ColorToHexString(Color.Black));
                writer.WriteCData(stmt.Note);
                writer.WriteEndElement();        //Note
            }
            writer.WriteEndElement();            //Notes
            //Detail items------------------------------------------------------------------------------
            writer.WriteStartElement("DetailItems");
            string descript;
            string fulldesc;
            string procCode;
            string tth;

            string[]      lineArray;
            List <string> lines;
            DateTime      date;
            int           seq = 0;

            for (int i = 0; i < tableAccount.Rows.Count; i++)
            {
                procCode  = tableAccount.Rows[i]["ProcCode"].ToString();
                tth       = tableAccount.Rows[i]["tth"].ToString();
                descript  = tableAccount.Rows[i]["description"].ToString();
                fulldesc  = procCode + " " + tth + " " + descript;
                lineArray = fulldesc.Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries);
                lines     = new List <string>(lineArray);
                //We assume that the line limit is 40 char.
                if (lines[0].Length > 40)
                {
                    string newline = lines[0].Substring(40);
                    lines[0] = lines[0].Substring(0, 40);       //first half
                    lines.Insert(1, newline);                   //second half
                }
                for (int li = 0; li < lines.Count; li++)
                {
                    writer.WriteStartElement("Item");
                    writer.WriteAttributeString("sequence", seq.ToString());
                    if (li == 0)
                    {
                        date = (DateTime)tableAccount.Rows[i]["DateTime"];
                        writer.WriteElementString("Date", date.ToString("MM/dd/yyyy"));
                        writer.WriteElementString("PatientName", tableAccount.Rows[i]["patient"].ToString());
                    }
                    else
                    {
                        writer.WriteElementString("Date", "");
                        writer.WriteElementString("PatientName", "");
                    }
                    writer.WriteElementString("Description", lines[li]);
                    if (li == 0)
                    {
                        writer.WriteElementString("Charges", tableAccount.Rows[i]["charges"].ToString());
                        writer.WriteElementString("Credits", tableAccount.Rows[i]["credits"].ToString());
                        writer.WriteElementString("Balance", tableAccount.Rows[i]["balance"].ToString());
                    }
                    else
                    {
                        writer.WriteElementString("Charges", "");
                        writer.WriteElementString("Credits", "");
                        writer.WriteElementString("Balance", "");
                    }
                    writer.WriteEndElement();                    //Item
                    seq++;
                }
            }
            writer.WriteEndElement();            //DetailItems
            writer.WriteEndElement();            //Statement
        }
예제 #10
0
        ///<summary>Supply pd so that we know the paper size and margins.</summary>
        public static void CreateDocument(FormRpStatement sender, MigraDoc.DocumentObjectModel.Document doc, PrintDocument pd, Family fam, Patient pat, DataSet dataSet, Statement Stmt)
        {
            //doc= new MigraDoc.DocumentObjectModel.Document();//don't do this or the reference to the original doc will be lost.
            doc.DefaultPageSetup.PageWidth    = Unit.FromInch((double)pd.DefaultPageSettings.PaperSize.Width / 100);
            doc.DefaultPageSetup.PageHeight   = Unit.FromInch((double)pd.DefaultPageSettings.PaperSize.Height / 100);
            doc.DefaultPageSetup.TopMargin    = Unit.FromInch((double)pd.DefaultPageSettings.Margins.Top / 100);
            doc.DefaultPageSetup.LeftMargin   = Unit.FromInch((double)pd.DefaultPageSettings.Margins.Left / 100);
            doc.DefaultPageSetup.RightMargin  = Unit.FromInch((double)pd.DefaultPageSettings.Margins.Right / 100);
            doc.DefaultPageSetup.BottomMargin = Unit.FromInch((double)pd.DefaultPageSettings.Margins.Bottom / 100);
            MigraDoc.DocumentObjectModel.Section section = doc.AddSection();          //so that Swiss will have different footer for each patient.
            string text;

            MigraDoc.DocumentObjectModel.Font font;
            //GetPatGuar(PatNums[famIndex][0]);
            //Family fam=Patients.GetFamily(Stmt.PatNum);
            Patient PatGuar = fam.ListPats[0];          //.Copy();
            //Patient pat=fam.GetPatient(Stmt.PatNum);
            DataTable tableMisc = dataSet.Tables["misc"];

            //HEADING------------------------------------------------------------------------------
            #region Heading
            Paragraph       par       = section.AddParagraph();
            ParagraphFormat parformat = new ParagraphFormat();
            parformat.Alignment = ParagraphAlignment.Center;
            par.Format          = parformat;
            font = MigraDocHelper.CreateFont(14, true);
            text = "This statement was generated from the plug-in";
            par.AddFormattedText(text, font);
            text = DateTime.Today.ToShortDateString();
            font = MigraDocHelper.CreateFont(10);
            par.AddLineBreak();
            par.AddFormattedText(text, font);
            text = Lan.g("FormRpStatement", "Account Number") + " ";
            if (PrefC.GetBool(PrefName.StatementAccountsUseChartNumber))
            {
                text += PatGuar.ChartNumber;
            }
            else
            {
                text += PatGuar.PatNum;
            }
            par.AddLineBreak();
            par.AddFormattedText(text, font);
            TextFrame frame;
            #endregion
            //Practice Address----------------------------------------------------------------------
            #region Practice Address
            if (PrefC.GetBool(PrefName.StatementShowReturnAddress))
            {
                font  = MigraDocHelper.CreateFont(10);
                frame = section.AddTextFrame();
                frame.RelativeVertical   = RelativeVertical.Page;
                frame.RelativeHorizontal = RelativeHorizontal.Page;
                frame.MarginLeft         = Unit.Zero;
                frame.MarginTop          = Unit.Zero;
                frame.Top   = TopPosition.Parse("0.5 in");
                frame.Left  = LeftPosition.Parse("0.3 in");
                frame.Width = Unit.FromInch(3);
                if (!PrefC.GetBool(PrefName.EasyNoClinics) && Clinics.List.Length > 0 &&           //if using clinics
                    Clinics.GetClinic(PatGuar.ClinicNum) != null)                             //and this patient assigned to a clinic
                {
                    Clinic clinic = Clinics.GetClinic(PatGuar.ClinicNum);
                    par             = frame.AddParagraph();
                    par.Format.Font = font;
                    par.AddText(clinic.Description);
                    par.AddLineBreak();
                    par.AddText(clinic.Address);
                    par.AddLineBreak();
                    if (clinic.Address2 != "")
                    {
                        par.AddText(clinic.Address2);
                        par.AddLineBreak();
                    }
                    if (CultureInfo.CurrentCulture.Name.EndsWith("CH"))                     //CH is for switzerland. eg de-CH
                    {
                        par.AddText(clinic.Zip + " " + clinic.City);
                    }
                    else
                    {
                        par.AddText(clinic.City + ", " + clinic.State + " " + clinic.Zip);
                    }
                    par.AddLineBreak();
                    text = clinic.Phone;
                    if (text.Length == 10)
                    {
                        text = "(" + text.Substring(0, 3) + ")" + text.Substring(3, 3) + "-" + text.Substring(6);
                    }
                    par.AddText(text);
                    par.AddLineBreak();
                }
                else
                {
                    par             = frame.AddParagraph();
                    par.Format.Font = font;
                    par.AddText(PrefC.GetString(PrefName.PracticeTitle));
                    par.AddLineBreak();
                    if (CultureInfo.CurrentCulture.Name == "en-AU")                   //English (Australia)
                    {
                        Provider defaultProv = Providers.GetProv(PrefC.GetLong(PrefName.PracticeDefaultProv));
                        par.AddText("ABN: " + defaultProv.NationalProvID);
                        par.AddLineBreak();
                    }
                    par.AddText(PrefC.GetString(PrefName.PracticeAddress));
                    par.AddLineBreak();
                    if (PrefC.GetString(PrefName.PracticeAddress2) != "")
                    {
                        par.AddText(PrefC.GetString(PrefName.PracticeAddress2));
                        par.AddLineBreak();
                    }
                    if (CultureInfo.CurrentCulture.Name.EndsWith("CH"))                     //CH is for switzerland. eg de-CH
                    {
                        par.AddText(PrefC.GetString(PrefName.PracticeZip) + " " + PrefC.GetString(PrefName.PracticeCity));
                    }
                    else
                    {
                        par.AddText(PrefC.GetString(PrefName.PracticeCity) + ", " + PrefC.GetString(PrefName.PracticeST) + " " + PrefC.GetString(PrefName.PracticeZip));
                    }
                    par.AddLineBreak();
                    text = PrefC.GetString(PrefName.PracticePhone);
                    if (text.Length == 10)
                    {
                        text = "(" + text.Substring(0, 3) + ")" + text.Substring(3, 3) + "-" + text.Substring(6);
                    }
                    par.AddText(text);
                    par.AddLineBreak();
                }
            }
            #endregion
            //AMOUNT ENCLOSED------------------------------------------------------------------------------------------------------
            #region Amount Enclosed
            Table  table;
            Column col;
            Row    row;
            Cell   cell;
            frame = MigraDocHelper.CreateContainer(section, 450, 110, 330, 29);
            if (!Stmt.HidePayment)
            {
                table = MigraDocHelper.DrawTable(frame, 0, 0, 29);
                col   = table.AddColumn(Unit.FromInch(1.1));
                col   = table.AddColumn(Unit.FromInch(1.1));
                col   = table.AddColumn(Unit.FromInch(1.1));
                row   = table.AddRow();
                row.Format.Alignment = ParagraphAlignment.Center;
                row.Borders.Color    = Colors.Black;
                row.Shading.Color    = Colors.LightGray;
                row.TopPadding       = Unit.FromInch(0);
                row.BottomPadding    = Unit.FromInch(0);
                font = MigraDocHelper.CreateFont(8, true);
                cell = row.Cells[0];
                par  = cell.AddParagraph();
                par.AddFormattedText(Lan.g("FormRpStatement", "Amount Due"), font);
                cell = row.Cells[1];
                par  = cell.AddParagraph();
                par.AddFormattedText(Lan.g("FormRpStatement", "Date Due"), font);
                cell = row.Cells[2];
                par  = cell.AddParagraph();
                par.AddFormattedText(Lan.g("FormRpStatement", "Amount Enclosed"), font);
                row = table.AddRow();
                row.Format.Alignment     = ParagraphAlignment.Center;
                row.Borders.Left.Color   = Colors.Gray;
                row.Borders.Bottom.Color = Colors.Gray;
                row.Borders.Right.Color  = Colors.Gray;
                font = MigraDocHelper.CreateFont(9);
                double balTotal = PatGuar.BalTotal;
                if (!PrefC.GetBool(PrefName.BalancesDontSubtractIns))                 //this is typical
                {
                    balTotal -= PatGuar.InsEst;
                }
                for (int m = 0; m < tableMisc.Rows.Count; m++)
                {
                    if (tableMisc.Rows[m]["descript"].ToString() == "payPlanDue")
                    {
                        balTotal += PIn.Double(tableMisc.Rows[m]["value"].ToString());
                        //payPlanDue;//PatGuar.PayPlanDue;
                    }
                }
                text = balTotal.ToString("F");
                cell = row.Cells[0];
                par  = cell.AddParagraph();
                par.AddFormattedText(text, font);
                if (PrefC.GetLong(PrefName.StatementsCalcDueDate) == -1)
                {
                    text = Lan.g("FormRpStatement", "Upon Receipt");
                }
                else
                {
                    text = DateTime.Today.AddDays(PrefC.GetLong(PrefName.StatementsCalcDueDate)).ToShortDateString();
                }
                cell = row.Cells[1];
                par  = cell.AddParagraph();
                par.AddFormattedText(text, font);
            }
            #endregion
            //Credit Card Info--------------------------------------------------------------------------------------------------------
            #region Credit Card Info
            if (!Stmt.HidePayment)
            {
                if (PrefC.GetBool(PrefName.StatementShowCreditCard))
                {
                    float yPos = 60;
                    font = MigraDocHelper.CreateFont(7, true);
                    text = Lan.g("FormRpStatement", "CREDIT CARD TYPE");
                    MigraDocHelper.DrawString(frame, text, font, 0, yPos);
                    float rowHeight            = 26;
                    System.Drawing.Font  wfont = new System.Drawing.Font("Arial", 7, FontStyle.Bold);
                    System.Drawing.Image img   = new Bitmap(500, 30);
                    Graphics             g     = Graphics.FromImage(img);  //just to measure strings
                    MigraDocHelper.DrawLine(frame, System.Drawing.Color.Black, g.MeasureString(text, wfont).Width,
                                            yPos + wfont.GetHeight(g), 326, yPos + wfont.GetHeight(g));
                    yPos += rowHeight;
                    text  = Lan.g("FormRpStatement", "#");
                    MigraDocHelper.DrawString(frame, text, font, 0, yPos);
                    MigraDocHelper.DrawLine(frame, System.Drawing.Color.Black, g.MeasureString(text, wfont).Width,
                                            yPos + wfont.GetHeight(g), 326, yPos + wfont.GetHeight(g));
                    yPos += rowHeight;
                    text  = Lan.g("FormRpStatement", "3 DIGIT CSV");
                    MigraDocHelper.DrawString(frame, text, font, 0, yPos);
                    MigraDocHelper.DrawLine(frame, System.Drawing.Color.Black, g.MeasureString(text, wfont).Width,
                                            yPos + wfont.GetHeight(g), 326, yPos + wfont.GetHeight(g));
                    yPos += rowHeight;
                    text  = Lan.g("FormRpStatement", "EXPIRES");
                    MigraDocHelper.DrawString(frame, text, font, 0, yPos);
                    MigraDocHelper.DrawLine(frame, System.Drawing.Color.Black, g.MeasureString(text, wfont).Width,
                                            yPos + wfont.GetHeight(g), 326, yPos + wfont.GetHeight(g));
                    yPos += rowHeight;
                    text  = Lan.g("FormRpStatement", "AMOUNT APPROVED");
                    MigraDocHelper.DrawString(frame, text, font, 0, yPos);
                    MigraDocHelper.DrawLine(frame, System.Drawing.Color.Black, g.MeasureString(text, wfont).Width,
                                            yPos + wfont.GetHeight(g), 326, yPos + wfont.GetHeight(g));
                    yPos += rowHeight;
                    text  = Lan.g("FormRpStatement", "NAME");
                    MigraDocHelper.DrawString(frame, text, font, 0, yPos);
                    MigraDocHelper.DrawLine(frame, System.Drawing.Color.Black, g.MeasureString(text, wfont).Width,
                                            yPos + wfont.GetHeight(g), 326, yPos + wfont.GetHeight(g));
                    yPos += rowHeight;
                    text  = Lan.g("FormRpStatement", "SIGNATURE");
                    MigraDocHelper.DrawString(frame, text, font, 0, yPos);
                    MigraDocHelper.DrawLine(frame, System.Drawing.Color.Black, g.MeasureString(text, wfont).Width,
                                            yPos + wfont.GetHeight(g), 326, yPos + wfont.GetHeight(g));
                    yPos -= rowHeight;
                    text  = Lan.g("FormRpStatement", "(As it appears on card)");
                    wfont = new System.Drawing.Font("Arial", 5);
                    font  = MigraDocHelper.CreateFont(5);
                    MigraDocHelper.DrawString(frame, text, font, 625 - g.MeasureString(text, wfont).Width / 2 + 5, yPos + 13);
                    g.Dispose();
                    img = null;
                }
            }
            #endregion
            //Patient's Billing Address---------------------------------------------------------------------------------------------
            #region Patient Billing Address
            font            = MigraDocHelper.CreateFont(11);
            frame           = MigraDocHelper.CreateContainer(section, 62.5f + 12.5f, 225 + 1, 300, 200);
            par             = frame.AddParagraph();
            par.Format.Font = font;
            if (Stmt.SinglePatient)
            {
                par.AddText(fam.GetNameInFamFL(Stmt.PatNum));
            }
            else
            {
                par.AddText(PatGuar.GetNameFLFormal());
            }
            par.AddLineBreak();
            par.AddText(PatGuar.Address);
            par.AddLineBreak();
            if (PatGuar.Address2 != "")
            {
                par.AddText(PatGuar.Address2);
                par.AddLineBreak();
            }
            if (CultureInfo.CurrentCulture.Name.EndsWith("CH"))             //CH is for switzerland. eg de-CH
            {
                par.AddText(PatGuar.Zip + " " + PatGuar.City);
            }
            else
            {
                par.AddText(PatGuar.City + ", " + PatGuar.State + " " + PatGuar.Zip);
            }
            //perforated line------------------------------------------------------------------------------------------------------
            //yPos=350;//3.62 inches from top, 1/3 page down
            frame = MigraDocHelper.CreateContainer(section, 0, 350, 850, 30);
            if (!Stmt.HidePayment)
            {
                MigraDocHelper.DrawLine(frame, System.Drawing.Color.LightGray, 0, 0, 850, 0);
                text = Lan.g("FormRpStatement", "PLEASE DETACH AND RETURN THE UPPER PORTION WITH YOUR PAYMENT");
                font = MigraDocHelper.CreateFont(6, true, System.Drawing.Color.Gray);
                par  = frame.AddParagraph();
                par.Format.Alignment = ParagraphAlignment.Center;
                par.Format.Font      = font;
                par.AddText(text);
            }
            #endregion
            //Australian Provider Legend
            #region Australian Provider Legend
            int legendOffset = 0;
            if (CultureInfo.CurrentCulture.Name == "en-AU")           //English (Australia)
            {
                Providers.RefreshCache();
                legendOffset = 25 + 15 * (1 + ProviderC.List.Length);
                MigraDocHelper.InsertSpacer(section, legendOffset);
                frame           = MigraDocHelper.CreateContainer(section, 45, 390, 250, legendOffset);
                par             = frame.AddParagraph();
                par.Format.Font = MigraDocHelper.CreateFont(8, true);
                par.AddLineBreak();
                par.AddText("PROVIDERS:");
                par             = frame.AddParagraph();
                par.Format.Font = MigraDocHelper.CreateFont(8, false);
                for (int i = 0; i < ProviderC.List.Length; i++)           //All non-hidden providers are added to the legend.
                {
                    Provider prov   = ProviderC.List[i];
                    string   suffix = "";
                    if (prov.Suffix.Trim() != "")
                    {
                        suffix = ", " + prov.Suffix.Trim();
                    }
                    par.AddText(prov.Abbr + " - " + prov.FName + " " + prov.LName + suffix + " - " + prov.MedicaidID);
                    par.AddLineBreak();
                }
                par.AddLineBreak();
            }
            #endregion
            //Aging-----------------------------------------------------------------------------------
            #region Aging
            MigraDocHelper.InsertSpacer(section, 275);
            frame = MigraDocHelper.CreateContainer(section, 55, 390 + legendOffset, 250, 29);
            if (!Stmt.HidePayment)
            {
                table = MigraDocHelper.DrawTable(frame, 0, 0, 29);
                col   = table.AddColumn(Unit.FromInch(1.1));
                col   = table.AddColumn(Unit.FromInch(1.1));
                col   = table.AddColumn(Unit.FromInch(1.1));
                col   = table.AddColumn(Unit.FromInch(1.1));
                row   = table.AddRow();
                row.Format.Alignment = ParagraphAlignment.Center;
                row.Borders.Color    = Colors.Black;
                row.Shading.Color    = Colors.LightGray;
                row.TopPadding       = Unit.FromInch(0);
                row.BottomPadding    = Unit.FromInch(0);
                font = MigraDocHelper.CreateFont(8, true);
                cell = row.Cells[0];
                par  = cell.AddParagraph();
                par.AddFormattedText(Lan.g("FormRpStatement", "0-30"), font);
                cell = row.Cells[1];
                par  = cell.AddParagraph();
                par.AddFormattedText(Lan.g("FormRpStatement", "31-60"), font);
                cell = row.Cells[2];
                par  = cell.AddParagraph();
                par.AddFormattedText(Lan.g("FormRpStatement", "61-90"), font);
                cell = row.Cells[3];
                par  = cell.AddParagraph();
                par.AddFormattedText(Lan.g("FormRpStatement", "over 90"), font);
                row = table.AddRow();
                row.Format.Alignment     = ParagraphAlignment.Center;
                row.Borders.Left.Color   = Colors.Gray;
                row.Borders.Bottom.Color = Colors.Gray;
                row.Borders.Right.Color  = Colors.Gray;
                font = MigraDocHelper.CreateFont(9);
                text = PatGuar.Bal_0_30.ToString("F");
                cell = row.Cells[0];
                par  = cell.AddParagraph();
                par.AddFormattedText(text, font);
                text = PatGuar.Bal_31_60.ToString("F");
                cell = row.Cells[1];
                par  = cell.AddParagraph();
                par.AddFormattedText(text, font);
                text = PatGuar.Bal_61_90.ToString("F");
                cell = row.Cells[2];
                par  = cell.AddParagraph();
                par.AddFormattedText(text, font);
                text = PatGuar.BalOver90.ToString("F");
                cell = row.Cells[3];
                par  = cell.AddParagraph();
                par.AddFormattedText(text, font);
            }
            #endregion
            //Floating Balance, Ins info-------------------------------------------------------------------
            #region FloatingBalance
            frame = MigraDocHelper.CreateContainer(section, 460, 380 + legendOffset, 250, 200);
            //table=MigraDocHelper.DrawTable(frame,0,0,90);
            par                 = frame.AddParagraph();
            parformat           = new ParagraphFormat();
            parformat.Alignment = ParagraphAlignment.Right;
            par.Format          = parformat;
            font                = MigraDocHelper.CreateFont(10, false);
            MigraDoc.DocumentObjectModel.Font fontBold = MigraDocHelper.CreateFont(10, true);
            if (PrefC.GetBool(PrefName.BalancesDontSubtractIns))
            {
                text = Lan.g("FormRpStatement", "Balance:");
                par.AddFormattedText(text, fontBold);
                //par.AddLineBreak();
                //text = Lan.g(this, "Ins Pending:");
                //par.AddFormattedText(text, font);
                //par.AddLineBreak();
                //text = Lan.g(this, "After Ins:");
                //par.AddFormattedText(text, font);
                //par.AddLineBreak();
            }
            else              //this is more common
            {
                if (PrefC.GetBool(PrefName.FuchsOptionsOn))
                {
                    text = Lan.g("FormRpStatement", "Balance:");
                    par.AddFormattedText(text, font);
                    par.AddLineBreak();
                    text = Lan.g("FormRpStatement", "-Ins Estimate:");
                    par.AddFormattedText(text, font);
                    par.AddLineBreak();
                    text = Lan.g("FormRpStatement", "=Owed Now:");
                    par.AddFormattedText(text, fontBold);
                    par.AddLineBreak();
                }
                else
                {
                    text = Lan.g("FormRpStatement", "Total:");
                    par.AddFormattedText(text, font);
                    par.AddLineBreak();
                    text = Lan.g("FormRpStatement", "-Ins Estimate:");
                    par.AddFormattedText(text, font);
                    par.AddLineBreak();
                    text = Lan.g("FormRpStatement", "=Balance:");
                    par.AddFormattedText(text, fontBold);
                    par.AddLineBreak();
                }
            }
            frame = MigraDocHelper.CreateContainer(section, 730, 380 + legendOffset, 100, 200);
            //table=MigraDocHelper.DrawTable(frame,0,0,90);
            par                 = frame.AddParagraph();
            parformat           = new ParagraphFormat();
            parformat.Alignment = ParagraphAlignment.Left;
            par.Format          = parformat;
            font                = MigraDocHelper.CreateFont(10, false);
            //numbers:
            if (PrefC.GetBool(PrefName.BalancesDontSubtractIns))
            {
                text = PatGuar.BalTotal.ToString("c");
                par.AddFormattedText(text, fontBold);
                //par.AddLineBreak();
                //text = PatGuar.InsEst.ToString("c");
                //par.AddFormattedText(text, font);
                //par.AddLineBreak();
                //text = (PatGuar.BalTotal - PatGuar.InsEst).ToString("c");
                //par.AddFormattedText(text, font);
                //par.AddLineBreak();
            }
            else              //more common
            {
                if (Stmt.SinglePatient)
                {
                    double patInsEst = 0;
                    for (int m = 0; m < tableMisc.Rows.Count; m++)
                    {
                        if (tableMisc.Rows[m]["descript"].ToString() == "patInsEst")
                        {
                            patInsEst = PIn.Double(tableMisc.Rows[m]["value"].ToString());
                        }
                    }
                    double patBal = pat.EstBalance - patInsEst;
                    text = pat.EstBalance.ToString("c");
                    par.AddFormattedText(text, font);
                    par.AddLineBreak();
                    text = patInsEst.ToString("c");
                    par.AddFormattedText(text, font);
                    par.AddLineBreak();
                    text = patBal.ToString("c");
                    par.AddFormattedText(text, fontBold);
                }
                else
                {
                    text = PatGuar.BalTotal.ToString("c");
                    par.AddFormattedText(text, font);
                    par.AddLineBreak();
                    text = PatGuar.InsEst.ToString("c");
                    par.AddFormattedText(text, font);
                    par.AddLineBreak();
                    text = (PatGuar.BalTotal - PatGuar.InsEst).ToString("c");
                    par.AddFormattedText(text, fontBold);
                    par.AddLineBreak();
                }
            }
            MigraDocHelper.InsertSpacer(section, 80);
            #endregion FloatingBalance
            //Bold note-------------------------------------------------------------------------------
            #region Bold note
            if (Stmt.NoteBold != "")
            {
                MigraDocHelper.InsertSpacer(section, 7);
                font            = MigraDocHelper.CreateFont(10, true, System.Drawing.Color.DarkRed);
                par             = section.AddParagraph();
                par.Format.Font = font;
                par.AddText(Stmt.NoteBold);
                MigraDocHelper.InsertSpacer(section, 8);
            }
            #endregion Bold note
            //Payment plan grid definition---------------------------------------------------------------------------------
            #region PayPlan grid definition
            ODGridColumn gcol;
            ODGridRow    grow;
            ODGrid       gridPP = new ODGrid();
            //this.Controls.Add(gridPP);
            gridPP.BeginUpdate();
            gridPP.Columns.Clear();
            gcol = new ODGridColumn(Lan.g("FormRpStatement", "Date"), 73);
            gridPP.Columns.Add(gcol);
            gcol = new ODGridColumn(Lan.g("FormRpStatement", "Description"), 270);
            gridPP.Columns.Add(gcol);
            gcol = new ODGridColumn(Lan.g("FormRpStatement", "Charges"), 60, HorizontalAlignment.Right);
            gridPP.Columns.Add(gcol);
            gcol = new ODGridColumn(Lan.g("FormRpStatement", "Credits"), 60, HorizontalAlignment.Right);
            gridPP.Columns.Add(gcol);
            gcol = new ODGridColumn(Lan.g("FormRpStatement", "Balance"), 60, HorizontalAlignment.Right);
            gridPP.Columns.Add(gcol);
            gridPP.Width = gridPP.WidthAllColumns + 20;
            gridPP.EndUpdate();
            #endregion PayPlan grid definition
            //Payment plan grid.  There will be only one, if any-----------------------------------------------------------------
            #region PayPlan grid
            DataTable  tablePP = dataSet.Tables["payplan"];
            ODGridCell gcell;
            if (tablePP.Rows.Count > 0)
            {
                //MigraDocHelper.InsertSpacer(section,5);
                par                  = section.AddParagraph();
                par.Format.Font      = MigraDocHelper.CreateFont(10, true);
                par.Format.Alignment = ParagraphAlignment.Center;
                //par.Format.SpaceBefore=Unit.FromInch(.05);
                //par.Format.SpaceAfter=Unit.FromInch(.05);
                par.AddText(Lan.g("FormRpStatement", "Payment Plans"));
                MigraDocHelper.InsertSpacer(section, 2);
                gridPP.BeginUpdate();
                gridPP.Rows.Clear();
                for (int p = 0; p < tablePP.Rows.Count; p++)
                {
                    grow = new ODGridRow();
                    grow.Cells.Add(tablePP.Rows[p]["date"].ToString());
                    grow.Cells.Add(tablePP.Rows[p]["description"].ToString());
                    grow.Cells.Add(tablePP.Rows[p]["charges"].ToString());
                    grow.Cells.Add(tablePP.Rows[p]["credits"].ToString());
                    gcell = new ODGridCell(tablePP.Rows[p]["balance"].ToString());
                    if (p == tablePP.Rows.Count - 1)
                    {
                        gcell.Bold = YN.Yes;
                    }
                    else if (tablePP.Rows[p + 1]["balance"].ToString() == "")                 //if next row balance is blank.
                    {
                        gcell.Bold = YN.Yes;
                    }
                    grow.Cells.Add(gcell);
                    gridPP.Rows.Add(grow);
                }
                gridPP.EndUpdate();
                MigraDocHelper.DrawGrid(section, gridPP);
                MigraDocHelper.InsertSpacer(section, 2);
                par                    = section.AddParagraph();
                par.Format.Font        = MigraDocHelper.CreateFont(10, true);
                par.Format.Alignment   = ParagraphAlignment.Right;
                par.Format.RightIndent = Unit.FromInch(0.25);
                double payPlanDue = 0;
                for (int m = 0; m < tableMisc.Rows.Count; m++)
                {
                    if (tableMisc.Rows[m]["descript"].ToString() == "payPlanDue")
                    {
                        payPlanDue = PIn.Double(tableMisc.Rows[m]["value"].ToString());
                    }
                }
                par.AddText(Lan.g("FormRpStatement", "Payment Plan Amount Due: ") + payPlanDue.ToString("c"));             //PatGuar.PayPlanDue.ToString("c"));
                MigraDocHelper.InsertSpacer(section, 10);
            }
            #endregion PayPlan grid
            //Body Table definition--------------------------------------------------------------------------------------------------------
            #region Body Table definition
            ODGrid gridPat = new ODGrid();
            //this.Controls.Add(gridPat);
            gridPat.BeginUpdate();
            gridPat.Columns.Clear();
            gcol = new ODGridColumn(Lan.g("FormRpStatement", "Date"), 73);
            gridPat.Columns.Add(gcol);
            gcol = new ODGridColumn(Lan.g("FormRpStatement", "Patient"), 100);
            gridPat.Columns.Add(gcol);
            //prov
            gcol = new ODGridColumn(Lan.g("FormRpStatement", "Code"), 45);
            gridPat.Columns.Add(gcol);
            gcol = new ODGridColumn(Lan.g("FormRpStatement", "Tooth"), 42);
            gridPat.Columns.Add(gcol);
            gcol = new ODGridColumn(Lan.g("FormRpStatement", "Description"), 270);
            gridPat.Columns.Add(gcol);
            gcol = new ODGridColumn(Lan.g("FormRpStatement", "Charges"), 60, HorizontalAlignment.Right);
            gridPat.Columns.Add(gcol);
            gcol = new ODGridColumn(Lan.g("FormRpStatement", "Credits"), 60, HorizontalAlignment.Right);
            gridPat.Columns.Add(gcol);
            gcol = new ODGridColumn(Lan.g("FormRpStatement", "Balance"), 60, HorizontalAlignment.Right);
            gridPat.Columns.Add(gcol);
            gridPat.Width = gridPat.WidthAllColumns + 20;
            gridPat.EndUpdate();
            #endregion Body Table definition
            //Loop through each table.  Could be one intermingled, or one for each patient-----------------------------------------
            DataTable tableAccount;
            string    tablename;
            long      patnum;
            for (int i = 0; i < dataSet.Tables.Count; i++)
            {
                tableAccount = dataSet.Tables[i];
                tablename    = tableAccount.TableName;
                if (!tablename.StartsWith("account"))
                {
                    continue;
                }
                par                    = section.AddParagraph();
                par.Format.Font        = MigraDocHelper.CreateFont(10, true);
                par.Format.SpaceBefore = Unit.FromInch(.05);
                par.Format.SpaceAfter  = Unit.FromInch(.05);
                patnum                 = 0;
                if (tablename != "account")               //account123 etc.
                {
                    patnum = PIn.Long(tablename.Substring(7));
                }
                if (patnum != 0)
                {
                    par.AddText(fam.GetNameInFamFLnoPref(patnum));
                }
                //if(FamilyStatementDataList[famIndex].PatAboutList[i].ApptDescript!=""){
                //	par=section.AddParagraph();
                //	par.Format.Font=MigraDocHelper.CreateFont(9);//same as body font
                //	par.AddText(FamilyStatementDataList[famIndex].PatAboutList[i].ApptDescript);
                //}
                gridPat.BeginUpdate();
                gridPat.Rows.Clear();
                //lineData=FamilyStatementDataList[famIndex].PatDataList[i].PatData;
                for (int p = 0; p < tableAccount.Rows.Count; p++)
                {
                    grow = new ODGridRow();
                    grow.Cells.Add(tableAccount.Rows[p]["date"].ToString());
                    grow.Cells.Add(tableAccount.Rows[p]["patient"].ToString());
                    grow.Cells.Add(tableAccount.Rows[p]["ProcCode"].ToString());
                    grow.Cells.Add(tableAccount.Rows[p]["tth"].ToString());
                    if (CultureInfo.CurrentCulture.Name == "en-AU")                   //English (Australia)
                    {
                        if (tableAccount.Rows[p]["prov"].ToString().Trim() != "")
                        {
                            grow.Cells.Add(tableAccount.Rows[p]["prov"].ToString() + " - " + tableAccount.Rows[p]["description"].ToString());
                        }
                        else                          //No provider on this account row item, so don't put the extra leading characters.
                        {
                            grow.Cells.Add(tableAccount.Rows[p]["description"].ToString());
                        }
                    }
                    else                      //Assume English (United States)
                    {
                        grow.Cells.Add(tableAccount.Rows[p]["description"].ToString());
                    }
                    grow.Cells.Add(tableAccount.Rows[p]["charges"].ToString());
                    grow.Cells.Add(tableAccount.Rows[p]["credits"].ToString());
                    grow.Cells.Add(tableAccount.Rows[p]["balance"].ToString());
                    gridPat.Rows.Add(grow);
                }
                gridPat.EndUpdate();
                MigraDocHelper.DrawGrid(section, gridPat);
                //Total
                frame = MigraDocHelper.CreateContainer(section);
                font  = MigraDocHelper.CreateFont(9, true);
                float totalPos = ((float)(doc.DefaultPageSetup.PageWidth.Inch //-doc.DefaultPageSetup.LeftMargin.Inch
                                                                              //-doc.DefaultPageSetup.RightMargin.Inch)
                                          ) * 100f) / 2f + (float)gridPat.WidthAllColumns / 2f + 7;
                RectangleF rectF = new RectangleF(0, 0, totalPos, 16);
                if (patnum != 0)
                {
                    MigraDocHelper.DrawString(frame, " ",
                                              //I decided this was unnecessary:
                                              //dataSet.Tables["patient"].Rows[fam.GetIndex(patnum)]["balance"].ToString(),
                                              font, rectF, ParagraphAlignment.Right);
                    //MigraDocHelper.DrawString(frame,FamilyStatementDataList[famIndex].PatAboutList[i].Balance.ToString("F"),font,rectF,
                    //	ParagraphAlignment.Right);
                }
            }
            gridPat.Dispose();
            //Future appointments---------------------------------------------------------------------------------------------
            #region Future appointments
            font = MigraDocHelper.CreateFont(9);
            DataTable tableAppt = dataSet.Tables["appts"];
            if (tableAppt.Rows.Count > 0)
            {
                par             = section.AddParagraph();
                par.Format.Font = font;
                par.AddText(Lan.g("FormRpStatement", "Scheduled Appointments:"));
            }
            for (int i = 0; i < tableAppt.Rows.Count; i++)
            {
                par.AddLineBreak();
                par.AddText(tableAppt.Rows[i]["descript"].ToString());
            }
            if (tableAppt.Rows.Count > 0)
            {
                MigraDocHelper.InsertSpacer(section, 10);
            }
            #endregion Future appointments
            //Note------------------------------------------------------------------------------------------------------------
            font            = MigraDocHelper.CreateFont(9);
            par             = section.AddParagraph();
            par.Format.Font = font;
            par.AddText(Stmt.Note);
            //bold note
            if (Stmt.NoteBold != "")
            {
                MigraDocHelper.InsertSpacer(section, 10);
                font            = MigraDocHelper.CreateFont(10, true, System.Drawing.Color.DarkRed);
                par             = section.AddParagraph();
                par.Format.Font = font;
                par.AddText(Stmt.NoteBold);
            }
            //return doc;
        }
예제 #11
0
        ///<summary>Generates all the xml up to the point where the first statement would go.</summary>
        public static void GeneratePracticeInfo(XmlWriter writer, long clinicNum)
        {
            Clinic clinic       = Clinics.GetClinic(clinicNum);
            Ebill  eBillClinic  = Ebills.GetForClinic(clinicNum);
            Ebill  eBillDefault = Ebills.GetForClinic(0);

            writer.WriteProcessingInstruction("xml", "version = \"1.0\" standalone=\"yes\"");
            writer.WriteStartElement("EISStatementFile");
            writer.WriteAttributeString("VendorID", PrefC.GetString(PrefName.BillingElectVendorId));
            writer.WriteAttributeString("OutputFormat", "StmOut_Blue6Col");
            writer.WriteAttributeString("Version", "2");
            writer.WriteElementString("SubmitDate", DateTime.Today.ToString("yyyy-MM-dd"));
            writer.WriteElementString("PrimarySubmitter", PrefC.GetString(PrefName.BillingElectVendorPMSCode));
            writer.WriteElementString("Transmitter", "EHG");
            writer.WriteStartElement("Practice");
            string billingClientAccountNumber = eBillDefault.ClientAcctNumber;

            if (eBillClinic != null && eBillClinic.ClientAcctNumber != "")         //clinic eBill entry exists, check the fields for overrides
            {
                billingClientAccountNumber = eBillClinic.ClientAcctNumber;
            }
            writer.WriteAttributeString("AccountNumber", billingClientAccountNumber);
            //sender address----------------------------------------------------------
            writer.WriteStartElement("SenderAddress");
            if (clinic == null)
            {
                writer.WriteElementString("Name", PrefC.GetString(PrefName.PracticeTitle));
            }
            else
            {
                writer.WriteElementString("Name", clinic.Description);
            }
            if (eBillClinic == null)
            {
                WriteAddress(writer, eBillDefault.PracticeAddress, clinic);
            }
            else
            {
                WriteAddress(writer, eBillClinic.PracticeAddress, clinic);
            }
            writer.WriteEndElement();            //senderAddress
            //remit address----------------------------------------------------------
            writer.WriteStartElement("RemitAddress");
            if (clinic == null)
            {
                writer.WriteElementString("Name", PrefC.GetString(PrefName.PracticeTitle));
            }
            else
            {
                writer.WriteElementString("Name", clinic.Description);
            }
            if (eBillClinic == null)
            {
                WriteAddress(writer, eBillDefault.RemitAddress, clinic);
            }
            else
            {
                WriteAddress(writer, eBillClinic.RemitAddress, clinic);
            }
            writer.WriteEndElement();            //remitAddress
            //Rendering provider------------------------------------------------------
            Provider prov = Providers.GetProv(PrefC.GetLong(PrefName.PracticeDefaultProv));

            writer.WriteStartElement("RenderingProvider");
            writer.WriteElementString("Name", prov.GetFormalName());
            writer.WriteElementString("LicenseNumber", prov.StateLicense);
            writer.WriteElementString("State", PrefC.GetString(PrefName.PracticeST));
            writer.WriteEndElement();            //Rendering provider
        }
예제 #12
0
        ///<summary>The insplan that's passed in need not be properly updated to the database first.</summary>
        public static void RequestBenefits(Clearinghouse clearhouse, InsPlan plan, long patNum, Carrier carrier, List <Benefit> benList, long patPlanNum, InsSub insSub)
        {
            Patient  pat      = Patients.GetPat(patNum);
            Patient  subsc    = Patients.GetPat(insSub.Subscriber);
            Clinic   clinic   = Clinics.GetClinic(pat.ClinicNum);
            Provider billProv = Providers.GetProv(Providers.GetBillingProvNum(pat.PriProv, pat.ClinicNum));
            //validation.  Throw exception if missing info----------------------------------------
            string validationResult = X270.Validate(clearhouse, carrier, billProv, clinic, plan, subsc, insSub);

            if (validationResult != "")
            {
                throw new Exception(Lan.g("FormInsPlan", "Please fix the following errors first:") + "\r\n" + validationResult);
            }
            //create a 270 message---------------------------------------------------------------
            string            x12message        = X270.GenerateMessageText(clearhouse, carrier, billProv, clinic, plan, subsc, insSub);
            EtransMessageText etransMessageText = new EtransMessageText();

            etransMessageText.MessageText = x12message;
            EtransMessageTexts.Insert(etransMessageText);
            //attach it to an etrans-------------------------------------------------------------
            Etrans etrans = new Etrans();

            etrans.DateTimeTrans        = DateTime.Now;
            etrans.ClearingHouseNum     = clearhouse.ClearinghouseNum;
            etrans.Etype                = EtransType.BenefitInquiry270;
            etrans.PlanNum              = plan.PlanNum;
            etrans.InsSubNum            = insSub.InsSubNum;
            etrans.EtransMessageTextNum = etransMessageText.EtransMessageTextNum;
            Etranss.Insert(etrans);
            //send the 270----------------------------------------------------------------------
            string x12response = "";

            //a connection error here needs to bubble up
            try {
                if (clearhouse.CommBridge == EclaimsCommBridge.ClaimConnect)
                {
                    x12response = ClaimConnect.Benefits270(clearhouse, x12message);
                }
            }
            catch (Exception ex) {
                EtransMessageTexts.Delete(etrans.EtransMessageTextNum);
                Etranss.Delete(etrans.EtransNum);
                throw new ApplicationException(Lan.g("FormInsPlan", "Connection Error:") + "\r\n" + ex.GetType().Name + "\r\n" + ex.Message);
            }
            //start to process the 271----------------------------------------------------------
            X271 x271 = null;

            if (X12object.IsX12(x12response))
            {
                X12object x12obj = new X12object(x12response);
                if (x12obj.Is271())
                {
                    x271 = new X271(x12response);
                }
            }
            else              //neither a 997 nor a 271
            {
                EtransMessageTexts.Delete(etrans.EtransMessageTextNum);
                Etranss.Delete(etrans.EtransNum);
                throw new ApplicationException(Lan.g("FormInsPlan", "Error:") + "\r\n" + x12response);
            }

            /*
             * //In realtime mode, X12 limits the request to one patient.
             * //We will always use the subscriber.
             * //So all EB segments are for the subscriber.
             * List<EB271> listEB=new List<EB271>();
             * EB271 eb;
             * if(x271 != null) {
             *      for(int i=0;i<x271.Segments.Count;i++) {
             *              if(x271.Segments[i].SegmentID != "EB") {
             *                      continue;
             *              }
             *              eb=new EB271(x271.Segments[i]);
             *              listEB.Add(eb);
             *      }
             * }*/
            //create an etrans for the 271------------------------------------------------------
            etransMessageText             = new EtransMessageText();
            etransMessageText.MessageText = x12response;
            EtransMessageTexts.Insert(etransMessageText);
            Etrans etrans271 = new Etrans();

            etrans271.DateTimeTrans    = DateTime.Now;
            etrans271.ClearingHouseNum = clearhouse.ClearinghouseNum;
            etrans271.Etype            = EtransType.TextReport;
            if (X12object.IsX12(x12response))             //this shouldn't need to be tested because it was tested above.
            {
                if (x271 == null)
                {
                    etrans271.Etype = EtransType.Acknowledge_997;
                }
                else
                {
                    etrans271.Etype = EtransType.BenefitResponse271;
                }
            }
            etrans271.PlanNum              = plan.PlanNum;
            etrans271.InsSubNum            = insSub.InsSubNum;
            etrans271.EtransMessageTextNum = etransMessageText.EtransMessageTextNum;
            Etranss.Insert(etrans271);
            etrans.AckEtransNum = etrans271.EtransNum;
            if (etrans271.Etype == EtransType.Acknowledge_997)
            {
                X997   x997     = new X997(x12response);
                string error997 = x997.GetHumanReadable();
                etrans.Note = "Error: " + error997;            //"Malformed document sent.  997 error returned.";
                Etranss.Update(etrans);
                MessageBox.Show(etrans.Note);
                //CodeBase.MsgBoxCopyPaste msgbox=new CodeBase.MsgBoxCopyPaste(etrans.Note);
                //msgbox.ShowDialog();
                //don't show the 270 interface.
                return;
            }
            else
            {
                string processingerror = x271.GetProcessingError();
                if (processingerror != "")
                {
                    etrans.Note = processingerror;
                    Etranss.Update(etrans);
                    MessageBox.Show(etrans.Note);
                    //CodeBase.MsgBoxCopyPaste msgbox=new CodeBase.MsgBoxCopyPaste(etrans.Note);
                    //msgbox.ShowDialog();
                    //don't show the 270 interface.
                    return;
                }
                else
                {
                    etrans.Note = "Normal 271 response.";                  //change this later to be explanatory of content.
                }
            }
            Etranss.Update(etrans);
            //show the user a list of benefits to pick from for import--------------------------
            FormEtrans270Edit formE = new FormEtrans270Edit(patPlanNum, plan.PlanNum, insSub.InsSubNum);

            formE.EtransCur         = etrans;
            formE.IsInitialResponse = true;
            formE.benList           = benList;
            formE.ShowDialog();
        }
예제 #13
0
        ///<summary>Throws exceptions. The insplan that's passed in need not be properly updated to the database first.</summary>
        ///<returns>The Etrans created from the request. Will be null if the request failed in any way.</returns>
        public static Etrans RequestBenefits(Clearinghouse clearinghouseClin, InsPlan plan, long patNum, Carrier carrier, InsSub insSub, out string error)
        {
            error = "";
            Patient  pat      = Patients.GetPat(patNum);
            Patient  subsc    = Patients.GetPat(insSub.Subscriber);
            Clinic   clinic   = Clinics.GetClinic(pat.ClinicNum);
            Provider billProv = Providers.GetProv(Providers.GetBillingProvNum(pat.PriProv, pat.ClinicNum));
            //validation.  Throw exception if missing info----------------------------------------
            string validationResult = X270.Validate(clearinghouseClin, carrier, billProv, clinic, plan, subsc, insSub, pat);

            if (validationResult != "")
            {
                throw new Exception(Lans.g("FormInsPlan", "Please fix the following errors first:") + "\r\n" + validationResult);
            }
            //create a 270 message---------------------------------------------------------------
            string            x12message        = X270.GenerateMessageText(clearinghouseClin, carrier, billProv, clinic, plan, subsc, insSub, pat);
            EtransMessageText etransMessageText = new EtransMessageText();

            etransMessageText.MessageText = x12message;
            EtransMessageTexts.Insert(etransMessageText);
            //attach it to an etrans-------------------------------------------------------------
            Etrans etrans = new Etrans();

            etrans.PatNum               = patNum;
            etrans.DateTimeTrans        = DateTime.Now;
            etrans.ClearingHouseNum     = clearinghouseClin.HqClearinghouseNum;
            etrans.Etype                = EtransType.BenefitInquiry270;
            etrans.PlanNum              = plan.PlanNum;
            etrans.InsSubNum            = insSub.InsSubNum;
            etrans.EtransMessageTextNum = etransMessageText.EtransMessageTextNum;
            Etranss.Insert(etrans);
            //send the 270----------------------------------------------------------------------
            string x12response = "";
            Etrans etransHtml  = null;

            //a connection error here needs to bubble up
            try {
                if (!String.IsNullOrWhiteSpace(FakeResponseOverride271))
                {
                    x12response = FakeResponseOverride271;
                }
                else if (clearinghouseClin.CommBridge == EclaimsCommBridge.ClaimConnect)
                {
                    x12response = ClaimConnect.Benefits270(clearinghouseClin, x12message);
                }
                else if (clearinghouseClin.CommBridge == EclaimsCommBridge.EDS)
                {
                    x12response = EDS.Benefits270(clearinghouseClin, x12message, out etransHtml);
                }
                else if (clearinghouseClin.CommBridge == EclaimsCommBridge.WebMD)
                {
                    x12response = WebMD.Benefits270(clearinghouseClin, x12message);
                }
            }
            catch (Exception ex) {
                EtransMessageTexts.Delete(etrans.EtransMessageTextNum);
                Etranss.Delete(etrans.EtransNum);
                throw new ApplicationException(Lans.g("FormInsPlan", "Connection Error:") + "\r\n" + ex.GetType().Name + "\r\n" + ex.Message);
            }
            //start to process the 271----------------------------------------------------------
            X271 x271 = null;

            if (X12object.IsX12(x12response))
            {
                X12object x12obj = new X12object(x12response);
                if (x12obj.Is271())
                {
                    x271 = new X271(x12response);
                }
            }
            else              //not a 997, 999, 277 or 271
            {
                EtransMessageTexts.Delete(etrans.EtransMessageTextNum);
                Etranss.Delete(etrans.EtransNum);
                throw new ApplicationException(Lans.g("FormInsPlan", "Error:") + "\r\n" + x12response);
            }

            /*
             * //In realtime mode, X12 limits the request to one patient.
             * //We will always use the subscriber.
             * //So all EB segments are for the subscriber.
             * List<EB271> listEB=new List<EB271>();
             * EB271 eb;
             * if(x271 != null) {
             *      for(int i=0;i<x271.Segments.Count;i++) {
             *              if(x271.Segments[i].SegmentID != "EB") {
             *                      continue;
             *              }
             *              eb=new EB271(x271.Segments[i]);
             *              listEB.Add(eb);
             *      }
             * }*/
            //create an etrans for the 271------------------------------------------------------
            etransMessageText             = new EtransMessageText();
            etransMessageText.MessageText = x12response;
            EtransMessageTexts.Insert(etransMessageText);
            Etrans etrans271 = new Etrans();

            etrans271.PatNum           = patNum;
            etrans271.DateTimeTrans    = DateTime.Now;
            etrans271.ClearingHouseNum = clearinghouseClin.HqClearinghouseNum;
            etrans271.Etype            = EtransType.TextReport;
            if (X12object.IsX12(x12response))             //this shouldn't need to be tested because it was tested above.
            {
                if (x271 == null)
                {
                    X12object Xobj = new X12object(x12response);
                    if (Xobj.Is997())
                    {
                        etrans271.Etype = EtransType.Acknowledge_997;
                    }
                    else if (Xobj.Is999())
                    {
                        etrans271.Etype = EtransType.Acknowledge_999;
                    }
                    else if (X277.Is277(Xobj))
                    {
                        etrans271.Etype = EtransType.StatusNotify_277;
                    }
                    else if (X835.Is835(Xobj))
                    {
                        etrans271.Etype = EtransType.ERA_835;
                    }
                    else if (Xobj.IsAckInterchange())
                    {
                        etrans271.Etype = EtransType.Ack_Interchange;
                    }
                }
                else
                {
                    etrans271.Etype = EtransType.BenefitResponse271;
                }
            }
            etrans271.PlanNum              = plan.PlanNum;
            etrans271.InsSubNum            = insSub.InsSubNum;
            etrans271.EtransMessageTextNum = etransMessageText.EtransMessageTextNum;
            etrans271.MessageText          = etransMessageText.MessageText; //Not a DB column, used to save queries for some calling methods (OpenDentalService).
            if (etransHtml != null)
            {
                etrans271.AckEtransNum = etransHtml.EtransNum;
            }
            Etranss.Insert(etrans271);
            etrans.AckEtransNum = etrans271.EtransNum;
            etrans.AckEtrans    = etrans271;       //Not a DB column, used to save queries for some calling methods (OpenDentalService).
            if (etrans271.Etype == EtransType.Acknowledge_997)
            {
                X997   x997     = new X997(x12response);
                string error997 = x997.GetHumanReadable();
                etrans.Note = "Error: " + error997;            //"Malformed document sent.  997 error returned.";
                Etranss.Update(etrans);
                error = etrans.Note;
                return(null);
            }
            else if (etrans271.Etype == EtransType.Acknowledge_999)
            {
                X999   x999     = new X999(x12response);
                string error999 = x999.GetHumanReadable();
                etrans.Note = "Error: " + error999;            //"Malformed document sent.  999 error returned.";
                Etranss.Update(etrans);
                error = etrans.Note;
                return(null);
            }
            else if (etrans271.Etype == EtransType.StatusNotify_277)
            {
                X277   x277     = new X277(x12response);
                string error277 = x277.GetHumanReadable();
                etrans.Note = "Error: " + error277;            //"Malformed document sent.  277 error returned.";
                Etranss.Update(etrans);
                error = etrans.Note;
                return(null);
            }
            else if (etrans271.Etype == EtransType.ERA_835)
            {
                X835   x835     = new X835(etrans271, x12response, "");
                string error835 = x835.GetHumanReadable();
                etrans.Note = "Error: " + error835;            //"Malformed document sent.  835 error returned.";
                Etranss.Update(etrans);
                error = etrans.Note;
                return(null);
            }
            else if (etrans271.Etype == EtransType.BenefitResponse271)            //271
            {
                string processingerror = x271.GetProcessingError();
                if (processingerror != "")
                {
                    etrans.Note = processingerror;
                    Etranss.Update(etrans);
                    error = etrans.Note;
                    return(null);
                }
                else
                {
                    etrans.Note = "Normal 271 response.";                  //change this later to be explanatory of content.
                }
            }
            else if (etrans271.Etype == EtransType.Ack_Interchange)           //See document "X092 Elig 270-271.pdf" pages 388 and 401.
            {
                X12object  xobj   = new X12object(x12response);
                X12Segment segTa1 = xobj.GetNextSegmentById(0, "TA1");
                if (segTa1.Get(4) == "A")
                {
                    etrans.Note = "The request was accepted, but the response is empty.";
                }
                else
                {
                    if (segTa1.Get(4) == "E")
                    {
                        etrans.Note = "The request was accepted with errors: ";
                    }
                    else if (segTa1.Get(4) == "R")
                    {
                        etrans.Note = "The request was rejected with errors: ";
                    }
                    switch (segTa1.Get(5))
                    {
                    case "000": etrans.Note += "No error"; break;

                    case "001": etrans.Note += "The Interchange Control Number in the Header and Trailer Do Not Match. "
                                               + "The Value From the Header is Used in the Acknowledgment."; break;

                    case "002": etrans.Note += "This Standard as Noted in the Control Standards Identifier is Not Supported."; break;

                    case "003": etrans.Note += "This Version of the Controls is Not Supported"; break;

                    case "004": etrans.Note += "The Segment Terminator is Invalid"; break;

                    case "005": etrans.Note += "Invalid Interchange ID Qualifier for Sender"; break;

                    case "006": etrans.Note += "Invalid Interchange Sender ID"; break;

                    case "007": etrans.Note += "Invalid Interchange ID Qualifier for Receiver"; break;

                    case "008": etrans.Note += "Invalid Interchange Receiver ID"; break;

                    case "009": etrans.Note += "Unknown Interchange Receiver ID"; break;

                    case "010": etrans.Note += "Invalid Authorization Information Qualifier Value"; break;

                    case "011": etrans.Note += "Invalid Authorization Information Value"; break;

                    case "012": etrans.Note += "Invalid Security Information Qualifier Value"; break;

                    case "013": etrans.Note += "Invalid Security Information Value"; break;

                    case "014": etrans.Note += "Invalid Interchange Date Value"; break;

                    case "015": etrans.Note += "Invalid Interchange Time Value"; break;

                    case "016": etrans.Note += "Invalid Interchange Standards Identifier Value"; break;

                    case "017": etrans.Note += "Invalid Interchange Version ID Value"; break;

                    case "018": etrans.Note += "Invalid Interchange Control Number Value"; break;

                    case "019": etrans.Note += "Invalid Acknowledgment Requested Value"; break;

                    case "020": etrans.Note += "Invalid Test Indicator Value"; break;

                    case "021": etrans.Note += "Invalid Number of Included Groups Value"; break;

                    case "022": etrans.Note += "Invalid Control Structure"; break;

                    case "023": etrans.Note += "Improper (Premature) End-of-File (Transmission)"; break;

                    case "024": etrans.Note += "Invalid Interchange Content (e.g., Invalid GS Segment)"; break;

                    case "025": etrans.Note += "Duplicate Interchange Control Number"; break;

                    case "026": etrans.Note += "Invalid Data Element Separator"; break;

                    case "027": etrans.Note += "Invalid Component Element Separator"; break;

                    case "028": etrans.Note += "Invalid Delivery Date in Deferred Delivery Request"; break;

                    case "029": etrans.Note += "Invalid Delivery Time in Deferred Delivery Request"; break;

                    case "030": etrans.Note += "Invalid Delivery Time Code in Deferred Delivery Request"; break;

                    case "031": etrans.Note += "Invalid Grade of Service Code"; break;
                    }
                }
            }
            else
            {
                throw new Exception("Unknown response");
            }
            Etranss.Update(etrans);
            return(etrans);
        }