Skip to content

Commit

Permalink
MAT-6058: Adding mongock script to update QDM measure stratification …
Browse files Browse the repository at this point in the history
…assoctions
  • Loading branch information
gregory-akins committed Sep 27, 2023
1 parent b9bba5f commit 990b625
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package cms.gov.madie.measure.config;

import java.util.List;

import org.apache.commons.collections4.CollectionUtils;

import cms.gov.madie.measure.repositories.MeasureRepository;
import gov.cms.madie.models.measure.Group;
import gov.cms.madie.models.measure.Measure;
import gov.cms.madie.models.measure.Stratification;
import io.mongock.api.annotations.ChangeUnit;
import io.mongock.api.annotations.Execution;
import io.mongock.api.annotations.RollbackExecution;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;

@ChangeUnit(id = "update_stratification-assocation", order = "1", author = "madie_dev")
@Slf4j
public class UpdateStratificationAssociation {

Check warning on line 19 in src/main/java/cms/gov/madie/measure/config/UpdateStratificationAssociation.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/cms/gov/madie/measure/config/UpdateStratificationAssociation.java#L18-L19

Added lines #L18 - L19 were not covered by tests

@Setter private List<Measure> tempMeasures;

@Execution
public void removeAssociationFromStratification(MeasureRepository measureRepository) {
List<Measure> measures = measureRepository.findAllByModel("QDM v5.6");

Check warning on line 25 in src/main/java/cms/gov/madie/measure/config/UpdateStratificationAssociation.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/cms/gov/madie/measure/config/UpdateStratificationAssociation.java#L25

Added line #L25 was not covered by tests
if (CollectionUtils.isNotEmpty(measures)) {
setTempMeasures(measures);
measures.forEach(

Check warning on line 28 in src/main/java/cms/gov/madie/measure/config/UpdateStratificationAssociation.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/cms/gov/madie/measure/config/UpdateStratificationAssociation.java#L27-L28

Added lines #L27 - L28 were not covered by tests
measure -> {
if ("QDM v5.6".equals(measure.getModel())) {
List<Group> groups = measure.getGroups();

Check warning on line 31 in src/main/java/cms/gov/madie/measure/config/UpdateStratificationAssociation.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/cms/gov/madie/measure/config/UpdateStratificationAssociation.java#L31

Added line #L31 was not covered by tests
if (CollectionUtils.isNotEmpty(groups)) {
groups.forEach(

Check warning on line 33 in src/main/java/cms/gov/madie/measure/config/UpdateStratificationAssociation.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/cms/gov/madie/measure/config/UpdateStratificationAssociation.java#L33

Added line #L33 was not covered by tests
group -> {
List<Stratification> strats = group.getStratifications();

Check warning on line 35 in src/main/java/cms/gov/madie/measure/config/UpdateStratificationAssociation.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/cms/gov/madie/measure/config/UpdateStratificationAssociation.java#L35

Added line #L35 was not covered by tests
if (CollectionUtils.isNotEmpty((strats))) {
strats.forEach(

Check warning on line 37 in src/main/java/cms/gov/madie/measure/config/UpdateStratificationAssociation.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/cms/gov/madie/measure/config/UpdateStratificationAssociation.java#L37

Added line #L37 was not covered by tests
strat -> {
log.info("Stratification...", strat);
strat.setAssociation(null);
});

Check warning on line 41 in src/main/java/cms/gov/madie/measure/config/UpdateStratificationAssociation.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/cms/gov/madie/measure/config/UpdateStratificationAssociation.java#L39-L41

Added lines #L39 - L41 were not covered by tests
}
group.setStratifications(strats);
});
measure.setGroups(groups);
measureRepository.save(measure);

Check warning on line 46 in src/main/java/cms/gov/madie/measure/config/UpdateStratificationAssociation.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/cms/gov/madie/measure/config/UpdateStratificationAssociation.java#L43-L46

Added lines #L43 - L46 were not covered by tests
}
}
});

Check warning on line 49 in src/main/java/cms/gov/madie/measure/config/UpdateStratificationAssociation.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/cms/gov/madie/measure/config/UpdateStratificationAssociation.java#L49

Added line #L49 was not covered by tests
}
}

Check warning on line 51 in src/main/java/cms/gov/madie/measure/config/UpdateStratificationAssociation.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/cms/gov/madie/measure/config/UpdateStratificationAssociation.java#L51

Added line #L51 was not covered by tests

@RollbackExecution
public void rollbackExecution(MeasureRepository measureRepository) {
if (CollectionUtils.isNotEmpty(tempMeasures)) {
tempMeasures.forEach(

Check warning on line 56 in src/main/java/cms/gov/madie/measure/config/UpdateStratificationAssociation.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/cms/gov/madie/measure/config/UpdateStratificationAssociation.java#L56

Added line #L56 was not covered by tests
measure -> {
measureRepository.save(measure);
});

Check warning on line 59 in src/main/java/cms/gov/madie/measure/config/UpdateStratificationAssociation.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/cms/gov/madie/measure/config/UpdateStratificationAssociation.java#L58-L59

Added lines #L58 - L59 were not covered by tests
}
}

Check warning on line 61 in src/main/java/cms/gov/madie/measure/config/UpdateStratificationAssociation.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/cms/gov/madie/measure/config/UpdateStratificationAssociation.java#L61

Added line #L61 was not covered by tests
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,12 @@ public interface MeasureRepository

boolean existsByMeasureSetIdAndActiveAndMeasureMetaDataDraft(
String setId, boolean active, boolean draft);

// Map measureSetId, boolean (ie.,
// id 1 - drafted , 2 - versioned setId 4 4, false
// id 1 - versioned , 2 - versioned setId 4 4, true
List<Measure> findAllByMeasureSetIdInAndActiveAndMeasureMetaDataDraft(
List<String> setIds, boolean active, boolean draft);

List<Measure> findAllByModel(String model);
}

0 comments on commit 990b625

Please sign in to comment.