Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PC-613 create and send weekly compliance report #235

Merged
merged 87 commits into from
Feb 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
87 commits
Select commit Hold shift + click to select a range
ee5db75
Add framework for polling on referral follow ups
CalPinSW Jan 15, 2024
b70b551
Add referral request follow up table to db
CalPinSW Jan 15, 2024
3d99a73
Add pages for following up referrals, fix some logic bugs, add test f…
CalPinSW Jan 16, 2024
189c7b4
Get e2e process working. Still need to write tests, get base address …
CalPinSW Jan 16, 2024
09444d4
Remove unused imports
CalPinSW Jan 16, 2024
630d67d
Remove console logs
CalPinSW Jan 16, 2024
0279535
Fix formtting
CalPinSW Jan 16, 2024
1387ddd
Update logged text in SendFollowUpEmail
CalPinSW Jan 17, 2024
8e92a5c
Remove unecessary comment
CalPinSW Jan 17, 2024
b6ff047
Add Referral follow up email generation to nightly tasks.
CalPinSW Jan 17, 2024
0e6242f
More formatting fixes
CalPinSW Jan 17, 2024
f34aa71
Add mockReferralFollowUpService to RegularJobsService Tests
CalPinSW Jan 17, 2024
7931eae
Add mockReferralFollowUpService to RegularJobsService Tests
CalPinSW Jan 17, 2024
9663e44
Add some unit tests for the ReferralRequestFollowUpService (1 to fix)
CalPinSW Jan 17, 2024
5e67080
Mock guid generation
CalPinSW Jan 17, 2024
0b5cc51
Mock guid generation
CalPinSW Jan 17, 2024
1ca6e6b
Compare moq functions calls on properties, rather than checking they …
CalPinSW Jan 17, 2024
92751df
Update Referral Request Model to include reference to Referral Reques…
CalPinSW Jan 19, 2024
497cc47
Remove accidental grouping variable
CalPinSW Jan 19, 2024
099dd21
Initial structure for testing
CalPinSW Jan 19, 2024
d13fa66
Add Referral Request foreign key to Referral Request Follow Up table
CalPinSW Jan 22, 2024
434c90a
Initial structure for testing
CalPinSW Jan 19, 2024
ba8ff32
Ensure csv files being created correctly
CalPinSW Jan 23, 2024
ea15b86
Merge remote-tracking branch 'refs/remotes/origin/PC-613-create-and-s…
CalPinSW Jan 23, 2024
8de5c8a
Ensure csv files being created correctly
CalPinSW Jan 23, 2024
c1ecf56
Fix some formatting
CalPinSW Jan 23, 2024
297e5d8
Set timing of weekly jobs and add third historic statistics table
CalPinSW Jan 23, 2024
a4f3f39
Reorder functions in CsvFileCreator for better clarity
CalPinSW Jan 23, 2024
e6942f2
Add tests for new CsvFileCreator functions
CalPinSW Jan 24, 2024
a7eb54d
Split out Regular Jobs Service into individual services after merging…
CalPinSW Jan 24, 2024
49a43d6
Merge branch 'PC-612-send-email-poll-checking-referral-follow-ups' in…
CalPinSW Jan 24, 2024
540cff1
Split out Regular Jobs Service following merge with 612
CalPinSW Jan 24, 2024
6a76bed
Pre-review cleanup
CalPinSW Jan 24, 2024
d9730da
Update the startDate calculation of RROverviewTable to match RRFollow…
CalPinSW Jan 24, 2024
30d8b70
Replace N/As with null in consortium fields in Local Authority Data
CalPinSW Jan 29, 2024
e796b1b
Update Consortiums for LAs
CalPinSW Jan 30, 2024
5a8b4ff
Propagate namespace changes from PC-611
CalPinSW Jan 30, 2024
625bf3f
Fix Upss typo
CalPinSW Jan 30, 2024
8157af7
Add whitespace to ReferralRequestFollowup class
CalPinSW Jan 30, 2024
45765a9
Simplify NewGuidString function
CalPinSW Jan 31, 2024
ae87825
pMerge branch 'develop' into PC-612-send-email-poll-checking-referral…
CalPinSW Jan 31, 2024
30158af
Use var for local variables in ReferralFollowUpService
CalPinSW Jan 31, 2024
edc9c2e
Fix indentation in ReferralFollowUpService
CalPinSW Jan 31, 2024
991ee30
Refactor ReferralFollowUpNotification Service to get referralRequestF…
CalPinSW Jan 31, 2024
8dae148
Update AddReferralFollowUpToken to PersistReferralFollowUpToken to ma…
CalPinSW Jan 31, 2024
b53bc36
Make GetReferralFollowUpByToken Async
CalPinSW Jan 31, 2024
68a834f
Use SingleAsync throughout DataAccessProvider
CalPinSW Jan 31, 2024
73e79ea
Use query string rather than URL parameter for respond-page get endpo…
CalPinSW Jan 31, 2024
e90b783
Simplify Referral Request Follow Up view names
CalPinSW Jan 31, 2024
a0fd2ef
Remove user dotsettings file
CalPinSW Jan 31, 2024
a09d656
Fix indentation of appsettings.json
CalPinSW Jan 31, 2024
c485b3c
Rename table parameters to indicate that they are actually file data
CalPinSW Jan 31, 2024
de4bd8b
Add Follow Up responses to file data
CalPinSW Jan 31, 2024
9da2f36
Reuse Csv MemoryStream creation in CsvFileCreator
CalPinSW Jan 31, 2024
699b921
Update run time of PolicyTeamUpdate to 7am
CalPinSW Jan 31, 2024
585820f
Remove unused RecipientNamePlaceholder from notify config
CalPinSW Jan 31, 2024
fff436f
Remove whitespace from appsettings.json
CalPinSW Jan 31, 2024
9554fe8
Fix new View names in controller. Make BaseUrl a config variable
CalPinSW Jan 31, 2024
fc485eb
Add newline at end of file
CalPinSW Jan 31, 2024
2f11b62
Fix unnecessary async test
CalPinSW Jan 31, 2024
7a25e21
Merge branch 'PC-612-send-email-poll-checking-referral-follow-ups' in…
CalPinSW Jan 31, 2024
32218b4
Pass through namespace change from 612
CalPinSW Jan 31, 2024
5f77cf6
Update percentage calculations to consider only RRs with follow ups
CalPinSW Feb 1, 2024
1f47b28
Refactor RegularJobsNotificationServiceConfiguration to be GlobalConf…
CalPinSW Feb 1, 2024
76c9708
Use Uri builder to construct follow up link
CalPinSW Feb 1, 2024
4fcacfc
Don't rethrow error on KeyNotFoundException in FollowUpEmail sending.…
CalPinSW Feb 1, 2024
8f3d960
Add cutoff epoch to referralRequestNotification service and only send…
CalPinSW Feb 1, 2024
a9c8d2f
Merge branch 'PC-612-send-email-poll-checking-referral-follow-ups' in…
CalPinSW Feb 1, 2024
68bee01
Return to calculating percentage of uncontactedConsortiumReferrals as…
CalPinSW Feb 1, 2024
b6e9f3b
Refactor CreateReferralRequestFollowUpFileData function for readability
CalPinSW Feb 1, 2024
590a7f3
Update CutoffEpoch
CalPinSW Feb 1, 2024
96ebc2d
Pull email addresses for compliance email from config
CalPinSW Feb 2, 2024
4f891dc
Move Cutoff Epoch forward a week to account for testing week
CalPinSW Feb 2, 2024
e00af09
Add earlier cutoff dates for RR notifications for dev and staging env…
CalPinSW Feb 2, 2024
c65484d
Merge branch 'PC-612-send-email-poll-checking-referral-follow-ups' in…
CalPinSW Feb 2, 2024
14ae600
Parse comma separated list of recipient emails for compliance email
CalPinSW Feb 2, 2024
88751d7
Multiply percentages by 100 and use doubles not floats.
CalPinSW Feb 2, 2024
60cb2d8
Use Counts instead of Sums for calculations in CsvFileCreator
CalPinSW Feb 2, 2024
9721117
Use requestGrouping.Key for custodian code
CalPinSW Feb 2, 2024
6a3d9fa
Improve parameter name in CsvRowLaDownloadInformation
CalPinSW Feb 2, 2024
d424b82
Re-enable email Sending
CalPinSW Feb 2, 2024
58f3883
Handle empty recipient list
CalPinSW Feb 2, 2024
5bb5f7d
Merge branch 'develop' into PC-613-create-and-send-weekly-compliance-…
CalPinSW Feb 2, 2024
73e174e
Use isNullOrEmpty to check recipient list
CalPinSW Feb 2, 2024
43ac10b
Update unit tests with double percentages and new columns
CalPinSW Feb 2, 2024
766ca52
Add ComplianceEmailRecipients to required secrets in Readme
CalPinSW Feb 2, 2024
b5c3452
Merge branch 'develop' into PC-613-create-and-send-weekly-compliance-…
CalPinSW Feb 5, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
using System;
using System.Collections.Generic;
using HerPublicWebsite.BusinessLogic.Models;
using HerPublicWebsite.BusinessLogic.Models;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using Notify.Client;
using Notify.Exceptions;
using Notify.Models.Responses;

