-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
O3-2635: prevent duplicate queue entries (#48)
--------- Co-authored-by: Michael Seaton <[email protected]>
- Loading branch information
Showing
10 changed files
with
229 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
api/src/main/java/org/openmrs/module/queue/exception/DuplicateQueueEntryException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* | ||
* This Source Code Form is subject to the terms of the Mozilla Public License, | ||
* v. 2.0. If a copy of the MPL was not distributed with this file, You can | ||
* obtain one at http://mozilla.org/MPL/2.0/. OpenMRS is also distributed under | ||
* the terms of the Healthcare Disclaimer located at http://openmrs.org/license. | ||
* | ||
* Copyright (C) OpenMRS Inc. OpenMRS is a registered trademark and the OpenMRS | ||
* graphic logo is a trademark of OpenMRS Inc. | ||
*/ | ||
package org.openmrs.module.queue.exception; | ||
|
||
import org.openmrs.api.APIException; | ||
|
||
public class DuplicateQueueEntryException extends APIException { | ||
|
||
private static final long serialVersionUID = 1L; | ||
|
||
public DuplicateQueueEntryException() { | ||
} | ||
|
||
/** | ||
* @param message | ||
*/ | ||
public DuplicateQueueEntryException(String message) { | ||
super(message); | ||
} | ||
|
||
/** | ||
* @param message | ||
* @param cause | ||
*/ | ||
public DuplicateQueueEntryException(String message, Throwable cause) { | ||
super(message, cause); | ||
} | ||
|
||
/** | ||
* @param cause | ||
*/ | ||
public DuplicateQueueEntryException(Throwable cause) { | ||
super(cause); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# | ||
# This Source Code Form is subject to the terms of the Mozilla Public License, | ||
# v. 2.0. If a copy of the MPL was not distributed with this file, You can | ||
# obtain one at http://mozilla.org/MPL/2.0/. OpenMRS is also distributed under | ||
# the terms of the Healthcare Disclaimer located at http://openmrs.org/license. | ||
# | ||
# Copyright (C) OpenMRS Inc. OpenMRS is a registered trademark and the OpenMRS | ||
# graphic logo is a trademark of OpenMRS Inc. | ||
# | ||
|
||
queue.entry.duplicate.patient=Patient already in the queue |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# | ||
# This Source Code Form is subject to the terms of the Mozilla Public License, | ||
# v. 2.0. If a copy of the MPL was not distributed with this file, You can | ||
# obtain one at http://mozilla.org/MPL/2.0/. OpenMRS is also distributed under | ||
# the terms of the Healthcare Disclaimer located at http://openmrs.org/license. | ||
# | ||
# Copyright (C) OpenMRS Inc. OpenMRS is a registered trademark and the OpenMRS | ||
# graphic logo is a trademark of OpenMRS Inc. | ||
# | ||
|
||
queue.entry.duplicate.patient=Paciente ya en la cola |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# | ||
# This Source Code Form is subject to the terms of the Mozilla Public License, | ||
# v. 2.0. If a copy of the MPL was not distributed with this file, You can | ||
# obtain one at http://mozilla.org/MPL/2.0/. OpenMRS is also distributed under | ||
# the terms of the Healthcare Disclaimer located at http://openmrs.org/license. | ||
# | ||
# Copyright (C) OpenMRS Inc. OpenMRS is a registered trademark and the OpenMRS | ||
# graphic logo is a trademark of OpenMRS Inc. | ||
# | ||
|
||
queue.entry.duplicate.patient=Patient déjà dans la queue |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# | ||
# This Source Code Form is subject to the terms of the Mozilla Public License, | ||
# v. 2.0. If a copy of the MPL was not distributed with this file, You can | ||
# obtain one at http://mozilla.org/MPL/2.0/. OpenMRS is also distributed under | ||
# the terms of the Healthcare Disclaimer located at http://openmrs.org/license. | ||
# | ||
# Copyright (C) OpenMRS Inc. OpenMRS is a registered trademark and the OpenMRS | ||
# graphic logo is a trademark of OpenMRS Inc. | ||
# | ||
|
||
queue.entry.duplicate.patient=Pasyan deja nan keu a |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
api/src/test/java/org/openmrs/module/queue/utils/QueueUtilsTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/* | ||
* This Source Code Form is subject to the terms of the Mozilla Public License, | ||
* v. 2.0. If a copy of the MPL was not distributed with this file, You can | ||
* obtain one at http://mozilla.org/MPL/2.0/. OpenMRS is also distributed under | ||
* the terms of the Healthcare Disclaimer located at http://openmrs.org/license. | ||
* | ||
* Copyright (C) OpenMRS Inc. OpenMRS is a registered trademark and the OpenMRS | ||
* graphic logo is a trademark of OpenMRS Inc. | ||
*/ | ||
package org.openmrs.module.queue.utils; | ||
|
||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.hamcrest.Matchers.is; | ||
|
||
import java.util.Date; | ||
|
||
import org.junit.Test; | ||
|
||
public class QueueUtilsTest { | ||
|
||
private static final Date NULL = null; | ||
|
||
private static final Date AUG_1 = QueueUtils.parseDate("2023-08-01 10:00:00"); | ||
|
||
private static final Date AUG_2 = QueueUtils.parseDate("2023-08-02 10:00:00"); | ||
|
||
private static final Date AUG_3 = QueueUtils.parseDate("2023-08-03 10:00:00"); | ||
|
||
private static final Date AUG_4 = QueueUtils.parseDate("2023-08-04 10:00:00"); | ||
|
||
@Test | ||
public void shouldReturnTrueIfDatesOverlap() { | ||
// Test that nulls are handled as open-ended dates | ||
assertThat(QueueUtils.datesOverlap(NULL, NULL, NULL, NULL), is(true)); | ||
assertThat(QueueUtils.datesOverlap(NULL, AUG_2, AUG_3, AUG_4), is(false)); | ||
assertThat(QueueUtils.datesOverlap(AUG_1, NULL, AUG_3, AUG_4), is(true)); | ||
assertThat(QueueUtils.datesOverlap(AUG_1, AUG_2, NULL, AUG_4), is(true)); | ||
assertThat(QueueUtils.datesOverlap(AUG_1, AUG_2, AUG_3, NULL), is(false)); | ||
|
||
// Test that order of date periods does not matter | ||
assertThat(QueueUtils.datesOverlap(AUG_1, AUG_2, AUG_3, AUG_4), is(false)); | ||
assertThat(QueueUtils.datesOverlap(AUG_1, AUG_3, AUG_2, AUG_4), is(true)); | ||
assertThat(QueueUtils.datesOverlap(AUG_3, AUG_4, AUG_1, AUG_2), is(false)); | ||
assertThat(QueueUtils.datesOverlap(AUG_2, AUG_4, AUG_1, AUG_3), is(true)); | ||
|
||
// Test date overlaps without nulls | ||
assertThat(QueueUtils.datesOverlap(AUG_1, AUG_2, AUG_3, AUG_4), is(false)); // one before two | ||
assertThat(QueueUtils.datesOverlap(AUG_1, AUG_2, AUG_2, AUG_3), is(false)); // one ends when two begins | ||
assertThat(QueueUtils.datesOverlap(AUG_1, AUG_3, AUG_2, AUG_4), is(true)); // one ends within two | ||
assertThat(QueueUtils.datesOverlap(AUG_1, AUG_4, AUG_2, AUG_3), is(true)); // one ends after two ends | ||
assertThat(QueueUtils.datesOverlap(AUG_2, AUG_4, AUG_1, AUG_3), is(true)); // one starts within two | ||
assertThat(QueueUtils.datesOverlap(AUG_3, AUG_4, AUG_1, AUG_2), is(false)); // one after two | ||
assertThat(QueueUtils.datesOverlap(AUG_1, AUG_2, AUG_1, AUG_3), is(true)); // one starts when two starts | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sorry @mseaton , I just discovered a typo on this line. The second arguments should have been:
queueEntry.getStartedAt(), queueEntry.getEndedAt() ?