Skip to content

Commit 0b9a793

Browse files
Merge branch 'dev' into dependabot/npm_and_yarn/Web/Admin.UI/version_updates-acfae90e01
2 parents 844de6d + d3e507a commit 0b9a793

4 files changed

Lines changed: 50 additions & 30 deletions

File tree

DotNet/Admin.BFF/Application/Commands/Integration/KafkaConsumerService.cs

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -41,30 +41,21 @@ public void StartConsumer(string groupId, List<string> topics, string reportTrac
4141
string traceId = string.Empty;
4242
string errorMessage = null;
4343

44-
if (consumeResult.Message.Headers.TryGetLastBytes("X-Correlation-Id",
45-
out var correlationHeader))
44+
if (consumeResult.Message.Headers.TryGetLastBytes("X-Correlation-Id", out var correlationHeader))
4645
{
4746
correlationId = System.Text.Encoding.UTF8.GetString(correlationHeader);
4847

4948
// read the exceptions
50-
if (consumeResult.Message.Headers.TryGetLastBytes("X-Exception-Message",
51-
out var exceptionMessage))
52-
{
53-
errorMessage = System.Text.Encoding.UTF8.GetString(exceptionMessage);
54-
}
55-
56-
else if (consumeResult.Message.Headers.TryGetLastBytes("X-Retry-Exception-Message",
57-
out var retryExceptionMessage))
58-
{
59-
errorMessage = System.Text.Encoding.UTF8.GetString(retryExceptionMessage);
60-
}
61-
62-
else if (consumeResult.Message.Headers.TryGetLastBytes("kafka_exception-message",
63-
out var kafkaErrorBytes))
49+
50+
if (TryReadHeader(consumeResult.Message.Headers, out var errorBytes,
51+
"X-Exception-Message",
52+
"X-Retry-Exception-Message",
53+
"kafka_exception-message",
54+
"kafka_dlt-exception-message"))
6455
{
65-
errorMessage = System.Text.Encoding.UTF8.GetString(kafkaErrorBytes);
56+
errorMessage = System.Text.Encoding.UTF8.GetString(errorBytes);
6657
}
67-
58+
6859
// Extract traceId from traceparent header
6960
if (consumeResult.Message.Headers.TryGetLastBytes("traceparent", out var traceParentBytes))
7061
{
@@ -155,6 +146,23 @@ public void StartConsumer(string groupId, List<string> topics, string reportTrac
155146
}
156147
}
157148

149+
private static bool TryReadHeader(
150+
Headers headers,
151+
out byte[] value,
152+
params string[] keys)
153+
{
154+
foreach (var key in keys)
155+
{
156+
if (headers.TryGetLastBytes(key, out value))
157+
{
158+
return true;
159+
}
160+
}
161+
162+
value = null!;
163+
return false;
164+
}
165+
158166
private bool checkReportTrackingId(string input, string reportTrackingId)
159167
{
160168
if (string.IsNullOrEmpty(input)) return false;

DotNet/Report/Domain/Queries/SubmissionEntryQueries.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -246,9 +246,11 @@ public async Task<bool> PatientAllReadyForValidation(
246246
string patientId,
247247
CancellationToken cancellationToken = default)
248248
{
249-
return await (from entry in _context.PatientSubmissionEntries
250-
where entry.ReportScheduleId == reportScheduleId && entry.FacilityId == facilityId && entry.PatientId == patientId
251-
select entry.Status).AllAsync(s => s == PatientSubmissionStatus.ReadyForValidation || s == PatientSubmissionStatus.NotReportable);
249+
List<PatientSubmissionStatus> statuses = await (from entry in _context.PatientSubmissionEntries
250+
where entry.ReportScheduleId == reportScheduleId && entry.FacilityId == facilityId && entry.PatientId == patientId
251+
select entry.Status).ToListAsync(cancellationToken);
252+
return statuses.All(s => s == PatientSubmissionStatus.ReadyForValidation || s == PatientSubmissionStatus.NotReportable) &&
253+
statuses.Any(s => s == PatientSubmissionStatus.ReadyForValidation);
252254
}
253255

254256
public async Task<PagedConfigModel<ResourceSummary>> GetResourceSummary(string facilityId, string reportScheduleId, ResourceType? resourceType, int pageSize, int pageNumber,

DotNet/Report/KafkaProducers/ReportManifestProducer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ private OperationOutcome CreateOperationOutcome(List<PatientSubmissionEntry> fai
235235
// Assuming PatientSubmissionEntry has a ValidationMessage property; adjust as per actual model
236236
operationOutcome.Issue.Add(new OperationOutcome.IssueComponent
237237
{
238-
Severity = OperationOutcome.IssueSeverity.Fatal,
238+
Severity = OperationOutcome.IssueSeverity.Error,
239239
Code = OperationOutcome.IssueType.Invalid,
240240
Diagnostics = $"Validation failed for patient {entry.PatientId}"
241241
});

DotNet/Report/Listeners/ValidationCompleteListener.cs

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
using System.Text;
2020
using LantanaGroup.Link.Shared.Application.Services.Security;
2121
using Task = System.Threading.Tasks.Task;
22+
using Hl7.Fhir.Support;
2223

2324
namespace LantanaGroup.Link.Report.Listeners
2425
{
@@ -190,18 +191,12 @@ public async Task ProcessMessageAsync(ConsumeResult<string, ValidationCompleteVa
190191
throw new DeadLetterException($"No Patient Submission Entries were found for schedule ID {schedule.Id}, patient ID {value.PatientId}, in status {PatientSubmissionStatus.ValidationRequested}");
191192
}
192193

194+
var operationOutcome = GetOperationOutcome();
195+
193196
foreach (var entry in submissionEntries)
194197
{
195198
if (!value.IsValid)
196199
{
197-
var operationOutcome = new OperationOutcome();
198-
var issue = new OperationOutcome.IssueComponent
199-
{
200-
Severity = OperationOutcome.IssueSeverity.Fatal,
201-
Code = OperationOutcome.IssueType.Invalid,
202-
Diagnostics = "Patient has failed Validation"
203-
};
204-
operationOutcome.Issue = new List<OperationOutcome.IssueComponent> { issue };
205200
await submissionEntryManager.AddResourceAsync(entry, operationOutcome, ResourceCategoryType.Patient, cancellationToken);
206201
}
207202

@@ -269,6 +264,21 @@ await submissionEntryManager.UpdateAsync(new PatientSubmissionEntryUpdateModel
269264
await _reportManifestProducer.Produce(schedule, correlationIdStr);
270265
}
271266

267+
private static OperationOutcome GetOperationOutcome()
268+
{
269+
OperationOutcome operationOutcome = new()
270+
{
271+
Id = Guid.NewGuid().ToString()
272+
};
273+
operationOutcome.AddIssue(new OperationOutcome.IssueComponent
274+
{
275+
Severity = OperationOutcome.IssueSeverity.Error,
276+
Code = OperationOutcome.IssueType.Invalid,
277+
Diagnostics = "Patient has failed Validation"
278+
});
279+
return operationOutcome;
280+
}
281+
272282
private static string GetFacilityIdFromHeader(Headers headers)
273283
{
274284
string facilityId = string.Empty;

0 commit comments

Comments
 (0)