From c264c77fdbb05be0fe1b3cf35e3ed1d598cae673 Mon Sep 17 00:00:00 2001 From: IamMujuziMoses Date: Fri, 29 Mar 2024 19:43:25 +0300 Subject: [PATCH] O3-2445: Queue Module - allow nullable priority and status on queue entry. --- .../module/queue/model/QueueEntry.java | 4 ++-- .../queue/validators/QueueEntryValidator.java | 21 +++++++------------ api/src/main/resources/liquibase.xml | 19 +++++++++++------ .../validators/QueueEntryValidatorTest.java | 12 +++++++++++ 4 files changed, 34 insertions(+), 22 deletions(-) diff --git a/api/src/main/java/org/openmrs/module/queue/model/QueueEntry.java b/api/src/main/java/org/openmrs/module/queue/model/QueueEntry.java index a2ab33be..48293832 100644 --- a/api/src/main/java/org/openmrs/module/queue/model/QueueEntry.java +++ b/api/src/main/java/org/openmrs/module/queue/model/QueueEntry.java @@ -63,14 +63,14 @@ public class QueueEntry extends BaseChangeableOpenmrsData { private Visit visit; @ManyToOne - @JoinColumn(name = "priority", referencedColumnName = "concept_id", nullable = false) + @JoinColumn(name = "priority", referencedColumnName = "concept_id") private Concept priority; @Column(name = "priority_comment") private String priorityComment; @ManyToOne - @JoinColumn(name = "status", referencedColumnName = "concept_id", nullable = false) + @JoinColumn(name = "status", referencedColumnName = "concept_id") private Concept status; // Provides a means to indicate the relative order within a queue. Higher weight reflects higher priority. diff --git a/api/src/main/java/org/openmrs/module/queue/validators/QueueEntryValidator.java b/api/src/main/java/org/openmrs/module/queue/validators/QueueEntryValidator.java index 9e68d972..b3d0bbda 100644 --- a/api/src/main/java/org/openmrs/module/queue/validators/QueueEntryValidator.java +++ b/api/src/main/java/org/openmrs/module/queue/validators/QueueEntryValidator.java @@ -65,21 +65,14 @@ public void validate(Object target, Errors errors) { } QueueServicesWrapper queueServices = Context.getRegisteredComponents(QueueServicesWrapper.class).get(0); - if (queueEntry.getStatus() == null) { - errors.rejectValue("status", "queueEntry.status.null", "The property status should not be null"); - } else { - if (!queueServices.getAllowedStatuses(queue).contains(queueEntry.getStatus())) { - errors.rejectValue("status", "queueEntry.status.invalid", - "The property status should be a member of configured queue status conceptSet."); - } + if (queueEntry.getStatus() != null && !queueServices.getAllowedStatuses(queue).contains(queueEntry.getStatus())) { + errors.rejectValue("status", "queueEntry.status.invalid", + "The property status should be a member of configured queue status conceptSet."); } - if (queueEntry.getPriority() == null) { - errors.rejectValue("priority", "queueEntry.priority.null", "The property priority should not be null"); - } else { - if (!queueServices.getAllowedPriorities(queue).contains(queueEntry.getPriority())) { - errors.rejectValue("priority", "queueEntry.priority.invalid", - "The property priority should be a member of configured queue priority conceptSet."); - } + if (queueEntry.getPriority() != null + && !queueServices.getAllowedPriorities(queue).contains(queueEntry.getPriority())) { + errors.rejectValue("priority", "queueEntry.priority.invalid", + "The property priority should be a member of configured queue priority conceptSet."); } } } diff --git a/api/src/main/resources/liquibase.xml b/api/src/main/resources/liquibase.xml index 27e2e7cb..8d86f81a 100644 --- a/api/src/main/resources/liquibase.xml +++ b/api/src/main/resources/liquibase.xml @@ -83,13 +83,9 @@ - - - + - - - + @@ -460,4 +456,15 @@ + + + + + + + Drop Not-Null constraint from columns queue_entry.priority and queue_entry.status + + + + diff --git a/integration-tests/src/test/java/org/openmrs/module/queue/validators/QueueEntryValidatorTest.java b/integration-tests/src/test/java/org/openmrs/module/queue/validators/QueueEntryValidatorTest.java index 62b8e051..4639a2a5 100644 --- a/integration-tests/src/test/java/org/openmrs/module/queue/validators/QueueEntryValidatorTest.java +++ b/integration-tests/src/test/java/org/openmrs/module/queue/validators/QueueEntryValidatorTest.java @@ -19,6 +19,7 @@ import org.apache.commons.lang.time.DateUtils; import org.junit.Before; +import org.junit.Ignore; import org.junit.Test; import org.openmrs.Concept; import org.openmrs.Visit; @@ -75,6 +76,7 @@ public void shouldSupportQueueEntry() { } @Test + @Ignore("O3-2445: Allow nullable priority and status on queue entry") public void shouldRejectQueueEntryWithNullStatus() { validator.validate(queueEntry, errors); @@ -85,6 +87,16 @@ public void shouldRejectQueueEntryWithNullStatus() { assertThat(queueEntryStatusFieldError.getDefaultMessage(), is("The property status should not be null")); } + @Test + public void shouldNotRejectQueueEntryWithNullStatusAndPriority() { + validator.validate(queueEntry, errors); + + FieldError queueEntryStatusFieldError = errors.getFieldError("status"); + FieldError queueEntryPriorityFieldError = errors.getFieldError("priority"); + assertNull(queueEntryStatusFieldError); + assertNull(queueEntryPriorityFieldError); + } + @Test public void shouldNotRejectQueueEntryWithValidConceptStatus() { Concept validStatusConcept = Context.getConceptService().getConceptByUuid(VALID_STATUS_CONCEPT);