Skip to content

Commit

Permalink
fixing formatting files
Browse files Browse the repository at this point in the history
  • Loading branch information
mario-areias committed Mar 31, 2014
1 parent a5303e8 commit e50a6ab
Show file tree
Hide file tree
Showing 6 changed files with 304 additions and 304 deletions.
Original file line number Diff line number Diff line change
@@ -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);
}

}
Original file line number Diff line number Diff line change
@@ -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);
}

}
Original file line number Diff line number Diff line change
@@ -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<TimeSlot> 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<TimeSlot> 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<TimeSlot> 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<TimeSlot> timeSlots) {

for (TimeSlot timeSlot : timeSlots) {
Context.getService(AppointmentService.class).voidTimeSlot(timeSlot,
"appointment block has more than one time slot");
}

}

}
Original file line number Diff line number Diff line change
@@ -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;
}
}
Loading

0 comments on commit e50a6ab

Please sign in to comment.