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 liquibase script, refactored TimeFrameUnits
  • Loading branch information
mogoodrich committed Sep 18, 2014
1 parent 297d0e0 commit 5d424db
Show file tree
Hide file tree
Showing 9 changed files with 181 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@

public class AppointmentRequest extends BaseOpenmrsData {

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

public enum AppointmentRequestStatus { PENDING, FULFILLED, CANCELLED };

private Integer appointmentRequestId;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package org.openmrs.module.appointmentscheduling;

public enum TimeFrameUnits {
DAYS, WEEKS, MONTHS, YEARS
}
Original file line number Diff line number Diff line change
Expand Up @@ -578,7 +578,6 @@ public AppointmentRequest getAppointmentRequestByUuid(String uuid) {
@Override
@Transactional
public AppointmentRequest saveAppointmentRequest(AppointmentRequest appointmentRequest) throws APIException {
ValidateUtil.validate(appointmentRequest);
return appointmentRequestDAO.saveOrUpdate(appointmentRequest);
}

Expand Down
4 changes: 2 additions & 2 deletions api/src/main/resources/AppointmentRequest.hbm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@
<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>
<param name="enumClassName">org.openmrs.module.appointmentscheduling.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>
<param name="enumClassName">org.openmrs.module.appointmentscheduling.TimeFrameUnits</param>
</type>
</property>

Expand Down
94 changes: 94 additions & 0 deletions api/src/main/resources/liquibase.xml
Original file line number Diff line number Diff line change
Expand Up @@ -306,4 +306,98 @@
</addColumn>
</changeSet>

<changeSet id="20140917-1-appointmentmentscheduling_appointment_request" author="mogoodrich">
<preConditions onFail="MARK_RAN">
<not><tableExists tableName="appointmentscheduling_appointment_request"/></not>
</preConditions>
<comment>
Create the appointment request table
</comment>

<createTable tableName="appointmentscheduling_appointment_request">
<column name="appointment_request_id" type="int" autoIncrement="true">
<constraints primaryKey="true" nullable="false"/>
</column>

<column name="patient_id" type="int">
<constraints nullable="false"/>
</column>

<column name="appointment_type_id" type="int">
<constraints nullable="false"/>
</column>

<column name="status" type="varchar(255)">
<constraints nullable="false"/>
</column>

<column name="provider_id" type="int" />
<column name="requested_by" type="int" />

<column name="requested_on" type="datetime">
<constraints nullable="false"/>
</column>

<column name="min_time_frame_value" type="int" />
<column name="min_time_frame_units" type="varchar(255)" />

<column name="max_time_frame_value" type="int" />
<column name="max_time_frame_units" type="varchar(255)" />

<column name="notes" type="varchar(1024)" />

<column name="uuid" type="char(38)">
<constraints nullable="false" unique="true"/>
</column>

<column name="creator" type="int" >
<constraints nullable="false" />
</column>

<column name="date_created" type="datetime" >
<constraints nullable="false"/>
</column>

<column name="changed_by" type="int" />
<column name="date_changed" type="datetime" />

<column name="voided" type="tinyint" defaultValueNumeric="0">
<constraints nullable="false"/>
</column>

<column name="voided_by" type="int" />
<column name="date_voided" type="datetime" />
<column name="void_reason" type="varchar(255)" defaultValue="null"/>

</createTable>

<addForeignKeyConstraint constraintName="appointment_request_creator"
baseTableName="appointmentscheduling_appointment_request" baseColumnNames="creator"
referencedTableName="users" referencedColumnNames="user_id"/>

<addForeignKeyConstraint constraintName="appointment_request_changed_by"
baseTableName="appointmentscheduling_appointment_request" baseColumnNames="changed_by"
referencedTableName="users" referencedColumnNames="user_id"/>

<addForeignKeyConstraint constraintName="appointment_request_voided_by"
baseTableName="appointmentscheduling_appointment_request" baseColumnNames="voided_by"
referencedTableName="users" referencedColumnNames="user_id"/>

<addForeignKeyConstraint constraintName="appointment_request_appointment_type_id"
baseTableName="appointmentscheduling_appointment_request" baseColumnNames="appointment_type_id"
referencedTableName="appointmentscheduling_appointment_type" referencedColumnNames="appointment_type_id"/>

<addForeignKeyConstraint constraintName="appointment_request_patient_id"
baseTableName="appointmentscheduling_appointment_request" baseColumnNames="patient_id"
referencedTableName="patient" referencedColumnNames="patient_id"/>

<addForeignKeyConstraint constraintName="appointment_request_provider_id"
baseTableName="appointmentscheduling_appointment_request" baseColumnNames="provider_id"
referencedTableName="provider" referencedColumnNames="provider_id"/>

<addForeignKeyConstraint constraintName="appointment_request_requested_by"
baseTableName="appointmentscheduling_appointment_request" baseColumnNames="requested_by"
referencedTableName="provider" referencedColumnNames="provider_id"/>
</changeSet>

</databaseChangeLog>
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.openmrs.api.PatientService;
import org.openmrs.api.ProviderService;
import org.openmrs.module.appointmentscheduling.AppointmentRequest;
import org.openmrs.module.appointmentscheduling.TimeFrameUnits;
import org.openmrs.test.BaseModuleContextSensitiveTest;
import org.openmrs.test.Verifies;
import org.springframework.beans.factory.annotation.Autowired;
Expand Down Expand Up @@ -64,9 +65,9 @@ public void getAppointmentRequest_shouldGetCorrectAppointmentRequest() throws Ex
assertEquals(providerService.getProvider(1), appointmentRequest.getRequestedBy());
assertEquals("ASAP", appointmentRequest.getNotes());
assertEquals(new Integer(0), appointmentRequest.getMinTimeFrameValue());
assertEquals(AppointmentRequest.TimeFrameUnits.DAYS, appointmentRequest.getMinTimeFrameUnits());
assertEquals(TimeFrameUnits.DAYS, appointmentRequest.getMinTimeFrameUnits());
assertEquals(new Integer(7), appointmentRequest.getMaxTimeFrameValue());
assertEquals(AppointmentRequest.TimeFrameUnits.DAYS, appointmentRequest.getMaxTimeFrameUnits());
assertEquals(TimeFrameUnits.DAYS, appointmentRequest.getMaxTimeFrameUnits());

appointmentRequest = service.getAppointmentRequest(2);
assertNotNull(appointmentRequest);
Expand All @@ -77,9 +78,9 @@ public void getAppointmentRequest_shouldGetCorrectAppointmentRequest() throws Ex
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(TimeFrameUnits.WEEKS, appointmentRequest.getMinTimeFrameUnits());
assertEquals(new Integer(2), appointmentRequest.getMaxTimeFrameValue());
assertEquals(AppointmentRequest.TimeFrameUnits.MONTHS, appointmentRequest.getMaxTimeFrameUnits());
assertEquals(TimeFrameUnits.MONTHS, appointmentRequest.getMaxTimeFrameUnits());
assertNull(appointmentRequest.getNotes());

}
Expand Down Expand Up @@ -107,9 +108,9 @@ public void saveAppointmentRequest_shouldSaveNewAppointmentRequest() throws Exce
appointmentRequest.setRequestedBy(providerService.getProvider(1));
appointmentRequest.setRequestedOn(new Date());
appointmentRequest.setMinTimeFrameValue(1);
appointmentRequest.setMinTimeFrameUnits(AppointmentRequest.TimeFrameUnits.MONTHS);
appointmentRequest.setMinTimeFrameUnits(TimeFrameUnits.MONTHS);
appointmentRequest.setMaxTimeFrameValue(6);
appointmentRequest.setMaxTimeFrameUnits(AppointmentRequest.TimeFrameUnits.MONTHS);
appointmentRequest.setMaxTimeFrameUnits(TimeFrameUnits.MONTHS);

appointmentRequest.setNotes("test");
appointmentRequest.setStatus(AppointmentRequest.AppointmentRequestStatus.PENDING);
Expand All @@ -134,6 +135,7 @@ public void saveAppointmentRequest_shouldSaveNewAppointmentRequestWithMinimalPar
service.saveAppointmentRequest(appointmentRequest);

appointmentRequest = service.getAppointmentRequest(4);
assertEquals(AppointmentRequest.AppointmentRequestStatus.PENDING, appointmentRequest.getStatus());
assertNotNull(appointmentRequest);

//Should create a new appointment request row
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package org.openmrs.module.appointmentscheduling.rest.resource.openmrs1_9;

import org.openmrs.module.appointmentscheduling.AppointmentRequest;
import org.openmrs.module.appointmentscheduling.rest.controller.AppointmentRestController;
import org.openmrs.module.webservices.rest.SimpleObject;
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.resource.api.Listable;
import org.openmrs.module.webservices.rest.web.resource.api.Searchable;
import org.openmrs.module.webservices.rest.web.response.ResponseException;

@Resource(name = RestConstants.VERSION_1 + AppointmentRestController.APPOINTMENT_SCHEDULING_REST_NAMESPACE
+ "/appointmenttrequeststatus", supportedClass = AppointmentRequest.AppointmentRequestStatus.class, supportedOpenmrsVersions = "1.9.*")
public class AppointmentRequestStatusResource1_9 implements Listable, Searchable {

@Override
public SimpleObject getAll(RequestContext requestContext) throws ResponseException {
AppointmentRequest.AppointmentRequestStatus[] appointmentRequestStatuses = AppointmentRequest.AppointmentRequestStatus.values();
SimpleObject simpleObject = new SimpleObject().add("results", appointmentRequestStatuses);
return simpleObject;
}

@Override
public String getUri(Object o) {
return RestConstants.URI_PREFIX + "/appointmentscheduling/appointmentrequeststatus/"
+ ((AppointmentRequest.AppointmentRequestStatus) o);
}

@Override
public SimpleObject search(RequestContext requestContext) throws ResponseException {
return null;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import org.openmrs.module.webservices.rest.web.response.ResponseException;

@Resource(name = RestConstants.VERSION_1 + AppointmentRestController.APPOINTMENT_SCHEDULING_REST_NAMESPACE
+ "/appointmentstatustype", supportedClass = AppointmentStatusTypeResource1_9.class, supportedOpenmrsVersions = "1.9.*")
+ "/appointmentstatustype", supportedClass = Appointment.AppointmentStatusType.class, supportedOpenmrsVersions = "1.9.*")
public class AppointmentStatusTypeResource1_9 implements Listable, Searchable {

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package org.openmrs.module.appointmentscheduling.rest.resource.openmrs1_9;

import org.openmrs.module.appointmentscheduling.AppointmentRequest;
import org.openmrs.module.appointmentscheduling.TimeFrameUnits;
import org.openmrs.module.appointmentscheduling.rest.controller.AppointmentRestController;
import org.openmrs.module.webservices.rest.SimpleObject;
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.resource.api.Listable;
import org.openmrs.module.webservices.rest.web.resource.api.Searchable;
import org.openmrs.module.webservices.rest.web.response.ResponseException;

@Resource(name = RestConstants.VERSION_1 + AppointmentRestController.APPOINTMENT_SCHEDULING_REST_NAMESPACE
+ "/timeframeunits", supportedClass = TimeFrameUnits.class, supportedOpenmrsVersions = "1.9.*")
public class TimeFrameUnitsResource1_9 implements Listable, Searchable {

@Override
public SimpleObject getAll(RequestContext requestContext) throws ResponseException {
TimeFrameUnits[] timeFrameUnits = TimeFrameUnits.values();
SimpleObject simpleObject = new SimpleObject().add("results", timeFrameUnits);
return simpleObject;
}

@Override
public String getUri(Object o) {
return RestConstants.URI_PREFIX + "/appointmentscheduling/timeframeunits/"
+ ((AppointmentRequest.AppointmentRequestStatus) o);
}

@Override
public SimpleObject search(RequestContext requestContext) throws ResponseException {
return null;
}

}

0 comments on commit 5d424db

Please sign in to comment.