Skip to content

Commit

Permalink
ground work for outputting coverage details
Browse files Browse the repository at this point in the history
  • Loading branch information
hossenlopp committed Mar 13, 2024
1 parent 4edcf01 commit 1974fc0
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 10 deletions.
40 changes: 30 additions & 10 deletions src/calculation/HTMLBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Annotation, ELM } from '../types/ELMTypes';
import Handlebars from 'handlebars';
import {
CalculationOptions,
ClauseCoverageDetails,
ClauseResult,
DetailedPopulationGroupResult,
ExecutionResult,
Expand Down Expand Up @@ -217,10 +218,15 @@ export function generateClauseCoverageHTML<T extends CalculationOptions>(
elmLibraries: ELM[],
executionResults: ExecutionResult<DetailedPopulationGroupResult>[],
options: T
): { coverage: Record<string, string>; uncoverage?: Record<string, string> } {
): {
coverage: Record<string, string>;
uncoverage?: Record<string, string>;
details?: Record<string, ClauseCoverageDetails>;
} {
const groupResultLookup: Record<string, DetailedPopulationGroupResult[]> = {};
const coverageHtmlGroupLookup: Record<string, string> = {};
const uncoverageHtmlGroupLookup: Record<string, string> = {};
const coverageDetailsGroupLookup: Record<string, ClauseCoverageDetails> = {};

// get the detailed result for each group within each patient and add it
// to the key in groupResults that matches the groupId
Expand Down Expand Up @@ -290,7 +296,6 @@ export function generateClauseCoverageHTML<T extends CalculationOptions>(
}
}

const covTimer = new Date();
// generate HTML clauses using hbs template for each annotation
statementAnnotations.forEach(a => {
coverageHtmlString += main({
Expand All @@ -315,17 +320,32 @@ export function generateClauseCoverageHTML<T extends CalculationOptions>(
coverageHtmlString += '</div>';
uncoverageHtmlString += '</div>';

console.debug(`Coverage and Uncoverage HTML took ${new Date().getTime() - covTimer.getTime()} ms`);

coverageHtmlGroupLookup[groupId] = coverageHtmlString;
uncoverageHtmlGroupLookup[groupId] = uncoverageHtmlString;
if (options.calculateClauseUncoverage) {
uncoverageHtmlGroupLookup[groupId] = uncoverageHtmlString;
}

// If details on coverage are requested, tally them up and add them to the map.
if (options.calculateCoverageDetails) {
coverageDetailsGroupLookup[groupId] = {
totalClauses: clauseCoverage.coveredClauses.length + clauseCoverage.uncoveredClauses.length,
coveredClauses: clauseCoverage.coveredClauses.length,
uncoveredClauses: clauseCoverage.uncoveredClauses.map(uncoveredClause => {
return {
localId: uncoveredClause.localId,
libraryName: uncoveredClause.libraryName,
statementName: uncoveredClause.statementName
};
})
};
}
});

if (options.calculateClauseUncoverage) {
return { coverage: coverageHtmlGroupLookup, uncoverage: uncoverageHtmlGroupLookup };
} else {
return { coverage: coverageHtmlGroupLookup };
}
return {
coverage: coverageHtmlGroupLookup,
...(options.calculateClauseUncoverage && { uncoverage: uncoverageHtmlGroupLookup }),
...(options.calculateCoverageDetails && { details: coverageDetailsGroupLookup })
};
}

/**
Expand Down
13 changes: 13 additions & 0 deletions src/types/Calculator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ export interface CalculationOptions {
calculateClauseCoverage?: boolean;
/** Include HTML structure with clause uncoverage highlighting. Highlights what is not covered */
calculateClauseUncoverage?: boolean;
/** Include details about the clause coverage. Total clause count, total covered count, info on uncovered clauses. */
calculateCoverageDetails?: boolean;
/** Enable debug output including CQL, ELM, results */
enableDebugOutput?: boolean;
/** Enables the return of ELM Libraries and name of main library to be used for further processing. ex. gaps in care */
Expand Down Expand Up @@ -398,6 +400,17 @@ export interface CalculationOutput<T extends CalculationOptions> extends Calcula
coverageHTML?: string;
groupClauseCoverageHTML?: Record<string, string>;
groupClauseUncoverageHTML?: Record<string, string>;
groupClauseCoverageDetails?: Record<string, ClauseCoverageDetails>;
}

export interface ClauseCoverageDetails {
totalClauses: number;
coveredClauses: number;
uncoveredClauses: {
libraryName: string;
statementName: string;
localId: string;
}[];
}

/**
Expand Down

0 comments on commit 1974fc0

Please sign in to comment.