@@ -140,9 +140,9 @@ public async Task<List<ExceptionManagement>> GetByFilter(Expression<Func<Excepti
140140
141141 public async Task < ValidationExceptionsByNhsNumberResponse > GetExceptionsWithReportsByNhsNumber ( string nhsNumber )
142142 {
143- var validationExceptions = await GetValidationExceptionsByNhsNumber ( nhsNumber ) ;
143+ var allValidationExceptions = await GetValidationExceptionsByNhsNumber ( nhsNumber ) ;
144144
145- if ( validationExceptions . Count == 0 )
145+ if ( allValidationExceptions . Count == 0 )
146146 {
147147 return new ValidationExceptionsByNhsNumberResponse
148148 {
@@ -152,15 +152,46 @@ public async Task<ValidationExceptionsByNhsNumberResponse> GetExceptionsWithRepo
152152 } ;
153153 }
154154
155- var reports = GenerateExceptionReports ( validationExceptions ) ;
155+ var exceptions = allValidationExceptions
156+ . Where ( x => x . Category == ( int ) ExceptionCategory . NBO )
157+ . ToList ( ) ;
158+
159+ var reportExceptions = allValidationExceptions
160+ . Where ( x => x . Category == ( int ) ExceptionCategory . Confusion ||
161+ x . Category == ( int ) ExceptionCategory . Superseded )
162+ . ToList ( ) ;
163+
164+ var reports = GenerateExceptionReports ( reportExceptions ) ;
165+
156166 return new ValidationExceptionsByNhsNumberResponse
157167 {
158- Exceptions = validationExceptions ,
168+ Exceptions = exceptions ,
159169 Reports = reports ,
160170 NhsNumber = nhsNumber
161171 } ;
162172 }
163173
174+ private async Task < List < ValidationException > > GetValidationExceptionsByNhsNumber ( string nhsNumber )
175+ {
176+ var exceptions = await _validationExceptionDataServiceClient . GetByFilter ( x =>
177+ x . NhsNumber == nhsNumber &&
178+ x . Category . HasValue &&
179+ ( x . Category . Value == ( int ) ExceptionCategory . NBO ||
180+ x . Category . Value == ( int ) ExceptionCategory . Confusion ||
181+ x . Category . Value == ( int ) ExceptionCategory . Superseded ) ) ;
182+
183+ if ( exceptions == null || ! exceptions . Any ( ) )
184+ {
185+ return [ ] ;
186+ }
187+
188+ return [ .. exceptions
189+ . Select ( GetValidationExceptionWithDetails )
190+ . Where ( x => x != null )
191+ . Cast < ValidationException > ( )
192+ . OrderByDescending ( x => x . DateCreated ) ] ;
193+ }
194+
164195 private List < ValidationException > MapToValidationExceptions ( IEnumerable < ExceptionManagement > exceptions )
165196 {
166197 return exceptions . Select ( GetValidationExceptionWithDetails ) . Where ( x => x != null ) . ToList ( ) ! ;
@@ -252,7 +283,6 @@ private ServiceResponseModel CreateResponse(bool success, HttpStatusCode statusC
252283 } ;
253284 }
254285
255-
256286 private static string ? ValidateServiceNowId ( string serviceNowId )
257287 {
258288 if ( string . IsNullOrWhiteSpace ( serviceNowId ) )
@@ -343,27 +373,9 @@ private static List<ValidationException> SortExceptions(SortOrder? sortOrder, IE
343373 : [ .. filteredList . OrderByDescending ( dateProperty ) ] ;
344374 }
345375
346-
347-
348- private async Task < List < ValidationException > > GetValidationExceptionsByNhsNumber ( string nhsNumber )
349- {
350- var exceptions = await _validationExceptionDataServiceClient . GetByFilter ( x => x . NhsNumber == nhsNumber && x . Category . HasValue && x . Category . Value == ( int ) ExceptionCategory . NBO ) ;
351- if ( exceptions == null || ! exceptions . Any ( ) )
352- {
353- return [ ] ;
354- }
355-
356- return [ .. exceptions
357- . Select ( GetValidationExceptionWithDetails )
358- . Where ( x => x != null )
359- . Cast < ValidationException > ( )
360- . OrderByDescending ( x => x . DateCreated ) ] ;
361- }
362-
363376 private static List < ValidationExceptionReport > GenerateExceptionReports ( List < ValidationException > validationExceptions )
364377 {
365378 return [ .. validationExceptions
366- . Where ( x => x . Category . HasValue && ( x . Category . Value == 12 || x . Category . Value == 13 ) )
367379 . GroupBy ( x => new
368380 {
369381 Date = x . DateCreated ? . Date ?? DateTime . Now . Date ,
0 commit comments