1919import java .util .ArrayList ;
2020import java .util .Date ;
2121import java .util .List ;
22+ import java .util .concurrent .CompletionStage ;
23+ import java .util .function .BiFunction ;
24+ import java .util .function .Consumer ;
2225import java .util .regex .Pattern ;
2326
2427import org .apache .commons .lang3 .StringUtils ;
4144import de .symeda .sormas .api .exposure .ExposureType ;
4245import de .symeda .sormas .api .externalmessage .ExternalMessageDto ;
4346import de .symeda .sormas .api .externalmessage .ExternalMessageStatus ;
47+ import de .symeda .sormas .api .externalmessage .labmessage .SampleReportDto ;
4448import de .symeda .sormas .api .externalmessage .processing .AbstractMessageProcessingFlowBase ;
4549import de .symeda .sormas .api .externalmessage .processing .ExternalMessageMapper ;
4650import de .symeda .sormas .api .externalmessage .processing .ExternalMessageProcessingFacade ;
5155import de .symeda .sormas .api .infrastructure .facility .FacilityReferenceDto ;
5256import de .symeda .sormas .api .infrastructure .facility .FacilityType ;
5357import de .symeda .sormas .api .person .PersonDto ;
58+ import de .symeda .sormas .api .sample .SampleSimilarityCriteria ;
5459import de .symeda .sormas .api .symptoms .SymptomsDto ;
5560import de .symeda .sormas .api .therapy .TherapyDto ;
5661import de .symeda .sormas .api .user .UserDto ;
5762import de .symeda .sormas .api .utils .DataHelper ;
5863import de .symeda .sormas .api .utils .DtoCopyHelper ;
5964import de .symeda .sormas .api .utils .YesNoUnknown ;
6065import de .symeda .sormas .api .utils .dataprocessing .ProcessingResult ;
66+ import de .symeda .sormas .api .utils .dataprocessing .flow .FlowThen ;
6167
6268/**
6369 * Abstract class defining the flow of processing a lab message allowing to
@@ -78,6 +84,30 @@ public AbstractDoctorDeclarationMessageProcessingFlow(
7884 super (user , externalMessage , mapper , processingFacade );
7985 }
8086
87+ protected FlowThen <ExternalMessageProcessingResult > doPickOrCreateSamplesFlow (
88+ Consumer <SampleSimilarityCriteria > addSampleSearchCriteria ,
89+ BiFunction <Integer , ExternalMessageProcessingResult , CompletionStage <ProcessingResult <ExternalMessageProcessingResult >>> createSampleAndPathogenTests ,
90+ FlowThen <ExternalMessageProcessingResult > flow ) {
91+
92+ // We use the non null safe sample reports list in case no samples reports were created following DD parsing
93+ final List <SampleReportDto > sampleReports = getExternalMessage ().getSampleReports ();
94+
95+ if (sampleReports == null || sampleReports .isEmpty ()) {
96+ // Just do nothing
97+ return flow .then (ProcessingResult ::asCompletedFuture );
98+ }
99+
100+ // The sample report is not null or empty, we need to check if any tests exists or there are just empty reports
101+ final boolean hasTests = sampleReports .stream ().anyMatch (report -> report .getTestReports () != null && !report .getTestReports ().isEmpty ());
102+ if (!hasTests ) {
103+ // Just do nothing
104+ return flow .then (ProcessingResult ::asCompletedFuture );
105+ }
106+
107+ // Just proceed with the default implementation
108+ return super .doPickOrCreateSamplesFlow (addSampleSearchCriteria , createSampleAndPathogenTests , flow );
109+ }
110+
81111 /**
82112 * Marks the external message as processed and updates its status.
83113 *
0 commit comments