Esempio n. 1
0
    protected void InsertEmail(bool PT, bool GP)
    {
        if (txtUpdatePatientID.Text.Length == 0)
        {
            SetErrorMessage("No PT Selected");
            return;
        }


        string[] emails  = null;
        string   refName = null;

        Patient patient = PatientDB.GetByID(Convert.ToInt32(txtUpdatePatientID.Text));

        if (PT)
        {
            emails = ContactDB.GetEmailsByEntityID(patient.Person.EntityID);
        }
        else if (GP)
        {
            PatientReferrer[] patRefs = PatientReferrerDB.GetActiveEPCPatientReferrersOf(patient.PatientID);
            if (patRefs.Length > 0)
            {
                refName = patRefs[0].RegisterReferrer.Referrer.Person.FullnameWithoutMiddlename;
                emails  = ContactDB.GetEmailsByEntityID(patRefs[0].RegisterReferrer.Organisation.EntityID);
            }
        }

        if (emails != null && emails.Length > 0)
        {
            txtEmailTo.Text = string.Join(",", emails);
        }
        else
        {
            if (PT)
            {
                SetErrorMessage("No email address set for " + patient.Person.FullnameWithoutMiddlename + "<br />");
            }
            else if (GP && refName == null)
            {
                SetErrorMessage("No referrer set for " + patient.Person.FullnameWithoutMiddlename + "<br />");
            }
            else if (GP)
            {
                SetErrorMessage("No email set for referrer " + refName + "<br />");
            }

            txtEmailTo.Text = string.Empty;
        }
    }
    protected Tuple <string, string, string, string> GetReferrersEmail()
    {
        if (!IsValidFormID())
        {
            return(null);
        }

        Booking booking = BookingDB.GetByEntityID(GetFormID());

        if (booking == null || booking.Patient == null)
        {
            return(null);
        }

        PatientReferrer[] patientReferrer = PatientReferrerDB.GetActiveEPCPatientReferrersOf(booking.Patient.PatientID);
        if (patientReferrer.Length == 0)
        {
            return(null);
        }

        PatientReferrer  currentPatRegReferrer = patientReferrer[patientReferrer.Length - 1];
        RegisterReferrer curRegReferrer        = currentPatRegReferrer.RegisterReferrer;

        //string refName = curRegReferrer.Referrer.Person.Surname + ", " + curRegReferrer.Referrer.Person.Firstname + " [" + curRegReferrer.Organisation.Name + "]" + " [" + currentPatRegReferrer.PatientReferrerDateAdded.ToString("dd-MM-yyyy") + "]";
        //SetErrorMessage("Name: " + refName);

        string[] emails = ContactDB.GetEmailsByEntityID(currentPatRegReferrer.RegisterReferrer.Organisation.EntityID);
        if (emails.Length == 0)
        {
            return(null);
        }

        string refEmail           = string.Join(",", emails);
        string refName            = (curRegReferrer.Referrer.Person.Title.ID == 0 ? "Dr." : curRegReferrer.Referrer.Person.Title.Descr) + " " + curRegReferrer.Referrer.Person.Surname;
        string bookingOrg         = booking.Organisation.Name;
        string bookingPatientName = booking.Patient.Person.FullnameWithoutMiddlename;

        return(new Tuple <string, string, string, string>(refEmail, refName, bookingOrg, bookingPatientName));
    }
    protected static string SendEmailToPT(bool incSending, DataTable dt, Patient patient, Site site)
    {
        DataRow row = dt.Select("patient_id = " + patient.PatientID)[0];
        string  daysOverdueCommaSep = (string)row["days_overdue_comma_sep"];

        string[] emails = ContactDB.GetEmailsByEntityID(patient.Person.EntityID);
        if (emails.Length == 0)
        {
            return(string.Empty + "[" + daysOverdueCommaSep + "]");
        }


        if (incSending)
        {
            string invoiceIDsCommaSep = (string)row["invoice_ids_comma_sep"];
            int[]  invoiceIDs         = Array.ConvertAll <string, int>(invoiceIDsCommaSep.Split(','), Convert.ToInt32);

            bool   isClinics           = site.SiteType.ID != 2;
            string tmpLettersDirectory = Letter.GetTempLettersDirectory();
            string originalFile        = Letter.GetLettersDirectory() + (isClinics ? @"OverdueInvoiceTemplate.docx" : @"OverdueInvoiceTemplateAC.docx");
            string tmpDir = FileHelper.GetTempDirectoryName(tmpLettersDirectory);
            System.IO.Directory.CreateDirectory(tmpDir);
            string outputFile = tmpDir + "OverdueInvoices.pdf";


            try
            {
                Letter.GenerateOutstandingInvoices(originalFile, outputFile, invoiceIDs, patient.PatientID, -1);

                EmailerNew.SimpleEmail(
                    ((SystemVariables)System.Web.HttpContext.Current.Session["SystemVariables"])["Email_FromEmail"].Value,
                    ((SystemVariables)System.Web.HttpContext.Current.Session["SystemVariables"])["Email_FromName"].Value,
                    IsDebug ? "*****@*****.**" : string.Join(",", emails),
                    "Overdue Invoices",
                    "Pease find your Invoices attached. <br />Please call us if you do not agree with the Invoice amount stated.<br /><br />Thank you.",
                    true,
                    new string[] { outputFile },
                    false,
                    null,
                    "*****@*****.**"
                    );
            }
            finally
            {
                try { if (System.IO.File.Exists(outputFile))
                      {
                          System.IO.File.Delete(outputFile);
                      }
                }
                catch (Exception) { }

                // delete temp dir
                if (tmpDir != null)
                {
                    try { System.IO.Directory.Delete(tmpDir, true); }
                    catch (Exception) { }
                }
            }
        }

        return(string.Join(", ", emails) + "[" + daysOverdueCommaSep + "]");
    }