namespace HerPublicWebsite.BusinessLogic.ExternalServices.EmailSending
{
Expand Down Expand Up @@ -135,8 +132,41 @@ string followUpLink


}
}

public void SendComplianceEmail(
MemoryStream recentReferralRequestOverviewFileData,
MemoryStream recentReferralRequestFollowUpFileData,
MemoryStream historicReferralRequestFollowUpFileData
)
{
var recipientList = govUkNotifyConfig.ComplianceEmailRecipients;
if (String.IsNullOrEmpty(recipientList))
{
return;
}

var template = govUkNotifyConfig.ComplianceReportTemplate;
Dictionary<String, dynamic> personalisation = new Dictionary<String, dynamic>
{
{ "File1Link", NotificationClient.PrepareUpload(recentReferralRequestOverviewFileData.ToArray(), true)},
{ "File2Link", NotificationClient.PrepareUpload(recentReferralRequestFollowUpFileData.ToArray(), true)},
{ "File3Link", NotificationClient.PrepareUpload(historicReferralRequestFollowUpFileData.ToArray(), true)},
};
foreach (var emailAddress in recipientList.Split(","))
{
var emailModel = new GovUkNotifyEmailModel
{
EmailAddress = emailAddress.Trim(),
TemplateId = template.Id,
Personalisation = personalisation
};
SendEmail(emailModel);
}
CalPinSW marked this conversation as resolved.
Show resolved Hide resolved

}

}

