Skip to content
This repository has been archived by the owner on Dec 18, 2024. It is now read-only.

BugFix-6194 changed the mapping of CQL to return population definitions #501

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions src/components/editTestCase/groupCoverage/QdmGroupCoverage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import {
MappedCql,
Population,
SelectedPopulationResult,
getFirstPopulation,
getPopulationAbbreviation,
} from "../../../util/GroupCoverageHelpers";
Expand All @@ -21,7 +20,7 @@
measureGroups: Group[];
}

type PopulationResult = Record<string, SelectedPopulationResult>;
type PopulationResult = Record<string, string>;

const populationCriteriaLabel = "Population Criteria";

Expand All @@ -39,17 +38,17 @@
const [
selectedPopulationDefinitionResults,
setSelectedPopulationDefinitionResults,
] = useState<SelectedPopulationResult>();
] = useState<string>();

useEffect(() => {
if (!isEmpty(testCaseGroups)) {
changeCriteria(testCaseGroups[0].groupId);
}
}, [testCaseGroups]);

Check warning on line 47 in src/components/editTestCase/groupCoverage/QdmGroupCoverage.tsx

View workflow job for this annotation

GitHub Actions / Checkout, install, lint, build and test with coverage

React Hook useEffect has a missing dependency: 'changeCriteria'. Either include it or remove the dependency array

useEffect(() => {
changePopulation(selectedHighlightingTab);
}, [populationResults]);

Check warning on line 51 in src/components/editTestCase/groupCoverage/QdmGroupCoverage.tsx

View workflow job for this annotation

GitHub Actions / Checkout, install, lint, build and test with coverage

React Hook useEffect has missing dependencies: 'changePopulation' and 'selectedHighlightingTab'. Either include them or remove the dependency array

const getCriteriaLabel = (index) => {
return testCaseGroups.length > 1
Expand Down Expand Up @@ -79,14 +78,14 @@
);
const selectedPopulationDefinition = selectedGroup?.populations?.find(
(pop) => pop.id === population.id
)?.definition;
)?.name;
const result =
populationResults &&
Object.entries(populationResults).find(
([key]) => key === _.camelCase(selectedPopulationDefinition)
);
setSelectedPopulationDefinitionResults(
result?.[1].text ? result[1] : undefined
result?.[1] ? result[1] : undefined
);
}
};
Expand Down Expand Up @@ -212,7 +211,7 @@
>
{selectedPopulationDefinitionResults
? parse(
`<pre><code>${selectedPopulationDefinitionResults?.text}</code></pre>`
`<pre><code>${selectedPopulationDefinitionResults}</code></pre>`
)
: "No results available"}
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ describe("CalculationResults with new tabbed highlighting layout on", () => {
expect(screen.getByText("Population Criteria 2")).toBeInTheDocument();
});
expect(screen.getByTestId("IP-highlighting")).toHaveTextContent(
`define "Initial Population": ["Encounter, Performed": "Emergency Department Visit"] //Encounter union ["Encounter, Performed": "Closed Head and Facial Trauma"] //Encounter union ["Encounter, Performed": "Dementia"]`
`define "Denominator": "Initial Population"`
);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const CalculationResults = ({
{!isEmpty(testCaseGroups) && (
<QdmGroupCoverage
testCaseGroups={testCaseGroups}
cqlPopulationDefinitions={mapCql(measureCql, testCaseGroups)}
cqlPopulationDefinitions={mapCql(measureCql, measureGroups)}
measureGroups={measureGroups}
/>
)}
Expand Down
58 changes: 21 additions & 37 deletions src/util/GroupCoverageHelpers.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
import { CqlAntlr } from "@madie/cql-antlr-parser/dist/src";
import {
PopulationType,
PopulationExpectedValue,
GroupPopulation,
} from "@madie/madie-models";
import { PopulationType, PopulationExpectedValue } from "@madie/madie-models";
import _ from "lodash";

export interface Population {
Expand All @@ -12,16 +8,10 @@ export interface Population {
criteriaReference?: string;
name: PopulationType;
}

export interface SelectedPopulationResult {
criteriaReference: string;
text: string;
}

export interface MappedCql {
[groupId: string]: {
populationDefinitions: {
[populationName: string]: SelectedPopulationResult;
[populationName: string]: string;
};
};
}
Expand Down Expand Up @@ -56,32 +46,26 @@ export const getFirstPopulation = (group) => {
};
};

export const mapCql = (
measureCql: string,
groupPopulations: GroupPopulation[]
): MappedCql => {
if (measureCql && groupPopulations) {
export const mapCql = (measureCql: string, measureGroups): MappedCql => {
if (measureCql && measureGroups) {
const definitions = new CqlAntlr(measureCql).parse().expressionDefinitions;

return groupPopulations.reduce((output, { groupId, populationValues }) => {
output[groupId] = {
populationDefinitions: populationValues?.reduce(
(populationDefinition, { name, criteriaReference }) => {
const matchingDefinition: any = definitions?.find(
(def) => _.camelCase(def?.name?.slice(1, -1)) === name
);

populationDefinition[name] = {
criteriaReference: criteriaReference || null,
text: matchingDefinition?.text || null,
};

return populationDefinition;
},
{}
),
};
return output;
return measureGroups.reduce((acc, group) => {
const populationDetails = group.populations.reduce(
(output, population) => {
const matchingDefinition: any = definitions?.find(
(def) =>
_.camelCase(def?.name?.slice(1, -1)) ===
_.camelCase(population.definition)
);
if (matchingDefinition) {
output[population.name] = matchingDefinition.text;
}
return output;
},
{}
);
acc[group.id] = { populationDefinitions: populationDetails };
return acc;
}, {});
}
};
Loading