Skip to content

Commit

Permalink
Merge pull request #724 from lantanagroup/fix-date-handling
Browse files Browse the repository at this point in the history
Tweaks to remove the assumption of millisecond precision in reporting period start/end
  • Loading branch information
smailliwcs committed Mar 15, 2024
2 parents a1a0776 + 349ae6a commit ace3451
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,6 @@ private MeasureReport generateMeasureReport() {
MeasureReport measureReport;
String patientDataBundleId = ReportIdHelper.getPatientDataBundleId(reportContext.getMasterIdentifierValue(), patientId);
String measureId = this.measureContext.getMeasure().getIdElement().getIdPart();
String start = this.criteria.getPeriodStart().substring(0, this.criteria.getPeriodStart().indexOf("."));
String end = this.criteria.getPeriodEnd().substring(0, this.criteria.getPeriodEnd().indexOf("."));

Bundle patientBundle;
try (Stopwatch stopwatch = this.stopwatchManager.start(Constants.TASK_RETRIEVE_PATIENT_DATA, Constants.CATEGORY_REPORT)) {
Expand All @@ -60,7 +58,7 @@ private MeasureReport generateMeasureReport() {
Helper.dumpToFile(patientBundle, config.getDebugPath(), fileName);
}

logger.info("Executing $evaluate-measure for measure: {}, start: {}, end: {}, patient: {}, resources: {}", measureId, start, end, patientId, patientBundle.getEntry().size());
logger.info("Executing $evaluate-measure for measure: {}, start: {}, end: {}, patient: {}, resources: {}", measureId, criteria.getPeriodStart(), criteria.getPeriodEnd(), patientId, patientBundle.getEntry().size());

//noinspection unused
try (Stopwatch stopwatch = this.stopwatchManager.start(Constants.TASK_MEASURE, Constants.CATEGORY_EVALUATE)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,25 +37,17 @@ public List<GlobalReportResponse> getReports(
if (!startDate.isEmpty()) {
Date date = Helper.parseFhirDate(startDate);

reports = reports.stream().filter(x -> {
try {
return Helper.parseFhirDate(x.getPeriodStart()).after(date) || Helper.parseFhirDate(x.getPeriodStart()).equals(date);
} catch (ParseException e) {
throw new RuntimeException(e);
}
}).collect(Collectors.toList());
reports = reports.stream().filter(x ->
Helper.parseFhirDate(x.getPeriodStart()).after(date) || Helper.parseFhirDate(x.getPeriodStart()).equals(date)
).collect(Collectors.toList());
}

if (!endDate.isEmpty()) {
Date date = Helper.parseFhirDate(endDate);

reports = reports.stream().filter(x -> {
try {
return Helper.parseFhirDate(x.getPeriodEnd()).before(date) || Helper.parseFhirDate(x.getPeriodStart()).equals(date);
} catch (ParseException e) {
throw new RuntimeException(e);
}
}).collect(Collectors.toList());
reports = reports.stream().filter(x ->
Helper.parseFhirDate(x.getPeriodEnd()).before(date) || Helper.parseFhirDate(x.getPeriodStart()).equals(date)
).collect(Collectors.toList());
}

if (!tenantId.isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,8 @@ public LogSearchResponse getLogs(@RequestParam(required = false) String startDat
Date startDateObj;
Date endDateObj;

try {
startDateObj = Helper.parseFhirDate(startDate);
endDateObj = Helper.parseFhirDate(endDate);
} catch (ParseException ex) {
throw new IllegalArgumentException("Invalid date format, must be in the format yyyy-MM-dd'T'HH:mm:ss.SSSXXX or yyyy-MM-dd'T'HH:mm:ssXXX");
}
startDateObj = Helper.parseFhirDate(startDate);
endDateObj = Helper.parseFhirDate(endDate);

List<LogMessage> logMessages = this.sharedService.findLogMessages(startDateObj, endDateObj, severity, page, content);
LogSearchResponse res = new LogSearchResponse();
Expand Down
17 changes: 3 additions & 14 deletions core/src/main/java/com/lantanagroup/link/Helper.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import org.apache.commons.text.StringEscapeUtils;
import org.hl7.fhir.r4.model.Bundle;
import org.hl7.fhir.r4.model.CapabilityStatement;
import org.hl7.fhir.r4.model.DateTimeType;
import org.hl7.fhir.r4.model.Resource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -66,20 +67,8 @@ public static String getFhirDate(Date date) {
return new SimpleDateFormat(SIMPLE_DATE_MILLIS_FORMAT).format(date);
}

public static Date parseFhirDate(String dateStr) throws ParseException {
if (StringUtils.isEmpty(dateStr)) {
return null;
}

SimpleDateFormat formatterMillis = new SimpleDateFormat(SIMPLE_DATE_MILLIS_FORMAT);
SimpleDateFormat formatterSec = new SimpleDateFormat(SIMPLE_DATE_SECONDS_FORMAT);
Date dateReturned;
try {
dateReturned = formatterMillis.parse(dateStr);
} catch (Exception ex) {
dateReturned = formatterSec.parse(dateStr);
}
return dateReturned;
public static Date parseFhirDate(String dateStr) {
return new DateTimeType(dateStr).getValue();
}

public static <T> List<T> concatenate(List<T> list1, List<T> list2) {
Expand Down

0 comments on commit ace3451

Please sign in to comment.