@@ -205,7 +205,9 @@ && samplesContainPositiveTest(externalMessageDto.getSampleReports(), PathogenTes
205205 caseClassification = CaseClassification .CONFIRMED ;
206206 }
207207
208- if (caseClassification != CaseClassification .NO_CASE && samplesContainOnlyNegativeTests (externalMessageDto .getSampleReports (), PathogenTestType .IGRA )) {
208+ // latent tuberculosis will contain only IGRA tests so check if all are negative which would indicate a NO_CASE
209+ if (caseClassification != CaseClassification .NO_CASE
210+ && samplesContainOnlyNegativeTests (externalMessageDto .getSampleReports (), PathogenTestType .IGRA )) {
209211 caseClassification = CaseClassification .NO_CASE ;
210212
211213 }
@@ -285,6 +287,11 @@ protected boolean isLatentTuberculosisMessage(ExternalMessageDto externalMessage
285287 return false ;
286288 }
287289
290+ final Collection <SampleReportDto > sampleReports = externalMessageDto .getSampleReports ();
291+ if (sampleReports == null || sampleReports .isEmpty ()) {
292+ return false ;
293+ }
294+
288295 // Latent Tubeculosis message should contain only IGRA tests othewise it is Tuberculosis
289296 final List <TestReportDto > testReports = externalMessageDto .getSampleReports ()
290297 .stream ()
@@ -357,9 +364,7 @@ protected boolean containsPositiveTest(Collection<TestReportDto> testReports) {
357364 return false ;
358365 }
359366
360- return testReports .stream ()
361- .filter (Objects ::nonNull )
362- .anyMatch (t -> t .getTestResult () == PathogenTestResultType .POSITIVE );
367+ return testReports .stream ().filter (Objects ::nonNull ).anyMatch (t -> t .getTestResult () == PathogenTestResultType .POSITIVE );
363368 }
364369
365370 protected boolean containsOnlyNegativeTests (Collection <TestReportDto > testReports ) {
@@ -370,9 +375,7 @@ protected boolean containsOnlyNegativeTests(Collection<TestReportDto> testReport
370375 return false ;
371376 }
372377
373- return testReports .stream ()
374- .filter (Objects ::nonNull )
375- .anyMatch (t -> t .getTestResult () == PathogenTestResultType .NEGATIVE );
378+ return testReports .stream ().filter (Objects ::nonNull ).allMatch (t -> t .getTestResult () == PathogenTestResultType .NEGATIVE );
376379 }
377380
378381 protected boolean containsPositiveTest (Collection <TestReportDto > testReports , PathogenTestType testType ) {
@@ -434,23 +437,4 @@ protected boolean hasIgraPositiveTest(Collection<TestReportDto> testReports) {
434437 return containsPositiveTest (testReports , PathogenTestType .IGRA );
435438 }
436439
437- /**
438- * Checks if there are only IGRA negative tests in the test reports.
439- *
440- * @param testReports
441- * @return true if all the IGRA tests in the testReports are negative, false otherwise
442- */
443- protected boolean hasOnlyIgraNegativeTest (List <TestReportDto > testReports ) {
444- if (testReports == null ) {
445- return false ;
446- }
447- if (testReports .isEmpty ()) {
448- return false ;
449- }
450- return testReports .stream ()
451- .filter (Objects ::nonNull )
452- .filter (t -> t .getTestType () == PathogenTestType .IGRA )
453- .allMatch (t -> t .getTestResult () == PathogenTestResultType .NEGATIVE );
454- }
455-
456440}
0 commit comments