-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #248 from MeasureAuthoringTool/feature/mat-7437-im…
…provement-notation-constraints
- Loading branch information
Showing
6 changed files
with
93 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
src/main/java/gov/cms/madie/models/validators/ImprovementNotationValidator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
20 changes: 0 additions & 20 deletions
20
src/main/java/gov/cms/madie/models/validators/OtherImprovementNotationValidator.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
src/test/java/gov/cms/madie/models/validators/ImprovementNotationValidatorTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} | ||
} |