Skip to content

Commit

Permalink
(feat) O3-3184 allow changing of LocationWaitingFor and ProviderWaiti…
Browse files Browse the repository at this point in the history
…ngFor during a transition
  • Loading branch information
chibongho committed May 9, 2024
1 parent c64ba23 commit 64fd1e5
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
*/
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<String, Object> rawBody) {
QueueEntryTransitionRequest body = new ObjectMapper().convertValue(rawBody, QueueEntryTransitionRequest.class);
QueueEntryTransition transition = new QueueEntryTransition();

// Queue Entry to Transition
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}

0 comments on commit 64fd1e5

Please sign in to comment.