Skip to content

Commit

Permalink
new logic to handle population changes
Browse files Browse the repository at this point in the history
  • Loading branch information
CeciliaLiu8 committed Oct 26, 2023
1 parent 1bcf476 commit a527438
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 32 deletions.
45 changes: 15 additions & 30 deletions src/main/java/cms/gov/madie/measure/services/GroupService.java
Original file line number Diff line number Diff line change
Expand Up @@ -322,49 +322,34 @@ private void handlePopulationChange(

if (!CollectionUtils.isEmpty(testCasePopulationValuesFromGroup)) {
if (!CollectionUtils.isEmpty(testCasePopulationValues)) {
// when there is added group population
if (testCasePopulationValuesFromGroup.size() > testCasePopulationValues.size()) {
for (int i = 0; i < testCasePopulationValuesFromGroup.size(); i++) {
TestCasePopulationValue testCasePopulationValueFromGroup =
testCasePopulationValuesFromGroup.get(i);
if (!findExistsInTestCasePopulationValues(
testCasePopulationValueFromGroup.getId(), testCasePopulationValues)) {
testCasePopulationValues.add(testCasePopulationValueFromGroup);
}
for (TestCasePopulationValue testCasePopulationValueFromGroup :
testCasePopulationValuesFromGroup) {
// if there is new population value from testCasePopulationValuesFromGroup
if (!findExistsTestCasePopulationValue(
testCasePopulationValueFromGroup.getId(), testCasePopulationValues)) {
testCasePopulationValues.add(testCasePopulationValueFromGroup);
}
} // when there is deleted group population
else {
// delete any that is not in testCasePopulationValuesFromGroup
List<TestCasePopulationValue> tempTestCasePopulationValues = new ArrayList<>();
for (int i = 0; i < testCasePopulationValues.size(); i++) {
if (findExistsInTestCasePopulationValues(
testCasePopulationValues.get(i).getId(), testCasePopulationValuesFromGroup)) {
tempTestCasePopulationValues.add(testCasePopulationValues.get(i));
for (TestCasePopulationValue tempTestCasePopulationValue : testCasePopulationValues) {
if (findExistsTestCasePopulationValue(
tempTestCasePopulationValue.getId(), testCasePopulationValuesFromGroup)) {
tempTestCasePopulationValues.add(tempTestCasePopulationValue);
}
}
testCaseStrata.setPopulationValues(tempTestCasePopulationValues);
}

} // when there is new strat
else {
List<TestCasePopulationValue> tempTestCasePopulationValues = new ArrayList<>();
for (int i = 0; i < testCasePopulationValuesFromGroup.size(); i++) {
tempTestCasePopulationValues.add(testCasePopulationValuesFromGroup.get(i));
}
testCaseStrata.setPopulationValues(tempTestCasePopulationValues);
testCaseStrata.setPopulationValues(testCasePopulationValuesFromGroup);
}
}
}

private boolean findExistsInTestCasePopulationValues(
private boolean findExistsTestCasePopulationValue(
String id, List<TestCasePopulationValue> testCasePopulationValues) {
boolean found = false;
for (int i = 0; i < testCasePopulationValues.size(); i++) {
TestCasePopulationValue testCasePopulationValue = testCasePopulationValues.get(i);
if (id.equalsIgnoreCase(testCasePopulationValue.getId())) {
found = true;
}
}
return found;
return testCasePopulationValues.stream()
.anyMatch(testCasePopulationValue -> id.equalsIgnoreCase(testCasePopulationValue.getId()));
}

private TestCasePopulationValue findTestCasePopulation(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1426,7 +1426,7 @@ public void testUpdateTestCaseStratificationForDeletedGroupPopulation() {
}

@Test
public void testUpdateTestCaseStratificationForSameGroupPopulation() {
public void testUpdateTestCaseStratificationForChangedGroupPopulation() {

List<TestCasePopulationValue> testCasePopulationValues = new ArrayList<>();

Expand All @@ -1435,8 +1435,8 @@ public void testUpdateTestCaseStratificationForSameGroupPopulation() {

List<TestCaseStratificationValue> testCaseStratificationValues = new ArrayList<>();
List<TestCasePopulationValue> testCaseStrataPopulationValues = new ArrayList<>();
testCaseStrataPopulationValues.add(testCasePopulationValue1);
testCaseStrataPopulationValues.add(testCasePopulationValue2);
testCaseStrataPopulationValues.add(testCasePopulationValue3);

TestCaseStratificationValue testCaseStratificationValue1 =
TestCaseStratificationValue.builder()
Expand All @@ -1462,6 +1462,12 @@ public void testUpdateTestCaseStratificationForSameGroupPopulation() {
stratification, testCaseGroupPopulation, "Strata-1");
assertTrue(testCaseStratificationValue != null);
assertEquals(testCaseStratificationValue.getPopulationValues().size(), 2);
assertNotEquals(
testCaseStratificationValue.getPopulationValues().get(0).getId(),
testCasePopulationValue3.getId());
assertNotEquals(
testCaseStratificationValue.getPopulationValues().get(1).getId(),
testCasePopulationValue3.getId());
}

@Test
Expand Down

0 comments on commit a527438

Please sign in to comment.