|
43 | 43 | import java.util.function.Consumer;
|
44 | 44 | import java.util.function.Supplier;
|
45 | 45 |
|
| 46 | +import de.symeda.sormas.api.caze.CaseOutcome; |
| 47 | +import de.symeda.sormas.backend.MockProducer; |
| 48 | +import de.symeda.sormas.backend.common.ConfigFacadeEjb; |
46 | 49 | import org.jetbrains.annotations.NotNull;
|
47 | 50 | import org.jetbrains.annotations.Nullable;
|
48 | 51 | import org.junit.jupiter.api.Test;
|
@@ -2816,6 +2819,196 @@ public void testCaseSurveillanceReportUnknownFacility() throws ExecutionExceptio
|
2816 | 2819 | assertThat(surveillanceReport.getFacilityDistrict(), is(nullValue()));
|
2817 | 2820 | }
|
2818 | 2821 |
|
| 2822 | + @Test |
| 2823 | + public void testCreateCaseWithPertusisTestTypeCultureForLuServers() throws ExecutionException, InterruptedException { |
| 2824 | + MockProducer.getProperties().setProperty(ConfigFacadeEjb.COUNTRY_LOCALE, "lu"); |
| 2825 | + ArgumentCaptor<PersonDto> personCaptor = ArgumentCaptor.forClass(PersonDto.class); |
| 2826 | + doAnswer(invocation -> { |
| 2827 | + HandlerCallback<EntitySelection<PersonDto>> callback = invocation.getArgument(1); |
| 2828 | + PersonDto person = invocation.getArgument(0); |
| 2829 | + |
| 2830 | + getPersonFacade().save(person); |
| 2831 | + |
| 2832 | + callback.done(new EntitySelection<>(person, true)); |
| 2833 | + |
| 2834 | + return null; |
| 2835 | + |
| 2836 | + }).when(handlePickOrCreatePerson).apply(personCaptor.capture(), any()); |
| 2837 | + |
| 2838 | + PickOrCreateEntryResult pickOrCreateEntryResult = new PickOrCreateEntryResult(); |
| 2839 | + pickOrCreateEntryResult.setNewCase(true); |
| 2840 | + doAnswer(answerPickOrCreateEntry(pickOrCreateEntryResult)).when(handlePickOrCreateEntry).handle(any(), any(), any(), any()); |
| 2841 | + |
| 2842 | + ArgumentCaptor<CaseDataDto> caseCaptor = ArgumentCaptor.forClass(CaseDataDto.class); |
| 2843 | + doAnswer((invocation) -> { |
| 2844 | + CaseDataDto caze = invocation.getArgument(0); |
| 2845 | + caze.setResponsibleRegion(rdcf.region); |
| 2846 | + caze.setResponsibleDistrict(rdcf.district); |
| 2847 | + caze.setFacilityType(FacilityType.HOSPITAL); |
| 2848 | + caze.setHealthFacility(rdcf.facility); |
| 2849 | + getCaseFacade().save(caze); |
| 2850 | + getCallbackParam(invocation).done(caze); |
| 2851 | + return null; |
| 2852 | + }).when(handleCreateCase).handle(caseCaptor.capture(), any(), any()); |
| 2853 | + |
| 2854 | + doAnswer((invocation) -> { |
| 2855 | + SampleDto sample = invocation.getArgument(0); |
| 2856 | + sample.setSamplingReason(SamplingReason.PROFESSIONAL_REASON); |
| 2857 | + |
| 2858 | + List<PathogenTestDto> pathogenTests = invocation.getArgument(1); |
| 2859 | + pathogenTests.get(0).setTestResultText("Dummy test result text"); |
| 2860 | + |
| 2861 | + getCallbackParam(invocation).done(new SampleAndPathogenTests(sample, pathogenTests)); |
| 2862 | + return null; |
| 2863 | + }).when(handleCreateSampleAndPathogenTests).handle(any(), any(), any(), eq(true), any()); |
| 2864 | + |
| 2865 | + SampleReportDto sampleReport = SampleReportDto.build(); |
| 2866 | + ExternalMessageDto labMessage = createLabMessage(Disease.PERTUSSIS, "test-report-id", ExternalMessageStatus.UNPROCESSED); |
| 2867 | + labMessage.addSampleReport(sampleReport); |
| 2868 | + sampleReport.setSampleDateTime(new Date()); |
| 2869 | + sampleReport.setSampleMaterial(SampleMaterial.BLOOD); |
| 2870 | + |
| 2871 | + TestReportDto testReport1 = TestReportDto.build(); |
| 2872 | + testReport1.setTestType(PathogenTestType.CULTURE); |
| 2873 | + testReport1.setTestResult(PathogenTestResultType.POSITIVE); |
| 2874 | + sampleReport.addTestReport(testReport1); |
| 2875 | + |
| 2876 | + ProcessingResult<ExternalMessageProcessingResult> result = runFlow(labMessage); |
| 2877 | + |
| 2878 | + assertThat(result.getStatus(), is(DONE)); |
| 2879 | + assertThat(getExternalMessageFacade().getByUuid(labMessage.getUuid()).getStatus(), is(ExternalMessageStatus.PROCESSED)); |
| 2880 | + assertThat(getSurveillanceReportFacade().getByCaseUuids(Collections.singletonList(result.getData().getCase().getUuid())), hasSize(1)); |
| 2881 | + |
| 2882 | + verify(handleCreateSampleAndPathogenTests).handle(argThat(sample -> { |
| 2883 | + assertThat(sample.getAssociatedCase(), is(caseCaptor.getValue().toReference())); |
| 2884 | + assertThat(sample.getSampleDateTime(), is(labMessage.getSampleReports().get(0).getSampleDateTime())); |
| 2885 | + assertThat(sample.getSampleMaterial(), is(SampleMaterial.BLOOD)); |
| 2886 | + assertThat(sample.getReportingUser(), is(user.toReference())); |
| 2887 | + |
| 2888 | + return true; |
| 2889 | + }), argThat(pathogenTests -> { |
| 2890 | + assertThat(pathogenTests, hasSize(1)); |
| 2891 | + |
| 2892 | + assertThat(pathogenTests.get(0).getTestType(), is(testReport1.getTestType())); |
| 2893 | + assertThat(pathogenTests.get(0).getTestResult(), is(testReport1.getTestResult())); |
| 2894 | + |
| 2895 | + return true; |
| 2896 | + }), argThat(entityCreated -> { |
| 2897 | + assertThat(entityCreated, is(true)); |
| 2898 | + |
| 2899 | + return true; |
| 2900 | + }), argThat(lastSample -> { |
| 2901 | + assertThat(lastSample, is(Boolean.TRUE)); |
| 2902 | + |
| 2903 | + return true; |
| 2904 | + }), any()); |
| 2905 | + |
| 2906 | + verify(handleCreateCase).handle(argThat(c -> { |
| 2907 | + assertThat(c.getPerson(), is(personCaptor.getValue().toReference())); |
| 2908 | + assertThat(c.getDisease(), is(Disease.PERTUSSIS)); |
| 2909 | + assertThat(c.getCaseClassification(), is(CaseClassification.CONFIRMED)); |
| 2910 | + assertThat(c.getInvestigationStatus(), is(InvestigationStatus.PENDING)); |
| 2911 | + assertThat(c.getOutcome(), is(CaseOutcome.NO_OUTCOME)); |
| 2912 | + assertThat(c.getReportingUser(), is(user.toReference())); |
| 2913 | + return true; |
| 2914 | + }), argThat(p -> p.equals(personCaptor.getValue())), any()); |
| 2915 | + } |
| 2916 | + |
| 2917 | + @Test |
| 2918 | + public void testCreateCaseWithPertusisOtherTestTypeForLuServers() throws ExecutionException, InterruptedException { |
| 2919 | + MockProducer.getProperties().setProperty(ConfigFacadeEjb.COUNTRY_LOCALE, "lu"); |
| 2920 | + ArgumentCaptor<PersonDto> personCaptor = ArgumentCaptor.forClass(PersonDto.class); |
| 2921 | + doAnswer(invocation -> { |
| 2922 | + HandlerCallback<EntitySelection<PersonDto>> callback = invocation.getArgument(1); |
| 2923 | + PersonDto person = invocation.getArgument(0); |
| 2924 | + |
| 2925 | + getPersonFacade().save(person); |
| 2926 | + |
| 2927 | + callback.done(new EntitySelection<>(person, true)); |
| 2928 | + |
| 2929 | + return null; |
| 2930 | + |
| 2931 | + }).when(handlePickOrCreatePerson).apply(personCaptor.capture(), any()); |
| 2932 | + |
| 2933 | + PickOrCreateEntryResult pickOrCreateEntryResult = new PickOrCreateEntryResult(); |
| 2934 | + pickOrCreateEntryResult.setNewCase(true); |
| 2935 | + doAnswer(answerPickOrCreateEntry(pickOrCreateEntryResult)).when(handlePickOrCreateEntry).handle(any(), any(), any(), any()); |
| 2936 | + |
| 2937 | + ArgumentCaptor<CaseDataDto> caseCaptor = ArgumentCaptor.forClass(CaseDataDto.class); |
| 2938 | + doAnswer((invocation) -> { |
| 2939 | + CaseDataDto caze = invocation.getArgument(0); |
| 2940 | + caze.setResponsibleRegion(rdcf.region); |
| 2941 | + caze.setResponsibleDistrict(rdcf.district); |
| 2942 | + caze.setFacilityType(FacilityType.HOSPITAL); |
| 2943 | + caze.setHealthFacility(rdcf.facility); |
| 2944 | + getCaseFacade().save(caze); |
| 2945 | + getCallbackParam(invocation).done(caze); |
| 2946 | + return null; |
| 2947 | + }).when(handleCreateCase).handle(caseCaptor.capture(), any(), any()); |
| 2948 | + |
| 2949 | + doAnswer((invocation) -> { |
| 2950 | + SampleDto sample = invocation.getArgument(0); |
| 2951 | + sample.setSamplingReason(SamplingReason.PROFESSIONAL_REASON); |
| 2952 | + |
| 2953 | + List<PathogenTestDto> pathogenTests = invocation.getArgument(1); |
| 2954 | + pathogenTests.get(0).setTestResultText("Dummy test result text"); |
| 2955 | + |
| 2956 | + getCallbackParam(invocation).done(new SampleAndPathogenTests(sample, pathogenTests)); |
| 2957 | + return null; |
| 2958 | + }).when(handleCreateSampleAndPathogenTests).handle(any(), any(), any(), eq(true), any()); |
| 2959 | + |
| 2960 | + SampleReportDto sampleReport = SampleReportDto.build(); |
| 2961 | + ExternalMessageDto labMessage = createLabMessage(Disease.PERTUSSIS, "test-report-id", ExternalMessageStatus.UNPROCESSED); |
| 2962 | + labMessage.addSampleReport(sampleReport); |
| 2963 | + sampleReport.setSampleDateTime(new Date()); |
| 2964 | + sampleReport.setSampleMaterial(SampleMaterial.BLOOD); |
| 2965 | + |
| 2966 | + TestReportDto testReport1 = TestReportDto.build(); |
| 2967 | + testReport1.setTestType(PathogenTestType.RAPID_TEST); |
| 2968 | + testReport1.setTestResult(PathogenTestResultType.POSITIVE); |
| 2969 | + sampleReport.addTestReport(testReport1); |
| 2970 | + |
| 2971 | + ProcessingResult<ExternalMessageProcessingResult> result = runFlow(labMessage); |
| 2972 | + |
| 2973 | + assertThat(result.getStatus(), is(DONE)); |
| 2974 | + assertThat(getExternalMessageFacade().getByUuid(labMessage.getUuid()).getStatus(), is(ExternalMessageStatus.PROCESSED)); |
| 2975 | + assertThat(getSurveillanceReportFacade().getByCaseUuids(Collections.singletonList(result.getData().getCase().getUuid())), hasSize(1)); |
| 2976 | + |
| 2977 | + verify(handleCreateSampleAndPathogenTests).handle(argThat(sample -> { |
| 2978 | + assertThat(sample.getAssociatedCase(), is(caseCaptor.getValue().toReference())); |
| 2979 | + assertThat(sample.getSampleDateTime(), is(labMessage.getSampleReports().get(0).getSampleDateTime())); |
| 2980 | + assertThat(sample.getSampleMaterial(), is(SampleMaterial.BLOOD)); |
| 2981 | + assertThat(sample.getReportingUser(), is(user.toReference())); |
| 2982 | + |
| 2983 | + return true; |
| 2984 | + }), argThat(pathogenTests -> { |
| 2985 | + assertThat(pathogenTests, hasSize(1)); |
| 2986 | + |
| 2987 | + assertThat(pathogenTests.get(0).getTestType(), is(testReport1.getTestType())); |
| 2988 | + assertThat(pathogenTests.get(0).getTestResult(), is(testReport1.getTestResult())); |
| 2989 | + |
| 2990 | + return true; |
| 2991 | + }), argThat(entityCreated -> { |
| 2992 | + assertThat(entityCreated, is(true)); |
| 2993 | + |
| 2994 | + return true; |
| 2995 | + }), argThat(lastSample -> { |
| 2996 | + assertThat(lastSample, is(Boolean.TRUE)); |
| 2997 | + |
| 2998 | + return true; |
| 2999 | + }), any()); |
| 3000 | + |
| 3001 | + verify(handleCreateCase).handle(argThat(c -> { |
| 3002 | + assertThat(c.getPerson(), is(personCaptor.getValue().toReference())); |
| 3003 | + assertThat(c.getDisease(), is(Disease.PERTUSSIS)); |
| 3004 | + assertThat(c.getCaseClassification(), is(CaseClassification.NOT_CLASSIFIED)); |
| 3005 | + assertThat(c.getInvestigationStatus(), is(InvestigationStatus.PENDING)); |
| 3006 | + assertThat(c.getOutcome(), is(CaseOutcome.NO_OUTCOME)); |
| 3007 | + assertThat(c.getReportingUser(), is(user.toReference())); |
| 3008 | + return true; |
| 3009 | + }), argThat(p -> p.equals(personCaptor.getValue())), any()); |
| 3010 | + } |
| 3011 | + |
2819 | 3012 | private ProcessingResult<ExternalMessageProcessingResult> runFlow(ExternalMessageDto labMessage) throws ExecutionException, InterruptedException {
|
2820 | 3013 | ExternalMessageProcessingFacade processingFacade = getExternalMessageProcessingFacade();
|
2821 | 3014 | AbstractLabMessageProcessingFlow flow = new AbstractLabMessageProcessingFlow(
|
|
0 commit comments