Skip to content

Commit

Permalink
MAT-6724 add measure observation to human readable
Browse files Browse the repository at this point in the history
  • Loading branch information
CeciliaLiu8 committed Feb 20, 2024
1 parent b2968c8 commit cf6ce99
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 20 deletions.
2 changes: 1 addition & 1 deletion madie-checkstyle.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

<!-- https://checkstyle.sourceforge.io/config_sizes.html#FileLength -->
<module name="FileLength">
<property name="max" value="450" />
<property name="max" value="460" />
</module>
<module name="SuppressionFilter">
<property name="file" value="suppressions.xml"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ public class CqlToolsController {
private final HumanReadableService humanReadableService;
private final CqlParsingService cqlParsingService;

@PutMapping(value = "/cql/format", produces = {MediaType.TEXT_PLAIN_VALUE})
@PutMapping(
value = "/cql/format",
produces = {MediaType.TEXT_PLAIN_VALUE})
public ResponseEntity<String> formatCql(@RequestBody String cqlData, Principal principal) {
try (var cqlDataStream = new ByteArrayInputStream(cqlData.getBytes())) {
CqlFormatterVisitor.FormatResult formatResult =
Expand All @@ -43,9 +45,7 @@ public ResponseEntity<String> formatCql(@RequestBody String cqlData, Principal p
"Unable to format CQL, because one or more Syntax errors are identified");
}
log.info("User [{}] successfully formatted the CQL", principal.getName());
return ResponseEntity.ok()
.contentType(MediaType.TEXT_PLAIN)
.body(formatResult.getOutput());
return ResponseEntity.ok().contentType(MediaType.TEXT_PLAIN).body(formatResult.getOutput());
} catch (IOException e) {
log.info("User [{}] is unable to format the CQL", principal.getName());
throw new CqlFormatException(e.getMessage());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import java.text.Collator;
import java.text.DateFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
Expand Down Expand Up @@ -180,8 +181,10 @@ List<HumanReadablePopulationCriteriaModel> buildPopCriteria(
.name(group.getGroupDescription())
.populations(
Stream.concat(
buildPopulations(group, allDefinitions).stream(),
buildStratification(group, allDefinitions).stream())
Stream.concat(
buildPopulations(group, allDefinitions).stream(),
buildStratification(group, allDefinitions).stream()),
buildMeasureObservation(group, allDefinitions).stream())
.toList())
.build())
.collect(Collectors.toList());
Expand Down Expand Up @@ -216,18 +219,42 @@ String getCQLDefinitionLogic(String id, Set<CQLDefinition> allDefinitions) {

List<HumanReadablePopulationModel> buildStratification(
Group group, Set<CQLDefinition> allDefinitions) {
return group.getStratifications().stream()
.map(
stratification ->
HumanReadablePopulationModel.builder()
.name("Stratification")
.id(stratification.getId())
.display("Stratification")
.logic(getCQLDefinitionLogic(stratification.getCqlDefinition(), allDefinitions))
.expressionName(stratification.getCqlDefinition())
.inGroup(!StringUtils.isBlank(stratification.getCqlDefinition()))
.build())
.collect(Collectors.toList());
if (!CollectionUtils.isEmpty(group.getStratifications())) {
return group.getStratifications().stream()
.map(
stratification ->
HumanReadablePopulationModel.builder()
.name("Stratification")
.id(stratification.getId())
.display("Stratification")
.logic(
getCQLDefinitionLogic(stratification.getCqlDefinition(), allDefinitions))
.expressionName(stratification.getCqlDefinition())
.inGroup(!StringUtils.isBlank(stratification.getCqlDefinition()))
.build())
.collect(Collectors.toList());
}
return Collections.emptyList();
}

List<HumanReadablePopulationModel> buildMeasureObservation(
Group group, Set<CQLDefinition> allDefinitions) {
if (!CollectionUtils.isEmpty(group.getMeasureObservations())) {
return group.getMeasureObservations().stream()
.map(
measureObservation ->
HumanReadablePopulationModel.builder()
.name(measureObservation.getDefinition())
.id(measureObservation.getId())
.display(measureObservation.getDefinition())
.logic(
getCQLDefinitionLogic(measureObservation.getDefinition(), allDefinitions))
.expressionName(measureObservation.getDefinition())
.inGroup(!StringUtils.isBlank(measureObservation.getDefinition()))
.build())
.collect(Collectors.toList());
}
return Collections.emptyList();
}

List<HumanReadableExpressionModel> buildDefinitions(Set<CQLDefinition> allDefinitions) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import gov.cms.mat.cql_elm_translation.utils.cql.parsing.model.CQLDefinition;
import gov.cms.mat.cql_elm_translation.utils.cql.parsing.model.CQLValueSet;

import org.apache.commons.collections4.CollectionUtils;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
Expand All @@ -43,6 +44,7 @@
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.when;

Expand Down Expand Up @@ -147,6 +149,12 @@ void setUp() {
.id("testStrat2Id")
.cqlDefinition("")
.build()))
.measureObservations(
List.of(
MeasureObservation.builder()
.definition(PopulationType.INITIAL_POPULATION.name())
.build(),
MeasureObservation.builder().build()))
.build()))
.baseConfigurationTypes(List.of(BaseConfigurationTypes.OUTCOME))
.riskAdjustmentDescription("test risk adjustment")
Expand Down Expand Up @@ -372,7 +380,10 @@ public void canBuildPopulationCriteriaModelFromMeasure() {
assertThat(popCriteriaModel.getName(), is(equalTo(group.getGroupDescription())));
assertThat(
popCriteriaModel.getPopulations().size(),
is(group.getPopulations().size() + group.getStratifications().size()));
is(
group.getPopulations().size()
+ group.getStratifications().size()
+ group.getMeasureObservations().size()));

Population measurePopulation = group.getPopulations().get(0);
HumanReadablePopulationModel populationModel = popCriteriaModel.getPopulations().get(0);
Expand Down Expand Up @@ -623,4 +634,22 @@ public void testBuildValuesetTerminologyList() {
terminologyModels.get(1).getName(),
is(equalTo("Routes of Administration for Opioid Antagonists")));
}

@Test
public void testbuildStratificationWithNoStratifications() {
Group group = measure.getGroups().get(0);
group.setStratifications(null);
List<HumanReadablePopulationModel> model =
humanReadableService.buildStratification(group, allDefinitions);
assertTrue(CollectionUtils.isEmpty(model));
}

@Test
public void testBuildMeasureObservationWithoutMeasureObservations() {
Group group = measure.getGroups().get(0);
group.setMeasureObservations(null);
List<HumanReadablePopulationModel> model =
humanReadableService.buildMeasureObservation(group, allDefinitions);
assertTrue(CollectionUtils.isEmpty(model));
}
}

0 comments on commit cf6ce99

Please sign in to comment.