Skip to content

Commit

Permalink
address PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
chibongho committed Mar 21, 2024
1 parent 268a617 commit 71d283d
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,15 @@ public interface QueueEntryService {
QueueEntry transitionQueueEntry(@NotNull QueueEntryTransition queueEntryTransition);

/**
* Undos a transition by voiding the input queue entry and making its previous queue entry
* (which MUST not be null) active by setting the previous entry's end time to null.
* Undos a transition to the input queue entry by voiding it and
* making its previous queue entry active by
* setting the previous entry's end time to null.
*
* @param queueEntry the queue entry to undo transition from
* @see QueueEntryService#getPreviousQueueEntry(QueueEntry)
* @param queueEntry the queue entry to undo transition to. Must be active
* @return the previous queue entry, re-activated
*
* @throws IllegalArgumentException if the previous queue entry does not exist
* @throws IllegalStateException if multiple previous entries are identified
*/
QueueEntry undoTransition(@NotNull QueueEntry queueEntry);

Expand Down Expand Up @@ -125,11 +128,12 @@ String generateVisitQueueNumber(@NotNull Location location, @NotNull Queue queue
void setSortWeightGenerator(SortWeightGenerator sortWeightGenerator);

/**
* Given a specified queue entry, return its previous queue entry (i.e. the queue entry the patient
* transition from to get to the specified one)
* Given a specified queue entry Q, return its previous queue entry P, where P has same patient and
* visit as Q, and P.endedAt time is same as Q.startAt time.
*
* @param queueEntry
* @return the previous queue entry, if uniquely identifable; null otherwise.
* @return the previous queue entry, null otherwise.
* @throws IllegalStateException if multiple previous queue entries are identified
*/
QueueEntry getPreviousQueueEntry(@NotNull QueueEntry queueEntry);
}
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,6 @@ public QueueEntry transitionQueueEntry(QueueEntryTransition queueEntryTransition
* @see QueueEntryService#undoTransition(QueueEntry)
*/
@Override
@Transactional
public QueueEntry undoTransition(@NotNull QueueEntry queueEntry) {
if (queueEntry.getVoided()) {
throw new IllegalArgumentException("cannot undo transition on a voided queue entry");
Expand All @@ -149,7 +148,7 @@ public QueueEntry undoTransition(@NotNull QueueEntry queueEntry) {
}
prevQueueEntry.setEndedAt(null);
prevQueueEntry = dao.createOrUpdate(prevQueueEntry);

queueEntry.setVoided(true);
queueEntry.setVoidReason("undo transition");
dao.createOrUpdate(queueEntry);
Expand Down Expand Up @@ -252,6 +251,7 @@ private void endQueueEntry(@NotNull QueueEntry queueEntry) {
}

@Override
@Transactional(readOnly = true)
public QueueEntry getPreviousQueueEntry(@NotNull QueueEntry queueEntry) {
QueueEntrySearchCriteria criteria = new QueueEntrySearchCriteria();
criteria.setPatient(queueEntry.getPatient());
Expand All @@ -260,6 +260,8 @@ public QueueEntry getPreviousQueueEntry(@NotNull QueueEntry queueEntry) {
List<QueueEntry> prevQueueEntries = dao.getQueueEntries(criteria);
if (prevQueueEntries.size() == 1) {
return prevQueueEntries.get(0);
} else if(prevQueueEntries.size() > 1) {
throw new IllegalStateException("Multiple previous queue entries found");
} else {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ public void shouldTransitionQueueEntry() {
assertThat(queueEntry3.getStartedAt(), equalTo(date3));
assertNull(queueEntry3.getEndedAt());
}

@Test
public void shouldUndoTransitionQueueEntry() {
Patient patient1 = new Patient();
Expand Down Expand Up @@ -325,13 +325,13 @@ public void shouldUndoTransitionQueueEntry() {
criteria.setVisit(visit1);
criteria.setEndedOn(date2);
when(dao.getQueueEntries(criteria)).thenReturn(Arrays.asList(queueEntry1));

// First transition test that no changes are required and all values will be pulled from existing queue entry
QueueEntryTransition transition1 = new QueueEntryTransition();
transition1.setQueueEntryToTransition(queueEntry1);
transition1.setTransitionDate(date2);
QueueEntry queueEntry2 = queueEntryService.transitionQueueEntry(transition1);

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 @@ -101,8 +101,7 @@ public Object transitionQueueEntry(@RequestBody QueueEntryTransitionRequest body
return ConversionUtil.convertToRepresentation(newQueueEntry, Representation.REF);
}

@RequestMapping(value = "/rest/" + RestConstants.VERSION_1 + "/queue-entry/undo-transition", method = {
RequestMethod.PUT, RequestMethod.POST })
@RequestMapping(value = "/rest/" + RestConstants.VERSION_1 + "/queue-entry/transition", method = RequestMethod.DELETE)
@ResponseBody
public Object undoTransition(@RequestBody UndoQueueEntryTransitionRequest body) {
QueueEntryService qes = services.getQueueEntryService();
Expand All @@ -111,7 +110,7 @@ public Object undoTransition(@RequestBody UndoQueueEntryTransitionRequest body)
QueueEntry unEndedQueueEntry = services.getQueueEntryService().undoTransition(queueEntry.get());
return ConversionUtil.convertToRepresentation(unEndedQueueEntry, Representation.REF);
} else {
throw new APIException("Invalid queue entry uuid: " + body);
throw new APIException("Invalid queue entry");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -177,11 +177,11 @@ public DelegatingResourceDescription getRepresentationDescription(Representation
description.addProperty("locationWaitingFor", Representation.DEFAULT);
description.addProperty("queueComingFrom", Representation.DEFAULT);
description.addProperty("providerWaitingFor", Representation.DEFAULT);

// gets the previous queue entry, but with REF representation so it doesn't recursively
// fetch more previous entries.
description.addProperty("previousQueueEntry", Representation.REF);

description.addLink("full", ".?v=" + RestConstants.REPRESENTATION_FULL);
} else if (representation instanceof FullRepresentation) {
addSharedResourceDescriptionProperties(description);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,16 @@ public class QueueEntrySearchCriteriaParser {

public static final String SEARCH_PARAM_STARTED_ON_OR_BEFORE = "startedOnOrBefore";

public static final String SEARCH_PARAM_STARTED_ON = "startedOn";

public static final String SEARCH_PARAM_IS_ENDED = "isEnded";

public static final String SEARCH_PARAM_ENDED_ON_OR_AFTER = "endedOnOrAfter";

public static final String SEARCH_PARAM_ENDED_ON_OR_BEFORE = "endedOnOrBefore";

public static final String SEARCH_PARAM_ENDED_ON = "endedOn";

public static final String SEARCH_PARAM_INCLUDE_VOIDED = "includedVoided";

public static final List<String> SEARCH_PARAMETERS = Arrays.asList(SEARCH_PARAM_QUEUE, SEARCH_PARAM_LOCATION,
Expand Down Expand Up @@ -157,6 +161,11 @@ public QueueEntrySearchCriteria constructFromRequest(Map<String, String[]> param
criteria.setStartedOnOrBefore(QueueUtils.parseDate(date));
break;
}
case SEARCH_PARAM_STARTED_ON: {
String date = parameterMap.get(SEARCH_PARAM_STARTED_ON)[0];
criteria.setStartedOn(QueueUtils.parseDate(date));
break;
}
case SEARCH_PARAM_ENDED_ON_OR_AFTER: {
String date = parameterMap.get(SEARCH_PARAM_ENDED_ON_OR_AFTER)[0];
criteria.setEndedOnOrAfter(QueueUtils.parseDate(date));
Expand All @@ -167,6 +176,11 @@ public QueueEntrySearchCriteria constructFromRequest(Map<String, String[]> param
criteria.setEndedOnOrBefore(QueueUtils.parseDate(date));
break;
}
case SEARCH_PARAM_ENDED_ON: {
String date = parameterMap.get(SEARCH_PARAM_ENDED_ON)[0];
criteria.setEndedOn(QueueUtils.parseDate(date));
break;
}
case SEARCH_PARAM_IS_ENDED: {
criteria.setIsEnded(parseBoolean(parameterMap.get(SEARCH_PARAM_IS_ENDED)[0]));
break;
Expand Down

0 comments on commit 71d283d

Please sign in to comment.