-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathDataLookupFacadeBreastScreening.cs
More file actions
112 lines (103 loc) · 4.25 KB
/
DataLookupFacadeBreastScreening.cs
File metadata and controls
112 lines (103 loc) · 4.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
namespace NHS.CohortManager.ScreeningValidationService;
using DataServices.Client;
using Microsoft.Extensions.Logging;
using Model;
using Common;
public class DataLookupFacadeBreastScreening : IDataLookupFacadeBreastScreening
{
private readonly ILogger<DataLookupFacadeBreastScreening> _logger;
private readonly IDataServiceClient<BsSelectGpPractice> _gpPracticeServiceClient;
private readonly IDataServiceClient<BsSelectOutCode> _outcodeClient;
private readonly IDataServiceClient<CurrentPosting> _currentPostingClient;
private readonly IDataServiceClient<ExcludedSMULookup> _excludedSMUClient;
private readonly string[] allPossiblePostingCategories = ["ENGLAND", "IOM", "DMS"];
public DataLookupFacadeBreastScreening
(
ILogger<DataLookupFacadeBreastScreening> logger,
IDataServiceClient<BsSelectGpPractice> gpPracticeClient,
IDataServiceClient<BsSelectOutCode> outcodeClient,
IDataServiceClient<CurrentPosting> currentPostingClient,
IDataServiceClient<ExcludedSMULookup> excludedSMUClient
)
{
_logger = logger;
_gpPracticeServiceClient = gpPracticeClient;
_outcodeClient = outcodeClient;
_currentPostingClient = currentPostingClient;
_excludedSMUClient = excludedSMUClient;
}
/// <summary>
/// Used in rule 36 in the lookup rules, and rule 54 in the cohort rules.
/// Validates the participants primary care provider (GP practice code)
/// </summary>
/// <param name="primaryCareProvider">The participant's primary care provider.</param>
/// <returns>bool, whether or not the GP practice code exists in the DB.<returns>
public bool CheckIfPrimaryCareProviderExists(string primaryCareProvider)
{
_logger.LogInformation("Checking Primary Care Provider {PrimaryCareProvider} Exists", primaryCareProvider);
var result = _gpPracticeServiceClient.GetSingle(primaryCareProvider).Result;
return result != null;
}
/// <summary>
/// Used in rule 54 in the cohort rules. Validates the participants outcode (1st part of the postcode)
/// </summary>
/// <param name="postcode">The participant's postcode.</param>
/// <returns>bool, whether or not the outcode code exists in the DB.<returns>
public bool ValidateOutcode(string postcode)
{
var outcode = ValidationHelper.ParseOutcode(postcode);
_logger.LogInformation("Validating Outcode: {Outcode}", outcode);
var result = _outcodeClient.GetSingle(outcode!).Result;
return result != null;
}
/// Used in rule 58 of the lookup rules.
/// Validates that the current posting exists, and that it is in the cohort and in use.
/// </summary>
/// <param name="currentPosting">The participant's current posting (area code).</param>
/// <returns>bool, whether or not the current posting is valid.<returns>
public bool CheckIfCurrentPostingExists(string? currentPosting)
{
var result = _currentPostingClient.GetByFilter(i => i.Posting == currentPosting && i.InUse == "Y").Result;
if (result == null)
{
return false;
}
if (result.Any())
{
return true;
}
return false;
}
/// <summary>
/// takes in posting and returns if that posting has a valid posting category in the database
/// </summary>
/// <param name="postingCategory"></param>
/// <returns></returns>
public bool ValidatePostingCategories(string currentPosting)
{
var result = _currentPostingClient.GetSingle(currentPosting).Result;
if (result == null)
{
return false;
}
if (allPossiblePostingCategories.Contains(result.PostingCategory))
{
return true;
}
return false;
}
public bool CheckIfPrimaryCareProviderInExcludedSmuList(string primaryCareProvider)
{
var result = _excludedSMUClient.GetSingle(primaryCareProvider).Result;
return result != null;
}
public string RetrievePostingCategory(string currentPosting)
{
if (string.IsNullOrEmpty(currentPosting))
{
return null;
}
var result = _currentPostingClient.GetSingle(currentPosting).Result;
return result.PostingCategory;
}
}