Skip to content

Commit

Permalink
Added Provider Default, Waiting Time, Status Buttons
Browse files Browse the repository at this point in the history
  • Loading branch information
yony258 committed Jan 7, 2013
1 parent f0624d8 commit b8b31e1
Show file tree
Hide file tree
Showing 13 changed files with 444 additions and 43 deletions.
Expand Up @@ -304,6 +304,7 @@ public interface AppointmentService extends OpenmrsService {
* @return all the appointments for the given patient id.
* @should return all of the appointments for the given patient.
*/
@Transactional(readOnly = true)
List<Appointment> getAppointmentsOfPatient(Patient patient);

/**
Expand All @@ -312,6 +313,7 @@ public interface AppointmentService extends OpenmrsService {
* @param visitId the visit id to search by.
* @return the appointment that is related to this visit, null if there isnt any.
*/
@Transactional(readOnly = true)
Appointment getAppointmentByVisit(Visit visit);

/*
Expand Down Expand Up @@ -402,6 +404,7 @@ public interface AppointmentService extends OpenmrsService {
* @param timeSlot the time slot to search by.
* @return the appointments in the given time slot.
*/
@Transactional(readOnly = true)
List<Appointment> getAppointmentsInTimeSlot(TimeSlot timeSlot);

/**
Expand Down Expand Up @@ -476,6 +479,7 @@ AppointmentStatusHistory saveAppointmentStatusHistory(AppointmentStatusHistory a
* @return List of TimeSlots that stands within the given constraints, null if illegal values
* (fromDate>toDate or null appointmentType)
*/
@Transactional(readOnly = true)
List<TimeSlot> getTimeSlotsByConstraints(AppointmentType appointmentType, Date fromDate, Date toDate, Provider provider,
Location location) throws APIException;

Expand All @@ -488,6 +492,7 @@ List<TimeSlot> getTimeSlotsByConstraints(AppointmentType appointmentType, Date f
* @param patient the patient.
* @return a list of strings where each string represents an identifier of the patient.
*/
@Transactional(readOnly = true)
List<String> getPatientIdentifiersRepresentation(Patient patient);

/**
Expand All @@ -497,6 +502,7 @@ List<TimeSlot> getTimeSlotsByConstraints(AppointmentType appointmentType, Date f
* @return The amount of minutes left in the given time slot. Returns null if the given time
* slot was null;
*/
@Transactional(readOnly = true)
Integer getTimeLeftInTimeSlot(TimeSlot timeSlot);

/**
Expand All @@ -508,6 +514,7 @@ List<TimeSlot> getTimeSlotsByConstraints(AppointmentType appointmentType, Date f
* @param descendants the result set which is being built recursively.
* @return A set that contains all of the descendants of the given location.
*/
@Transactional(readOnly = true)
Set<Location> getAllLocationDescendants(Location location, Set<Location> descendants);

/**
Expand All @@ -522,6 +529,26 @@ List<TimeSlot> getTimeSlotsByConstraints(AppointmentType appointmentType, Date f
* @param status - The appointment status
* @return a list of appointments that satisfy the given constraints
*/
@Transactional(readOnly = true)
List<Appointment> getAppointmentsByConstraints(Date fromDate, Date toDate, Location location, Provider provider,
AppointmentType type, String status) throws APIException;

/**
*
* Retrives the start date of the current status of a given appointment.
*
* @param appointment - The appointment.
* @return the start date of the current status of a given appointment.
*/
@Transactional(readOnly = true)
Date getAppointmentCurrentStatusStartDate(Appointment appointment);

/**
*
* Changes the given appointment status.
*
* @param appointment - The appointment
* @param newStatus - The new status
*/
void changeAppointmentStatus(Appointment appointment, String newStatus);
}
Expand Up @@ -13,12 +13,24 @@
*/
package org.openmrs.module.appointment.api.db;

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

import org.openmrs.module.appointment.AppointmentStatusHistory;
import org.openmrs.module.appointment.Appointment;
import org.openmrs.module.appointment.api.AppointmentService;
import org.springframework.transaction.annotation.Transactional;

/**
* Database methods for {@link AppointmentService}.
*/
public interface AppointmentStatusHistoryDAO extends SingleClassDAO {}
public interface AppointmentStatusHistoryDAO extends SingleClassDAO {

/**
*
* Retrives the start date of the current status of a given appointment.
*
* @param appointment - The appointment.
* @return the start date of the current status of a given appointment.
*/
@Transactional(readOnly = true)

This comment has been minimized.

Copy link
@dkayiwa

dkayiwa Jan 18, 2013

Member

Don't we put the transactional attribute at the service layer instead of hibernate layer?

public Date getStartDateOfCurrentStatus(Appointment appointment);
}
Expand Up @@ -13,12 +13,14 @@
*/
package org.openmrs.module.appointment.api.db.hibernate;

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

import org.hibernate.Criteria;
import org.hibernate.criterion.MatchMode;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;
import org.openmrs.module.appointment.Appointment;
import org.openmrs.module.appointment.AppointmentStatusHistory;
import org.openmrs.module.appointment.api.db.AppointmentStatusHistoryDAO;
import org.springframework.transaction.annotation.Transactional;
Expand All @@ -38,4 +40,15 @@ public List<AppointmentStatusHistory> getAll(String status) {
return criteria.list();
}

@Override
@Transactional(readOnly = true)

This comment has been minimized.

Copy link
@dkayiwa

dkayiwa Jan 18, 2013

Member

Don't we put the transactional attribute at the service layer instead of hibernate layer?

This comment has been minimized.

Copy link
@djazayeri

djazayeri Jan 18, 2013

Member

I've been pushing for us to start doing things the way it's done here. I.e. you put the transactional annotation in the concrete place that actually needs a transaction.

This comment has been minimized.

Copy link
@yony258

yony258 Jan 19, 2013

Author Member

so whats the verdict on this?

public Date getStartDateOfCurrentStatus(Appointment appointment) {
String query = "Select Max(endDate) from AppointmentStatusHistory where appointment=:appointment";
Date endDate = (Date) super.sessionFactory.getCurrentSession().createQuery(query).setParameter("appointment",
appointment).uniqueResult();
endDate = (endDate == null && appointment != null) ? appointment.getDateCreated() : endDate;

return endDate;
}

}
Expand Up @@ -423,6 +423,7 @@ public AppointmentStatusHistory saveAppointmentStatusHistory(AppointmentStatusHi
}

