diff --git a/Services/Common/src/Controllers/ServiceBaseController.cs b/Services/Common/src/Controllers/ServiceBaseController.cs index 7fcdf26..9629732 100644 --- a/Services/Common/src/Controllers/ServiceBaseController.cs +++ b/Services/Common/src/Controllers/ServiceBaseController.cs @@ -117,7 +117,7 @@ protected async Task> PharmanetRequest() ClaimsPrincipal? user = this.HttpContext!.User; - var traceId = this.Request.Headers.TryGetValue("Kong-Request-ID", out var value) ? value.SingleOrDefault() : null; + var traceId = this.Request.Headers.TryGetValue("Kong-Request-ID", out var value) ? value.FirstOrDefault() : ""; Logger.LogInformation(this.logger, $"Trace ID: {traceId}: ServiceBaseController.PharmanetRequest. Extracted Kong-Request-ID header as the Trace ID."); string jsonString = await this.Request.GetRawBodyStringAsync().ConfigureAwait(true); @@ -140,6 +140,8 @@ protected async Task> PharmanetRequest() return this.StatusCode((int)HttpStatusCode.BadRequest, ex.Message); } + HL7.Dotnetcore.Segment? mshSegment = hl7v2Message.Segments("MSH").FirstOrDefault(); + Logger.LogInformation(this.logger, $"Trace ID: {traceId}: ServiceBaseController.PharmanetRequest: Message MSH: {mshSegment?.Value}"); Logger.LogInformation(this.logger, $"Trace ID: {traceId}: ServiceBaseController.PharmanetRequest: Authorizing..."); AuthorizationResult authResult = await this.authorizationService.AuthorizeAsync( @@ -152,7 +154,7 @@ protected async Task> PharmanetRequest() } Logger.LogInformation(this.logger, $"Trace ID: {traceId}: ServiceBaseController.PharmanetRequest: Authorization completed. Submitting request..."); - RequestResult response = await this.service.SubmitRequest(fhirRequest).ConfigureAwait(true); + RequestResult response = await this.service.SubmitRequest(fhirRequest, traceId + "").ConfigureAwait(true); if (response.IsSuccessStatusCode == false) { Logger.LogError(this.logger, $"An Error occurred while invoking Pharmanet endpoint: {response.ErrorMessage}"); diff --git a/Services/Common/src/Services/IPharmanetService.cs b/Services/Common/src/Services/IPharmanetService.cs index 1c6c280..26d6906 100644 --- a/Services/Common/src/Services/IPharmanetService.cs +++ b/Services/Common/src/Services/IPharmanetService.cs @@ -28,7 +28,8 @@ public interface IPharmanetService /// Submit request of type DocumentReference containing HL7v2 message to PharmaNet. /// /// An HL7 FHIR DocumentReference request containing HL7v2 payload. + /// The value used to track messages from API Gateway. /// Returns a DocumentReference response. - Task> SubmitRequest(DocumentReference request); + Task> SubmitRequest(DocumentReference request, string traceId); } } \ No newline at end of file diff --git a/Services/Common/src/Services/PharmanetService.cs b/Services/Common/src/Services/PharmanetService.cs index 1453795..ba09cb3 100644 --- a/Services/Common/src/Services/PharmanetService.cs +++ b/Services/Common/src/Services/PharmanetService.cs @@ -56,16 +56,17 @@ public PharmanetService( /// Submit Request to Pharmanet. /// /// The DocumentReference to be submitted. + /// The value used to track messages from API Gateway. /// Returns a DocumentReference containing the response from PharmaNet. - public async Task> SubmitRequest(DocumentReference request) + public async Task> SubmitRequest(DocumentReference request, string traceId) { - Logger.LogInformation(this.logger, $"PharmanetService.SubmitRequest start"); + Logger.LogInformation(this.logger, $"Trace ID: {traceId}: PharmanetService.SubmitRequest start"); RequestResult response = new RequestResult(); bool base64Encode = this.configuration.GetSection(PharmanetDelegateConfig.ConfigurationSectionKey).GetValue("Base64EncodeHl7Message"); - Logger.LogInformation(this.logger, $"PharmanetService.SubmitRequest: UUID exists in FHIR? {request.MasterIdentifier != null} "); + Logger.LogInformation(this.logger, $"Trace ID: {traceId}: PharmanetService.SubmitRequest: UUID exists in FHIR? {request.MasterIdentifier != null} "); PharmanetMessageModel requestMessage = PharmanetDelegateAdapter.ToPharmanetMessageModel(request, base64Encode); - Logger.LogInformation(this.logger, $"Transaction UUID: {requestMessage.TransactionId}: PharmanetService.SubmitRequest: PharmanetMessageModel created."); + Logger.LogInformation(this.logger, $"Trace ID: {traceId}: Transaction UUID: {requestMessage.TransactionId}: PharmanetService.SubmitRequest: PharmanetMessageModel created."); try {