Skip to content

Commit

Permalink
Merge pull request #248 from MeasureAuthoringTool/feature/mat-7437-im…
Browse files Browse the repository at this point in the history
…provement-notation-constraints
  • Loading branch information
jkotanchik-SB authored Oct 22, 2024
2 parents b322fd3 + 35a44d0 commit 06a0080
Show file tree
Hide file tree
Showing 6 changed files with 93 additions and 26 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>gov.cms.madie</groupId>
<artifactId>madie-java-models</artifactId>
<version>0.6.66-SNAPSHOT</version>
<version>0.6.67-SNAPSHOT</version>
<name>madie-java-models</name>
<description>Java based models for MADiE microservices</description>
<properties>
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/gov/cms/madie/models/measure/QdmMeasure.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import com.fasterxml.jackson.annotation.JsonTypeName;
import gov.cms.madie.models.validators.ValidMeasureScoring;
import gov.cms.madie.models.validators.ValidOtherImprovementNotation;
import gov.cms.madie.models.validators.ValidImprovementNotation;
import gov.cms.madie.models.validators.ValidQDMGroupScoring;
import lombok.Builder;
import lombok.Data;
Expand All @@ -19,7 +19,7 @@
@ToString(callSuper = true)
@ValidMeasureScoring
@ValidQDMGroupScoring
@ValidOtherImprovementNotation
@ValidImprovementNotation
public class QdmMeasure extends Measure {

private String scoring;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package gov.cms.madie.models.validators;

import gov.cms.madie.models.measure.*;
import jakarta.validation.ConstraintValidator;
import jakarta.validation.ConstraintValidatorContext;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;

@Slf4j
public class ImprovementNotationValidator
implements ConstraintValidator<ValidImprovementNotation, QdmMeasure> {

@Override
public boolean isValid(QdmMeasure measure, ConstraintValidatorContext context) {
if (StringUtils.equalsIgnoreCase(
measure.getImprovementNotation(), "Increased score indicates improvement")
|| StringUtils.equalsIgnoreCase(
measure.getImprovementNotation(), "Decreased score indicates improvement")) {
return true;
} else if (StringUtils.equalsIgnoreCase(measure.getImprovementNotation(), "Other")) {
return StringUtils.isNotBlank(measure.getImprovementNotationDescription());
}
return false;
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@

@Target({ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Constraint(validatedBy = OtherImprovementNotationValidator.class)
@Constraint(validatedBy = ImprovementNotationValidator.class)
@Documented
public @interface ValidOtherImprovementNotation {
public @interface ValidImprovementNotation {

String message() default "Improvement Notation Description is required when Other is selected";
String message() default "Improvement Notation Description is invalid";

Class<?>[] groups() default {};

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package gov.cms.madie.models.validators;

import gov.cms.madie.models.measure.QdmMeasure;
import jakarta.validation.ConstraintValidatorContext;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.Mock;

import static org.junit.jupiter.api.Assertions.*;

class ImprovementNotationValidatorTest {
private final ImprovementNotationValidator validator = new ImprovementNotationValidator();

@Mock private ConstraintValidatorContext validatorContext;

private QdmMeasure measure;

@BeforeEach
public void setUp() {
measure =
QdmMeasure.builder()
.id("testId")
.measureSetId("testMeasureSetId")
.cqlLibraryName("TestCqlLibraryName")
.ecqmTitle("testECqm")
.measureName("testMeasureName")
.versionId("0.0.000")
.build();
}

@Test
void testImprovementNotationIncrease() {
measure.setImprovementNotation("Increased score indicates improvement");
assertTrue(validator.isValid(measure, validatorContext));
}

@Test
void testImprovementNotationDecrease() {
measure.setImprovementNotation("Decreased score indicates improvement");
assertTrue(validator.isValid(measure, validatorContext));
}

@Test
void testImprovementNotationOtherHasDescription() {
measure.setImprovementNotation("Other");
measure.setImprovementNotationDescription("desc");
assertTrue(validator.isValid(measure, validatorContext));
}

@Test
void testImprovementNotationOtherMissingDescription() {
measure.setImprovementNotation("Other");
measure.setImprovementNotationDescription("");
assertFalse(validator.isValid(measure, validatorContext));
}

@Test
void testInvalidImprovementNotation() {
measure.setImprovementNotation("Invalid");
assertFalse(validator.isValid(measure, validatorContext));
}
}

0 comments on commit 06a0080

Please sign in to comment.