Example #1
0
    protected static void MergeDocument(string sourceTemplatePath, string outputDocPath,
                    Booking booking, Patient patient, Contact patientAddress, ContactAus patientAddressAus, Contact patientPhone, ContactAus patientPhoneAus, HealthCard medicareCard, HealthCard dvaCard, Site site,
                    Organisation org, Contact orgAddress, ContactAus orgAddressAus, Contact orgPhone, ContactAus orgPhoneAus, Contact orgFax, ContactAus orgFaxAus, Contact orgWeb, ContactAus orgWebAus, Contact orgEmail, ContactAus orgEmailAus,
                    Staff staff, RegisterReferrer regReferrer, Contact referrerAddress, ContactAus referrerAddressAus, Contact referrerPhone, ContactAus referrerPhoneAus, Contact referrerFax, ContactAus referrerFaxAus, HealthCardAction healthCardAction,

                    DateTime pt_last_bk_date, DateTime epc_expire_date, int      epc_count_remaining, 

                    bool isDoubleSidedPrinting, string[] extraPages,
                    bool keepHistoryInDB, bool keepHistoryInFile, int letterPrintHistorySendMethodID, string historyDir, string historyFileName, int letterID)
    {
        HealthCard activeHcCard = (medicareCard != null && medicareCard.IsActive) ? medicareCard : ((dvaCard != null && dvaCard.IsActive) ? dvaCard : null);

        DataSet sourceDataSet = new DataSet();
        sourceDataSet.Tables.Add("MergeIt");

        sourceDataSet.Tables[0].Columns.Add("curr_date");

        sourceDataSet.Tables[0].Columns.Add("pt_name");
        sourceDataSet.Tables[0].Columns.Add("pt_title");
        sourceDataSet.Tables[0].Columns.Add("pt_firstname");
        sourceDataSet.Tables[0].Columns.Add("pt_middlename");
        sourceDataSet.Tables[0].Columns.Add("pt_surname");
        sourceDataSet.Tables[0].Columns.Add("pt_gender");
        sourceDataSet.Tables[0].Columns.Add("pt_dob");
        sourceDataSet.Tables[0].Columns.Add("pt_dob_day_month_only");

        sourceDataSet.Tables[0].Columns.Add("pt_conditions");

        sourceDataSet.Tables[0].Columns.Add("pt_addr");
        sourceDataSet.Tables[0].Columns.Add("pt_addr_tabbedx1");
        //sourceDataSet.Tables[0].Columns.Add("pt_addr_line1");
        //sourceDataSet.Tables[0].Columns.Add("pt_addr_line2");
        //sourceDataSet.Tables[0].Columns.Add("pt_addr_street");
        //sourceDataSet.Tables[0].Columns.Add("pt_addr_suburb");
        //sourceDataSet.Tables[0].Columns.Add("pt_addr_postcode");
        //sourceDataSet.Tables[0].Columns.Add("pt_addr_country");
        sourceDataSet.Tables[0].Columns.Add("pt_phone");

        sourceDataSet.Tables[0].Columns.Add("pt_last_bk_date");

        sourceDataSet.Tables[0].Columns.Add("pt_hc_card_nbr");
        sourceDataSet.Tables[0].Columns.Add("pt_hc_card_name");
        sourceDataSet.Tables[0].Columns.Add("pt_hc_card_refsigneddate");
        sourceDataSet.Tables[0].Columns.Add("pt_epc_expire_date");
        sourceDataSet.Tables[0].Columns.Add("pt_epc_count_remaining");

        sourceDataSet.Tables[0].Columns.Add("pt_mc_card_nbr");
        sourceDataSet.Tables[0].Columns.Add("pt_mc_card_name");
        sourceDataSet.Tables[0].Columns.Add("pt_mc_card_refsigneddate");

        sourceDataSet.Tables[0].Columns.Add("pt_dvacard_nbr");
        sourceDataSet.Tables[0].Columns.Add("pt_dvacard_name");
        sourceDataSet.Tables[0].Columns.Add("pt_dvacard_refsigneddate");

        sourceDataSet.Tables[0].Columns.Add("org_name");
        sourceDataSet.Tables[0].Columns.Add("org_abn");
        sourceDataSet.Tables[0].Columns.Add("org_acn");
        sourceDataSet.Tables[0].Columns.Add("org_bpay_account");

        sourceDataSet.Tables[0].Columns.Add("org_addr");
        sourceDataSet.Tables[0].Columns.Add("org_addr_tabbedx1");
        //sourceDataSet.Tables[0].Columns.Add("org_addr_line1");
        //sourceDataSet.Tables[0].Columns.Add("org_addr_line2");
        //sourceDataSet.Tables[0].Columns.Add("org_addr_street");
        //sourceDataSet.Tables[0].Columns.Add("org_addr_suburb");
        //sourceDataSet.Tables[0].Columns.Add("org_addr_postcode");
        //sourceDataSet.Tables[0].Columns.Add("org_addr_country");
        sourceDataSet.Tables[0].Columns.Add("org_phone");
        sourceDataSet.Tables[0].Columns.Add("org_office_fax");
        sourceDataSet.Tables[0].Columns.Add("org_web");
        sourceDataSet.Tables[0].Columns.Add("org_email");

        sourceDataSet.Tables[0].Columns.Add("ref_name");
        sourceDataSet.Tables[0].Columns.Add("ref_title");
        sourceDataSet.Tables[0].Columns.Add("ref_firstname");
        sourceDataSet.Tables[0].Columns.Add("ref_middlename");
        sourceDataSet.Tables[0].Columns.Add("ref_surname");
        //sourceDataSet.Tables[0].Columns.Add("ref_gender");
        //sourceDataSet.Tables[0].Columns.Add("ref_dob");

        sourceDataSet.Tables[0].Columns.Add("ref_addr");
        sourceDataSet.Tables[0].Columns.Add("ref_addr_tabbedx1");
        //sourceDataSet.Tables[0].Columns.Add("ref_addr_line1");
        //sourceDataSet.Tables[0].Columns.Add("ref_addr_line2");
        //sourceDataSet.Tables[0].Columns.Add("ref_addr_street");
        //sourceDataSet.Tables[0].Columns.Add("ref_addr_suburb");
        //sourceDataSet.Tables[0].Columns.Add("ref_addr_postcode");
        //sourceDataSet.Tables[0].Columns.Add("ref_addr_country");
        sourceDataSet.Tables[0].Columns.Add("ref_phone");
        sourceDataSet.Tables[0].Columns.Add("ref_fax");

        sourceDataSet.Tables[0].Columns.Add("bk_date");
        sourceDataSet.Tables[0].Columns.Add("bk_time");
        sourceDataSet.Tables[0].Columns.Add("bk_length");

        sourceDataSet.Tables[0].Columns.Add("bk_prov_name");
        sourceDataSet.Tables[0].Columns.Add("bk_prov_title");
        sourceDataSet.Tables[0].Columns.Add("bk_prov_firstname");
        sourceDataSet.Tables[0].Columns.Add("bk_prov_middlename");
        sourceDataSet.Tables[0].Columns.Add("bk_prov_surname");
        sourceDataSet.Tables[0].Columns.Add("bk_prov_number");
        //sourceDataSet.Tables[0].Columns.Add("bk_prov_gender");
        //sourceDataSet.Tables[0].Columns.Add("bk_prov_dob");

        sourceDataSet.Tables[0].Columns.Add("bk_treatment_notes");

        sourceDataSet.Tables[0].Columns.Add("bk_offering_name");
        sourceDataSet.Tables[0].Columns.Add("bk_offering_short_name");
        sourceDataSet.Tables[0].Columns.Add("bk_offering_descr");

        string bookingNotes = string.Empty;
        if (booking != null)
        {
            if (booking.Patient != null)
            {
                foreach (Note note in booking.GetTreatmentNotes())
                    bookingNotes += "Treatment Note:" + Environment.NewLine + Environment.NewLine + note.Text + Environment.NewLine + Environment.NewLine;
            }
            else if (patient != null) // group bookings - but need patientID
            {
                BookingPatient bp = BookingPatientDB.GetByBookingAndPatientID(booking.BookingID, patient.PatientID);
                if (bp != null)
                    foreach (Note note in NoteDB.GetByEntityID(bp.EntityID, "252"))
                        bookingNotes += "Treatment Note:" + Environment.NewLine + Environment.NewLine + note.Text + Environment.NewLine + Environment.NewLine;
            }

        }

        /*  -- for testing
            string s1 = patient == null ? "No patient found" : patient.Person.FullnameWithTitleWithoutMiddlename;
            string s2 = patient == null ? "No patient found" : (patient.Person.Title.ID == 0 ? "" : patient.Person.Title.Descr);
            string s3 = patient == null ? "" : patient.Person.Firstname;
            string s4 = patient == null ? "" : patient.Person.Middlename;
            string s5 = patient == null ? "" : patient.Person.Surname;
            string s6 = patient == null ? "" : patient.Person.Gender;
            string s7 = patient == null ? "" : patient.Person.Dob == DateTime.MinValue ? "" : patient.Person.Dob.ToString("d MMMM, yyyy");

            string s8 = patientAddress == null ? "No address found" : patientAddress.AddrLine1;
            string s9 = patientAddress == null ? "" : patientAddress.AddrLine2;
            string s10 = patientAddress == null || patientAddress.AddressChannel == null ? "" : (patientAddress.AddressChannel.AddressChannelID == 1 ? "" : patientAddress.AddressChannel.DisplayName);
            string s11 = patientAddress == null ? "" : patientAddress.Suburb.Name;
            string s12 = patientAddress == null ? "" : patientAddress.Suburb.Postcode;
            string s13 = patientAddress == null || patientAddress.Country == null ? "" : patientAddress.Country.Descr;

            string s14 = activeHcCard == null ? "No hc card found" : activeHcCard.CardNbr + " - " + activeHcCard.CardFamilyMemberNbr;
            string s15 = activeHcCard == null ? "" : activeHcCard.CardName;
            string s16 = activeHcCard == null ? "" : activeHcCard.DateReferralSigned.ToString("d MMMM, yyyy");

            string s17 = medicareCard == null ? "No medicare card found" : medicareCard.CardNbr + " - " + medicareCard.CardFamilyMemberNbr;
            string s18 = medicareCard == null ? "" : medicareCard.CardName;
            string s19 = medicareCard == null ? "" : medicareCard.DateReferralSigned.ToString("d MMMM, yyyy");

            string s20 = dvaCard == null ? "No dva card found" : dvaCard.CardNbr;
            string s21 = dvaCard == null ? "" : dvaCard.CardName;
            string s22 = dvaCard == null ? "" : dvaCard.DateReferralSigned.ToString("d MMMM, yyyy");

            string s23 = org != null ? org.Name        : site.Name;
            string s24 = org != null ? org.Abn         : site.Abn;
            string s25 = org != null ? org.Acn         : site.Acn;
            string s26 = org != null ? org.BpayAccount : site.BankBpay;

            string s27 = orgAddress == null ? "No address found" : orgAddress.AddrLine1;
            string s28 = orgAddress == null ? "" : orgAddress.AddrLine2;
            string s29 = orgAddress == null ? "" : (orgAddress.AddressChannel.AddressChannelID == 1 ? "" : orgAddress.AddressChannel.DisplayName);
            string s30 = orgAddress == null ? "" : orgAddress.Suburb.Name;
            string s31 = orgAddress == null ? "" : orgAddress.Suburb.Postcode;
            string s32 = orgAddress == null || orgAddress.Country == null ? "" : orgAddress.Country.Descr;

            string s33 = regReferrer == null ? "No referrer found" : regReferrer.Referrer.Person.FullnameWithTitleWithoutMiddlename;
            string s34 = regReferrer == null ? "No referrer found" : (regReferrer.Referrer.Person.Title.ID == 0 ? "" : regReferrer.Referrer.Person.Title.Descr);
            string s35 = regReferrer == null ? "" : regReferrer.Referrer.Person.Firstname;
            string s36 = regReferrer == null ? "" : regReferrer.Referrer.Person.Middlename;
            string s37 = regReferrer == null ? "" : regReferrer.Referrer.Person.Surname;
            string s38 = regReferrer == null ? "" : regReferrer.Referrer.Person.Gender;
            string s39 = regReferrer == null ? "" : regReferrer.Referrer.Person.Dob.ToString("d MMMM, yyyy");

            string s40 = referrerAddress == null ? "No address found" : referrerAddress.AddrLine1;
            string s41 = referrerAddress == null ? "" : referrerAddress.AddrLine2;
            string s42 = referrerAddress == null ? "" : (referrerAddress.AddressChannel.AddressChannelID == 1 ? "" : referrerAddress.AddressChannel.DisplayName);
            string s43 = referrerAddress == null ? "" : referrerAddress.Suburb.Name;
            string s44 = referrerAddress == null ? "" : referrerAddress.Suburb.Postcode;
            string s45 = referrerAddress == null || referrerAddress.Country == null ? "" : referrerAddress.Country.Descr;

            string s46 = booking == null ? "" : booking.DateStart.ToString("d MMMM, yyyy");
            string s47 = booking == null ? "" : booking.DateStart.ToString("HH:mm");

            string s48 = booking == null || booking.Provider == null ? "" : booking.Provider.Person.FullnameWithTitleWithoutMiddlename;
            string s49 = booking == null || booking.Provider == null ? "" : (booking.Provider.Person.Title.ID == 0 ? "" : booking.Provider.Person.Title.Descr);
            string s50 = booking == null || booking.Provider == null ? "" : booking.Provider.Person.Firstname;
            string s51 = booking == null || booking.Provider == null ? "" : booking.Provider.Person.Middlename;
            string s52 = booking == null || booking.Provider == null ? "" : booking.Provider.Person.Surname;
            string s53 = booking == null || booking.Provider == null ? "" : booking.Provider.Person.Gender;
            string s54 = booking == null || booking.Provider == null ? "" : booking.Provider.Person.Dob.ToString("d MMMM, yyyy");

            string s55 = booking == null ? "" : bookingNotes;

            string s56 = booking == null || booking.Offering == null ? "" : booking.Offering.Name;
            string s57 = booking == null || booking.Offering == null ? "" : booking.Offering.ShortName;
            string s58 = booking == null || booking.Offering == null ? "" : booking.Offering.Descr;
        */

        string patientAddressText  , patientAddressTabbedText  , patientPhoneText;
        string orgAddressText      , orgAddressTabbedText      , orgPhoneText       , orgFaxText, orgWebText, orgEmailText;
        string referrerAddressText , referrerAddressTabbedText , referrerPhoneText, referrerFaxText;
        if (Utilities.GetAddressType().ToString() == "Contact")
        {
            patientAddressText        = patientAddress == null    ? "No address found"      : patientAddress.GetFormattedAddress("No address found");
            patientAddressTabbedText  = patientAddress == null    ? "No address found"      : patientAddress.GetFormattedAddress("No address found", 1);
            orgAddressText            = orgAddress     == null    ? "No address found"      : orgAddress.GetFormattedAddress("No address found");
            orgAddressTabbedText      = orgAddress     == null    ? "No address found"      : orgAddress.GetFormattedAddress("No address found", 1);
            referrerAddressText       = orgAddress     == null    ? "No address found"      : referrerAddress.GetFormattedAddress("No address found");
            referrerAddressTabbedText = orgAddress     == null    ? "No address found"      : referrerAddress.GetFormattedAddress("No address found", 1);
            patientPhoneText          = patientPhone   == null    ? "No phone number found" : patientPhone.GetFormattedPhoneNumber("No phone number found");
            orgPhoneText              = orgPhone       == null    ? "No phone number found" : orgPhone.GetFormattedPhoneNumber("No phone number found");
            referrerPhoneText         = referrerPhone  == null    ? "No phone number found" : referrerPhone.GetFormattedPhoneNumber("No phone number found");
            referrerFaxText           = referrerFax    == null    ? "No fax number found"   : referrerFax.GetFormattedPhoneNumber("No fax number found");
            orgFaxText                = orgFax         == null    ? "No fax number found"   : orgFax.GetFormattedPhoneNumber("No fax number found");
            orgWebText                = orgWeb         == null    ? "No website found"      : orgWeb.AddrLine1;
            orgEmailText              = orgEmail       == null    ? "No email found"        : orgEmail.AddrLine1;
        }
        else if (Utilities.GetAddressType().ToString() == "ContactAus")
        {
            patientAddressText        = patientAddressAus  == null ? "No address found"      : patientAddressAus.GetFormattedAddress("No address found");
            patientAddressTabbedText  = patientAddressAus  == null ? "No address found"      : patientAddressAus.GetFormattedAddress("No address found", 1);
            orgAddressText            = orgAddressAus      == null ? "No address found"      : orgAddressAus.GetFormattedAddress("No address found");
            orgAddressTabbedText      = orgAddressAus      == null ? "No address found"      : orgAddressAus.GetFormattedAddress("No address found", 1);
            referrerAddressText       = referrerAddressAus == null ? "No address found"      : referrerAddressAus.GetFormattedAddress("No address found");
            referrerAddressTabbedText = referrerAddressAus == null ? "No address found"      : referrerAddressAus.GetFormattedAddress("No address found", 1);
            patientPhoneText          = patientPhoneAus    == null ? "No phone number found" : patientPhoneAus.GetFormattedPhoneNumber("No phone number found");
            orgPhoneText              = orgPhoneAus        == null ? "No phone number found" : orgPhoneAus.GetFormattedPhoneNumber("No phone number found");
            referrerPhoneText         = referrerPhoneAus   == null ? "No phone number found" : referrerPhoneAus.GetFormattedPhoneNumber("No phone number found");
            referrerFaxText           = referrerFaxAus     == null ? "No fax number found"   : referrerFaxAus.GetFormattedPhoneNumber("No fax number found");
            orgFaxText                = orgFaxAus          == null ? "No fax number found"   : orgFaxAus.GetFormattedPhoneNumber("No fax number found");
            orgWebText                = orgWebAus          == null ? "No website found"      : orgWebAus.AddrLine1;
            orgEmailText              = orgEmailAus        == null ? "No email found"        : orgEmailAus.AddrLine1;
        }
        else
            throw new Exception("Unknown AddressType in config: " + Utilities.GetAddressType().ToString().ToString());

        string    ptConditionsText   = string.Empty;
        Hashtable selectedConditions = PatientConditionDB.GetHashtable_ByPatientID(patient.PatientID, false);
        foreach (Condition condition in ConditionDB.GetAll())
            if (selectedConditions[condition.ConditionID] != null)
                ptConditionsText += (ptConditionsText.Length == 0 ? "" : Environment.NewLine) + " • " + ((PatientCondition)selectedConditions[condition.ConditionID]).Condition.Descr;
        if (ptConditionsText == string.Empty)
            ptConditionsText = " • None";

        string bk_prov_number = string.Empty;
        if (booking != null && booking.Provider != null && booking.Organisation != null)
        {
            RegisterStaff regStaff = RegisterStaffDB.GetByStaffIDAndOrganisationID(booking.Provider.StaffID, booking.Organisation.OrganisationID);
            bk_prov_number = (regStaff == null) ? string.Empty : regStaff.ProviderNumber;
        }

        TimeSpan bkTime = booking != null ? booking.DateEnd.Subtract(booking.DateStart) : TimeSpan.Zero;
        string bkTimeLength;
        if (bkTime.Minutes > 0 && bkTime.Hours > 0)
            bkTimeLength = bkTime.Hours + (bkTime.Hours > 1 ? "hrs " : "hr ") + bkTime.Minutes + " minutes";
        else if (bkTime.Hours > 0)
            bkTimeLength = bkTime.Hours + (bkTime.Hours > 1 ? "hours " : "hour ");
        else if (bkTime.Minutes > 0)
            bkTimeLength = bkTime.Minutes + bkTime.Minutes + " minutes";
        else
            bkTimeLength = bkTime.Minutes + " minutes";

        sourceDataSet.Tables[0].Rows.Add(

            DateTime.Now.ToString("d MMMM, yyyy"),

            patient == null ? "No patient found" : patient.Person.FullnameWithTitleWithoutMiddlename,
            patient == null ? "No patient found" : (patient.Person.Title.ID == 0 ? "" : patient.Person.Title.Descr),
            patient == null ? "" : patient.Person.Firstname,
            patient == null ? "" : patient.Person.Middlename,
            patient == null ? "" : patient.Person.Surname,
            patient == null ? "" : patient.Person.Gender,
            patient == null ? "" : patient.Person.Dob == DateTime.MinValue ? (object)DBNull.Value : patient.Person.Dob.ToString("d MMMM, yyyy"),
            patient == null ? "" : patient.Person.Dob == DateTime.MinValue ? (object)DBNull.Value : patient.Person.Dob.ToString("MMMM ") + Utilities.GetDateOrdinal(patient.Person.Dob.Day),

            ptConditionsText,

            patientAddressText,
            patientAddressTabbedText,
            //patientAddress == null                                          ? "No address found" : patientAddress.AddrLine1,
            //patientAddress == null                                          ? "" : patientAddress.AddrLine2,
            //patientAddress == null || patientAddress.AddressChannel == null ? "" : (patientAddress.AddressChannel.AddressChannelID == 1 ? "" : patientAddress.AddressChannel.DisplayName),
            //patientAddress == null || patientAddress.Suburb  == null        ? "" : patientAddress.Suburb.Name,
            //patientAddress == null || patientAddress.Suburb  == null        ? "" : patientAddress.Suburb.Postcode,
            //patientAddress == null || patientAddress.Country == null        ? "" : patientAddress.Country.Descr,
            patientPhoneText,

            pt_last_bk_date == DateTime.MinValue ? "No previous bookings found" : pt_last_bk_date.ToString("d MMMM, yyyy"),

            activeHcCard == null ? "No hc card found" : activeHcCard.CardNbr + " - " + activeHcCard.CardFamilyMemberNbr,
            activeHcCard == null ? "" : activeHcCard.CardName,
            activeHcCard == null ? (object)"" : activeHcCard.DateReferralSigned.ToString("d MMMM, yyyy"),
            epc_expire_date == DateTime.MinValue ? (object)"" : epc_expire_date.ToString("d MMMM, yyyy"),
            epc_expire_date == DateTime.MinValue ? (object)"" : epc_count_remaining,

            medicareCard == null ? "No medicare card found" : medicareCard.CardNbr + " - " + medicareCard.CardFamilyMemberNbr,
            medicareCard == null ? " " : medicareCard.CardName,
            medicareCard == null ? (object)" " : medicareCard.DateReferralSigned.ToString("d MMMM, yyyy"),

            dvaCard == null ? "No dva card found" : dvaCard.CardNbr,
            dvaCard == null ? "" : dvaCard.CardName,
            dvaCard == null ? (object)"" : dvaCard.DateReferralSigned.ToString("d MMMM, yyyy"),

            org != null ? org.Name        : site.Name,
            org != null ? org.Abn         : site.Abn,
            org != null ? org.Acn         : site.Acn,
            org != null ? org.BpayAccount : site.BankBpay,

            orgAddressText,
            orgAddressTabbedText,
            //orgAddress == null ? "No address found" : orgAddress.AddrLine1,
            //orgAddress == null ? "" : orgAddress.AddrLine2,
            //orgAddress == null ? "" : (orgAddress.AddressChannel.AddressChannelID == 1 ? "" : orgAddress.AddressChannel.DisplayName),
            //orgAddress == null ? "" : orgAddress.Suburb.Name,
            //orgAddress == null ? "" : orgAddress.Suburb.Postcode,
            //orgAddress == null || orgAddress.Country == null ? "" : orgAddress.Country.Descr,
            orgPhoneText,
            orgFaxText,
            orgWebText,
            orgEmailText,

            regReferrer == null ? "No referrer found" : regReferrer.Referrer.Person.FullnameWithTitleWithoutMiddlename,
            regReferrer == null ? "No referrer found" : (regReferrer.Referrer.Person.Title.ID == 0 ? "" : regReferrer.Referrer.Person.Title.Descr),
            regReferrer == null ? "" : regReferrer.Referrer.Person.Firstname,
            regReferrer == null ? "" : regReferrer.Referrer.Person.Middlename,
            regReferrer == null ? "" : regReferrer.Referrer.Person.Surname,
            //regReferrer == null ? "" : regReferrer.Referrer.Person.Gender,
            //regReferrer == null ? (object)"" : regReferrer.Referrer.Person.Dob.ToString("d MMMM, yyyy"),

            referrerAddressText,
            referrerAddressTabbedText,
            //referrerAddress == null ? "No address found" : referrerAddress.AddrLine1,
            //referrerAddress == null ? "" : referrerAddress.AddrLine2,
            //referrerAddress == null ? "" : (referrerAddress.AddressChannel.AddressChannelID == 1 ? "" : referrerAddress.AddressChannel.DisplayName),
            //referrerAddress == null ? "" : referrerAddress.Suburb.Name,
            //referrerAddress == null ? "" : referrerAddress.Suburb.Postcode,
            //referrerAddress == null || referrerAddress.Country == null ? "" : referrerAddress.Country.Descr,
            referrerPhoneText,
            referrerFaxText,

            booking == null ? "" : booking.DateStart.ToString("d MMMM, yyyy"),
            booking == null ? "" : booking.DateStart.ToString("HH:mm"),
            booking == null ? "" : bkTimeLength,

            booking == null || booking.Provider == null ? "" : booking.Provider.Person.FullnameWithTitleWithoutMiddlename,
            booking == null || booking.Provider == null ? "" : (booking.Provider.Person.Title.ID == 0 ? "" : booking.Provider.Person.Title.Descr),
            booking == null || booking.Provider == null ? "" : booking.Provider.Person.Firstname,
            booking == null || booking.Provider == null ? "" : booking.Provider.Person.Middlename,
            booking == null || booking.Provider == null ? "" : booking.Provider.Person.Surname,
            bk_prov_number,
            //booking == null || booking.Provider == null ? "" : booking.Provider.Person.Gender,
            //booking == null || booking.Provider == null ? "" : booking.Provider.Person.Dob.ToString("d MMMM, yyyy"),

            booking == null ? "" : bookingNotes,

            booking == null || booking.Offering == null ? "" : booking.Offering.Name,
            booking == null || booking.Offering == null ? "" : booking.Offering.ShortName,
            booking == null || booking.Offering == null ? "" : booking.Offering.Descr

            );

        //now merge
        string errorString = string.Empty;
        //if (!OfficeInterop.MailMerge.MergeDataWithWordTemplate(sourceTemplatePath, outputDocPath, sourceDataSet, isDoubleSidedPrinting, extraPages, out errorString))
        //    throw new CustomMessageException("Error:" + errorString);
        if (!WordMailMerger.Merge(sourceTemplatePath, outputDocPath, sourceDataSet, null, 0, false, isDoubleSidedPrinting, extraPages, true, null, out errorString))
            throw new CustomMessageException("Error:" + errorString);

        if (!historyDir.EndsWith(@"\"))
            historyDir += @"\";

        //
        // create pdf file to be stored because it's much smaller in size
        //
        string tmpLettersDirectory = Letter.GetTempLettersDirectory();
        if (!System.IO.Directory.Exists(tmpLettersDirectory))
            throw new CustomMessageException("Temp letters directory doesn't exist");
        string outputDocPathPDF = FileHelper.GetTempFileName(tmpLettersDirectory + Path.ChangeExtension(historyFileName, ".pdf"));
        string _errorString = string.Empty;
        if (keepHistoryInDB || keepHistoryInFile)
            OfficeInterop.FormatConverter.WordToPDF(outputDocPath, outputDocPathPDF, out _errorString);

        if (keepHistoryInDB)
        {
            byte[] doc_contents = System.IO.File.ReadAllBytes(outputDocPathPDF);
            int letterHistoryID = LetterPrintHistoryDB.Insert(letterID, letterPrintHistorySendMethodID, booking == null ? -1 : booking.BookingID, patient == null ? -1 : patient.PatientID, org != null ? org.OrganisationID : 0, regReferrer == null ? -1 : regReferrer.RegisterReferrerID, staff.StaffID, -1, historyFileName, doc_contents);

            if (keepHistoryInFile)
            {
                string filePath = historyDir + letterHistoryID + System.IO.Path.GetExtension(outputDocPathPDF);
                if (System.IO.File.Exists(filePath))
                    throw new CustomMessageException("File already exists: " + filePath);
                if (!Directory.Exists(historyDir))
                    Directory.CreateDirectory(historyDir);
                System.IO.File.Copy(outputDocPathPDF, filePath);
            }
        }
        else if (keepHistoryInFile)
        {
            int letterHistoryID = LetterPrintHistoryDB.Insert(letterID, letterPrintHistorySendMethodID, booking == null ? -1 : booking.BookingID, patient == null ? -1 : patient.PatientID, org != null ? org.OrganisationID : 0, regReferrer == null ? -1 : regReferrer.RegisterReferrerID, staff == null ? -1 : staff.StaffID, healthCardAction == null ? -1 : healthCardAction.HealthCardActionID, historyFileName, null);

            string filePath = historyDir + letterHistoryID + System.IO.Path.GetExtension(outputDocPathPDF);
            if (System.IO.File.Exists(filePath))
                throw new CustomMessageException("File already exists: " + filePath);
            if (!Directory.Exists(historyDir))
                Directory.CreateDirectory(historyDir);
            System.IO.File.Copy(outputDocPathPDF, filePath);
        }

        if (keepHistoryInDB || keepHistoryInFile)
            File.Delete(outputDocPathPDF);
    }
Example #2
0
    protected string GetContactDetail(DataRow[] rows)
    {
        string output = string.Empty;

        for (int i = 0; i < rows.Length; i++)
        {
            ContactAus contact = ContactAusDB.LoadAll(rows[i]);

            bool isAddress = contact.ContactType.ContactTypeGroup.ID == 1;
            bool isPhone   = contact.ContactType.ContactTypeGroup.ID == 2;
            bool isBedroom = contact.ContactType.ContactTypeGroup.ID == 3;

            bool isEmail   = contact.ContactType.ContactTypeID == 27;
            bool isWebsite = contact.ContactType.ContactTypeID == 28;


            if (isAddress)
            {
                output += @"<tr><td style=""min-width:140px"">" + contact.ContactType.Descr + @"</td><td style=""min-width:10px;""></td><td>" + contact.GetFormattedAddress() + "<br>" + "</td></tr>";
            }
            else if (isPhone)
            {
                output += @"<tr><td style=""min-width:140px"">" + contact.ContactType.Descr + @"</td><td style=""min-width:10px;""></td><td>" + contact.GetFormattedPhoneNumber() + "</td></tr>";
            }
            else if (isEmail)
            {
                output += @"<tr><td style=""min-width:140px"">" + contact.ContactType.Descr + @"</td><td style=""min-width:10px;""></td><td>" + contact.AddrLine1 + "</td></tr>";
            }
        }

        return(output);
    }
Example #3
0
    protected void MergeFile(bool isAgedCare, string originalFile, string outputFile)
    {
        Booking   booking = BookingDB.GetByID(GetFormBooking());
        DataTable dt      = Session["invoicelistac_data"] as DataTable;


        string orgAddressText, orgAddressTabbedText, orgPhoneText, orgFaxText, orgWebText, orgEmailText;

        if (Utilities.GetAddressType().ToString() == "Contact")
        {
            Contact orgAddress = ContactDB.GetFirstByEntityID(1, booking.Organisation != null ? booking.Organisation.EntityID : -1);
            Contact orgPhone   = ContactDB.GetFirstByEntityID(null, booking.Organisation != null ? booking.Organisation.EntityID : -1, "30,33,34");
            Contact orgFax     = ContactDB.GetFirstByEntityID(-1, booking.Organisation != null ? booking.Organisation.EntityID : -1, 29);
            Contact orgWeb     = ContactDB.GetFirstByEntityID(-1, booking.Organisation != null ? booking.Organisation.EntityID : -1, 28);
            Contact orgEmail   = ContactDB.GetFirstByEntityID(-1, booking.Organisation != null ? booking.Organisation.EntityID : -1, 27);

            orgAddressText       = orgAddress == null    ? "No address found"      : orgAddress.GetFormattedAddress("No address found");
            orgAddressTabbedText = orgAddress == null    ? "No address found"      : orgAddress.GetFormattedAddress("No address found", 1);
            orgPhoneText         = orgPhone == null    ? "No phone number found" : orgPhone.GetFormattedPhoneNumber("No phone number found");
            orgFaxText           = orgFax == null    ? "No fax number found"   : orgFax.GetFormattedPhoneNumber("No fax number found");
            orgWebText           = orgWeb == null    ? "No website found"      : orgWeb.AddrLine1;
            orgEmailText         = orgEmail == null    ? "No email found"        : orgEmail.AddrLine1;
        }
        else if (Utilities.GetAddressType().ToString() == "ContactAus")
        {
            ContactAus orgAddressAus = ContactAusDB.GetFirstByEntityID(1, booking.Organisation != null ? booking.Organisation.EntityID : -1);
            ContactAus orgPhoneAus   = ContactAusDB.GetFirstByEntityID(null, booking.Organisation != null ? booking.Organisation.EntityID : -1, "30,33,34");
            ContactAus orgFaxAus     = ContactAusDB.GetFirstByEntityID(-1, booking.Organisation != null ? booking.Organisation.EntityID : -1, 29);
            ContactAus orgWebAus     = ContactAusDB.GetFirstByEntityID(-1, booking.Organisation != null ? booking.Organisation.EntityID : -1, 28);
            ContactAus orgEmailAus   = ContactAusDB.GetFirstByEntityID(-1, booking.Organisation != null ? booking.Organisation.EntityID : -1, 27);

            orgAddressText       = orgAddressAus == null ? "No address found"      : orgAddressAus.GetFormattedAddress("No address found");
            orgAddressTabbedText = orgAddressAus == null ? "No address found"      : orgAddressAus.GetFormattedAddress("No address found", 1);
            orgPhoneText         = orgPhoneAus == null ? "No phone number found" : orgPhoneAus.GetFormattedPhoneNumber("No phone number found");
            orgFaxText           = orgFaxAus == null ? "No fax number found"   : orgFaxAus.GetFormattedPhoneNumber("No fax number found");
            orgWebText           = orgWebAus == null ? "No website found"      : orgWebAus.AddrLine1;
            orgEmailText         = orgEmailAus == null ? "No email found"        : orgEmailAus.AddrLine1;
        }
        else
        {
            throw new Exception("Unknown AddressType in config: " + Utilities.GetAddressType().ToString().ToString());
        }


        string providerNumber = booking.Provider.ProviderNumber;

        if (!isAgedCare)
        {
            RegisterStaff regStaff = RegisterStaffDB.GetByStaffIDAndOrganisationID(booking.Provider.StaffID, booking.Organisation.OrganisationID, true);
            if (regStaff != null)
            {
                providerNumber = regStaff.ProviderNumber;
            }
        }


        System.Data.DataSet sourceDataSet = new System.Data.DataSet();
        sourceDataSet.Tables.Add("MergeIt");


        sourceDataSet.Tables[0].Columns.Add("curr_date");

        sourceDataSet.Tables[0].Columns.Add("bk_prov_fullname");
        sourceDataSet.Tables[0].Columns.Add("bk_prov_number");
        sourceDataSet.Tables[0].Columns.Add("bk_date");

        sourceDataSet.Tables[0].Columns.Add("bk_org_name");
        sourceDataSet.Tables[0].Columns.Add("bk_org_abn");
        sourceDataSet.Tables[0].Columns.Add("bk_org_acn");
        sourceDataSet.Tables[0].Columns.Add("bk_org_bpay_account");
        sourceDataSet.Tables[0].Columns.Add("bk_org_addr");
        sourceDataSet.Tables[0].Columns.Add("bk_org_addr_tabbedx1");
        sourceDataSet.Tables[0].Columns.Add("bk_org_phone");
        sourceDataSet.Tables[0].Columns.Add("bk_org_office_fax");
        sourceDataSet.Tables[0].Columns.Add("bk_org_web");
        sourceDataSet.Tables[0].Columns.Add("bk_org_email");


        sourceDataSet.Tables[0].Rows.Add(
            DateTime.Now.ToString("d MMMM, yyyy"),

            booking.Provider.Person.FullnameWithoutMiddlename,
            providerNumber,
            booking.DateStart.ToString("d MMMM, yyyy"),

            booking.Organisation.Name,
            booking.Organisation.Abn,
            booking.Organisation.Acn,
            booking.Organisation.BpayAccount,
            orgAddressText,
            orgAddressTabbedText,
            orgPhoneText,
            orgFaxText,
            orgWebText,
            orgEmailText
            );



        string[,] tblInfo = new string[dt.Rows.Count, isAgedCare ? 5 : 4];

        for (int i = 0; i < dt.Rows.Count; i++)
        {
            if (isAgedCare)
            {
                /*
                 *  0 = i (row nbr)
                 *  1 = room (addr1 of patient)
                 *  2 = resident
                 *  3 = resident type
                 *  4 = debtor
                 */

                tblInfo[i, 0] = (i + 1).ToString();
                tblInfo[i, 1] = dt.Rows[i]["Room"].ToString();
                tblInfo[i, 2] = dt.Rows[i]["PatientName"].ToString();
                tblInfo[i, 3] = dt.Rows[i]["ItemDescr"].ToString();
                tblInfo[i, 4] = dt.Rows[i]["Debtor"].ToString();
            }
            else
            {
                /*
                 *  0 = i (row nbr)
                 *  1 = patient
                 *  2 = service
                 *  3 = debtor
                 */

                tblInfo[i, 0] = (i + 1).ToString();
                tblInfo[i, 1] = dt.Rows[i]["PatientName"].ToString();
                tblInfo[i, 2] = dt.Rows[i]["ItemDescr"].ToString();
                tblInfo[i, 3] = dt.Rows[i]["Debtor"].ToString();
            }
        }



        // merge

        string errorString = null;

        WordMailMerger.Merge(

            originalFile,
            outputFile,
            sourceDataSet,

            tblInfo,
            1,
            true,

            true,
            null,
            true,
            null,
            out errorString);

        if (errorString != string.Empty)
        {
            throw new Exception(errorString);
        }
    }