Skip to content

Commit

Permalink
Pulled coverage details into debug output. Fixed uncoverage highlight…
Browse files Browse the repository at this point in the history
…ing to have it's own strategy for highlighting
  • Loading branch information
hossenlopp committed Mar 14, 2024
1 parent 1974fc0 commit bec3555
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 14 deletions.
8 changes: 7 additions & 1 deletion src/calculation/Calculator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import { clearElmInfoCache } from '../helpers/elm/ELMInfoCache';
import _, { omit } from 'lodash';
import { ELM } from '../types/ELMTypes';
import { getReportBuilder } from '../helpers/ReportBuilderFactory';
import { option } from 'commander';

Check warning on line 44 in src/calculation/Calculator.ts

View workflow job for this annotation

GitHub Actions / build (14.x)

'option' is defined but never used

Check warning on line 44 in src/calculation/Calculator.ts

View workflow job for this annotation

GitHub Actions / build (16.x)

'option' is defined but never used

/**
* Calculate measure against a set of patients. Returning detailed results for each patient and population group.
Expand Down Expand Up @@ -271,7 +272,7 @@ export async function calculate<T extends CalculationOptions>(
}
});

// pull out
// pull out uncoverage html
if (options.calculateClauseUncoverage && coverage.uncoverage) {
groupClauseUncoverageHTML = coverage.uncoverage;
if (debugObject && options.enableDebugOutput) {
Expand All @@ -296,6 +297,11 @@ export async function calculate<T extends CalculationOptions>(
html: overallClauseCoverageHTML
});
}

// grab coverage details
if (debugObject && options.enableDebugOutput && options.calculateCoverageDetails) {
debugObject.coverageDetails = coverage.details;
}
}
}

Expand Down
26 changes: 13 additions & 13 deletions src/calculation/HTMLBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,18 @@ Handlebars.registerHelper('highlightCoverage', (localId, context) => {
return '';
});

// apply highlighting style to uncovered clauses
Handlebars.registerHelper('highlightUncoverage', (localId, context) => {

Check warning on line 96 in src/calculation/HTMLBuilder.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🕹️ Function is not covered

Warning! Not covered function
const libraryName: string = context.data.root.libraryName;

Check warning on line 97 in src/calculation/HTMLBuilder.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement
const clauseResults: ClauseResult[] = context.data.root.clauseResults;

Check warning on line 98 in src/calculation/HTMLBuilder.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement

const clauseResult = clauseResults.filter(result => result.libraryName === libraryName && result.localId === localId);

Check warning on line 100 in src/calculation/HTMLBuilder.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement

Check warning on line 100 in src/calculation/HTMLBuilder.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement

Check warning on line 100 in src/calculation/HTMLBuilder.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🌿 Branch is not covered

Warning! Not covered branch

Check warning on line 100 in src/calculation/HTMLBuilder.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🌿 Branch is not covered

Warning! Not covered branch

Check warning on line 100 in src/calculation/HTMLBuilder.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🕹️ Function is not covered

Warning! Not covered function
if (clauseResult.length > 0) {
return objToCSS(cqlLogicClauseFalseStyle);

Check warning on line 102 in src/calculation/HTMLBuilder.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement
}

Check warning on line 103 in src/calculation/HTMLBuilder.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement

Check warning on line 103 in src/calculation/HTMLBuilder.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🌿 Branch is not covered

Warning! Not covered branch
return '';

Check warning on line 104 in src/calculation/HTMLBuilder.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement
});

/**
* Sort statements into population, then non-functions, then functions
*/
Expand Down Expand Up @@ -287,13 +299,6 @@ export function generateClauseCoverageHTML<T extends CalculationOptions>(
let uncoverageHtmlString = '';
if (options.calculateClauseUncoverage) {
uncoverageHtmlString = `<div><h2> ${groupId} Clause Uncoverage: ${clauseCoverage.uncoveredClauses.length} clauses</h2>`;
if (clauseCoverage.uncoveredClauses.length > 0 && clauseCoverage.uncoveredClauses.length <= 20) {
uncoverageHtmlString += `<pre><code>\n${JSON.stringify(
clauseCoverage.uncoveredClauses,
undefined,
2
)}</code></pre>`;
}
}

// generate HTML clauses using hbs template for each annotation
Expand All @@ -313,7 +318,7 @@ export function generateClauseCoverageHTML<T extends CalculationOptions>(
statementName: a.statementName,
clauseResults: clauseCoverage.uncoveredClauses,
...a.annotation[0].s,
highlightCoverage: false
highlightUncoverage: true
});

