diff --git a/api/src/main/java/org/openmrs/module/appointmentscheduling/Appointment.java b/api/src/main/java/org/openmrs/module/appointmentscheduling/Appointment.java index ca60b7cf..c1f5b245 100644 --- a/api/src/main/java/org/openmrs/module/appointmentscheduling/Appointment.java +++ b/api/src/main/java/org/openmrs/module/appointmentscheduling/Appointment.java @@ -13,14 +13,19 @@ */ package org.openmrs.module.appointmentscheduling; +import java.io.Serializable; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import org.apache.commons.collections.CollectionUtils; +import org.apache.commons.collections.Predicate; import org.openmrs.BaseOpenmrsData; import org.openmrs.BaseOpenmrsMetadata; import org.openmrs.BaseOpenmrsObject; import org.openmrs.Patient; import org.openmrs.Visit; -import java.io.Serializable; - /** * It is a model class. It should extend either {@link BaseOpenmrsObject} or * {@link BaseOpenmrsMetadata}. @@ -29,18 +34,43 @@ public class Appointment extends BaseOpenmrsData implements Serializable { private static final long serialVersionUID = 1L; + // TODO confirm that "WALK-IN" should be considered active public enum AppointmentStatus { - SCHEDULED("Scheduled"), RESCHEDULED("Rescheduled"), WALKIN("Walk-In"), CANCELLED("Cancelled"), WAITING("Waiting"), INCONSULTATION( - "In-Consultation"), COMPLETED("Completed"), MISSED("Missed"); + SCHEDULED("Scheduled", true, false), RESCHEDULED("Rescheduled", true, false), WALKIN("Walk-In", true, true), CANCELLED( + "Cancelled", false, false), WAITING("Waiting", true, true), INCONSULTATION("In-Consultation", true, true), COMPLETED( + "Completed", true, false), MISSED("Missed", false, false), CANCELLED_AND_NEEDS_RESCHEDULE( + "Cancelled and Needs Reschedule", false, false); private final String name; + /** + * Whether or not an appointment with this status should be considered "cancelled" Right now + * we consider CANCELLED, CANCELLED_AND_NEEDS_RESCHEDULE, and MISSED appts as cancelled + */ + private Boolean cancelled; + + /** + * Whether or not this appointment represents an "active" appointment, where active=patient + * checked-in and present within the health facility + */ + private Boolean active; + + private AppointmentStatus(final String name, final Boolean cancelled, final Boolean active) { + this.name = name; + this.cancelled = cancelled; + this.active = active; + } + public String getName() { return this.name; } - private AppointmentStatus(final String name) { - this.name = name; + public Boolean isCancelled() { + return this.cancelled; + } + + public Boolean isActive() { + return this.active; } @Override @@ -48,6 +78,20 @@ public String toString() { return name; } + public static List filter(Predicate predicate) { + List appointmentStatuses = new ArrayList(Arrays.asList(AppointmentStatus.values())); // need to assign to a new array because Arrays.asList is fixed length + CollectionUtils.filter(appointmentStatuses, predicate); + return appointmentStatuses; + } + + public static Predicate cancelledPredicate = new Predicate() { + + @Override + public boolean evaluate(Object o) { + return ((AppointmentStatus) o).isCancelled(); + } + }; + } private Integer appointmentId; diff --git a/api/src/main/java/org/openmrs/module/appointmentscheduling/api/AppointmentService.java b/api/src/main/java/org/openmrs/module/appointmentscheduling/api/AppointmentService.java index f8783bf2..b1aac11d 100644 --- a/api/src/main/java/org/openmrs/module/appointmentscheduling/api/AppointmentService.java +++ b/api/src/main/java/org/openmrs/module/appointmentscheduling/api/AppointmentService.java @@ -209,6 +209,7 @@ public interface AppointmentService extends OpenmrsService { * @param reason the reason why the appointment block is voided. * @return the appointment block that has been voided. * @should void given appointment block + * @should void all associated time slots */ AppointmentBlock voidAppointmentBlock(AppointmentBlock appointmentBlock, String reason); @@ -235,6 +236,7 @@ public interface AppointmentService extends OpenmrsService { * @return a list of appointment block objects. * @should get all appointment blocks which have contains in a given date interval and * corresponds to a given locations, provider and appointment type. + * @should not return voided appointment blocks */ @Transactional(readOnly = true) List getAppointmentBlocks(Date fromDate, Date toDate, String locations, Provider provider, @@ -435,15 +437,17 @@ List getAppointmentBlocks(Date fromDate, Date toDate, String l List getAppointmentsInTimeSlot(TimeSlot timeSlot); /** - * Should retrieve all appointments in the given time slot that are not missed or cancelled + * Should retrieve all appointments in the given time slot that do not have a status that means + * the appointment has been cancelled (ie status=CANCELLED, CANCELLED_AND_NEEDS_RESCHEDULE, + * MISSED, etc) * * @param timeSlot the time slot to search by. * @return the appointments in the given time slo - * @should not return missed and cancelled appointments. + * @should not return missed, cancelled, and needs_reschedule appointments. * @should not return voided appointments */ @Transactional(readOnly = true) - List getAppointmentsInTimeSlotExcludingMissedAndCancelled(TimeSlot timeSlot); + List getAppointmentsInTimeSlotThatAreNotCancelled(TimeSlot timeSlot); /** * Gets a count of the number of appointments in a time slot @@ -456,15 +460,17 @@ List getAppointmentBlocks(Date fromDate, Date toDate, String l Integer getCountOfAppointmentsInTimeSlot(TimeSlot timeSlot); /** - * Gets a count of the number of appointments in a time slot that are not missed or cancelled + * Gets a count of all appointments in the given time slot that do not have a status that means + * the appointment has been cancelled (ie status=CANCELLED, CANCELLED_AND_NEEDS_RESCHEDULE, + * MISSED, etc) * * @param timeSlot the time slot to search by. * @return the count of appointments in the given time slot - * @should not count missed and cancelled appointments. + * @should not count missed, cancelled and needs rescheduled appointments. * @should not count voided appointments */ @Transactional(readOnly = true) - Integer getCountOfAppointmentsInTimeSlotExcludingMissedAndCancelled(TimeSlot timeSlot); + Integer getCountOfAppointmentsInTimeSlotThatAreNotCancelled(TimeSlot timeSlot); /** * Should retrieve all time slots in the given appointment block. @@ -576,6 +582,7 @@ List getTimeSlotsByConstraintsIncludingFull(AppointmentType appointmen * @param timeSlot the given time slot. * @return The amount of minutes left in the given time slot. Returns null if the given time * slot was null; + * @should ignore appointments with statuses that reflect a "cancelled" appointment */ @Transactional(readOnly = true) Integer getTimeLeftInTimeSlot(TimeSlot timeSlot); @@ -721,8 +728,8 @@ public Map getAverageHistoryDurationByConditionsPerProvider(Da /** * Given an appointment block, this method creates a ScheduledAppointmentBlock convenience - * object that contains all the appointments in the block that are not CANCELLED or MISSED, as - * well as the remaining time available in the blocks + * object that contains all the appointments in the block that are not voided or in one of the + * "cancelled" states * * @param appointmentBlock * @return @@ -731,9 +738,8 @@ public Map getAverageHistoryDurationByConditionsPerProvider(Da ScheduledAppointmentBlock createScheduledAppointmentBlock(AppointmentBlock appointmentBlock); /** - * Gets all scheduled appointment blocks for a certain day at a certain location Ignores any - * blocks within the time period that *do not* have any appointments that are not CANCELLED or - * MISSED + * Gets all scheduled appointment blocks for a certain day at a certain location. Ignores any + * appointments that are voided or in one of the "cancelled" states * * @param location * @param date @@ -742,16 +748,6 @@ public Map getAverageHistoryDurationByConditionsPerProvider(Da @Transactional(readOnly = true) List getDailyAppointmentBlocks(Location location, Date date); - /** - * Calculate the unallocated minutes in the time slot. As follows: Number minutes in time slot - * minus minutes allocated for all appts in the time slot that aren't CANCELLED or MISSED - * - * @param timeSlot - * @return - */ - @Transactional(readOnly = true) - Integer calculateUnallocatedMinutesInTimeSlot(TimeSlot timeSlot); - /** * Books a new appointment * diff --git a/api/src/main/java/org/openmrs/module/appointmentscheduling/api/db/hibernate/HibernateAppointmentDAO.java b/api/src/main/java/org/openmrs/module/appointmentscheduling/api/db/hibernate/HibernateAppointmentDAO.java index 3dd30ccd..9bbcdcd2 100644 --- a/api/src/main/java/org/openmrs/module/appointmentscheduling/api/db/hibernate/HibernateAppointmentDAO.java +++ b/api/src/main/java/org/openmrs/module/appointmentscheduling/api/db/hibernate/HibernateAppointmentDAO.java @@ -155,8 +155,6 @@ public List getAppointmentsByAppointmentBlock(AppointmentBlock appo Criteria criteria = sessionFactory.getCurrentSession().createCriteria(mappedClass); criteria.createAlias("timeSlot", "time_slot"); criteria.add(Restrictions.eq("time_slot.appointmentBlock", appointmentBlock)); - // skip cancelled and missed appointment blocks - criteria.add(Restrictions.and(Restrictions.ne("status", CANCELLED), Restrictions.ne("status", MISSED))); criteria.add(Restrictions.eq("voided", false)); return criteria.list(); diff --git a/api/src/main/java/org/openmrs/module/appointmentscheduling/api/impl/AppointmentServiceImpl.java b/api/src/main/java/org/openmrs/module/appointmentscheduling/api/impl/AppointmentServiceImpl.java index 5b5171b7..ab7dfc7d 100644 --- a/api/src/main/java/org/openmrs/module/appointmentscheduling/api/impl/AppointmentServiceImpl.java +++ b/api/src/main/java/org/openmrs/module/appointmentscheduling/api/impl/AppointmentServiceImpl.java @@ -14,7 +14,6 @@ package org.openmrs.module.appointmentscheduling.api.impl; import java.util.ArrayList; -import java.util.Arrays; import java.util.Calendar; import java.util.Collections; import java.util.Comparator; @@ -27,12 +26,12 @@ import java.util.Map; import java.util.Set; -import org.joda.time.DateTime; -import org.joda.time.Minutes; -import org.openmrs.module.appointmentscheduling.ScheduledAppointmentBlock; -import org.openmrs.module.appointmentscheduling.StudentT; +import org.apache.commons.collections.CollectionUtils; +import org.apache.commons.collections.Predicate; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.joda.time.DateTime; +import org.joda.time.Minutes; import org.openmrs.Location; import org.openmrs.Patient; import org.openmrs.PatientIdentifier; @@ -46,6 +45,8 @@ import org.openmrs.module.appointmentscheduling.AppointmentBlock; import org.openmrs.module.appointmentscheduling.AppointmentStatusHistory; import org.openmrs.module.appointmentscheduling.AppointmentType; +import org.openmrs.module.appointmentscheduling.ScheduledAppointmentBlock; +import org.openmrs.module.appointmentscheduling.StudentT; import org.openmrs.module.appointmentscheduling.TimeSlot; import org.openmrs.module.appointmentscheduling.api.AppointmentService; import org.openmrs.module.appointmentscheduling.api.db.AppointmentBlockDAO; @@ -91,7 +92,7 @@ public AppointmentTypeDAO getAppointmentTypeDAO() { /** * @see org.openmrs.module.appointmentscheduling.api.AppointmentService#getAllAppointmentTypes() */ - @Override + @Override @Transactional(readOnly = true) public Set getAllAppointmentTypes() { HashSet set = new HashSet(); @@ -242,6 +243,7 @@ public AppointmentBlock voidAppointmentBlock(AppointmentBlock appointmentBlock, /** * @see org.openmrs.module.appointmentscheduling.api.AppointmentService#unvoidAppointmentBlock(org.openmrs.AppointmentBlock) */ + // TODO what should this do regarding voided time slots within this block? public AppointmentBlock unvoidAppointmentBlock(AppointmentBlock appointmentBlock) { return saveAppointmentBlock(appointmentBlock); } @@ -408,11 +410,9 @@ public List getAppointmentsInTimeSlot(TimeSlot timeSlot) { } @Override - public List getAppointmentsInTimeSlotExcludingMissedAndCancelled(TimeSlot timeSlot) { - return getAppointmentDAO().getAppointmentsInTimeSlotByStatus( - timeSlot, - Arrays.asList(AppointmentStatus.COMPLETED, AppointmentStatus.INCONSULTATION, AppointmentStatus.RESCHEDULED, - AppointmentStatus.SCHEDULED, AppointmentStatus.WAITING, AppointmentStatus.WALKIN)); + public List getAppointmentsInTimeSlotThatAreNotCancelled(TimeSlot timeSlot) { + return getAppointmentDAO().getAppointmentsInTimeSlotByStatus(timeSlot, + AppointmentStatus.filter(AppointmentStatus.cancelledPredicate)); } @Override @@ -421,11 +421,9 @@ public Integer getCountOfAppointmentsInTimeSlot(TimeSlot timeSlot) { } @Override - public Integer getCountOfAppointmentsInTimeSlotExcludingMissedAndCancelled(TimeSlot timeSlot) { - return getAppointmentDAO().getCountOfAppointmentsInTimeSlotByStatus( - timeSlot, - Arrays.asList(AppointmentStatus.COMPLETED, AppointmentStatus.INCONSULTATION, AppointmentStatus.RESCHEDULED, - AppointmentStatus.SCHEDULED, AppointmentStatus.WAITING, AppointmentStatus.WALKIN)); + public Integer getCountOfAppointmentsInTimeSlotThatAreNotCancelled(TimeSlot timeSlot) { + return getAppointmentDAO().getCountOfAppointmentsInTimeSlotByStatus(timeSlot, + AppointmentStatus.filter(AppointmentStatus.cancelledPredicate)); } @Override @@ -565,27 +563,20 @@ public List getPatientIdentifiersRepresentation(Patient patient) { @Override @Transactional(readOnly = true) public Integer getTimeLeftInTimeSlot(TimeSlot timeSlot) { - Integer timeLeft = null; - if (timeSlot == null) - return timeLeft; - - Date startDate = timeSlot.getStartDate(); - Date endDate = timeSlot.getEndDate(); + if (timeSlot == null) { + return null; + } - //Calculate total number of minutes in the time slot. - timeLeft = (int) ((endDate.getTime() / 60000) - (startDate.getTime() / 60000)); + Integer minutes = Minutes.minutesBetween(new DateTime(timeSlot.getStartDate()), new DateTime(timeSlot.getEndDate())) + .getMinutes(); - //Subtract from time left the amounts of minutes already scheduled - //Should not take into consideration cancelled or missed appointments - List appointments = getAppointmentsInTimeSlot(timeSlot); - for (Appointment appointment : appointments) { - if (!appointment.isVoided() && appointment.getStatus() != AppointmentStatus.CANCELLED - && appointment.getStatus() != AppointmentStatus.MISSED) - timeLeft -= appointment.getAppointmentType().getDuration(); + for (Appointment appointment : Context.getService(AppointmentService.class) + .getAppointmentsInTimeSlotThatAreNotCancelled(timeSlot)) { + minutes = minutes - appointment.getAppointmentType().getDuration(); } - return timeLeft; + return minutes; } @Override @@ -922,22 +913,19 @@ public List getDailyAppointmentBlocks(Location locati @Transactional(readOnly = true) public ScheduledAppointmentBlock createScheduledAppointmentBlock(AppointmentBlock appointmentBlock) { List appointmentList = getAppointmentDAO().getAppointmentsByAppointmentBlock(appointmentBlock); - return new ScheduledAppointmentBlock(appointmentList, appointmentBlock); - } - - @Override - @Transactional(readOnly = true) - public Integer calculateUnallocatedMinutesInTimeSlot(TimeSlot timeSlot) { - Integer minutes = Minutes.minutesBetween(new DateTime(timeSlot.getStartDate()), new DateTime(timeSlot.getEndDate())) - .getMinutes(); - - for (Appointment appointment : Context.getService(AppointmentService.class) - .getAppointmentsInTimeSlotExcludingMissedAndCancelled(timeSlot)) { - minutes = minutes - appointment.getAppointmentType().getDuration(); - } + // only include appointments that aren't "cancelled" + CollectionUtils.filter(appointmentList, new Predicate() { + + List cancelledStatuses = AppointmentStatus.filter(AppointmentStatus.cancelledPredicate); + + @Override + public boolean evaluate(Object o) { + return cancelledStatuses.contains(((Appointment) o).getStatus()); + } + }); - return minutes; + return new ScheduledAppointmentBlock(appointmentList, appointmentBlock); } @Override @@ -948,13 +936,12 @@ public Appointment bookAppointment(Appointment appointment, Boolean allowOverboo if (appointment.getId() != null) { throw new APIException("Cannot book appointment that has already been persisted"); } - - // annoying that we have to do this, since it will be called during save, but otherwise we might get a NPE below if time slot or appointment type == null + + // annoying that we have to do this, since it will be called during save, but otherwise we might get a NPE below if time slot or appointment type == null ValidateUtil.validate(appointment); if (!allowOverbook) { - if (calculateUnallocatedMinutesInTimeSlot(appointment.getTimeSlot()) < appointment.getAppointmentType() - .getDuration()) { + if (getTimeLeftInTimeSlot(appointment.getTimeSlot()) < appointment.getAppointmentType().getDuration()) { throw new TimeSlotFullException(); } } diff --git a/api/src/test/java/org/openmrs/module/appointmentscheduling/api/AppointmentServiceTest.java b/api/src/test/java/org/openmrs/module/appointmentscheduling/api/AppointmentServiceTest.java index 56b385c5..7032a38a 100644 --- a/api/src/test/java/org/openmrs/module/appointmentscheduling/api/AppointmentServiceTest.java +++ b/api/src/test/java/org/openmrs/module/appointmentscheduling/api/AppointmentServiceTest.java @@ -340,7 +340,7 @@ public void shouldgetAllUnvoidedAppointmentsByStatus_getAppointmentsByConstraint assertEquals(3, appointments.size()); appointments = service.getAppointmentsByConstraints(null, null, null, null, null, AppointmentStatus.MISSED); - assertEquals(3, appointments.size()); + assertEquals(2, appointments.size()); ; } @@ -365,10 +365,10 @@ public void shouldGetCorrectAppointments_getAppointmentsByStatus() { assertNotNull(appointment); assertTrue(result.contains(appointment)); - // +"MISSED": 2 5 9 + // +"MISSED": 2 5 states.add(AppointmentStatus.MISSED); result = service.getAppointmentsByStatus(states); - assertEquals(6, result.size()); + assertEquals(5, result.size()); appointment = service.getAppointment(1); assertNotNull(appointment); assertTrue(result.contains(appointment)); @@ -384,10 +384,6 @@ public void shouldGetCorrectAppointments_getAppointmentsByStatus() { appointment = service.getAppointment(5); assertNotNull(appointment); assertTrue(result.contains(appointment)); - appointment = service.getAppointment(9); - assertNotNull(appointment); - assertTrue(result.contains(appointment)); - } @Test @@ -523,13 +519,13 @@ public void getCountOfAppointmentInTimeSlot_shouldGetCorrectCount() { } @Test - public void getAppointmentsInTimeSlotExcludingMissedAndCancelled_shouldGetCorrectAppointments() { + public void getAppointmentsInTimeSlotThatAreNotCancelled_shouldGetCorrectAppointments() { TimeSlot timeSlot = service.getTimeSlot(8); assertNotNull(timeSlot); - List appointments = service.getAppointmentsInTimeSlotExcludingMissedAndCancelled(timeSlot); + List appointments = service.getAppointmentsInTimeSlotThatAreNotCancelled(timeSlot); assertNotNull(appointments); - assertEquals(2, appointments.size()); // there are five appointments in this time slot, but one is voided, one is cancelled, and one is missed + assertEquals(2, appointments.size()); // there are five appointments in this time slot, but one is voided, one is cancelled, and one is needs_reschedule Appointment appointment = service.getAppointment(7); assertTrue(appointments.contains(appointment)); @@ -538,9 +534,9 @@ public void getAppointmentsInTimeSlotExcludingMissedAndCancelled_shouldGetCorrec } @Test - public void getCountOfAppointmentsInTimeSlotExcludingMissedAndCancelled_shouldGetCorrectAppointments() { + public void getCountOfAppointmentsInTimeSlotThatAreNotCancelled_shouldGetCorrectAppointments() { TimeSlot timeSlot = service.getTimeSlot(8); - assertEquals(new Integer(2), service.getCountOfAppointmentsInTimeSlotExcludingMissedAndCancelled(timeSlot)); // there are five appointments in this time slot, but one is voided, one is cancelled, and one is missed + assertEquals(new Integer(2), service.getCountOfAppointmentsInTimeSlotThatAreNotCancelled(timeSlot)); // there are five appointments in this time slot, but one is voided, one is need_reschedule, and one is missed } @Test(expected = APIException.class) diff --git a/api/src/test/java/org/openmrs/module/appointmentscheduling/api/TimeSlotServiceTest.java b/api/src/test/java/org/openmrs/module/appointmentscheduling/api/TimeSlotServiceTest.java index 4aa935ac..fe914477 100644 --- a/api/src/test/java/org/openmrs/module/appointmentscheduling/api/TimeSlotServiceTest.java +++ b/api/src/test/java/org/openmrs/module/appointmentscheduling/api/TimeSlotServiceTest.java @@ -407,10 +407,4 @@ public void shouldGetOnlyAvailableTimeSlotsByConstraintsSortedByStartDate() thro assertEquals(9, lastTimeSlot.getTimeSlotId().intValue()); } - @Test - public void calculateUnallocatedMinutesInTimeSlot_shouldProperlyCalculateUnallocatedMinutes() { - TimeSlot timeSlot = service.getTimeSlot(8); - // block is 12 hours long, with 2 appointments of 54 each = 12 * 60 - 54 + 2 - assertEquals(new Integer(612), service.calculateUnallocatedMinutesInTimeSlot(timeSlot)); - } } diff --git a/api/src/test/resources/standardAppointmentTestDataset.xml b/api/src/test/resources/standardAppointmentTestDataset.xml index 4ae16b04..be64745e 100644 --- a/api/src/test/resources/standardAppointmentTestDataset.xml +++ b/api/src/test/resources/standardAppointmentTestDataset.xml @@ -37,7 +37,6 @@ - @@ -51,7 +50,7 @@ - + diff --git a/omod/src/main/java/org/openmrs/module/appointmentscheduling/rest/resource/openmrs1_9/AppointmentResource1_9.java b/omod/src/main/java/org/openmrs/module/appointmentscheduling/rest/resource/openmrs1_9/AppointmentResource1_9.java index 1a83cea3..7264a257 100644 --- a/omod/src/main/java/org/openmrs/module/appointmentscheduling/rest/resource/openmrs1_9/AppointmentResource1_9.java +++ b/omod/src/main/java/org/openmrs/module/appointmentscheduling/rest/resource/openmrs1_9/AppointmentResource1_9.java @@ -72,7 +72,7 @@ public DelegatingResourceDescription getCreatableProperties() { @Override public DelegatingResourceDescription getUpdatableProperties() { - // note that time slot and appointment type are not updateable + // note that time slot and appointment type are not updateable DelegatingResourceDescription description = new DelegatingResourceDescription(); description.addProperty("visit"); description.addRequiredProperty("status"); @@ -113,8 +113,8 @@ protected Appointment save(Appointment appointment, Boolean allowOverbook) { return Context.getService(AppointmentService.class).bookAppointment(appointment, allowOverbook); } catch (TimeSlotFullException e) { - Errors errors = new BindException(appointment, ""); - errors.reject("appointmentscheduling.Appointment.error.timeSlotFull"); + Errors errors = new BindException(appointment, ""); + errors.reject("appointmentscheduling.Appointment.error.timeSlotFull"); throw new ValidationException("appointmentscheduling.Appointment.error.timeSlotFull", errors); } } diff --git a/omod/src/main/java/org/openmrs/module/appointmentscheduling/rest/resource/openmrs1_9/TimeSlotResource1_9.java b/omod/src/main/java/org/openmrs/module/appointmentscheduling/rest/resource/openmrs1_9/TimeSlotResource1_9.java index ce13be94..feeba64a 100644 --- a/omod/src/main/java/org/openmrs/module/appointmentscheduling/rest/resource/openmrs1_9/TimeSlotResource1_9.java +++ b/omod/src/main/java/org/openmrs/module/appointmentscheduling/rest/resource/openmrs1_9/TimeSlotResource1_9.java @@ -157,12 +157,11 @@ public String getDisplayString(TimeSlot timeSlot) { } public Integer getCountOfAppointments(TimeSlot timeSlot) { - return Context.getService(AppointmentService.class).getCountOfAppointmentsInTimeSlotExcludingMissedAndCancelled( - timeSlot); + return Context.getService(AppointmentService.class).getCountOfAppointmentsInTimeSlotThatAreNotCancelled(timeSlot); } public Integer getUnallocatedMinutes(TimeSlot timeSlot) { - return Context.getService(AppointmentService.class).calculateUnallocatedMinutesInTimeSlot(timeSlot); + return Context.getService(AppointmentService.class).getTimeLeftInTimeSlot(timeSlot); } } diff --git a/omod/src/test/java/org/openmrs/module/appointmentscheduling/rest/controller/AppointmentBlockResource1_9ControllerTest.java b/omod/src/test/java/org/openmrs/module/appointmentscheduling/rest/controller/AppointmentBlockResource1_9ControllerTest.java index 08dcc17e..f361f34f 100644 --- a/omod/src/test/java/org/openmrs/module/appointmentscheduling/rest/controller/AppointmentBlockResource1_9ControllerTest.java +++ b/omod/src/test/java/org/openmrs/module/appointmentscheduling/rest/controller/AppointmentBlockResource1_9ControllerTest.java @@ -1,5 +1,8 @@ package org.openmrs.module.appointmentscheduling.rest.controller; +import java.util.List; +import java.util.Map; + import org.apache.commons.beanutils.PropertyUtils; import org.junit.Assert; import org.junit.Before; @@ -14,9 +17,6 @@ import org.springframework.mock.web.MockHttpServletRequest; import org.springframework.web.bind.annotation.RequestMethod; -import java.util.List; -import java.util.Map; - import static org.junit.Assert.assertThat; import static org.openmrs.module.appointmentscheduling.rest.test.SameDatetimeMatcher.sameDatetime; @@ -71,7 +71,7 @@ public void shouldGetFullAppointmentBlockByUuid() throws Exception { PropertyUtils.getProperty(result, "display")); Assert.assertEquals("c0c549b0-8e59-401d-8a4a-976a0b183599", Util.getByPath(result, "provider/uuid")); - Assert.assertEquals("Super User", Util.getByPath(result, "provider/person/preferredName/display")); + Assert.assertEquals("Super User", Util.getByPath(result, "provider/person/display")); Assert.assertEquals("9356400c-a5a2-4532-8f2b-2361b3446eb8", Util.getByPath(result, "location/uuid")); Assert.assertEquals("Xanadu", Util.getByPath(result, "location/name"));