Skip to content

Commit

Permalink
Fix inclusion impact analysis where censor period is being used (#66)
Browse files Browse the repository at this point in the history
* Added cohort_censor_stats table.
* censor stats only calculated when there is a censor window specified.
  • Loading branch information
wivern authored and chrisknoll committed Jan 22, 2019
1 parent b5ec99c commit 98911c6
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ public class CohortExpressionQueryBuilder implements IGetCriteriaSqlDispatcher,
private final static String CODESET_JOIN_TEMPLATE = "JOIN #Codesets codesets on (@codesetClauses)";

private final static String COHORT_INCLUSION_ANALYSIS_TEMPALTE = ResourceHelper.GetResourceAsString("/resources/cohortdefinition/sql/cohortInclusionAnalysis.sql");
private final static String COHORT_CENSORED_STATS_TEMPLATE = ResourceHelper.GetResourceAsString("/resources/cohortdefinition/sql/cohortCensoredStats.sql");

// Strategy templates
private final static String DATE_OFFSET_STRATEGY_TEMPLATE = ResourceHelper.GetResourceAsString("/resources/cohortdefinition/sql/dateOffsetStrategy.sql");
Expand Down Expand Up @@ -365,7 +366,7 @@ private String getInclusionAnalysisQuery(String eventTable, int modeId) {
resultSql = StringUtils.replace(resultSql, "@eventTable", eventTable);
return resultSql;
}

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

Expand Down Expand Up @@ -463,7 +464,12 @@ public String buildExpressionQuery(CohortExpression expression, BuildExpressionQ

resultSql = StringUtils.replace(resultSql, "@inclusionImpactAnalysisByEventQuery", getInclusionAnalysisQuery("#qualified_events", 0));
resultSql = StringUtils.replace(resultSql, "@inclusionImpactAnalysisByPersonQuery", getInclusionAnalysisQuery("#best_events", 1));


resultSql = StringUtils.replace(resultSql, "@cohortCensoredStatsQuery",
(expression.censorWindow != null && (!StringUtils.isEmpty(expression.censorWindow.startDate) || !StringUtils.isEmpty(expression.censorWindow.endDate)))
? COHORT_CENSORED_STATS_TEMPLATE
: "");

if (options != null)
{
// replease query parameters with tokens
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
-- calculate censored
delete from @results_database_schema.cohort_censor_stats where cohort_definition_id = @target_cohort_id;
insert into @results_database_schema.cohort_censor_stats (cohort_definition_id, lost_count)
select @target_cohort_id as cohort_definition_id, coalesce(FCC.total_people - TC.total, 0) as lost_count
FROM
(select count_big(distinct person_id) as total_people from #final_cohort) FCC,
(select count_big(distinct subject_id) as total from @target_database_schema.@target_cohort_table t where t.cohort_definition_id = @target_cohort_id) TC;
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,10 @@ WHERE ranked.rank_value = 1
@inclusionImpactAnalysisByPersonQuery
-- END: Inclusion Impact Analysis - person

-- BEGIN: Censored Stats
@cohortCensoredStatsQuery
-- END: Censored Stats

TRUNCATE TABLE #best_events;
DROP TABLE #best_events;

Expand Down

0 comments on commit 98911c6

Please sign in to comment.