diff --git a/src/main/java/cms/gov/madie/measure/config/UpdateStratificationAssociation.java b/src/main/java/cms/gov/madie/measure/config/UpdateStratificationAssociation.java new file mode 100644 index 000000000..26643134d --- /dev/null +++ b/src/main/java/cms/gov/madie/measure/config/UpdateStratificationAssociation.java @@ -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 { + + @Setter private List tempMeasures; + + @Execution + public void removeAssociationFromStratification(MeasureRepository measureRepository) { + List measures = measureRepository.findAllByModel("QDM v5.6"); + if (CollectionUtils.isNotEmpty(measures)) { + setTempMeasures(measures); + measures.forEach( + measure -> { + if ("QDM v5.6".equals(measure.getModel())) { + List groups = measure.getGroups(); + if (CollectionUtils.isNotEmpty(groups)) { + groups.forEach( + group -> { + List strats = group.getStratifications(); + if (CollectionUtils.isNotEmpty((strats))) { + strats.forEach( + strat -> { + log.info("Stratification...", strat); + strat.setAssociation(null); + }); + } + group.setStratifications(strats); + }); + measure.setGroups(groups); + measureRepository.save(measure); + } + } + }); + } + } + + @RollbackExecution + public void rollbackExecution(MeasureRepository measureRepository) { + if (CollectionUtils.isNotEmpty(tempMeasures)) { + tempMeasures.forEach( + measure -> { + measureRepository.save(measure); + }); + } + } +} diff --git a/src/main/java/cms/gov/madie/measure/repositories/MeasureRepository.java b/src/main/java/cms/gov/madie/measure/repositories/MeasureRepository.java index f712815ae..040e387a2 100644 --- a/src/main/java/cms/gov/madie/measure/repositories/MeasureRepository.java +++ b/src/main/java/cms/gov/madie/measure/repositories/MeasureRepository.java @@ -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 findAllByMeasureSetIdInAndActiveAndMeasureMetaDataDraft( List setIds, boolean active, boolean draft); + + List findAllByModel(String model); }