Skip to content

Commit

Permalink
[JN-1395] adding pre-enroll to export (#1135)
Browse files Browse the repository at this point in the history
  • Loading branch information
devonbush authored Oct 9, 2024
1 parent b3a75d6 commit 083d10d
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import bio.terra.pearl.core.model.participant.Enrollee;
import bio.terra.pearl.core.model.participant.EnrolleeRelation;
import bio.terra.pearl.core.model.search.EnrolleeSearchExpressionResult;
import bio.terra.pearl.core.model.study.StudyEnvironment;
import bio.terra.pearl.core.model.study.StudyEnvironmentConfig;
import bio.terra.pearl.core.model.survey.StudyEnvironmentSurvey;
import bio.terra.pearl.core.model.survey.Survey;
Expand All @@ -21,8 +22,10 @@
import bio.terra.pearl.core.service.search.EnrolleeSearchExpression;
import bio.terra.pearl.core.service.search.EnrolleeSearchOptions;
import bio.terra.pearl.core.service.study.StudyEnvironmentConfigService;
import bio.terra.pearl.core.service.study.StudyEnvironmentService;
import bio.terra.pearl.core.service.study.StudyEnvironmentSurveyService;
import bio.terra.pearl.core.service.survey.SurveyResponseService;
import bio.terra.pearl.core.service.survey.SurveyService;
import bio.terra.pearl.core.service.workflow.ParticipantTaskService;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.extern.slf4j.Slf4j;
Expand All @@ -41,6 +44,8 @@ public class EnrolleeExportService {
private final AnswerDao answerDao;
private final SurveyQuestionDefinitionDao surveyQuestionDefinitionDao;
private final StudyEnvironmentSurveyService studyEnvironmentSurveyService;
private final SurveyService surveyService;
private final StudyEnvironmentService studyEnvironmentService;
private final SurveyResponseService surveyResponseService;
private final ParticipantTaskService participantTaskService;
private final KitRequestService kitRequestService;
Expand All @@ -55,7 +60,7 @@ public EnrolleeExportService(ProfileService profileService,
AnswerDao answerDao,
SurveyQuestionDefinitionDao surveyQuestionDefinitionDao,
StudyEnvironmentSurveyService studyEnvironmentSurveyService,
SurveyResponseService surveyResponseService,
SurveyService surveyService, StudyEnvironmentService studyEnvironmentService, SurveyResponseService surveyResponseService,
ParticipantTaskService participantTaskService,
KitRequestService kitRequestService,
ParticipantUserService participantUserService,
Expand All @@ -67,6 +72,8 @@ public EnrolleeExportService(ProfileService profileService,
this.answerDao = answerDao;
this.surveyQuestionDefinitionDao = surveyQuestionDefinitionDao;
this.studyEnvironmentSurveyService = studyEnvironmentSurveyService;
this.surveyService = surveyService;
this.studyEnvironmentService = studyEnvironmentService;
this.surveyResponseService = surveyResponseService;
this.participantTaskService = participantTaskService;
this.kitRequestService = kitRequestService;
Expand Down Expand Up @@ -163,6 +170,21 @@ public List<ModuleFormatter> generateModuleInfos(ExportOptions exportOptions, UU
* If multiple versions of a survey have been attached, those will be consolidated into a single ModuleExportInfo
*/
protected List<SurveyFormatter> generateSurveyModules(ExportOptions exportOptions, UUID studyEnvironmentId, List<EnrolleeExportData> enrolleeExportData) {
List<SurveyFormatter> moduleFormatters = new ArrayList<>();
// now add the pre-enrollment survey (if it exists)
StudyEnvironment studyEnvironment = studyEnvironmentService.find(studyEnvironmentId).orElseThrow();
if (studyEnvironment.getPreEnrollSurveyId() != null) {
Survey preEnrollSurvey = surveyService.find(studyEnvironment.getPreEnrollSurveyId()).orElseThrow();
List<SurveyQuestionDefinition> preEnrollSurveyQuestionDefinitions = surveyQuestionDefinitionDao.findAllBySurveyIds(List.of(preEnrollSurvey.getId()));
moduleFormatters.add(new SurveyFormatter(
exportOptions,
preEnrollSurvey.getStableId(),
List.of(preEnrollSurvey),
preEnrollSurveyQuestionDefinitions,
enrolleeExportData,
objectMapper));
}

// get all surveys that have ever been attached to the StudyEnvironment, including inactive ones
List<StudyEnvironmentSurvey> configuredSurveys = studyEnvironmentSurveyService.findAllByStudyEnvIdWithSurvey(studyEnvironmentId, null);
Map<String, List<StudyEnvironmentSurvey>> configuredSurveysByStableId = configuredSurveys.stream().collect(
Expand All @@ -177,7 +199,7 @@ protected List<SurveyFormatter> generateSurveyModules(ExportOptions exportOption
.toList();

// create one moduleExportInfo for each survey stableId.
List<SurveyFormatter> moduleFormatters = new ArrayList<>();

for (Map.Entry<String, List<StudyEnvironmentSurvey>> surveysOfStableId : sortedCfgSurveysByStableId) {
List<Survey> surveys = surveysOfStableId.getValue().stream().map(StudyEnvironmentSurvey::getSurvey).toList();
List<SurveyQuestionDefinition> surveyQuestionDefinitions = surveyQuestionDefinitionDao.findAllBySurveyIds(surveys.stream().map(Survey::getId).toList());
Expand All @@ -189,14 +211,12 @@ protected List<SurveyFormatter> generateSurveyModules(ExportOptions exportOption
enrolleeExportData,
objectMapper));
}

return moduleFormatters;
}

protected List<EnrolleeExportData> loadEnrolleesForExport(StudyEnvironmentConfig config,
List<Enrollee> enrollees) {


// for now, load each enrollee individually. Later we'll want more sophisticated batching strategies
return enrollees
.stream()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import bio.terra.pearl.core.service.participant.FamilyEnrolleeService;
import bio.terra.pearl.core.service.participant.FamilyService;
import bio.terra.pearl.core.service.workflow.ParticipantDataChangeService;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

Expand Down Expand Up @@ -64,7 +65,7 @@ public StudyEnvironmentService(StudyEnvironmentDao studyEnvironmentDao,
FamilyEnrolleeService familyEnrolleeService,
EnrolleeRelationService enrolleeRelationService,
ParticipantDataChangeService participantDataChangeService,
ExportIntegrationService exportIntegrationService) {
@Lazy ExportIntegrationService exportIntegrationService) {
super(studyEnvironmentDao);
this.studyEnvironmentSurveyDao = studyEnvironmentSurveyDao;
this.studyEnvironmentConfigService = studyEnvironmentConfigService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,12 @@ private void checkExportContent(UUID sandboxEnvironmentId) throws Exception {
List<Map<String, String>> exportData = enrolleeExportService.generateExportMaps(enrolleeExportData, moduleInfos);

assertThat(exportData, hasSize(13));
// confirm pre-enroll questions are included
Map<String, String> salkMap = exportData.stream().filter(map -> "HDSALK".equals(map.get("enrollee.shortcode")))
.findFirst().get();
assertThat(salkMap.get("hd_hd_preenroll.hd_hd_preenroll_livesInUS"), equalTo("Yes"));


Map<String, String> oldVersionMap = exportData.stream().filter(map -> "HDVERS".equals(map.get("enrollee.shortcode")))
.findFirst().get();
assertThat(oldVersionMap.get("account.username"), equalTo("oldversion@test.com"));
Expand Down
2 changes: 1 addition & 1 deletion ui-admin/src/study/export/ExportDataModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const DEFAULT_EXPORT_OPTS: ExportOptions = {
excludeModules: []
}

const MODULE_EXCLUDE_OPTIONS: Record<string, string> = { surveys: 'Surveys' }
const MODULE_EXCLUDE_OPTIONS: Record<string, string> = { surveys: 'Surveys', profile: 'Profile', account: 'Account' }

/** form for configuring and downloading enrollee data */
const ExportDataModal = ({ studyEnvContext, show, setShow }: {studyEnvContext: StudyEnvContextT, show: boolean,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ export default function ExportIntegrationList({ studyEnvContext }:
<Button variant="secondary" onClick={() => {
setShowCreateModal(false)
setNewIntegration(DEFAULT_EXPORT_INTEGRATION)
}}>Create</Button>
}}>Cancel</Button>
</Modal.Footer>
</Modal>

Expand Down

0 comments on commit 083d10d

Please sign in to comment.