Skip to content

Commit

Permalink
O3-2868 - queue-entry-transition should return the new queue entry in…
Browse files Browse the repository at this point in the history
… the response body
  • Loading branch information
mseaton committed Feb 16, 2024
1 parent 8919b34 commit bf8b659
Showing 1 changed file with 9 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@
import org.openmrs.module.queue.model.QueueEntryTransition;
import org.openmrs.module.webservices.rest.web.ConversionUtil;
import org.openmrs.module.webservices.rest.web.RestConstants;
import org.openmrs.module.webservices.rest.web.representation.Representation;
import org.openmrs.module.webservices.rest.web.v1_0.controller.BaseRestController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.ResponseBody;

/**
* The main controller that exposes additional end points for order entry
Expand All @@ -55,17 +55,15 @@ public QueueEntryTransitionRestController(QueueServicesWrapper services) {
}

@RequestMapping(method = { RequestMethod.PUT, RequestMethod.POST })
@ResponseStatus(HttpStatus.OK)
public void transitionQueueEntry(@RequestBody Map<String, String> body) {
@ResponseBody
public Object transitionQueueEntry(@RequestBody Map<String, String> body) {
QueueEntryTransition transition = new QueueEntryTransition();

// Queue Entry to Transition
String queueEntryUuid = body.get(QUEUE_ENTRY_TO_TRANSITION);
Optional<QueueEntry> queueEntryOptional = services.getQueueEntryService().getQueueEntryByUuid(queueEntryUuid);
if (!queueEntryOptional.isPresent()) {
throw new APIException(QUEUE_ENTRY_TO_TRANSITION + " is a required parameter");
}
transition.setQueueEntryToTransition(queueEntryOptional.get());
QueueEntry queueEntry = services.getQueueEntryService().getQueueEntryByUuid(queueEntryUuid)
.orElseThrow(() -> new APIException(QUEUE_ENTRY_TO_TRANSITION + " is a required parameter"));
transition.setQueueEntryToTransition(queueEntry);

// Transition Date
Date transitionDate = new Date();
Expand Down Expand Up @@ -105,6 +103,7 @@ public void transitionQueueEntry(@RequestBody Map<String, String> body) {
}

// Execute transition
services.getQueueEntryService().transitionQueueEntry(transition);
QueueEntry newQueueEntry = services.getQueueEntryService().transitionQueueEntry(transition);
return ConversionUtil.convertToRepresentation(newQueueEntry, Representation.REF);
}
}

0 comments on commit bf8b659

Please sign in to comment.