Check warning on line 322 in src/calculation/HTMLBuilder.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement
}

Check warning on line 323 in src/calculation/HTMLBuilder.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🌿 Branch is not covered

Warning! Not covered branch
});
Expand Down Expand Up @@ -359,7 +364,6 @@ export function calculateClauseCoverage(
relevantStatements: StatementResult[],
clauseResults: ClauseResult[]
): { percentage: string; coveredClauses: ClauseResult[]; uncoveredClauses: ClauseResult[] } {
const covTimer = new Date();
// find all relevant clauses using statementName and libraryName from relevant statements
const allRelevantClauses = clauseResults.filter(c =>
relevantStatements.some(
Expand All @@ -376,17 +380,13 @@ export function calculateClauseCoverage(
(c1, c2) => c1.libraryName === c2.libraryName && c1.localId === c2.localId
);

const unCovTimer = new Date();
const uncoveredClauses = allUniqueClauses.filter(c => {
if (coveredClauses.find(coveredC => c.libraryName === coveredC.libraryName && c.localId === coveredC.localId)) {
return false;
} else {
return true;
}
});
console.debug(`Uncoverage took ${new Date().getTime() - unCovTimer.getTime()} ms`);
console.debug(`Coverage took ${new Date().getTime() - covTimer.getTime()} ms`);
console.debug(`Found ${uncoveredClauses.length} uncovered clauses.`, uncoveredClauses);

return {
percentage: ((coveredClauses.length / allUniqueClauses.length) * 100).toPrecision(3),
Expand Down
5 changes: 5 additions & 0 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ async function calc(
result = await calculateRaw(measureBundle, patientBundles, calcOptions, valueSetCache);
} else if (program.outputType === 'detailed') {
calcOptions.calculateClauseUncoverage = true;
calcOptions.calculateCoverageDetails = true;
result = await calculate(measureBundle, patientBundles, calcOptions, valueSetCache);
} else if (program.outputType === 'reports') {
calcOptions.reportType = program.reportType || 'individual';
Expand Down Expand Up @@ -243,6 +244,10 @@ populatePatientBundles().then(async patientBundles => {
dumpObject(debugOutput.gaps, 'gaps.json');
}

if (debugOutput?.coverageDetails) {
dumpObject(debugOutput.coverageDetails, 'coverageDetails.json');
}

// Dump ELM
if (debugOutput?.elm) {
dumpELMJSONs(debugOutput.elm);
Expand Down
13 changes: 13 additions & 0 deletions src/templates/clause.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,18 @@ export default `{{~#if @root.highlightCoverage~}}
{{~/if~}}
</span>
{{~else~}}
{{~#if @root.highlightUncoverage~}}
<span{{#if r}} data-ref-id="{{r}}" style="{{highlightUncoverage r}}"{{/if}}>
{{~#if value ~}}
{{ concat value }}
{{~/if ~}}
{{~#if s~}}
{{~#each s~}}
{{> clause ~}}
{{~/each ~}}
{{~/if~}}
</span>
{{~else~}}
<span{{#if r}} data-ref-id="{{r}}" style="{{highlightClause r}}"{{/if}}>
{{~#if value ~}}
{{ concat value }}
Expand All @@ -20,4 +32,5 @@ export default `{{~#if @root.highlightCoverage~}}
{{~/each ~}}
{{~/if~}}
</span>
{{~/if~}}
{{~/if~}}`;
1 change: 1 addition & 0 deletions src/types/Calculator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,7 @@ export interface DebugOutput {
retrieves?: DataTypeQuery[];
bundle?: fhir4.Bundle | fhir4.Bundle[];
};
coverageDetails?: Record<string, ClauseCoverageDetails>;
}

/*
Expand Down

0 comments on commit bec3555

Please sign in to comment.