Skip to content

Commit

Permalink
Fix incorrect hourly schedules for the second day day after schedule …
Browse files Browse the repository at this point in the history
…creation

Due to the way schedules were created, the second day was missing the
hourly intakes before the "starting hour", which should only be counted
for the first day.
  • Loading branch information
AlvaroBrey committed Oct 17, 2018
1 parent bd9ebf3 commit 68de899
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -193,10 +193,7 @@ public void createSchedule(final Schedule s, List<ScheduleItem> items, Medicine
DailyAgenda.instance().addItem(patient, item, false);
}
} else {
for (DateTime time : s.hourlyItemsToday()) {
LocalTime timeToday = time.toLocalTime();
DailyAgenda.instance().addItem(patient, s, timeToday);
}
DailyAgenda.instance().generateItemsForHourlySchedule(patient, s);
}
// save and fire event
DB.schedules().saveAndFireEvent(s);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@
import com.j256.ormlite.misc.TransactionManager;

import org.greenrobot.eventbus.Subscribe;
import org.joda.time.DateTime;
import org.joda.time.LocalTime;

import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -125,10 +123,7 @@ public Object call() throws Exception {
DailyAgenda.instance().addItem(patient, item, false);
}
} else {
for (DateTime time : s.hourlyItemsToday()) {
LocalTime timeToday = time.toLocalTime();
DailyAgenda.instance().addItem(patient, s, timeToday);
}
DailyAgenda.instance().generateItemsForHourlySchedule(patient, s);
}
// save and fire event
DB.schedules().saveAndFireEvent(s);
Expand Down Expand Up @@ -193,10 +188,7 @@ public Object call() throws Exception {
}
} else {
DB.dailyScheduleItems().removeAllFrom(s);
for (DateTime time : s.hourlyItemsToday()) {
LocalTime timeToday = time.toLocalTime();
DailyAgenda.instance().addItem(patient, s, timeToday);
}
DailyAgenda.instance().generateItemsForHourlySchedule(patient, s);
}

// save and fire event
Expand All @@ -216,6 +208,7 @@ public Object call() throws Exception {
}
}


public void saveSchedule() {

if (!validateBeforeSave()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.joda.time.DateTime;
import org.joda.time.Interval;
import org.joda.time.LocalDate;
import org.joda.time.LocalDateTime;
import org.joda.time.LocalTime;

import java.sql.SQLException;
Expand Down Expand Up @@ -161,6 +162,9 @@ public void createDailySchedule(DateTime d) {
}
}

/**
* Generates item for a ROUTINE SCHEDULE
*/
public void addItem(Patient p, ScheduleItem item, boolean taken) {
// add to daily schedule
DailyScheduleItem dsi;
Expand All @@ -183,21 +187,35 @@ public void addItem(Patient p, ScheduleItem item, boolean taken) {
}
}

public void addItem(Patient p, Schedule s, LocalTime time) {

/**
* Generates item for a HOURLY REP SCHEDULE
*/
private void addItem(Patient p, Schedule s, LocalDateTime time) {
// add to daily schedule
DailyScheduleItem dsi;
if (s.enabledForDate(LocalDate.now())) {
dsi = new DailyScheduleItem(s, time);
if (s.enabledForDate(time.toLocalDate())) {
dsi = new DailyScheduleItem(s, time.toLocalTime());
dsi.setDate(time.toLocalDate());
dsi.setPatient(p);
dsi.save();
}
for (int i = 1; i <= NEXT_DAYS_TO_SHOW; i++) {
LocalDate date = LocalDate.now().plusDays(i);
if (s.enabledForDate(date)) {
dsi = new DailyScheduleItem(s, time);
dsi.setPatient(p);
dsi.setDate(date);
dsi.save();
}


/**
* Generates DailyScheduleItems for today and tomorrow for the given HOURLY schedule
*
* @param patient the patient
* @param s the HOURLY schedule
*/
public void generateItemsForHourlySchedule(Patient patient, Schedule s) {
for (DateTime time : s.hourlyItemsToday()) {
DailyAgenda.instance().addItem(patient, s, time.toLocalDateTime());
}
for (int i = 1; i <= DailyAgenda.NEXT_DAYS_TO_SHOW; i++) {
for (DateTime time : s.hourlyItemsAt(DateTime.now().plusDays(i))) {
DailyAgenda.instance().addItem(patient, s, time.toLocalDateTime());
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@

package es.usc.citius.servando.calendula.util.alerts;

import org.joda.time.DateTime;
import org.joda.time.LocalTime;

import java.util.List;
import java.util.concurrent.Callable;

Expand Down Expand Up @@ -94,10 +91,7 @@ public static void unblockSchedule(final Schedule schedule) {
DailyAgenda.instance().addItem(schedule.patient(), item, false);
}
} else {
for (DateTime time : schedule.hourlyItemsToday()) {
LocalTime timeToday = time.toLocalTime();
DailyAgenda.instance().addItem(schedule.patient(), schedule, timeToday);
}
DailyAgenda.instance().generateItemsForHourlySchedule(schedule.patient(), schedule);
}
CalendulaApp.eventBus().post(PersistenceEvents.SCHEDULE_EVENT);
}
Expand Down

0 comments on commit 68de899

Please sign in to comment.