///<summary>Returns true if the patient should be sent an email. If false, the reason why the patient can't receive an email is ///added to the details dictionary.</summary> internal bool DoSendEmail(long patNum, long fkey, AsapCommFKeyType fkeyType) { PatComm patComm; _dictPatComms.TryGetValue(patNum, out patComm); if (patComm == null) { return(false); } PatientDetail patDetail; _dictPatDetails.TryGetValue(patNum, out patDetail); if (patDetail == null) { patDetail = new PatientDetail { PatNum = patNum }; _dictPatDetails[patNum] = patDetail; } //Local function to evaluate if the patient should be sent an email. Func <bool> funcSendEmail = new Func <bool>(() => { if (_sendMode == SendMode.Text) { return(false); //No need to note the reason. } if (_dictPatAsapComms.ContainsKey(patNum) && _dictPatAsapComms[patNum] .Any(x => x.FKey == fkey && x.FKeyType == fkeyType && x.ResponseStatus == AsapRSVPStatus.DeclinedStopComm)) { string email_type = fkeyType == AsapCommFKeyType.Recall ? "recall" : "appointment"; patDetail.AppendNote(Lans.g(_lanThis, "Not sending email because this patient has requested to not be texted or emailed about this " + email_type + ".")); return(false); } bool isWithin30Minutes = (DtSendEmail < _dtSlotStart && (_dtSlotStart - DtSendEmail).TotalMinutes < TextMinMinutesBefore); bool isAfterSlot = (DtSendEmail > _dtSlotStart); if (isWithin30Minutes) { patDetail.AppendNote(Lans.g(_lanThis, "Not sending email because the email would be sent less than") + " " + TextMinMinutesBefore + " " + Lans.g(_lanThis, "before the time slot.")); return(false); } if (isAfterSlot) { patDetail.AppendNote(Lans.g(_lanThis, "Not sending email because the email would be sent after the time slot.")); return(false); } if (_sendMode == SendMode.Text) { return(false); } if (_sendMode == SendMode.PreferredContact && patComm.PreferContactMethod != ContactMethod.Email) { patDetail.AppendNote(Lans.g(_lanThis, "Not sending email because this patient's preferred contact method is not email.")); return(false); } if (!patComm.IsEmailAnOption) { patDetail.AppendNote(Lans.g(_lanThis, patComm.GetReasonCantEmail())); return(false); } return(true); }); bool doSendEmail = funcSendEmail(); patDetail.IsSendingEmail = doSendEmail; return(doSendEmail); }
///<summary>Returns true if the patient should be sent a text. If false, the reason why the patient can't receive a text is ///added to the details dictionary.</summary> internal bool DoSendText(long patNum, long fkey, AsapCommFKeyType fkeyType) { PatComm patComm; _dictPatComms.TryGetValue(patNum, out patComm); if (patComm == null) { return(false); } PatientDetail patDetail; _dictPatDetails.TryGetValue(patNum, out patDetail); if (patDetail == null) { patDetail = new PatientDetail { PatNum = patNum }; _dictPatDetails[patNum] = patDetail; } //Local function to evaluate if the patient should be sent a text. Func <bool> funcSendText = new Func <bool>(() => { if (_sendMode == SendMode.Email) { return(false); //No need to note the reason. } if (_dictPatAsapComms.ContainsKey(patNum)) { if (_dictPatAsapComms[patNum] .Any(x => x.FKey == fkey && x.FKeyType == fkeyType && x.ResponseStatus == AsapRSVPStatus.DeclinedStopComm)) { string text_type = fkeyType == AsapCommFKeyType.Recall ? "recall" : "appointment"; patDetail.AppendNote(Lans.g(_lanThis, "Not sending text because this patient has requested to not be texted or emailed about this " + text_type + ".")); return(false); } int textsSent = _dictPatAsapComms[patNum] .Count(x => (x.SmsSendStatus == AutoCommStatus.SendNotAttempted && x.DateTimeSmsScheduled.Date == DtStartSendText.Date) || (x.SmsSendStatus == AutoCommStatus.SendSuccessful && x.DateTimeSmsSent.Date == DtStartSendText.Date)); if (textsSent >= _maxTextsPerDay) { patDetail.AppendNote(Lans.g(_lanThis, "Not sending text because this patient has received") + " " + _maxTextsPerDay + " " + Lans.g(_lanThis, "texts today.")); return(false); } } bool isWithin30Minutes = (GetNextTextSendTime() < _dtSlotStart && (_dtSlotStart - GetNextTextSendTime()).TotalMinutes < TextMinMinutesBefore); bool isAfterSlot = (GetNextTextSendTime() > _dtSlotStart); if (isWithin30Minutes) { patDetail.AppendNote(Lans.g(_lanThis, "Not sending text because the text would be sent less than") + " " + TextMinMinutesBefore + " " + Lans.g(_lanThis, "before the time slot.")); return(false); } if (isAfterSlot) { patDetail.AppendNote(Lans.g(_lanThis, "Not sending text because the text would be sent after the time slot.")); return(false); } if (_sendMode == SendMode.Email) { return(false); } if (_sendMode == SendMode.PreferredContact && patComm.PreferContactMethod != ContactMethod.TextMessage) { patDetail.AppendNote(Lans.g(_lanThis, "Not sending text because this patient's preferred contact method is not text message.")); return(false); } if (!patComm.IsSmsAnOption) { patDetail.AppendNote(Lans.g(_lanThis, patComm.GetReasonCantText())); return(false); } return(true); }); bool doSendText = funcSendText(); patDetail.IsSendingText = doSendText; return(doSendText); }