diff --git a/api/src/main/java/org/openmrs/module/queue/api/impl/QueueEntryServiceImpl.java b/api/src/main/java/org/openmrs/module/queue/api/impl/QueueEntryServiceImpl.java index 13791503..b417d16a 100644 --- a/api/src/main/java/org/openmrs/module/queue/api/impl/QueueEntryServiceImpl.java +++ b/api/src/main/java/org/openmrs/module/queue/api/impl/QueueEntryServiceImpl.java @@ -257,7 +257,7 @@ private void endQueueEntry(@NotNull QueueEntry queueEntry) { @Transactional(readOnly = true) public QueueEntry getPreviousQueueEntry(@NotNull QueueEntry queueEntry) { Queue queueComingFrom = queueEntry.getQueueComingFrom(); - if(queueComingFrom == null) { + if (queueComingFrom == null) { return null; } QueueEntrySearchCriteria criteria = new QueueEntrySearchCriteria(); diff --git a/api/src/main/java/org/openmrs/module/queue/model/QueueEntryTransition.java b/api/src/main/java/org/openmrs/module/queue/model/QueueEntryTransition.java index 367db1d5..e8ee385f 100644 --- a/api/src/main/java/org/openmrs/module/queue/model/QueueEntryTransition.java +++ b/api/src/main/java/org/openmrs/module/queue/model/QueueEntryTransition.java @@ -14,6 +14,8 @@ import lombok.Data; import org.openmrs.Concept; +import org.openmrs.Location; +import org.openmrs.Provider; /** * Bean definition that encapsulates the supported criteria for saving a direct transition from one @@ -36,6 +38,10 @@ public class QueueEntryTransition implements Serializable { private String newPriorityComment; + private Location newLocationWaitingFor; // value obtrained from queueEntryToTransition if not provided by request + + private Provider newProviderWaitingFor; // value obtrained from queueEntryToTransition if not provided by request + /** * @return a new queue entry representing what one intends to transition into */ @@ -49,8 +55,8 @@ public QueueEntry constructNewQueueEntry() { newPriorityComment == null ? queueEntryToTransition.getPriorityComment() : newPriorityComment); queueEntry.setStatus(newStatus == null ? queueEntryToTransition.getStatus() : newStatus); queueEntry.setSortWeight(queueEntryToTransition.getSortWeight()); - queueEntry.setLocationWaitingFor(queueEntryToTransition.getLocationWaitingFor()); - queueEntry.setProviderWaitingFor(queueEntryToTransition.getProviderWaitingFor()); + queueEntry.setLocationWaitingFor(newLocationWaitingFor); + queueEntry.setProviderWaitingFor(newProviderWaitingFor); queueEntry.setQueueComingFrom(queueEntryToTransition.getQueue()); queueEntry.setStartedAt(transitionDate); return queueEntry; diff --git a/api/src/test/java/org/openmrs/module/queue/api/QueueEntryServiceTest.java b/api/src/test/java/org/openmrs/module/queue/api/QueueEntryServiceTest.java index 03416cc1..b39f28fa 100644 --- a/api/src/test/java/org/openmrs/module/queue/api/QueueEntryServiceTest.java +++ b/api/src/test/java/org/openmrs/module/queue/api/QueueEntryServiceTest.java @@ -248,6 +248,8 @@ public void shouldTransitionQueueEntry() { QueueEntryTransition transition1 = new QueueEntryTransition(); transition1.setQueueEntryToTransition(queueEntry1); transition1.setTransitionDate(date2); + transition1.setNewLocationWaitingFor(location1); + transition1.setNewProviderWaitingFor(provider1); QueueEntry queueEntry2 = queueEntryService.transitionQueueEntry(transition1); assertThat(queueEntry1.getEndedAt(), equalTo(date2)); assertThat(queueEntry2.getQueue(), equalTo(queue1)); @@ -280,8 +282,8 @@ public void shouldTransitionQueueEntry() { assertThat(queueEntry3.getPriorityComment(), equalTo(string2)); assertThat(queueEntry3.getStatus(), equalTo(concept2)); assertThat(queueEntry3.getSortWeight(), equalTo(double1)); - assertThat(queueEntry3.getLocationWaitingFor(), equalTo(location1)); - assertThat(queueEntry3.getProviderWaitingFor(), equalTo(provider1)); + assertThat(queueEntry3.getLocationWaitingFor(), equalTo(null)); + assertThat(queueEntry3.getProviderWaitingFor(), equalTo(null)); assertThat(queueEntry3.getQueueComingFrom(), equalTo(queue1)); assertThat(queueEntry3.getStartedAt(), equalTo(date3)); assertNull(queueEntry3.getEndedAt()); @@ -332,7 +334,7 @@ public void shouldUndoTransitionQueueEntry() { criteria.setEndedOn(date2); criteria.setQueues(Arrays.asList(queueEntry2.getQueueComingFrom())); when(dao.getQueueEntries(criteria)).thenReturn(Arrays.asList(queueEntry1)); - + queueEntryService.undoTransition(queueEntry2); assertThat(queueEntry2.getVoided(), equalTo(true)); assertNull(queueEntry1.getEndedAt()); diff --git a/omod/src/main/java/org/openmrs/module/queue/web/QueueEntryTransitionRestController.java b/omod/src/main/java/org/openmrs/module/queue/web/QueueEntryTransitionRestController.java index caa32c5e..e0309762 100644 --- a/omod/src/main/java/org/openmrs/module/queue/web/QueueEntryTransitionRestController.java +++ b/omod/src/main/java/org/openmrs/module/queue/web/QueueEntryTransitionRestController.java @@ -10,9 +10,13 @@ package org.openmrs.module.queue.web; import java.util.Date; +import java.util.Map; import java.util.Optional; +import com.fasterxml.jackson.databind.ObjectMapper; import org.openmrs.Concept; +import org.openmrs.Location; +import org.openmrs.Provider; import org.openmrs.api.APIException; import org.openmrs.module.queue.api.QueueEntryService; import org.openmrs.module.queue.api.QueueServicesWrapper; @@ -48,7 +52,8 @@ public QueueEntryTransitionRestController(QueueServicesWrapper services) { @RequestMapping(value = "/rest/" + RestConstants.VERSION_1 + "/queue-entry/transition", method = { RequestMethod.PUT, RequestMethod.POST }) @ResponseBody - public Object transitionQueueEntry(@RequestBody QueueEntryTransitionRequest body) { + public Object transitionQueueEntry(@RequestBody Map rawBody) { + QueueEntryTransitionRequest body = new ObjectMapper().convertValue(rawBody, QueueEntryTransitionRequest.class); QueueEntryTransition transition = new QueueEntryTransition(); // Queue Entry to Transition @@ -96,6 +101,36 @@ public Object transitionQueueEntry(@RequestBody QueueEntryTransitionRequest body transition.setNewPriorityComment(body.getNewPriorityComment()); + // Location waiting for + if (rawBody.containsKey(QueueEntryTransitionRequest.NEW_LOCATION_WAITING_FOR_FIELD)) { + if (body.getNewLocationWaitingFor() == null) { + transition.setNewLocationWaitingFor(null); + } else { + Location location = services.getLocationService().getLocationByUuid(body.getNewLocationWaitingFor()); + if (location == null) { + throw new APIException("Invalid locationWaitingFor specified: " + body.getNewLocationWaitingFor()); + } + transition.setNewLocationWaitingFor(location); + } + } else { + transition.setNewLocationWaitingFor(queueEntry.getLocationWaitingFor()); + } + + // Provider waiting for + if (rawBody.containsKey(QueueEntryTransitionRequest.NEW_PROVIDER_WAITING_FOR_FIELD)) { + if (body.getNewProviderWaitingFor() == null) { + transition.setNewProviderWaitingFor(null); + } else { + Provider provider = services.getProviderService().getProviderByUuid(body.getNewLocationWaitingFor()); + if (provider == null) { + throw new APIException("Invalid providerWaitingFor specified: " + body.getNewProviderWaitingFor()); + } + transition.setNewProviderWaitingFor(provider); + } + } else { + transition.setNewProviderWaitingFor(queueEntry.getProviderWaitingFor()); + } + // Execute transition QueueEntry newQueueEntry = services.getQueueEntryService().transitionQueueEntry(transition); return ConversionUtil.convertToRepresentation(newQueueEntry, Representation.REF); diff --git a/omod/src/main/java/org/openmrs/module/queue/web/dto/QueueEntryTransitionRequest.java b/omod/src/main/java/org/openmrs/module/queue/web/dto/QueueEntryTransitionRequest.java index 946cc235..fdc95757 100644 --- a/omod/src/main/java/org/openmrs/module/queue/web/dto/QueueEntryTransitionRequest.java +++ b/omod/src/main/java/org/openmrs/module/queue/web/dto/QueueEntryTransitionRequest.java @@ -25,4 +25,12 @@ public class QueueEntryTransitionRequest { private String newPriority; private String newPriorityComment; + + private String newLocationWaitingFor; + + private String newProviderWaitingFor; + + public static final String NEW_LOCATION_WAITING_FOR_FIELD = "newLocationWaitingFor"; + + public static final String NEW_PROVIDER_WAITING_FOR_FIELD = "newProviderWaitingFor"; }