Skip to content

Commit

Permalink
Validation Issue Metric Logging and Incorporation into Metrics.
Browse files Browse the repository at this point in the history
  • Loading branch information
MontaltoNick committed Jan 30, 2024
1 parent dbf3a05 commit a8b31f4
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,14 @@ public MetricsReportResponse getMetricReport(

//calculate metrics based on period, we can assume that all categories have already been
//filtered down based on tenant and/or report if those parameters were provided
MetricsReportResponse report = this.calculatePeriodMetrics(period, endDate, metrics);
MetricsReportResponse report = this.calculatePeriodMetrics(period, endDate, metrics, tenantId);

return report;
}

//TODO: This functionality probably should be broken out into a service

private MetricsReportResponse calculatePeriodMetrics(String period, LocalDate end, List<Metrics> metrics) {
private MetricsReportResponse calculatePeriodMetrics(String period, LocalDate end, List<Metrics> metrics, String tenantId) {
MetricsReportResponse report = new MetricsReportResponse();

//get current period metrics
Expand Down Expand Up @@ -151,12 +151,18 @@ private MetricsReportResponse calculatePeriodMetrics(String period, LocalDate en
EvaluationMetric evaluationTimeMetric = new EvaluationMetric();
evaluationTimeMetric.setAverage(currentEvaluationTimeAvg);

//calculate current Validation Issues metrics
double currentValidationIssueAvg = calculateValidationIssueAvg(periodMetrics);
ValidationMetric validationIssueMetric = new ValidationMetric();
validationIssueMetric.setAverage(currentValidationIssueAvg);

//loop back through the historical data to produce previous 10 totals/averages
double[] queryTimeHistory = new double[10];
long[] patientsQueriedHistory = new long[10];
long[] patientsReportedHistory = new long[10];
double[] validationTimeHistory = new double[10];
double[] evaluationTimeHistory = new double[10];
double[] validationIssueHistory = new double[10];
for (int i = 1; i <= 10; i++) {
//get historical period
LocalDate historicalStart;
Expand Down Expand Up @@ -191,6 +197,7 @@ private MetricsReportResponse calculatePeriodMetrics(String period, LocalDate en
patientsReportedHistory[i-1] = calculatePatientsReported(historicalMetrics);
validationTimeHistory[i-1] = calculateValidationTimeAvg(historicalMetrics, reportIds);
evaluationTimeHistory[i-1] = calculateEvaluationTimeAvg(historicalMetrics, reportIds);
validationIssueHistory[i-1] = calculateValidationIssueAvg(historicalMetrics);
}

//add historical averages for query time
Expand All @@ -213,6 +220,10 @@ private MetricsReportResponse calculatePeriodMetrics(String period, LocalDate en
evaluationTimeMetric.setHistory(evaluationTimeHistory);
report.setEvaluation(evaluationTimeMetric);

//add historical averages for validation issues
validationIssueMetric.setHistory(validationIssueHistory);
report.setValidationIssues(validationIssueMetric);

return report;
}

Expand Down Expand Up @@ -319,6 +330,24 @@ private double calculateEvaluationTimeAvg(List<Metrics> periodMetrics, List<Stri

return currentEvaluationTimeAvg;
}
private double calculateValidationIssueAvg(List<Metrics> periodMetrics) {
//get total patients queried in the metric period
double totalValidationIssues = 0;

//if no period metrics exist, return 0
if(!(periodMetrics.size() > 0)) {
return totalValidationIssues;
}

List<MetricData> periodQueryMetrics = getPeriodMetricData(Constants.VALIDATION_ISSUE_CATEGORY, Constants.VALIDATION_ISSUE_TASK, periodMetrics);
for(MetricData data: periodQueryMetrics) {
totalValidationIssues += data.count;
}

double validationIssueAvg = (totalValidationIssues / Integer.max(1, periodQueryMetrics.size()));

return validationIssueAvg;
}

private List<String> getUniqueReportIds(List<Metrics> metrics) {

Expand Down
3 changes: 3 additions & 0 deletions core/src/main/java/com/lantanagroup/link/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,7 @@ public class Constants {
public static final String MONTHLY_PERIOD = "lastMonth";
public static final String QUARTERLY_PERIOD = "lastQuarter";
public static final String YEARLY_PERIOD = "lastYear";

public static final String VALIDATION_ISSUE_TASK = "Validation";
public static final String VALIDATION_ISSUE_CATEGORY = "Validation Issues";
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public class MetricsReportResponse {
private PatientsQueriedMetric patientsQueried;
private PatientsReportedMetric patientsReported;
private ValidationMetric validation;
private ValidationMetric validationIssues;
private EvaluationMetric evaluation;
}

Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@
import com.lantanagroup.link.EventService;
import com.lantanagroup.link.Helper;
import com.lantanagroup.link.ValidationCategorizer;
import com.lantanagroup.link.config.api.ApiConfig;
import com.lantanagroup.link.db.SharedService;
import com.lantanagroup.link.db.TenantService;
import com.lantanagroup.link.db.mappers.ValidationResultMapper;
import com.lantanagroup.link.db.model.MetricData;
import com.lantanagroup.link.db.model.Metrics;
import com.lantanagroup.link.db.model.Report;
import com.lantanagroup.link.db.model.tenant.ValidationResult;
import com.lantanagroup.link.db.model.tenant.ValidationResultCategory;
Expand All @@ -20,6 +21,8 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.UUID;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -76,6 +79,24 @@ public OperationOutcome validate(StopwatchManager stopwatchManager, TenantServic
}
}

//log validation issue metrics
List<Metrics> metrics = new ArrayList<>();
Metrics metric = new Metrics();
metrics.add(metric);
String task = Constants.VALIDATION_ISSUE_TASK;
String category = Constants.VALIDATION_ISSUE_CATEGORY;
metric.setTenantId(tenantService.getConfig().getId());
metric.setReportId(report.getId());
metric.setTaskName(task);
metric.setCategory(category);
metric.setTimestamp(new Date());

MetricData data = new MetricData();
data.count = outcome.getIssue().size();
metric.setData(data);

this.sharedService.saveMetrics(metrics);

return outcome;
}
}

0 comments on commit a8b31f4

Please sign in to comment.