From 41d1841108d10f8862daf8b887e0baaca746b076 Mon Sep 17 00:00:00 2001 From: Vitaly Koulakov Date: Thu, 21 Mar 2019 19:20:28 +0300 Subject: [PATCH 1/9] WebAPI-975 Extract Cohort Characterization analysis to external package --- pom.xml | 7 +- .../cohortcharacterization/CcResultType.java | 6 - .../cohortcharacterization/CcServiceImpl.java | 3 +- ...GenerateCohortCharacterizationTasklet.java | 509 ++---------------- .../converter/BaseCcToCcDTOConverter.java | 2 +- .../domain/CcParamEntity.java | 2 +- .../domain/CcStrataEntity.java | 5 +- .../domain/CohortCharacterizationEntity.java | 3 +- .../cohortcharacterization/dto/CcResult.java | 3 +- .../feanalysis/FeAnalysisDeserializer.java | 2 +- .../feanalysis/FeAnalysisServiceImpl.java | 2 +- ...DTOToFeAnalysisWithCriteriasConverter.java | 2 +- ...nalysisShortDTOToFeaAnalysisConverter.java | 2 +- .../domain/FeAnalysisCriteriaEntity.java | 3 +- .../FeAnalysisDemographicCriteriaEntity.java | 3 +- .../feanalysis/domain/FeAnalysisEntity.java | 4 +- .../FeAnalysisWindowedCriteriaEntity.java | 3 +- .../domain/FeAnalysisWithCriteriaEntity.java | 3 +- .../domain/FeAnalysisWithStringEntity.java | 1 + .../feanalysis/dto/FeAnalysisShortDTO.java | 2 +- .../org/ohdsi/webapi/model/CommonEntity.java | 3 +- .../java/org/ohdsi/webapi/model/WithId.java | 6 - .../sql/customDistribution.sql | 44 -- .../sql/customPrevalence.sql | 28 - .../sql/distributionRetrieving.sql | 29 - .../sql/distributionWithCriteria.sql | 91 ---- .../sql/prevalenceRetrieving.sql | 20 - .../sql/prevalenceWithCriteria.sql | 27 - .../sql/strataWithCriteria.sql | 17 - 29 files changed, 79 insertions(+), 753 deletions(-) delete mode 100644 src/main/java/org/ohdsi/webapi/cohortcharacterization/CcResultType.java delete mode 100644 src/main/java/org/ohdsi/webapi/model/WithId.java delete mode 100644 src/main/resources/resources/cohortcharacterizations/sql/customDistribution.sql delete mode 100644 src/main/resources/resources/cohortcharacterizations/sql/customPrevalence.sql delete mode 100644 src/main/resources/resources/cohortcharacterizations/sql/distributionRetrieving.sql delete mode 100644 src/main/resources/resources/cohortcharacterizations/sql/distributionWithCriteria.sql delete mode 100644 src/main/resources/resources/cohortcharacterizations/sql/prevalenceRetrieving.sql delete mode 100644 src/main/resources/resources/cohortcharacterizations/sql/prevalenceWithCriteria.sql delete mode 100644 src/main/resources/resources/cohortcharacterizations/sql/strataWithCriteria.sql diff --git a/pom.xml b/pom.xml index 7bdf189214..5cf450b412 100644 --- a/pom.xml +++ b/pom.xml @@ -704,7 +704,12 @@ org.ohdsi standardized-analysis-api - 1.1.0-SNAPSHOT + 1.1.1-SNAPSHOT + + + org.ohdsi + SkeletonCohortCharacterization + 1.0.0-SNAPSHOT com.cosium.spring.data diff --git a/src/main/java/org/ohdsi/webapi/cohortcharacterization/CcResultType.java b/src/main/java/org/ohdsi/webapi/cohortcharacterization/CcResultType.java deleted file mode 100644 index 295ec1e5a5..0000000000 --- a/src/main/java/org/ohdsi/webapi/cohortcharacterization/CcResultType.java +++ /dev/null @@ -1,6 +0,0 @@ -package org.ohdsi.webapi.cohortcharacterization; - -public enum CcResultType { - PREVALENCE, - DISTRIBUTION -} diff --git a/src/main/java/org/ohdsi/webapi/cohortcharacterization/CcServiceImpl.java b/src/main/java/org/ohdsi/webapi/cohortcharacterization/CcServiceImpl.java index 52a03c6951..f7870d3075 100644 --- a/src/main/java/org/ohdsi/webapi/cohortcharacterization/CcServiceImpl.java +++ b/src/main/java/org/ohdsi/webapi/cohortcharacterization/CcServiceImpl.java @@ -3,6 +3,8 @@ import com.cosium.spring.data.jpa.entity.graph.domain.EntityGraph; import com.google.common.collect.ImmutableList; import org.apache.commons.lang3.StringUtils; +import org.ohdsi.analysis.WithId; +import org.ohdsi.analysis.cohortcharacterization.design.CcResultType; import org.ohdsi.analysis.cohortcharacterization.design.CohortCharacterization; import org.ohdsi.analysis.cohortcharacterization.design.StandardFeatureAnalysisType; import org.ohdsi.circe.helper.ResourceHelper; @@ -23,7 +25,6 @@ import org.ohdsi.webapi.job.GeneratesNotification; import org.ohdsi.webapi.job.JobExecutionResource; import org.ohdsi.webapi.job.JobTemplate; -import org.ohdsi.webapi.model.WithId; import org.ohdsi.webapi.service.*; import org.ohdsi.webapi.shiro.annotations.CcGenerationId; import org.ohdsi.webapi.shiro.annotations.DataSourceAccess; diff --git a/src/main/java/org/ohdsi/webapi/cohortcharacterization/GenerateCohortCharacterizationTasklet.java b/src/main/java/org/ohdsi/webapi/cohortcharacterization/GenerateCohortCharacterizationTasklet.java index 1bccc666ff..87a339f046 100644 --- a/src/main/java/org/ohdsi/webapi/cohortcharacterization/GenerateCohortCharacterizationTasklet.java +++ b/src/main/java/org/ohdsi/webapi/cohortcharacterization/GenerateCohortCharacterizationTasklet.java @@ -17,20 +17,12 @@ import com.google.common.collect.ImmutableList; import com.odysseusinc.arachne.commons.types.DBMSType; -import org.apache.commons.lang3.ArrayUtils; -import org.apache.commons.lang3.StringUtils; -import org.eclipse.collections.impl.factory.Lists; -import org.json.JSONObject; -import org.ohdsi.analysis.cohortcharacterization.design.StandardFeatureAnalysisType; import org.ohdsi.circe.cohortdefinition.*; import org.ohdsi.circe.helper.ResourceHelper; -import org.ohdsi.featureExtraction.FeatureExtraction; -import org.ohdsi.sql.SqlRender; +import org.ohdsi.cohortcharacterization.CCQueryBuilder; import org.ohdsi.sql.SqlSplit; import org.ohdsi.sql.SqlTranslate; import org.ohdsi.webapi.cohortcharacterization.converter.SerializedCcToCcConverter; -import org.ohdsi.webapi.cohortcharacterization.domain.CcParamEntity; -import org.ohdsi.webapi.cohortcharacterization.domain.CcStrataEntity; import org.ohdsi.webapi.cohortcharacterization.domain.CohortCharacterizationEntity; import org.ohdsi.webapi.cohortcharacterization.repository.AnalysisGenerationInfoEntityRepository; import org.ohdsi.webapi.common.generation.AnalysisTasklet; @@ -43,17 +35,11 @@ import org.ohdsi.webapi.util.*; import org.slf4j.LoggerFactory; import org.springframework.batch.core.scope.context.ChunkContext; -import org.springframework.jdbc.core.PreparedStatementCreator; -import org.springframework.jdbc.core.PreparedStatementSetter; -import org.springframework.jdbc.core.SqlProvider; import org.springframework.transaction.TransactionDefinition; import org.springframework.transaction.TransactionStatus; import org.springframework.transaction.support.DefaultTransactionDefinition; import org.springframework.transaction.support.TransactionTemplate; -import java.sql.Connection; -import java.sql.PreparedStatement; -import java.sql.SQLException; import java.util.*; import java.util.function.Function; import java.util.stream.Collectors; @@ -113,8 +99,50 @@ protected void doBefore(ChunkContext chunkContext) { } @Override - protected List prepareStatementCreators(ChunkContext chunkContext, CancelableJdbcTemplate jdbcTemplate) { - return new CcTask(chunkContext).run(); + protected String[] prepareQueries(ChunkContext chunkContext, CancelableJdbcTemplate jdbcTemplate) { + Map jobParams = chunkContext.getStepContext().getJobParameters(); + CohortCharacterizationEntity cohortCharacterization = ccService.findByIdWithLinkedEntities( + Long.valueOf(jobParams.get(COHORT_CHARACTERIZATION_ID).toString()) + ); + final Long jobId = chunkContext.getStepContext().getStepExecution().getJobExecution().getId(); + final UserEntity userEntity = userRepository.findByLogin(jobParams.get(JOB_AUTHOR).toString()); + saveInfo(jobId, new SerializedCcToCcConverter().convertToDatabaseColumn(cohortCharacterization), userEntity); + final Integer sourceId = Integer.valueOf(jobParams.get(SOURCE_ID).toString()); + final Source source = sourceService.findBySourceId(sourceId); + final String cohortTable = jobParams.get(TARGET_TABLE).toString(); + final String sessionId = jobParams.get(SESSION_ID).toString(); + final String tempSchema = SourceUtils.getTempQualifier(source); + CCQueryBuilder ccQueryBuilder = new CCQueryBuilder(cohortCharacterization, cohortTable, sessionId, + SourceUtils.getCdmQualifier(source), SourceUtils.getResultsQualifier(source), + SourceUtils.getVocabularyQualifier(source), tempSchema, + jobId, feAnalysisService.findAllPresetAnalyses().stream().map(FeAnalysisWithStringEntity::getDesign).collect(Collectors.toList())); + String sql = ccQueryBuilder.build(); + + /* + * There is an issue with temp tables on sql server: Temp tables scope is session or stored procedure. + * To execute PreparedStatement sql server uses stored procedure sp_executesql + * and this is the reason why multiple PreparedStatements cannot share the same local temporary table. + * + * On the other side, temp tables cannot be re-used in the same PreparedStatement, e.g. temp table cannot be created, used, dropped + * and created again in the same PreparedStatement because sql optimizator detects object already exists and fails. + * When is required to re-use temp table it should be separated to several PreparedStatements. + * + * An option to use global temp tables also doesn't work since such tables can be not supported / disabled. + * + * Therefore, there are two ways: + * - either precisely group SQLs into statements so that temp tables aren't re-used in a single statement, + * - or use ‘permenant temporary tables’ + * + * The second option looks better since such SQL could be exported and executed manually, + * which is not the case with the first option. + */ + if (ImmutableList.of(DBMSType.MS_SQL_SERVER.getOhdsiDB(), DBMSType.PDW.getOhdsiDB()).contains(source.getSourceDialect())) { + sql = sql + .replaceAll("#", tempSchema + "." + sessionId + "_") + .replaceAll("tempdb\\.\\.", ""); + } + final String translatedSql = SqlTranslate.translateSql(sql, source.getSourceDialect()); + return SqlSplit.splitSql(translatedSql); } private void initTx() { @@ -124,451 +152,4 @@ private void initTx() { this.transactionTemplate.getTransactionManager().commit(initStatus); } - private class CcTask { - - final String prevalenceRetrievingQuery = ResourceHelper.GetResourceAsString("/resources/cohortcharacterizations/sql/prevalenceRetrieving.sql"); - - final String distributionRetrievingQuery = ResourceHelper.GetResourceAsString("/resources/cohortcharacterizations/sql/distributionRetrieving.sql"); - - final String customDistributionQueryWrapper = ResourceHelper.GetResourceAsString("/resources/cohortcharacterizations/sql/customDistribution.sql"); - - final String customPrevalenceQueryWrapper = ResourceHelper.GetResourceAsString("/resources/cohortcharacterizations/sql/customPrevalence.sql"); - - final CohortCharacterizationEntity cohortCharacterization; - final Source source; - final UserEntity userEntity; - final String cohortTable; - final String sessionId; - - private final Long jobId; - private final Integer sourceId; - - CcTask(final ChunkContext context) { - Map jobParams = context.getStepContext().getJobParameters(); - this.cohortCharacterization = ccService.findByIdWithLinkedEntities( - Long.valueOf(jobParams.get(COHORT_CHARACTERIZATION_ID).toString()) - ); - this.jobId = context.getStepContext().getStepExecution().getJobExecution().getId(); - sourceId = Integer.valueOf(jobParams.get(SOURCE_ID).toString()); - this.source = sourceService.findBySourceId(sourceId); - this.cohortTable = jobParams.get(TARGET_TABLE).toString(); - this.userEntity = userRepository.findByLogin(jobParams.get(JOB_AUTHOR).toString()); - this.sessionId = jobParams.get(SESSION_ID).toString(); - } - - private List run() { - - saveInfo(jobId, new SerializedCcToCcConverter().convertToDatabaseColumn(cohortCharacterization), userEntity); - return cohortCharacterization.getCohortDefinitions() - .stream() - .map(def -> getAnalysisQueriesOnCohort(def.getId())) - .flatMap(Collection::stream) - .collect(Collectors.toList()); - } - - private List getAnalysisQueriesOnCohort(final Integer cohortDefinitionId) { - - final CohortExpressionQueryBuilder.BuildExpressionQueryOptions options = createDefaultOptions(cohortDefinitionId); - return getSqlQueriesToRun(createFeJsonObject(options, options.resultSchema + "." + cohortTable), cohortDefinitionId); - } - - private String renderCustomAnalysisDesign(FeAnalysisWithStringEntity fa, Integer cohortId) { - Map params = cohortCharacterization.getParameters().stream().collect(Collectors.toMap(CcParamEntity::getName, CcParamEntity::getValue)); - params.put("cdm_database_schema", SourceUtils.getCdmQualifier(source)); - params.put("cohort_table", SourceUtils.getTempQualifier(source) + "." + cohortTable); - params.put("cohort_id", cohortId.toString()); - params.put("analysis_id", fa.getId().toString()); - - return SqlRender.renderSql( - fa.getDesign(), - params.keySet().toArray(new String[params.size()]), - params.values().toArray(new String[params.size()]) - ); - } - - private List getQueriesForCustomDistributionAnalyses(final Integer cohortId) { - String[] sqlParamNames = new String[]{ "strataId", "strataName" }; - Object[] sqlParamVars = new Object[]{ null, null }; - - return cohortCharacterization.getFeatureAnalyses() - .stream() - .filter(FeAnalysisEntity::isCustom) - .filter(v -> v.getStatType() == CcResultType.DISTRIBUTION) - .flatMap(v -> prepareStatements(customDistributionQueryWrapper, sessionId, - CUSTOM_PARAMETERS, - new String[] { String.valueOf(v.getId()), v.getName(), String.valueOf(cohortId), String.valueOf(jobId), renderCustomAnalysisDesign((FeAnalysisWithStringEntity) v, cohortId) }, sqlParamNames, sqlParamVars).stream()) - .collect(Collectors.toList()); - } - - private List getQueriesForCustomPrevalenceAnalyses(final Integer cohortId) { - String[] sqlParamNames = new String[]{ "strataId", "strataName" }; - Object[] sqlParamVars = new Object[]{ null, null }; - - return cohortCharacterization.getFeatureAnalyses() - .stream() - .filter(FeAnalysisEntity::isCustom) - .filter(v -> v.getStatType() == CcResultType.PREVALENCE) - .flatMap(v -> prepareStatements(customPrevalenceQueryWrapper, sessionId, - CUSTOM_PARAMETERS, - new String[] { String.valueOf(v.getId()), v.getName(), String.valueOf(cohortId), String.valueOf(jobId), renderCustomAnalysisDesign((FeAnalysisWithStringEntity) v, cohortId) }, sqlParamNames, sqlParamVars).stream()) - .collect(Collectors.toList()); - } - - private List getQueriesForCriteriaAnalyses(Integer cohortDefinitionId, CcStrataEntity strata) { - List queries = new ArrayList<>(); - List analysesWithCriteria = getFeAnalysesWithCriteria(); - if (!analysesWithCriteria.isEmpty()) { - String cohortTable = Objects.nonNull(strata) ? getStrataCohortTable(strata) : SourceUtils.getTempQualifier(source) + "." + this.cohortTable; - analysesWithCriteria.stream() - .map(analysis -> getCriteriaFeaturesQueries(cohortDefinitionId, analysis, cohortTable, strata)) - .flatMap(Collection::stream) - .forEach(queries::add); - } - return queries; - } - - private List getFeAnalysesWithCriteria() { - - return cohortCharacterization.getFeatureAnalyses().stream() - .filter(fa -> StandardFeatureAnalysisType.CRITERIA_SET.equals(fa.getType())) - .map(fa -> (FeAnalysisWithCriteriaEntity)fa) - .collect(Collectors.toList()); - } - - private List getQueriesForPresetAnalyses(final JSONObject jsonObject, final Integer cohortId, final CcStrataEntity strata) { - final String cohortWrapper = "select %1$d as %2$s from (%3$s) W"; - - final String featureRefColumns = "cohort_definition_id, covariate_id, covariate_name, analysis_id, concept_id"; - final String featureRefs = String.format(cohortWrapper, cohortId, featureRefColumns, - StringUtils.stripEnd(jsonObject.getString("sqlQueryFeatureRef"), ";")); - - final String analysisRefColumns = "cohort_definition_id, CAST(analysis_id AS INT) analysis_id, analysis_name, domain_id, start_day, end_day, CAST(is_binary AS CHAR(1)) is_binary,CAST(missing_means_zero AS CHAR(1)) missing_means_zero"; - final String analysisRefs = String.format(cohortWrapper, cohortId, analysisRefColumns, - StringUtils.stripEnd(jsonObject.getString("sqlQueryAnalysisRef"), ";")); - - final List queries = new ArrayList<>(); - - Long strataId = Objects.nonNull(strata) ? strata.getId() : null; - String strataName = Objects.nonNull(strata) ? strata.getName() : null; - - String[] sqlParamNames = new String[]{ "strataId", "strataName" }; - Object[] sqlParamVars = new Object[]{ strataId, strataName }; - - if (ccHasPresetDistributionAnalyses()) { - final String distColumns = "cohort_definition_id, covariate_id, count_value, min_value, max_value, average_value, " - + "standard_deviation, median_value, p10_value, p25_value, p75_value, p90_value"; - final String distFeatures = String.format(cohortWrapper, cohortId, distColumns, - StringUtils.stripEnd(jsonObject.getString("sqlQueryContinuousFeatures"), ";")); - queries.addAll(prepareStatements(distributionRetrievingQuery, sessionId, RETRIEVING_PARAMETERS, - new String[] { distFeatures, featureRefs, analysisRefs, String.valueOf(cohortId), String.valueOf(jobId) }, sqlParamNames, sqlParamVars)); - } - if (ccHasPresetPrevalenceAnalyses()) { - final String featureColumns = "cohort_definition_id, covariate_id, sum_value, average_value"; - final String features = String.format(cohortWrapper, cohortId, featureColumns, - StringUtils.stripEnd(jsonObject.getString("sqlQueryFeatures"), ";")); - String[] paramValues = new String[]{ features, featureRefs, analysisRefs, String.valueOf(cohortId), String.valueOf(jobId) }; - queries.addAll(prepareStatements(prevalenceRetrievingQuery, sessionId, RETRIEVING_PARAMETERS, paramValues, sqlParamNames, sqlParamVars)); - } - - return queries; - } - - private boolean ccHasPresetPrevalenceAnalyses() { - return cohortCharacterization.getFeatureAnalyses() - .stream() - .anyMatch(analysis -> analysis.isPreset() && analysis.getStatType() == CcResultType.PREVALENCE); - } - - private boolean ccHasPresetDistributionAnalyses() { - return cohortCharacterization.getFeatureAnalyses() - .stream() - .anyMatch(analysis -> analysis.isPreset() && analysis.getStatType() == CcResultType.DISTRIBUTION); - } - - private CohortExpressionQueryBuilder.BuildExpressionQueryOptions createDefaultOptions(final Integer id) { - final CohortExpressionQueryBuilder.BuildExpressionQueryOptions options = new CohortExpressionQueryBuilder.BuildExpressionQueryOptions(); - options.cdmSchema = SourceUtils.getCdmQualifier(source); - // Target schema - options.resultSchema = SourceUtils.getTempQualifier(source); - options.cohortId = id; - options.generateStats = false; - return options; - } - - private List getCriteriaFeatureQuery(Integer cohortDefinitionId, FeAnalysisWithCriteriaEntity analysis, FeAnalysisCriteriaEntity feature, String targetTable, CcStrataEntity strata) { - - Long conceptId = 0L; - String queryFile; - String groupQuery = getCriteriaGroupQuery(analysis, feature, "qualified_events"); - String[] paramNames = CRITERIA_PARAM_NAMES.toArray(new String[0]); - - if (CcResultType.PREVALENCE.equals(analysis.getStatType())) { - queryFile = COHORT_STATS_QUERY; - } else if (CcResultType.DISTRIBUTION.equals(analysis.getStatType())) { - queryFile = COHORT_DIST_QUERY; - } else { - throw new IllegalArgumentException(String.format("Stat type %s is not supported", analysis.getStatType())); - } - Long strataId = Objects.nonNull(strata) ? strata.getId() : 0L; - String strataName = Objects.nonNull(strata) ? strata.getName() : null; - Collection paramValues = Lists.mutable.with(cohortDefinitionId, jobId, analysis.getId(), analysis.getName(), feature.getName(), conceptId, - feature.getId(), strataId, strataName); - String[] criteriaValues = new String[]{ groupQuery, "0", targetTable, cohortTable }; - - return Arrays.stream(SqlSplit.splitSql(queryFile)) - .map(COMPLETE_DOTCOMMA) - .flatMap(sql -> prepareStatements(sql, sessionId, CRITERIA_REGEXES, criteriaValues, - paramNames, paramValues.toArray(new Object[0])).stream()) - .collect(Collectors.toList()); - } - - private String getCriteriaGroupQuery(FeAnalysisWithCriteriaEntity analysis, FeAnalysisCriteriaEntity feature, String eventTable) { - String groupQuery; - if (CcResultType.PREVALENCE.equals(analysis.getStatType())) { - groupQuery = queryBuilder.getCriteriaGroupQuery(((FeAnalysisCriteriaGroupEntity)feature).getExpression(), eventTable); - } else if (CcResultType.DISTRIBUTION.equals(analysis.getStatType())) { - if (feature instanceof FeAnalysisWindowedCriteriaEntity) { - WindowedCriteria criteria = ((FeAnalysisWindowedCriteriaEntity) feature).getExpression(); - criteria.ignoreObservationPeriod = true; - groupQuery = queryBuilder.getWindowedCriteriaQuery(criteria, eventTable); - } else if (feature instanceof FeAnalysisDemographicCriteriaEntity) { - DemographicCriteria criteria = ((FeAnalysisDemographicCriteriaEntity)feature).getExpression(); - groupQuery = queryBuilder.getDemographicCriteriaQuery(criteria, eventTable); - } else { - throw new IllegalArgumentException(String.format("Feature class %s is not supported", feature.getClass())); - } - } else { - throw new IllegalArgumentException(String.format("Stat type %s is not supported", analysis.getStatType())); - } - return groupQuery; - } - - private List getQueriesForStratifiedCriteriaAnalyses(Integer cohortDefinitionId) { - - List queriesToRun = new ArrayList<>(); - List strataCohortQueries = new ArrayList<>(); - strataCohortQueries.addAll(getCodesetQuery(cohortCharacterization.getConceptSets())); - - //Generate stratified cohorts - strataCohortQueries.addAll(cohortCharacterization.getStratas().stream() - .flatMap(strata -> getStrataQuery(cohortDefinitionId, strata).stream()) - .collect(Collectors.toList())); - - strataCohortQueries.addAll(prepareStatements("TRUNCATE TABLE #Codesets;\n", sessionId)); - strataCohortQueries.addAll(prepareStatements("DROP TABLE #Codesets;\n", sessionId)); - queriesToRun.addAll(strataCohortQueries); - - //Extract features from stratified cohorts - queriesToRun.addAll(cohortCharacterization.getStratas().stream() - .flatMap(strata -> { - JSONObject jsonObject = createFeJsonObject(createDefaultOptions(cohortDefinitionId), getStrataCohortTable(strata)); - List queries = new ArrayList<>(); - queries.addAll(getCreateQueries(jsonObject)); - queries.addAll(getFeatureAnalysesQueries(jsonObject, cohortDefinitionId, strata)); - queries.addAll(getCleanupQueries(jsonObject)); - return queries.stream(); - }) - .collect(Collectors.toList())); - - //Cleanup stratified cohorts tables - queriesToRun.addAll(cohortCharacterization.getStratas().stream() - .flatMap(strata -> prepareStatements("DROP TABLE " + getStrataCohortTable(strata) + ";", sessionId).stream()) - .collect(Collectors.toList())); - - return queriesToRun; - } - - private List getStrataQuery(Integer cohortDefinitionId, CcStrataEntity strata) { - List queries = new ArrayList<>(); - String eventsTable = String.format("#qualified_events_%d", strata.getId()); - String strataQuery = queryBuilder.getCriteriaGroupQuery(strata.getCriteria(), eventsTable); - String[] paramNames = STRATA_PARAM_NAMES.toArray(new String[0]); - String[] replacements = new String[]{ strataQuery, "0", cohortTable, getStrataCohortTable(strata), eventsTable }; - Object[] paramValues = new Object[]{ cohortDefinitionId, strata.getId() }; - queries.addAll(prepareStatements("CREATE TABLE " + getStrataCohortTable(strata) - + "(cohort_definition_id INTEGER, strata_id BIGINT, subject_id BIGINT, cohort_start_date DATE, cohort_end_date DATE);", sessionId)); - String[] statements = SqlSplit.splitSql(COHORT_STRATA_QUERY); - queries.addAll(Arrays.stream(statements) - .map(COMPLETE_DOTCOMMA) - .flatMap(q -> prepareStatements(q, sessionId, STRATA_REGEXES, replacements, paramNames, paramValues).stream()) - .collect(Collectors.toList()) - ); - return queries; - } - - private String getStrataCohortTable(CcStrataEntity strata) { - - return String.format("@temp_database_schema.sc_%s_%d", sessionId, strata.getId()); - } - - private List getCodesetQuery(Collection conceptSets) { - - String codesetQuery = queryBuilder.getCodesetQuery(conceptSets.toArray(new ConceptSet[0])); - return new ArrayList<>(prepareStatements(codesetQuery, sessionId)); - } - - private List getCriteriaFeaturesQueries(Integer cohortDefinitionId, FeAnalysisWithCriteriaEntity analysis, String targetTable, CcStrataEntity strata) { - - List queriesToRun = new ArrayList<>(); - queriesToRun.addAll(getCodesetQuery(analysis.getConceptSets())); - - queriesToRun.addAll(analysis.getDesign().stream() - .map(feature -> getCriteriaFeatureQuery(cohortDefinitionId, analysis, feature, targetTable, strata)) - .flatMap(Collection::stream) - .collect(Collectors.toList())); // statistics queries - queriesToRun.addAll(prepareStatements("DROP TABLE #Codesets;", sessionId)); - return queriesToRun; - } - - private Collection prepareStatements(String query, String sessionId, String[] regexes, String[] variables, String[] paramNames, Object[] paramValues) { - - final String resultsQualifier = SourceUtils.getResultsQualifier(source); - final String cdmQualifier = SourceUtils.getCdmQualifier(source); - final String tempQualifier = SourceUtils.getTempQualifier(source, resultsQualifier); - final String vocabularyQualifier = SourceUtils.getVocabularyQualifier(source); - final String[] tmpRegexes = ArrayUtils.addAll(regexes, DAIMONS); - final String[] tmpValues = ArrayUtils.addAll(variables, resultsQualifier, cdmQualifier, tempQualifier, vocabularyQualifier); - - String sql = SqlRender.renderSql(query, tmpRegexes, tmpValues); - - /* - * There is an issue with temp tables on sql server: Temp tables scope is session or stored procedure. - * To execute PreparedStatement sql server uses stored procedure sp_executesql - * and this is the reason why multiple PreparedStatements cannot share the same local temporary table. - * - * On the other side, temp tables cannot be re-used in the same PreparedStatement, e.g. temp table cannot be created, used, dropped - * and created again in the same PreparedStatement because sql optimizator detects object already exists and fails. - * When is required to re-use temp table it should be separated to several PreparedStatements. - * - * An option to use global temp tables also doesn't work since such tables can be not supported / disabled. - * - * Therefore, there are two ways: - * - either precisely group SQLs into statements so that temp tables aren't re-used in a single statement, - * - or use ‘permenant temporary tables’ - * - * The second option looks better since such SQL could be exported and executed manually, - * which is not the case with the first option. - */ - if (ImmutableList.of(DBMSType.MS_SQL_SERVER.getOhdsiDB(), DBMSType.PDW.getOhdsiDB()).contains(source.getSourceDialect())) { - sql = sql - .replaceAll("#", tempQualifier + "." + sessionId + "_") - .replaceAll("tempdb\\.\\.", ""); - } - String translatedSql = SqlTranslate.translateSql(sql, source.getSourceDialect(), sessionId, tempQualifier); - - String[] stmts = SqlSplit.splitSql(translatedSql); - - return Arrays.stream(stmts).map(stmt -> { - PreparedStatementRenderer psr = new PreparedStatementRenderer(null, stmt, tmpRegexes, tmpValues, paramNames, paramValues, sessionId); - String translatedStatement = psr.getSql(); - PreparedStatementSetter setter = psr.getSetter(); - List orderedParams = psr.getOrderedParamsList(); - return new PreparedStatementWithParamsCreator() { - @Override - public String getSql() { - return translatedStatement; - } - - @Override - public PreparedStatement createPreparedStatement(Connection con) throws SQLException { - PreparedStatement statement = con.prepareStatement(translatedStatement); - if (Objects.nonNull(setter) && translatedStatement.contains("?")) { - setter.setValues(statement); - } - return statement; - } - - @Override - public List getOrderedParamsList() { - return Objects.nonNull(setter) && translatedStatement.contains("?") ? orderedParams : null; - } - }; - }) - .collect(Collectors.toList()); - } - - private Collection prepareStatements(String query, String sessionId, String[] regexes, String[] variables) { - - return prepareStatements(query, sessionId, regexes, variables, new String[]{}, new Object[]{}); - } - - private Collection prepareStatements(String query, String sessionId) { - - return prepareStatements(query, sessionId, new String[]{}, new String[]{}, new String[]{}, new Object[]{}); - } - - private List getSqlQueriesToRun(final JSONObject jsonObject, final Integer cohortDefinitionId) { - List queriesToRun = new LinkedList<>(); - - if (!cohortCharacterization.getStrataOnly() || cohortCharacterization.getStratas().isEmpty()) { - List ccQueries = new LinkedList<>(); - ccQueries.addAll(getCreateQueries(jsonObject)); - ccQueries.addAll(getFeatureAnalysesQueries(jsonObject, cohortDefinitionId, null)); - ccQueries.addAll(getCleanupQueries(jsonObject)); - - queriesToRun.addAll(ccQueries); - } - - if (!cohortCharacterization.getStratas().isEmpty()) { - queriesToRun.addAll(getQueriesForStratifiedCriteriaAnalyses(cohortDefinitionId)); - } - - if (log.isDebugEnabled()) { - String sql = queriesToRun.stream().map(q -> ((SqlProvider) q).getSql()).collect(Collectors.joining("\n")); - log.debug("Generated SQL: {}", sql); - } - - return queriesToRun; - } - - private List getCreateQueries(final JSONObject jsonObject) { - - return Arrays.stream(SqlSplit.splitSql(jsonObject.getString("sqlConstruction"))) - .map(COMPLETE_DOTCOMMA) - .flatMap(sql -> prepareStatements(sql, sessionId).stream()) - .collect(Collectors.toList()); - } - - private List getCleanupQueries(final JSONObject jsonObject) { - - return Arrays.stream(SqlSplit.splitSql(jsonObject.getString("sqlCleanup"))) - .map(COMPLETE_DOTCOMMA) - .flatMap(sql -> prepareStatements(sql, sessionId).stream()) - .collect(Collectors.toList()); - } - - private List getFeatureAnalysesQueries(final JSONObject jsonObject, final Integer cohortDefinitionId, final CcStrataEntity strata) { - - List queriesToRun = new ArrayList<>(); - queriesToRun.addAll(getQueriesForPresetAnalyses(jsonObject,cohortDefinitionId, strata)); - queriesToRun.addAll(getQueriesForCustomDistributionAnalyses(cohortDefinitionId)); - queriesToRun.addAll(getQueriesForCustomPrevalenceAnalyses(cohortDefinitionId)); - queriesToRun.addAll(getQueriesForCriteriaAnalyses(cohortDefinitionId, strata)); - return queriesToRun; - } - - private JSONObject createFeJsonObject(final CohortExpressionQueryBuilder.BuildExpressionQueryOptions options, final String cohortTable) { - FeatureExtraction.init(null); - String settings = buildSettings(); - String sqlJson = FeatureExtraction.createSql(settings, true, cohortTable, - "subject_id", options.cohortId, options.cdmSchema); - return new JSONObject(sqlJson); - } - - private String buildSettings() { - - final JSONObject defaultSettings = new JSONObject(FeatureExtraction.getDefaultPrespecAnalyses()); - - feAnalysisService.findAllPresetAnalyses().forEach(v -> defaultSettings.remove(v.getDesign())); - - cohortCharacterization.getParameters().forEach(param -> defaultSettings.put(param.getName(), param.getValue())); - cohortCharacterization.getFeatureAnalyses() - .stream() - .filter(FeAnalysisEntity::isPreset) - .forEach(analysis -> defaultSettings.put(((FeAnalysisWithStringEntity) analysis).getDesign(), Boolean.TRUE)); - - return defaultSettings.toString(); - } - - } } diff --git a/src/main/java/org/ohdsi/webapi/cohortcharacterization/converter/BaseCcToCcDTOConverter.java b/src/main/java/org/ohdsi/webapi/cohortcharacterization/converter/BaseCcToCcDTOConverter.java index 0739fd20b2..097e7fabc8 100644 --- a/src/main/java/org/ohdsi/webapi/cohortcharacterization/converter/BaseCcToCcDTOConverter.java +++ b/src/main/java/org/ohdsi/webapi/cohortcharacterization/converter/BaseCcToCcDTOConverter.java @@ -31,7 +31,7 @@ public T convert(CohortCharacterizationEntity source) { cohortCharacterizationDTO.setStratifiedBy(source.getStratifiedBy()); cohortCharacterizationDTO.setStrataOnly(source.getStrataOnly()); - cohortCharacterizationDTO.setStrataConceptSets(source.getConceptSets()); + cohortCharacterizationDTO.setStrataConceptSets(source.getStrataConceptSets()); return cohortCharacterizationDTO; } diff --git a/src/main/java/org/ohdsi/webapi/cohortcharacterization/domain/CcParamEntity.java b/src/main/java/org/ohdsi/webapi/cohortcharacterization/domain/CcParamEntity.java index 7e671deb04..93b2f42009 100644 --- a/src/main/java/org/ohdsi/webapi/cohortcharacterization/domain/CcParamEntity.java +++ b/src/main/java/org/ohdsi/webapi/cohortcharacterization/domain/CcParamEntity.java @@ -12,9 +12,9 @@ import org.hibernate.annotations.GenericGenerator; import org.hibernate.annotations.Parameter; +import org.ohdsi.analysis.WithId; import org.ohdsi.analysis.cohortcharacterization.design.CohortCharacterization; import org.ohdsi.analysis.cohortcharacterization.design.CohortCharacterizationParam; -import org.ohdsi.webapi.model.WithId; @Entity @Table(name = "cc_param") diff --git a/src/main/java/org/ohdsi/webapi/cohortcharacterization/domain/CcStrataEntity.java b/src/main/java/org/ohdsi/webapi/cohortcharacterization/domain/CcStrataEntity.java index a7e91a2dc8..51a7c0a9c4 100644 --- a/src/main/java/org/ohdsi/webapi/cohortcharacterization/domain/CcStrataEntity.java +++ b/src/main/java/org/ohdsi/webapi/cohortcharacterization/domain/CcStrataEntity.java @@ -12,14 +12,13 @@ import org.hibernate.annotations.GenericGenerator; import org.hibernate.annotations.Parameter; import org.ohdsi.analysis.Utils; +import org.ohdsi.analysis.WithId; import org.ohdsi.analysis.cohortcharacterization.design.CohortCharacterizationStrata; import org.ohdsi.circe.cohortdefinition.CriteriaGroup; -import org.ohdsi.webapi.model.WithId; - @Entity @Table(name = "cc_strata") -public class CcStrataEntity implements CohortCharacterizationStrata, WithId { +public class CcStrataEntity implements CohortCharacterizationStrata, WithId { @Id @GenericGenerator( diff --git a/src/main/java/org/ohdsi/webapi/cohortcharacterization/domain/CohortCharacterizationEntity.java b/src/main/java/org/ohdsi/webapi/cohortcharacterization/domain/CohortCharacterizationEntity.java index 34a08c5c0a..cf5d41a3ca 100644 --- a/src/main/java/org/ohdsi/webapi/cohortcharacterization/domain/CohortCharacterizationEntity.java +++ b/src/main/java/org/ohdsi/webapi/cohortcharacterization/domain/CohortCharacterizationEntity.java @@ -151,7 +151,8 @@ public void setConceptSetEntity(CcStrataConceptSetEntity conceptSetEntity) { this.conceptSetEntity = conceptSetEntity; } - public List getConceptSets() { + @Override + public Collection getStrataConceptSets() { return Objects.nonNull(this.conceptSetEntity) ? this.conceptSetEntity.getConceptSets() : Collections.emptyList(); } diff --git a/src/main/java/org/ohdsi/webapi/cohortcharacterization/dto/CcResult.java b/src/main/java/org/ohdsi/webapi/cohortcharacterization/dto/CcResult.java index 62377ad24a..dca161a0ee 100644 --- a/src/main/java/org/ohdsi/webapi/cohortcharacterization/dto/CcResult.java +++ b/src/main/java/org/ohdsi/webapi/cohortcharacterization/dto/CcResult.java @@ -1,6 +1,7 @@ package org.ohdsi.webapi.cohortcharacterization.dto; -import org.ohdsi.webapi.cohortcharacterization.CcResultType; + +import org.ohdsi.analysis.cohortcharacterization.design.CcResultType; public class CcResult { diff --git a/src/main/java/org/ohdsi/webapi/feanalysis/FeAnalysisDeserializer.java b/src/main/java/org/ohdsi/webapi/feanalysis/FeAnalysisDeserializer.java index 0cd4b5582f..10fcd8f696 100644 --- a/src/main/java/org/ohdsi/webapi/feanalysis/FeAnalysisDeserializer.java +++ b/src/main/java/org/ohdsi/webapi/feanalysis/FeAnalysisDeserializer.java @@ -15,10 +15,10 @@ import javax.annotation.PostConstruct; import com.fasterxml.jackson.databind.type.CollectionType; +import org.ohdsi.analysis.cohortcharacterization.design.CcResultType; import org.ohdsi.analysis.cohortcharacterization.design.StandardFeatureAnalysisDomain; import org.ohdsi.analysis.cohortcharacterization.design.StandardFeatureAnalysisType; import org.ohdsi.circe.cohortdefinition.ConceptSet; -import org.ohdsi.webapi.cohortcharacterization.CcResultType; import org.ohdsi.webapi.feanalysis.dto.BaseFeAnalysisCriteriaDTO; import org.ohdsi.webapi.feanalysis.dto.FeAnalysisDTO; import org.ohdsi.webapi.feanalysis.dto.FeAnalysisWithConceptSetDTO; diff --git a/src/main/java/org/ohdsi/webapi/feanalysis/FeAnalysisServiceImpl.java b/src/main/java/org/ohdsi/webapi/feanalysis/FeAnalysisServiceImpl.java index d2c068e013..2b0d77dbee 100644 --- a/src/main/java/org/ohdsi/webapi/feanalysis/FeAnalysisServiceImpl.java +++ b/src/main/java/org/ohdsi/webapi/feanalysis/FeAnalysisServiceImpl.java @@ -5,8 +5,8 @@ import com.cosium.spring.data.jpa.entity.graph.domain.EntityGraph; import org.apache.commons.lang3.StringUtils; +import org.ohdsi.analysis.cohortcharacterization.design.CcResultType; import org.ohdsi.analysis.cohortcharacterization.design.StandardFeatureAnalysisType; -import org.ohdsi.webapi.cohortcharacterization.CcResultType; import org.ohdsi.webapi.cohortcharacterization.domain.CohortCharacterizationEntity; import org.ohdsi.webapi.feanalysis.domain.*; import org.ohdsi.webapi.feanalysis.repository.FeAnalysisCriteriaRepository; diff --git a/src/main/java/org/ohdsi/webapi/feanalysis/converter/FeAnalysisDTOToFeAnalysisWithCriteriasConverter.java b/src/main/java/org/ohdsi/webapi/feanalysis/converter/FeAnalysisDTOToFeAnalysisWithCriteriasConverter.java index 4bbac4c7ee..3f5ad344b1 100644 --- a/src/main/java/org/ohdsi/webapi/feanalysis/converter/FeAnalysisDTOToFeAnalysisWithCriteriasConverter.java +++ b/src/main/java/org/ohdsi/webapi/feanalysis/converter/FeAnalysisDTOToFeAnalysisWithCriteriasConverter.java @@ -1,8 +1,8 @@ package org.ohdsi.webapi.feanalysis.converter; import org.ohdsi.analysis.Utils; +import org.ohdsi.analysis.cohortcharacterization.design.CcResultType; import org.ohdsi.analysis.cohortcharacterization.design.StandardFeatureAnalysisType; -import org.ohdsi.webapi.cohortcharacterization.CcResultType; import org.ohdsi.webapi.feanalysis.domain.*; import org.ohdsi.webapi.feanalysis.dto.*; import org.springframework.stereotype.Component; diff --git a/src/main/java/org/ohdsi/webapi/feanalysis/converter/FeAnalysisShortDTOToFeaAnalysisConverter.java b/src/main/java/org/ohdsi/webapi/feanalysis/converter/FeAnalysisShortDTOToFeaAnalysisConverter.java index 8cfee0ae2d..eb9cb58d6c 100644 --- a/src/main/java/org/ohdsi/webapi/feanalysis/converter/FeAnalysisShortDTOToFeaAnalysisConverter.java +++ b/src/main/java/org/ohdsi/webapi/feanalysis/converter/FeAnalysisShortDTOToFeaAnalysisConverter.java @@ -1,7 +1,7 @@ package org.ohdsi.webapi.feanalysis.converter; +import org.ohdsi.analysis.cohortcharacterization.design.CcResultType; import org.ohdsi.analysis.cohortcharacterization.design.StandardFeatureAnalysisType; -import org.ohdsi.webapi.cohortcharacterization.CcResultType; import org.ohdsi.webapi.feanalysis.domain.*; import org.ohdsi.webapi.feanalysis.dto.FeAnalysisShortDTO; import org.springframework.stereotype.Component; diff --git a/src/main/java/org/ohdsi/webapi/feanalysis/domain/FeAnalysisCriteriaEntity.java b/src/main/java/org/ohdsi/webapi/feanalysis/domain/FeAnalysisCriteriaEntity.java index 73bfd58820..688e9f3b54 100644 --- a/src/main/java/org/ohdsi/webapi/feanalysis/domain/FeAnalysisCriteriaEntity.java +++ b/src/main/java/org/ohdsi/webapi/feanalysis/domain/FeAnalysisCriteriaEntity.java @@ -16,13 +16,14 @@ import org.hibernate.annotations.GenericGenerator; import org.hibernate.annotations.Parameter; import org.hibernate.annotations.Type; +import org.ohdsi.analysis.WithId; @Entity @Table(name = "fe_analysis_criteria") @Inheritance(strategy = InheritanceType.SINGLE_TABLE) @DiscriminatorColumn(name = "criteria_type") @DiscriminatorOptions(force = false) -public abstract class FeAnalysisCriteriaEntity { +public abstract class FeAnalysisCriteriaEntity implements WithId { @Id @GenericGenerator( diff --git a/src/main/java/org/ohdsi/webapi/feanalysis/domain/FeAnalysisDemographicCriteriaEntity.java b/src/main/java/org/ohdsi/webapi/feanalysis/domain/FeAnalysisDemographicCriteriaEntity.java index 09d7db810d..5aa7ceeac5 100644 --- a/src/main/java/org/ohdsi/webapi/feanalysis/domain/FeAnalysisDemographicCriteriaEntity.java +++ b/src/main/java/org/ohdsi/webapi/feanalysis/domain/FeAnalysisDemographicCriteriaEntity.java @@ -1,6 +1,7 @@ package org.ohdsi.webapi.feanalysis.domain; import org.ohdsi.analysis.Utils; +import org.ohdsi.analysis.cohortcharacterization.design.DemographicCriteriaFeature; import org.ohdsi.circe.cohortdefinition.DemographicCriteria; import javax.persistence.DiscriminatorValue; @@ -8,7 +9,7 @@ @Entity @DiscriminatorValue("DEMOGRAPHIC_CRITERIA") -public class FeAnalysisDemographicCriteriaEntity extends FeAnalysisDistributionCriteriaEntity { +public class FeAnalysisDemographicCriteriaEntity extends FeAnalysisDistributionCriteriaEntity implements DemographicCriteriaFeature { @Override public DemographicCriteria getExpression() { diff --git a/src/main/java/org/ohdsi/webapi/feanalysis/domain/FeAnalysisEntity.java b/src/main/java/org/ohdsi/webapi/feanalysis/domain/FeAnalysisEntity.java index 6820b1aa37..4b9c3627a0 100644 --- a/src/main/java/org/ohdsi/webapi/feanalysis/domain/FeAnalysisEntity.java +++ b/src/main/java/org/ohdsi/webapi/feanalysis/domain/FeAnalysisEntity.java @@ -21,10 +21,10 @@ import org.hibernate.annotations.GenericGenerator; import org.hibernate.annotations.Parameter; import org.hibernate.annotations.Type; +import org.ohdsi.analysis.cohortcharacterization.design.CcResultType; import org.ohdsi.analysis.cohortcharacterization.design.FeatureAnalysis; import org.ohdsi.analysis.cohortcharacterization.design.StandardFeatureAnalysisDomain; import org.ohdsi.analysis.cohortcharacterization.design.StandardFeatureAnalysisType; -import org.ohdsi.webapi.cohortcharacterization.CcResultType; import org.ohdsi.webapi.cohortcharacterization.domain.CohortCharacterizationEntity; import org.ohdsi.webapi.model.CommonEntity; @@ -35,7 +35,7 @@ "CASE WHEN type = 'CRITERIA_SET' THEN CONCAT(type,'_',stat_type)" + "ELSE type END" ) -public abstract class FeAnalysisEntity extends CommonEntity implements FeatureAnalysis, Comparable { +public abstract class FeAnalysisEntity extends CommonEntity implements FeatureAnalysis, Comparable> { public FeAnalysisEntity() { } diff --git a/src/main/java/org/ohdsi/webapi/feanalysis/domain/FeAnalysisWindowedCriteriaEntity.java b/src/main/java/org/ohdsi/webapi/feanalysis/domain/FeAnalysisWindowedCriteriaEntity.java index 6fe9923397..c730d7d103 100644 --- a/src/main/java/org/ohdsi/webapi/feanalysis/domain/FeAnalysisWindowedCriteriaEntity.java +++ b/src/main/java/org/ohdsi/webapi/feanalysis/domain/FeAnalysisWindowedCriteriaEntity.java @@ -1,6 +1,7 @@ package org.ohdsi.webapi.feanalysis.domain; import org.ohdsi.analysis.Utils; +import org.ohdsi.analysis.cohortcharacterization.design.WindowedCriteriaFeature; import org.ohdsi.circe.cohortdefinition.WindowedCriteria; import javax.persistence.DiscriminatorValue; @@ -8,7 +9,7 @@ @Entity @DiscriminatorValue("WINDOWED_CRITERIA") -public class FeAnalysisWindowedCriteriaEntity extends FeAnalysisDistributionCriteriaEntity { +public class FeAnalysisWindowedCriteriaEntity extends FeAnalysisDistributionCriteriaEntity implements WindowedCriteriaFeature { @Override public WindowedCriteria getExpression() { diff --git a/src/main/java/org/ohdsi/webapi/feanalysis/domain/FeAnalysisWithCriteriaEntity.java b/src/main/java/org/ohdsi/webapi/feanalysis/domain/FeAnalysisWithCriteriaEntity.java index 840c81cb7c..dfae657284 100644 --- a/src/main/java/org/ohdsi/webapi/feanalysis/domain/FeAnalysisWithCriteriaEntity.java +++ b/src/main/java/org/ohdsi/webapi/feanalysis/domain/FeAnalysisWithCriteriaEntity.java @@ -1,5 +1,6 @@ package org.ohdsi.webapi.feanalysis.domain; +import org.ohdsi.analysis.cohortcharacterization.design.FeatureAnalysisWithCriteria; import org.ohdsi.circe.cohortdefinition.ConceptSet; import javax.persistence.*; @@ -8,7 +9,7 @@ import java.util.Objects; @Entity -public abstract class FeAnalysisWithCriteriaEntity extends FeAnalysisEntity> { +public abstract class FeAnalysisWithCriteriaEntity extends FeAnalysisEntity> implements FeatureAnalysisWithCriteria { @OneToMany(targetEntity = FeAnalysisCriteriaEntity.class, fetch = FetchType.EAGER, mappedBy = "featureAnalysis", cascade = CascadeType.ALL) private List design; diff --git a/src/main/java/org/ohdsi/webapi/feanalysis/domain/FeAnalysisWithStringEntity.java b/src/main/java/org/ohdsi/webapi/feanalysis/domain/FeAnalysisWithStringEntity.java index dbe0b865ae..4f77de9a1d 100644 --- a/src/main/java/org/ohdsi/webapi/feanalysis/domain/FeAnalysisWithStringEntity.java +++ b/src/main/java/org/ohdsi/webapi/feanalysis/domain/FeAnalysisWithStringEntity.java @@ -4,6 +4,7 @@ import javax.persistence.Entity; import javax.persistence.Lob; import org.hibernate.annotations.Type; +import org.ohdsi.analysis.cohortcharacterization.design.FeatureAnalysis; @Entity @DiscriminatorValue("not null") diff --git a/src/main/java/org/ohdsi/webapi/feanalysis/dto/FeAnalysisShortDTO.java b/src/main/java/org/ohdsi/webapi/feanalysis/dto/FeAnalysisShortDTO.java index 7d16251f5a..fc0629a091 100644 --- a/src/main/java/org/ohdsi/webapi/feanalysis/dto/FeAnalysisShortDTO.java +++ b/src/main/java/org/ohdsi/webapi/feanalysis/dto/FeAnalysisShortDTO.java @@ -1,9 +1,9 @@ package org.ohdsi.webapi.feanalysis.dto; import com.fasterxml.jackson.annotation.JsonProperty; +import org.ohdsi.analysis.cohortcharacterization.design.CcResultType; import org.ohdsi.analysis.cohortcharacterization.design.StandardFeatureAnalysisDomain; import org.ohdsi.analysis.cohortcharacterization.design.StandardFeatureAnalysisType; -import org.ohdsi.webapi.cohortcharacterization.CcResultType; import org.ohdsi.webapi.service.dto.CommonEntityDTO; public class FeAnalysisShortDTO extends CommonEntityDTO { diff --git a/src/main/java/org/ohdsi/webapi/model/CommonEntity.java b/src/main/java/org/ohdsi/webapi/model/CommonEntity.java index 13abef163a..7230ba6320 100644 --- a/src/main/java/org/ohdsi/webapi/model/CommonEntity.java +++ b/src/main/java/org/ohdsi/webapi/model/CommonEntity.java @@ -1,5 +1,6 @@ package org.ohdsi.webapi.model; +import org.ohdsi.analysis.WithId; import org.ohdsi.webapi.shiro.Entities.UserEntity; import java.io.Serializable; @@ -7,7 +8,7 @@ import javax.persistence.*; @MappedSuperclass -public abstract class CommonEntity implements Serializable, WithId { +public abstract class CommonEntity implements Serializable, WithId { @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "created_by_id", updatable = false) private UserEntity createdBy; diff --git a/src/main/java/org/ohdsi/webapi/model/WithId.java b/src/main/java/org/ohdsi/webapi/model/WithId.java deleted file mode 100644 index bd3132f355..0000000000 --- a/src/main/java/org/ohdsi/webapi/model/WithId.java +++ /dev/null @@ -1,6 +0,0 @@ -package org.ohdsi.webapi.model; - -public interface WithId { - - T getId(); -} diff --git a/src/main/resources/resources/cohortcharacterizations/sql/customDistribution.sql b/src/main/resources/resources/cohortcharacterizations/sql/customDistribution.sql deleted file mode 100644 index fb18b8fc98..0000000000 --- a/src/main/resources/resources/cohortcharacterizations/sql/customDistribution.sql +++ /dev/null @@ -1,44 +0,0 @@ -insert into - @results_database_schema.cc_results (type, - fa_type, - covariate_id, - covariate_name, - analysis_id, - analysis_name, - concept_id, - count_value, - min_value, - max_value, - avg_value, - stdev_value, - median_value, - p10_value, - p25_value, - p75_value, - p90_value, - cohort_definition_id, - strata_id, - strata_name, - cc_generation_id) - select CAST('DISTRIBUTION' AS VARCHAR(255)) as type, - CAST('CUSTOM_FE' AS VARCHAR(255)) as fa_type, - covariate_id, - covariate_name, - @analysisId as analysis_id, - @analysisName as analysis_name, - concept_id, - count_value, - min_value, - max_value, - average_value, - standard_deviation, - median_value, - p10_value, - p25_value, - p75_value, - p90_value, - @cohortId as cohort_definition_id, - @strataId as strata_id, - CAST(@strataName AS VARCHAR(1000)) as strata_name, - @jobId as cc_generation_id - from (@design) subquery; diff --git a/src/main/resources/resources/cohortcharacterizations/sql/customPrevalence.sql b/src/main/resources/resources/cohortcharacterizations/sql/customPrevalence.sql deleted file mode 100644 index ebdc711c68..0000000000 --- a/src/main/resources/resources/cohortcharacterizations/sql/customPrevalence.sql +++ /dev/null @@ -1,28 +0,0 @@ -insert into @results_database_schema.cc_results ( - type, - fa_type, - covariate_id, - covariate_name, - analysis_id, - analysis_name, - concept_id, - count_value, - avg_value, - cohort_definition_id, - strata_id, - strata_name, - cc_generation_id) -select CAST('PREVALENCE' AS VARCHAR(255)) as type, - CAST('CUSTOM_FE' AS VARCHAR(255)) as fa_type, - CAST(covariate_id AS BIGINT) as covariate_id, - CAST(covariate_name AS VARCHAR(1000)) as covariate_name, - CAST(@analysisId AS INTEGER) as analysis_id, - CAST('@analysisName' AS VARCHAR(1000)) as analysis_name, - CAST(concept_id AS INTEGER) as concept_id, - sum_value as count_value, - average_value as stat_value, - CAST(@cohortId AS BIGINT) as cohort_definition_id, - CAST(@strataId AS BIGINT) as strata_id, - CAST(@strataName AS VARCHAR(1000)) as strata_name, - CAST(@jobId AS BIGINT) as cc_generation_id -from (@design) subquery; diff --git a/src/main/resources/resources/cohortcharacterizations/sql/distributionRetrieving.sql b/src/main/resources/resources/cohortcharacterizations/sql/distributionRetrieving.sql deleted file mode 100644 index 029b7c3b4d..0000000000 --- a/src/main/resources/resources/cohortcharacterizations/sql/distributionRetrieving.sql +++ /dev/null @@ -1,29 +0,0 @@ -insert into @results_database_schema.cc_results (type, fa_type, covariate_id, covariate_name, analysis_id, analysis_name, concept_id, - count_value, min_value, max_value, avg_value, stdev_value, median_value, - p10_value, p25_value, p75_value, p90_value, strata_id, strata_name, cohort_definition_id, cc_generation_id) - select CAST('DISTRIBUTION' AS VARCHAR(255)) as type, - CAST('PRESET' AS VARCHAR(255)) as fa_type, - f.covariate_id, - fr.covariate_name, - ar.analysis_id, - ar.analysis_name, - fr.concept_id, - f.count_value, - f.min_value, - f.max_value, - f.average_value, - f.standard_deviation, - f.median_value, - f.p10_value, - f.p25_value, - f.p75_value, - f.p90_value, - @strataId as strata_id, - CAST(@strataName AS VARCHAR(1000)) as strata_name, - @cohortId as cohort_definition_id, - @executionId as cc_generation_id - from (@features) f - join (@featureRefs) fr on fr.covariate_id = f.covariate_id and fr.cohort_definition_id = f.cohort_definition_id - join (@analysisRefs) ar - on ar.analysis_id = fr.analysis_id and ar.cohort_definition_id = fr.cohort_definition_id - left join @cdm_database_schema.concept c on c.concept_id = fr.concept_id; diff --git a/src/main/resources/resources/cohortcharacterizations/sql/distributionWithCriteria.sql b/src/main/resources/resources/cohortcharacterizations/sql/distributionWithCriteria.sql deleted file mode 100644 index bc61706d36..0000000000 --- a/src/main/resources/resources/cohortcharacterizations/sql/distributionWithCriteria.sql +++ /dev/null @@ -1,91 +0,0 @@ -IF OBJECT_ID('tempdb..#events_count', 'U') IS NOT NULL - DROP TABLE #events_count; - -WITH qualified_events AS ( - SELECT ROW_NUMBER() OVER (partition by E.subject_id order by E.cohort_start_date) AS event_id, E.subject_id AS person_id, E.cohort_start_date AS start_date, E.cohort_end_date AS end_date, OP.observation_period_start_date AS op_start_date, OP.observation_period_end_date AS op_end_date - FROM @targetTable E - JOIN @cdm_database_schema.observation_period OP ON E.subject_id = OP.person_id AND E.cohort_start_date >= OP.observation_period_start_date AND E.cohort_start_date <= OP.observation_period_end_date - WHERE cohort_definition_id = @cohortId -) -select - v.person_id as person_id, - count(*) as value_as_int -into #events_count -from ( @groupQuery ) v -group by v.person_id; - -with - total_cohort_count AS ( - SELECT COUNT(*) cnt FROM @targetTable where cohort_definition_id = @cohortId - ), - events_max_value as ( - select max(value_as_int) as max_value from #events_count - ), - event_stat_values as ( - select - count(*) as count_value, - min(value_as_int) as min_value, - max(value_as_int) as max_value, - sum(value_as_int) as sum_value, - stdev(value_as_int) as stdev_value, - total_cohort_count.cnt - count(*) as count_no_value, - total_cohort_count.cnt as population_size - from #events_count, total_cohort_count - group by total_cohort_count.cnt - ), - event_prep as (select row_number() over (order by value_as_int) as rn, value_as_int, count(*) as people_count from #events_count group by value_as_int), - events_dist as ( - select s.value_as_int, sum(p.people_count) as people_count - from event_prep s join event_prep p on p.rn <= s.rn group by s.value_as_int - ), - events_p10_value as ( - select min(value_as_int) as p10 from events_dist, event_stat_values where (people_count + count_no_value) >= 0.1 * population_size - ), - events_p25_value as ( - select min(value_as_int) as p25 from events_dist, event_stat_values where (people_count + count_no_value) >= 0.25 * population_size - ), - events_median_value as ( - select min(value_as_int) as median_value from events_dist, event_stat_values where (people_count + count_no_value) >= 0.5 * population_size - ), - events_p75_value as ( - select min(value_as_int) as p75 from events_dist, event_stat_values where people_count + count_no_value >= 0.75 * population_size - ), - events_p90_value as ( - select min(value_as_int) as p90 from events_dist, event_stat_values where people_count + count_no_value >= 0.9 * population_size - ) -select - CAST('DISTRIBUTION' AS VARCHAR(255)) as type, - CAST('CRITERIA' AS VARCHAR(255)) as fa_type, - CAST(@covariateId AS BIGINT) as covariate_id, - CAST('@covariateName' AS VARCHAR(1000)) as covariate_name, - CAST(@analysisId AS INT) as analysis_id, - CAST('@analysisName' AS VARCHAR(1000)) as analysis_name, - CAST(@conceptId AS INT) as concept_id, - CAST(@cohortId AS BIGINT) as cohort_definition_id, - CAST(@executionId AS BIGINT) as cc_generation_id, - CAST(@strataId AS BIGINT) as strata_id, - CAST('@strataName' AS VARCHAR(255)) as strata_name, - event_stat_values.count_value, - CAST(case when count_no_value = 0 then event_stat_values.min_value else 0 end AS float) as min_value, - event_stat_values.max_value, - cast(event_stat_values.sum_value / (1.0 * population_size) as float) as avg_value, - event_stat_values.stdev_value, - case when population_size * .10 < count_no_value then 0 else events_p10_value.p10 end as p10_value, - case when population_size * .25 < count_no_value then 0 else events_p25_value.p25 end as p25_value, - case when population_size * .50 < count_no_value then 0 else events_median_value.median_value end as median_value, - case when population_size * .75 < count_no_value then 0 else events_p75_value.p75 end as p75_value, - case when population_size * .90 < count_no_value then 0 else events_p90_value.p90 end as p90_value -INTO #events_dist -from events_max_value, event_stat_values, events_p10_value, events_p25_value, events_median_value, events_p75_value, events_p90_value; - -insert into @results_database_schema.cc_results(type, fa_type, covariate_id, covariate_name, analysis_id, analysis_name, concept_id, - cohort_definition_id, cc_generation_id, strata_id, strata_name, count_value, min_value, max_value, avg_value, stdev_value, p10_value, p25_value, median_value, p75_value, p90_value) -select type, fa_type, covariate_id, covariate_name, analysis_id, analysis_name, concept_id, - cohort_definition_id, cc_generation_id, strata_id, strata_name, count_value, min_value, max_value, avg_value, stdev_value, p10_value, p25_value, median_value, p75_value, p90_value -FROM #events_dist; - -truncate table #events_dist; -drop table #events_dist; - -truncate table #events_count; -drop table #events_count; \ No newline at end of file diff --git a/src/main/resources/resources/cohortcharacterizations/sql/prevalenceRetrieving.sql b/src/main/resources/resources/cohortcharacterizations/sql/prevalenceRetrieving.sql deleted file mode 100644 index 5f7bfcbe1c..0000000000 --- a/src/main/resources/resources/cohortcharacterizations/sql/prevalenceRetrieving.sql +++ /dev/null @@ -1,20 +0,0 @@ -insert into @results_database_schema.cc_results (type, fa_type, covariate_id, covariate_name, analysis_id, analysis_name, concept_id, count_value, avg_value, - strata_id, strata_name, cohort_definition_id, cc_generation_id) - select CAST('PREVALENCE' AS VARCHAR(255)) as type, - CAST('PRESET' AS VARCHAR(255)) as fa_type, - f.covariate_id, - fr.covariate_name, - ar.analysis_id, - ar.analysis_name, - fr.concept_id, - f.sum_value as count_value, - f.average_value as stat_value, - @strataId as strata_id, - CAST(@strataName AS VARCHAR(1000)) as strata_name, - @cohortId as cohort_definition_id, - @executionId as cc_generation_id - from (@features) f - join (@featureRefs) fr on fr.covariate_id = f.covariate_id and fr.cohort_definition_id = f.cohort_definition_id - join (@analysisRefs) ar - on ar.analysis_id = fr.analysis_id and ar.cohort_definition_id = fr.cohort_definition_id - left join @cdm_database_schema.concept c on c.concept_id = fr.concept_id; \ No newline at end of file diff --git a/src/main/resources/resources/cohortcharacterizations/sql/prevalenceWithCriteria.sql b/src/main/resources/resources/cohortcharacterizations/sql/prevalenceWithCriteria.sql deleted file mode 100644 index 3f70c45f36..0000000000 --- a/src/main/resources/resources/cohortcharacterizations/sql/prevalenceWithCriteria.sql +++ /dev/null @@ -1,27 +0,0 @@ -WITH qualified_events AS ( - SELECT ROW_NUMBER() OVER (partition by E.subject_id order by E.cohort_start_date) AS event_id, E.subject_id AS person_id, E.cohort_start_date AS start_date, E.cohort_end_date AS end_date, OP.observation_period_start_date AS op_start_date, OP.observation_period_end_date AS op_end_date - FROM @targetTable E - JOIN @cdm_database_schema.observation_period OP ON E.subject_id = OP.person_id AND E.cohort_start_date >= OP.observation_period_start_date AND E.cohort_start_date <= OP.observation_period_end_date - WHERE cohort_definition_id = @cohortId -) -insert into @results_database_schema.cc_results (type, fa_type, covariate_id, covariate_name, analysis_id, analysis_name, concept_id, count_value, avg_value, strata_id, strata_name, cohort_definition_id, cc_generation_id) - select CAST('PREVALENCE' AS VARCHAR(255)) as type, - CAST('CRITERIA' AS VARCHAR(255)) as fa_type, - CAST(@covariateId AS BIGINT) as covariate_id, - CAST('@covariateName' AS VARCHAR(1000)) as covariate_name, - CAST(@analysisId AS INTEGER) as analysis_id, - CAST('@analysisName' AS VARCHAR(1000)) as analysis_name, - CAST(@conceptId AS INTEGER) as concept_id, - sum.sum_value as count_value, - case - when totals.total > 0 then (sum.sum_value * 1.0 / totals.total * 1.0) - else 0.0 - end as stat_value, - CAST(@strataId AS BIGINT) as strata_id, - CAST(@strataName AS VARCHAR(1000)) as strata_name, - CAST(@cohortId AS BIGINT) as cohort_definition_id, - CAST(@executionId AS BIGINT) as cc_generation_id -from (select count(*) as sum_value from( - select person_id from ( @groupQuery ) pi group by pi.person_id) pci) sum, - (select count(*) as total from @temp_database_schema.@totalsTable where cohort_definition_id = @cohortId) totals -; diff --git a/src/main/resources/resources/cohortcharacterizations/sql/strataWithCriteria.sql b/src/main/resources/resources/cohortcharacterizations/sql/strataWithCriteria.sql deleted file mode 100644 index e6e325831f..0000000000 --- a/src/main/resources/resources/cohortcharacterizations/sql/strataWithCriteria.sql +++ /dev/null @@ -1,17 +0,0 @@ -IF OBJECT_ID('@eventsTable', 'U') IS NOT NULL DROP TABLE @eventsTable; - -CREATE TABLE @eventsTable (event_id BIGINT, person_id BIGINT, start_date DATE, end_date DATE, op_start_date DATE, op_end_date DATE); - -INSERT INTO @eventsTable (event_id, person_id, start_date, end_date, op_start_date, op_end_date) -SELECT ROW_NUMBER() OVER (partition by E.subject_id order by E.cohort_start_date) AS event_id, E.subject_id AS person_id, E.cohort_start_date AS start_date, E.cohort_end_date AS end_date, OP.observation_period_start_date AS op_start_date, OP.observation_period_end_date AS op_end_date -FROM @temp_database_schema.@targetTable E - JOIN @cdm_database_schema.observation_period OP ON E.subject_id = OP.person_id AND E.cohort_start_date >= OP.observation_period_start_date AND E.cohort_start_date <= OP.observation_period_end_date - WHERE cohort_definition_id = @cohortId; - -INSERT INTO @strataCohortTable(cohort_definition_id, strata_id, subject_id, cohort_start_date, cohort_end_date) -SELECT @cohortId AS cohort_definition_id, @strataId AS strata_id, q.person_id as subject_id, q.start_date AS cohort_start_date, q.end_date AS cohort_end_date - FROM @eventsTable q - JOIN (SELECT person_id FROM (@strataQuery) st GROUP BY person_id) sti ON sti.person_id = q.person_id -; - -IF OBJECT_ID('@eventsTable', 'U') IS NOT NULL DROP TABLE @eventsTable; \ No newline at end of file From 54496fe953a980041b1334fc91add2c3248e7050 Mon Sep 17 00:00:00 2001 From: Vitaly Koulakov Date: Fri, 22 Mar 2019 11:57:53 +0300 Subject: [PATCH 2/9] WebAPI-975 Extract Cohort Characterization analysis to external package --- ...GenerateCohortCharacterizationTasklet.java | 34 +++---------------- 1 file changed, 4 insertions(+), 30 deletions(-) diff --git a/src/main/java/org/ohdsi/webapi/cohortcharacterization/GenerateCohortCharacterizationTasklet.java b/src/main/java/org/ohdsi/webapi/cohortcharacterization/GenerateCohortCharacterizationTasklet.java index 8740fc4ed5..10c1b31514 100644 --- a/src/main/java/org/ohdsi/webapi/cohortcharacterization/GenerateCohortCharacterizationTasklet.java +++ b/src/main/java/org/ohdsi/webapi/cohortcharacterization/GenerateCohortCharacterizationTasklet.java @@ -17,8 +17,6 @@ import com.google.common.collect.ImmutableList; import com.odysseusinc.arachne.commons.types.DBMSType; -import org.ohdsi.circe.cohortdefinition.*; -import org.ohdsi.circe.helper.ResourceHelper; import org.ohdsi.cohortcharacterization.CCQueryBuilder; import org.ohdsi.sql.SqlSplit; import org.ohdsi.sql.SqlTranslate; @@ -27,12 +25,13 @@ import org.ohdsi.webapi.cohortcharacterization.repository.AnalysisGenerationInfoEntityRepository; import org.ohdsi.webapi.common.generation.AnalysisTasklet; import org.ohdsi.webapi.feanalysis.FeAnalysisService; -import org.ohdsi.webapi.feanalysis.domain.*; +import org.ohdsi.webapi.feanalysis.domain.FeAnalysisWithStringEntity; import org.ohdsi.webapi.service.SourceService; import org.ohdsi.webapi.shiro.Entities.UserEntity; import org.ohdsi.webapi.shiro.Entities.UserRepository; import org.ohdsi.webapi.source.Source; -import org.ohdsi.webapi.util.*; +import org.ohdsi.webapi.util.CancelableJdbcTemplate; +import org.ohdsi.webapi.util.SourceUtils; import org.slf4j.LoggerFactory; import org.springframework.batch.core.scope.context.ChunkContext; import org.springframework.transaction.TransactionDefinition; @@ -40,41 +39,17 @@ import org.springframework.transaction.support.DefaultTransactionDefinition; import org.springframework.transaction.support.TransactionTemplate; -import java.util.*; -import java.util.function.Function; +import java.util.Map; import java.util.stream.Collectors; import static org.ohdsi.webapi.Constants.Params.*; public class GenerateCohortCharacterizationTasklet extends AnalysisTasklet { - private static final String[] CUSTOM_PARAMETERS = {"analysisId", "analysisName", "cohortId", "jobId", "design"}; - private static final String[] RETRIEVING_PARAMETERS = {"features", "featureRefs", "analysisRefs", "cohortId", "executionId"}; - private static final String[] DAIMONS = {RESULTS_DATABASE_SCHEMA, CDM_DATABASE_SCHEMA, TEMP_DATABASE_SCHEMA, VOCABULARY_DATABASE_SCHEMA}; - - private static final String COHORT_STATS_QUERY = ResourceHelper.GetResourceAsString("/resources/cohortcharacterizations/sql/prevalenceWithCriteria.sql"); - private static final String COHORT_DIST_QUERY = ResourceHelper.GetResourceAsString("/resources/cohortcharacterizations/sql/distributionWithCriteria.sql"); - - private static final String COHORT_STRATA_QUERY = ResourceHelper.GetResourceAsString("/resources/cohortcharacterizations/sql/strataWithCriteria.sql"); - - private static final String[] CRITERIA_REGEXES = new String[] { "groupQuery", "indexId", "targetTable", "totalsTable", "eventsTable" }; - private static final String[] STRATA_REGEXES = new String[] { "strataQuery", "indexId", "targetTable", "strataCohortTable", "eventsTable" }; - - private static final Collection CRITERIA_PARAM_NAMES = ImmutableList.builder() - .add("cohortId", "executionId", "analysisId", "analysisName", "covariateName", "conceptId", "covariateId", "strataId", "strataName") - .build(); - - private static final Collection STRATA_PARAM_NAMES = ImmutableList.builder() - .add("cohortId") - .add("strataId") - .build(); - - private static final Function COMPLETE_DOTCOMMA = s -> s.trim().endsWith(";") ? s : s + ";"; private final CcService ccService; private final FeAnalysisService feAnalysisService; private final SourceService sourceService; private final UserRepository userRepository; - private final CohortExpressionQueryBuilder queryBuilder; public GenerateCohortCharacterizationTasklet( final CancelableJdbcTemplate jdbcTemplate, @@ -90,7 +65,6 @@ public GenerateCohortCharacterizationTasklet( this.feAnalysisService = feAnalysisService; this.sourceService = sourceService; this.userRepository = userRepository; - this.queryBuilder = new CohortExpressionQueryBuilder(); } @Override From e09593617ac39ee3ec612458fb3731dbaf5e9db3 Mon Sep 17 00:00:00 2001 From: Vitaly Koulakov Date: Mon, 25 Mar 2019 15:06:24 +0300 Subject: [PATCH 3/9] WebAPI-975 Extract Cohort Characterization analysis to external package --- .../cohortcharacterization/CcServiceImpl.java | 26 +++--- .../BaseCcDTOToCcEntityConverter.java | 3 +- .../domain/CcGenerationEntity.java | 5 - ...nalysisGenerationInfoEntityRepository.java | 5 +- .../AnalysisGenerationBaseInfo.java | 27 ++++++ .../generation/AnalysisGenerationInfo.java | 26 +----- .../AnalysisGenerationInfoEntity.java | 4 + .../common/generation/CommonGeneration.java | 4 +- .../domain/EstimationGenerationEntity.java | 5 - .../webapi/pathway/PathwayController.java | 3 +- .../ohdsi/webapi/pathway/PathwayService.java | 3 + .../webapi/pathway/PathwayServiceImpl.java | 28 +++++- .../PathwayAnalysisGenerationEntity.java | 5 - .../domain/PredictionGenerationEntity.java | 5 - ...14500__delete_design_column_from_views.sql | 88 ++++++++++++++++++ ...14500__delete_design_column_from_views.sql | 91 +++++++++++++++++++ ...14500__delete_design_column_from_views.sql | 88 ++++++++++++++++++ 17 files changed, 348 insertions(+), 68 deletions(-) create mode 100644 src/main/java/org/ohdsi/webapi/common/generation/AnalysisGenerationBaseInfo.java create mode 100644 src/main/resources/db/migration/oracle/V2.8.0.20190319114500__delete_design_column_from_views.sql create mode 100644 src/main/resources/db/migration/postgresql/V2.8.0.20190319114500__delete_design_column_from_views.sql create mode 100644 src/main/resources/db/migration/sqlserver/V2.8.0.20190319114500__delete_design_column_from_views.sql diff --git a/src/main/java/org/ohdsi/webapi/cohortcharacterization/CcServiceImpl.java b/src/main/java/org/ohdsi/webapi/cohortcharacterization/CcServiceImpl.java index eb263d463c..02fbcd0bcc 100644 --- a/src/main/java/org/ohdsi/webapi/cohortcharacterization/CcServiceImpl.java +++ b/src/main/java/org/ohdsi/webapi/cohortcharacterization/CcServiceImpl.java @@ -1,8 +1,10 @@ package org.ohdsi.webapi.cohortcharacterization; import com.cosium.spring.data.jpa.entity.graph.domain.EntityGraph; +import com.fasterxml.jackson.core.type.TypeReference; import com.google.common.collect.ImmutableList; import org.apache.commons.lang3.StringUtils; +import org.ohdsi.analysis.Utils; import org.ohdsi.analysis.WithId; import org.ohdsi.analysis.cohortcharacterization.design.CcResultType; import org.ohdsi.analysis.cohortcharacterization.design.CohortCharacterization; @@ -12,19 +14,19 @@ import org.ohdsi.webapi.cohortcharacterization.converter.SerializedCcToCcConverter; import org.ohdsi.webapi.cohortcharacterization.domain.*; import org.ohdsi.webapi.cohortcharacterization.dto.CcDistributionStat; +import org.ohdsi.webapi.cohortcharacterization.dto.CcExportDTO; import org.ohdsi.webapi.cohortcharacterization.dto.CcPrevalenceStat; import org.ohdsi.webapi.cohortcharacterization.dto.CcResult; import org.ohdsi.webapi.cohortcharacterization.repository.*; import org.ohdsi.webapi.cohortdefinition.CohortDefinition; -import org.ohdsi.webapi.cohortdefinition.CohortDefinitionRepository; import org.ohdsi.webapi.common.DesignImportService; +import org.ohdsi.webapi.common.generation.AnalysisGenerationInfoEntity; import org.ohdsi.webapi.common.generation.GenerationUtils; import org.ohdsi.webapi.feanalysis.FeAnalysisService; import org.ohdsi.webapi.feanalysis.domain.FeAnalysisEntity; import org.ohdsi.webapi.feanalysis.domain.FeAnalysisWithCriteriaEntity; import org.ohdsi.webapi.job.GeneratesNotification; import org.ohdsi.webapi.job.JobExecutionResource; -import org.ohdsi.webapi.job.JobTemplate; import org.ohdsi.webapi.service.*; import org.ohdsi.webapi.shiro.annotations.CcGenerationId; import org.ohdsi.webapi.shiro.annotations.DataSourceAccess; @@ -43,9 +45,11 @@ import org.springframework.batch.core.JobParametersBuilder; import org.springframework.batch.core.job.builder.SimpleJobBuilder; import org.springframework.batch.core.repository.JobRepository; +import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.context.ApplicationEventPublisher; import org.springframework.context.annotation.DependsOn; import org.springframework.core.convert.ConversionService; +import org.springframework.core.convert.support.GenericConversionService; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; import org.springframework.stereotype.Service; @@ -94,11 +98,9 @@ public class CcServiceImpl extends AbstractDaoService implements CcService, Gene private CcStrataRepository strataRepository; private CcConceptSetRepository conceptSetRepository; private FeAnalysisService analysisService; - private CohortDefinitionRepository cohortRepository; private CcGenerationEntityRepository ccGenerationRepository; private FeatureExtractionService featureExtractionService; private DesignImportService designImportService; - private CohortGenerationService cohortGenerationService; private AnalysisGenerationInfoEntityRepository analysisGenerationInfoEntityRepository; private SourceService sourceService; private GenerationUtils generationUtils; @@ -108,6 +110,7 @@ public class CcServiceImpl extends AbstractDaoService implements CcService, Gene private final JobRepository jobRepository; private final SourceAwareSqlRender sourceAwareSqlRender; private final JobService jobService; + private final GenericConversionService genericConversionService; public CcServiceImpl( final CcRepository ccRepository, @@ -115,13 +118,10 @@ public CcServiceImpl( final CcStrataRepository strataRepository, final CcConceptSetRepository conceptSetRepository, final FeAnalysisService analysisService, - final CohortDefinitionRepository cohortRepository, - final JobTemplate jobTemplate, final CcGenerationEntityRepository ccGenerationRepository, final FeatureExtractionService featureExtractionService, final ConversionService conversionService, final DesignImportService designImportService, - final CohortGenerationService cohortGenerationService, final JobRepository jobRepository, final AnalysisGenerationInfoEntityRepository analysisGenerationInfoEntityRepository, final SourceService sourceService, @@ -129,18 +129,16 @@ public CcServiceImpl( SourceAwareSqlRender sourceAwareSqlRender, final EntityManager entityManager, final JobService jobService, - final ApplicationEventPublisher eventPublisher - ) { + final ApplicationEventPublisher eventPublisher, + @Qualifier("conversionService") final GenericConversionService genericConversionService) { this.repository = ccRepository; this.paramRepository = paramRepository; this.strataRepository = strataRepository; this.conceptSetRepository = conceptSetRepository; this.analysisService = analysisService; - this.cohortRepository = cohortRepository; this.ccGenerationRepository = ccGenerationRepository; this.featureExtractionService = featureExtractionService; this.designImportService = designImportService; - this.cohortGenerationService = cohortGenerationService; this.jobRepository = jobRepository; this.analysisGenerationInfoEntityRepository = analysisGenerationInfoEntityRepository; this.sourceService = sourceService; @@ -149,6 +147,7 @@ public CcServiceImpl( this.entityManager = entityManager; this.jobService = jobService; this.eventPublisher = eventPublisher; + this.genericConversionService = genericConversionService; SerializedCcToCcConverter.setConversionService(conversionService); } @@ -355,7 +354,10 @@ public CohortCharacterizationEntity findByIdWithLinkedEntities(final Long id) { @Override @DataSourceAccess public CohortCharacterization findDesignByGenerationId(@CcGenerationId final Long id) { - return ccGenerationRepository.findById(id).map(gen -> gen.getDesign()).orElse(null); + final AnalysisGenerationInfoEntity entity = analysisGenerationInfoEntityRepository.findById(id) + .orElseThrow(() -> new IllegalArgumentException("Analysis with id: " + id + " cannot be found")); + return genericConversionService.convert(Utils.deserialize(entity.getDesign(), + new TypeReference() {}), CohortCharacterizationEntity.class); } @Override diff --git a/src/main/java/org/ohdsi/webapi/cohortcharacterization/converter/BaseCcDTOToCcEntityConverter.java b/src/main/java/org/ohdsi/webapi/cohortcharacterization/converter/BaseCcDTOToCcEntityConverter.java index 0e4f3c5b5e..50867a5d3a 100644 --- a/src/main/java/org/ohdsi/webapi/cohortcharacterization/converter/BaseCcDTOToCcEntityConverter.java +++ b/src/main/java/org/ohdsi/webapi/cohortcharacterization/converter/BaseCcDTOToCcEntityConverter.java @@ -1,10 +1,9 @@ package org.ohdsi.webapi.cohortcharacterization.converter; import com.odysseusinc.arachne.commons.utils.ConverterUtils; -import org.apache.commons.lang3.ObjectUtils; import org.ohdsi.analysis.CohortMetadata; import org.ohdsi.analysis.Utils; -import org.ohdsi.webapi.cohortcharacterization.CcResultType; +import org.ohdsi.analysis.cohortcharacterization.design.CcResultType; import org.ohdsi.webapi.cohortcharacterization.domain.CcStrataConceptSetEntity; import org.ohdsi.webapi.cohortcharacterization.domain.CcParamEntity; import org.ohdsi.webapi.cohortcharacterization.domain.CcStrataEntity; diff --git a/src/main/java/org/ohdsi/webapi/cohortcharacterization/domain/CcGenerationEntity.java b/src/main/java/org/ohdsi/webapi/cohortcharacterization/domain/CcGenerationEntity.java index 888f3703db..d597d39636 100644 --- a/src/main/java/org/ohdsi/webapi/cohortcharacterization/domain/CcGenerationEntity.java +++ b/src/main/java/org/ohdsi/webapi/cohortcharacterization/domain/CcGenerationEntity.java @@ -6,7 +6,6 @@ import javax.persistence.ManyToOne; import javax.persistence.Table; -import org.ohdsi.webapi.cohortcharacterization.converter.SerializedCcToCcConverter; import org.ohdsi.webapi.common.generation.CommonGeneration; @Entity @@ -20,8 +19,4 @@ public class CcGenerationEntity extends CommonGeneration { public CohortCharacterizationEntity getCohortCharacterization() { return cohortCharacterization; } - - public CohortCharacterizationEntity getDesign() { - return info != null ? new SerializedCcToCcConverter().convertToEntityAttribute(info.getDesign()) : null; - } } diff --git a/src/main/java/org/ohdsi/webapi/cohortcharacterization/repository/AnalysisGenerationInfoEntityRepository.java b/src/main/java/org/ohdsi/webapi/cohortcharacterization/repository/AnalysisGenerationInfoEntityRepository.java index d18fb947e0..6ec0327fbd 100644 --- a/src/main/java/org/ohdsi/webapi/cohortcharacterization/repository/AnalysisGenerationInfoEntityRepository.java +++ b/src/main/java/org/ohdsi/webapi/cohortcharacterization/repository/AnalysisGenerationInfoEntityRepository.java @@ -3,5 +3,8 @@ import com.cosium.spring.data.jpa.entity.graph.repository.EntityGraphJpaRepository; import org.ohdsi.webapi.common.generation.AnalysisGenerationInfoEntity; -public interface AnalysisGenerationInfoEntityRepository extends EntityGraphJpaRepository { +import java.util.Optional; + +public interface AnalysisGenerationInfoEntityRepository extends EntityGraphJpaRepository { + Optional findById(Long generationId); } diff --git a/src/main/java/org/ohdsi/webapi/common/generation/AnalysisGenerationBaseInfo.java b/src/main/java/org/ohdsi/webapi/common/generation/AnalysisGenerationBaseInfo.java new file mode 100644 index 0000000000..195ef82d72 --- /dev/null +++ b/src/main/java/org/ohdsi/webapi/common/generation/AnalysisGenerationBaseInfo.java @@ -0,0 +1,27 @@ +package org.ohdsi.webapi.common.generation; + +import org.ohdsi.webapi.shiro.Entities.UserEntity; + +import javax.persistence.*; + +@Embeddable +@MappedSuperclass +public class AnalysisGenerationBaseInfo { + + @Column(name = "hash_code") + protected Integer hashCode; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "created_by_id", updatable = false) + protected UserEntity createdBy; + + public Integer getHashCode() { + + return hashCode; + } + + public UserEntity getCreatedBy() { + + return createdBy; + } +} diff --git a/src/main/java/org/ohdsi/webapi/common/generation/AnalysisGenerationInfo.java b/src/main/java/org/ohdsi/webapi/common/generation/AnalysisGenerationInfo.java index aae039b565..6b46ca7db1 100644 --- a/src/main/java/org/ohdsi/webapi/common/generation/AnalysisGenerationInfo.java +++ b/src/main/java/org/ohdsi/webapi/common/generation/AnalysisGenerationInfo.java @@ -1,38 +1,16 @@ package org.ohdsi.webapi.common.generation; -import org.ohdsi.webapi.shiro.Entities.UserEntity; - import javax.persistence.Column; import javax.persistence.Embeddable; -import javax.persistence.FetchType; -import javax.persistence.JoinColumn; -import javax.persistence.ManyToOne; @Embeddable -public class AnalysisGenerationInfo { +public class AnalysisGenerationInfo extends AnalysisGenerationBaseInfo{ @Column(name = "design") protected String design; - @Column(name = "hash_code") - protected Integer hashCode; - - @ManyToOne(fetch = FetchType.LAZY) - @JoinColumn(name = "created_by_id", updatable = false) - protected UserEntity createdBy; - public String getDesign() { return design; } - - public Integer getHashCode() { - - return hashCode; - } - - public UserEntity getCreatedBy() { - - return createdBy; - } -} +} \ No newline at end of file diff --git a/src/main/java/org/ohdsi/webapi/common/generation/AnalysisGenerationInfoEntity.java b/src/main/java/org/ohdsi/webapi/common/generation/AnalysisGenerationInfoEntity.java index 46832e8326..40345d17d1 100644 --- a/src/main/java/org/ohdsi/webapi/common/generation/AnalysisGenerationInfoEntity.java +++ b/src/main/java/org/ohdsi/webapi/common/generation/AnalysisGenerationInfoEntity.java @@ -24,6 +24,10 @@ public void setId(Long id) { this.id = id; } + public String getDesign() { + return info.getDesign(); + } + public void setDesign(String serializedDesign) { this.info.design = serializedDesign; diff --git a/src/main/java/org/ohdsi/webapi/common/generation/CommonGeneration.java b/src/main/java/org/ohdsi/webapi/common/generation/CommonGeneration.java index af7791ebc5..884a24ef96 100644 --- a/src/main/java/org/ohdsi/webapi/common/generation/CommonGeneration.java +++ b/src/main/java/org/ohdsi/webapi/common/generation/CommonGeneration.java @@ -40,7 +40,7 @@ public abstract class CommonGeneration { private String exitMessage; @Embedded - protected AnalysisGenerationInfo info; + protected AnalysisGenerationBaseInfo info; public Long getId() { @@ -72,8 +72,6 @@ public String getExitMessage() { return exitMessage; } - public abstract T getDesign(); - public Integer getHashCode() { return this.info != null ? this.info.getHashCode() : null; } diff --git a/src/main/java/org/ohdsi/webapi/estimation/domain/EstimationGenerationEntity.java b/src/main/java/org/ohdsi/webapi/estimation/domain/EstimationGenerationEntity.java index dee123d34b..4a4ec0c058 100644 --- a/src/main/java/org/ohdsi/webapi/estimation/domain/EstimationGenerationEntity.java +++ b/src/main/java/org/ohdsi/webapi/estimation/domain/EstimationGenerationEntity.java @@ -16,9 +16,4 @@ public class EstimationGenerationEntity extends ExecutionEngineGenerationEntity public Estimation getEstimationAnalysis() { return estimationAnalysis; } - - @Override - public T getDesign() { - return null; - } } diff --git a/src/main/java/org/ohdsi/webapi/pathway/PathwayController.java b/src/main/java/org/ohdsi/webapi/pathway/PathwayController.java index 369f08daaf..db1bc23b5b 100644 --- a/src/main/java/org/ohdsi/webapi/pathway/PathwayController.java +++ b/src/main/java/org/ohdsi/webapi/pathway/PathwayController.java @@ -219,8 +219,7 @@ public String getGenerationDesign( @PathParam("generationId") final Long generationId ) { - PathwayAnalysisGenerationEntity generation = pathwayService.getGeneration(generationId); - return new SerializedPathwayAnalysisToPathwayAnalysisConverter().convertToDatabaseColumn(generation.getDesign()); + return pathwayService.findDesignByGenerationId(generationId); } diff --git a/src/main/java/org/ohdsi/webapi/pathway/PathwayService.java b/src/main/java/org/ohdsi/webapi/pathway/PathwayService.java index 2adc7ff833..b9b994a6b9 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.internal.PathwayAnalysisResult; +import org.ohdsi.webapi.shiro.annotations.PathwayAnalysisGenerationId; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; @@ -43,4 +44,6 @@ public interface PathwayService { void cancelGeneration(Integer pathwayAnalysisId, Integer sourceId); int countLikeName(String copyName); + + String findDesignByGenerationId(@PathwayAnalysisGenerationId final Long id); } diff --git a/src/main/java/org/ohdsi/webapi/pathway/PathwayServiceImpl.java b/src/main/java/org/ohdsi/webapi/pathway/PathwayServiceImpl.java index 6155d74c87..3e9fbdd8f8 100644 --- a/src/main/java/org/ohdsi/webapi/pathway/PathwayServiceImpl.java +++ b/src/main/java/org/ohdsi/webapi/pathway/PathwayServiceImpl.java @@ -1,13 +1,16 @@ package org.ohdsi.webapi.pathway; import com.cosium.spring.data.jpa.entity.graph.domain.EntityGraph; +import com.fasterxml.jackson.core.type.TypeReference; import com.google.common.base.MoreObjects; +import org.ohdsi.analysis.Utils; import org.ohdsi.circe.helper.ResourceHelper; import org.ohdsi.sql.SqlRender; import org.ohdsi.sql.SqlTranslate; import org.ohdsi.webapi.cohortcharacterization.repository.AnalysisGenerationInfoEntityRepository; import org.ohdsi.webapi.cohortdefinition.CohortDefinition; import org.ohdsi.webapi.common.DesignImportService; +import org.ohdsi.webapi.common.generation.AnalysisGenerationInfoEntity; import org.ohdsi.webapi.common.generation.GenerationUtils; import org.ohdsi.webapi.job.GeneratesNotification; import org.ohdsi.webapi.job.JobExecutionResource; @@ -18,6 +21,7 @@ import org.ohdsi.webapi.pathway.domain.PathwayCohort; import org.ohdsi.webapi.pathway.domain.PathwayEventCohort; import org.ohdsi.webapi.pathway.domain.PathwayTargetCohort; +import org.ohdsi.webapi.pathway.dto.PathwayAnalysisExportDTO; import org.ohdsi.webapi.pathway.dto.internal.CohortPathways; import org.ohdsi.webapi.pathway.dto.internal.PathwayAnalysisResult; import org.ohdsi.webapi.pathway.dto.internal.PathwayCode; @@ -44,7 +48,9 @@ import org.springframework.batch.core.JobParametersBuilder; 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.core.convert.ConversionService; +import org.springframework.core.convert.support.GenericConversionService; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; import org.springframework.jdbc.core.JdbcTemplate; @@ -85,6 +91,7 @@ public class PathwayServiceImpl extends AbstractDaoService implements PathwaySer private final UserRepository userRepository; private final GenerationUtils generationUtils; private final JobService jobService; + private final GenericConversionService genericConversionService; private final EntityGraph defaultEntityGraph = EntityUtils.fromAttributePaths( "targetCohorts.cohortDefinition", @@ -106,7 +113,8 @@ public PathwayServiceImpl( AnalysisGenerationInfoEntityRepository analysisGenerationInfoEntityRepository, UserRepository userRepository, GenerationUtils generationUtils, - JobService jobService) { + JobService jobService, + @Qualifier("conversionService") GenericConversionService genericConversionService) { this.pathwayAnalysisRepository = pathwayAnalysisRepository; this.pathwayAnalysisGenerationRepository = pathwayAnalysisGenerationRepository; @@ -114,6 +122,7 @@ public PathwayServiceImpl( this.jobTemplate = jobTemplate; this.entityManager = entityManager; this.jobService = jobService; + this.genericConversionService = genericConversionService; this.security = security; this.designImportService = designImportService; this.analysisGenerationInfoEntityRepository = analysisGenerationInfoEntityRepository; @@ -400,7 +409,10 @@ public PathwayAnalysisResult getResultingPathways(final @PathwayAnalysisGenerati List targetCohortStatsList = queryGenerationStats(source, generationId); - generation.getDesign().getTargetCohorts().forEach(tc -> { + final PathwayAnalysisEntity design = genericConversionService + .convert(Utils.deserialize(findDesignByGenerationId(generationId), + new TypeReference() {}), PathwayAnalysisEntity.class); + design.getTargetCohorts().forEach(tc -> { CohortPathways cohortPathways = new CohortPathways(); cohortPathways.setCohortId(tc.getCohortDefinition().getId()); @@ -427,7 +439,7 @@ public PathwayAnalysisResult getResultingPathways(final @PathwayAnalysisGenerati .collect(Collectors.groupingBy(Function.identity(), summingInt(x -> 1))) .entrySet() .stream() - .filter(entry -> entry.getValue() > generation.getDesign().getMinCellCount()) + .filter(entry -> entry.getValue() > design.getMinCellCount()) .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); cohortPathways.setPathwaysCounts(chains); @@ -436,7 +448,7 @@ public PathwayAnalysisResult getResultingPathways(final @PathwayAnalysisGenerati }); comboCodes.forEach(code -> { - List eventCohorts = getEventCohortsByComboCode(generation.getDesign(), code); + List eventCohorts = getEventCohortsByComboCode(design, code); String names = eventCohorts.stream() .map(PathwayEventCohort::getName) .collect(Collectors.joining(",")); @@ -446,6 +458,14 @@ public PathwayAnalysisResult getResultingPathways(final @PathwayAnalysisGenerati return result; } + @Override + @DataSourceAccess + public String findDesignByGenerationId(@PathwayAnalysisGenerationId final Long id) { + final AnalysisGenerationInfoEntity entity = analysisGenerationInfoEntityRepository.findById(id) + .orElseThrow(() -> new IllegalArgumentException("Analysis with id: " + id + " cannot be found")); + return entity.getDesign(); + } + private List queryGenerationResults(Source source, Long generationId, Integer targetCohortId) { PreparedStatementRenderer pathwayEventsPsr = new PreparedStatementRenderer( diff --git a/src/main/java/org/ohdsi/webapi/pathway/domain/PathwayAnalysisGenerationEntity.java b/src/main/java/org/ohdsi/webapi/pathway/domain/PathwayAnalysisGenerationEntity.java index 9a6eac8cd8..9a0eeb43a4 100644 --- a/src/main/java/org/ohdsi/webapi/pathway/domain/PathwayAnalysisGenerationEntity.java +++ b/src/main/java/org/ohdsi/webapi/pathway/domain/PathwayAnalysisGenerationEntity.java @@ -1,7 +1,6 @@ package org.ohdsi.webapi.pathway.domain; import org.ohdsi.webapi.common.generation.CommonGeneration; -import org.ohdsi.webapi.pathway.converter.SerializedPathwayAnalysisToPathwayAnalysisConverter; import javax.persistence.Entity; import javax.persistence.FetchType; @@ -21,8 +20,4 @@ public PathwayAnalysisEntity getPathwayAnalysis() { return pathwayAnalysis; } - - public PathwayAnalysisEntity getDesign() { - return new SerializedPathwayAnalysisToPathwayAnalysisConverter().convertToEntityAttribute(this.info.getDesign()); - } } diff --git a/src/main/java/org/ohdsi/webapi/prediction/domain/PredictionGenerationEntity.java b/src/main/java/org/ohdsi/webapi/prediction/domain/PredictionGenerationEntity.java index 3371aa367d..445a5e8e47 100644 --- a/src/main/java/org/ohdsi/webapi/prediction/domain/PredictionGenerationEntity.java +++ b/src/main/java/org/ohdsi/webapi/prediction/domain/PredictionGenerationEntity.java @@ -12,9 +12,4 @@ public class PredictionGenerationEntity extends ExecutionEngineGenerationEntity @ManyToOne(targetEntity = PredictionAnalysis.class, fetch = FetchType.LAZY) @JoinColumn(name = "prediction_id") private PredictionAnalysis predictionAnalysis; - - @Override - public PredictionAnalysis getDesign() { - return null; - } } diff --git a/src/main/resources/db/migration/oracle/V2.8.0.20190319114500__delete_design_column_from_views.sql b/src/main/resources/db/migration/oracle/V2.8.0.20190319114500__delete_design_column_from_views.sql new file mode 100644 index 0000000000..51fa3df528 --- /dev/null +++ b/src/main/resources/db/migration/oracle/V2.8.0.20190319114500__delete_design_column_from_views.sql @@ -0,0 +1,88 @@ +DROP VIEW ${ohdsiSchema}.cc_generation; +CREATE OR REPLACE VIEW ${ohdsiSchema}.cc_generation as + SELECT job.job_execution_id id, + job.create_time start_time, + job.end_time end_time, + job.status status, + job.exit_message exit_message, + CAST(CAST(cc_id_param.string_val AS VARCHAR2(50)) AS NUMBER(10)) cc_id, + CAST(CAST(source_param.string_val AS VARCHAR2(50)) AS NUMBER(10)) source_id, + -- Generation info based + gen_info.hash_code hash_code, + gen_info.created_by_id created_by_id + FROM ${ohdsiSchema}.batch_job_execution job + JOIN ${ohdsiSchema}.batch_job_execution_params cc_id_param + ON job.job_execution_id = cc_id_param.job_execution_id AND cc_id_param.key_name = 'cohort_characterization_id' + JOIN ${ohdsiSchema}.batch_job_execution_params source_param + ON job.job_execution_id = source_param.job_execution_id AND source_param.key_name = 'source_id' + LEFT JOIN ${ohdsiSchema}.analysis_generation_info gen_info + ON job.job_execution_id = gen_info.job_execution_id + ORDER BY start_time DESC; + +DROP VIEW ${ohdsiSchema}.estimation_analysis_generation; +CREATE OR REPLACE VIEW ${ohdsiSchema}.estimation_analysis_generation as + SELECT + job.job_execution_id id, + job.create_time start_time, + job.end_time end_time, + job.status status, + job.exit_message exit_message, + CAST(CAST(estimation_id_param.string_val AS VARCHAR2(50)) AS NUMBER(10)) estimation_id, + CAST(CAST(source_param.string_val AS VARCHAR2(50)) AS NUMBER(10)) source_id, + passwd_param.string_val update_password, + -- Generation info based + gen_info.hash_code hash_code, + gen_info.created_by_id created_by_id, + -- Execution info based + exec_info.id analysis_execution_id + FROM ${ohdsiSchema}.batch_job_execution job + JOIN ${ohdsiSchema}.batch_job_execution_params estimation_id_param ON job.job_execution_id = estimation_id_param.job_execution_id AND estimation_id_param.key_name = 'estimation_analysis_id' + JOIN ${ohdsiSchema}.batch_job_execution_params source_param ON job.job_execution_id = source_param.job_execution_id AND source_param.key_name = 'source_id' + JOIN ${ohdsiSchema}.batch_job_execution_params passwd_param ON job.job_execution_id = passwd_param.job_execution_id AND passwd_param.key_name = 'update_password' + LEFT JOIN ${ohdsiSchema}.ee_analysis_status exec_info ON job.job_execution_id = exec_info.job_execution_id + LEFT JOIN ${ohdsiSchema}.analysis_generation_info gen_info ON job.job_execution_id = gen_info.job_execution_id; + +DROP VIEW ${ohdsiSchema}.pathway_analysis_generation; +CREATE OR REPLACE VIEW ${ohdsiSchema}.pathway_analysis_generation as +SELECT + job.job_execution_id id, + job.create_time start_time, + job.end_time end_time, + job.status status, + job.exit_message exit_message, + CAST(CAST(pa_id_param.string_val AS VARCHAR2(50)) AS NUMBER(10)) pathway_analysis_id, + CAST(CAST(source_param.string_val AS VARCHAR2(50)) AS NUMBER(10)) source_id, + -- Generation info based + gen_info.hash_code hash_code, + gen_info.created_by_id created_by_id +FROM ${ohdsiSchema}.batch_job_execution job + JOIN ${ohdsiSchema}.batch_job_execution_params pa_id_param + ON job.job_execution_id = pa_id_param.job_execution_id AND pa_id_param.key_name = 'pathway_analysis_id' + JOIN ${ohdsiSchema}.batch_job_execution_params source_param + ON job.job_execution_id = source_param.job_execution_id AND source_param.key_name = 'source_id' + LEFT JOIN ${ohdsiSchema}.analysis_generation_info gen_info + ON job.job_execution_id = gen_info.job_execution_id +ORDER BY start_time DESC; + +DROP VIEW ${ohdsiSchema}.prediction_analysis_generation; +CREATE OR REPLACE VIEW ${ohdsiSchema}.prediction_analysis_generation as + SELECT + job.job_execution_id id, + job.create_time start_time, + job.end_time end_time, + job.status status, + job.exit_message exit_message, + CAST(CAST(plp_id_param.string_val AS VARCHAR2(50)) AS NUMBER(10)) prediction_id, + CAST(CAST(source_param.string_val AS VARCHAR2(50)) AS NUMBER(10)) source_id, + passwd_param.string_val update_password, + -- Generation info based + gen_info.hash_code hash_code, + gen_info.created_by_id created_by_id, + -- Execution info based + exec_info.id analysis_execution_id + FROM ${ohdsiSchema}.batch_job_execution job + JOIN ${ohdsiSchema}.batch_job_execution_params plp_id_param ON job.job_execution_id = plp_id_param.job_execution_id AND plp_id_param.key_name = 'prediction_analysis_id' + JOIN ${ohdsiSchema}.batch_job_execution_params source_param ON job.job_execution_id = source_param.job_execution_id AND source_param.key_name = 'source_id' + JOIN ${ohdsiSchema}.batch_job_execution_params passwd_param ON job.job_execution_id = passwd_param.job_execution_id AND passwd_param.key_name = 'update_password' + LEFT JOIN ${ohdsiSchema}.ee_analysis_status exec_info ON job.job_execution_id = exec_info.job_execution_id + LEFT JOIN ${ohdsiSchema}.analysis_generation_info gen_info ON job.job_execution_id = gen_info.job_execution_id; diff --git a/src/main/resources/db/migration/postgresql/V2.8.0.20190319114500__delete_design_column_from_views.sql b/src/main/resources/db/migration/postgresql/V2.8.0.20190319114500__delete_design_column_from_views.sql new file mode 100644 index 0000000000..771040ff0e --- /dev/null +++ b/src/main/resources/db/migration/postgresql/V2.8.0.20190319114500__delete_design_column_from_views.sql @@ -0,0 +1,91 @@ +DROP VIEW ${ohdsiSchema}.cc_generation; +CREATE OR REPLACE VIEW ${ohdsiSchema}.cc_generation as ( +SELECT + -- Spring batch based + job.job_execution_id id, + job.create_time start_time, + job.end_time end_time, + job.status status, + job.exit_message exit_message, + CAST(cc_id_param.string_val AS INTEGER) cc_id, + CAST(source_param.string_val AS INTEGER) source_id, + -- Generation info based + gen_info.hash_code hash_code, + gen_info.created_by_id created_by_id +FROM ${ohdsiSchema}.batch_job_execution job + JOIN ${ohdsiSchema}.batch_job_execution_params cc_id_param + ON job.job_execution_id = cc_id_param.job_execution_id AND cc_id_param.key_name = 'cohort_characterization_id' + JOIN ${ohdsiSchema}.batch_job_execution_params source_param + ON job.job_execution_id = source_param.job_execution_id AND source_param.key_name = 'source_id' + LEFT JOIN ${ohdsiSchema}.analysis_generation_info gen_info + ON job.job_execution_id = gen_info.job_execution_id +ORDER BY start_time DESC +); + +DROP VIEW ${ohdsiSchema}.estimation_analysis_generation; +CREATE OR REPLACE VIEW ${ohdsiSchema}.estimation_analysis_generation as + SELECT + job.job_execution_id id, + job.create_time start_time, + job.end_time end_time, + job.status status, + job.exit_message exit_message, + CAST(estimation_id_param.string_val AS INTEGER) estimation_id, + CAST(source_param.string_val AS INTEGER) source_id, + passwd_param.string_val update_password, + -- Generation info based + gen_info.hash_code hash_code, + gen_info.created_by_id created_by_id, + -- Execution info based + exec_info.id analysis_execution_id + FROM ${ohdsiSchema}.batch_job_execution job + JOIN ${ohdsiSchema}.batch_job_execution_params estimation_id_param ON job.job_execution_id = estimation_id_param.job_execution_id AND estimation_id_param.key_name = 'estimation_analysis_id' + JOIN ${ohdsiSchema}.batch_job_execution_params source_param ON job.job_execution_id = source_param.job_execution_id AND source_param.key_name = 'source_id' + JOIN ${ohdsiSchema}.batch_job_execution_params passwd_param ON job.job_execution_id = passwd_param.job_execution_id AND passwd_param.key_name = 'update_password' + LEFT JOIN ${ohdsiSchema}.ee_analysis_status exec_info ON job.job_execution_id = exec_info.job_execution_id + LEFT JOIN ${ohdsiSchema}.analysis_generation_info gen_info ON job.job_execution_id = gen_info.job_execution_id; + +DROP VIEW ${ohdsiSchema}.pathway_analysis_generation; +CREATE OR REPLACE VIEW ${ohdsiSchema}.pathway_analysis_generation as + (SELECT + job.job_execution_id id, + job.create_time start_time, + job.end_time end_time, + job.status status, + job.exit_message exit_message, + CAST(pa_id_param.string_val AS INTEGER) pathway_analysis_id, + CAST(source_param.string_val AS INTEGER) source_id, + -- Generation info based + gen_info.hash_code hash_code, + gen_info.created_by_id created_by_id +FROM ${ohdsiSchema}.batch_job_execution job + JOIN ${ohdsiSchema}.batch_job_execution_params pa_id_param + ON job.job_execution_id = pa_id_param.job_execution_id AND pa_id_param.key_name = 'pathway_analysis_id' + JOIN ${ohdsiSchema}.batch_job_execution_params source_param + ON job.job_execution_id = source_param.job_execution_id AND source_param.key_name = 'source_id' + LEFT JOIN ${ohdsiSchema}.analysis_generation_info gen_info + ON job.job_execution_id = gen_info.job_execution_id +ORDER BY start_time DESC); + +DROP VIEW ${ohdsiSchema}.prediction_analysis_generation; +CREATE OR REPLACE VIEW ${ohdsiSchema}.prediction_analysis_generation as + SELECT + job.job_execution_id id, + job.create_time start_time, + job.end_time end_time, + job.status status, + job.exit_message exit_message, + CAST(plp_id_param.string_val AS INTEGER) prediction_id, + CAST(source_param.string_val AS INTEGER) source_id, + passwd_param.string_val update_password, + -- Generation info based + gen_info.hash_code hash_code, + gen_info.created_by_id created_by_id, + -- Execution info based + exec_info.id analysis_execution_id + FROM ${ohdsiSchema}.batch_job_execution job + JOIN ${ohdsiSchema}.batch_job_execution_params plp_id_param ON job.job_execution_id = plp_id_param.job_execution_id AND plp_id_param.key_name = 'prediction_analysis_id' + JOIN ${ohdsiSchema}.batch_job_execution_params source_param ON job.job_execution_id = source_param.job_execution_id AND source_param.key_name = 'source_id' + JOIN ${ohdsiSchema}.batch_job_execution_params passwd_param ON job.job_execution_id = passwd_param.job_execution_id AND passwd_param.key_name = 'update_password' + LEFT JOIN ${ohdsiSchema}.ee_analysis_status exec_info ON job.job_execution_id = exec_info.job_execution_id + LEFT JOIN ${ohdsiSchema}.analysis_generation_info gen_info ON job.job_execution_id = gen_info.job_execution_id; \ No newline at end of file diff --git a/src/main/resources/db/migration/sqlserver/V2.8.0.20190319114500__delete_design_column_from_views.sql b/src/main/resources/db/migration/sqlserver/V2.8.0.20190319114500__delete_design_column_from_views.sql new file mode 100644 index 0000000000..c153d1bf45 --- /dev/null +++ b/src/main/resources/db/migration/sqlserver/V2.8.0.20190319114500__delete_design_column_from_views.sql @@ -0,0 +1,88 @@ +ALTER VIEW ${ohdsiSchema}.cc_generation as + (SELECT + job.job_execution_id id, + job.create_time start_time, + job.end_time end_time, + job.status status, + job.exit_message exit_message, + TRY_CAST(cc_id_param.string_val AS INTEGER) cc_id, + TRY_CAST(source_param.string_val AS INTEGER) source_id, + -- Generation info based + gen_info.hash_code hash_code, + gen_info.created_by_id created_by_id + FROM ${ohdsiSchema}.batch_job_execution job + JOIN ${ohdsiSchema}.batch_job_execution_params cc_id_param + ON job.job_execution_id = cc_id_param.job_execution_id AND cc_id_param.key_name = 'cohort_characterization_id' + JOIN ${ohdsiSchema}.batch_job_execution_params source_param + ON job.job_execution_id = source_param.job_execution_id AND source_param.key_name = 'source_id' + LEFT JOIN ${ohdsiSchema}.analysis_generation_info gen_info + ON job.job_execution_id = gen_info.job_execution_id + ); +GO + +ALTER VIEW ${ohdsiSchema}.estimation_analysis_generation as + (SELECT + job.job_execution_id id, + job.create_time start_time, + job.end_time end_time, + job.status status, + job.exit_message exit_message, + CAST(estimation_id_param.string_val AS INTEGER) estimation_id, + CAST(source_param.string_val AS INTEGER) source_id, + passwd_param.string_val update_password, + -- Generation info based + gen_info.hash_code hash_code, + gen_info.created_by_id created_by_id, + -- Execution info based + exec_info.id analysis_execution_id + FROM ${ohdsiSchema}.batch_job_execution job + JOIN ${ohdsiSchema}.batch_job_execution_params estimation_id_param ON job.job_execution_id = estimation_id_param.job_execution_id AND estimation_id_param.key_name = 'estimation_analysis_id' + JOIN ${ohdsiSchema}.batch_job_execution_params source_param ON job.job_execution_id = source_param.job_execution_id AND source_param.key_name = 'source_id' + JOIN ${ohdsiSchema}.batch_job_execution_params passwd_param ON job.job_execution_id = passwd_param.job_execution_id AND passwd_param.key_name = 'update_password' + LEFT JOIN ${ohdsiSchema}.ee_analysis_status exec_info ON job.job_execution_id = exec_info.job_execution_id + LEFT JOIN ${ohdsiSchema}.analysis_generation_info gen_info ON job.job_execution_id = gen_info.job_execution_id + ); +GO + +ALTER VIEW ${ohdsiSchema}.pathway_analysis_generation as ( +SELECT + job.job_execution_id id, + job.create_time start_time, + job.end_time end_time, + job.status status, + job.exit_message exit_message, + TRY_CAST(pa_id_param.string_val AS INTEGER) pathway_analysis_id, + TRY_CAST(source_param.string_val AS INTEGER) source_id, + -- Generation info based + gen_info.hash_code hash_code, + gen_info.created_by_id created_by_id +FROM ${ohdsiSchema}.batch_job_execution job +JOIN ${ohdsiSchema}.batch_job_execution_params pa_id_param ON job.job_execution_id = pa_id_param.job_execution_id AND pa_id_param.key_name = 'pathway_analysis_id' +JOIN ${ohdsiSchema}.batch_job_execution_params source_param ON job.job_execution_id = source_param.job_execution_id AND source_param.key_name = 'source_id' +LEFT JOIN ${ohdsiSchema}.analysis_generation_info gen_info ON job.job_execution_id = gen_info.job_execution_id +); +GO + +ALTER VIEW ${ohdsiSchema}.prediction_analysis_generation as + (SELECT + job.job_execution_id id, + job.create_time start_time, + job.end_time end_time, + job.status status, + job.exit_message exit_message, + CAST(plp_id_param.string_val AS INTEGER) prediction_id, + CAST(source_param.string_val AS INTEGER) source_id, + passwd_param.string_val update_password, + -- Generation info based + gen_info.hash_code hash_code, + gen_info.created_by_id created_by_id, + -- Execution info based + exec_info.id analysis_execution_id + FROM ${ohdsiSchema}.batch_job_execution job + JOIN ${ohdsiSchema}.batch_job_execution_params plp_id_param ON job.job_execution_id = plp_id_param.job_execution_id AND plp_id_param.key_name = 'prediction_analysis_id' + JOIN ${ohdsiSchema}.batch_job_execution_params source_param ON job.job_execution_id = source_param.job_execution_id AND source_param.key_name = 'source_id' + JOIN ${ohdsiSchema}.batch_job_execution_params passwd_param ON job.job_execution_id = passwd_param.job_execution_id AND passwd_param.key_name = 'update_password' + LEFT JOIN ${ohdsiSchema}.ee_analysis_status exec_info ON job.job_execution_id = exec_info.job_execution_id + LEFT JOIN ${ohdsiSchema}.analysis_generation_info gen_info ON job.job_execution_id = gen_info.job_execution_id +); +GO \ No newline at end of file From dc53fdc3c9380e56d5b7979c7a343c27e914eda3 Mon Sep 17 00:00:00 2001 From: Vitaly Koulakov Date: Wed, 27 Mar 2019 11:32:56 +0300 Subject: [PATCH 4/9] WebAPI-975 Extract Cohort Characterization analysis to external package --- .../cohortcharacterization/CcController.java | 63 +++++++++++-------- .../cohortcharacterization/CcService.java | 4 ++ .../cohortcharacterization/CcServiceImpl.java | 40 ++++++++++-- .../BaseCcToCcExportDTOConverter.java | 27 ++++++++ .../converter/CcToCcExportDTOConverter.java | 24 +------ ...ToCohortCharacterizationImplConverter.java | 12 ++++ .../CohortCharacterizationImpl.java | 55 ++++++++++++++++ .../generation/AnalysisExecutionSupport.java | 2 +- ...0326180601__add-cc-download-permission.sql | 9 +++ ...0326180601__add-cc-download-permission.sql | 9 +++ ...0326180601__add-cc-download-permission.sql | 9 +++ .../cohortcharacterizations/r/runAnalysis.R | 43 +++++++++++++ 12 files changed, 242 insertions(+), 55 deletions(-) create mode 100644 src/main/java/org/ohdsi/webapi/cohortcharacterization/converter/BaseCcToCcExportDTOConverter.java create mode 100644 src/main/java/org/ohdsi/webapi/cohortcharacterization/converter/CcToCohortCharacterizationImplConverter.java create mode 100644 src/main/java/org/ohdsi/webapi/cohortcharacterization/specification/CohortCharacterizationImpl.java create mode 100644 src/main/resources/db/migration/oracle/V2.8.0.20190326180601__add-cc-download-permission.sql create mode 100644 src/main/resources/db/migration/postgresql/V2.8.0.20190326180601__add-cc-download-permission.sql create mode 100644 src/main/resources/db/migration/sqlserver/V2.8.0.20190326180601__add-cc-download-permission.sql create mode 100644 src/main/resources/resources/cohortcharacterizations/r/runAnalysis.R diff --git a/src/main/java/org/ohdsi/webapi/cohortcharacterization/CcController.java b/src/main/java/org/ohdsi/webapi/cohortcharacterization/CcController.java index 383f867852..f014c97ffb 100644 --- a/src/main/java/org/ohdsi/webapi/cohortcharacterization/CcController.java +++ b/src/main/java/org/ohdsi/webapi/cohortcharacterization/CcController.java @@ -1,25 +1,7 @@ package org.ohdsi.webapi.cohortcharacterization; import com.odysseusinc.arachne.commons.utils.ConverterUtils; - -import java.util.Collections; -import java.util.List; -import java.util.Map; -import java.util.Objects; -import java.util.stream.Collectors; -import javax.ws.rs.Consumes; -import javax.ws.rs.DELETE; -import javax.ws.rs.DefaultValue; -import javax.ws.rs.GET; -import javax.ws.rs.POST; -import javax.ws.rs.PUT; -import javax.ws.rs.Path; -import javax.ws.rs.PathParam; -import javax.ws.rs.Produces; -import javax.ws.rs.QueryParam; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.Response; - +import org.ohdsi.analysis.Utils; import org.ohdsi.analysis.cohortcharacterization.design.CohortCharacterization; import org.ohdsi.analysis.cohortcharacterization.design.StandardFeatureAnalysisType; import org.ohdsi.featureExtraction.FeatureExtraction; @@ -27,13 +9,9 @@ import org.ohdsi.webapi.Pagination; import org.ohdsi.webapi.cohortcharacterization.domain.CcGenerationEntity; import org.ohdsi.webapi.cohortcharacterization.domain.CohortCharacterizationEntity; -import org.ohdsi.webapi.cohortcharacterization.dto.CcExportDTO; -import org.ohdsi.webapi.cohortcharacterization.dto.CcPrevalenceStat; -import org.ohdsi.webapi.cohortcharacterization.dto.CcResult; -import org.ohdsi.webapi.cohortcharacterization.dto.CcShortDTO; -import org.ohdsi.webapi.cohortcharacterization.dto.CohortCharacterizationDTO; -import org.ohdsi.webapi.common.generation.CommonGenerationDTO; +import org.ohdsi.webapi.cohortcharacterization.dto.*; import org.ohdsi.webapi.common.SourceMapKey; +import org.ohdsi.webapi.common.generation.CommonGenerationDTO; import org.ohdsi.webapi.common.sensitiveinfo.CommonGenerationSensitiveInfoService; import org.ohdsi.webapi.feanalysis.FeAnalysisService; import org.ohdsi.webapi.feanalysis.domain.FeAnalysisEntity; @@ -48,6 +26,17 @@ import org.springframework.stereotype.Controller; import org.springframework.transaction.annotation.Transactional; +import javax.ws.rs.*; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.util.Collections; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.stream.Collectors; + @Path("/cohort-characterization") @Controller @Transactional @@ -255,6 +244,30 @@ public List getPrevalenceStat(@PathParam("generationId") Long return stats; } + @GET + @Path("{id}/download") + @Consumes(MediaType.APPLICATION_JSON) + @Produces(MediaType.APPLICATION_OCTET_STREAM) + public Response downloadPackage(@PathParam("id") Long analysisId, @QueryParam("packageName") String packageName) { + + if (packageName == null) { + packageName = "CohortCharacterization" + String.valueOf(analysisId); + } + if (!Utils.isAlphaNumeric(packageName)) { + throw new IllegalArgumentException("The package name must be alphanumeric only."); + } + + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + + service.hydrateAnalysis(analysisId, packageName, baos); + + return Response + .ok(baos) + .type(MediaType.APPLICATION_OCTET_STREAM) + .header("Content-Disposition", String.format("attachment; filename=\"cohort_characterization_study_%d_export.zip\"", analysisId)) + .build(); + } + private void convertPresetAnalysesToLocal(List ccResults) { List presetFeAnalyses = feAnalysisService.findPresetAnalysesBySystemNames(ccResults.stream().map(CcResult::getAnalysisName).distinct().collect(Collectors.toList())); diff --git a/src/main/java/org/ohdsi/webapi/cohortcharacterization/CcService.java b/src/main/java/org/ohdsi/webapi/cohortcharacterization/CcService.java index a9c1654a00..32a1a23594 100644 --- a/src/main/java/org/ohdsi/webapi/cohortcharacterization/CcService.java +++ b/src/main/java/org/ohdsi/webapi/cohortcharacterization/CcService.java @@ -1,5 +1,7 @@ package org.ohdsi.webapi.cohortcharacterization; +import java.io.IOException; +import java.io.OutputStream; import java.util.List; import org.ohdsi.analysis.cohortcharacterization.design.CohortCharacterization; @@ -48,6 +50,8 @@ public interface CcService { List getPrevalenceStatsByGenerationId(final Long id, Long analysisId, final Long cohortId, final Long covariateId); + void hydrateAnalysis(Long analysisId, String packageName, OutputStream out); + void deleteCcGeneration(Long generationId); void cancelGeneration(Long id, String sourceKey); diff --git a/src/main/java/org/ohdsi/webapi/cohortcharacterization/CcServiceImpl.java b/src/main/java/org/ohdsi/webapi/cohortcharacterization/CcServiceImpl.java index 3fdcc072be..ef6d7bb953 100644 --- a/src/main/java/org/ohdsi/webapi/cohortcharacterization/CcServiceImpl.java +++ b/src/main/java/org/ohdsi/webapi/cohortcharacterization/CcServiceImpl.java @@ -7,10 +7,10 @@ import org.ohdsi.analysis.Utils; import org.ohdsi.analysis.WithId; import org.ohdsi.analysis.cohortcharacterization.design.CcResultType; -import org.ohdsi.analysis.Utils; import org.ohdsi.analysis.cohortcharacterization.design.CohortCharacterization; import org.ohdsi.analysis.cohortcharacterization.design.StandardFeatureAnalysisType; import org.ohdsi.circe.helper.ResourceHelper; +import org.ohdsi.hydra.Hydra; import org.ohdsi.sql.SqlTranslate; import org.ohdsi.webapi.cohortcharacterization.converter.SerializedCcToCcConverter; import org.ohdsi.webapi.cohortcharacterization.domain.*; @@ -19,6 +19,7 @@ import org.ohdsi.webapi.cohortcharacterization.dto.CcPrevalenceStat; import org.ohdsi.webapi.cohortcharacterization.dto.CcResult; import org.ohdsi.webapi.cohortcharacterization.repository.*; +import org.ohdsi.webapi.cohortcharacterization.specification.CohortCharacterizationImpl; import org.ohdsi.webapi.cohortdefinition.CohortDefinition; import org.ohdsi.webapi.common.DesignImportService; import org.ohdsi.webapi.common.generation.AnalysisGenerationInfoEntity; @@ -51,6 +52,7 @@ import org.springframework.context.annotation.DependsOn; import org.springframework.core.convert.ConversionService; import org.springframework.core.convert.support.GenericConversionService; +import org.springframework.core.env.Environment; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; import org.springframework.stereotype.Service; @@ -59,6 +61,7 @@ import javax.annotation.PostConstruct; import javax.persistence.EntityManager; import javax.ws.rs.NotFoundException; +import java.io.OutputStream; import java.sql.ResultSet; import java.sql.SQLException; import java.util.*; @@ -113,6 +116,8 @@ public class CcServiceImpl extends AbstractDaoService implements CcService, Gene private final JobService jobService; private final GenericConversionService genericConversionService; + private final Environment env; + public CcServiceImpl( final CcRepository ccRepository, final CcParamRepository paramRepository, @@ -131,7 +136,8 @@ public CcServiceImpl( final EntityManager entityManager, final JobService jobService, final ApplicationEventPublisher eventPublisher, - @Qualifier("conversionService") final GenericConversionService genericConversionService) { + @Qualifier("conversionService") final GenericConversionService genericConversionService, + Environment env) { this.repository = ccRepository; this.paramRepository = paramRepository; this.strataRepository = strataRepository; @@ -149,7 +155,8 @@ public CcServiceImpl( this.jobService = jobService; this.eventPublisher = eventPublisher; this.genericConversionService = genericConversionService; - SerializedCcToCcConverter.setConversionService(conversionService); + this.env = env; + SerializedCcToCcConverter.setConversionService(conversionService); } @Override @@ -331,9 +338,8 @@ public String getNameForCopy(String dtoName) { @Override public String serializeCc(final Long id) { - final CohortCharacterizationEntity cohortCharacterizationEntity = repository.findById(id) - .orElseThrow(() -> new IllegalArgumentException("Cohort characterization cannot be found by id: " + id)); - return this.serializeCc(cohortCharacterizationEntity); + + return Utils.serialize(exportCc(id), true); } @Override @@ -341,6 +347,14 @@ public String serializeCc(final CohortCharacterizationEntity cohortCharacterizat return new SerializedCcToCcConverter().convertToDatabaseColumn(cohortCharacterizationEntity); } + private CohortCharacterizationImpl exportCc(final Long id) { + final CohortCharacterizationEntity cohortCharacterizationEntity = repository.findById(id) + .orElseThrow(() -> new IllegalArgumentException("Cohort characterization cannot be found by id: " + id)); + CohortCharacterizationImpl cc = genericConversionService.convert(cohortCharacterizationEntity, CohortCharacterizationImpl.class); + cc.setOrganizationName(env.getRequiredProperty("organization.name")); + return cc; + } + @Override public CohortCharacterizationEntity findById(final Long id) { return repository.findById(id) @@ -371,6 +385,19 @@ public Page getPage(final Pageable pageable) { return repository.findAll(pageable); } + @Override + public void hydrateAnalysis(Long analysisId, String packageName, OutputStream out) { + + if (packageName == null || !Utils.isAlphaNumeric(packageName)) { + throw new IllegalArgumentException("The package name must be alphanumeric only."); + } + CohortCharacterizationImpl analysis = exportCc(analysisId); + analysis.setPackageName(packageName); + String studySpecs = Utils.serialize(analysis, true); + Hydra hydra = new Hydra(studySpecs); + hydra.hydrate(out); + } + @Override @DataSourceAccess public JobExecutionResource generateCc(final Long id, @SourceKey final String sourceKey) { @@ -654,4 +681,5 @@ private void invalidateGenerations() { return null; }); } + } diff --git a/src/main/java/org/ohdsi/webapi/cohortcharacterization/converter/BaseCcToCcExportDTOConverter.java b/src/main/java/org/ohdsi/webapi/cohortcharacterization/converter/BaseCcToCcExportDTOConverter.java new file mode 100644 index 0000000000..9915086389 --- /dev/null +++ b/src/main/java/org/ohdsi/webapi/cohortcharacterization/converter/BaseCcToCcExportDTOConverter.java @@ -0,0 +1,27 @@ +package org.ohdsi.webapi.cohortcharacterization.converter; + +import org.apache.commons.lang3.ObjectUtils; +import org.ohdsi.webapi.cohortcharacterization.domain.CohortCharacterizationEntity; +import org.ohdsi.webapi.cohortcharacterization.dto.CcExportDTO; +import org.ohdsi.webapi.cohortdefinition.dto.CohortDTO; +import org.ohdsi.webapi.feanalysis.dto.FeAnalysisDTO; + +import java.util.Set; +import java.util.TreeSet; + +public abstract class BaseCcToCcExportDTOConverter extends BaseCcToCcDTOConverter { + @Override + public T convert(CohortCharacterizationEntity source) { + + final T exportDTO = super.convert(source); + + Set convertedCohortDTOs = new TreeSet<>((o1, o2) -> ObjectUtils.compare(o1.getId(), o2.getId())); + convertedCohortDTOs.addAll(converterUtils.convertSet(source.getCohortDefinitions(), CohortDTO.class)); + exportDTO.setCohorts(convertedCohortDTOs); + + Set convertedFeAnalysisDTOs = new TreeSet<>((o1, o2) -> ObjectUtils.compare(o1.getId(), o2.getId())); + convertedFeAnalysisDTOs.addAll(converterUtils.convertSet(source.getFeatureAnalyses(), FeAnalysisDTO.class)); + exportDTO.setFeatureAnalyses(convertedFeAnalysisDTOs); + return exportDTO; + } +} diff --git a/src/main/java/org/ohdsi/webapi/cohortcharacterization/converter/CcToCcExportDTOConverter.java b/src/main/java/org/ohdsi/webapi/cohortcharacterization/converter/CcToCcExportDTOConverter.java index deeac720d8..73285cde9d 100644 --- a/src/main/java/org/ohdsi/webapi/cohortcharacterization/converter/CcToCcExportDTOConverter.java +++ b/src/main/java/org/ohdsi/webapi/cohortcharacterization/converter/CcToCcExportDTOConverter.java @@ -1,32 +1,10 @@ package org.ohdsi.webapi.cohortcharacterization.converter; -import org.apache.commons.lang3.ObjectUtils; -import org.ohdsi.webapi.cohortcharacterization.domain.CohortCharacterizationEntity; import org.ohdsi.webapi.cohortcharacterization.dto.CcExportDTO; -import org.ohdsi.webapi.cohortdefinition.dto.CohortDTO; -import org.ohdsi.webapi.feanalysis.dto.FeAnalysisDTO; import org.springframework.stereotype.Component; -import java.util.Set; -import java.util.TreeSet; - @Component -public class CcToCcExportDTOConverter extends BaseCcToCcDTOConverter { - - @Override - public CcExportDTO convert(CohortCharacterizationEntity source) { - - final CcExportDTO exportDTO = super.convert(source); - - Set convertedCohortDTOs = new TreeSet<>((o1, o2) -> ObjectUtils.compare(o1.getId(), o2.getId())); - convertedCohortDTOs.addAll(converterUtils.convertSet(source.getCohortDefinitions(), CohortDTO.class)); - exportDTO.setCohorts(convertedCohortDTOs); - - Set convertedFeAnalysisDTOs = new TreeSet<>((o1, o2) -> ObjectUtils.compare(o1.getId(), o2.getId())); - convertedFeAnalysisDTOs.addAll(converterUtils.convertSet(source.getFeatureAnalyses(), FeAnalysisDTO.class)); - exportDTO.setFeatureAnalyses(convertedFeAnalysisDTOs); - return exportDTO; - } +public class CcToCcExportDTOConverter extends BaseCcToCcExportDTOConverter { @Override protected CcExportDTO createResultObject() { diff --git a/src/main/java/org/ohdsi/webapi/cohortcharacterization/converter/CcToCohortCharacterizationImplConverter.java b/src/main/java/org/ohdsi/webapi/cohortcharacterization/converter/CcToCohortCharacterizationImplConverter.java new file mode 100644 index 0000000000..88b3fd127d --- /dev/null +++ b/src/main/java/org/ohdsi/webapi/cohortcharacterization/converter/CcToCohortCharacterizationImplConverter.java @@ -0,0 +1,12 @@ +package org.ohdsi.webapi.cohortcharacterization.converter; + +import org.ohdsi.webapi.cohortcharacterization.specification.CohortCharacterizationImpl; +import org.springframework.stereotype.Component; + +@Component +public class CcToCohortCharacterizationImplConverter extends BaseCcToCcExportDTOConverter { + @Override + protected CohortCharacterizationImpl createResultObject() { + return new CohortCharacterizationImpl(); + } +} diff --git a/src/main/java/org/ohdsi/webapi/cohortcharacterization/specification/CohortCharacterizationImpl.java b/src/main/java/org/ohdsi/webapi/cohortcharacterization/specification/CohortCharacterizationImpl.java new file mode 100644 index 0000000000..a2b57790a0 --- /dev/null +++ b/src/main/java/org/ohdsi/webapi/cohortcharacterization/specification/CohortCharacterizationImpl.java @@ -0,0 +1,55 @@ +package org.ohdsi.webapi.cohortcharacterization.specification; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import org.ohdsi.analysis.cohortcharacterization.design.CohortCharacterization; +import org.ohdsi.analysis.hydra.design.SkeletonTypeEnum; +import org.ohdsi.webapi.cohortcharacterization.dto.CcExportDTO; + +@JsonIgnoreProperties(ignoreUnknown = true) +public class CohortCharacterizationImpl extends CcExportDTO implements CohortCharacterization { + + @JsonProperty + private SkeletonTypeEnum skeletonType = SkeletonTypeEnum.COHORT_CHARACTERIZATION; + + @JsonProperty + private String skeletonVersion = "v0.0.1"; + + @JsonProperty + private String packageName = null; + + @JsonProperty + private String organizationName = null; + + public SkeletonTypeEnum getSkeletonType() { + return skeletonType; + } + + public void setSkeletonType(SkeletonTypeEnum skeletonType) { + this.skeletonType = skeletonType; + } + + public String getSkeletonVersion() { + return skeletonVersion; + } + + public void setSkeletonVersion(String skeletonVersion) { + this.skeletonVersion = skeletonVersion; + } + + public String getPackageName() { + return packageName; + } + + public void setPackageName(String packageName) { + this.packageName = packageName; + } + + public String getOrganizationName() { + return organizationName; + } + + public void setOrganizationName(String organizationName) { + this.organizationName = organizationName; + } +} diff --git a/src/main/java/org/ohdsi/webapi/common/generation/AnalysisExecutionSupport.java b/src/main/java/org/ohdsi/webapi/common/generation/AnalysisExecutionSupport.java index e9cc75d2fd..50e8aea000 100644 --- a/src/main/java/org/ohdsi/webapi/common/generation/AnalysisExecutionSupport.java +++ b/src/main/java/org/ohdsi/webapi/common/generation/AnalysisExecutionSupport.java @@ -12,7 +12,7 @@ public abstract class AnalysisExecutionSupport extends AbstractDaoService { - protected AnalysisFile prepareAnalysisExecution(String packageName, String packageFilename, Integer analysisId) { + protected AnalysisFile prepareAnalysisExecution(String packageName, String packageFilename, Number analysisId) { AnalysisFile execFile = new AnalysisFile(); execFile.setFileName("runAnalysis.R"); String[] paramNames = {"packageFile", "packageName", "analysisDir"}; diff --git a/src/main/resources/db/migration/oracle/V2.8.0.20190326180601__add-cc-download-permission.sql b/src/main/resources/db/migration/oracle/V2.8.0.20190326180601__add-cc-download-permission.sql new file mode 100644 index 0000000000..7d9b45d0e0 --- /dev/null +++ b/src/main/resources/db/migration/oracle/V2.8.0.20190326180601__add-cc-download-permission.sql @@ -0,0 +1,9 @@ +INSERT INTO ${ohdsiSchema}.sec_permission(id, value, description) VALUES + (${ohdsiSchema}.sec_permission_id_seq.nextval, 'cohort-characterization:*:download:get', 'Download Cohort Characterization package'); + +INSERT INTO ${ohdsiSchema}.sec_role_permission(id, role_id, permission_id) + SELECT ${ohdsiSchema}.sec_role_permission_sequence.nextval, sr.id, sp.id + FROM ${ohdsiSchema}.sec_permission SP, ${ohdsiSchema}.sec_role sr + WHERE sp.value IN ( + 'cohort-characterization:*:download:get' + ) AND sr.name IN ('Atlas users'); \ No newline at end of file diff --git a/src/main/resources/db/migration/postgresql/V2.8.0.20190326180601__add-cc-download-permission.sql b/src/main/resources/db/migration/postgresql/V2.8.0.20190326180601__add-cc-download-permission.sql new file mode 100644 index 0000000000..3dcaa6f0b3 --- /dev/null +++ b/src/main/resources/db/migration/postgresql/V2.8.0.20190326180601__add-cc-download-permission.sql @@ -0,0 +1,9 @@ +INSERT INTO ${ohdsiSchema}.sec_permission(id, value, description) VALUES + (nextval('${ohdsiSchema}.sec_permission_id_seq'), 'cohort-characterization:*:download:get', 'Download Cohort Characterization package'); + +INSERT INTO ${ohdsiSchema}.sec_role_permission(id, role_id, permission_id) + SELECT nextval('${ohdsiSchema}.sec_role_permission_sequence'), sr.id, sp.id + FROM ${ohdsiSchema}.sec_permission SP, ${ohdsiSchema}.sec_role sr + WHERE sp.value IN ( + 'cohort-characterization:*:download:get' + ) AND sr.name IN ('Atlas users'); \ No newline at end of file diff --git a/src/main/resources/db/migration/sqlserver/V2.8.0.20190326180601__add-cc-download-permission.sql b/src/main/resources/db/migration/sqlserver/V2.8.0.20190326180601__add-cc-download-permission.sql new file mode 100644 index 0000000000..4d7238cdb1 --- /dev/null +++ b/src/main/resources/db/migration/sqlserver/V2.8.0.20190326180601__add-cc-download-permission.sql @@ -0,0 +1,9 @@ +INSERT INTO ${ohdsiSchema}.sec_permission(id, value, description) VALUES + (NEXT VALUE FOR ${ohdsiSchema}.sec_permission_id_seq, 'cohort-characterization:*:download:get', 'Download Cohort Characterization package'); + +INSERT INTO ${ohdsiSchema}.sec_role_permission(id, role_id, permission_id) + SELECT NEXT VALUE FOR ${ohdsiSchema}.sec_role_permission_sequence, sr.id, sp.id + FROM ${ohdsiSchema}.sec_permission SP, ${ohdsiSchema}.sec_role sr + WHERE sp.value IN ( + 'cohort-characterization:*:download:get' + ) AND sr.name IN ('Atlas users'); \ No newline at end of file diff --git a/src/main/resources/resources/cohortcharacterizations/r/runAnalysis.R b/src/main/resources/resources/cohortcharacterizations/r/runAnalysis.R new file mode 100644 index 0000000000..d74d5f68db --- /dev/null +++ b/src/main/resources/resources/cohortcharacterizations/r/runAnalysis.R @@ -0,0 +1,43 @@ +library(devtools) +options(devtools.install.args = "--no-multiarch") + +setwd("./") +tryCatch({ + unzip('@packageFile', exdir = file.path(".", "@analysisDir")) + install_local(file.path(".", "@analysisDir")) +}, finally = { + unlink('@analysisDir', recursive = TRUE, force = TRUE) +}) + +library(DatabaseConnector) +library(@packageName) + +tryCatch({ + maxCores <- parallel::detectCores() + + dbms <- Sys.getenv("DBMS_TYPE") + connectionString <- Sys.getenv("CONNECTION_STRING") + user <- Sys.getenv("DBMS_USERNAME") + pwd <- Sys.getenv("DBMS_PASSWORD") + cdmDatabaseSchema <- Sys.getenv("DBMS_SCHEMA") + cohortsDatabaseSchema <- Sys.getenv("TARGET_SCHEMA") + tempSchema <- if (is.null(Sys.getenv("TEMP_SCHEMA"))) cohortsDatabaseSchema else Sys.getenv("TEMP_SCHEMA") + cohortTable <- Sys.getenv("COHORT_TARGET_TABLE") + + connectionDetails <- DatabaseConnector::createConnectionDetails(dbms = dbms, + connectionString = connectionString, + user = user, + password = pwd) + + runAnalysis(connectionDetails = connectionDetails, + cohortTable = cohortTable, + sessionId = "", + cdmSchema = cdmDatabaseSchema, + resultsSchema = cohortsDatabaseSchema, + vocabularySchema = cdmDatabaseSchema, + tempSchema = tempSchema, + analysisId = @analysisId, + outputFolder = file.path('.', 'results')) +}, finally = { + remove.packages('@packageName') +}) \ No newline at end of file From bb8a680c0d69ecc96911a04a646b831570c6ec5e Mon Sep 17 00:00:00 2001 From: Vitaly Koulakov Date: Mon, 1 Apr 2019 12:29:17 +0300 Subject: [PATCH 5/9] library version --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 0384602c9d..d0c807010c 100644 --- a/pom.xml +++ b/pom.xml @@ -704,7 +704,7 @@ org.ohdsi standardized-analysis-api - 1.1.1-SNAPSHOT + 1.2.0-SNAPSHOT org.ohdsi From 254d5dc20eb91f615a59219e852c3952ae9dcaa9 Mon Sep 17 00:00:00 2001 From: Vitaly Koulakov Date: Mon, 1 Apr 2019 14:35:33 +0300 Subject: [PATCH 6/9] jdbc driver path added --- .../resources/cohortcharacterizations/r/runAnalysis.R | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/resources/resources/cohortcharacterizations/r/runAnalysis.R b/src/main/resources/resources/cohortcharacterizations/r/runAnalysis.R index d74d5f68db..b4a3596a24 100644 --- a/src/main/resources/resources/cohortcharacterizations/r/runAnalysis.R +++ b/src/main/resources/resources/cohortcharacterizations/r/runAnalysis.R @@ -23,11 +23,13 @@ tryCatch({ cohortsDatabaseSchema <- Sys.getenv("TARGET_SCHEMA") tempSchema <- if (is.null(Sys.getenv("TEMP_SCHEMA"))) cohortsDatabaseSchema else Sys.getenv("TEMP_SCHEMA") cohortTable <- Sys.getenv("COHORT_TARGET_TABLE") + driverPath <- Sys.getenv("JDBC_DRIVER_PATH") connectionDetails <- DatabaseConnector::createConnectionDetails(dbms = dbms, connectionString = connectionString, user = user, - password = pwd) + password = pwd, + pathToDriver = driverPath) runAnalysis(connectionDetails = connectionDetails, cohortTable = cohortTable, From 919b9cfbf7988321120cb791c0bff81ab9776989 Mon Sep 17 00:00:00 2001 From: Vitaly Koulakov Date: Mon, 1 Apr 2019 14:40:27 +0300 Subject: [PATCH 7/9] runAnalysis removed --- .../cohortcharacterizations/r/runAnalysis.R | 45 ------------------- 1 file changed, 45 deletions(-) delete mode 100644 src/main/resources/resources/cohortcharacterizations/r/runAnalysis.R diff --git a/src/main/resources/resources/cohortcharacterizations/r/runAnalysis.R b/src/main/resources/resources/cohortcharacterizations/r/runAnalysis.R deleted file mode 100644 index b4a3596a24..0000000000 --- a/src/main/resources/resources/cohortcharacterizations/r/runAnalysis.R +++ /dev/null @@ -1,45 +0,0 @@ -library(devtools) -options(devtools.install.args = "--no-multiarch") - -setwd("./") -tryCatch({ - unzip('@packageFile', exdir = file.path(".", "@analysisDir")) - install_local(file.path(".", "@analysisDir")) -}, finally = { - unlink('@analysisDir', recursive = TRUE, force = TRUE) -}) - -library(DatabaseConnector) -library(@packageName) - -tryCatch({ - maxCores <- parallel::detectCores() - - dbms <- Sys.getenv("DBMS_TYPE") - connectionString <- Sys.getenv("CONNECTION_STRING") - user <- Sys.getenv("DBMS_USERNAME") - pwd <- Sys.getenv("DBMS_PASSWORD") - cdmDatabaseSchema <- Sys.getenv("DBMS_SCHEMA") - cohortsDatabaseSchema <- Sys.getenv("TARGET_SCHEMA") - tempSchema <- if (is.null(Sys.getenv("TEMP_SCHEMA"))) cohortsDatabaseSchema else Sys.getenv("TEMP_SCHEMA") - cohortTable <- Sys.getenv("COHORT_TARGET_TABLE") - driverPath <- Sys.getenv("JDBC_DRIVER_PATH") - - connectionDetails <- DatabaseConnector::createConnectionDetails(dbms = dbms, - connectionString = connectionString, - user = user, - password = pwd, - pathToDriver = driverPath) - - runAnalysis(connectionDetails = connectionDetails, - cohortTable = cohortTable, - sessionId = "", - cdmSchema = cdmDatabaseSchema, - resultsSchema = cohortsDatabaseSchema, - vocabularySchema = cdmDatabaseSchema, - tempSchema = tempSchema, - analysisId = @analysisId, - outputFolder = file.path('.', 'results')) -}, finally = { - remove.packages('@packageName') -}) \ No newline at end of file From 3b0981885cdfd0c227a8f32a0ff97acc6af11341 Mon Sep 17 00:00:00 2001 From: Vitaly Koulakov Date: Mon, 1 Apr 2019 19:19:08 +0300 Subject: [PATCH 8/9] Perfomance fixes for extracted CC analysis generation --- pom.xml | 2 +- .../ohdsi/webapi/cohortcharacterization/CcServiceImpl.java | 1 - .../GenerateCohortCharacterizationTasklet.java | 7 +------ 3 files changed, 2 insertions(+), 8 deletions(-) diff --git a/pom.xml b/pom.xml index d0c807010c..9b6667f94b 100644 --- a/pom.xml +++ b/pom.xml @@ -641,7 +641,7 @@ org.ohdsi featureExtraction - 2.1.5-SNAPSHOT + 2.2.0-SNAPSHOT com.amazon.redshift diff --git a/src/main/java/org/ohdsi/webapi/cohortcharacterization/CcServiceImpl.java b/src/main/java/org/ohdsi/webapi/cohortcharacterization/CcServiceImpl.java index ef6d7bb953..9112bfae7e 100644 --- a/src/main/java/org/ohdsi/webapi/cohortcharacterization/CcServiceImpl.java +++ b/src/main/java/org/ohdsi/webapi/cohortcharacterization/CcServiceImpl.java @@ -427,7 +427,6 @@ public JobExecutionResource generateCc(final Long id, @SourceKey final String so jdbcTemplate, getTransactionTemplate(), ccService, - analysisService, analysisGenerationInfoEntityRepository, sourceService, userRepository diff --git a/src/main/java/org/ohdsi/webapi/cohortcharacterization/GenerateCohortCharacterizationTasklet.java b/src/main/java/org/ohdsi/webapi/cohortcharacterization/GenerateCohortCharacterizationTasklet.java index 10c1b31514..dfdd46218f 100644 --- a/src/main/java/org/ohdsi/webapi/cohortcharacterization/GenerateCohortCharacterizationTasklet.java +++ b/src/main/java/org/ohdsi/webapi/cohortcharacterization/GenerateCohortCharacterizationTasklet.java @@ -40,14 +40,12 @@ import org.springframework.transaction.support.TransactionTemplate; import java.util.Map; -import java.util.stream.Collectors; import static org.ohdsi.webapi.Constants.Params.*; public class GenerateCohortCharacterizationTasklet extends AnalysisTasklet { private final CcService ccService; - private final FeAnalysisService feAnalysisService; private final SourceService sourceService; private final UserRepository userRepository; @@ -55,14 +53,12 @@ public GenerateCohortCharacterizationTasklet( final CancelableJdbcTemplate jdbcTemplate, final TransactionTemplate transactionTemplate, final CcService ccService, - final FeAnalysisService feAnalysisService, final AnalysisGenerationInfoEntityRepository analysisGenerationInfoEntityRepository, final SourceService sourceService, final UserRepository userRepository ) { super(LoggerFactory.getLogger(GenerateCohortCharacterizationTasklet.class), jdbcTemplate, transactionTemplate, analysisGenerationInfoEntityRepository); this.ccService = ccService; - this.feAnalysisService = feAnalysisService; this.sourceService = sourceService; this.userRepository = userRepository; } @@ -88,8 +84,7 @@ protected String[] prepareQueries(ChunkContext chunkContext, CancelableJdbcTempl final String tempSchema = SourceUtils.getTempQualifier(source); CCQueryBuilder ccQueryBuilder = new CCQueryBuilder(cohortCharacterization, cohortTable, sessionId, SourceUtils.getCdmQualifier(source), SourceUtils.getResultsQualifier(source), - SourceUtils.getVocabularyQualifier(source), tempSchema, - jobId, feAnalysisService.findAllPresetAnalyses().stream().map(FeAnalysisWithStringEntity::getDesign).collect(Collectors.toList())); + SourceUtils.getVocabularyQualifier(source), tempSchema, jobId); String sql = ccQueryBuilder.build(); /* From 7161b02496fb65ba214a58247cc74c5b6b5bbf3e Mon Sep 17 00:00:00 2001 From: Vitaly Koulakov Date: Tue, 2 Apr 2019 13:07:56 +0300 Subject: [PATCH 9/9] removes duplicated dependency --- pom.xml | 5 ----- 1 file changed, 5 deletions(-) diff --git a/pom.xml b/pom.xml index 52f93ba978..9b6667f94b 100644 --- a/pom.xml +++ b/pom.xml @@ -711,11 +711,6 @@ SkeletonCohortCharacterization 1.0.0-SNAPSHOT - - org.ohdsi - SkeletonCohortCharacterization - 1.0.0-SNAPSHOT - com.cosium.spring.data spring-data-jpa-entity-graph