diff --git a/pom.xml b/pom.xml
index 222100829..a8cdfd3a6 100644
--- a/pom.xml
+++ b/pom.xml
@@ -302,6 +302,9 @@
false
/tmp/atlas/audit/audit.log
/tmp/atlas/audit/audit-extra.log
+
+
+ false
@@ -1256,6 +1259,15 @@
2.0.1
test
+
+ com.squareup.okhttp3
+ okhttp
+ 4.12.0
+
+
+ com.fasterxml.jackson.datatype
+ jackson-datatype-jsr310
+
@@ -1895,5 +1907,107 @@
+
+ webapi-shiny
+
+ true
+ http://localhost/Atlas
+ src/main/resources/shiny
+
+ default,shiny
+
+
+
+
+ org.apache.maven.plugins
+ maven-clean-plugin
+ 3.3.2
+
+
+
+ ${shiny.output.directory}
+
+ shiny-cohortCounts.zip
+ shiny-incidenceRates.zip
+ shiny-cohortCharacterizations.zip
+
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-assembly-plugin
+ 3.6.0
+
+
+ build-cohortCounts-archive
+
+ single
+
+ generate-resources
+
+ false
+ ${shiny.app.directory}
+ ${shiny.output.directory}
+
+ src/main/assembly/shiny-cohortCounts.xml
+
+ shiny-cohortCounts
+
+
+
+ build-incidenceRates-archive
+
+ single
+
+ generate-resources
+
+ false
+ ${shiny.app.directory}
+ ${shiny.output.directory}
+
+ src/main/assembly/shiny-incidenceRates.xml
+
+ shiny-incidenceRates
+
+
+
+ build-cohortCharacterizations-archive
+
+ single
+
+ generate-resources
+
+ false
+ ${shiny.app.directory}
+ ${shiny.output.directory}
+
+ src/main/assembly/shiny-cohortCharacterizations.xml
+
+ shiny-cohortCharacterizations
+
+
+
+ build-cohortPathways-archive
+
+ single
+
+ generate-resources
+
+ false
+ ${shiny.app.directory}
+ ${shiny.output.directory}
+
+ src/main/assembly/shiny-cohortPathways.xml
+
+ shiny-cohortPathways
+
+
+
+
+
+
+
diff --git a/src/main/assembly/shiny-cohortCharacterizations.xml b/src/main/assembly/shiny-cohortCharacterizations.xml
new file mode 100644
index 000000000..359932716
--- /dev/null
+++ b/src/main/assembly/shiny-cohortCharacterizations.xml
@@ -0,0 +1,18 @@
+
+
+ shiny-cohortCharacterizations
+
+ zip
+
+ false
+
+
+ ./apps/cohortCharacterization
+
+ data/**
+
+ /
+
+
+
\ No newline at end of file
diff --git a/src/main/assembly/shiny-cohortCounts.xml b/src/main/assembly/shiny-cohortCounts.xml
new file mode 100644
index 000000000..5c43b81be
--- /dev/null
+++ b/src/main/assembly/shiny-cohortCounts.xml
@@ -0,0 +1,18 @@
+
+
+ shiny-cohortCounts
+
+ zip
+
+ false
+
+
+ ./apps/cohortCounts
+
+ data/**
+
+ /
+
+
+
\ No newline at end of file
diff --git a/src/main/assembly/shiny-cohortPathways.xml b/src/main/assembly/shiny-cohortPathways.xml
new file mode 100644
index 000000000..3dc1e0fba
--- /dev/null
+++ b/src/main/assembly/shiny-cohortPathways.xml
@@ -0,0 +1,18 @@
+
+
+ shiny-incidenceRates
+
+ zip
+
+ false
+
+
+ ./apps/cohortPathways
+
+ data/**
+
+ /
+
+
+
\ No newline at end of file
diff --git a/src/main/assembly/shiny-incidenceRates.xml b/src/main/assembly/shiny-incidenceRates.xml
new file mode 100644
index 000000000..0c03a906b
--- /dev/null
+++ b/src/main/assembly/shiny-incidenceRates.xml
@@ -0,0 +1,18 @@
+
+
+ shiny-incidenceRates
+
+ zip
+
+ false
+
+
+ ./apps/IncidenceRate
+
+ data/**
+
+ /
+
+
+
\ No newline at end of file
diff --git a/src/main/java/org/ohdsi/webapi/Constants.java b/src/main/java/org/ohdsi/webapi/Constants.java
index 2069ed108..7e1f07a4a 100644
--- a/src/main/java/org/ohdsi/webapi/Constants.java
+++ b/src/main/java/org/ohdsi/webapi/Constants.java
@@ -89,9 +89,13 @@ interface Variables {
}
interface Headers {
+ String ACCESS_CONTROL_EXPOSE_HEADERS = "Access-Control-Expose-Headers";
String AUTH_PROVIDER = "x-auth-provider";
String USER_LANGAUGE = "User-Language";
String ACTION_LOCATION = "action-location";
+ String BEARER = "Bearer";
+ String X_AUTH_ERROR = "x-auth-error";
+ String CONTENT_DISPOSITION = "Content-Disposition";
}
interface SecurityProviders {
diff --git a/src/main/java/org/ohdsi/webapi/JerseyConfig.java b/src/main/java/org/ohdsi/webapi/JerseyConfig.java
index eabc3f818..ba14ac91a 100644
--- a/src/main/java/org/ohdsi/webapi/JerseyConfig.java
+++ b/src/main/java/org/ohdsi/webapi/JerseyConfig.java
@@ -30,6 +30,7 @@
import org.ohdsi.webapi.service.TherapyPathResultsService;
import org.ohdsi.webapi.service.UserService;
import org.ohdsi.webapi.service.VocabularyService;
+import org.ohdsi.webapi.shiny.ShinyController;
import org.ohdsi.webapi.source.SourceController;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Value;
@@ -47,6 +48,8 @@ public class JerseyConfig extends ResourceConfig implements InitializingBean {
@Value("${jersey.resources.root.package}")
private String rootPackage;
+ @Value("${shiny.enabled:false}")
+ private Boolean shinyEnabled;
public JerseyConfig() {
RuntimeDelegate.setInstance(new org.glassfish.jersey.internal.RuntimeDelegateImpl());
@@ -94,5 +97,8 @@ protected void configure() {
.in(Singleton.class);
}
});
+ if (shinyEnabled) {
+ register(ShinyController.class);
+ }
}
}
diff --git a/src/main/java/org/ohdsi/webapi/pathway/PathwayController.java b/src/main/java/org/ohdsi/webapi/pathway/PathwayController.java
index fdd1c011d..dcf53b5cc 100644
--- a/src/main/java/org/ohdsi/webapi/pathway/PathwayController.java
+++ b/src/main/java/org/ohdsi/webapi/pathway/PathwayController.java
@@ -431,38 +431,7 @@ public String getGenerationDesign(
public PathwayPopulationResultsDTO getGenerationResults(
@PathParam("generationId") final Long generationId
) {
-
- PathwayAnalysisResult resultingPathways = pathwayService.getResultingPathways(generationId);
-
- List eventCodeDtos = resultingPathways.getCodes()
- .stream()
- .map(entry -> {
- PathwayCodeDTO dto = new PathwayCodeDTO();
- dto.setCode(entry.getCode());
- dto.setName(entry.getName());
- dto.setIsCombo(entry.isCombo());
- return dto;
- })
- .collect(Collectors.toList());
-
- List pathwayDtos = resultingPathways.getCohortPathwaysList()
- .stream()
- .map(cohortResults -> {
- if (cohortResults.getPathwaysCounts() == null) {
- return null;
- }
-
- List eventDTOs = cohortResults.getPathwaysCounts()
- .entrySet()
- .stream()
- .map(entry -> new PathwayPopulationEventDTO(entry.getKey(), entry.getValue()))
- .collect(Collectors.toList());
- return new TargetCohortPathwaysDTO(cohortResults.getCohortId(), cohortResults.getTargetCohortCount(), cohortResults.getTotalPathwaysCount(), eventDTOs);
- })
- .filter(Objects::nonNull)
- .collect(Collectors.toList());
-
- return new PathwayPopulationResultsDTO(eventCodeDtos, pathwayDtos);
+ return pathwayService.getGenerationResults(generationId);
}
private PathwayAnalysisDTO reloadAndConvert(Integer id) {
diff --git a/src/main/java/org/ohdsi/webapi/pathway/PathwayService.java b/src/main/java/org/ohdsi/webapi/pathway/PathwayService.java
index dcbd7785a..a3137ab18 100644
--- a/src/main/java/org/ohdsi/webapi/pathway/PathwayService.java
+++ b/src/main/java/org/ohdsi/webapi/pathway/PathwayService.java
@@ -4,6 +4,7 @@
import org.ohdsi.webapi.pathway.domain.PathwayAnalysisEntity;
import org.ohdsi.webapi.pathway.domain.PathwayAnalysisGenerationEntity;
import org.ohdsi.webapi.pathway.dto.PathwayAnalysisDTO;
+import org.ohdsi.webapi.pathway.dto.PathwayPopulationResultsDTO;
import org.ohdsi.webapi.pathway.dto.PathwayVersionFullDTO;
import org.ohdsi.webapi.pathway.dto.internal.PathwayAnalysisResult;
import org.ohdsi.webapi.shiro.annotations.PathwayAnalysisGenerationId;
@@ -69,4 +70,8 @@ public interface PathwayService extends HasTags {
PathwayVersion saveVersion(int id);
List listByTags(TagNameListRequestDTO requestDTO);
+
+ PathwayAnalysisDTO getByGenerationId(Integer id);
+
+ PathwayPopulationResultsDTO getGenerationResults(Long generationId);
}
diff --git a/src/main/java/org/ohdsi/webapi/pathway/PathwayServiceImpl.java b/src/main/java/org/ohdsi/webapi/pathway/PathwayServiceImpl.java
index dd4e62987..65dd22155 100644
--- a/src/main/java/org/ohdsi/webapi/pathway/PathwayServiceImpl.java
+++ b/src/main/java/org/ohdsi/webapi/pathway/PathwayServiceImpl.java
@@ -24,12 +24,17 @@
import org.ohdsi.webapi.pathway.domain.PathwayEventCohort;
import org.ohdsi.webapi.pathway.domain.PathwayTargetCohort;
import org.ohdsi.webapi.pathway.dto.PathwayAnalysisDTO;
+import org.ohdsi.webapi.pathway.dto.PathwayCodeDTO;
+import org.ohdsi.webapi.pathway.dto.PathwayPopulationEventDTO;
+import org.ohdsi.webapi.pathway.dto.PathwayPopulationResultsDTO;
import org.ohdsi.webapi.pathway.dto.PathwayVersionFullDTO;
+import org.ohdsi.webapi.pathway.dto.TargetCohortPathwaysDTO;
import org.ohdsi.webapi.pathway.dto.internal.CohortPathways;
import org.ohdsi.webapi.pathway.dto.internal.PathwayAnalysisResult;
import org.ohdsi.webapi.pathway.dto.internal.PathwayCode;
import org.ohdsi.webapi.pathway.repository.PathwayAnalysisEntityRepository;
import org.ohdsi.webapi.pathway.repository.PathwayAnalysisGenerationRepository;
+import org.ohdsi.webapi.security.PermissionService;
import org.ohdsi.webapi.service.AbstractDaoService;
import org.ohdsi.webapi.service.CohortDefinitionService;
import org.ohdsi.webapi.service.JobService;
@@ -63,9 +68,11 @@
import org.springframework.batch.core.job.builder.SimpleJobBuilder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
+import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.convert.ConversionService;
import org.springframework.core.convert.support.GenericConversionService;
import org.springframework.data.domain.Page;
+import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.Pageable;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.ResultSetExtractor;
@@ -96,613 +103,653 @@
import static org.ohdsi.webapi.Constants.Params.JOB_NAME;
import static org.ohdsi.webapi.Constants.Params.PATHWAY_ANALYSIS_ID;
import static org.ohdsi.webapi.Constants.Params.SOURCE_ID;
-import org.ohdsi.webapi.cohortcharacterization.domain.CohortCharacterizationEntity;
-import org.ohdsi.webapi.security.PermissionService;
-import org.springframework.beans.factory.annotation.Value;
-import org.springframework.data.domain.PageImpl;
@Service
@Transactional
public class PathwayServiceImpl extends AbstractDaoService implements PathwayService, GeneratesNotification {
- private final PathwayAnalysisEntityRepository pathwayAnalysisRepository;
- private final PathwayAnalysisGenerationRepository pathwayAnalysisGenerationRepository;
- private final SourceService sourceService;
- private final JobTemplate jobTemplate;
- private final EntityManager entityManager;
- private final DesignImportService designImportService;
- private final AnalysisGenerationInfoEntityRepository analysisGenerationInfoEntityRepository;
- private final UserRepository userRepository;
- private final GenerationUtils generationUtils;
- private final JobService jobService;
- private final GenericConversionService genericConversionService;
- private final StepBuilderFactory stepBuilderFactory;
- private final CohortDefinitionService cohortDefinitionService;
- private final VersionService versionService;
-
- private PermissionService permissionService;
-
- @Value("${security.defaultGlobalReadPermissions}")
- private boolean defaultGlobalReadPermissions;
-
- private final List STEP_COLUMNS = Arrays.asList(new String[]{"step_1", "step_2", "step_3", "step_4", "step_5", "step_6", "step_7", "step_8", "step_9", "step_10"});
-
- private final EntityGraph defaultEntityGraph = EntityUtils.fromAttributePaths(
- "targetCohorts.cohortDefinition",
- "eventCohorts.cohortDefinition",
- "createdBy",
- "modifiedBy"
- );
-
- @Autowired
- public PathwayServiceImpl(
- PathwayAnalysisEntityRepository pathwayAnalysisRepository,
- PathwayAnalysisGenerationRepository pathwayAnalysisGenerationRepository,
- SourceService sourceService,
- ConversionService conversionService,
- JobTemplate jobTemplate,
- EntityManager entityManager,
- Security security,
- DesignImportService designImportService,
- AnalysisGenerationInfoEntityRepository analysisGenerationInfoEntityRepository,
- UserRepository userRepository,
- GenerationUtils generationUtils,
- JobService jobService,
- @Qualifier("conversionService") GenericConversionService genericConversionService,
- StepBuilderFactory stepBuilderFactory,
- CohortDefinitionService cohortDefinitionService,
- VersionService versionService,
- PermissionService permissionService) {
-
- this.pathwayAnalysisRepository = pathwayAnalysisRepository;
- this.pathwayAnalysisGenerationRepository = pathwayAnalysisGenerationRepository;
- this.sourceService = sourceService;
- this.jobTemplate = jobTemplate;
- this.entityManager = entityManager;
- this.jobService = jobService;
- this.genericConversionService = genericConversionService;
- this.security = security;
- this.designImportService = designImportService;
- this.analysisGenerationInfoEntityRepository = analysisGenerationInfoEntityRepository;
- this.userRepository = userRepository;
- this.generationUtils = generationUtils;
- this.stepBuilderFactory = stepBuilderFactory;
- this.cohortDefinitionService = cohortDefinitionService;
- this.versionService = versionService;
- this.permissionService = permissionService;
-
- SerializedPathwayAnalysisToPathwayAnalysisConverter.setConversionService(conversionService);
- }
-
- @Override
- public PathwayAnalysisEntity create(PathwayAnalysisEntity toSave) {
-
- PathwayAnalysisEntity newAnalysis = new PathwayAnalysisEntity();
-
- copyProps(toSave, newAnalysis);
-
- toSave.getTargetCohorts().forEach(tc -> {
- tc.setId(null);
- tc.setPathwayAnalysis(newAnalysis);
- newAnalysis.getTargetCohorts().add(tc);
- });
-
- toSave.getEventCohorts().forEach(ec -> {
- ec.setId(null);
- ec.setPathwayAnalysis(newAnalysis);
- newAnalysis.getEventCohorts().add(ec);
- });
-
- newAnalysis.setCreatedBy(getCurrentUser());
- newAnalysis.setCreatedDate(new Date());
- // Fields with information about modifications have to be reseted
- newAnalysis.setModifiedBy(null);
- newAnalysis.setModifiedDate(null);
- return save(newAnalysis);
- }
-
- @Override
- public PathwayAnalysisEntity importAnalysis(PathwayAnalysisEntity toImport) {
-
- PathwayAnalysisEntity newAnalysis = new PathwayAnalysisEntity();
-
- copyProps(toImport, newAnalysis);
-
- Stream.concat(toImport.getTargetCohorts().stream(), toImport.getEventCohorts().stream()).forEach(pc -> {
- CohortDefinition cohortDefinition = designImportService.persistCohortOrGetExisting(pc.getCohortDefinition());
- pc.setId(null);
- pc.setName(cohortDefinition.getName());
- pc.setCohortDefinition(cohortDefinition);
- pc.setPathwayAnalysis(newAnalysis);
- if (pc instanceof PathwayTargetCohort) {
- newAnalysis.getTargetCohorts().add((PathwayTargetCohort) pc);
- } else {
- newAnalysis.getEventCohorts().add((PathwayEventCohort) pc);
- }
- });
-
- newAnalysis.setCreatedBy(getCurrentUser());
- newAnalysis.setCreatedDate(new Date());
-
- return save(newAnalysis);
- }
-
- @Override
- public Page getPage(final Pageable pageable) {
- List pathwayList = pathwayAnalysisRepository.findAll(defaultEntityGraph)
- .stream().filter(!defaultGlobalReadPermissions ? entity -> permissionService.hasReadAccess(entity) : entity -> true)
- .collect(Collectors.toList());
- return getPageFromResults(pageable, pathwayList);
- }
-
- private Page getPageFromResults(Pageable pageable, List results) {
- // Calculate the start and end indices for the current page
- int startIndex = pageable.getPageNumber() * pageable.getPageSize();
- int endIndex = Math.min(startIndex + pageable.getPageSize(), results.size());
-
- return new PageImpl<>(results.subList(startIndex, endIndex), pageable, results.size());
- }
-
- @Override
- public int getCountPAWithSameName(Integer id, String name) {
-
- return pathwayAnalysisRepository.getCountPAWithSameName(id, name);
- }
-
- @Override
- public PathwayAnalysisEntity getById(Integer id) {
-
- PathwayAnalysisEntity entity = pathwayAnalysisRepository.findOne(id, defaultEntityGraph);
- if (Objects.nonNull(entity)) {
- entity.getTargetCohorts().forEach(tc -> Hibernate.initialize(tc.getCohortDefinition().getDetails()));
- entity.getEventCohorts().forEach(ec -> Hibernate.initialize(ec.getCohortDefinition().getDetails()));
- }
- return entity;
- }
-
- private List getNamesLike(String name) {
-
- return pathwayAnalysisRepository.findAllByNameStartsWith(name).stream().map(PathwayAnalysisEntity::getName).collect(Collectors.toList());
- }
-
- @Override
- public String getNameForCopy(String dtoName) {
- return NameUtils.getNameForCopy(dtoName, this::getNamesLike, pathwayAnalysisRepository.findByName(dtoName));
- }
-
- @Override
- public String getNameWithSuffix(String dtoName) {
- return NameUtils.getNameWithSuffix(dtoName, this::getNamesLike);
- }
-
- @Override
- public PathwayAnalysisEntity update(PathwayAnalysisEntity forUpdate) {
-
- PathwayAnalysisEntity existing = getById(forUpdate.getId());
-
- copyProps(forUpdate, existing);
- updateCohorts(existing, existing.getTargetCohorts(), forUpdate.getTargetCohorts());
- updateCohorts(existing, existing.getEventCohorts(), forUpdate.getEventCohorts());
-
- existing.setModifiedBy(getCurrentUser());
- existing.setModifiedDate(new Date());
-
- return save(existing);
- }
-
- private void updateCohorts(PathwayAnalysisEntity analysis, Set existing, Set forUpdate) {
-
- Set removedCohorts = existing
- .stream()
- .filter(ec -> !forUpdate.contains(ec))
- .collect(Collectors.toSet());
- existing.removeAll(removedCohorts);
- forUpdate.forEach(updatedCohort -> existing.stream()
- .filter(ec -> ec.equals(updatedCohort))
- .findFirst()
- .map(ec -> {
- ec.setName(updatedCohort.getName());
- return ec;
- })
- .orElseGet(() -> {
- updatedCohort.setId(null);
- updatedCohort.setPathwayAnalysis(analysis);
- existing.add(updatedCohort);
- return updatedCohort;
- }));
- }
-
- @Override
- public void delete(Integer id) {
-
- pathwayAnalysisRepository.delete(id);
- }
-
- @Override
- public Map getEventCohortCodes(PathwayAnalysisEntity pathwayAnalysis) {
-
- Integer index = 0;
-
- List sortedEventCohortsCopy = pathwayAnalysis.getEventCohorts()
- .stream()
- .sorted(Comparator.comparing(PathwayEventCohort::getName))
- .collect(Collectors.toList());
-
- Map cohortDefIdToIndexMap = new HashMap<>();
-
- for (PathwayEventCohort eventCohort : sortedEventCohortsCopy) {
- cohortDefIdToIndexMap.put(eventCohort.getCohortDefinition().getId(), index++);
- }
-
- return cohortDefIdToIndexMap;
- }
-
- @Override
- @DataSourceAccess
- public String buildAnalysisSql(Long generationId, PathwayAnalysisEntity pathwayAnalysis, @SourceId Integer sourceId, String cohortTable, String sessionId) {
-
- Map eventCohortCodes = getEventCohortCodes(pathwayAnalysis);
- Source source = sourceService.findBySourceId(sourceId);
- final StringJoiner joiner = new StringJoiner("\n\n");
-
- String analysisSql = ResourceHelper.GetResourceAsString("/resources/pathway/runPathwayAnalysis.sql");
- String eventCohortInputSql = ResourceHelper.GetResourceAsString("/resources/pathway/eventCohortInput.sql");
-
- String tempTableQualifier = SourceUtils.getTempQualifier(source);
- String resultsTableQualifier = SourceUtils.getResultsQualifier(source);
-
- String eventCohortIdIndexSql = eventCohortCodes.entrySet()
- .stream()
- .map(ec -> {
- String[] params = new String[]{"cohort_definition_id", "event_cohort_index"};
- String[] values = new String[]{ec.getKey().toString(), ec.getValue().toString()};
- return SqlRender.renderSql(eventCohortInputSql, params, values);
- })
- .collect(Collectors.joining(" UNION ALL "));
-
- pathwayAnalysis.getTargetCohorts().forEach(tc -> {
-
- String[] params = new String[]{
- GENERATION_ID,
- "event_cohort_id_index_map",
- "temp_database_schema",
- "target_database_schema",
- "target_cohort_table",
- "pathway_target_cohort_id",
- "max_depth",
- "combo_window",
- "allow_repeats",
- "isHive"
- };
- String[] values = new String[]{
- generationId.toString(),
- eventCohortIdIndexSql,
- tempTableQualifier,
- resultsTableQualifier,
- cohortTable,
- tc.getCohortDefinition().getId().toString(),
- pathwayAnalysis.getMaxDepth().toString(),
- MoreObjects.firstNonNull(pathwayAnalysis.getCombinationWindow(), 1).toString(),
- String.valueOf(pathwayAnalysis.isAllowRepeats()),
- String.valueOf(Objects.equals(DBMSType.HIVE.getOhdsiDB(), source.getSourceDialect()))
- };
-
- String renderedSql = SqlRender.renderSql(analysisSql, params, values);
- String translatedSql = SqlTranslate.translateSql(renderedSql, source.getSourceDialect(), sessionId, SourceUtils.getTempQualifier(source));
-
- joiner.add(translatedSql);
- });
-
- return joiner.toString();
- }
-
- @Override
- public String buildAnalysisSql(Long generationId, PathwayAnalysisEntity pathwayAnalysis, Integer sourceId) {
-
- return buildAnalysisSql(generationId, pathwayAnalysis, sourceId, "cohort", SessionUtils.sessionId());
- }
-
- @Override
- @DataSourceAccess
- public JobExecutionResource generatePathways(final Integer pathwayAnalysisId, final @SourceId Integer sourceId) {
-
- PathwayService pathwayService = this;
-
- PathwayAnalysisEntity pathwayAnalysis = getById(pathwayAnalysisId);
- Source source = getSourceRepository().findBySourceId(sourceId);
-
- JobParametersBuilder builder = new JobParametersBuilder();
- builder.addString(JOB_NAME, String.format("Generating Pathway Analysis %d using %s (%s)", pathwayAnalysisId, source.getSourceName(), source.getSourceKey()));
- builder.addString(SOURCE_ID, String.valueOf(source.getSourceId()));
- builder.addString(PATHWAY_ANALYSIS_ID, pathwayAnalysis.getId().toString());
- builder.addString(JOB_AUTHOR, getCurrentUserLogin());
-
- JdbcTemplate jdbcTemplate = getSourceJdbcTemplate(source);
-
- SimpleJobBuilder generateAnalysisJob = generationUtils.buildJobForCohortBasedAnalysisTasklet(
- GENERATE_PATHWAY_ANALYSIS,
- source,
- builder,
- jdbcTemplate,
- chunkContext -> {
- Integer analysisId = Integer.valueOf(chunkContext.getStepContext().getJobParameters().get(PATHWAY_ANALYSIS_ID).toString());
- PathwayAnalysisEntity analysis = pathwayService.getById(analysisId);
- return Stream.concat(analysis.getTargetCohorts().stream(), analysis.getEventCohorts().stream())
- .map(PathwayCohort::getCohortDefinition)
- .collect(Collectors.toList());
- },
- new GeneratePathwayAnalysisTasklet(
- getSourceJdbcTemplate(source),
- getTransactionTemplate(),
- pathwayService,
- analysisGenerationInfoEntityRepository,
- userRepository,
- sourceService
- )
- );
- TransactionalTasklet statisticsTasklet = new PathwayStatisticsTasklet(getSourceJdbcTemplate(source), getTransactionTemplate(), source, this, genericConversionService);
- Step generateStatistics = stepBuilderFactory.get(GENERATE_PATHWAY_ANALYSIS + ".generateStatistics")
- .tasklet(statisticsTasklet)
- .build();
-
- generateAnalysisJob.next(generateStatistics);
-
- final JobParameters jobParameters = builder.toJobParameters();
-
- return jobService.runJob(generateAnalysisJob.build(), jobParameters);
- }
-
- @Override
- @DataSourceAccess
- public void cancelGeneration(Integer pathwayAnalysisId, @SourceId Integer sourceId) {
-
- PathwayAnalysisEntity entity = pathwayAnalysisRepository.findOne(pathwayAnalysisId, defaultEntityGraph);
- String sourceKey = getSourceRepository().findBySourceId(sourceId).getSourceKey();
- entity.getTargetCohorts().forEach(tc -> cohortDefinitionService.cancelGenerateCohort(tc.getId(), sourceKey));
- entity.getEventCohorts().forEach(ec -> cohortDefinitionService.cancelGenerateCohort(ec.getId(), sourceKey));
- jobService.cancelJobExecution(j -> {
- JobParameters jobParameters = j.getJobParameters();
- String jobName = j.getJobInstance().getJobName();
- return Objects.equals(jobParameters.getString(PATHWAY_ANALYSIS_ID), Integer.toString(pathwayAnalysisId))
- && Objects.equals(jobParameters.getString(SOURCE_ID), String.valueOf(sourceId))
- && Objects.equals(GENERATE_PATHWAY_ANALYSIS, jobName);
- });
- }
-
- @Override
- public List getPathwayGenerations(final Integer pathwayAnalysisId) {
-
- return pathwayAnalysisGenerationRepository.findAllByPathwayAnalysisId(pathwayAnalysisId, EntityUtils.fromAttributePaths("source"));
- }
-
- @Override
- public PathwayAnalysisGenerationEntity getGeneration(Long generationId) {
-
- return pathwayAnalysisGenerationRepository.findOne(generationId, EntityUtils.fromAttributePaths("source"));
- }
-
- @Override
- @DataSourceAccess
- public PathwayAnalysisResult getResultingPathways(final @PathwayAnalysisGenerationId Long generationId) {
-
- PathwayAnalysisGenerationEntity generation = getGeneration(generationId);
- Source source = generation.getSource();
- return queryGenerationResults(source, generationId);
- }
-
- private final RowMapper codeRowMapper = (final ResultSet resultSet, final int arg1) -> {
- return new PathwayCode(resultSet.getLong("code"), resultSet.getString("name"), resultSet.getInt("is_combo") != 0);
- };
-
- private final RowMapper pathwayStatsRowMapper = (final ResultSet rs, final int arg1) -> {
- CohortPathways cp = new CohortPathways();
- cp.setCohortId(rs.getInt("target_cohort_id"));
- cp.setTargetCohortCount(rs.getInt("target_cohort_count"));
- cp.setTotalPathwaysCount(rs.getInt("pathways_count"));
- return cp;
- };
-
- private final ResultSetExtractor