Skip to content

Commit

Permalink
Merge pull request #240 from MeasureAuthoringTool/feature/mat-7570-li…
Browse files Browse the repository at this point in the history
…mit-date-shift-year-range

[MAT-7570] Limit date shift results to [0, 9999]
  • Loading branch information
jkotanchik-SB authored Aug 28, 2024
2 parents ac83956 + eda2c82 commit 245b1d5
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 4 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.58-SNAPSHOT</version>
<version>0.6.59-SNAPSHOT</version>
<name>madie-java-models</name>
<description>Java based models for MADiE microservices</description>
<properties>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,10 @@ public Interval shiftIntervalByYear(Interval interval, int year) {
return null;
}
if (interval.getLow() != null) {
interval.setLow(interval.getLow().plusYears(year));
interval.setLow(shiftDateByYear(interval.getLow(), year));
}
if (interval.getHigh() != null) {
interval.setHigh(interval.getHigh().plusYears(year));
interval.setHigh(shiftDateByYear(interval.getHigh(), year));
}
return interval;
}
Expand All @@ -129,6 +129,13 @@ public ZonedDateTime shiftDateByYear(ZonedDateTime dateTime, int year) {
if (dateTime == null) {
return null;
}
return dateTime.plusYears(year);
ZonedDateTime shiftedDateTime = dateTime.plusYears(year);
if (shiftedDateTime.getYear() > 9999) {
return shiftedDateTime.withYear(9999);
}
if (shiftedDateTime.getYear() < 0) {
return shiftedDateTime.withYear(0);
}
return shiftedDateTime;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package gov.cms.madie.models.cqm.datacriteria.basetypes;

import gov.cms.madie.models.cqm.datacriteria.EncounterPerformed;
import org.junit.jupiter.api.Test;

import java.time.Instant;
import java.time.ZoneId;
import java.time.ZonedDateTime;

import static org.assertj.core.api.Assertions.assertThat;

class DataElementTest {

@Test
void shiftDateByYearAfterYear9999() {
EncounterPerformed encounterPerformed = new EncounterPerformed();
ZonedDateTime dateTime = ZonedDateTime.ofInstant(Instant.now(), ZoneId.of("UTC"));
encounterPerformed.setAuthorDatetime(dateTime);
ZonedDateTime shiftedDateTime = encounterPerformed.shiftDateByYear(dateTime, 100000);
assertThat(shiftedDateTime).isEqualTo(dateTime.withYear(9999));
}

@Test
void shiftDateByYearBeforeYear0() {
EncounterPerformed encounterPerformed = new EncounterPerformed();
ZonedDateTime dateTime = ZonedDateTime.ofInstant(Instant.now(), ZoneId.of("UTC"));
encounterPerformed.setAuthorDatetime(dateTime);
ZonedDateTime shiftedDateTime = encounterPerformed.shiftDateByYear(dateTime, -100000);
assertThat(shiftedDateTime).isEqualTo(dateTime.withYear(0));
}
}

0 comments on commit 245b1d5

Please sign in to comment.