@@ -117,7 +117,7 @@ public async Task<IEnumerable<PatientEventModel>> GetAdmittedPatientEventModelsB
117117 {
118118 // Find the latest event for this patient
119119 var latestEvent = events
120- . OrderByDescending ( e => e . CreateDate )
120+ . OrderByDescending ( e => e . EventDate )
121121 . FirstOrDefault ( ) ;
122122
123123 // If the latest event is an admit event, include this patient
@@ -180,7 +180,7 @@ public async Task<PatientEvent> GetLatestEventByFacilityAndPatientId(string faci
180180
181181 return await _context . PatientEvents
182182 . Where ( x => x . FacilityId == facilityId && x . SourcePatientId == patientId )
183- . OrderByDescending ( x => x . CreateDate )
183+ . OrderByDescending ( x => x . EventDate )
184184 . FirstOrDefaultAsync ( cancellationToken ) ;
185185 }
186186
@@ -296,12 +296,12 @@ private IQueryable<PatientEvent> GetPatientQuery(string facilityId, string? corr
296296
297297 if ( startDate . HasValue && startDate != default )
298298 {
299- baseQuery = baseQuery . Where ( x => x . CreateDate >= startDate . Value ) ;
299+ baseQuery = baseQuery . Where ( x => x . EventDate >= startDate . Value ) ;
300300 }
301301
302302 if ( endDate . HasValue && endDate != default )
303303 {
304- baseQuery = baseQuery . Where ( x => x . CreateDate <= endDate . Value ) ;
304+ baseQuery = baseQuery . Where ( x => x . EventDate <= endDate . Value ) ;
305305 }
306306
307307 // Create specific queries for FHIR events with date filtering
@@ -317,14 +317,12 @@ private IQueryable<PatientEvent> GetPatientQuery(string facilityId, string? corr
317317
318318 if ( startDate . HasValue && startDate != default )
319319 {
320- admitQuery = admitQuery . Where ( x =>
321- ( ( FHIRListAdmitPayload ) x . Payload ) . AdmitDate >= startDate . Value ) ;
320+ admitQuery = admitQuery . Where ( x => x . EventDate >= startDate . Value ) ;
322321 }
323322
324323 if ( endDate . HasValue && endDate != default )
325324 {
326- admitQuery = admitQuery . Where ( x =>
327- ( ( FHIRListAdmitPayload ) x . Payload ) . AdmitDate <= endDate . Value ) ;
325+ admitQuery = admitQuery . Where ( x => x . EventDate <= endDate . Value ) ;
328326 }
329327
330328 queries . Add ( admitQuery ) ;
@@ -334,14 +332,12 @@ private IQueryable<PatientEvent> GetPatientQuery(string facilityId, string? corr
334332
335333 if ( startDate . HasValue && startDate != default )
336334 {
337- dischargeQuery = dischargeQuery . Where ( x =>
338- ( ( FHIRListDischargePayload ) x . Payload ) . DischargeDate >= startDate . Value ) ;
335+ dischargeQuery = dischargeQuery . Where ( x => x . EventDate >= startDate . Value ) ;
339336 }
340337
341338 if ( endDate . HasValue && endDate != default )
342339 {
343- dischargeQuery = dischargeQuery . Where ( x =>
344- ( ( FHIRListDischargePayload ) x . Payload ) . DischargeDate <= endDate . Value ) ;
340+ dischargeQuery = dischargeQuery . Where ( x => x . EventDate <= endDate . Value ) ;
345341 }
346342
347343 queries . Add ( dischargeQuery ) ;
0 commit comments