|
31 | 31 | import java.io.File; |
32 | 32 | import java.io.FileWriter; |
33 | 33 | import java.io.IOException; |
| 34 | +import java.time.LocalDate; |
34 | 35 | import java.util.ArrayList; |
35 | 36 | import java.util.Collections; |
36 | 37 | import java.util.Date; |
37 | 38 | import java.util.List; |
38 | 39 | import java.util.Locale; |
39 | 40 | import java.util.Map; |
40 | 41 | import java.util.TimeZone; |
41 | | -import java.util.concurrent.TimeUnit; |
42 | 42 | import java.util.stream.Collectors; |
43 | 43 |
|
44 | 44 | @Operation(name = "RollTestDates") |
@@ -190,7 +190,7 @@ public boolean getAllDateElements(FhirContext fhirContext, IBaseResource resourc |
190 | 190 | thePathToElement.remove(thePathToElement.size() - 1); |
191 | 191 | thePathToElement.add(s); |
192 | 192 | } |
193 | | - int daysToAdd = getDaysBetweenDates(getLastUpdatedDate(resource), new Date()); |
| 193 | + int daysToAdd = getDaysBetweenDates(getLastUpdatedDate(resource), LocalDate.now()); |
194 | 194 | if (theElement instanceof org.hl7.fhir.dstu3.model.BaseDateTimeType) { |
195 | 195 | TimeZone timeZone = ((org.hl7.fhir.dstu3.model.BaseDateTimeType) theElement).getTimeZone(); |
196 | 196 | ((org.hl7.fhir.dstu3.model.BaseDateTimeType) theElement).setValue(DateUtils.addDays( |
@@ -249,22 +249,19 @@ public boolean getAllDateElements(FhirContext fhirContext, IBaseResource resourc |
249 | 249 | return false; |
250 | 250 | } |
251 | 251 |
|
252 | | - private int getDaysBetweenDates(Date start, Date end) { |
253 | | - long startInMs = start.getTime(); |
254 | | - long endInMs = end.getTime(); |
255 | | - long timeDiff = Math.abs(endInMs - startInMs); |
256 | | - return (int) TimeUnit.DAYS.convert(timeDiff, TimeUnit.MILLISECONDS); |
| 252 | + private int getDaysBetweenDates(LocalDate start, LocalDate end) { |
| 253 | + return end.getDayOfYear() - start.getDayOfYear(); |
257 | 254 | } |
258 | 255 |
|
259 | | - private Date getLastUpdatedDate(IBaseResource resource) { |
| 256 | + private LocalDate getLastUpdatedDate(IBaseResource resource) { |
260 | 257 | IBaseDatatype dateLastUpdated = ExtensionUtil.getExtensionByUrl( |
261 | 258 | ExtensionUtil.getExtensionByUrl(resource, DATEROLLER_EXT_URL), "dateLastUpdated").getValue(); |
262 | 259 | if (dateLastUpdated instanceof org.hl7.fhir.dstu3.model.BaseDateTimeType) { |
263 | | - return ((org.hl7.fhir.dstu3.model.BaseDateTimeType) dateLastUpdated).getValue(); |
| 260 | + return LocalDate.parse(((org.hl7.fhir.dstu3.model.BaseDateTimeType) dateLastUpdated).getValueAsString().split("T")[0]); |
264 | 261 | } else if (dateLastUpdated instanceof org.hl7.fhir.r4.model.BaseDateTimeType) { |
265 | | - return ((org.hl7.fhir.r4.model.BaseDateTimeType) dateLastUpdated).getValue(); |
| 262 | + return LocalDate.parse(((org.hl7.fhir.r4.model.BaseDateTimeType) dateLastUpdated).getValueAsString().split("T")[0]); |
266 | 263 | } else if (dateLastUpdated instanceof org.hl7.fhir.r5.model.BaseDateTimeType) { |
267 | | - return ((org.hl7.fhir.r5.model.BaseDateTimeType) dateLastUpdated).getValue(); |
| 264 | + return LocalDate.parse(((org.hl7.fhir.r5.model.BaseDateTimeType) dateLastUpdated).getValueAsString().split("T")[0]); |
268 | 265 | } else { |
269 | 266 | throw new IllegalArgumentException("Unsupported type/version found for dateLastUpdated extension: " |
270 | 267 | + dateLastUpdated.fhirType()); |
@@ -304,8 +301,7 @@ private int getFrequencyInDays(IBaseResource resource) { |
304 | 301 | } |
305 | 302 |
|
306 | 303 | private boolean doUpdate(IBaseResource resource) { |
307 | | - Date today = new Date(); |
308 | | - return DateUtils.addDays(getLastUpdatedDate(resource), getFrequencyInDays(resource)).before(today); |
| 304 | + return getLastUpdatedDate(resource).isBefore(LocalDate.now()); |
309 | 305 | } |
310 | 306 |
|
311 | 307 | private void updateDateRollerExtension(FhirContext fhirContext, IBaseResource resource) { |
|
0 commit comments