Skip to content

Commit 25122c0

Browse files
Merge branch 'dev' into users/mtherien/leglink-774-app-config
2 parents daeead6 + 1f59229 commit 25122c0

1 file changed

Lines changed: 18 additions & 14 deletions

File tree

DotNet/Report/KafkaProducers/ReadyForValidationProducer.cs

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
using LantanaGroup.Link.Report.Domain.Managers;
33
using LantanaGroup.Link.Report.Models;
44
using LantanaGroup.Link.Shared.Application.Models;
5-
using LantanaGroup.Link.Shared.Application.Models.Integration.Report;
65
using ReportingStatus = LantanaGroup.Link.Report.Domain.Enums.ReportingStatus;
76
using SubmissionStatus = LantanaGroup.Link.Report.Domain.Enums.SubmissionStatus;
87
using System.Text;
@@ -44,6 +43,24 @@ public async Task Produce(Guid scheduleId, List<string> reportTypes, string faci
4443
{
4544
cancellationToken.ThrowIfCancellationRequested();
4645

46+
// The PendingValidation status must be persisted before the message is produced.
47+
// Otherwise a fast ValidationComplete round-trip can set PassedValidation/FailedValidation
48+
// first, and the write below would regress the entry to PendingValidation after a
49+
// SubmitPayload was already produced, permanently blocking report completion.
50+
using var scope = _serviceScopeFactory.CreateScope();
51+
var reportEntryManager = scope.ServiceProvider.GetRequiredService<IReportEntryManager>();
52+
var entry = await reportEntryManager.GetEntry(scheduleId, patientId, cancellationToken);
53+
54+
if (entry == null)
55+
{
56+
throw new Exception($"No report entry record was found (ReportId = {scheduleId}, FacilityId = {facilityId}).");
57+
}
58+
59+
entry.ReportingStatus = ReportingStatus.PendingValidation;
60+
entry.SubmissionStatus = SubmissionStatus.PendingValidation;
61+
62+
await reportEntryManager.UpdateAsync(entry, cancellationToken);
63+
4764
_logger.LogDebug("Producing ReadyForValidation (Facility = {FacilityId}, PatientId = {PatientId}, ReportScheduleId = {ReportScheduleId})", facilityId.SanitizeForLog(), patientId.SanitizeForLog(), scheduleId.SanitizeForLog());
4865

4966
_readyForValidationProducer.Produce(nameof(KafkaTopic.ReadyForValidation),
@@ -68,19 +85,6 @@ public async Task Produce(Guid scheduleId, List<string> reportTypes, string faci
6885
});
6986

7087
_readyForValidationProducer.Flush();
71-
72-
var reportEntryManager = _serviceScopeFactory.CreateScope().ServiceProvider.GetRequiredService<IReportEntryManager>();
73-
var entry = await reportEntryManager.GetEntry(scheduleId, patientId, CancellationToken.None);
74-
75-
if (entry == null)
76-
{
77-
throw new Exception($"No report entry record was found (ReportId = {scheduleId}, FacilityId = {facilityId}).");
78-
}
79-
80-
entry.ReportingStatus = ReportingStatus.PendingValidation;
81-
entry.SubmissionStatus = SubmissionStatus.PendingValidation;
82-
83-
await reportEntryManager.UpdateAsync(entry, CancellationToken.None);
8488
}
8589
}
8690
}

0 commit comments

Comments
 (0)