From 9b2f24d36422d30cc9c74faf11819c3b0f12acc7 Mon Sep 17 00:00:00 2001 From: Jason Walonoski Date: Tue, 2 May 2023 14:45:29 -0400 Subject: [PATCH] CSV sort patient expenses and payer transitions by time. --- .../org/mitre/synthea/export/CSVExporter.java | 24 ++++++++++++------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/src/main/java/org/mitre/synthea/export/CSVExporter.java b/src/main/java/org/mitre/synthea/export/CSVExporter.java index e94f6ca15c..957100c68f 100644 --- a/src/main/java/org/mitre/synthea/export/CSVExporter.java +++ b/src/main/java/org/mitre/synthea/export/CSVExporter.java @@ -436,9 +436,13 @@ public void exportPayers() throws IOException { * * @throws IOException if any IO errors occur. */ - private void exportPayerTransitions(Person person, long stopTime) throws IOException { - for (PlanRecord planRecord : person.coverage.getPlanHistory()) { - if (planRecord.getStartTime() <= stopTime) { + private void exportPayerTransitions(Person person, long cutOffTime, long stopTime) + throws IOException { + List sortedPlanRecords = person.coverage.getPlanHistory().stream() + .sorted(Comparator.comparingLong(PlanRecord::getStartTime)) + .collect(Collectors.toList()); + for (PlanRecord planRecord : sortedPlanRecords) { + if ((planRecord.getStartTime() <= stopTime) && (planRecord.getStopTime() >= cutOffTime)) { payerTransition(person, planRecord); } } @@ -451,9 +455,13 @@ private void exportPayerTransitions(Person person, long stopTime) throws IOExcep * * @throws IOException if any IO errors occur. */ - private void exportPatientExpenses(Person person, long stopTime) throws IOException { - for (PlanRecord planRecord : person.coverage.getPlanHistory()) { - if (planRecord.getStartTime() <= stopTime) { + private void exportPatientExpenses(Person person, long cutOffTime, long stopTime) + throws IOException { + List sortedPlanRecords = person.coverage.getPlanHistory().stream() + .sorted(Comparator.comparingLong(PlanRecord::getStartTime)) + .collect(Collectors.toList()); + for (PlanRecord planRecord : sortedPlanRecords) { + if ((planRecord.getStartTime() <= stopTime) && (planRecord.getStopTime() >= cutOffTime)) { patientExpense(person, planRecord); } } @@ -529,14 +537,14 @@ public void export(Person person, long time) throws IOException { supply(personID, encounterID, encounter, supply); } } - CSVExporter.getInstance().exportPayerTransitions(person, time); - CSVExporter.getInstance().exportPatientExpenses(person, time); int yearsOfHistory = Integer.parseInt(Config.get("exporter.years_of_history")); Calendar cutOff = new GregorianCalendar(1900, 0, 1); if (yearsOfHistory > 0) { cutOff = Calendar.getInstance(); cutOff.set(cutOff.get(Calendar.YEAR) - yearsOfHistory, 0, 1); } + CSVExporter.getInstance().exportPayerTransitions(person, cutOff.getTimeInMillis(), time); + CSVExporter.getInstance().exportPatientExpenses(person, cutOff.getTimeInMillis(), time); Calendar now = Calendar.getInstance(); Calendar birthDay = Calendar.getInstance(); birthDay.setTimeInMillis((long) person.attributes.get(Person.BIRTHDATE));