Skip to content

Commit

Permalink
feat: DTOSS 5431 create get participant screening profile functions (#55
Browse files Browse the repository at this point in the history
)

* feat: adding two new functions for getting profile data

* feat: minor improvements

* feat: logging improvements

* feat: some corrections and starting unit tests

* feat: adding unit tests for GetParticipantScreeningProfileData

* feat: testing and minor improvements

* feat: adding new funcs to the compose files

* fix: formatting issues

* fix: fixing small unit test issue

* fix: fixing small unit test issue

* fix: fixing small unit test issue

* fix: fixing small unit test issue

* feat: adding datetime format provider

* feat: changing to use host.RunAsync()

* feat: changing to use host.RunAsync()

* fix: unit testing issue

* fix: fixing unit test issue

* feat: updating tables and related code

* fix: fixing type mismatch

* feat: correcting db context

* feat: updating objects according to new data model

* feat: changing mapping function

* fix: build issue

* fix: changing logs to SonarCloud is happy

* feat: changing to find

* fix: changing localhost to 127.0.0.1

* fix: changing localhost to function name

* fix: fixing mac compose file

* fix: fixing syntax issue
  • Loading branch information
SamTyrrellNHS authored Nov 15, 2024
1 parent ca2426c commit a4b3128
Show file tree
Hide file tree
Showing 40 changed files with 1,054 additions and 231 deletions.
32 changes: 32 additions & 0 deletions compose-mac.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,22 @@ services:
- ASPNETCORE_URLS=http://*:6011
- ServiceInsightsDbConnectionString=Server=${DB_CONNECTION},1433;Database=${DB_NAME};User Id=SA;Password=${PASSWORD};TrustServerCertificate=True

get-participant-screening-profile-data:
container_name: get-participant-screening-profile-data
restart: always
build:
context: ./src/
dockerfile: ./BIAnalyticsDataService/GetParticipantScreeningProfileData/Dockerfile
networks:
- app-network
ports:
- "6062:6062"
environment:
- ASPNETCORE_ENVIRONMENT=Development
- FUNCTIONS_WORKER_RUNTIME=dotnet-isolated
- ASPNETCORE_URLS=http://*:6062
- ServiceInsightsDbConnectionString=Server=${DB_CONNECTION},1433;Database=${DB_NAME};User Id=SA;Password=${PASSWORD};TrustServerCertificate=True

# BI Analytics Service
create-participant-screening-episode:
container_name: create-participant-screening-episode
Expand Down Expand Up @@ -142,6 +158,22 @@ services:
- CreateParticipantScreeningProfileUrl=http://create-participant-screening-profile-data:6011/api/CreateParticipantScreeningProfile
- DemographicsServiceUrl=http://get-demographics-data:6080/api/GetDemographicsData

get-participant-screening-profile:
container_name: get-participant-screening-profile
restart: always
build:
context: ./src/
dockerfile: ./BIAnalyticsService/GetParticipantScreeningProfile/Dockerfile
networks:
- app-network
ports:
- "6063:6063"
environment:
- ASPNETCORE_ENVIRONMENT=Development
- FUNCTIONS_WORKER_RUNTIME=dotnet-isolated
- ASPNETCORE_URLS=http://*:6063
- GetProfilesUrl=http://get-participant-screening-profile-data:6062/api/GetParticipantScreeningProfileData

# Demographics Service
get-demographics-data:
container_name: get-demographics-data
Expand Down
28 changes: 28 additions & 0 deletions compose-win.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,20 @@ services:
- ASPNETCORE_URLS=http://*:6011
- ServiceInsightsDbConnectionString=Server=${DB_CONNECTION},1433;Database=${DB_NAME};User Id=SA;Password=${PASSWORD};TrustServerCertificate=True

get-participant-screening-profile-data:
container_name: get-participant-screening-profile-data
network_mode: host
build:
context: ./src/
dockerfile: ./BIAnalyticsDataService/GetParticipantScreeningProfileData/Dockerfile
ports:
- "6062:6062"
environment:
- ASPNETCORE_ENVIRONMENT=Development
- FUNCTIONS_WORKER_RUNTIME=dotnet-isolated
- ASPNETCORE_URLS=http://*:6062
- ServiceInsightsDbConnectionString=Server=${DB_CONNECTION},1433;Database=${DB_NAME};User Id=SA;Password=${PASSWORD};TrustServerCertificate=True

# BI Analytics Service
create-participant-screening-episode:
container_name: create-participant-screening-episode
Expand Down Expand Up @@ -125,6 +139,20 @@ services:
- CreateParticipantScreeningProfileUrl=http://127.0.0.1:6011/api/CreateParticipantScreeningProfile
- DemographicsServiceUrl=http://127.0.0.1:6080/api/GetDemographicsData

