Skip to content

Commit 14808c8

Browse files
LNK-4424: Encounter Creation and Test Data fix (#1234)
* Update index.mdx * Update Program.cs * LNK-4421: fix multiple instance running job factory * Update JobFactory.cs * Update Program.cs * LNK-4424: Fix logging messages and test data * fix logging messages and introduce encounter creation for discharge only records earlier so that correlation id is better tracked. * fix confusing logging messages * Update Program.cs * Update PatientListService.cs
1 parent c2a571a commit 14808c8

4 files changed

Lines changed: 40 additions & 9 deletions

File tree

DotNet/Census/Application/Services/PatientListService.cs

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,6 @@ public async Task<List<IBaseResponse>> ProcessList(string facilityId, PatientLis
8282
var existingEvent =
8383
await _patientEventQueries.GetLatestEventByFacilityAndPatientId(facilityId, patientId,
8484
cancellationToken);
85-
string sharedCorrelationId = existingEvent?.CorrelationId ?? Guid.NewGuid().ToString();
8685

8786
bool shouldSkip = false;
8887
if (existingEvent != null)
@@ -91,11 +90,13 @@ await _patientEventQueries.GetLatestEventByFacilityAndPatientId(facilityId, pati
9190
if (skipProcessing.result)
9291
{
9392
_logger.LogInformation(
94-
"Skipping processing for patient {PatientId} in facility {FacilityId}. " +
95-
"Reason: Admit event processing is planned for future implementation. " +
96-
"Event type: {EventType}, List type: {ListType}",
97-
patientId, facilityId, "Admit", list.ListType);
98-
93+
"{SkipMessage} PatientId: {PatientId}, FacilityId: {FacilityId}, EventType: {EventType}, ListType: {ListType}",
94+
skipProcessing.message,
95+
patientId,
96+
facilityId,
97+
"Admit",
98+
list.ListType);
99+
99100
shouldSkip = true; // Mark for skipping but don't continue yet
100101
}
101102
}
@@ -105,6 +106,11 @@ await _patientEventQueries.GetLatestEventByFacilityAndPatientId(facilityId, pati
105106
continue; // Skip processing for this patient
106107
}
107108

109+
var sharedCorrelationId = existingEvent != null
110+
&& existingEvent.EventType == EventType.FHIRListDischarge
111+
&& list.ListType == ListType.Admit
112+
? Guid.NewGuid().ToString() : (existingEvent?.CorrelationId ?? Guid.NewGuid().ToString());
113+
108114
await EnsureAdmitEventExists(facilityId, patientId, sharedCorrelationId, list.ListType,
109115
existingEvent,
110116
cancellationToken);
@@ -185,13 +191,25 @@ private async Task EnsureAdmitEventExists(string facilityId, string patientId, s
185191
if (existingEvent == null && listType == ListType.Discharge)
186192
{
187193
//create and add an admit event
188-
var admitEvent =
189-
new FHIRListAdmitPayload(patientId, DateTime.UtcNow).CreatePatientEvent(facilityId, correlationId);
194+
var payload = new FHIRListAdmitPayload(patientId, DateTime.UtcNow);
195+
var admitEvent = payload.CreatePatientEvent(facilityId, correlationId);
196+
190197
try
191198
{
192199
await _patientEventManager.AddPatientEvent(admitEvent, cancellationToken);
193200
_logger.LogInformation("Added admit event for patient {patientId} in facility {facilityId}", patientId,
194201
facilityId);
202+
203+
PatientEncounter encounter =
204+
await _patientEncounterQueries.GetPatientEncounterByCorrelationIdAsync(correlationId,
205+
cancellationToken);
206+
207+
if (encounter == null)
208+
{
209+
var patientEncounter = payload.CreatePatientEncounter(facilityId, correlationId);
210+
encounter = await _patientEncounterManager.AddPatientEncounterAsync(patientEncounter,
211+
cancellationToken);
212+
}
195213
}
196214
catch (Exception ex)
197215
{
@@ -238,7 +256,7 @@ public async Task<List<IBaseResponse>> ProcessLists(string facilityId, List<Pati
238256
}
239257

240258
List<IBaseResponse> messages = new List<IBaseResponse>();
241-
foreach (var list in lists)
259+
foreach (var list in lists.OrderBy(x => x.ListType))
242260
{
243261
messages.AddRange(await ProcessList(facilityId, list, cancellationToken));
244262
}

DotNet/Census/Program.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@ static void RegisterServices(WebApplicationBuilder builder)
211211
q.UseMicrosoftDependencyInjectionJobFactory();
212212
});
213213

214+
builder.Services.AddSingleton<IJobFactory, JobFactory>();
214215
builder.Services.AddTransient<SchedulePatientListRetrieval>();
215216
builder.Services.AddTransient<RetryJob>();
216217

Tests/BackendE2ETests/fhir_server_data/20250527_STU3_AdhocSmokeTestList_Discharge_Between24To48Hrs.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,12 @@
3636
"reference": "Patient/CYUcGIlSrpJxCBMeEml30YSmE0Ea7loNBPVZfhCUkv7A3",
3737
"display": "Caleb058 Ryan027 Vasquez055"
3838
}
39+
},
40+
{
41+
"item": {
42+
"reference": "Patient/9i6Xi6uG2WjuGxHTmpbin4ct2ZwevRwTWhIkJkRjVFZ4C",
43+
"display": "Chloe017 Matthew058 Martinez091"
44+
}
3945
}
4046
]
4147
}

Tests/BackendE2ETests/fhir_server_data/20250527_STU3_AdhocSmokeTestList_Discharge_LessThan24Hrs.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,12 @@
3636
"reference": "Patient/x25sJU80vVa51mxJ6vSDcjbNC3BcdCQujJbXQwqdppFOO",
3737
"display": "Robert091 Veronica020 Price042"
3838
}
39+
},
40+
{
41+
"item": {
42+
"reference": "Patient/jbbPDJeGWyEyudcf6EBKTgmeCLxB7jTgu5Ugm27JAO494",
43+
"display": "William037 Robert002 Tapia002"
44+
}
3945
}
4046
]
4147
}

0 commit comments

Comments
 (0)