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

Commit

Permalink
Merge branch 'develop' into MAT-6431
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmcphillips authored Nov 25, 2023
2 parents 9a300f3 + 0bbff47 commit 5425fdb
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 45 deletions.
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 _, { isEmpty } from "lodash";
import {
MappedCql,
Population,
SelectedPopulationResult,
getFirstPopulation,
getPopulationAbbreviation,
} from "../../../util/GroupCoverageHelpers";
Expand All @@ -21,7 +20,7 @@ interface Props {
measureGroups: Group[];
}

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

const populationCriteriaLabel = "Population Criteria";

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

useEffect(() => {
if (!isEmpty(testCaseGroups)) {
Expand Down Expand Up @@ -79,14 +78,14 @@ const QdmGroupCoverage = ({
);
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 @@ const QdmGroupCoverage = ({
>
{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;
}, {});
}
};

0 comments on commit 5425fdb

Please sign in to comment.