Skip to content

Commit

Permalink
UHM-855 Test scheduled appointment block resource
Browse files Browse the repository at this point in the history
  • Loading branch information
pamcdm committed Mar 19, 2014
1 parent 7bb20e2 commit 5074697
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import org.openmrs.module.webservices.rest.web.resource.api.Retrievable;
import org.openmrs.module.webservices.rest.web.resource.api.Searchable;
import org.openmrs.module.webservices.rest.web.response.ResponseException;
import org.openmrs.module.webservices.validation.ValidationException;

import java.util.ArrayList;
import java.util.Arrays;
Expand All @@ -33,6 +34,10 @@ public SimpleObject search(RequestContext context) throws ResponseException {
Location location = getLocation(context);
AppointmentType appointmentType = getAppointmentType(context);

if (date == null || location == null) {
throw new ValidationException("appointmentschedulingui.dailyScheduledAppointments.validationExeptionMessage");
}

List<ScheduledAppointmentBlock> dailyAppointmentBlocks = getScheduledAppointmentBlocks(date, location,
appointmentType);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,9 +195,9 @@ public void shouldFetchAppointmentsByPatient() throws Exception {
handle(req);

List<Map<String, String>> appointments = (List<Map<String, String>>) deserialize(handle(req)).get("results");
Assert.assertEquals(1, appointments.size());
Assert.assertEquals(2, appointments.size());
Assert.assertEquals("c0c579b0-8e59-401d-8a4a-976a0b183602", appointments.get(0).get("uuid"));

Assert.assertEquals("c0c579b0-8e59-401d-8a4a-976a0b183606", appointments.get(1).get("uuid"));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,14 @@
import org.mockito.Mockito;
import org.openmrs.module.webservices.rest.SimpleObject;
import org.openmrs.module.webservices.rest.web.RequestContext;
import org.openmrs.module.webservices.validation.ValidationException;
import org.openmrs.web.test.BaseModuleWebContextSensitiveTest;

import java.util.List;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.when;

public class ScheduledAppointmentBlockResource1_9Test extends BaseModuleWebContextSensitiveTest {
Expand All @@ -27,8 +32,91 @@ public void shouldSearchForScheduledAppointmentBlock() {
when(context.getParameter("appointmentType")).thenReturn("759799ab-c9a5-435e-b671-77773ada74e6");

SimpleObject search = scheduledAppointmentBlockResource1_9.search(context);
assertSearchResults(search);

List resultList = (List) search.get("results");
assertRepresentationOfEachResult(resultList);

SimpleObject firstResult = (SimpleObject) resultList.get(0);

SimpleObject appointmentBlock = (SimpleObject) firstResult.get("appointmentBlock");
assertAppointmentBlockResult(appointmentBlock);

List appointments = (List) firstResult.get("appointments");
assertAppointmentsResult(appointments);
}

private void assertAppointmentsResult(List appointments) {
assertEquals(2, appointments.size());

SimpleObject firstAppointment = (SimpleObject) appointments.get(0);

assertTrue(firstAppointment.containsKey("patient"));
assertEquals("22b47970-8f52-11e3-baa8-0800200c9a66", ((SimpleObject) firstAppointment.get("patient")).get("uuid")
.toString());
assertTrue(firstAppointment.containsKey("appointmentType"));
assertEquals("759799ab-c9a5-435e-b671-77773ada74e6",
((SimpleObject) firstAppointment.get("appointmentType")).get("uuid").toString());

SimpleObject secondAppointment = (SimpleObject) appointments.get(1);

assertTrue(secondAppointment.containsKey("patient"));
assertEquals("31e09960-8f52-11e3-baa8-0800200c9a66", ((SimpleObject) secondAppointment.get("patient")).get("uuid")
.toString());
assertTrue(secondAppointment.containsKey("appointmentType"));
assertEquals("759799ab-c9a5-435e-b671-77773ada74e6",
((SimpleObject) secondAppointment.get("appointmentType")).get("uuid").toString());

}

private void assertAppointmentBlockResult(SimpleObject appointmentBlock) {
assertTrue(appointmentBlock.containsKey("provider"));
assertEquals("c0c54sd0-8e59-401d-8a4a-976a0b183599", ((SimpleObject) appointmentBlock.get("provider")).get("uuid")
.toString());

assertTrue(appointmentBlock.containsKey("location"));
assertEquals("9356400c-a5a2-4532-8f2b-2361b3446eb7", ((SimpleObject) appointmentBlock.get("location")).get("uuid")
.toString());

assertTrue(appointmentBlock.containsKey("startDate"));
assertEquals("2005-01-03T00:00:00.000-0200", appointmentBlock.get("startDate").toString());

assertTrue(appointmentBlock.containsKey("endDate"));
assertEquals("2005-01-03T11:00:00.000-0200", appointmentBlock.get("endDate").toString());
}

private void assertRepresentationOfEachResult(List results) {
SimpleObject firstResult = (SimpleObject) results.get(0);

assertTrue(firstResult.containsKey("appointmentBlock"));
assertTrue(firstResult.containsKey("appointments"));
}

private void assertSearchResults(SimpleObject search) {
assertNotNull(search);
assertTrue(search.containsKey("results"));
assertEquals(1, search.size());
}

@Test(expected = ValidationException.class)
public void shouldReturnErrorWhenDateParameterIsMissing() {
ScheduledAppointmentBlockResource1_9 scheduledAppointmentBlockResource1_9 = new ScheduledAppointmentBlockResource1_9();

RequestContext context = Mockito.mock(RequestContext.class);
when(context.getParameter("date")).thenReturn(null);
when(context.getParameter("location")).thenReturn("9356400c-a5a2-4532-8f2b-2361b3446eb7");

scheduledAppointmentBlockResource1_9.search(context);
}

@Test(expected = ValidationException.class)
public void shouldReturnErrorWhenLocationParameterIsMissing() {
ScheduledAppointmentBlockResource1_9 scheduledAppointmentBlockResource1_9 = new ScheduledAppointmentBlockResource1_9();

RequestContext context = Mockito.mock(RequestContext.class);
when(context.getParameter("date")).thenReturn("2005-01-03 00:00:00.0");
when(context.getParameter("location")).thenReturn(null);

scheduledAppointmentBlockResource1_9.search(context);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
<appointmentscheduling_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"/>
<appointmentscheduling_appointment appointment_id="5" time_slot_id="7" appointment_type_id="3" patient_id="1" status="SCHEDULED" uuid="c0c579b0-8e59-401d-8a4a-976a0b183607" date_created="2005-01-01 00:00:00.0" voided="false" creator="1"/>
<appointmentscheduling_appointment appointment_id="6" time_slot_id="8" appointment_type_id="3" patient_id="1" status="SCHEDULED" uuid="c0c579b0-8e59-401d-8a4a-976a0b183605" date_created="2005-01-01 00:00:00.0" voided="false" creator="1"/>
<appointmentscheduling_appointment appointment_id="7" time_slot_id="8" appointment_type_id="3" patient_id="1" status="SCHEDULED" uuid="c0c579b0-8e59-401d-8a4a-976a0b183606" date_created="2005-01-01 00:00:00.0" voided="false" creator="1"/>
<appointmentscheduling_appointment appointment_id="7" time_slot_id="8" appointment_type_id="3" patient_id="2" status="SCHEDULED" uuid="c0c579b0-8e59-401d-8a4a-976a0b183606" date_created="2005-01-01 00:00:00.0" voided="false" creator="1"/>

<appointmentscheduling_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"/>
<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"/>
Expand Down

0 comments on commit 5074697

Please sign in to comment.