Skip to content

Commit

Permalink
Merge pull request synthetichealth#1288 from synthetichealth/csv_orde…
Browse files Browse the repository at this point in the history
…ring

CSV sort patient expenses and payer transitions by time.
  • Loading branch information
jawalonoski authored May 25, 2023
2 parents 5c87fbc + 9b2f24d commit 9ad8bbb
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions src/main/java/org/mitre/synthea/export/CSVExporter.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<PlanRecord> 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);
}
}
Expand All @@ -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<PlanRecord> 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);
}
}
Expand Down Expand Up @@ -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));
Expand Down

0 comments on commit 9ad8bbb

Please sign in to comment.