Skip to content

Commit

Permalink
UHM-1050 Addition of parameter appointment type to scheduled appointm…
Browse files Browse the repository at this point in the history
…ent blocks resource
  • Loading branch information
pamcdm committed Mar 13, 2014
1 parent 19af3ea commit 22a698c
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -737,10 +737,11 @@ public Map<Provider, Double> getAverageHistoryDurationByConditionsPerProvider(Da
*
* @param location
* @param date
* @param appointmentType
* @return
*/
@Transactional(readOnly = true)
List<ScheduledAppointmentBlock> getDailyAppointmentBlocks(Location location, Date date);
List<ScheduledAppointmentBlock> getDailyAppointmentBlocks(Location location, Date date, AppointmentType appointmentType);

/**
* Calculate the unallocated minutes in the time slot. As follows: Number minutes in time slot
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -900,12 +900,13 @@ public Map<AppointmentType, Integer> getAppointmentTypeDistribution(Date fromDat

@Override
@Transactional(readOnly = true)
public List<ScheduledAppointmentBlock> getDailyAppointmentBlocks(Location location, Date date) {
public List<ScheduledAppointmentBlock> getDailyAppointmentBlocks(Location location, Date date,
AppointmentType appointmentType) {
AppointmentDAO appointmentDao = getAppointmentDAO();

List<ScheduledAppointmentBlock> scheduledAppointmentBlockList = new ArrayList<ScheduledAppointmentBlock>();

for (AppointmentBlock appointmentBlock : getAppointmentBlockList(location, date)) {
for (AppointmentBlock appointmentBlock : getAppointmentBlockList(location, date, appointmentType)) {

ScheduledAppointmentBlock scheduledAppointmentBlock = createScheduledAppointmentBlock(appointmentBlock);

Expand Down Expand Up @@ -962,9 +963,9 @@ public Appointment bookAppointment(Appointment appointment, Boolean allowOverboo
return Context.getService(AppointmentService.class).saveAppointment(appointment);
}

private List<AppointmentBlock> getAppointmentBlockList(Location location, Date date) {
private List<AppointmentBlock> getAppointmentBlockList(Location location, Date date, AppointmentType appointmentType) {
return getAppointmentBlocks(setDateToStartOfDay(date), setDateToEndOfDay(date), location.getId().toString(), null,
null);
appointmentType);
}

private Date setDateToEndOfDay(Date date) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -449,8 +449,10 @@ public void shouldGetDailyAppointments() throws Exception {
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.S");
Date date = format.parse("2014-01-02 10:00:00.0");
Provider provider = Context.getProviderService().getProvider(1);
AppointmentType appointmentType = Context.getService(AppointmentService.class).getAppointmentType(1);

List<ScheduledAppointmentBlock> scheduledAppointmentBlockList = service.getDailyAppointmentBlocks(location, date);
List<ScheduledAppointmentBlock> scheduledAppointmentBlockList = service.getDailyAppointmentBlocks(location, date,
appointmentType);

assertNotNull(scheduledAppointmentBlockList);
assertEquals(1, scheduledAppointmentBlockList.size());
Expand All @@ -477,26 +479,30 @@ public void shouldNotReturnDailyAppointmentsWhenThereIsNoScheduledAppointments()
Location location = Context.getLocationService().getLocation(1);
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.S");
Date date = format.parse("2005-01-02 10:00:00.0");
AppointmentType appointmentType = null;

List<ScheduledAppointmentBlock> scheduledAppointmentBlockList = service.getDailyAppointmentBlocks(location, date);
List<ScheduledAppointmentBlock> scheduledAppointmentBlockList = service.getDailyAppointmentBlocks(location, date,
appointmentType);
assertEquals(0, scheduledAppointmentBlockList.size());
}

@Test
public void shouldReturnDailyAppointmentsWithoutProviderAssigned() throws Exception {
Location location = Context.getLocationService().getLocation(3);
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.S");
Date date = format.parse("2014-01-02 10:00:00.0");

List<ScheduledAppointmentBlock> scheduledAppointmentBlockList = service.getDailyAppointmentBlocks(location, date);
assertEquals(1, scheduledAppointmentBlockList.size());

AppointmentBlock appointmentBlock = scheduledAppointmentBlockList.get(0).getAppointmentBlock();
assertEquals(null, appointmentBlock.getProvider());

List<Appointment> appointmentList = scheduledAppointmentBlockList.get(0).getAppointments();
assertEquals(1, appointmentList.size());
}

@Test
public void shouldReturnDailyAppointmentsWithoutProviderAssigned() throws Exception {
Location location = Context.getLocationService().getLocation(3);
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.S");
Date date = format.parse("2014-01-02 10:00:00.0");
AppointmentType appointmentType = null;

List<ScheduledAppointmentBlock> scheduledAppointmentBlockList = service.getDailyAppointmentBlocks(location, date,
appointmentType);
assertEquals(1, scheduledAppointmentBlockList.size());

AppointmentBlock appointmentBlock = scheduledAppointmentBlockList.get(0).getAppointmentBlock();
assertEquals(null, appointmentBlock.getProvider());

List<Appointment> appointmentList = scheduledAppointmentBlockList.get(0).getAppointments();
assertEquals(1, appointmentList.size());
}

@Test
@Verifies(value = "retrieve all appointments scheduled in a given time slot", method = "getAppointmentsInTimeSlot(TimeSlot)")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import org.apache.commons.beanutils.PropertyUtils;
import org.openmrs.Location;
import org.openmrs.api.context.Context;
import org.openmrs.module.appointmentscheduling.AppointmentType;
import org.openmrs.module.appointmentscheduling.ScheduledAppointmentBlock;
import org.openmrs.module.appointmentscheduling.api.AppointmentService;
import org.openmrs.module.appointmentscheduling.rest.controller.AppointmentRestController;
Expand Down Expand Up @@ -30,17 +31,20 @@ public SimpleObject search(RequestContext context) throws ResponseException {

Date date = getDate(context);
Location location = getLocation(context);
AppointmentType appointmentType = getAppointmentType(context);

List<ScheduledAppointmentBlock> dailyAppointmentBlocks = getScheduledAppointmentBlocks(date, location);
List<ScheduledAppointmentBlock> dailyAppointmentBlocks = getScheduledAppointmentBlocks(date, location,
appointmentType);

SimpleObject result = new SimpleObject();
result.add("results", convertToSimpleObjectList(dailyAppointmentBlocks));

return result;
}

private List<ScheduledAppointmentBlock> getScheduledAppointmentBlocks(Date startDate, Location location) {
return Context.getService(AppointmentService.class).getDailyAppointmentBlocks(location, startDate);
private List<ScheduledAppointmentBlock> getScheduledAppointmentBlocks(Date startDate, Location location,
AppointmentType appointmentType) {
return Context.getService(AppointmentService.class).getDailyAppointmentBlocks(location, startDate, appointmentType);
}

private Location getLocation(RequestContext context) {
Expand All @@ -53,6 +57,11 @@ private Date getDate(RequestContext context) {
.convert(context.getParameter("date"), Date.class) : null;
}

private AppointmentType getAppointmentType(RequestContext context) {
return context.getParameter("serviceType") != null ? Context.getService(AppointmentService.class)
.getAppointmentTypeByUuid(context.getParameter("serviceType")) : null;
}

private List<SimpleObject> convertToSimpleObjectList(List<ScheduledAppointmentBlock> dailyAppointmentBlocks) {
List<SimpleObject> simpleObjects = new ArrayList<SimpleObject>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public void shouldSearchForScheduledAppointmentBlock() {
RequestContext context = Mockito.mock(RequestContext.class);
when(context.getParameter("date")).thenReturn("2005-01-03 00:00:00.0");
when(context.getParameter("location")).thenReturn("9356400c-a5a2-4532-8f2b-2361b3446eb7");
when(context.getParameter("appointmentType")).thenReturn("759799ab-c9a5-435e-b671-77773ada74e6");

SimpleObject search = scheduledAppointmentBlockResource1_9.search(context);

Expand Down

0 comments on commit 22a698c

Please sign in to comment.