get-participant-screening-profile:
container_name: get-participant-screening-profile
network_mode: host
build:
context: ./src/
dockerfile: ./BIAnalyticsService/GetParticipantScreeningProfile/Dockerfile
ports:
- "6063:6063"
environment:
- ASPNETCORE_ENVIRONMENT=Development
- FUNCTIONS_WORKER_RUNTIME=dotnet-isolated
- ASPNETCORE_URLS=http://*:6063
- GetProfilesUrl=http://127.0.0.1:6062/api/GetParticipantScreeningProfileData

# Demographics Service
get-demographics-data:
container_name: get-demographics-data
Expand Down
81 changes: 43 additions & 38 deletions scripts/database/create_tables.sql
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ IF NOT EXISTS
BEGIN
CREATE TABLE REASON_CLOSED_CODE_LKP
(
REASON_CLOSED_CODE_ID BIGINT not null,
REASON_CLOSED_CODE_ID BIGINT not null,
REASON_CLOSED_CODE VARCHAR(50) not null,
REASON_CLOSED_CODE_DESCRIPTION VARCHAR(300) null,
constraint PK_REASON_CLOSED_CODE_LKP primary key (REASON_CLOSED_CODE_ID)
Expand All @@ -152,25 +152,25 @@ BEGIN
CREATE TABLE PARTICIPANT_SCREENING_PROFILE
(
ID BIGINT IDENTITY(1,1) PRIMARY KEY,
NHS_NUMBER NVARCHAR (50) NOT NULL,
SCREENING_NAME VARCHAR(50) NULL,
PRIMARY_CARE_PROVIDER VARCHAR(50) NULL,
PREFERRED_LANGUAGE VARCHAR(50) NULL,
REASON_FOR_REMOVAL VARCHAR(50) NULL,
REASON_FOR_REMOVAL_DT VARCHAR(50) NULL,
NEXT_TEST_DUE_DATE VARCHAR(50) NULL,
NEXT_TEST_DUE_DATE_CALCULATION_METHOD VARCHAR(50) NULL,
PARTICIPANT_SCREENING_STATUS VARCHAR(50) NULL,
SCREENING_CEASED_REASON VARCHAR(50) NULL,
IS_HIGHER_RISK VARCHAR(10) NULL,
IS_HIGHER_RISK_ACTIVE VARCHAR(10) NULL,
HIGHER_RISK_NEXT_TEST_DUE_DATE VARCHAR(50) NULL,
HIGHER_RISK_REFERRAL_REASON_CODE VARCHAR(50) NULL,
HR_REASON_CODE_DESCRIPTION VARCHAR(50) NULL,
DATE_IRRADIATED VARCHAR(50) NULL,
GENE_CODE VARCHAR(50) NULL,
GENE_CODE_DESCRIPTION VARCHAR(50) NULL,
RECORD_INSERT_DATETIME VARCHAR(50) NULL
NHS_NUMBER BIGINT NOT NULL,
SCREENING_NAME VARCHAR(200) NULL,
PRIMARY_CARE_PROVIDER VARCHAR(50) NULL,
PREFERRED_LANGUAGE VARCHAR(50) NULL,
REASON_FOR_REMOVAL VARCHAR(50) NULL,
REASON_FOR_REMOVAL_DT DATE NULL,
NEXT_TEST_DUE_DATE DATE NULL,
NEXT_TEST_DUE_DATE_CALC_METHOD VARCHAR(100) NULL,
PARTICIPANT_SCREENING_STATUS VARCHAR(100) NULL,
SCREENING_CEASED_REASON VARCHAR(100) NULL,
IS_HIGHER_RISK SMALLINT NULL,
IS_HIGHER_RISK_ACTIVE SMALLINT NULL,
HIGHER_RISK_NEXT_TEST_DUE_DATE DATE NULL,
HIGHER_RISK_REFERRAL_REASON_CODE VARCHAR(100) NULL,
HR_REASON_CODE_DESCRIPTION VARCHAR(200) NULL,
DATE_IRRADIATED DATE NULL,
GENE_CODE VARCHAR(100) NULL,
GENE_CODE_DESCRIPTION VARCHAR(200) NULL,
RECORD_INSERT_DATETIME DATETIME NULL
);
END

Expand All @@ -188,24 +188,29 @@ BEGIN
CREATE TABLE PARTICIPANT_SCREENING_EPISODE
(
ID BIGINT IDENTITY(1,1) PRIMARY KEY,
EPISODE_ID NVARCHAR (50) NOT NULL,
SCREENING_NAME VARCHAR(50) NULL,
NHS_NUMBER VARCHAR(50) NULL,
EPISODE_TYPE VARCHAR(50) NULL,
EPISODE_TYPE_DESCRIPTION VARCHAR(50) NULL,
EPISODE_OPEN_DATE VARCHAR(50) NULL,
APPOINTMENT_MADE_FLAG VARCHAR(10) NULL,
FIRST_OFFERED_APPOINTMENT_DATE VARCHAR(50) NULL,
ACTUAL_SCREENING_DATE VARCHAR(50) NULL,
EARLY_RECALL_DATE VARCHAR(50) NULL,
CALL_RECALL_STATUS_AUTHORISED_BY VARCHAR(50) NULL,
END_CODE VARCHAR(50) NULL,
END_CODE_DESCRIPTION VARCHAR(50) NULL,
END_CODE_LAST_UPDATED VARCHAR(50) NULL,
ORGANISATION_CODE VARCHAR(50) NULL,
ORGANISATION_NAME VARCHAR(50) NULL,
BATCH_ID VARCHAR(50) NULL,
RECORD_INSERT_DATETIME VARCHAR(50) NULL
EPISODE_ID BIGINT NOT NULL,
NHS_NUMBER BIGINT NOT NULL,
SCREENING_NAME VARCHAR(200) NULL,
EPISODE_TYPE VARCHAR(50) NULL,
EPISODE_TYPE_DESCRIPTION VARCHAR(300) NULL,
EPISODE_OPEN_DATE DATE NULL,
APPOINTMENT_MADE_FLAG SMALLINT NULL,
FIRST_OFFERED_APPOINTMENT_DATE DATE NULL,
ACTUAL_SCREENING_DATE DATE NULL,
EARLY_RECALL_DATE DATE NULL,
CALL_RECALL_STATUS_AUTHORISED_BY VARCHAR(200) NULL,
END_CODE VARCHAR(50) NULL,
END_CODE_DESCRIPTION VARCHAR(300) NULL,
END_CODE_LAST_UPDATED DATETIME NULL,
REASON_CLOSED_CODE VARCHAR(50) NULL,
REASON_CLOSED_CODE_DESCRIPTION VARCHAR(300) NULL,
FINAL_ACTION_CODE VARCHAR(50) NULL,
FINAL_ACTION_CODE_DESCRIPTION VARCHAR(300) NULL,
END_POINT VARCHAR(200) NULL,
ORGANISATION_CODE VARCHAR(50) NULL,
ORGANISATION_NAME VARCHAR(300) NULL,
BATCH_ID VARCHAR(100) NULL,
RECORD_INSERT_DATETIME DATETIME NULL
);
END

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS installer-env

COPY ./BIAnalyticsDataService/GetParticipantScreeningProfileData /src/dotnet-function-app
COPY ./Shared /Shared
RUN cd /src/dotnet-function-app && \
mkdir -p /home/site/wwwroot && \
dotnet publish *.csproj --output /home/site/wwwroot

# To enable ssh & remote debugging on app service change the base image to the one below
# FROM mcr.microsoft.com/azure-functions/dotnet-isolated:4-dotnet-isolated8.0-appservice
FROM mcr.microsoft.com/azure-functions/dotnet-isolated:4-dotnet-isolated8.0
ENV AzureWebJobsScriptRoot=/home/site/wwwroot \
AzureFunctionsJobHost__Logging__Console__IsEnabled=true

COPY --from=installer-env ["/home/site/wwwroot", "/home/site/wwwroot"]
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
using System.Net;
using Microsoft.Azure.Functions.Worker;
using Microsoft.Azure.Functions.Worker.Http;
using Microsoft.Extensions.Logging;
using System.Text;
using System.Text.Json;
using System.Globalization;
using NHS.ServiceInsights.Data;
using NHS.ServiceInsights.Model;

namespace NHS.ServiceInsights.BIAnalyticsDataService;

public class GetParticipantScreeningProfileData
{
private readonly ILogger<GetParticipantScreeningProfileData> _logger;

private readonly IParticipantScreeningProfileRepository _participantScreeningProfileRepository;

public GetParticipantScreeningProfileData(ILogger<GetParticipantScreeningProfileData> logger, IParticipantScreeningProfileRepository participantScreeningProfileRepository)
{
_logger = logger;
_participantScreeningProfileRepository = participantScreeningProfileRepository;
}

[Function("GetParticipantScreeningProfileData")]
public async Task<HttpResponseData> Run([HttpTrigger(AuthorizationLevel.Anonymous, "get")] HttpRequestData req)
{
int page = int.Parse(req.Query["page"]);
int pageSize = int.Parse(req.Query["pageSize"]);
DateTime startDate = DateTime.Parse(req.Query["startDate"], CultureInfo.InvariantCulture);
DateTime endDate = DateTime.Parse(req.Query["endDate"], CultureInfo.InvariantCulture);

var numberOfRowsToSkip = (page - 1) * pageSize;

try
{
ProfilesDataPage result = await _participantScreeningProfileRepository.GetParticipantProfile(page, pageSize, startDate, endDate, numberOfRowsToSkip);
if (result.Profiles.Count == 0)
{
_logger.LogInformation("GetParticipantScreeningProfileData: Could not find any participant profiles.");
return req.CreateResponse(HttpStatusCode.NotFound);
}

_logger.LogInformation("GetParticipantScreeningProfileData: Participant profiles found successfully.");

var response = req.CreateResponse(HttpStatusCode.OK);
response.Headers.Add("Content-Type", "application/json");
await JsonSerializer.SerializeAsync(response.Body, result);
return response;
}
catch (Exception ex)
{
_logger.LogError(ex, "GetParticipantScreeningProfileData: Failed to get participant profiles from the database.\nException: {Message}", ex.Message);
return req.CreateResponse(HttpStatusCode.InternalServerError);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<AzureFunctionsVersion>v4</AzureFunctionsVersion>
<OutputType>Exe</OutputType>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Azure.Functions.Worker" Version="1.19.0" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Http" Version="3.0.13" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Sdk" Version="1.15.1" />
</ItemGroup>
<ItemGroup>
<None Update="host.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="local.settings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<CopyToPublishDirectory>Never</CopyToPublishDirectory>
</None>
</ItemGroup>
<ItemGroup>
<Using Include="System.Threading.ExecutionContext" Alias="ExecutionContext" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\Shared\Model\Model.csproj" />
<ProjectReference Include="..\..\Shared\Data\Data.csproj" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using NHS.ServiceInsights.Data;

var host = new HostBuilder()
.ConfigureFunctionsWorkerDefaults()
.ConfigureServices(services =>
{
services.AddScoped<IParticipantScreeningProfileRepository, ParticipantScreeningProfileRepository>();
services.AddDbContext<ServiceInsightsDbContext>(
options => options.UseSqlServer(Environment.GetEnvironmentVariable("ServiceInsightsDbConnectionString")));
})
.Build();
await host.RunAsync();
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"profiles": {
"GetEpisode": {
"commandName": "Project",
"commandLineArgs": "--port 7208",
"launchBrowser": false
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"version": "2.0",
"logging": {
"applicationInsights": {
"samplingSettings": {
"isEnabled": true,
"excludedTypes": "Request"
},
"enableLiveMetricsFilters": true
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"IsEncrypted": false,
"Values": {
"AzureWebJobsStorage": "UseDevelopmentStorage=true",
"FUNCTIONS_WORKER_RUNTIME": "dotnet-isolated",
"ServiceInsightsDbConnectionString": "YOUR_CONNECTION_STRING"
},
"Host": {
"LocalHttpPort": 6062
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -78,22 +78,22 @@ private async Task SendToCreateParticipantScreeningEpisodeAsync(Episode episode)
{
EpisodeId = episode.EpisodeId,
ScreeningName = episode.ScreeningId.ToString(),
NhsNumber = episode.NhsNumber.ToString(),
NhsNumber = episode.NhsNumber,
EpisodeType = episode.EpisodeTypeId.ToString(),
EpisodeTypeDescription = String.Empty,
EpisodeOpenDate = episode.EpisodeOpenDate.ToString(),
AppointmentMadeFlag = episode.AppointmentMadeFlag.ToString(),
FirstOfferedAppointmentDate = episode.FirstOfferedAppointmentDate.ToString(),
ActualScreeningDate = episode.ActualScreeningDate.ToString(),
EarlyRecallDate = episode.EarlyRecallDate.ToString(),
EpisodeOpenDate = episode.EpisodeOpenDate,
AppointmentMadeFlag = episode.AppointmentMadeFlag,
FirstOfferedAppointmentDate = episode.FirstOfferedAppointmentDate,
ActualScreeningDate = episode.ActualScreeningDate,
EarlyRecallDate = episode.EarlyRecallDate,
CallRecallStatusAuthorisedBy = episode.CallRecallStatusAuthorisedBy,
EndCode = episode.EndCodeId.ToString(),
EndCodeDescription = String.Empty,
EndCodeLastUpdated = episode.EndCodeLastUpdated.ToString(),
EndCodeLastUpdated = episode.EndCodeLastUpdated,
OrganisationCode = episode.OrganisationId.ToString(),
OrganisationName = String.Empty,
BatchId = episode.BatchId,
RecordInsertDatetime = DateTime.Now.ToString()
RecordInsertDatetime = DateTime.Now
};

var screeningEpisodeUrl = Environment.GetEnvironmentVariable("CreateParticipantScreeningEpisodeUrl");
Expand Down
Loading

0 comments on commit a4b3128

Please sign in to comment.