Esempio n. 4
0
    protected void GrdOrgInvoicesOutstanding_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName == "Email")
        {
            int          organisationID = Convert.ToInt32(e.CommandArgument);
            Organisation org            = OrganisationDB.GetByID(organisationID);
            string[]     emails         = ContactDB.GetEmailsByEntityID(org.EntityID);

            if (emails.Length == 0)
            {
                SetErrorMessage("No email address set for '" + org.Name + "'. Please set one to email invoices to them.");
                return;
            }
            else
            {
                DataTable dt  = Session["orginvoicesoutstanding_data"] as DataTable;
                DataRow   row = dt.Select("organisation_id = " + organisationID)[0];

                string invoiceIDsCommaSep = (string)row["invoice_ids_comma_sep"];
                int[]  invoiceIDs         = Array.ConvertAll <string, int>(invoiceIDsCommaSep.Split(','), Convert.ToInt32);


                string tmpLettersDirectory = Letter.GetTempLettersDirectory();
                string originalFile        = Letter.GetLettersDirectory() + (!UserView.GetInstance().IsAgedCareView ? @"OverdueInvoiceTemplate.docx" : @"OverdueInvoiceTemplateAC.docx");
                string tmpDir = FileHelper.GetTempDirectoryName(tmpLettersDirectory);
                System.IO.Directory.CreateDirectory(tmpDir);
                string outputFile = tmpDir + "OverdueInvoices.pdf";


                try
                {
                    Letter.GenerateOutstandingInvoices(originalFile, outputFile, invoiceIDs, -1, organisationID);

                    EmailerNew.SimpleEmail(
                        ((SystemVariables)System.Web.HttpContext.Current.Session["SystemVariables"])["Email_FromEmail"].Value,
                        ((SystemVariables)System.Web.HttpContext.Current.Session["SystemVariables"])["Email_FromName"].Value,
                        string.Join(",", emails),
                        "Overdue Invoices",
                        "Pease find your Invoices attached. <br/>Please call us if you do not agree with the Invoice amount stated.<br /><br />Thank you.",
                        true,
                        new string[] { outputFile },
                        false,
                        null
                        );

                    SetErrorMessage("Invoices Emailed to " + org.Name + " (" + string.Join(",", emails) + ")");
                }
                catch (CustomMessageException cmEx)
                {
                    SetErrorMessage(cmEx.Message);
                }
                catch (Exception ex)
                {
                    SetErrorMessage("", ex.ToString());
                }
                finally
                {
                    try { if (System.IO.File.Exists(outputFile))
                          {
                              System.IO.File.Delete(outputFile);
                          }
                    }
                    catch (Exception) { }

                    // delete temp dir
                    if (tmpDir != null)
                    {
                        try { System.IO.Directory.Delete(tmpDir, true); }
                        catch (Exception) { }
                    }
                }
            }
        }

        if (e.CommandName == "Print")
        {
            int organisationID = Convert.ToInt32(e.CommandArgument);

            DataTable dt  = Session["orginvoicesoutstanding_data"] as DataTable;
            DataRow   row = dt.Select("organisation_id = " + organisationID)[0];

            SetErrorMessage("Org ID: " + row["organisation_id"] + "<br />Invoices: " + row["invoice_ids_comma_sep"]);

            string invoiceIDsCommaSep = (string)row["invoice_ids_comma_sep"];
            int[]  invoiceIDs         = Array.ConvertAll <string, int>(invoiceIDsCommaSep.Split(','), Convert.ToInt32);

            Letter.GenerateOutstandingInvoicesToPrint(Response, invoiceIDs, -1, organisationID, !UserView.GetInstance().IsAgedCareView);
        }

        if (e.CommandName == "SetAllPaid" || e.CommandName == "SetAllWiped")
        {
            try
            {
                int organisationID = Convert.ToInt32(e.CommandArgument);

                DataTable dt  = Session["orginvoicesoutstanding_data"] as DataTable;
                DataRow   row = dt.Select("organisation_id = " + organisationID)[0];

                string invoiceIDsCommaSep = (string)row["invoice_ids_comma_sep"];
                int[]  invoiceIDs         = Array.ConvertAll <string, int>(invoiceIDsCommaSep.Split(','), Convert.ToInt32);


                foreach (int invoiceID in invoiceIDs)
                {
                    Invoice invoice = InvoiceDB.GetByID(invoiceID);
                    if (invoice == null || invoice.IsPaID)
                    {
                        continue;
                    }

                    if (e.CommandName.Equals("SetAllPaid"))
                    {
                        ReceiptDB.Insert(null, 362, invoice.InvoiceID, invoice.TotalDue, Convert.ToDecimal(0.00), false, false, DateTime.MinValue, Convert.ToInt32(Session["StaffID"]));
                        InvoiceDB.UpdateIsPaid(null, invoice.InvoiceID, true);
                    }
                    else if (e.CommandName.Equals("SetAllWiped"))
                    {
                        CreditNoteDB.Insert(invoice.InvoiceID, invoice.TotalDue, string.Empty, Convert.ToInt32(Session["StaffID"]));
                        InvoiceDB.UpdateIsPaid(null, invoice.InvoiceID, true);
                    }
                }

                SetErrorMessage("Invoices Set As " + (e.CommandName.Equals("SetAllPaid") ? "Paid" : "Wiped") + " : " + row["invoice_ids_comma_sep"]);

                GrdOrgInvoicesOutstanding_FillGrid();
            }
            catch (CustomMessageException cmEx)
            {
                SetErrorMessage(cmEx.Message);
            }
            catch (Exception ex)
            {
                SetErrorMessage("", ex.ToString());
            }
        }
    }
    protected void Retrieve(string username)
    {
        try
        {
            Session.Remove("DB");
            if (Convert.ToBoolean(System.Configuration.ConfigurationManager.AppSettings["UseConfigDB"]))
            {
                Session["DB"] = System.Configuration.ConfigurationManager.AppSettings["Database"];
            }
            else // Get DB from Mediclinic_Main
            {
                UserDatabaseMapper user = UserDatabaseMapperDB.GetByLogin(username);
                if (user == null)
                {
                    this.FailureText.Text = "Login Failed.";
                    return;
                }

                Session["DB"] = user.DBName;
            }

            Session["SystemVariables"] = SystemVariableDB.GetAll();


            if (username.Length > 0)
            {
                Staff   staff   = StaffDB.GetByLogin(username);
                Patient patient = PatientDB.GetByLogin(username);

                if (staff != null && !staff.IsFired)
                {
                    string[] emails = ContactDB.GetEmailsByEntityID(staff.Person.EntityID);

                    if (emails.Length == 0)
                    {
                        throw new CustomMessageException("No email is set for user: "******",", emails));

                    this.FailureText.Text = "An email has been sent with login details for '" + username + "' to the email address(es) associated with that user";
                }
                else if (patient != null && !patient.IsDeleted)
                {
                    string[] emails = ContactDB.GetEmailsByEntityID(patient.Person.EntityID);

                    if (emails.Length == 0)
                    {
                        throw new CustomMessageException("No email is set for user: "******",", emails));

                    this.FailureText.Text = "An email has been sent with login details for '" + username + "' to the email address(es) associated with that user";
                }
                else
                {
                    throw new CustomMessageException("Username does not exist");
                }
            }
            else
            {
                throw new CustomMessageException("Please enter a username");
            }
        }
        catch (CustomMessageException cmEx)
        {
            this.FailureText.Text = cmEx.Message;
        }
        finally
        {
            Session.Remove("DB");
            Session.Remove("SystemVariables");
        }
    }
