forked from openmrs/openmrs-module-appointmentscheduling
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
UHM-974 Update getTimeSlotsByConstraints to return list sorted by sta…
…rdate
- Loading branch information
pamcdm
committed
Jan 6, 2014
1 parent
c8bf52a
commit 13e796f
Showing
3 changed files
with
503 additions
and
505 deletions.
There are no files selected for viewing
143 changes: 70 additions & 73 deletions
143
.../java/org/openmrs/module/appointmentscheduling/api/db/hibernate/HibernateTimeSlotDAO.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,73 +1,70 @@ | ||
package org.openmrs.module.appointmentscheduling.api.db.hibernate; | ||
|
||
import java.util.Date; | ||
import java.util.List; | ||
import java.util.Set; | ||
import java.util.Vector; | ||
|
||
import org.hibernate.Query; | ||
import org.hibernate.criterion.Restrictions; | ||
import org.openmrs.Location; | ||
import org.openmrs.Provider; | ||
import org.openmrs.api.APIException; | ||
import org.openmrs.api.context.Context; | ||
import org.openmrs.module.appointmentscheduling.Appointment; | ||
import org.openmrs.module.appointmentscheduling.AppointmentBlock; | ||
import org.openmrs.module.appointmentscheduling.AppointmentType; | ||
import org.openmrs.module.appointmentscheduling.TimeSlot; | ||
import org.openmrs.module.appointmentscheduling.api.db.TimeSlotDAO; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
public class HibernateTimeSlotDAO extends HibernateSingleClassDAO implements TimeSlotDAO { | ||
|
||
public HibernateTimeSlotDAO() { | ||
super(TimeSlot.class); | ||
} | ||
|
||
@Override | ||
public List<Appointment> getAppointmentsInTimeSlot(TimeSlot timeSlot) { | ||
return super.sessionFactory.getCurrentSession().createCriteria(Appointment.class) | ||
.add(Restrictions.eq("timeSlot", timeSlot)).list(); | ||
} | ||
|
||
@Override | ||
@Transactional(readOnly = true) | ||
public List<TimeSlot> getTimeSlotsByConstraints(AppointmentType appointmentType, Date fromDate, Date toDate, | ||
Provider provider) throws APIException { | ||
if (appointmentType == null) | ||
throw new APIException("Appointment Type can not be null."); | ||
else if (fromDate != null && toDate != null && !fromDate.before(toDate)) | ||
throw new APIException("fromDate can not be later than toDate"); | ||
else { | ||
Date startDate = (fromDate == null) ? new Date() : fromDate; | ||
|
||
String stringQuery = "SELECT timeSlot FROM TimeSlot AS timeSlot WHERE timeSlot.appointmentBlock IN(" | ||
+ " FROM AppointmentBlock WHERE :appointmentType IN elements(types)) AND voided = 0 AND endDate > :startDate"; | ||
|
||
if (toDate != null) | ||
stringQuery += " AND endDate <= :endDate"; | ||
if (provider != null) | ||
stringQuery += " AND timeSlot.appointmentBlock.provider = :provider"; | ||
|
||
Query query = super.sessionFactory.getCurrentSession().createQuery(stringQuery) | ||
.setParameter("appointmentType", appointmentType).setParameter("startDate", startDate); | ||
|
||
if (toDate != null) | ||
query.setParameter("endDate", toDate); | ||
if (provider != null) | ||
query.setParameter("provider", provider); | ||
|
||
return query.list(); | ||
} | ||
} | ||
|
||
@Override | ||
@Transactional(readOnly = true) | ||
public List<TimeSlot> getTimeSlotsByAppointmentBlock(AppointmentBlock appointmentBlock) { | ||
if (appointmentBlock == null) | ||
return new Vector<TimeSlot>(); | ||
return super.sessionFactory.getCurrentSession().createCriteria(TimeSlot.class) | ||
.add(Restrictions.eq("appointmentBlock", appointmentBlock)).list(); | ||
} | ||
|
||
} | ||
package org.openmrs.module.appointmentscheduling.api.db.hibernate; | ||
|
||
import org.hibernate.Query; | ||
import org.hibernate.criterion.Restrictions; | ||
import org.openmrs.Provider; | ||
import org.openmrs.api.APIException; | ||
import org.openmrs.module.appointmentscheduling.Appointment; | ||
import org.openmrs.module.appointmentscheduling.AppointmentBlock; | ||
import org.openmrs.module.appointmentscheduling.AppointmentType; | ||
import org.openmrs.module.appointmentscheduling.TimeSlot; | ||
import org.openmrs.module.appointmentscheduling.api.db.TimeSlotDAO; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import java.util.Date; | ||
import java.util.List; | ||
import java.util.Vector; | ||
|
||
public class HibernateTimeSlotDAO extends HibernateSingleClassDAO implements TimeSlotDAO { | ||
|
||
public HibernateTimeSlotDAO() { | ||
super(TimeSlot.class); | ||
} | ||
|
||
@Override | ||
public List<Appointment> getAppointmentsInTimeSlot(TimeSlot timeSlot) { | ||
return super.sessionFactory.getCurrentSession().createCriteria(Appointment.class) | ||
.add(Restrictions.eq("timeSlot", timeSlot)).list(); | ||
} | ||
|
||
@Override | ||
@Transactional(readOnly = true) | ||
public List<TimeSlot> getTimeSlotsByConstraints(AppointmentType appointmentType, Date fromDate, Date toDate, | ||
Provider provider) throws APIException { | ||
if (appointmentType == null) | ||
throw new APIException("Appointment Type can not be null."); | ||
else if (fromDate != null && toDate != null && !fromDate.before(toDate)) | ||
throw new APIException("fromDate can not be later than toDate"); | ||
else { | ||
Date startDate = (fromDate == null) ? new Date() : fromDate; | ||
|
||
String stringQuery = "SELECT timeSlot FROM TimeSlot AS timeSlot WHERE timeSlot.appointmentBlock IN(" | ||
+ " FROM AppointmentBlock WHERE :appointmentType IN elements(types)) AND voided = 0 AND endDate > :startDate ORDER BY startDate"; | ||
|
||
if (toDate != null) | ||
stringQuery += " AND endDate <= :endDate"; | ||
if (provider != null) | ||
stringQuery += " AND timeSlot.appointmentBlock.provider = :provider"; | ||
|
||
Query query = super.sessionFactory.getCurrentSession().createQuery(stringQuery) | ||
.setParameter("appointmentType", appointmentType).setParameter("startDate", startDate); | ||
|
||
if (toDate != null) | ||
query.setParameter("endDate", toDate); | ||
if (provider != null) | ||
query.setParameter("provider", provider); | ||
|
||
return query.list(); | ||
} | ||
} | ||
|
||
@Override | ||
@Transactional(readOnly = true) | ||
public List<TimeSlot> getTimeSlotsByAppointmentBlock(AppointmentBlock appointmentBlock) { | ||
if (appointmentBlock == null) | ||
return new Vector<TimeSlot>(); | ||
return super.sessionFactory.getCurrentSession().createCriteria(TimeSlot.class) | ||
.add(Restrictions.eq("appointmentBlock", appointmentBlock)).list(); | ||
} | ||
|
||
} |
Oops, something went wrong.