Skip to content

Commit

Permalink
AM-159: Add domain object to capure an Appointment Request
Browse files Browse the repository at this point in the history
Added web services call for domain object; added min/max values to domain object
  • Loading branch information
mogoodrich committed Sep 17, 2014
1 parent 5522685 commit 297d0e0
Show file tree
Hide file tree
Showing 12 changed files with 587 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@

public class AppointmentRequest extends BaseOpenmrsData {

public enum TimeFrameUnits { DAYS, MONTHS, YEARS }
public enum TimeFrameUnits { DAYS, WEEKS, MONTHS, YEARS };

public enum AppointmentRequestStatus { PENDING, FULFILLED, CANCELLED }
public enum AppointmentRequestStatus { PENDING, FULFILLED, CANCELLED };

private Integer appointmentRequestId;

Expand All @@ -28,8 +28,15 @@ public enum AppointmentRequestStatus { PENDING, FULFILLED, CANCELLED }

private Date requestedOn;

// TODO
// TODO link to the existing appointment somehow?
private Integer minTimeFrameValue;

private TimeFrameUnits minTimeFrameUnits;

private Integer maxTimeFrameValue;

private TimeFrameUnits maxTimeFrameUnits;

// TODO Do we want tio link to the created appointment somehow?

@Override
public Integer getId() {
Expand Down Expand Up @@ -104,4 +111,36 @@ public Date getRequestedOn() {
public void setRequestedOn(Date requestedOn) {
this.requestedOn = requestedOn;
}

public Integer getMinTimeFrameValue() {
return minTimeFrameValue;
}

public void setMinTimeFrameValue(Integer minTimeFrameValue) {
this.minTimeFrameValue = minTimeFrameValue;
}

public TimeFrameUnits getMinTimeFrameUnits() {
return minTimeFrameUnits;
}

public void setMinTimeFrameUnits(TimeFrameUnits minTimeFrameUnits) {
this.minTimeFrameUnits = minTimeFrameUnits;
}

public Integer getMaxTimeFrameValue() {
return maxTimeFrameValue;
}

public void setMaxTimeFrameValue(Integer maxTimeFrameValue) {
this.maxTimeFrameValue = maxTimeFrameValue;
}

public TimeFrameUnits getMaxTimeFrameUnits() {
return maxTimeFrameUnits;
}

public void setMaxTimeFrameUnits(TimeFrameUnits maxTimeFrameUnits) {
this.maxTimeFrameUnits = maxTimeFrameUnits;
}
}
14 changes: 14 additions & 0 deletions api/src/main/resources/AppointmentRequest.hbm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,20 @@
</type>
</property>

<property name="minTimeFrameValue" type="int" column="min_time_frame_value" length="11"/>
<property name="minTimeFrameUnits" column="min_time_frame_units" length="255">
<type name="org.openmrs.util.HibernateEnumType">
<param name="enumClassName">org.openmrs.module.appointmentscheduling.AppointmentRequest$TimeFrameUnits</param>
</type>
</property>

<property name="maxTimeFrameValue" type="int" column="max_time_frame_value" length="11"/>
<property name="maxTimeFrameUnits" column="max_time_frame_units" length="255">
<type name="org.openmrs.util.HibernateEnumType">
<param name="enumClassName">org.openmrs.module.appointmentscheduling.AppointmentRequest$TimeFrameUnits</param>
</type>
</property>

<property name="notes" type="java.lang.String" column="notes" length="1024" />

<property name="uuid" type="java.lang.String" column="uuid" length="38" unique="true" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ public void getAppointmentRequest_shouldGetCorrectAppointmentRequest() throws Ex
assertEquals(AppointmentRequest.AppointmentRequestStatus.PENDING, appointmentRequest.getStatus());
assertEquals(providerService.getProvider(1), appointmentRequest.getRequestedBy());
assertEquals("ASAP", appointmentRequest.getNotes());
assertEquals(new Integer(0), appointmentRequest.getMinTimeFrameValue());
assertEquals(AppointmentRequest.TimeFrameUnits.DAYS, appointmentRequest.getMinTimeFrameUnits());
assertEquals(new Integer(7), appointmentRequest.getMaxTimeFrameValue());
assertEquals(AppointmentRequest.TimeFrameUnits.DAYS, appointmentRequest.getMaxTimeFrameUnits());

appointmentRequest = service.getAppointmentRequest(2);
assertNotNull(appointmentRequest);
Expand All @@ -72,6 +76,10 @@ public void getAppointmentRequest_shouldGetCorrectAppointmentRequest() throws Ex
assertEquals(service.getAppointmentType(2), appointmentRequest.getAppointmentType());
assertEquals(AppointmentRequest.AppointmentRequestStatus.FULFILLED, appointmentRequest.getStatus());
assertEquals(providerService.getProvider(2), appointmentRequest.getRequestedBy());
assertEquals(new Integer(6), appointmentRequest.getMinTimeFrameValue());
assertEquals(AppointmentRequest.TimeFrameUnits.WEEKS, appointmentRequest.getMinTimeFrameUnits());
assertEquals(new Integer(2), appointmentRequest.getMaxTimeFrameValue());
assertEquals(AppointmentRequest.TimeFrameUnits.MONTHS, appointmentRequest.getMaxTimeFrameUnits());
assertNull(appointmentRequest.getNotes());

}
Expand All @@ -98,6 +106,11 @@ public void saveAppointmentRequest_shouldSaveNewAppointmentRequest() throws Exce
appointmentRequest.setProvider(providerService.getProvider(1));
appointmentRequest.setRequestedBy(providerService.getProvider(1));
appointmentRequest.setRequestedOn(new Date());
appointmentRequest.setMinTimeFrameValue(1);
appointmentRequest.setMinTimeFrameUnits(AppointmentRequest.TimeFrameUnits.MONTHS);
appointmentRequest.setMaxTimeFrameValue(6);
appointmentRequest.setMaxTimeFrameUnits(AppointmentRequest.TimeFrameUnits.MONTHS);

appointmentRequest.setNotes("test");
appointmentRequest.setStatus(AppointmentRequest.AppointmentRequestStatus.PENDING);
service.saveAppointmentRequest(appointmentRequest);
Expand Down
6 changes: 3 additions & 3 deletions api/src/test/resources/standardAppointmentTestDataset.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<appointmentscheduling_appointment_type appointment_type_id="4" name="Hospitalization" description="Hospitalization Description" duration="10" creator="1" date_created="2005-01-01 00:00:00.0" retired="true" retire_reason="Some Retire Reason" uuid="759799ab-c9a5-435e-b671-77373ada74e6"/>

<appointmentscheduling_appointment_block appointment_block_id="1" start_date="2005-01-01 00:00:00.0" end_date="2005-01-01 11:00:00.0" provider_id="1" location_id="3" uuid="c0c579b0-8e59-401d-8a4a-976a0b183599" date_created="2005-01-01 00:00:00.0" date_changed="2005-01-01 00:00:00.0" date_voided="2005-01-01 00:00:00.0" voided="false" creator="1" changed_by="1"/>
<appointmentscheduling_appointment_block appointment_block_id="2" start_date="2005-01-02 00:00:00.0" end_date="2005-01-02 11:00:00.0" provider_id="1" location_id="1" uuid="759799ab-c9a5-435e-b671-77773ada99e9" date_created="2005-01-01 00:00:00.0" date_changed="2005-01-01 00:00:00.0" date_voided="2005-01-01 00:00:00.0" voided="false" void_reason="Some void reason" creator="1" voided_by="1"/>
<appointmentscheduling_appointment_block appointment_block_id="2" start_date="2005-01-02 00:00:00.0" end_date="2005-01-02 11:00:00.0" provider_id="1" location_id="1" uuid="759799ab-c9a5-435e-b671-77773ada99e9" date_created="2005-01-01 00:00:00.0" date_changed="2005-01-01 00:00:00.0" date_voided="2005-01-01 00:00:00.0" voided="false" creator="1" />
<appointmentscheduling_appointment_block appointment_block_id="3" start_date="2005-01-03 00:00:00.0" end_date="2005-01-03 11:00:00.0" provider_id="1" location_id="2" uuid="759799ab-c9a5-435e-b671-77773ada7499" date_created="2005-01-01 00:00:00.0" date_changed="2005-01-01 00:00:00.0" date_voided="2005-01-01 00:00:00.0" voided="true" void_reason="Some void reason" creator="1" changed_by="1" voided_by="1"/>
<appointmentscheduling_appointment_block appointment_block_id="4" start_date="2014-01-02 00:00:00.0" end_date="2014-01-02 12:00:00.0" provider_id="1" location_id="2" uuid="759799ab-c9a5-435e-b671-77773ada7490" date_created="2014-01-02 00:00:00.0" date_changed="2014-01-02 00:00:00.0" date_voided="2014-01-02 00:00:00.0" voided="false" creator="1" changed_by="1"/>
<appointmentscheduling_appointment_block appointment_block_id="5" start_date="2014-01-02 00:00:00.0" end_date="2014-01-02 12:00:00.0" location_id="3" uuid="759799ab-c9a5-435e-b671-77773ada7491" date_created="2014-01-02 00:00:00.0" date_changed="2014-01-02 00:00:00.0" date_voided="2014-01-02 00:00:00.0" voided="false" creator="1" changed_by="1"/>
Expand Down Expand Up @@ -60,8 +60,8 @@
<appointmentscheduling_appointment_status_history appointment_status_history_id="2" appointment_id="1" status="INCONSULTATION" start_date="2005-01-01 00:30:00.0" end_date="2005-01-01 02:00:00.0"/>
<appointmentscheduling_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"/>

<appointmentscheduling_appointment_request appointment_request_id="1" appointment_type_id="1" patient_id="2" provider_id="1" status="PENDING" requested_on="2014-01-01 00:00:00.0" requested_by="1" notes="ASAP" uuid="862c94f0-3dae-11e4-916c-0800200c9a66" date_created="2005-01-01 00:00:00.0" voided="false" creator="1"/>
<appointmentscheduling_appointment_request appointment_request_id="2" appointment_type_id="2" patient_id="6" provider_id="1" status="FULFILLED" requested_on="2014-01-02 00:00:00.0" requested_by="2" uuid="862c94f1-3dae-11e4-916c-0800200c9a66" date_created="2005-01-01 00:00:00.0" voided="false" creator="1"/>
<appointmentscheduling_appointment_request appointment_request_id="1" appointment_type_id="1" patient_id="2" provider_id="1" status="PENDING" requested_on="2014-01-01 00:00:00.0" requested_by="1" min_time_frame_value="0" min_time_frame_units="DAYS" max_time_frame_value="7" max_time_frame_units="DAYS" notes="ASAP" uuid="862c94f0-3dae-11e4-916c-0800200c9a66" date_created="2005-01-01 00:00:00.0" voided="false" creator="1"/>
<appointmentscheduling_appointment_request appointment_request_id="2" appointment_type_id="2" patient_id="6" provider_id="1" status="FULFILLED" requested_on="2014-01-02 00:00:00.0" requested_by="2" min_time_frame_value="6" min_time_frame_units="WEEKS" max_time_frame_value="2" max_time_frame_units="MONTHS" uuid="862c94f1-3dae-11e4-916c-0800200c9a66" date_created="2005-01-01 00:00:00.0" voided="false" creator="1"/>
<appointmentscheduling_appointment_request appointment_request_id="3" appointment_type_id="2" patient_id="6" provider_id="2" status="CANCELLED" requested_on="2014-01-03 00:00:00.0" requested_by="2" uuid="862c94f2-3dae-11e4-916c-0800200c9a66" date_created="2005-01-01 00:00:00.0" voided="true" creator="1"/>

<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
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
package org.openmrs.module.appointmentscheduling.rest.resource.openmrs1_9;

import org.openmrs.api.context.Context;
import org.openmrs.module.appointmentscheduling.AppointmentRequest;
import org.openmrs.module.appointmentscheduling.api.AppointmentService;
import org.openmrs.module.appointmentscheduling.rest.controller.AppointmentRestController;
import org.openmrs.module.webservices.rest.web.RequestContext;
import org.openmrs.module.webservices.rest.web.RestConstants;
import org.openmrs.module.webservices.rest.web.annotation.Resource;
import org.openmrs.module.webservices.rest.web.representation.DefaultRepresentation;
import org.openmrs.module.webservices.rest.web.representation.FullRepresentation;
import org.openmrs.module.webservices.rest.web.representation.Representation;
import org.openmrs.module.webservices.rest.web.resource.impl.DataDelegatingCrudResource;
import org.openmrs.module.webservices.rest.web.resource.impl.DelegatingResourceDescription;
import org.openmrs.module.webservices.rest.web.resource.impl.NeedsPaging;
import org.openmrs.module.webservices.rest.web.response.ResponseException;

@Resource(name = RestConstants.VERSION_1 + AppointmentRestController.APPOINTMENT_SCHEDULING_REST_NAMESPACE + "/appointmentrequest", supportedClass = AppointmentRequest.class, supportedOpenmrsVersions = "1.9.*")
public class AppointmentRequestResource1_9 extends DataDelegatingCrudResource<AppointmentRequest> {

@Override
public DelegatingResourceDescription getRepresentationDescription(Representation representation) {
if (representation instanceof DefaultRepresentation) {
DelegatingResourceDescription description = new DelegatingResourceDescription();
description.addProperty("uuid");
description.addProperty("display", findMethod("getDisplayString"));
description.addProperty("patient", Representation.DEFAULT);
description.addProperty("appointmentType", Representation.REF);
description.addProperty("provider", Representation.DEFAULT);
description.addProperty("requestedBy", Representation.DEFAULT);
description.addProperty("requestedOn");
description.addProperty("status");
description.addProperty("minTimeFrameValue");
description.addProperty("minTimeFrameUnits");
description.addProperty("maxTimeFrameValue");
description.addProperty("maxTimeFrameUnits");
description.addProperty("notes");
description.addProperty("voided");
description.addSelfLink();
description.addLink("full", ".?v=" + RestConstants.REPRESENTATION_FULL);
return description;
} else if (representation instanceof FullRepresentation) {
DelegatingResourceDescription description = new DelegatingResourceDescription();
description.addProperty("uuid");
description.addProperty("display", findMethod("getDisplayString"));
description.addProperty("patient", Representation.FULL);
description.addProperty("appointmentType", Representation.FULL);
description.addProperty("provider", Representation.FULL);
description.addProperty("requestedBy", Representation.FULL);
description.addProperty("requestedOn");
description.addProperty("status");
description.addProperty("minTimeFrameValue");
description.addProperty("minTimeFrameUnits");
description.addProperty("maxTimeFrameValue");
description.addProperty("maxTimeFrameUnits");
description.addProperty("notes");
description.addProperty("voided");
description.addProperty("auditInfo", findMethod("getAuditInfo"));
description.addSelfLink();
return description;
}

return null;
}

@Override
public DelegatingResourceDescription getCreatableProperties() {
DelegatingResourceDescription description = new DelegatingResourceDescription();
description.addRequiredProperty("patient");
description.addRequiredProperty("appointmentType");
description.addProperty("provider");
description.addProperty("requestedBy");
description.addRequiredProperty("requestedOn");
description.addRequiredProperty("status");
description.addProperty("minTimeFrameValue");
description.addProperty("minTimeFrameUnits");
description.addProperty("maxTimeFrameValue");
description.addProperty("maxTimeFrameUnits");
description.addProperty("notes");
return description;
}

@Override
public DelegatingResourceDescription getUpdatableProperties() {
DelegatingResourceDescription description = new DelegatingResourceDescription();
description.addRequiredProperty("patient");
description.addRequiredProperty("appointmentType");
description.addProperty("provider");
description.addProperty("requestedBy");
description.addRequiredProperty("requestedOn");
description.addRequiredProperty("status");
description.addProperty("minTimeFrameValue");
description.addProperty("minTimeFrameUnits");
description.addProperty("maxTimeFrameValue");
description.addProperty("maxTimeFrameUnits");
description.addProperty("notes");
return description;
}

@Override
public AppointmentRequest getByUniqueId(String uuid) {
return Context.getService(AppointmentService.class).getAppointmentRequestByUuid(uuid);
}

@Override
protected void delete(AppointmentRequest appointmentRequest, String reason, RequestContext requestContext) throws ResponseException {
if (appointmentRequest.isVoided()) {
return;
}
Context.getService(AppointmentService.class).voidAppointmentRequest(appointmentRequest, reason);
}

@Override
public AppointmentRequest newDelegate() {
return new AppointmentRequest();
}

@Override
public AppointmentRequest save(AppointmentRequest appointmentRequest) {
return Context.getService(AppointmentService.class).saveAppointmentRequest(appointmentRequest);
}

@Override
public void purge(AppointmentRequest appointmentRequest, RequestContext requestContext) throws ResponseException {
if (appointmentRequest == null) {
return;
}
Context.getService(AppointmentService.class).purgeAppointmentRequest(appointmentRequest);
}

@Override
protected NeedsPaging<AppointmentRequest> doGetAll(RequestContext context) {
return new NeedsPaging<AppointmentRequest>(Context.getService(AppointmentService.class).getAllAppointmentRequests(
context.getIncludeAll()), context);
}

public String getDisplayString(AppointmentRequest appointmentRequest) {
return appointmentRequest.getAppointmentType().getName() + " : " + appointmentRequest.getStatus();
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
package org.openmrs.module.appointmentscheduling.rest.resource.openmrs1_9;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.List;

import org.openmrs.Location;
import org.openmrs.Patient;
import org.openmrs.Provider;
Expand All @@ -30,6 +25,11 @@
import org.springframework.validation.BindException;
import org.springframework.validation.Errors;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.List;

import static org.openmrs.module.appointmentscheduling.Appointment.AppointmentStatus;
import static org.openmrs.module.appointmentscheduling.Appointment.AppointmentStatus.getAppointmentsStatusByType;
import static org.openmrs.module.appointmentscheduling.Appointment.AppointmentStatusType;
Expand Down Expand Up @@ -149,7 +149,7 @@ public void purge(Appointment appointment, RequestContext requestContext) throws
@Override
protected PageableResult doGetAll(RequestContext context) throws ResponseException {
AppointmentService service = Context.getService(AppointmentService.class);
return new NeedsPaging<Appointment>(service.getAllAppointments(), context);
return new NeedsPaging<Appointment>(service.getAllAppointments(context.getIncludeAll()), context);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public void shouldCreateNewAppointmentEvenIfTimeBlockFull() throws Exception {
Assert.assertEquals("SCHEDULED", PropertyUtils.getProperty(appt, "status.code"));
Assert.assertEquals("c0c579b0-8e59-401d-8a4a-976a0b183519",
PropertyUtils.getProperty(PropertyUtils.getProperty(appt, "appointmentType"), "uuid"));
Assert.assertEquals(getAllCount() + 1, appointmentService.getAllAppointments().size());
Assert.assertEquals(getAllCount() + 1, appointmentService.getAllAppointments(false).size());

}

Expand All @@ -55,6 +55,6 @@ public String getUuid() {

@Override
public long getAllCount() {
return 7;
return 6;
}
}
Loading

0 comments on commit 297d0e0

Please sign in to comment.