internal class GovUkNotifyEmailModel
{
public string EmailAddress { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ public class GovUkNotifyConfiguration
public const string ConfigSection = "GovUkNotify";

public string ApiKey { get; set; }
public string ComplianceEmailRecipients { get; set; }
public ReferenceCodeConfiguration ReferenceCodeTemplate { get; set; }
public ReferralFollowUpConfiguration ReferralFollowUpTemplate { get; set; }
public ComplianceReportConfiguration ComplianceReportTemplate { get; set; }
}

public class ReferenceCodeConfiguration
Expand All @@ -27,3 +29,12 @@ public class ReferralFollowUpConfiguration
public string ReferralDatePlaceholder { get; set; }
public string FollowUpLinkPlaceholder {get; set; }
}

public class ComplianceReportConfiguration
{
public string Id { get; set; }
public string RecipientNamePlaceholder { get; set; }
public string File1Link { get; set; }
public string File2Link { get; set; }
public string File3Link { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,11 @@ public void SendFollowUpEmail
ReferralRequest referralRequest,
string followUpLink
);

public void SendComplianceEmail
(
MemoryStream recentReferralRequestOverviewFileData,
MemoryStream recentReferralRequestFollowUpFileData,
MemoryStream historicReferralRequestFollowUpFileData
);
}
2 changes: 2 additions & 0 deletions HerPublicWebsite.BusinessLogic/IDataAccessProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ public interface IDataAccessProvider
Task<ReferralRequest> UpdateReferralRequestByIdWithFollowUpSentAsync(int id);
Task PersistNotificationConsentAsync(string referralId, NotificationDetails notificationDetails);
Task<IList<ReferralRequest>> GetUnsubmittedReferralRequestsAsync();
Task<IList<ReferralRequest>> GetAllReferralRequests();
Task<IList<ReferralRequest>> GetReferralRequestsBetweenDates(DateTime startDate, DateTime endDate);
Task<IList<ReferralRequest>> GetReferralRequestsWithNoFollowUpBetweenDates(DateTime startDate, DateTime endDate);
Task<IList<ReferralRequest>> GetReferralRequestsByCustodianAndRequestDateAsync(string custodianCode, int month, int year);
Task<AnonymisedReport> PersistAnonymisedReportAsync(AnonymisedReport report);
Expand Down
705 changes: 353 additions & 352 deletions HerPublicWebsite.BusinessLogic/Models/LocalAuthorityData.cs

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion HerPublicWebsite.BusinessLogic/Models/ReferralRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@
public bool ReferralWrittenToCsv { get; set; }

