Skip to content

Commit

Permalink
Added support for creating cohort SQL from raw json.
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisknoll committed Apr 30, 2021
1 parent e162c8a commit f63f996
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,10 @@ private String getInclusionAnalysisQuery(String eventTable, int modeId) {
return resultSql;
}

public String buildExpressionQuery(String expression, BuildExpressionQueryOptions options) {
return this.buildExpressionQuery(CohortExpression.fromJson(expression), options);
}

public String buildExpressionQuery(CohortExpression expression, BuildExpressionQueryOptions options) {
String resultSql = COHORT_QUERY_TEMPLATE;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,29 @@ public void loadTestData() throws SQLException, DataSetException {
}


/* Cohort Expression Tests */

@Test
public void rawJsonTest() throws SQLException {

final CohortExpressionQueryBuilder.BuildExpressionQueryOptions options = buildExpressionQueryOptions(1,"allCriteriaTest");

// prepare results schema
prepareSchema(options.resultSchema, RESULTS_DDL_PATH);

// load 'all' criteria json
final String expression = ResourceHelper.GetResourceAsString("/cohortgeneration/allCriteria/allCriteriaExpression.json");

// build Sql
final CohortExpressionQueryBuilder builder = new CohortExpressionQueryBuilder();
String cohortSql = builder.buildExpressionQuery(expression, options);
cohortSql = SqlRender.renderSql(SqlTranslate.translateSql(cohortSql, "postgresql"), null, null);

// execute on database, expect no errors
jdbcTemplate.batchUpdate(SqlSplit.splitSql(cohortSql));
}

/* Cohort Expression Tests */

@Test
public void allCriteriaTest() throws SQLException {

Expand Down

0 comments on commit f63f996

Please sign in to comment.