Skip to content

Commit

Permalink
MAT-6911 ass stratification to the HQMF
Browse files Browse the repository at this point in the history
  • Loading branch information
adongare committed Mar 12, 2024
1 parent 9889169 commit 4618183
Show file tree
Hide file tree
Showing 4 changed files with 110 additions and 4 deletions.
16 changes: 13 additions & 3 deletions src/main/java/gov/cms/madie/services/MeasureMapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,10 @@ public interface MeasureMapper {
target = "measureObservationsDescription",
expression =
"java(gov.cms.madie.util.MappingUtil.getPopulationDescription(measure, PopulationType.MEASURE_OBSERVATION))")
@Mapping(
target = "stratification",
expression =
"java(gov.cms.madie.util.MappingUtil.getStratificationDescription(measure.getGroups()))")
@Mapping(target = "supplementalData", source = "supplementalDataDescription")
@Mapping(target = "finalizedDate", source = "measure")
@Mapping(target = "qualityMeasureSet", source = "measure")
Expand Down Expand Up @@ -277,12 +281,18 @@ CqlfunctionType observationToCqlFunction(
target = "isInGrouping",
expression =
"java(String.valueOf(org.apache.commons.lang3.StringUtils.isNotBlank(stratification.getCqlDefinition())))")
@Mapping(target = "uuid", expression = "java(java.util.UUID.randomUUID().toString())")
@Mapping(target = "uuid", source = "stratification.id")
@Mapping(target = "type", constant = "stratum")
@Mapping(target = "displayName", constant = "stratum")
@Mapping(target = "displayName", constant = "Stratum")
@Mapping(
target = "cqldefinition",
expression = "java(getStratificationDefinition(stratification, cqlDefinition))")
ClauseType stratificationToClauseType(Stratification stratification, CQLDefinition cqlDefinition);

// TODO: map stratification to definition/aggregate function
@Mapping(target = "displayName", source = "stratification.cqlDefinition")
@Mapping(target = "uuid", source = "cqlDefinition.uuid")
CqldefinitionType getStratificationDefinition(
Stratification stratification, CQLDefinition cqlDefinition);

@Named("scoringUnitToUcum")
default String scoringUnitToUcum(Object scoringUnit) {
Expand Down
35 changes: 35 additions & 0 deletions src/main/java/gov/cms/madie/util/MappingUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@

import com.nimbusds.oauth2.sdk.util.CollectionUtils;
import gov.cms.madie.models.measure.BaseConfigurationTypes;
import gov.cms.madie.models.measure.Group;
import gov.cms.madie.models.measure.Measure;
import gov.cms.madie.models.measure.MeasureScoring;
import gov.cms.madie.models.measure.PopulationType;
import org.apache.commons.lang3.StringUtils;

import java.util.List;
import java.util.stream.Collectors;

public final class MappingUtil {
Expand Down Expand Up @@ -104,4 +106,37 @@ && isPopulationObservation(populationType)) {
.collect(Collectors.joining(" "));
return StringUtils.isBlank(description) ? null : description;
}

/**
* Fetch descriptions of all the stratification from all the groups Combine all descriptions with
* a space (not a newline)
*
* @param groups - measure groups
* @return
*/
public static String getStratificationDescription(List<Group> groups) {
if (CollectionUtils.isEmpty(groups)) {
return null;
}
final String description =
groups.stream()
.map(
group -> {
if (CollectionUtils.isNotEmpty(group.getStratifications())) {
// there is only one stratum description field, so grab all available
// measure stratification descriptions
return group.getStratifications().stream()
.filter(
stratum ->
StringUtils.isNotBlank(stratum.getCqlDefinition())
&& StringUtils.isNotBlank(stratum.getDescription()))
.map(stratum -> stratum.getDescription().replaceAll("[\\t\\n\\r]+", " "))
.collect(Collectors.joining(" "));
}
return null;
})
.filter(StringUtils::isNotBlank)
.collect(Collectors.joining(" "));
return StringUtils.isBlank(description) ? null : description;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ void testMeasureToMeasureGroupingTypeReturnsNullForSingleGroupInput() {
assertThat(
firstGroup.getClause().get(2).getDisplayName(), is(equalTo("Denominator Exclusion")));
assertThat(firstGroup.getClause().get(6).getIsInGrouping(), is(equalTo("true")));
assertThat(firstGroup.getClause().get(6).getDisplayName(), is(equalTo("stratum")));
assertThat(firstGroup.getClause().get(6).getDisplayName(), is(equalTo("Stratum")));
assertThat(firstGroup.getClause().get(6).getType(), is(equalTo("stratum")));
}

Expand Down
61 changes: 61 additions & 0 deletions src/test/java/gov/cms/madie/util/MappingUtilTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import gov.cms.madie.models.measure.MeasureScoring;
import gov.cms.madie.models.measure.Population;
import gov.cms.madie.models.measure.PopulationType;
import gov.cms.madie.models.measure.Stratification;
import org.junit.jupiter.api.Test;

import java.util.List;
Expand Down Expand Up @@ -358,4 +359,64 @@ void getPopulationDescriptionGroupMultipleDescriptions() {
equalTo(
"Denominator Obs Description Numerator Obs Description G2 Denominator Obs Description G2 Numerator Obs Description"));
}

@Test
void getStratificationDescriptionNullGroups() {
Measure measure = Measure.builder().groups(null).build();
String output = MappingUtil.getStratificationDescription(measure.getGroups());
assertThat(output, is(nullValue()));
}

@Test
void getStratificationDescriptionGroupEmpty() {
Measure measure =
Measure.builder().groups(List.of(Group.builder().build(), Group.builder().build())).build();
String output = MappingUtil.getStratificationDescription(measure.getGroups());
assertThat(output, is(nullValue()));
}

@Test
void getStratificationDescriptionIfStratificationNull() {
Group group = Group.builder().stratifications(null).build();
Measure measure = Measure.builder().groups(List.of(group)).build();
String output = MappingUtil.getStratificationDescription(measure.getGroups());
assertThat(output, is(nullValue()));
}

@Test
void getStratificationDescriptionIfStratificationDefinitionIsNull() {
Group group =
Group.builder().stratifications(List.of(Stratification.builder().build())).build();
Measure measure = Measure.builder().groups(List.of(group)).build();
String output = MappingUtil.getStratificationDescription(measure.getGroups());
assertThat(output, is(nullValue()));
}

@Test
void getGroupStratificationDescriptionIfDescriptionIsNull() {
Group group =
Group.builder()
.stratifications(List.of(Stratification.builder().cqlDefinition("IPP").build()))
.build();
Measure measure = Measure.builder().groups(List.of(group)).build();
String output = MappingUtil.getStratificationDescription(measure.getGroups());
assertThat(output, is(nullValue()));
}

@Test
void getStratificationDescriptionForValidStratifications() {
Group group =
Group.builder()
.stratifications(
List.of(
Stratification.builder().cqlDefinition("IPP").description("Stratum 1").build(),
Stratification.builder()
.cqlDefinition("Denominator")
.description("Stratum 2")
.build()))
.build();
Measure measure = Measure.builder().groups(List.of(group)).build();
String output = MappingUtil.getStratificationDescription(measure.getGroups());
assertThat(output, is(equalTo("Stratum 1 Stratum 2")));
}
}

0 comments on commit 4618183

Please sign in to comment.