Skip to content
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
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
Expand Up @@ -6,6 +6,7 @@ namespace NHS.Screening.ReceiveCaasFile;
using Data.Database;
using DataServices.Client;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using Microsoft.IdentityModel.Protocols.Configuration;
using Model;

Expand All @@ -21,6 +22,7 @@ public class ProcessCaasFile : IProcessCaasFile
private readonly IRecordsProcessedTracker _recordsProcessTracker;
private readonly IValidateDates _validateDates;
private readonly ICallFunction _callFunction;
private readonly ReceiveCaasFileConfig _config;
private readonly string DemographicURI;
private readonly string AddParticipantQueueName;
private readonly string UpdateParticipantQueueName;
Expand All @@ -36,7 +38,8 @@ public ProcessCaasFile(
IDataServiceClient<ParticipantDemographic> participantDemographic,
IRecordsProcessedTracker recordsProcessedTracker,
IValidateDates validateDates,
ICallFunction callFunction
ICallFunction callFunction,
IOptions<ReceiveCaasFileConfig> receiveCaasFileConfig
)
{
_logger = logger;
Expand All @@ -49,10 +52,11 @@ ICallFunction callFunction
_recordsProcessTracker = recordsProcessedTracker;
_validateDates = validateDates;
_callFunction = callFunction;
_config = receiveCaasFileConfig.Value;

DemographicURI = Environment.GetEnvironmentVariable("DemographicURI");
AddParticipantQueueName = Environment.GetEnvironmentVariable("AddQueueName");
UpdateParticipantQueueName = Environment.GetEnvironmentVariable("UpdateQueueName");
DemographicURI = _config.DemographicURI;
AddParticipantQueueName = _config.AddQueueName;
UpdateParticipantQueueName = _config.UpdateQueueName;


if (string.IsNullOrEmpty(DemographicURI) || string.IsNullOrEmpty(AddParticipantQueueName) || string.IsNullOrEmpty(UpdateParticipantQueueName))
Expand Down Expand Up @@ -207,7 +211,7 @@ private async Task RemoveParticipant(BasicParticipantCsvRecord basicParticipantC
{
_logger.LogInformation("AllowDeleteRecords flag is true, delete record sent to RemoveParticipant function.");
var json = JsonSerializer.Serialize(basicParticipantCsvRecord);
await _callFunction.SendPost(Environment.GetEnvironmentVariable("PMSRemoveParticipant"), json);
await _callFunction.SendPost(_config.PMSRemoveParticipant, json);
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@
try
{
var host = new HostBuilder()
.AddConfiguration<ReceiveCaasFileConfig>(out ReceiveCaasFileConfig config)
.AddDataServicesHandler()
.AddDataService<ParticipantDemographic>(Environment.GetEnvironmentVariable("DemographicDataServiceURL"))
.AddCachedDataService<ScreeningLkp>(Environment.GetEnvironmentVariable("ScreeningLkpDataServiceURL"))
.AddDataService<ParticipantDemographic>(config.DemographicDataServiceURL)
.AddCachedDataService<ScreeningLkp>(config.ScreeningLkpDataServiceURL)
.Build()
.ConfigureFunctionsWebApplication()

Expand All @@ -37,7 +38,7 @@
services.AddScoped<IRecordsProcessedTracker, RecordsProcessedTracker>(); //Do not change the lifetime of this.
services.AddHttpClient<ICheckDemographic, CheckDemographic>(client =>
{
client.BaseAddress = new Uri(Environment.GetEnvironmentVariable("DemographicURI"));
client.BaseAddress = new Uri(config.DemographicURI);
});
services.AddScoped<IValidateDates, ValidateDates>();
services.AddScoped<IQueueClientFactory, QueueClientFactory>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,29 @@ namespace NHS.Screening.ReceiveCaasFile;
using System.Threading.Tasks;
using Common.Interfaces;
using DataServices.Client;
using Microsoft.Extensions.Options;

public class ReceiveCaasFile
{
private readonly ILogger<ReceiveCaasFile> _logger;
private readonly IReceiveCaasFileHelper _receiveCaasFileHelper;
private readonly IProcessCaasFile _processCaasFile;
private readonly IDataServiceClient<ScreeningLkp> _screeningLkpClient;
private readonly ReceiveCaasFileConfig _config;

public ReceiveCaasFile(
ILogger<ReceiveCaasFile> logger,
IReceiveCaasFileHelper receiveCaasFileHelper,
IProcessCaasFile processCaasFile,
IDataServiceClient<ScreeningLkp> screeningLkpClient
IDataServiceClient<ScreeningLkp> screeningLkpClient,
IOptions<ReceiveCaasFileConfig> receiveCaasFileConfig
)
{
_logger = logger;
_receiveCaasFileHelper = receiveCaasFileHelper;
_processCaasFile = processCaasFile;
_screeningLkpClient = screeningLkpClient;
_config = receiveCaasFileConfig.Value;
}

[Function(nameof(ReceiveCaasFile))]
Expand All @@ -36,7 +40,7 @@ public async Task Run([BlobTrigger("inbound/{name}", Connection = "caasfolder_ST
var ErrorOccurred = false;
var downloadFilePath = string.Empty;
// for larger batches use size of 5000 - this works the best
int.TryParse(Environment.GetEnvironmentVariable("BatchSize"), out var BatchSize);
var BatchSize = _config.BatchSize;
try
{
FileNameParser fileNameParser = new FileNameParser(name);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
namespace NHS.Screening.ReceiveCaasFile;

using System.ComponentModel.DataAnnotations;

public class ReceiveCaasFileConfig
{
[Required]
public string DemographicDataServiceURL {get; set;}
[Required]
public string ScreeningLkpDataServiceURL {get; set;}
[Required]
public string DemographicURI {get; set;}
[Required]
public int BatchSize {get; set;}
[Required]
public string AddQueueName {get; set;}
[Required]
public string UpdateQueueName {get; set;}
[Required]
public string PMSRemoveParticipant {get; set;}
}
Loading