Skip to content

Commit

Permalink
UHM-1050 Update service to get scheduled appointments to filter by se…
Browse files Browse the repository at this point in the history
…rvice type
  • Loading branch information
pamcdm committed Mar 14, 2014
1 parent 22a698c commit 7d9039a
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 62 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -719,17 +719,6 @@ public Map<Provider, Double> getAverageHistoryDurationByConditionsPerProvider(Da
@Transactional(readOnly = true)
List<Appointment> getScheduledAppointmentsForPatient(Patient patient);

/**
* 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
*
* @param appointmentBlock
* @return
*/
@Transactional(readOnly = true)
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@
*/
package org.openmrs.module.appointmentscheduling.api.db;

import java.util.Date;
import java.util.List;

import org.openmrs.Patient;
import org.openmrs.Provider;
import org.openmrs.Visit;
Expand All @@ -27,6 +24,9 @@
import org.openmrs.module.appointmentscheduling.TimeSlot;
import org.openmrs.module.appointmentscheduling.api.AppointmentService;

import java.util.Date;
import java.util.List;

/**
* Database methods for {@link AppointmentService}.
*/
Expand All @@ -47,7 +47,8 @@ List<Appointment> getAppointmentsByConstraints(Date fromDate, Date toDate, Provi

List<Appointment> getScheduledAppointmentsForPatient(Patient patient);

List<Appointment> getAppointmentsByAppointmentBlock(AppointmentBlock appointmentBlock);
List<Appointment> getAppointmentsByAppointmentBlockAndAppointmentType(AppointmentBlock appointmentBlock,
AppointmentType appointmentType);

/**
* Retrieve all appointments in a given time slot.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,13 @@ public List<Appointment> getScheduledAppointmentsForPatient(Patient patient) {
}

@Override
public List<Appointment> getAppointmentsByAppointmentBlock(AppointmentBlock appointmentBlock) {
public List<Appointment> getAppointmentsByAppointmentBlockAndAppointmentType(AppointmentBlock appointmentBlock,
AppointmentType appointmentType) {
Criteria criteria = sessionFactory.getCurrentSession().createCriteria(mappedClass);
criteria.createAlias("timeSlot", "time_slot");
criteria.add(Restrictions.eq("time_slot.appointmentBlock", appointmentBlock));
if (appointmentType != null)
criteria.add(Restrictions.eq("appointmentType", appointmentType));
// skip cancelled and missed appointment blocks
criteria.add(Restrictions.and(Restrictions.ne("status", CANCELLED), Restrictions.ne("status", MISSED)));
criteria.add(Restrictions.eq("voided", false));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,10 @@
*/
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;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
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.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;
Expand All @@ -46,6 +30,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;
Expand All @@ -57,6 +43,20 @@
import org.openmrs.validator.ValidateUtil;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Set;

/**
* It is a default implementation of {@link AppointmentService}.
*/
Expand Down Expand Up @@ -908,7 +908,8 @@ public List<ScheduledAppointmentBlock> getDailyAppointmentBlocks(Location locati

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

ScheduledAppointmentBlock scheduledAppointmentBlock = createScheduledAppointmentBlock(appointmentBlock);
ScheduledAppointmentBlock scheduledAppointmentBlock = createScheduledAppointmentBlock(appointmentBlock,
appointmentType);

if (!scheduledAppointmentBlock.getAppointments().isEmpty()) {
scheduledAppointmentBlockList.add(scheduledAppointmentBlock);
Expand All @@ -918,10 +919,10 @@ public List<ScheduledAppointmentBlock> getDailyAppointmentBlocks(Location locati
return scheduledAppointmentBlockList;
}

@Override
@Transactional(readOnly = true)
public ScheduledAppointmentBlock createScheduledAppointmentBlock(AppointmentBlock appointmentBlock) {
List<Appointment> appointmentList = getAppointmentDAO().getAppointmentsByAppointmentBlock(appointmentBlock);
private ScheduledAppointmentBlock createScheduledAppointmentBlock(AppointmentBlock appointmentBlock,
AppointmentType appointmentType) {
List<Appointment> appointmentList = getAppointmentDAO().getAppointmentsByAppointmentBlockAndAppointmentType(
appointmentBlock, appointmentType);
return new ScheduledAppointmentBlock(appointmentList, appointmentBlock);
}

Expand All @@ -948,8 +949,8 @@ 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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -423,25 +423,25 @@ public void shouldGetScheduledAppointmentsForPatientOrderedByStartData() {
assertEquals(new Integer(7), appointments.get(3).getId());
}

@Test
public void shouldCreateScheduledAppointmentBlock() throws Exception {
AppointmentBlock appointmentBlock = service.getAppointmentBlock(4);
ScheduledAppointmentBlock scheduledAppointmentBlock = service.createScheduledAppointmentBlock(appointmentBlock);
assertEquals(appointmentBlock, scheduledAppointmentBlock.getAppointmentBlock());
assertEquals(2, scheduledAppointmentBlock.getAppointments().size());
List<Appointment> appointmentList = scheduledAppointmentBlock.getAppointments();
Appointment appointment = appointmentList.get(0);
assertEquals(1, appointment.getPatient().getId().intValue());
assertEquals("Initial HIV Clinic Appointment", appointment.getAppointmentType().getName());
appointment = appointmentList.get(1);
assertEquals(6, appointment.getPatient().getId().intValue());
assertEquals("Initial HIV Clinic Appointment", appointment.getAppointmentType().getName());
}
// @Test
// public void shouldCreateScheduledAppointmentBlock() throws Exception {
//
// AppointmentBlock appointmentBlock = service.getAppointmentBlock(4);
//
// ScheduledAppointmentBlock scheduledAppointmentBlock = service.createScheduledAppointmentBlock(appointmentBlock, );
//
// assertEquals(appointmentBlock, scheduledAppointmentBlock.getAppointmentBlock());
// assertEquals(2, scheduledAppointmentBlock.getAppointments().size());
//
// List<Appointment> appointmentList = scheduledAppointmentBlock.getAppointments();
// Appointment appointment = appointmentList.get(0);
// assertEquals(1, appointment.getPatient().getId().intValue());
// assertEquals("Initial HIV Clinic Appointment", appointment.getAppointmentType().getName());
//
// appointment = appointmentList.get(1);
// assertEquals(6, appointment.getPatient().getId().intValue());
// assertEquals("Initial HIV Clinic Appointment", appointment.getAppointmentType().getName());
// }

@Test
public void shouldGetDailyAppointments() throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ private Date getDate(RequestContext context) {
}

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

private List<SimpleObject> convertToSimpleObjectList(List<ScheduledAppointmentBlock> dailyAppointmentBlocks) {
Expand Down

0 comments on commit 7d9039a

Please sign in to comment.