Skip to content
Snippets Groups Projects

Appointments dev

Merged Piotr Gawron requested to merge appointments-dev into master
46 files
+ 1443
254
Compare changes
  • Side-by-side
  • Inline
Files
46
package smash.appointment.parse;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
@@ -36,7 +39,7 @@ public class AppointmentDao {
this.appointments = appointments;
}
public List<Visit> getVisits() {
public List<Visit> getVisits() throws ParseException {
List<Visit> result = new ArrayList<>();
Map<Subject, List<AppointmentEntry>> subjectAppointments = new HashMap<>();
for (AppointmentEntry entry : appointments) {
@@ -51,7 +54,7 @@ public class AppointmentDao {
return result;
}
private List<Visit> getVisitsForSubject(Subject subject, List<AppointmentEntry> list) {
private List<Visit> getVisitsForSubject(Subject subject, List<AppointmentEntry> list) throws ParseException {
Comparator<AppointmentEntry> comparator = new Comparator<AppointmentEntry>() {
@Override
@@ -87,7 +90,7 @@ public class AppointmentDao {
String date = currentVisit.getLastAppointmentDate();
if (date.equals(appointmentEntry.getDay().substring(0, 10))) {
currentVisit.getLastAppointment().addTypes(appointmentEntry.getTypes());
String source = appointmentEntry.getSource() + "\n"+currentVisit.getLastAppointment().getSource();
String source = appointmentEntry.getSource() + "\n" + currentVisit.getLastAppointment().getSource();
currentVisit.getLastAppointment().setSource(source);
} else {
currentVisit.addAppointment(appointmentEntry);
@@ -97,9 +100,34 @@ public class AppointmentDao {
if (currentVisit.getAppointments().size() > 0) {
result.add(currentVisit);
}
if (shouldBeFinished(currentVisit.getEndDate())) {
result.add(createNextVisit(currentVisit));
}
return result;
}
protected Visit createNextVisit(Visit currentVisit) throws ParseException {
Visit visit = new Visit(currentVisit.getSubject());
Calendar date = Calendar.getInstance();
String dateStr =currentVisit.getStartDate();
date.setTime(DATE_FORMATTER.parse(dateStr));
if (currentVisit.getSubject().getType().equals(SubjectType.CONTROL)) {
date.add(Calendar.YEAR, 4);
} else {
date.add(Calendar.YEAR, 1);
}
visit.setStartDate(DATE_FORMATTER.format(date.getTime()));
return visit;
}
private static final SimpleDateFormat DATE_FORMATTER = new SimpleDateFormat("yyyy-MM-dd");
protected boolean shouldBeFinished(String endDate) {
Calendar today_minus_two_months = Calendar.getInstance();
today_minus_two_months.add(Calendar.MONTH, -2);
return DATE_FORMATTER.format(today_minus_two_months.getTime()).compareTo(endDate) > 0;
}
public void addAppointment(AppointmentEntry appointment) {
appointments.add(appointment);
Loading