@Override
@Transactional(readOnly = true)
public Appointment getLastAppointment(Patient patient) {
return getAppointmentDAO().getLastAppointment(patient);
}
Expand Down Expand Up @@ -461,6 +462,7 @@ public List<TimeSlot> getTimeSlotsByConstraints(AppointmentType appointmentType,
}

@Override
@Transactional(readOnly = true)
public List<String> getPatientIdentifiersRepresentation(Patient patient) {
LinkedList<String> identifiers = new LinkedList<String>();

Expand All @@ -483,6 +485,7 @@ public List<String> getPatientIdentifiersRepresentation(Patient patient) {
}

@Override
@Transactional(readOnly = true)
public Integer getTimeLeftInTimeSlot(TimeSlot timeSlot) {
Integer timeLeft = null;

Expand All @@ -506,6 +509,7 @@ public Integer getTimeLeftInTimeSlot(TimeSlot timeSlot) {
}

@Override
@Transactional(readOnly = true)
public Set<Location> getAllLocationDescendants(Location location, Set<Location> descendants) {
if (descendants == null)
descendants = new HashSet<Location>();
Expand All @@ -521,6 +525,7 @@ public Set<Location> getAllLocationDescendants(Location location, Set<Location>
}

@Override
@Transactional(readOnly = true)
public List<Appointment> getAppointmentsByConstraints(Date fromDate, Date toDate, Location location, Provider provider,
AppointmentType type, String status) throws APIException {

Expand Down Expand Up @@ -548,4 +553,28 @@ public List<Appointment> getAppointmentsByConstraints(Date fromDate, Date toDate

}

@Override
@Transactional(readOnly = true)
public Date getAppointmentCurrentStatusStartDate(Appointment appointment) {
return appointmentStatusHistoryDAO.getStartDateOfCurrentStatus(appointment);
}

@Override
public void changeAppointmentStatus(Appointment appointment, String newStatus) {
//TODO change to use enum

This comment has been minimized.

Copy link
@dkayiwa

dkayiwa Jan 18, 2013

Member

Have you changed this to enum?

This comment has been minimized.

Copy link
@yony258

yony258 Jan 18, 2013

Author Member

Yes

if (appointment != null) {
AppointmentStatusHistory history = new AppointmentStatusHistory();
history.setAppointment(appointment);
history.setEndDate(new Date());
history.setStartDate(getAppointmentCurrentStatusStartDate(appointment));
history.setStatus(appointment.getStatus());

saveAppointmentStatusHistory(history);

appointment.setStatus(newStatus);
saveAppointment(appointment);
}

}

}
8 changes: 8 additions & 0 deletions api/src/main/resources/messages.properties
Expand Up @@ -125,7 +125,15 @@ ${project.parent.artifactId}.Appointment.list.label.betweenDates=Between Dates:
${project.parent.artifactId}.Appointment.list.label.clinician=Clinician:
${project.parent.artifactId}.Appointment.list.label.location=Location:
${project.parent.artifactId}.Appointment.list.button.applyFilters=Apply Filters
${project.parent.artifactId}.Appointment.list.button.startConsultation=Start Consultation
${project.parent.artifactId}.Appointment.list.button.endConsultation=End Consultation
${project.parent.artifactId}.Appointment.list.button.checkIn=Check-In
${project.parent.artifactId}.Appointment.list.button.missAppointment=Miss Appointment
${project.parent.artifactId}.Appointment.list.button.cancelAppointment=Cancel Appointment
${project.parent.artifactId}.Appointment.add=Schedule New Appointment
${project.parent.artifactId}.Appointment.minutes=Minutes
${project.parent.artifactId}.Appointment.hours=Hours
${project.parent.artifactId}.Appointment.days=Days

${project.parent.artifactId}.TimeSlot.emptyStartDate=Empty time slot start date
${project.parent.artifactId}.TimeSlot.emptyEndDate=Empty time slot end date
Expand Down
Expand Up @@ -15,11 +15,11 @@

import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertNotNull;
import static junit.framework.Assert.assertTrue;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Set;

import junit.framework.Assert;

Expand All @@ -34,7 +34,7 @@
import org.openmrs.test.Verifies;

/**
* Tests Appointment Status History methods in the {@link ${AppointmentService}}.
* Tests Appointment Status History methods in the {@link $ AppointmentService}}.
*/
public class AppointmentStatusHistoryServiceTest extends BaseModuleContextSensitiveTest {

Expand Down Expand Up @@ -128,4 +128,30 @@ public void saveAppointmentStatusHistory_shouldSaveEditedAppointmentStatusHistor
assertEquals(3, service.getAllAppointmentStatusHistories().size());
}

@Test
@Verifies(value = "Should get correct start date of current status", method = "getAppointmentCurrentStatusStartDate(Appointment) ")
public void getAppointmentCurrentStatusStartDate_shouldGetCorrectDate() throws ParseException {
Date startDate = service.getAppointmentCurrentStatusStartDate(null);
Assert.assertNull(startDate);

Appointment appointment = service.getAppointment(1);
assertNotNull(appointment);
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.S");
startDate = format.parse("2005-01-01 02:00:00.0");
assertEquals(startDate, service.getAppointmentCurrentStatusStartDate(appointment));
}

@Test
@Verifies(value = "Should change appointment status correctly", method = "changeAppointmentStatus(Appointment, String)")
public void changeAppointmentStatus_shouldChangeCorrectly() {
Appointment appointment = service.getAppointment(1);
assertNotNull(appointment);

service.changeAppointmentStatus(appointment, "Completed");

This comment has been minimized.

Copy link
@dkayiwa

dkayiwa Jan 18, 2013

Member

Did we change this to enum

This comment has been minimized.

Copy link
@yony258

yony258 Jan 18, 2013

Author Member

Yes

//Should add new history
assertEquals(4, service.getAllAppointmentStatusHistories().size());

//Should not add new appointment
assertEquals(4, service.getAllAppointments().size());
}
}
4 changes: 2 additions & 2 deletions api/src/test/resources/standardAppointmentTestDataset.xml
Expand Up @@ -36,8 +36,8 @@
<appointment appointment_id="3" time_slot_id="1" appointment_type_id="2" patient_id="2" status="FINISHED" uuid="c0c579b0-8e59-401d-8a4a-976a0b183603" date_created="2005-01-01 00:00:00.0" voided="true" creator="1" void_reason="some void reason"/>
<appointment appointment_id="4" time_slot_id="3" appointment_type_id="3" patient_id="1" status="SCHEDULED" uuid="c0c579b0-8e59-401d-8a4a-976a0b183604" date_created="2005-01-01 00:00:00.0" voided="false" creator="1"/>

<appointment_status_history appointment_status_history_id="1" appointment_id="1" status="Waiting" start_date="2005-01-01 00:00:00.0" end_date="2005-01-01 00:00:00.0"/>
<appointment_status_history appointment_status_history_id="2" appointment_id="1" status="In-Consultation" start_date="2005-01-01 00:00:00.0" end_date="2005-01-01 00:00:00.0"/>
<appointment_status_history appointment_status_history_id="1" appointment_id="1" status="Waiting" start_date="2005-01-01 00:00:00.0" end_date="2005-01-01 01:00:00.0"/>
<appointment_status_history appointment_status_history_id="2" appointment_id="1" status="In-Consultation" start_date="2005-01-01 01:00:00.0" end_date="2005-01-01 02:00:00.0"/>
<appointment_status_history appointment_status_history_id="3" appointment_id="2" status="Missed" start_date="2005-01-01 00:00:00.0" end_date="2005-01-01 00:00:00.0"/>

<location location_id="2" name="Xanadu" description="A metaphor for opulence, most famously in the English Romantic Samuel Taylor Coleridge&apos;s poem Kubla Khan." address1="800 Boylston Street" address2="" city_village="Boston" state_province="MA" postal_code="02115" country="USA" latitude="" longitude="" creator="1" date_created="2008-08-15 13:46:50.0" retired="false" uuid="9356400c-a5a2-4532-8f2b-2361b3446eb7"/>
Expand Down
@@ -0,0 +1,63 @@
/**
* The contents of this file are subject to the OpenMRS Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://license.openmrs.org
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
* License for the specific language governing rights and limitations
* under the License.
*
* Copyright (C) OpenMRS, LLC. All Rights Reserved.
*/
package org.openmrs.module.appointment.web;

import java.beans.PropertyEditorSupport;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.openmrs.api.context.Context;
import org.openmrs.module.appointment.Appointment;
import org.openmrs.module.appointment.api.AppointmentService;
import org.springframework.util.StringUtils;

public class AppointmentEditor extends PropertyEditorSupport {

private Log log = LogFactory.getLog(this.getClass());

public AppointmentEditor() {
}

/**
* @should set using id
* @should set using uuid
*/
public void setAsText(String text) throws IllegalArgumentException {
AppointmentService as = Context.getService(AppointmentService.class);
if (StringUtils.hasText(text)) {
try {
setValue(as.getAppointment(Integer.valueOf(text)));
}
catch (Exception ex) {
Appointment ts = as.getAppointmentByUuid(text);
setValue(ts);
if (ts == null) {
log.error("Error setting text: " + text, ex);
throw new IllegalArgumentException("Appointment not found: " + ex.getMessage());
}
}
} else {
setValue(null);
}
}

public String getAsText() {
Appointment t = (Appointment) getValue();
if (t == null) {
return "";
} else {
return t.getId().toString();
}
}
}
Expand Up @@ -40,7 +40,6 @@
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
Expand Down

0 comments on commit b8b31e1

Please sign in to comment.