Esempio n. 6
0
    protected int AddEmailIfNotExists(Patient patient, int siteID, string email)
    {
        // add email if different from existing

        int email_id = -1;

        string[] emails = ContactDB.GetEmailsByEntityID(patient.Person.EntityID);

        bool emailAlreadyExists = false;

        foreach (string e in emails)
        {
            if (e == email)
            {
                emailAlreadyExists = true;
            }
        }

        if (!emailAlreadyExists)
        {
            if (Utilities.GetAddressType().ToString() == "Contact")
            {
                if (email.Length > 0)
                {
                    email_id = ContactDB.Insert(patient.Person.EntityID,
                                                27,
                                                "",
                                                email,
                                                string.Empty,
                                                -1,
                                                -1,
                                                -1,
                                                Convert.ToInt32(siteID),
                                                true,
                                                true);
                }
            }
            else if (Utilities.GetAddressType().ToString() == "ContactAus")
            {
                if (email.Length > 0)
                {
                    email_id = ContactAusDB.Insert(patient.Person.EntityID,
                                                   27,
                                                   "",
                                                   email,
                                                   string.Empty,
                                                   string.Empty,
                                                   -1,
                                                   -1,
                                                   -1,
                                                   Convert.ToInt32(siteID),
                                                   true,
                                                   true);
                }
            }
            else
            {
                throw new Exception("Unknown AddressType in config: " + Utilities.GetAddressType().ToString().ToString());
            }
        }

        return(email_id);
    }
