Skip to content

Commit

Permalink
Merge branch 'main' into remove-unused-files
Browse files Browse the repository at this point in the history
  • Loading branch information
arlowatts committed Aug 30, 2024
2 parents 47a66c6 + fe3db0b commit a377009
Show file tree
Hide file tree
Showing 107 changed files with 696 additions and 317 deletions.
5 changes: 1 addition & 4 deletions Services/ClaimService/src/ClaimService.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,10 @@
<PropertyGroup>
<RootNamespace>Health.PharmaNet.ClaimService</RootNamespace>
<DocumentationFile>bin\$(Configuration)\$(TargetFramework)\$(MSBuildThisFileName).xml</DocumentationFile>
</PropertyGroup>
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
</PropertyGroup>
<PropertyGroup Condition=" '$(RunConfiguration)' == 'ClaimService' " />
<ItemGroup>
<Content Include=".vscode\launch.json" />
<Content Include="health-check.sh" CopyToOutputDirectory="Always" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\Common\src\Common.csproj" />
Expand Down
23 changes: 20 additions & 3 deletions Services/ClaimService/src/Controllers/ClaimController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
//-------------------------------------------------------------------------

namespace Health.PharmaNet.Controllers
{
using System.Security.Claims;
Expand All @@ -33,10 +34,9 @@ namespace Health.PharmaNet.Controllers
using Microsoft.Extensions.Logging;

/// <summary>
/// The MedicationService controller.
/// The Claim service controller.
/// </summary>
[ApiVersion("1.0")]
[Route("/api/v{version:apiVersion}/Claim/")]
[ApiController]
public class ClaimController : ServiceBaseController
{
Expand All @@ -61,11 +61,12 @@ public ClaimController(
}

/// <summary>
/// The Patient is a citizen as patient resource and manages demographics, addresses, and identifiers.
/// Execute a transaction on this service.
/// </summary>
/// <returns>A DocumentReference response as Json.</returns>
/// <response code="200">Returns Ok when the transaction went through.</response>
/// <response code="401">Authorization error, returns JSON describing the error.</response>
[Route("/api/v{version:apiVersion}/Claim/")]
[HttpPost]
[Produces("application/fhir+json")]
[ProducesResponseType(StatusCodes.Status200OK)]
Expand All @@ -74,5 +75,21 @@ public async Task<ActionResult<DocumentReference>> Claim()
{
return await this.PharmanetRequest().ConfigureAwait(true);
}

/// <summary>
/// Execute a health check on this service.
/// </summary>
/// <returns>A DocumentReference response as Json.</returns>
/// <response code="200">Returns Ok when the transaction went through.</response>
/// <response code="401">Authorization error, returns JSON describing the error.</response>
[Route("/healthz")]
[HttpPost]
[Produces("application/fhir+json")]
[ProducesResponseType(StatusCodes.Status200OK)]
[Authorize(Policy = FhirScopesPolicy.Access)]
public async Task<ActionResult<DocumentReference>> HealthCheck()
{
return await this.PharmanetRequest(true).ConfigureAwait(true);
}
}
}
1 change: 1 addition & 0 deletions Services/ClaimService/src/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,7 @@
},
"PharmanetProxy": {
"Endpoint": "{pharmanet_endpoint}",
"HealthCheckEndpoint": "{health check endpoint}",
"Password": "{password}",
"Username": "{username}",
"ClientCertificatePath": "",
Expand Down
3 changes: 3 additions & 0 deletions Services/ClaimService/src/health-check.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash

./health-check-common.sh 'TVNIfF5+XCZ8fHx8fHx8WlBOfDB8UHwNWlpafFRBQw1aWlp8VERVDVpDQXx8fDAxDQo='
1 change: 1 addition & 0 deletions Services/Common/src/Common.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
<Content Include="Swagger\ConfigureSwaggerGenOptions.cs" />
<Content Include="obj\project.assets.json" />
<Content Include="Http\HttpRequestExtension.cs" />
<Content Include="health-check-common.sh" CopyToOutputDirectory="Always" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\HL7-dotnetcore\src\HL7-dotnetcore.csproj" />
Expand Down
4 changes: 2 additions & 2 deletions Services/Common/src/Controllers/ServiceBaseController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public ServiceBaseController(
// [ProducesResponseType(StatusCodes.Status200OK)]
// [Authorize(Policy = FhirScopesPolicy.Access)]
[Authorize]
protected async Task<ActionResult<DocumentReference>> PharmanetRequest()
protected async Task<ActionResult<DocumentReference>> PharmanetRequest(bool isHealthCheck = false)
{
Logger.LogInformation(this.logger, $"ServiceBaseController.PharmanetRequest start");

Expand Down Expand Up @@ -154,7 +154,7 @@ protected async Task<ActionResult<DocumentReference>> PharmanetRequest()
}
Logger.LogInformation(this.logger, $"Trace ID: {traceId}: ServiceBaseController.PharmanetRequest: Authorization completed. Submitting request...");

RequestResult<DocumentReference> response = await this.service.SubmitRequest(fhirRequest, traceId + "").ConfigureAwait(true);
RequestResult<DocumentReference> response = await this.service.SubmitRequest(fhirRequest, traceId + "", isHealthCheck).ConfigureAwait(true);
if (response.IsSuccessStatusCode == false)
{
Logger.LogError(this.logger, $"An Error occurred while invoking Pharmanet endpoint: {response.ErrorMessage}");
Expand Down
3 changes: 2 additions & 1 deletion Services/Common/src/Delegates/IPharmanetDelegate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ public interface IPharmanetDelegate
/// The Pharmanet Delegate, which communicates directly to the Pharmanet proxy service.
/// </summary>
/// <param name="request">A PharmanetMessageModel instance containing the HL7v2 request message.</param>
/// <param name="isHealthCheck">A boolean indicating if this request is a health check or a transaction.</param>
/// <returns>A PharmanetMessageModel as response.</returns>
public Task<RequestResult<PharmanetMessageModel>> SubmitRequest(PharmanetMessageModel request);
public Task<RequestResult<PharmanetMessageModel>> SubmitRequest(PharmanetMessageModel request, bool isHealthCheck);
}
}
5 changes: 3 additions & 2 deletions Services/Common/src/Delegates/PharmanetDelegate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,9 @@ public PharmanetDelegate(HttpClient client, ILogger<PharmanetDelegate> logger, I
/// Submit a PharmanetMessage to Pharmanet System.
/// </summary>
/// <param name="request">The PharmanetMessage request containing HL7v2 base 64 payload.</param>
/// <param name="isHealthCheck">A boolean indicating if this request is a health check or a transaction.</param>
/// <returns>A PharmanetMessage response.</returns>
public async Task<RequestResult<PharmanetMessageModel>> SubmitRequest(PharmanetMessageModel request)
public async Task<RequestResult<PharmanetMessageModel>> SubmitRequest(PharmanetMessageModel request, bool isHealthCheck)
{
Logger.LogInformation(this.logger, $"Transaction UUID: {request.TransactionId}: PharmanetDelegate.SubmitRequest start");

Expand All @@ -109,7 +110,7 @@ public async Task<RequestResult<PharmanetMessageModel>> SubmitRequest(PharmanetM

try
{
Uri delegateUri = new Uri(this.pharmanetDelegateConfig.Endpoint);
Uri delegateUri = new Uri(isHealthCheck ? this.pharmanetDelegateConfig.HealthCheckEndpoint : this.pharmanetDelegateConfig.Endpoint);

Logger.LogInformation(this.logger, $"Transaction UUID: {request.TransactionId}: PharmanetDelegate.SubmitRequest: Sending message to PharmaNet...");
// This log statement logs sensitive health information - use it only for debugging in a development environment
Expand Down
8 changes: 7 additions & 1 deletion Services/Common/src/Models/PharmanetDelegateConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ public class PharmanetDelegateConfig
[JsonPropertyName("Endpoint")]
public string Endpoint { get; set; } = string.Empty;

/// <summary>
/// Gets or sets the endpoint path for the service's health checks.
/// </summary>
[JsonPropertyName("HealthCheckEndpoint")]
public string HealthCheckEndpoint { get; set; } = string.Empty;

/// <summary>
/// Gets or sets the username to use for authentication.
/// </summary>
Expand All @@ -63,4 +69,4 @@ public class PharmanetDelegateConfig
[JsonPropertyName("ClientCertificatePassword")]
public string ClientCertificatePassword { get; set; } = string.Empty;
}
}
}
5 changes: 3 additions & 2 deletions Services/Common/src/Services/IPharmanetService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ public interface IPharmanetService
/// </summary>
/// <param name="request">An HL7 FHIR DocumentReference request containing HL7v2 payload.</param>
/// <param name="traceId">The value used to track messages from API Gateway.</param>
/// <param name="isHealthCheck">A boolean indicating if this request is a health check or a transaction.</param>
/// <returns>Returns a DocumentReference response.</returns>
Task<RequestResult<DocumentReference>> SubmitRequest(DocumentReference request, string traceId);
Task<RequestResult<DocumentReference>> SubmitRequest(DocumentReference request, string traceId, bool isHealthCheck);
}
}
}
5 changes: 3 additions & 2 deletions Services/Common/src/Services/PharmanetService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,9 @@ public PharmanetService(
/// </summary>
/// <param name="request">The DocumentReference to be submitted.</param>
/// <param name="traceId">The value used to track messages from API Gateway.</param>
/// <param name="isHealthCheck">A boolean indicating if this request is a health check or a transaction.</param>
/// <returns>Returns a DocumentReference containing the response from PharmaNet.</returns>
public async Task<RequestResult<DocumentReference>> SubmitRequest(DocumentReference request, string traceId)
public async Task<RequestResult<DocumentReference>> SubmitRequest(DocumentReference request, string traceId, bool isHealthCheck)
{
Logger.LogInformation(this.logger, $"Trace ID: {traceId}: PharmanetService.SubmitRequest start");

Expand All @@ -73,7 +74,7 @@ public async Task<RequestResult<DocumentReference>> SubmitRequest(DocumentRefere
// This log statement logs sensitive health information - use it only for debugging in a development environment
// Logger.LogDebug(this.logger, $"Pharmanet Request: {requestMessage.Hl7Message}");

RequestResult<PharmanetMessageModel> result = await this.pharmanetDelegate.SubmitRequest(requestMessage).ConfigureAwait(true);
RequestResult<PharmanetMessageModel> result = await this.pharmanetDelegate.SubmitRequest(requestMessage, isHealthCheck).ConfigureAwait(true);

response.StatusCode = result.StatusCode;
response.ErrorMessage = result.ErrorMessage;
Expand Down
44 changes: 44 additions & 0 deletions Services/Common/src/health-check-common.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/bin/bash

# get the payload from the script argument
payload=$1

# select the correct keycloak token url by environment
if [ $ASPNETCORE_ENVIRONMENT = 'dev' ]; then
tokenEndpoint='https://common-logon-dev.hlth.gov.bc.ca/auth/realms/v2_pos/protocol/openid-connect/token'

elif [ $ASPNETCORE_ENVIRONMENT = 'tr1' ]; then
tokenEndpoint='https://common-logon-test.hlth.gov.bc.ca/auth/realms/moh_applications/protocol/openid-connect/token'

elif [ $ASPNETCORE_ENVIRONMENT = 'vs1' ]; then
tokenEndpoint='https://common-logon-test.hlth.gov.bc.ca/auth/realms/moh_applications/protocol/openid-connect/token'

elif [ $ASPNETCORE_ENVIRONMENT = 'vc2' ]; then
tokenEndpoint='https://common-logon-test.hlth.gov.bc.ca/auth/realms/moh_applications/protocol/openid-connect/token'

elif [ $ASPNETCORE_ENVIRONMENT = 'vc1' ]; then
tokenEndpoint='https://common-logon-test.hlth.gov.bc.ca/auth/realms/moh_applications/protocol/openid-connect/token'

elif [ $ASPNETCORE_ENVIRONMENT = 'prd' ]; then
tokenEndpoint='https://common-logon.hlth.gov.bc.ca/auth/realms/moh_applications/protocol/openid-connect/token'

else
exit 1
fi

# request the access token from keycloak
accessToken=$(curl --silent --location --request POST ${tokenEndpoint} \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'grant_type=client_credentials' \
--data-urlencode "client_id=${HEALTH_CHECK_CLIENT_ID}" \
--data-urlencode 'audience=pharmanet' \
--data-urlencode 'scope=openid system/*.write system/*.read system/Claim.read system/Claim.write system/Consent.read system/Consent.write system/Location.read system/Medication.read system/MedicationDispense.read system/MedicationDispense.write system/MedicationRequest.read system/MedicationRequest.write system/MedicationStatement.read system/Patient.read system/Patient.write system/Practitioner.read' \
--data-urlencode "client_secret=${HEALTH_CHECK_CLIENT_SECRET}" \
| sed 's/.*"access_token":"\([0-9a-zA-Z_\-]*\.[0-9a-zA-Z_\-]*\.[0-9a-zA-Z_\-]*\)".*/\1/')

# submit a transaction to the current service
curl --silent --request POST "http://127.0.0.1:8080/healthz" \
--header 'Content-Type: application/json' \
--header "Authorization: Bearer ${accessToken}" \
--header 'Kong-Request-ID: health-check' \
--data "{'resourceType':'DocumentReference','status':'current','date':'$(date --iso-8601=seconds)','content':[{'attachment':{'contentType':'x-application/hl7-v2+er7','data':'${payload}'}}]}"
5 changes: 1 addition & 4 deletions Services/ConsentService/src/ConsentService.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,10 @@
<PropertyGroup>
<RootNamespace>Health.PharmaNet.ConsentService</RootNamespace>
<DocumentationFile>bin\$(Configuration)\$(TargetFramework)\$(MSBuildThisFileName).xml</DocumentationFile>
</PropertyGroup>
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
</PropertyGroup>
<PropertyGroup Condition=" '$(RunConfiguration)' == 'ConsentService' " />
<ItemGroup>
<Content Include=".vscode\launch.json" />
<Content Include="health-check.sh" CopyToOutputDirectory="Always" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\Common\src\Common.csproj" />
Expand Down
22 changes: 19 additions & 3 deletions Services/ConsentService/src/Controllers/ConsentController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,9 @@ namespace Health.PharmaNet.Controllers
using Microsoft.Extensions.Logging;

/// <summary>
/// The MedicationService controller.
/// The Consent service controller.
/// </summary>
[ApiVersion("1.0")]
[Route("/api/v{version:apiVersion}/Consent/")]
[ApiController]
public class ConsentController : ServiceBaseController
{
Expand All @@ -62,11 +61,12 @@ public ConsentController(
}

/// <summary>
/// The ProtectiveKeyword acts as a lock; only a practitioner with the protective word can unlock the record to view and/or update its contents. ... Access to PharmaNet is strictly controlled.
/// Execute a transaction on this service.
/// </summary>
/// <returns>A DocumentReference response as Json.</returns>
/// <response code="200">Returns Ok when the transaction went through.</response>
/// <response code="401">Authorization error, returns JSON describing the error.</response>
[Route("/api/v{version:apiVersion}/Consent/")]
[HttpPost]
[Produces("application/fhir+json")]
[ProducesResponseType(StatusCodes.Status200OK)]
Expand All @@ -75,5 +75,21 @@ public async Task<ActionResult<DocumentReference>> Consent()
{
return await this.PharmanetRequest().ConfigureAwait(true);
}

/// <summary>
/// Execute a health check on this service.
/// </summary>
/// <returns>A DocumentReference response as Json.</returns>
/// <response code="200">Returns Ok when the transaction went through.</response>
/// <response code="401">Authorization error, returns JSON describing the error.</response>
[Route("/healthz")]
[HttpPost]
[Produces("application/fhir+json")]
[ProducesResponseType(StatusCodes.Status200OK)]
[Authorize(Policy = FhirScopesPolicy.Access)]
public async Task<ActionResult<DocumentReference>> HealthCheck()
{
return await this.PharmanetRequest(true).ConfigureAwait(true);
}
}
}
1 change: 1 addition & 0 deletions Services/ConsentService/src/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
},
"PharmanetProxy": {
"Endpoint": "{pharmanet_endpoint}",
"HealthCheckEndpoint": "{health check endpoint}",
"Password": "{password}",
"Username": "{username}",
"ClientCertificatePath": "",
Expand Down
3 changes: 3 additions & 0 deletions Services/ConsentService/src/health-check.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash

./health-check-common.sh 'TVNIfF5+XCZ8fHx8fHx8WlBOfDB8UHwNWlpafFRDUA1aQ0F8fHwwMA0K'
23 changes: 20 additions & 3 deletions Services/LocationService/src/Controllers/LocationController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
//-------------------------------------------------------------------------

namespace Health.PharmaNet.Controllers
{
using System.Security.Claims;
Expand All @@ -33,10 +34,9 @@ namespace Health.PharmaNet.Controllers
using Microsoft.Extensions.Logging;

/// <summary>
/// The MedicationService controller.
/// The Location service controller.
/// </summary>
[ApiVersion("1.0")]
[Route("/api/v{version:apiVersion}/Location/")]
[ApiController]
public class LocationController : ServiceBaseController
{
Expand All @@ -61,11 +61,12 @@ public LocationController(
}

/// <summary>
/// The Patient is a citizen as patient resource and manages demographics, addresses, and identifiers.
/// Execute a transaction on this service.
/// </summary>
/// <returns>A DocumentReference response as Json.</returns>
/// <response code="200">Returns Ok when the transaction went through.</response>
/// <response code="401">Authorization error, returns JSON describing the error.</response>
[Route("/api/v{version:apiVersion}/Location/")]
[HttpPost]
[Produces("application/fhir+json")]
[ProducesResponseType(StatusCodes.Status200OK)]
Expand All @@ -74,5 +75,21 @@ public async Task<ActionResult<DocumentReference>> Location()
{
return await this.PharmanetRequest().ConfigureAwait(true);
}

/// <summary>
/// Execute a health check on this service.
/// </summary>
/// <returns>A DocumentReference response as Json.</returns>
/// <response code="200">Returns Ok when the transaction went through.</response>
/// <response code="401">Authorization error, returns JSON describing the error.</response>
[Route("/healthz")]
[HttpPost]
[Produces("application/fhir+json")]
[ProducesResponseType(StatusCodes.Status200OK)]
[Authorize(Policy = FhirScopesPolicy.Access)]
public async Task<ActionResult<DocumentReference>> HealthCheck()
{
return await this.PharmanetRequest(true).ConfigureAwait(true);
}
}
}
3 changes: 1 addition & 2 deletions Services/LocationService/src/LocationService.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@
<DocumentationFile>bin\$(Configuration)\$(TargetFramework)\$(MSBuildThisFileName).xml</DocumentationFile>
<TargetFramework>net6.0</TargetFramework>
</PropertyGroup>
<PropertyGroup Condition=" '$(RunConfiguration)' == 'LocationService' " />
<ItemGroup>
<Content Include=".vscode\launch.json" />
<Content Include="health-check.sh" CopyToOutputDirectory="Always" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\Common\src\Common.csproj" />
Expand Down
1 change: 1 addition & 0 deletions Services/LocationService/src/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
},
"PharmanetProxy": {
"Endpoint": "{pharmanet_endpoint}",
"HealthCheckEndpoint": "{health check endpoint}",
"Password": "{password}",
"Username": "{username}",
"ClientCertificatePath": "",
Expand Down
3 changes: 3 additions & 0 deletions Services/LocationService/src/health-check.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash

./health-check-common.sh 'TVNIfF5+XCZ8fHx8fHx8WlBOfDB8UHwNWlpafFRJTA1aQ0F8fHwwMA0K'
Loading

0 comments on commit a377009

Please sign in to comment.