-
Notifications
You must be signed in to change notification settings - Fork 23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
(feat) O3-3184 allow changing of LocationWaitingFor and ProviderWaiti… #74
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It seems a little inconsistent here to do this vs. what we do for status, priority, etc. For the existing fields, we handle the logic here for setting them to existing fields. For these new properties, we handle that logic in the REST controller. Would it make sense to be consistent? |
||
queueEntry.setQueueComingFrom(queueEntryToTransition.getQueue()); | ||
queueEntry.setStartedAt(transitionDate); | ||
return queueEntry; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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<String, Object> 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)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Was there a reason these couldn't just be added as properties for the QueueEntryTransitionRequest? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. They are properties already, but having those properties be null is not sufficient to distinguish between "we intend to set this to null" vs "we don't want to change this property". So we check the rawBody to see if those optional properties are provided at all, and only set the corresponding queue entry field if so. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @chibongho - isn't that also the case for some of the other, already existing properties you are setting? For example There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @mseaton that's a good point about I originally intended the |
||
if (body.getNewLocationWaitingFor() == null) { | ||
transition.setNewLocationWaitingFor(null); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This seems unnecessary. Isn't it always null already in this case? |
||
} 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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same comment as above. |
||
} else { | ||
Provider provider = services.getProviderService().getProviderByUuid(body.getNewLocationWaitingFor()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a bug, probably related to copying the code block. This should be |
||
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); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo in both comments "obtrained" -> "obtained"