Skip to content

Commit 4869b6c

Browse files
refactor: DTOSS-7517 - Continued adding config classes for the rest of the functions (#793)
* Added AddCohortDistributionDataConfig.cs and used in AddCohortDistributionData function * Added config class + changed Program.cs in RetrieveParticipantData function * Added config class to ValidateCohortDistributionRecord + used in program.cs * Added config class and program.cs treatment to DemographicDataManagementFunction * Added new config scheme to DemographicDurableFunction * Added config class to RetrievePDSDemographic * Added CreateExceptionConfig for CreateException function * Added AddParticipantConfig to AddParticipant Function * Add CheckParticipantExistsConfig to CheckParticipantExists function * Added config class to GetParticipantReferenceData function * Added config class to RemoveParticipant function * Added config class to UpdateParticipant function * Added config class to UpdateParticipantFromScreeningProvider function * Added config class to CreateParticipant function app * Added config class to GetValidationExceptions function * Added config classes to 3 functions: markParticipantAsEligible, markParticipantAsIneligible, updateParticipantDetails * Added config class to RemoveValidationException function * Cleared environment variable usage from rest of RetrieveMeshFile function * Removed env var direct usage from CreateCohortDistribution function * Removed all direct calls to env vars in RetrieveParticipantData function * Removed environment variable usage from ValidateCohortDistributionRecord function * Removed direct usage of env vars from RetrievePDSDemographic and addParticipant functions * Removed env var usage from RemoveParticipant function app * Removed env var direct usage from updateParticipant * Removed env var direct usage from createParticipant function * Removed env var direct usage from markParticipantAsIneligible function * Removed direct env var usage from updateParticipantDetails function * Removed env var usage from FileValidation function, added config class * Updated FileValidation function Program.cs to include new config class * Removed env var usage from StaticValidation function, added new StaticValidationConfig class * Removed required flag on markParticipantAsIneligible in updateParticipant function * Corrected FileValidationTests to inject new config object * Corrected MarkParticipantAsIneligible unit tests to inject new config class * Corrected CreateParticipantTest.cs unit tests to inject new config object * Corrected more unit tests with prefilled config object * Expanded and corrected config setup for RetrieveMeshFileTest * Updated RetrievePdsDemographicTests to include new config item * Updated UpdateParticipantDetailsTests to include new config * Removed incorrect change to CreateParticipantTest.cs * cleaned up and fixed MarkParticipantAsIneligibleTests * Made markParticipantAsIneligible in UpdateParticipantConfig Required
1 parent 99578b1 commit 4869b6c

72 files changed

Lines changed: 950 additions & 269 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

application/CohortManager/src/Functions/CaasIntegration/RetrieveMeshFile/Program.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@
2525

2626
host.AddConfiguration<RetrieveMeshFileConfig>(out RetrieveMeshFileConfig config);
2727

28-
if (!string.IsNullOrEmpty(KeyVaultConnectionString))
28+
if (!string.IsNullOrEmpty(config.KeyVaultConnectionString))
2929
{
3030
logger.LogInformation("Pulling Mesh Certificate from KeyVault");
31-
var client = new CertificateClient(vaultUri: new Uri(KeyVaultConnectionString), credential: new DefaultAzureCredential());
31+
var client = new CertificateClient(vaultUri: new Uri(config.KeyVaultConnectionString), credential: new DefaultAzureCredential());
3232
var certificate = await client.DownloadCertificateAsync(config.MeshKeyName);
3333
cert = certificate.Value;
3434
}

application/CohortManager/src/Functions/CaasIntegration/RetrieveMeshFile/RetrieveMeshFile.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ public class RetrieveMeshFile
2222
private readonly string _mailboxId;
2323
private readonly string _blobConnectionString;
2424
private readonly IBlobStorageHelper _blobStorageHelper;
25+
private readonly RetrieveMeshFileConfig _config;
2526
private const string NextHandShakeTimeConfigKey = "NextHandShakeTime";
2627
private const string ConfigFileName = "MeshState.json";
2728

@@ -31,7 +32,8 @@ public RetrieveMeshFile(ILogger<RetrieveMeshFile> logger, IMeshToBlobTransferHan
3132
_meshToBlobTransferHandler = meshToBlobTransferHandler;
3233
_blobStorageHelper = blobStorageHelper;
3334
_mailboxId = options.Value.BSSMailBox;
34-
_blobConnectionString = Environment.GetEnvironmentVariable("caasfolder_STORAGE");
35+
_config = options.Value;
36+
_blobConnectionString = _config.caasfolder_STORAGE;
3537
}
3638
/// <summary>
3739
/// This function polls the MESH Mailbox every 5 minutes, if there is a file posted to the mailbox.

application/CohortManager/src/Functions/CaasIntegration/RetrieveMeshFile/RetrieveMeshFileConfig.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,11 @@ public class RetrieveMeshFileConfig
1010
[Required]
1111
public string MeshPassword { get; set; }
1212
[Required]
13-
public string MeshSharedKey { get; set; }
14-
public string MeshKeyPassphrase { get; set; }
15-
public string MeshKeyName { get; set; }
16-
13+
public string MeshSharedKey {get; set;}
14+
public string MeshKeyPassphrase {get; set;}
15+
public string MeshKeyName {get; set;}
16+
public string KeyVaultConnectionString {get; set;}
17+
[Required]
18+
public string caasfolder_STORAGE {get; set;}
1719
public string ServerSideCerts { get; set; }
18-
1920
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
namespace NHS.Screening.AddCohortDistribution;
2+
3+
using System.ComponentModel.DataAnnotations;
4+
5+
public class AddCohortDistributionDataConfig
6+
{
7+
[Required]
8+
public string CohortDistributionDataServiceURL {get; set;}
9+
}

application/CohortManager/src/Functions/CohortDistributionServices/AddCohortDistributionData/Program.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,13 @@
77
using Microsoft.Extensions.Hosting;
88
using Model;
99
using HealthChecks.Extensions;
10+
using NHS.Screening.AddCohortDistribution;
1011

1112
var host = new HostBuilder()
12-
.AddDataServicesHandler()
13-
.AddDataService<CohortDistribution>(Environment.GetEnvironmentVariable("CohortDistributionDataServiceURL"))
14-
.Build()
13+
.AddConfiguration<AddCohortDistributionDataConfig>(out AddCohortDistributionDataConfig config)
14+
.AddDataServicesHandler()
15+
.AddDataService<CohortDistribution>(config.CohortDistributionDataServiceURL)
16+
.Build()
1517
.ConfigureFunctionsWorkerDefaults()
1618
.ConfigureServices(services =>
1719
{

application/CohortManager/src/Functions/CohortDistributionServices/CreateCohortDistribution/CreateCohortDistribution.cs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ namespace NHS.CohortManager.CohortDistributionService;
1010
using Model.Enums;
1111
using Data.Database;
1212
using DataServices.Client;
13+
using NHS.Screening.CreateCohortDistribution;
14+
using Microsoft.Extensions.Options;
1315

1416
public class CreateCohortDistribution
1517
{
@@ -18,18 +20,21 @@ public class CreateCohortDistribution
1820
private readonly ICohortDistributionHelper _CohortDistributionHelper;
1921
private readonly IExceptionHandler _exceptionHandler;
2022
private readonly IAzureQueueStorageHelper _azureQueueStorageHelper;
23+
private readonly CreateCohortDistributionConfig _config;
2124

2225
public CreateCohortDistribution(ILogger<CreateCohortDistribution> logger,
2326
ICallFunction callFunction,
2427
ICohortDistributionHelper CohortDistributionHelper,
2528
IExceptionHandler exceptionHandler,
26-
IAzureQueueStorageHelper azureQueueStorageHelper)
29+
IAzureQueueStorageHelper azureQueueStorageHelper,
30+
IOptions<CreateCohortDistributionConfig> createCohortDistributionConfig)
2731
{
2832
_logger = logger;
2933
_callFunction = callFunction;
3034
_CohortDistributionHelper = CohortDistributionHelper;
3135
_exceptionHandler = exceptionHandler;
3236
_azureQueueStorageHelper = azureQueueStorageHelper;
37+
_config = createCohortDistributionConfig.Value;
3338
}
3439

3540
[Function(nameof(CreateCohortDistribution))]
@@ -64,7 +69,7 @@ public async Task RunAsync([QueueTrigger("%CohortQueueName%", Connection = "Azur
6469
}
6570

6671
// Check if participant has exceptions
67-
bool ignoreParticipantExceptions = Environment.GetEnvironmentVariable("IgnoreParticipantExceptions") == "true";
72+
bool ignoreParticipantExceptions = _config.IgnoreParticipantExceptions;
6873
_logger.LogInformation("Environment variable IgnoreParticipantExceptions is set to {IgnoreParticipantExceptions}", ignoreParticipantExceptions);
6974
bool participantHasException = participantData.ExceptionFlag == 1;
7075

@@ -121,14 +126,14 @@ private async Task HandleErrorResponseAsync(string errorMessage, CohortDistribut
121126
}
122127

123128
await _exceptionHandler.CreateSystemExceptionLog(new Exception(errorMessage), participant, fileName);
124-
await _azureQueueStorageHelper.AddItemToQueueAsync<CohortDistributionParticipant>(cohortDistributionParticipant, Environment.GetEnvironmentVariable("CohortQueueNamePoison"));
129+
await _azureQueueStorageHelper.AddItemToQueueAsync<CohortDistributionParticipant>(cohortDistributionParticipant, _config.CohortQueueNamePoison);
125130
}
126131

127132
private async Task<HttpWebResponse> AddCohortDistribution(CohortDistributionParticipant transformedParticipant)
128133
{
129134
transformedParticipant.Extracted = DatabaseHelper.ConvertBoolStringToBoolByType("IsExtractedToBSSelect", DataTypes.Integer).ToString();
130135
var json = JsonSerializer.Serialize(transformedParticipant);
131-
var response = await _callFunction.SendPost(Environment.GetEnvironmentVariable("AddCohortDistributionURL"), json);
136+
var response = await _callFunction.SendPost(_config.AddCohortDistributionURL, json);
132137

133138
_logger.LogInformation("Called {AddCohortDistribution} function", nameof(AddCohortDistribution));
134139
return response;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
namespace NHS.Screening.CreateCohortDistribution;
2+
3+
using System.ComponentModel.DataAnnotations;
4+
5+
public class CreateCohortDistributionConfig
6+
{
7+
[Required]
8+
public bool IgnoreParticipantExceptions {get; set;}
9+
[Required]
10+
public string CohortQueueNamePoison {get; set;}
11+
[Required]
12+
public string AddCohortDistributionURL {get; set;}
13+
}

application/CohortManager/src/Functions/CohortDistributionServices/CreateCohortDistribution/Program.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,13 @@
33
using Microsoft.Extensions.DependencyInjection;
44
using Microsoft.Extensions.DependencyInjection.Extensions;
55
using Microsoft.Extensions.Hosting;
6+
using DataServices.Client;
7+
using Model;
8+
using NHS.Screening.CreateCohortDistribution;
69
using HealthChecks.Extensions;
710

811
var host = new HostBuilder()
12+
.AddConfiguration<CreateCohortDistributionConfig>(out CreateCohortDistributionConfig config)
913
.ConfigureFunctionsWorkerDefaults()
1014
.ConfigureServices(services =>
1115
{

application/CohortManager/src/Functions/CohortDistributionServices/RetrieveParticipantData/Program.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@
55
using Microsoft.Extensions.DependencyInjection;
66
using Microsoft.Extensions.Hosting;
77
using Model;
8+
using NHS.Screening.RetrieveParticipantData;
89

910
var host = new HostBuilder()
1011
.ConfigureFunctionsWorkerDefaults()
12+
.AddConfiguration<RetrieveParticipantDataConfig>(out RetrieveParticipantDataConfig config)
1113
.AddDataServicesHandler()
12-
.AddDataService<ParticipantManagement>(Environment.GetEnvironmentVariable("ParticipantManagementUrl"))
14+
.AddDataService<ParticipantManagement>(config.ParticipantManagementUrl)
1315
.Build()
1416
.ConfigureServices(services =>
1517
{

application/CohortManager/src/Functions/CohortDistributionServices/RetrieveParticipantData/RetrieveParticipantData.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ namespace NHS.CohortManager.CohortDistributionService;
1010
using System.Text;
1111
using System.Text.Json;
1212
using DataServices.Client;
13+
using Microsoft.Extensions.Options;
14+
using NHS.Screening.RetrieveParticipantData;
1315

1416
public class RetrieveParticipantData
1517
{
@@ -19,18 +21,20 @@ public class RetrieveParticipantData
1921
private readonly ICreateParticipant _createParticipant;
2022
private readonly IExceptionHandler _exceptionHandler;
2123
private readonly IDataServiceClient<ParticipantManagement> _participantManagementClient;
24+
private readonly RetrieveParticipantDataConfig _config;
2225

2326
public RetrieveParticipantData(ICreateResponse createResponse, ILogger<RetrieveParticipantData> logger,
2427
IDataServiceClient<ParticipantManagement> participantManagementClient,
2528
ICreateParticipant createParticipant, IExceptionHandler exceptionHandler,
26-
ICallFunction callFunction)
29+
ICallFunction callFunction, IOptions<RetrieveParticipantDataConfig> retrieveParticipantDataConfig)
2730
{
2831
_createResponse = createResponse;
2932
_logger = logger;
3033
_callFunction = callFunction;
3134
_createParticipant = createParticipant;
3235
_exceptionHandler = exceptionHandler;
3336
_participantManagementClient = participantManagementClient;
37+
_config = retrieveParticipantDataConfig.Value;
3438
}
3539

3640
[Function("RetrieveParticipantData")]
@@ -68,7 +72,7 @@ public async Task<HttpResponseData> RunAsync([HttpTrigger(AuthorizationLevel.Ano
6872
{"Id", requestBody.NhsNumber }
6973
};
7074

71-
var demographicDataJson = await _callFunction.SendGet(Environment.GetEnvironmentVariable("DemographicDataFunctionURL"), demographicFunctionParams);
75+
var demographicDataJson = await _callFunction.SendGet(_config.DemographicDataFunctionURL, demographicFunctionParams);
7276

7377
var demographicData = JsonSerializer.Deserialize<Demographic>(demographicDataJson);
7478
if (demographicData == null)

0 commit comments

Comments
 (0)