public bool FollowUpEmailSent { get; set; }


public ReferralRequestFollowUp? FollowUp {get; set;}

Check warning on line 37 in HerPublicWebsite.BusinessLogic/Models/ReferralRequest.cs

View workflow job for this annotation

GitHub Actions / build-and-run-tests

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 37 in HerPublicWebsite.BusinessLogic/Models/ReferralRequest.cs

View workflow job for this annotation

GitHub Actions / build-and-run-tests

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

public string ReferralCode { get; set; }

public ReferralRequest()
Expand Down
170 changes: 155 additions & 15 deletions HerPublicWebsite.BusinessLogic/Services/CsvFileCreator/CsvFileCreator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,149 @@ namespace HerPublicWebsite.BusinessLogic.Services.CsvFileCreator;

public class CsvFileCreator
{
public MemoryStream CreateFileData(IEnumerable<ReferralRequest> referralRequests)
public MemoryStream CreateReferralRequestFileData(IEnumerable<ReferralRequest> referralRequests)
{
var rows = referralRequests.Select(rr => new CsvRow(rr));
var rows = referralRequests.Select(rr => new CsvRowReferralRequest(rr));
return GenerateCsvMemoryStreamFromFileRows(rows);
}

var csvConfiguration = new CsvConfiguration(CultureInfo.InvariantCulture)
{
InjectionOptions = InjectionOptions.Strip
};
public MemoryStream CreateReferralRequestOverviewFileData(IEnumerable<ReferralRequest> referralRequests)
{
var rows = referralRequests.Select(rr => new CsvRowReferralCodes(rr));
return GenerateCsvMemoryStreamFromFileRows(rows);
}

using var writeableMemoryStream = new MemoryStream();
using var streamWriter = new StreamWriter(writeableMemoryStream, Encoding.UTF8);
using var csvWriter = new CsvWriter(streamWriter, csvConfiguration);
{
csvWriter.WriteRecords(rows);
csvWriter.Flush();
return new MemoryStream(writeableMemoryStream.GetBuffer(), 0, (int)writeableMemoryStream.Length, false);
public MemoryStream CreateReferralRequestFollowUpFileData(IEnumerable<ReferralRequest> referralRequests)
{
var rows = referralRequests
.GroupBy(rr => rr.CustodianCode)
.GroupBy(groupingByLa =>
LocalAuthorityData.LocalAuthorityDetailsByCustodianCode[groupingByLa.Key].Consortium)
.SelectMany(groupingByConsortium =>
{
var consortiumReferrals = groupingByConsortium.SelectMany(g => g).ToList();
var consortiumStatistics = new ConsortiumStatistics(consortiumReferrals);
return groupingByConsortium.Select(groupingByLa => new CsvRowLaDownloadInformation(groupingByLa, consortiumStatistics));
}
);
return GenerateCsvMemoryStreamFromFileRows(rows);
}

private class CsvRowReferralCodes
{
[Index(0)]
[Name("Consortium")]
public string Consortium { get; set; }

[Index(1)]
[Name("Local Authority")]
public string LocalAuthority { get; set; }

[Index(2)]
[Name("Referral Code")]
public string ReferralCode { get; set; }
public CsvRowReferralCodes(ReferralRequest request){
Consortium = LocalAuthorityData.LocalAuthorityDetailsByCustodianCode[request.CustodianCode].Consortium;
LocalAuthority = LocalAuthorityData.LocalAuthorityDetailsByCustodianCode[request.CustodianCode].Name;
ReferralCode = request.ReferralCode;
}
}

private class ConsortiumStatistics
{
public bool AllConsortiumReferralsDownloaded { get; set; }
public int NumberUndownloadedConsortiumReferrals { get; set; }
public double PercentageUndownloadedConsortiumReferrals { get; set; }
public bool AllConsortiumReferralsContacted { get; set; }
public int NumberUncontactedConsortiumReferrals { get; set; }
public double PercentageUncontactedConsortiumReferrals { get; set; }
public ConsortiumStatistics(List<ReferralRequest> referralRequests){
NumberUndownloadedConsortiumReferrals = referralRequests.Count(rr => !rr.ReferralWrittenToCsv);
AllConsortiumReferralsDownloaded = NumberUndownloadedConsortiumReferrals == 0;
PercentageUndownloadedConsortiumReferrals = 100 * (double)NumberUndownloadedConsortiumReferrals / referralRequests.Count();
CalPinSW marked this conversation as resolved.
Show resolved Hide resolved
NumberUncontactedConsortiumReferrals = referralRequests.Count(rr => rr.FollowUp?.WasFollowedUp == false);
AllConsortiumReferralsContacted = NumberUncontactedConsortiumReferrals == 0;
PercentageUncontactedConsortiumReferrals = 100 * (double)NumberUncontactedConsortiumReferrals / referralRequests.Count();
}
}

private class CsvRowLaDownloadInformation
{
[Index(0)]
[Name("Consortium")]
public string Consortium { get; set; }

[Index(1)]
[Name("Consortium All Referrals Downloaded")]
public bool AllConsortiumReferralsDownloaded { get; set; }

[Index(2)]
[Name("Consortium Number of Referrals Not Downloaded")]
public int NumberUndownloadedConsortiumReferrals { get; set; }

[Index(3)]
[Name("Consortium Percentage of Referrals Not Downloaded")]
public double PercentageUndownloadedConsortiumReferrals { get; set; }

[Index(4)]
[Name("Consortium All Referrals Contacted")]
public bool AllConsortiumReferralsContacted { get; set; }

[Index(5)]
[Name("Consortium Number of Referrals Not Contacted")]
public int NumberUncontactedConsortiumReferrals { get; set; }

[Index(6)]
[Name("Consortium Percentage of Referrals Not Contacted")]
public double PercentageUncontactedConsortiumReferrals { get; set; }

[Index(7)]
[Name("LA")]
public string LocalAuthority { get; set; }

[Index(8)]
[Name("LA Number of Referrals Not Downloaded")]
public int NumberUndownloadedLaReferrals { get; set; }

[Index(9)]
[Name("LA Percentage of Referrals Not Downloaded")]
public double PercentageUndownloadedLaReferrals { get; set; }

[Index(10)]
[Name("LA Number of Referrals Not Contacted")]
public int NumberUncontactedLaReferrals { get; set; }

[Index(11)]
[Name("LA Percentage of Referrals Not Contacted")]
public double PercentageUncontactedLaReferrals { get; set; }

[Index(12)]
[Name("LA Number of Referrals Responded to email")]
public int LaNumberOfFollowUpResponses { get; set; }

[Index(13)]
[Name("LA Percentage of Referrals Responded to email")]
public double LaPercentageOfFollowUpResponses { get; set; }

public CsvRowLaDownloadInformation(IGrouping<string,ReferralRequest> requestGroupingByCustodianCode, ConsortiumStatistics consortiumData){
Consortium = LocalAuthorityData.LocalAuthorityDetailsByCustodianCode[requestGroupingByCustodianCode.Key].Consortium;
LocalAuthority = LocalAuthorityData.LocalAuthorityDetailsByCustodianCode[requestGroupingByCustodianCode.Key].Name;
AllConsortiumReferralsDownloaded = consortiumData.AllConsortiumReferralsDownloaded;
NumberUndownloadedConsortiumReferrals = consortiumData.NumberUndownloadedConsortiumReferrals;
PercentageUndownloadedConsortiumReferrals = consortiumData.PercentageUndownloadedConsortiumReferrals;
AllConsortiumReferralsContacted = consortiumData.AllConsortiumReferralsContacted;
NumberUncontactedConsortiumReferrals = consortiumData.NumberUncontactedConsortiumReferrals;
PercentageUncontactedConsortiumReferrals = consortiumData.PercentageUncontactedConsortiumReferrals;
NumberUndownloadedLaReferrals = requestGroupingByCustodianCode.Count(rr => !rr.ReferralWrittenToCsv);
PercentageUndownloadedLaReferrals = 100 * (double)NumberUndownloadedLaReferrals/requestGroupingByCustodianCode.Count();
NumberUncontactedLaReferrals = requestGroupingByCustodianCode.Count(rr => rr.FollowUp?.WasFollowedUp == false);
PercentageUncontactedLaReferrals = 100 * (double)NumberUncontactedLaReferrals / requestGroupingByCustodianCode.Count();
LaNumberOfFollowUpResponses = requestGroupingByCustodianCode.Count(rr => rr.FollowUp?.WasFollowedUp != null);
LaPercentageOfFollowUpResponses = 100 * (double)LaNumberOfFollowUpResponses / requestGroupingByCustodianCode.Sum(rr => rr.FollowUp != null ? 1 : 0 );
}
}

private class CsvRow
private class CsvRowReferralRequest
{
[Index(0)]
[Name("Referral date")]
Expand Down Expand Up @@ -98,7 +221,7 @@ private class CsvRow
[Index(17)]
public string Tenure { get; set; }

public CsvRow(ReferralRequest request)
public CsvRowReferralRequest(ReferralRequest request)
{
ReferralDate = request.RequestDate.ToString("yyyy-MM-dd HH:mm:ss");
ReferralCode = request.ReferralCode;
Expand Down Expand Up @@ -139,4 +262,21 @@ public CsvRow(ReferralRequest request)
Tenure = "Owner";
}
}

private MemoryStream GenerateCsvMemoryStreamFromFileRows<T>(IEnumerable<T> rows)
{
var csvConfiguration = new CsvConfiguration(CultureInfo.InvariantCulture)
{
InjectionOptions = InjectionOptions.Strip
};

using var writeableMemoryStream = new MemoryStream();
using var streamWriter = new StreamWriter(writeableMemoryStream, Encoding.UTF8);
using var csvWriter = new CsvWriter(streamWriter, csvConfiguration);
{
csvWriter.WriteRecords(rows);
csvWriter.Flush();
return new MemoryStream(writeableMemoryStream.GetBuffer(), 0, (int)writeableMemoryStream.Length, false);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
using HerPublicWebsite.BusinessLogic.ExternalServices.EmailSending;
using HerPublicWebsite.BusinessLogic.Services.RegularJobs;

namespace HerPublicWebsite.BusinessLogic.Services.PolicyTeamUpdate;

public interface IPolicyTeamUpdate
{
public Task SendPolicyTeamUpdate();
}

public class PolicyTeamUpdateService : IPolicyTeamUpdate
{
private readonly IDataAccessProvider dataProvider;
private readonly CsvFileCreator.CsvFileCreator csvFileCreator;
private readonly IWorkingDayHelperService workingDayHelperService;
private readonly IEmailSender emailSender;

public PolicyTeamUpdateService(
IDataAccessProvider dataProvider,
CsvFileCreator.CsvFileCreator csvFileCreator,
IWorkingDayHelperService workingDayHelperService,
IEmailSender emailSender
)
{
this.dataProvider = dataProvider;
this.csvFileCreator = csvFileCreator;
this.workingDayHelperService = workingDayHelperService;
this.emailSender = emailSender;
}

public async Task SendPolicyTeamUpdate(){
var recentReferralRequestOverviewFileData = await CreateReferralRequestOverviewFileData();
var recentReferralRequestFollowUpFileData = await BuildRecentReferralRequestFollowUpFileData();
var historicReferralRequestFollowUpFileData = await BuildHistoricReferralRequestFollowUpFileData();
emailSender.SendComplianceEmail(
recentReferralRequestOverviewFileData,
recentReferralRequestFollowUpFileData,
historicReferralRequestFollowUpFileData
);

}

private async Task<MemoryStream> CreateReferralRequestOverviewFileData (){
DateTime endDate = await workingDayHelperService.AddWorkingDaysToDateTime(DateTime.Now, -10);
DateTime startDate = await workingDayHelperService.AddWorkingDaysToDateTime(DateTime.Now.AddDays(-7), -10);
var newReferrals = await dataProvider.GetReferralRequestsBetweenDates(startDate, endDate);
return csvFileCreator.CreateReferralRequestOverviewFileData(newReferrals);
}

private async Task<MemoryStream> BuildRecentReferralRequestFollowUpFileData (){
DateTime endDate = await workingDayHelperService.AddWorkingDaysToDateTime(DateTime.Now, -10);
DateTime startDate = await workingDayHelperService.AddWorkingDaysToDateTime(DateTime.Now.AddDays(-7), -10);
CalPinSW marked this conversation as resolved.
Show resolved Hide resolved
var newReferrals = await dataProvider.GetReferralRequestsBetweenDates(startDate, endDate);
return csvFileCreator.CreateReferralRequestFollowUpFileData(newReferrals);
}

private async Task<MemoryStream> BuildHistoricReferralRequestFollowUpFileData (){
var newReferrals = await dataProvider.GetAllReferralRequests();
return csvFileCreator.CreateReferralRequestFollowUpFileData(newReferrals);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public async Task WriteUnsubmittedReferralRequestsToCsv()
var grouping = referralsByCustodianMonthAndYear.Key;
var referralsForFile = await dataProvider.GetReferralRequestsByCustodianAndRequestDateAsync(grouping.CustodianCode, grouping.Month, grouping.Year);

using (var fileData = csvFileCreator.CreateFileData(referralsForFile))
using (var fileData = csvFileCreator.CreateReferralRequestFileData(referralsForFile))
{
await s3FileWriter.WriteFileAsync(grouping.CustodianCode, grouping.Month, grouping.Year, fileData);
}
Expand Down
15 changes: 15 additions & 0 deletions HerPublicWebsite.Data/DataAccessProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,21 @@ public async Task<IList<ReferralRequest>> GetUnsubmittedReferralRequestsAsync()
.ToListAsync();
}

public async Task<IList<ReferralRequest>> GetAllReferralRequests()
{
return await context.ReferralRequests
.Include(rr => rr.FollowUp)
.ToListAsync();
}

public async Task<IList<ReferralRequest>> GetReferralRequestsBetweenDates(DateTime startDate, DateTime endDate)
{
return await context.ReferralRequests
.Where(rr => rr.RequestDate >= startDate && rr.RequestDate <= endDate)
.Include(rr => rr.FollowUp)
.ToListAsync();
}

public async Task<IList<ReferralRequest>> GetReferralRequestsWithNoFollowUpBetweenDates(DateTime startDate, DateTime endDate)
{
return await context.ReferralRequests
Expand Down
Loading
Loading