Esempio n. 7
0
    protected void btnEmailToFac_Click(object sender, EventArgs e)
    {
        Booking booking = BookingDB.GetByID(GetFormBooking());

        string[] emails = ContactDB.GetEmailsByEntityID(booking.Organisation.EntityID);

        if (emails.Length == 0)
        {
            SetErrorMessage("No email address set for '" + booking.Organisation.Name + "'. Please set one to email treatment list to them.");
            return;
        }
        else
        {
            string tmpLettersDirectory = FileHelper.GetTempDirectoryName(Letter.GetTempLettersDirectory());
            Directory.CreateDirectory(tmpLettersDirectory);

            string originalFile  = Letter.GetLettersDirectory() + @"ACTreatmentList.docx";
            string tmpOutputFile = tmpLettersDirectory + "TreatmentList.pdf";

            if (!File.Exists(originalFile))
            {
                SetErrorMessage("Template File 'ACTreatmentList.docx' does not exist.");
                return;
            }

            MergeFile(true, originalFile, tmpOutputFile);

            try
            {
                EmailerNew.SimpleEmail(
                    ((SystemVariables)System.Web.HttpContext.Current.Session["SystemVariables"])["Email_FromEmail"].Value,
                    ((SystemVariables)System.Web.HttpContext.Current.Session["SystemVariables"])["Email_FromName"].Value,
                    (Utilities.IsDev() ? "*****@*****.**" : string.Join(",", emails)),
                    "Treatement List",
                    "Pease find the <u>Residents Treated List</u> for " + booking.DateStart.ToString("d MMM, yyyy") + " at " + booking.Organisation.Name + "<br /><br />Regards,<br />" + ((SystemVariables)System.Web.HttpContext.Current.Session["SystemVariables"])["Email_FromName"].Value,
                    true,
                    new string[] { tmpOutputFile },
                    false,
                    null
                    );

                SetErrorMessage("Emailed to &nbsp;&nbsp;" + booking.Organisation.Name + " (" + string.Join(", ", emails) + ")");
            }
            catch (CustomMessageException cmEx)
            {
                SetErrorMessage(cmEx.Message);
            }
            catch (Exception ex)
            {
                SetErrorMessage("", ex.ToString());
            }
            finally
            {
                try { if (System.IO.File.Exists(tmpOutputFile))
                      {
                          System.IO.File.Delete(tmpOutputFile);
                      }
                }
                catch (Exception) { }

                // delete temp dir
                if (tmpLettersDirectory != null)
                {
                    try { System.IO.Directory.Delete(tmpLettersDirectory, true); }
                    catch (Exception) { }
                }
            }
        }
    }
    protected Letter.FileContents[] ProcessReferrersLetters(bool viewListOnly, ArrayList bookingsForCurrentReferrer, bool autoSendFaxesAsEmailsIfNoEmailExistsToGPs, ref string debugOutput, int bulkLetterSendingQueueBatchID)
    {
        if (bookingsForCurrentReferrer.Count == 0)
        {
            return(new Letter.FileContents[0]);
        }


        // to return - only files to print, as emailing will have been completed
        ArrayList filesToPrint = new ArrayList();


        // single db lookup per referrer to get email
        Tuple <Booking, PatientReferrer, bool, bool, HealthCard> firstTuple = (Tuple <Booking, PatientReferrer, bool, bool, HealthCard>)bookingsForCurrentReferrer[0];
        PatientReferrer firstPR = firstTuple.Item2;


        int s = firstPR.RegisterReferrer.RegisterReferrerID;



        string[] refEmails = ContactDB.GetEmailsByEntityID(firstPR.RegisterReferrer.Organisation.EntityID);
        string[] refFaxes  = ContactDB.GetFaxesByEntityID(firstPR.RegisterReferrer.Organisation.EntityID);

        bool   firstRefHasEmail = refEmails.Length > 0;
        string refEmail         = refEmails.Length > 0 ? string.Join(",", refEmails) : null;

        bool   firstRefHasFax = refFaxes.Length > 0;
        string refFax         = refFaxes.Length > 0 ? refFaxes[0] : null;


        int  siteID  = Convert.ToInt32(Session["SiteID"]);
        Site site    = SiteDB.GetByID(siteID);
        int  staffID = Convert.ToInt32(Session["StaffID"]);

        Site[] sites = SiteDB.GetAll();
        for (int i = 0; i < bookingsForCurrentReferrer.Count; i++)
        {
            Tuple <Booking, PatientReferrer, bool, bool, HealthCard> curTuple = (Tuple <Booking, PatientReferrer, bool, bool, HealthCard>)bookingsForCurrentReferrer[i];
            Booking         curBooking     = curTuple.Item1;
            PatientReferrer curPR          = curTuple.Item2;
            bool            curRefHasEmail = curTuple.Item3;
            bool            curRefHasFax   = curTuple.Item4;
            HealthCard      curHC          = curTuple.Item5;


            bool needToGenerateLetters = curBooking.NeedToGenerateFirstLetter || curBooking.NeedToGenerateLastLetter ||
                                         (curPR.RegisterReferrer.ReportEveryVisitToReferrer && curBooking.NoteCount > 0);
            if (needToGenerateLetters)
            {
                SendMethod sendMethod = (curRefHasEmail && this.SelectedSendMethod == SendMethod.Email ? SendMethod.Email : SendMethod.Print);

                if (!viewListOnly)
                {
                    bool sendViaEmail = autoSendFaxesAsEmailsIfNoEmailExistsToGPs ? (curRefHasEmail || curRefHasFax) : curRefHasEmail;
                    if (sendViaEmail && this.SelectedSendMethod == SendMethod.Email)
                    {
                        string toEmail = autoSendFaxesAsEmailsIfNoEmailExistsToGPs ?
                                         (curRefHasEmail ? refEmail : Regex.Replace(refFax, "[^0-9]", "") + "@fax.houseofit.com.au")
                            :
                                         refEmail;

                        if (UseBulkLetterSender)
                        {
                            BulkLetterSendingQueueAdditionalLetter[] filesList = GetFilesInfo(curBooking, Letter.FileFormat.PDF, curBooking.Patient, curHC, curBooking.Offering.Field.ID, curPR.RegisterReferrer.Referrer, false, curBooking.NeedToGenerateFirstLetter, curBooking.NeedToGenerateLastLetter, curPR.RegisterReferrer.ReportEveryVisitToReferrer, siteID, staffID, sendMethod == SendMethod.Email ? 2 : 1);

                            if (filesList != null && filesList.Length > 0)
                            {
                                string from_email = ((SystemVariables)System.Web.HttpContext.Current.Session["SystemVariables"])["Email_FromEmail"].Value;
                                string subject    = "Referral/Treatment Note Letters From Mediclinic" + (curPR.Patient == null ? string.Empty : " For " + curPR.Patient.Person.FullnameWithoutMiddlename);
                                string text       = "Dr. " + curPR.RegisterReferrer.Referrer.Person.FullnameWithoutMiddlename + "<br /><br />Please find attached referral/treatment note letters for your referrered patient" + (curPR.Patient == null ? string.Empty : " <b>" + curPR.Patient.Person.FullnameWithoutMiddlename + "</b>") + "<br /><br />Best regards,<br />" + site.Name;

                                int bulk_letter_sending_queue_id = BulkLetterSendingQueueDB.Insert
                                                                   (
                                    bulkLetterSendingQueueBatchID,
                                    2,                                          // bulk_letter_sending_queue_method_id (2 = email)
                                    staffID,                                    // added_by
                                    curPR.Patient.PatientID,                    // patient_id
                                    curPR.RegisterReferrer.Referrer.ReferrerID, // referrer_id
                                    curBooking.BookingID,                       // booking_id
                                    "",                                         // phone_number
                                    toEmail,                                    // email_to_address
                                    "",                                         // email_to_name
                                    from_email,                                 // email_from_address
                                    site.Name,                                  // email_from_name
                                    text,                                       // text
                                    subject,                                    // email_subject
                                    "",                                         // email_attachment_location
                                    false,                                      // email_attachment_delete_after_sending
                                    false,                                      // email_attachment_folder_delete_after_sending

                                    filesList[0].EmailLetterLetterID,
                                    filesList[0].EmailLetterKeepHistoryInDb,
                                    filesList[0].EmailLetterKeepHistoryInFile,
                                    filesList[0].EmailLetterLetterPrintHistorySendMethodID,
                                    filesList[0].EmailLetterHistoryDir,
                                    filesList[0].EmailLetterHistoryFilename,
                                    filesList[0].EmailLetterSiteID,
                                    filesList[0].EmailLetterOrganisationID,
                                    filesList[0].EmailLetterBookingID,
                                    filesList[0].EmailLetterPatientID,
                                    filesList[0].EmailLetterRegisterReferrerIdToUseInsteadOfPatientsRegRef,
                                    filesList[0].EmailLetterStaffID,
                                    filesList[0].EmailLetterHealthCardActionID,
                                    filesList[0].EmailLetterSourceTemplatePath,
                                    filesList[0].EmailLetterOutputDocPath,
                                    false, // filesList[0].EmailLetterIsDoubleSidedPrinting,
                                    filesList[0].EmailLetterExtraPages,
                                    filesList[0].EmailLetterItemSeperator,

                                    "",    // sql_to_run_on_completion
                                    ""     // sql_to_run_on_failure
                                                                   );

                                for (int f = 1; f < filesList.Length; f++)
                                {
                                    BulkLetterSendingQueueAdditionalLetterDB.Insert(
                                        bulk_letter_sending_queue_id,
                                        filesList[f].EmailLetterLetterID,
                                        filesList[f].EmailLetterKeepHistoryInDb,
                                        filesList[f].EmailLetterKeepHistoryInFile,
                                        filesList[f].EmailLetterLetterPrintHistorySendMethodID,
                                        filesList[f].EmailLetterHistoryDir,
                                        filesList[f].EmailLetterHistoryFilename,
                                        filesList[f].EmailLetterSiteID,
                                        filesList[f].EmailLetterOrganisationID,
                                        filesList[f].EmailLetterBookingID,
                                        filesList[f].EmailLetterPatientID,
                                        filesList[f].EmailLetterRegisterReferrerIdToUseInsteadOfPatientsRegRef,
                                        filesList[f].EmailLetterStaffID,
                                        filesList[f].EmailLetterHealthCardActionID,
                                        filesList[f].EmailLetterSourceTemplatePath,
                                        filesList[f].EmailLetterOutputDocPath,
                                        false, // filesList[f].EmailLetterIsDoubleSidedPrinting,
                                        filesList[f].EmailLetterExtraPages,
                                        filesList[f].EmailLetterItemSeperator);
                                }
                            }
                        }
                        else
                        {
                            Letter.FileContents[] fileContentsList = curBooking.GetSystemLettersList(Letter.FileFormat.PDF, curBooking.Patient, curHC, curBooking.Offering.Field.ID, curPR.RegisterReferrer.Referrer, false, curBooking.NeedToGenerateFirstLetter, curBooking.NeedToGenerateLastLetter, curPR.RegisterReferrer.ReportEveryVisitToReferrer, false, Convert.ToInt32(Session["SiteID"]), Convert.ToInt32(Session["StaffID"]), sendMethod == SendMethod.Email ? 2 : 1);
                            if (fileContentsList != null && fileContentsList.Length > 0)
                            {
                                //Logger.LogQuery("ReferrerEPCLetters_Reprint -- Email Send Item Starting!");
                                Site bkSite = SiteDB.GetSiteByType(curBooking.Organisation.IsAgedCare ? SiteDB.SiteType.AgedCare : SiteDB.SiteType.Clinic, sites);
                                Letter.EmailSystemLetter(bkSite.Name, toEmail, fileContentsList);
                                //Logger.LogQuery("ReferrerEPCLetters_Reprint -- Email Send Item Done!");
                            }
                        }
                    }
                    else
                    {
                        Letter.FileContents[] fileContentsList = curBooking.GetSystemLettersList(Letter.FileFormat.Word, curBooking.Patient, curHC, curBooking.Offering.Field.ID, curPR.RegisterReferrer.Referrer, false, curBooking.NeedToGenerateFirstLetter, curBooking.NeedToGenerateLastLetter, curPR.RegisterReferrer.ReportEveryVisitToReferrer, false, Convert.ToInt32(Session["SiteID"]), Convert.ToInt32(Session["StaffID"]), sendMethod == SendMethod.Email ? 2 : 1);
                        if (fileContentsList != null && fileContentsList.Length > 0)
                        {
                            filesToPrint.AddRange(fileContentsList);
                        }
                    }

                    BookingDB.UpdateSetGeneratedSystemLetters(curBooking.BookingID, curBooking.NeedToGenerateFirstLetter, curBooking.NeedToGenerateLastLetter, true);
                }

                ArrayList toGenerateList = new ArrayList();
                if (curBooking.NeedToGenerateFirstLetter)
                {
                    toGenerateList.Add("First");
                }
                if (curBooking.NeedToGenerateLastLetter)
                {
                    toGenerateList.Add("Last");
                }
                if (curPR.RegisterReferrer.ReportEveryVisitToReferrer && curBooking.NoteCount > 0)
                {
                    toGenerateList.Add("Notes");
                }
                string toGenerate = string.Join(",", (string[])toGenerateList.ToArray(typeof(string)));

                debugOutput += @"<tr>
                                    <td>" + sendMethod + @"</td>
                                    <td style=""white-space:nowrap;"">" + curBooking.BookingID + " &nbsp;&nbsp;&nbsp;[" + curBooking.DateStart.ToString("dd-MM-yyyy") + "&nbsp;&nbsp;&nbsp;" + curBooking.DateStart.ToString("HH:mm") + "-" + curBooking.DateEnd.ToString("HH:mm") + "]" + @"</td>
                                    <td>" + toGenerate + @"</td>
                                    <td>" + curPR.RegisterReferrer.Referrer.Person.FullnameWithoutMiddlename + @"</td>
                                    <td style=""white-space:nowrap;"">" + (curRefHasEmail ? refEmail : "") + @"</td>
                                    <td style=""white-space:nowrap;"">" + (curRefHasFax ? refFax : "") + @"</td>
                                    <td>" + curPR.Patient.Person.FullnameWithoutMiddlename + @"</td>
                                </tr>";
            }
        }

        return((Letter.FileContents[])filesToPrint.ToArray(typeof(Letter.FileContents)));
    }