diff --git a/api/src/main/java/org/openmrs/module/appointmentscheduling/exception/TimeSlotFullException.java b/api/src/main/java/org/openmrs/module/appointmentscheduling/exception/TimeSlotFullException.java index 799b4397..f63772a8 100644 --- a/api/src/main/java/org/openmrs/module/appointmentscheduling/exception/TimeSlotFullException.java +++ b/api/src/main/java/org/openmrs/module/appointmentscheduling/exception/TimeSlotFullException.java @@ -1,15 +1,15 @@ -package org.openmrs.module.appointmentscheduling.exception; - -public class TimeSlotFullException extends Exception { - - private static final long serialVersionUID = 1L; - - public TimeSlotFullException() { - super(); - } - - public TimeSlotFullException(String message) { - super(message); - } - -} +package org.openmrs.module.appointmentscheduling.exception; + +public class TimeSlotFullException extends Exception { + + private static final long serialVersionUID = 1L; + + public TimeSlotFullException() { + super(); + } + + public TimeSlotFullException(String message) { + super(message); + } + +} diff --git a/omod/src/main/java/org/openmrs/module/appointmentscheduling/rest/resource/openmrs1_9/AppointmentAllowingOverbookResource1_9.java b/omod/src/main/java/org/openmrs/module/appointmentscheduling/rest/resource/openmrs1_9/AppointmentAllowingOverbookResource1_9.java index a64f96cb..fa8b84e1 100644 --- a/omod/src/main/java/org/openmrs/module/appointmentscheduling/rest/resource/openmrs1_9/AppointmentAllowingOverbookResource1_9.java +++ b/omod/src/main/java/org/openmrs/module/appointmentscheduling/rest/resource/openmrs1_9/AppointmentAllowingOverbookResource1_9.java @@ -1,17 +1,17 @@ -package org.openmrs.module.appointmentscheduling.rest.resource.openmrs1_9; - -import org.openmrs.module.appointmentscheduling.Appointment; -import org.openmrs.module.appointmentscheduling.rest.controller.AppointmentRestController; -import org.openmrs.module.webservices.rest.web.RestConstants; -import org.openmrs.module.webservices.rest.web.annotation.Resource; - -@Resource(name = RestConstants.VERSION_1 + AppointmentRestController.APPOINTMENT_SCHEDULING_REST_NAMESPACE - + "/appointmentallowingoverbook", supportedClass = Appointment.class, supportedOpenmrsVersions = "1.9.*") -public class AppointmentAllowingOverbookResource1_9 extends AppointmentResource1_9 { - - @Override - public Appointment save(Appointment appointment) { - return save(appointment, true); - } - -} +package org.openmrs.module.appointmentscheduling.rest.resource.openmrs1_9; + +import org.openmrs.module.appointmentscheduling.Appointment; +import org.openmrs.module.appointmentscheduling.rest.controller.AppointmentRestController; +import org.openmrs.module.webservices.rest.web.RestConstants; +import org.openmrs.module.webservices.rest.web.annotation.Resource; + +@Resource(name = RestConstants.VERSION_1 + AppointmentRestController.APPOINTMENT_SCHEDULING_REST_NAMESPACE + + "/appointmentallowingoverbook", supportedClass = Appointment.class, supportedOpenmrsVersions = "1.9.*") +public class AppointmentAllowingOverbookResource1_9 extends AppointmentResource1_9 { + + @Override + public Appointment save(Appointment appointment) { + return save(appointment, true); + } + +} diff --git a/omod/src/main/java/org/openmrs/module/appointmentscheduling/rest/resource/openmrs1_9/AppointmentBlockWithTimeSlotResource1_9.java b/omod/src/main/java/org/openmrs/module/appointmentscheduling/rest/resource/openmrs1_9/AppointmentBlockWithTimeSlotResource1_9.java index 05f42b62..0597ab9c 100644 --- a/omod/src/main/java/org/openmrs/module/appointmentscheduling/rest/resource/openmrs1_9/AppointmentBlockWithTimeSlotResource1_9.java +++ b/omod/src/main/java/org/openmrs/module/appointmentscheduling/rest/resource/openmrs1_9/AppointmentBlockWithTimeSlotResource1_9.java @@ -1,75 +1,75 @@ -package org.openmrs.module.appointmentscheduling.rest.resource.openmrs1_9; - -import java.util.List; - -import org.openmrs.api.context.Context; -import org.openmrs.module.appointmentscheduling.AppointmentBlock; -import org.openmrs.module.appointmentscheduling.TimeSlot; -import org.openmrs.module.appointmentscheduling.api.AppointmentService; -import org.openmrs.module.appointmentscheduling.rest.controller.AppointmentRestController; -import org.openmrs.module.webservices.rest.web.RestConstants; -import org.openmrs.module.webservices.rest.web.annotation.Resource; -import org.springframework.transaction.annotation.Transactional; - -/** - * This is a special resource for interacting with AppointmentBlocks in the use case where we want a - * 1-to-1 relationship with Time Slots (that is, each AppointmentBlock has a single TimeSlot with - * the same start and end time); this resource overrides the save method of the main - * AppointmentBlockResource1_9 to create/update an associated Time Slot whenever an AppointmentBlock - * is updated - */ - -@Resource(name = RestConstants.VERSION_1 + AppointmentRestController.APPOINTMENT_SCHEDULING_REST_NAMESPACE - + "/appointmentblockwithtimeslot", supportedClass = AppointmentBlock.class, supportedOpenmrsVersions = "1.9.*") -public class AppointmentBlockWithTimeSlotResource1_9 extends AppointmentBlockResource1_9 { - - @Override - @Transactional - // TODO does this actually make this transactional? probably not? - public AppointmentBlock save(AppointmentBlock appointmentBlock) { - - appointmentBlock = Context.getService(AppointmentService.class).saveAppointmentBlock(appointmentBlock); - - List timeSlots = Context.getService(AppointmentService.class).getTimeSlotsInAppointmentBlock( - appointmentBlock); - - if (timeSlots == null || timeSlots.isEmpty()) { - createTimeSlotInAppointmentBlock(appointmentBlock); - } else { - updateTimeSlotInAppointmentBlock(appointmentBlock, timeSlots.get(0)); - if (timeSlots.size() > 1) { - voidTimeSlots(timeSlots.subList(1, timeSlots.size())); - } - } - - return appointmentBlock; - } - - private TimeSlot createTimeSlotInAppointmentBlock(AppointmentBlock appointmentBlock) { - - TimeSlot timeSlot = new TimeSlot(); - timeSlot.setAppointmentBlock(appointmentBlock); - timeSlot.setStartDate(appointmentBlock.getStartDate()); - timeSlot.setEndDate(appointmentBlock.getEndDate()); - - return Context.getService(AppointmentService.class).saveTimeSlot(timeSlot); - } - - private TimeSlot updateTimeSlotInAppointmentBlock(AppointmentBlock appointmentBlock, TimeSlot timeSlot) { - - timeSlot.setStartDate(appointmentBlock.getStartDate()); - timeSlot.setEndDate(appointmentBlock.getEndDate()); - - return Context.getService(AppointmentService.class).saveTimeSlot(timeSlot); - } - - private void voidTimeSlots(List timeSlots) { - - for (TimeSlot timeSlot : timeSlots) { - Context.getService(AppointmentService.class).voidTimeSlot(timeSlot, - "appointment block has more than one time slot"); - } - - } - -} +package org.openmrs.module.appointmentscheduling.rest.resource.openmrs1_9; + +import java.util.List; + +import org.openmrs.api.context.Context; +import org.openmrs.module.appointmentscheduling.AppointmentBlock; +import org.openmrs.module.appointmentscheduling.TimeSlot; +import org.openmrs.module.appointmentscheduling.api.AppointmentService; +import org.openmrs.module.appointmentscheduling.rest.controller.AppointmentRestController; +import org.openmrs.module.webservices.rest.web.RestConstants; +import org.openmrs.module.webservices.rest.web.annotation.Resource; +import org.springframework.transaction.annotation.Transactional; + +/** + * This is a special resource for interacting with AppointmentBlocks in the use case where we want a + * 1-to-1 relationship with Time Slots (that is, each AppointmentBlock has a single TimeSlot with + * the same start and end time); this resource overrides the save method of the main + * AppointmentBlockResource1_9 to create/update an associated Time Slot whenever an AppointmentBlock + * is updated + */ + +@Resource(name = RestConstants.VERSION_1 + AppointmentRestController.APPOINTMENT_SCHEDULING_REST_NAMESPACE + + "/appointmentblockwithtimeslot", supportedClass = AppointmentBlock.class, supportedOpenmrsVersions = "1.9.*") +public class AppointmentBlockWithTimeSlotResource1_9 extends AppointmentBlockResource1_9 { + + @Override + @Transactional + // TODO does this actually make this transactional? probably not? + public AppointmentBlock save(AppointmentBlock appointmentBlock) { + + appointmentBlock = Context.getService(AppointmentService.class).saveAppointmentBlock(appointmentBlock); + + List timeSlots = Context.getService(AppointmentService.class).getTimeSlotsInAppointmentBlock( + appointmentBlock); + + if (timeSlots == null || timeSlots.isEmpty()) { + createTimeSlotInAppointmentBlock(appointmentBlock); + } else { + updateTimeSlotInAppointmentBlock(appointmentBlock, timeSlots.get(0)); + if (timeSlots.size() > 1) { + voidTimeSlots(timeSlots.subList(1, timeSlots.size())); + } + } + + return appointmentBlock; + } + + private TimeSlot createTimeSlotInAppointmentBlock(AppointmentBlock appointmentBlock) { + + TimeSlot timeSlot = new TimeSlot(); + timeSlot.setAppointmentBlock(appointmentBlock); + timeSlot.setStartDate(appointmentBlock.getStartDate()); + timeSlot.setEndDate(appointmentBlock.getEndDate()); + + return Context.getService(AppointmentService.class).saveTimeSlot(timeSlot); + } + + private TimeSlot updateTimeSlotInAppointmentBlock(AppointmentBlock appointmentBlock, TimeSlot timeSlot) { + + timeSlot.setStartDate(appointmentBlock.getStartDate()); + timeSlot.setEndDate(appointmentBlock.getEndDate()); + + return Context.getService(AppointmentService.class).saveTimeSlot(timeSlot); + } + + private void voidTimeSlots(List timeSlots) { + + for (TimeSlot timeSlot : timeSlots) { + Context.getService(AppointmentService.class).voidTimeSlot(timeSlot, + "appointment block has more than one time slot"); + } + + } + +} diff --git a/omod/src/test/java/org/openmrs/module/appointmentscheduling/rest/controller/AppointmentAllowingOverbookResource1_9ControllerTest.java b/omod/src/test/java/org/openmrs/module/appointmentscheduling/rest/controller/AppointmentAllowingOverbookResource1_9ControllerTest.java index f5363a0f..8cf80f71 100644 --- a/omod/src/test/java/org/openmrs/module/appointmentscheduling/rest/controller/AppointmentAllowingOverbookResource1_9ControllerTest.java +++ b/omod/src/test/java/org/openmrs/module/appointmentscheduling/rest/controller/AppointmentAllowingOverbookResource1_9ControllerTest.java @@ -1,60 +1,60 @@ -package org.openmrs.module.appointmentscheduling.rest.controller; - -import org.apache.commons.beanutils.PropertyUtils; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; -import org.openmrs.api.context.Context; -import org.openmrs.module.appointmentscheduling.api.AppointmentService; -import org.openmrs.module.webservices.rest.web.v1_0.controller.MainResourceControllerTest; -import org.springframework.mock.web.MockHttpServletRequest; -import org.springframework.web.bind.annotation.RequestMethod; - -public class AppointmentAllowingOverbookResource1_9ControllerTest extends MainResourceControllerTest { - - private AppointmentService appointmentService; - - @Before - public void setup() throws Exception { - appointmentService = Context.getService(AppointmentService.class); - executeDataSet("standardWebAppointmentTestDataset.xml"); - } - - @Test - public void shouldCreateNewAppointmentEvenIfTimeBlockFull() throws Exception { - - String json = "{ \"timeSlot\":\"c0c579b0-8e59-401d-8a4a-976a0b183604\", " - + "\"patient\":\"31e09960-8f52-11e3-baa8-0800200c9a66\", \"status\":\"SCHEDULED\", " - + "\"appointmentType\": \"c0c579b0-8e59-401d-8a4a-976a0b183519\" }"; - - MockHttpServletRequest req = request(RequestMethod.POST, getURI()); - req.setContent(json.getBytes()); - - Object appt = deserialize(handle(req)); - Assert.assertNotNull(PropertyUtils.getProperty(appt, "uuid")); - Assert.assertEquals("c0c579b0-8e59-401d-8a4a-976a0b183604", - PropertyUtils.getProperty(PropertyUtils.getProperty(appt, "timeSlot"), "uuid")); - Assert.assertEquals("31e09960-8f52-11e3-baa8-0800200c9a66", - PropertyUtils.getProperty(PropertyUtils.getProperty(appt, "patient"), "uuid")); - Assert.assertEquals("SCHEDULED", PropertyUtils.getProperty(appt, "status")); - Assert.assertEquals("c0c579b0-8e59-401d-8a4a-976a0b183519", - PropertyUtils.getProperty(PropertyUtils.getProperty(appt, "appointmentType"), "uuid")); - Assert.assertEquals(getAllCount() + 1, appointmentService.getAllAppointments().size()); - - } - - @Override - public String getURI() { - return AppointmentRestController.APPOINTMENT_SCHEDULING_REST_NAMESPACE + "/appointmentallowingoverbook"; - } - - @Override - public String getUuid() { - return "c0c579b0-8e59-401d-8a4a-976a0b183601"; - } - - @Override - public long getAllCount() { - return 7; - } -} +package org.openmrs.module.appointmentscheduling.rest.controller; + +import org.apache.commons.beanutils.PropertyUtils; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.openmrs.api.context.Context; +import org.openmrs.module.appointmentscheduling.api.AppointmentService; +import org.openmrs.module.webservices.rest.web.v1_0.controller.MainResourceControllerTest; +import org.springframework.mock.web.MockHttpServletRequest; +import org.springframework.web.bind.annotation.RequestMethod; + +public class AppointmentAllowingOverbookResource1_9ControllerTest extends MainResourceControllerTest { + + private AppointmentService appointmentService; + + @Before + public void setup() throws Exception { + appointmentService = Context.getService(AppointmentService.class); + executeDataSet("standardWebAppointmentTestDataset.xml"); + } + + @Test + public void shouldCreateNewAppointmentEvenIfTimeBlockFull() throws Exception { + + String json = "{ \"timeSlot\":\"c0c579b0-8e59-401d-8a4a-976a0b183604\", " + + "\"patient\":\"31e09960-8f52-11e3-baa8-0800200c9a66\", \"status\":\"SCHEDULED\", " + + "\"appointmentType\": \"c0c579b0-8e59-401d-8a4a-976a0b183519\" }"; + + MockHttpServletRequest req = request(RequestMethod.POST, getURI()); + req.setContent(json.getBytes()); + + Object appt = deserialize(handle(req)); + Assert.assertNotNull(PropertyUtils.getProperty(appt, "uuid")); + Assert.assertEquals("c0c579b0-8e59-401d-8a4a-976a0b183604", + PropertyUtils.getProperty(PropertyUtils.getProperty(appt, "timeSlot"), "uuid")); + Assert.assertEquals("31e09960-8f52-11e3-baa8-0800200c9a66", + PropertyUtils.getProperty(PropertyUtils.getProperty(appt, "patient"), "uuid")); + Assert.assertEquals("SCHEDULED", PropertyUtils.getProperty(appt, "status")); + Assert.assertEquals("c0c579b0-8e59-401d-8a4a-976a0b183519", + PropertyUtils.getProperty(PropertyUtils.getProperty(appt, "appointmentType"), "uuid")); + Assert.assertEquals(getAllCount() + 1, appointmentService.getAllAppointments().size()); + + } + + @Override + public String getURI() { + return AppointmentRestController.APPOINTMENT_SCHEDULING_REST_NAMESPACE + "/appointmentallowingoverbook"; + } + + @Override + public String getUuid() { + return "c0c579b0-8e59-401d-8a4a-976a0b183601"; + } + + @Override + public long getAllCount() { + return 7; + } +} diff --git a/omod/src/test/java/org/openmrs/module/appointmentscheduling/rest/controller/AppointmentBlockWithTimeSlotResource1_9ControllerTest.java b/omod/src/test/java/org/openmrs/module/appointmentscheduling/rest/controller/AppointmentBlockWithTimeSlotResource1_9ControllerTest.java index 293e5beb..1796e2d6 100644 --- a/omod/src/test/java/org/openmrs/module/appointmentscheduling/rest/controller/AppointmentBlockWithTimeSlotResource1_9ControllerTest.java +++ b/omod/src/test/java/org/openmrs/module/appointmentscheduling/rest/controller/AppointmentBlockWithTimeSlotResource1_9ControllerTest.java @@ -1,76 +1,76 @@ -package org.openmrs.module.appointmentscheduling.rest.controller; - -import org.apache.commons.beanutils.PropertyUtils; -import org.junit.Assert; -import org.junit.Test; -import org.openmrs.module.appointmentscheduling.AppointmentBlock; -import org.openmrs.module.appointmentscheduling.TimeSlot; -import org.openmrs.module.appointmentscheduling.api.AppointmentService; -import org.springframework.mock.web.MockHttpServletRequest; -import org.springframework.web.bind.annotation.RequestMethod; - -import java.util.List; - -import static org.junit.Assert.assertThat; -import static org.openmrs.module.appointmentscheduling.rest.test.SameDatetimeMatcher.sameDatetime; - -public class AppointmentBlockWithTimeSlotResource1_9ControllerTest extends AppointmentBlockResource1_9ControllerTest { - - // runs all the basic AppointmentBlockResource1_9 tests plus these additional tests - - @Test - public void shouldCreateNewAppointmentBlockWithTimeSlot() throws Exception { - - String json = "{ \"startDate\":\"2005-03-01T00:00:00.000-0500\", \"endDate\":\"2005-03-01T11:00:00.000-0500\", " - + "\"provider\":\"c0c54sd0-8e59-401d-8a4a-976a0b183599\", \"location\":\"9356400c-a5a2-4532-8f2b-2361b3446eb8\", " - + "\"types\": [ \"c0c579b0-8e59-401d-8a4a-976a0b183519\" ]" + "}"; - - MockHttpServletRequest req = request(RequestMethod.POST, getURI()); - req.setContent(json.getBytes()); - - Object appt = deserialize(handle(req)); - Assert.assertNotNull(PropertyUtils.getProperty(appt, "uuid")); - assertThat((String) PropertyUtils.getProperty(appt, "startDate"), sameDatetime("2005-03-01T00:00:00.000-0500")); - assertThat((String) PropertyUtils.getProperty(appt, "endDate"), sameDatetime("2005-03-01T11:00:00.000-0500")); - Assert.assertEquals("c0c54sd0-8e59-401d-8a4a-976a0b183599", - PropertyUtils.getProperty(PropertyUtils.getProperty(appt, "provider"), "uuid")); - Assert.assertEquals("9356400c-a5a2-4532-8f2b-2361b3446eb8", - PropertyUtils.getProperty(PropertyUtils.getProperty(appt, "location"), "uuid")); - - // make sure a time slot has been created for the appointment block - AppointmentBlock appointmentBlock = appointmentService.getAppointmentBlockByUuid(PropertyUtils.getProperty(appt, - "uuid").toString()); - Assert.assertNotNull(appointmentBlock); - TimeSlot timeSlot = appointmentService.getTimeSlotsInAppointmentBlock(appointmentBlock).get(0); - Assert.assertNotNull(timeSlot); - Assert.assertEquals(appointmentBlock.getStartDate(), timeSlot.getStartDate()); - Assert.assertEquals(appointmentBlock.getEndDate(), timeSlot.getEndDate()); - - } - - @Test - public void shouldEditAnAppointmentBlockAndUpdateTimeSlots() throws Exception { - - String json = "{ \"provider\":\"c0c54sd0-8e59-401d-8a4a-976a0b183599\" }"; - MockHttpServletRequest req = request(RequestMethod.POST, getURI() + "/c0c579b0-8e59-401d-8a4a-976a0b183599"); - req.setContent(json.getBytes()); - handle(req); - - AppointmentBlock updated = appointmentService.getAppointmentBlockByUuid("c0c579b0-8e59-401d-8a4a-976a0b183599"); - Assert.assertNotNull(updated); - Assert.assertEquals("c0c54sd0-8e59-401d-8a4a-976a0b183599", updated.getProvider().getUuid()); - - // make sure a time slot has been updated for the appointment block - List timeSlots = appointmentService.getTimeSlotsInAppointmentBlock(updated); - Assert.assertEquals(1, timeSlots.size()); - TimeSlot timeSlot = timeSlots.get(0); - Assert.assertNotNull(timeSlot); - Assert.assertEquals(updated.getStartDate(), timeSlot.getStartDate()); - Assert.assertEquals(updated.getEndDate(), timeSlot.getEndDate()); - } - - @Override - public String getURI() { - return AppointmentRestController.APPOINTMENT_SCHEDULING_REST_NAMESPACE + "/appointmentblockwithtimeslot"; - } -} +package org.openmrs.module.appointmentscheduling.rest.controller; + +import org.apache.commons.beanutils.PropertyUtils; +import org.junit.Assert; +import org.junit.Test; +import org.openmrs.module.appointmentscheduling.AppointmentBlock; +import org.openmrs.module.appointmentscheduling.TimeSlot; +import org.openmrs.module.appointmentscheduling.api.AppointmentService; +import org.springframework.mock.web.MockHttpServletRequest; +import org.springframework.web.bind.annotation.RequestMethod; + +import java.util.List; + +import static org.junit.Assert.assertThat; +import static org.openmrs.module.appointmentscheduling.rest.test.SameDatetimeMatcher.sameDatetime; + +public class AppointmentBlockWithTimeSlotResource1_9ControllerTest extends AppointmentBlockResource1_9ControllerTest { + + // runs all the basic AppointmentBlockResource1_9 tests plus these additional tests + + @Test + public void shouldCreateNewAppointmentBlockWithTimeSlot() throws Exception { + + String json = "{ \"startDate\":\"2005-03-01T00:00:00.000-0500\", \"endDate\":\"2005-03-01T11:00:00.000-0500\", " + + "\"provider\":\"c0c54sd0-8e59-401d-8a4a-976a0b183599\", \"location\":\"9356400c-a5a2-4532-8f2b-2361b3446eb8\", " + + "\"types\": [ \"c0c579b0-8e59-401d-8a4a-976a0b183519\" ]" + "}"; + + MockHttpServletRequest req = request(RequestMethod.POST, getURI()); + req.setContent(json.getBytes()); + + Object appt = deserialize(handle(req)); + Assert.assertNotNull(PropertyUtils.getProperty(appt, "uuid")); + assertThat((String) PropertyUtils.getProperty(appt, "startDate"), sameDatetime("2005-03-01T00:00:00.000-0500")); + assertThat((String) PropertyUtils.getProperty(appt, "endDate"), sameDatetime("2005-03-01T11:00:00.000-0500")); + Assert.assertEquals("c0c54sd0-8e59-401d-8a4a-976a0b183599", + PropertyUtils.getProperty(PropertyUtils.getProperty(appt, "provider"), "uuid")); + Assert.assertEquals("9356400c-a5a2-4532-8f2b-2361b3446eb8", + PropertyUtils.getProperty(PropertyUtils.getProperty(appt, "location"), "uuid")); + + // make sure a time slot has been created for the appointment block + AppointmentBlock appointmentBlock = appointmentService.getAppointmentBlockByUuid(PropertyUtils.getProperty(appt, + "uuid").toString()); + Assert.assertNotNull(appointmentBlock); + TimeSlot timeSlot = appointmentService.getTimeSlotsInAppointmentBlock(appointmentBlock).get(0); + Assert.assertNotNull(timeSlot); + Assert.assertEquals(appointmentBlock.getStartDate(), timeSlot.getStartDate()); + Assert.assertEquals(appointmentBlock.getEndDate(), timeSlot.getEndDate()); + + } + + @Test + public void shouldEditAnAppointmentBlockAndUpdateTimeSlots() throws Exception { + + String json = "{ \"provider\":\"c0c54sd0-8e59-401d-8a4a-976a0b183599\" }"; + MockHttpServletRequest req = request(RequestMethod.POST, getURI() + "/c0c579b0-8e59-401d-8a4a-976a0b183599"); + req.setContent(json.getBytes()); + handle(req); + + AppointmentBlock updated = appointmentService.getAppointmentBlockByUuid("c0c579b0-8e59-401d-8a4a-976a0b183599"); + Assert.assertNotNull(updated); + Assert.assertEquals("c0c54sd0-8e59-401d-8a4a-976a0b183599", updated.getProvider().getUuid()); + + // make sure a time slot has been updated for the appointment block + List timeSlots = appointmentService.getTimeSlotsInAppointmentBlock(updated); + Assert.assertEquals(1, timeSlots.size()); + TimeSlot timeSlot = timeSlots.get(0); + Assert.assertNotNull(timeSlot); + Assert.assertEquals(updated.getStartDate(), timeSlot.getStartDate()); + Assert.assertEquals(updated.getEndDate(), timeSlot.getEndDate()); + } + + @Override + public String getURI() { + return AppointmentRestController.APPOINTMENT_SCHEDULING_REST_NAMESPACE + "/appointmentblockwithtimeslot"; + } +} diff --git a/omod/src/test/java/org/openmrs/module/appointmentscheduling/rest/resource/openmrs1_9/AppointmentBlockWithTimeSlotResource1_9Test.java b/omod/src/test/java/org/openmrs/module/appointmentscheduling/rest/resource/openmrs1_9/AppointmentBlockWithTimeSlotResource1_9Test.java index b0344dce..37295246 100644 --- a/omod/src/test/java/org/openmrs/module/appointmentscheduling/rest/resource/openmrs1_9/AppointmentBlockWithTimeSlotResource1_9Test.java +++ b/omod/src/test/java/org/openmrs/module/appointmentscheduling/rest/resource/openmrs1_9/AppointmentBlockWithTimeSlotResource1_9Test.java @@ -1,61 +1,61 @@ -package org.openmrs.module.appointmentscheduling.rest.resource.openmrs1_9; - -import org.junit.Before; -import org.openmrs.api.context.Context; -import org.openmrs.module.appointmentscheduling.AppointmentBlock; -import org.openmrs.module.appointmentscheduling.api.AppointmentService; -import org.openmrs.module.webservices.rest.web.resource.impl.BaseDelegatingResourceTest; - -public class AppointmentBlockWithTimeSlotResource1_9Test extends BaseDelegatingResourceTest { - - @Before - public void setup() throws Exception { - executeDataSet("standardWebAppointmentTestDataset.xml"); - } - - @Override - public AppointmentBlock newObject() { - return Context.getService(AppointmentService.class).getAppointmentBlockByUuid(getUuidProperty()); - } - - @Override - public void validateRefRepresentation() throws Exception { - super.validateRefRepresentation(); - assertPropEquals("voided", null); // voided parameter only included if voided - } - - @Override - public void validateDefaultRepresentation() throws Exception { - super.validateDefaultRepresentation(); - assertPropEquals("startDate", getObject().getStartDate()); - assertPropEquals("endDate", getObject().getEndDate()); - assertPropEquals("voided", getObject().isVoided()); - assertPropPresent("provider"); - assertPropPresent("location"); - assertPropPresent("types"); - assertPropNotPresent("auditInfo"); - } - - @Override - public void validateFullRepresentation() throws Exception { - super.validateFullRepresentation(); - assertPropEquals("startDate", getObject().getStartDate()); - assertPropEquals("endDate", getObject().getEndDate()); - assertPropEquals("voided", getObject().isVoided()); - assertPropPresent("provider"); - assertPropPresent("location"); - assertPropPresent("types"); - assertPropPresent("auditInfo"); - } - - @Override - public String getDisplayProperty() { - return "Mr. Horatio Test Hornblower Esq., Xanadu: 2005-01-03 00:00:00.0 - 2005-01-03 11:00:00.0"; - } - - @Override - public String getUuidProperty() { - return "759799ab-c9a5-435e-b671-77773ada7499"; - } - -} +package org.openmrs.module.appointmentscheduling.rest.resource.openmrs1_9; + +import org.junit.Before; +import org.openmrs.api.context.Context; +import org.openmrs.module.appointmentscheduling.AppointmentBlock; +import org.openmrs.module.appointmentscheduling.api.AppointmentService; +import org.openmrs.module.webservices.rest.web.resource.impl.BaseDelegatingResourceTest; + +public class AppointmentBlockWithTimeSlotResource1_9Test extends BaseDelegatingResourceTest { + + @Before + public void setup() throws Exception { + executeDataSet("standardWebAppointmentTestDataset.xml"); + } + + @Override + public AppointmentBlock newObject() { + return Context.getService(AppointmentService.class).getAppointmentBlockByUuid(getUuidProperty()); + } + + @Override + public void validateRefRepresentation() throws Exception { + super.validateRefRepresentation(); + assertPropEquals("voided", null); // voided parameter only included if voided + } + + @Override + public void validateDefaultRepresentation() throws Exception { + super.validateDefaultRepresentation(); + assertPropEquals("startDate", getObject().getStartDate()); + assertPropEquals("endDate", getObject().getEndDate()); + assertPropEquals("voided", getObject().isVoided()); + assertPropPresent("provider"); + assertPropPresent("location"); + assertPropPresent("types"); + assertPropNotPresent("auditInfo"); + } + + @Override + public void validateFullRepresentation() throws Exception { + super.validateFullRepresentation(); + assertPropEquals("startDate", getObject().getStartDate()); + assertPropEquals("endDate", getObject().getEndDate()); + assertPropEquals("voided", getObject().isVoided()); + assertPropPresent("provider"); + assertPropPresent("location"); + assertPropPresent("types"); + assertPropPresent("auditInfo"); + } + + @Override + public String getDisplayProperty() { + return "Mr. Horatio Test Hornblower Esq., Xanadu: 2005-01-03 00:00:00.0 - 2005-01-03 11:00:00.0"; + } + + @Override + public String getUuidProperty() { + return "759799ab-c9a5-435e-b671-77773ada7499"; + } + +}