protected Letter.FileContents[] ProcessReferrersLetters(bool viewListOnly, ArrayList bookingsForCurrentReferrer, ref string debugOutput) { 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(); // an email belongs to the regRef.Org ... so one referrer can have multiple. // keep in hash to avoid continued lookups. Hashtable refEmailHash = new Hashtable(); ArrayList regRefIDsToUpdateDateTimeOfLastBatchSend = new ArrayList(); Site[] sites = SiteDB.GetAll(); for (int i = 0; i < bookingsForCurrentReferrer.Count; i++) { Tuple <Booking, PatientReferrer, bool, string, HealthCard> curTuple = (Tuple <Booking, PatientReferrer, bool, string, HealthCard>)bookingsForCurrentReferrer[i]; Booking curBooking = curTuple.Item1; PatientReferrer curPR = curTuple.Item2; bool curRefHasEmail = curTuple.Item3; string curRefEmail = 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) { if (curRefHasEmail && this.SelectedSendMethod == SendMethod.Email) { Letter.FileContents[] fileContentsList = curBooking.GetSystemLettersList(Letter.FileFormat.PDF, curBooking.Patient, curHC, curBooking.Offering.Field.ID, curPR.RegisterReferrer.Referrer, true, 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) { if (ReferrerEPCLettersSendingV2.LogDebugEmailInfo) { Logger.LogQuery("C ReferrerEPCLetters_GenerateUnsent -- Email Send Item Starting [" + curRefEmail + "]", false, false, true); } Site site = SiteDB.GetSiteByType(curBooking.Organisation.IsAgedCare ? SiteDB.SiteType.AgedCare : SiteDB.SiteType.Clinic, sites); Letter.EmailSystemLetter(site.Name, curRefEmail, fileContentsList, "Referral/Treatment Note Letters From Mediclinic" + (curPR.Patient == null ? string.Empty : " For " + curPR.Patient.Person.FullnameWithoutMiddlename), "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); if (ReferrerEPCLettersSendingV2.LogDebugEmailInfo) { Logger.LogQuery("C ReferrerEPCLetters_GenerateUnsent -- Email Send Item Done!", false, false, true); } } } else { Letter.FileContents[] fileContentsList = curBooking.GetSystemLettersList(Letter.FileFormat.Word, curBooking.Patient, curHC, curBooking.Offering.Field.ID, curPR.RegisterReferrer.Referrer, true, 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))); string addEditContactListPage; if (Utilities.GetAddressType().ToString() == "Contact") { addEditContactListPage = "AddEditContactList.aspx"; } else if (Utilities.GetAddressType().ToString() == "ContactAus") { addEditContactListPage = "ContactAusListV2.aspx"; } else { throw new Exception("Unknown AddressType in config: " + Utilities.GetAddressType().ToString().ToString()); } string allFeatures = "dialogWidth:525px;dialogHeight:430px;center:yes;resizable:no; scroll:no"; string onclick = "onclick=\"javascript:window.showModalDialog('" + addEditContactListPage + "?entity_type=referrer&id=" + curPR.RegisterReferrer.Organisation.EntityID.ToString() + "', '', '" + allFeatures + "');document.getElementById('" + btnViewList.ClientID + "').click();return false;\""; string hrefUpdateEmail = "<u><a style=\"text-decoration: none\" title=\"Edit\" AlternateText=\"Edit\" " + onclick + " href=\"\">Update Clinic Email</a></u>"; debugOutput += @"<tr> <td>" + sendMethod + @"</td> <td style=""white-space:nowrap;"">" + curBooking.BookingID + " [" + curBooking.DateStart.ToString("dd-MM-yyyy") + " " + 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 ? curRefEmail : "Has No Email") + " (" + hrefUpdateEmail + ")" + @"</td> <td>" + curPR.Patient.Person.FullnameWithoutMiddlename + @"</td> </tr>"; } if (curPR.RegisterReferrer.BatchSendAllPatientsTreatmentNotes) { regRefIDsToUpdateDateTimeOfLastBatchSend.Add(curPR.RegisterReferrer.RegisterReferrerID); } } RegisterReferrerDB.UpdateLastBatchSendAllPatientsTreatmentNotes((int[])regRefIDsToUpdateDateTimeOfLastBatchSend.ToArray(typeof(int)), DateTime.Now); return((Letter.FileContents[])filesToPrint.ToArray(typeof(Letter.FileContents))); }