|
17 | 17 | import bio.terra.pearl.core.model.study.StudyEnvironment;
|
18 | 18 | import bio.terra.pearl.core.model.study.StudyEnvironmentConfig;
|
19 | 19 | import bio.terra.pearl.core.model.survey.Survey;
|
| 20 | +import bio.terra.pearl.core.model.survey.SurveyResponse; |
20 | 21 | import bio.terra.pearl.core.model.survey.SurveyResponseWithTaskDto;
|
21 | 22 | import bio.terra.pearl.core.model.survey.SurveyType;
|
| 23 | +import bio.terra.pearl.core.model.workflow.ParticipantTask; |
| 24 | +import bio.terra.pearl.core.model.workflow.TaskStatus; |
| 25 | +import bio.terra.pearl.core.model.workflow.TaskType; |
22 | 26 | import bio.terra.pearl.core.service.export.formatters.ExportFormatUtils;
|
23 | 27 | import bio.terra.pearl.core.service.export.formatters.item.AnswerItemFormatter;
|
24 | 28 | import bio.terra.pearl.core.service.export.formatters.item.ItemFormatter;
|
@@ -745,4 +749,97 @@ public void testExportSubheadersOption(TestInfo testInfo) throws Exception {
|
745 | 749 | assertThat(export, containsString(",enrollee.createdAt"));
|
746 | 750 | assertThat(export, containsString(",Created At"));
|
747 | 751 | }
|
| 752 | + |
| 753 | + @Test |
| 754 | + @Transactional |
| 755 | + public void testOnlyCompleteSurveyResponses(TestInfo testInfo) throws Exception { |
| 756 | + |
| 757 | + ParticipantTask.ParticipantTaskBuilder taskBuilder = ParticipantTask.builder() |
| 758 | + .status(TaskStatus.NEW) |
| 759 | + .taskType(TaskType.SURVEY) |
| 760 | + .targetName("test") |
| 761 | + .taskOrder(1); |
| 762 | + |
| 763 | + String testName = getTestName(testInfo); |
| 764 | + StudyEnvironmentBundle studyEnvBundle = studyEnvironmentFactory.buildBundle(testName, EnvironmentName.sandbox); |
| 765 | + StudyEnvironment studyEnv = studyEnvBundle.getStudyEnv(); |
| 766 | + PortalEnvironment portalEnv = studyEnvBundle.getPortalEnv(); |
| 767 | + Survey survey = surveyService.create( |
| 768 | + surveyFactory |
| 769 | + .builderWithDependencies(getTestName(testInfo)) |
| 770 | + .content(SOCIAL_HEALTH_EXCERPT) |
| 771 | + .name("Survey Test") |
| 772 | + .stableId("examplesurvey") |
| 773 | + .surveyType(SurveyType.RESEARCH) |
| 774 | + .version(1) |
| 775 | + .autoAssign(false) |
| 776 | + .build()); |
| 777 | + |
| 778 | + surveyFactory.attachToEnv(survey, studyEnv.getId(), true); |
| 779 | + |
| 780 | + EnrolleeBundle enrollee1Bundle = enrolleeFactory.buildWithPortalUser(testName, portalEnv, studyEnv, new Profile()); |
| 781 | + Enrollee enrollee1 = enrollee1Bundle.enrollee(); |
| 782 | + |
| 783 | + SurveyResponse e1r1 = surveyResponseFactory.buildWithAnswers( |
| 784 | + enrollee1, |
| 785 | + survey, |
| 786 | + Map.of( |
| 787 | + "hd_hd_socialHealth_neighborhoodIsWalkable", "agree" |
| 788 | + ), |
| 789 | + true |
| 790 | + ); |
| 791 | + |
| 792 | + SurveyResponse e1r2 = surveyResponseFactory.buildWithAnswers( |
| 793 | + enrollee1, |
| 794 | + survey, |
| 795 | + Map.of( |
| 796 | + "hd_hd_socialHealth_neighborhoodIsWalkable", "disagree" |
| 797 | + ) |
| 798 | + ); |
| 799 | + |
| 800 | + participantTaskFactory.buildPersisted(enrollee1Bundle, |
| 801 | + taskBuilder |
| 802 | + .surveyResponseId(e1r1.getId()) |
| 803 | + .status(TaskStatus.COMPLETE)); |
| 804 | + participantTaskFactory.buildPersisted(enrollee1Bundle, |
| 805 | + taskBuilder |
| 806 | + .surveyResponseId(e1r2.getId()) |
| 807 | + .status(TaskStatus.IN_PROGRESS)); |
| 808 | + |
| 809 | + |
| 810 | + Enrollee enrollee2 = enrolleeFactory.buildPersisted(testName, studyEnv, new Profile()); |
| 811 | + |
| 812 | + SurveyResponse e2r1 = surveyResponseFactory.buildWithAnswers( |
| 813 | + enrollee2, |
| 814 | + survey, |
| 815 | + Map.of( |
| 816 | + "hd_hd_socialHealth_neighborhoodIsWalkable", "agree" |
| 817 | + ) |
| 818 | + ); |
| 819 | + |
| 820 | + participantTaskFactory.buildPersisted(enrollee1Bundle, |
| 821 | + taskBuilder |
| 822 | + .surveyResponseId(e2r1.getId()) |
| 823 | + .status(TaskStatus.IN_PROGRESS)); |
| 824 | + |
| 825 | + |
| 826 | + ExportOptionsWithExpression exportOptions = new ExportOptionsWithExpression(); |
| 827 | + |
| 828 | + exportOptions.setOnlyIncludeCompleted(true); |
| 829 | + |
| 830 | + List<EnrolleeExportData> exportData = enrolleeExportService.loadEnrolleeExportData(studyEnv.getId(), exportOptions); |
| 831 | + List<ModuleFormatter> moduleFormatters = enrolleeExportService.generateModuleInfos(new ExportOptions(), studyEnv.getId(), exportData); |
| 832 | + List<Map<String, String>> exportMaps = enrolleeExportService.generateExportMaps(exportData, moduleFormatters); |
| 833 | + |
| 834 | + |
| 835 | + assertThat(exportMaps, hasSize(2)); |
| 836 | + |
| 837 | + Map<String, String> enrollee1Map = exportMaps.stream().filter(map -> map.get("enrollee.shortcode").equals(enrollee1.getShortcode())).findFirst().get(); |
| 838 | + Map<String, String> enrollee2Map = exportMaps.stream().filter(map -> map.get("enrollee.shortcode").equals(enrollee2.getShortcode())).findFirst().get(); |
| 839 | + |
| 840 | + assertThat(enrollee1Map.get("examplesurvey.hd_hd_socialHealth_neighborhoodIsWalkable"), equalTo("Agree")); |
| 841 | + assertThat(enrollee1Map.containsKey("examplesurvey.hd_hd_socialHealth_neighborhoodIsWalkable[1]"), equalTo(false)); |
| 842 | + |
| 843 | + assertThat(enrollee2Map.containsKey("examplesurvey.hd_hd_socialHealth_neighborhoodIsWalkable"), equalTo(false)); |
| 844 | + } |
748 | 845 | }
|
0 commit comments