Skip to content

Commit 310978d

Browse files
O3-2454: Queue Module - allow nullable location and service on queue.
1 parent 21c98ae commit 310978d

File tree

4 files changed

+39
-15
lines changed

4 files changed

+39
-15
lines changed

api/src/main/java/org/openmrs/module/queue/model/Queue.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,11 @@ public class Queue extends BaseChangeableOpenmrsMetadata {
5050
private Integer queueId;
5151

5252
@ManyToOne
53-
@JoinColumn(name = "location_id", nullable = false)
53+
@JoinColumn(name = "location_id")
5454
private Location location;
5555

5656
@ManyToOne
57-
@JoinColumn(name = "service", referencedColumnName = "concept_id", nullable = false)
57+
@JoinColumn(name = "service", referencedColumnName = "concept_id")
5858
private Concept service;
5959

6060
@ManyToOne

api/src/main/java/org/openmrs/module/queue/validators/QueueValidator.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,18 +39,17 @@ public void validate(Object target, Errors errors) {
3939
}
4040
Queue queue = (Queue) target;
4141
ValidationUtils.rejectIfEmptyOrWhitespace(errors, "name", "queue.name.null", "Queue name can't be null");
42-
ValidationUtils.rejectIfEmptyOrWhitespace(errors, "location", "queue.location.null", "Location can't be null");
4342

4443
// TODO: Check if the location is tagged as a Queue Location?
4544

4645
QueueServicesWrapper queueServices = Context.getRegisteredComponents(QueueServicesWrapper.class).get(0);
4746
if (queue.getService() == null) {
48-
errors.rejectValue("service", "QueueEntry.service.null", "The property service should not be null");
49-
} else {
50-
if (!queueServices.getAllowedServices().contains(queue.getService())) {
51-
errors.rejectValue("service", "Queue.service.invalid",
52-
"The property service should be a member of configured queue service conceptSet.");
53-
}
47+
return;
48+
}
49+
50+
if (!queueServices.getAllowedServices().contains(queue.getService())) {
51+
errors.rejectValue("service", "Queue.service.invalid",
52+
"The property service should be a member of configured queue service conceptSet.");
5453
}
5554
}
5655
}

api/src/main/resources/liquibase.xml

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,8 @@
2626
<constraints nullable="false"/>
2727
</column>
2828
<column name="description" type="varchar(255)"/>
29-
<column name="location_id" type="int">
30-
<constraints nullable="false"/>
31-
</column>
32-
<column name="service" type="int">
33-
<constraints nullable="false"/>
34-
</column>
29+
<column name="location_id" type="int"/>
30+
<column name="service" type="int"/>
3531
<column name="creator" type="int">
3632
<constraints nullable="false"/>
3733
</column>
@@ -460,4 +456,16 @@
460456
</sql>
461457
</changeSet>
462458

459+
<changeSet id="nullable_location_and_service_on_queue_20240329" author="mujuzi">
460+
<preConditions onFail="MARK_RAN">
461+
<columnExists tableName="queue" columnName="location_id"/>
462+
<columnExists tableName="queue" columnName="service"/>
463+
</preConditions>
464+
<comment>
465+
Drop Not-Null constraint from columns queue.location_id and queue.service
466+
</comment>
467+
<dropNotNullConstraint tableName="queue" columnName="location_id" columnDataType="int"/>
468+
<dropNotNullConstraint tableName="queue" columnName="service" columnDataType="int"/>
469+
</changeSet>
470+
463471
</databaseChangeLog>

integration-tests/src/test/java/org/openmrs/module/queue/validators/QueueValidatorTest.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,11 @@
1010
package org.openmrs.module.queue.validators;
1111

1212
import static org.hamcrest.Matchers.equalTo;
13+
import static org.junit.Assert.assertNull;
1314
import static org.junit.Assert.assertThat;
1415

1516
import org.junit.Before;
17+
import org.junit.Ignore;
1618
import org.junit.Test;
1719
import org.openmrs.api.context.Context;
1820
import org.openmrs.module.queue.SpringTestConfiguration;
@@ -22,6 +24,7 @@
2224
import org.springframework.test.context.ContextConfiguration;
2325
import org.springframework.validation.BindException;
2426
import org.springframework.validation.Errors;
27+
import org.springframework.validation.FieldError;
2528

2629
@ContextConfiguration(classes = SpringTestConfiguration.class, inheritLocations = false)
2730
public class QueueValidatorTest extends BaseModuleContextSensitiveTest {
@@ -83,11 +86,25 @@ public void shouldSucceedForValidLocation() {
8386
}
8487

8588
@Test
89+
@Ignore("O3-2454: Allow nullable location and service on queue")
8690
public void shouldFailForInvalidLocation() {
8791
queue.setName("Test Queue");
8892
queue.setLocation(Context.getLocationService().getLocationByUuid(BAD_LOCATION_UUID));
8993
queue.setService(Context.getConceptService().getConceptByUuid(VALID_SERVICE_CONCEPT));
9094
validator.validate(queue, errors);
9195
assertThat(errors.getAllErrors().size(), equalTo(1));
9296
}
97+
98+
@Test
99+
public void shouldSucceedForNullServiceConceptAndLocation() {
100+
queue.setName("Test Queue");
101+
queue.setLocation(null);
102+
queue.setService(null);
103+
validator.validate(queue, errors);
104+
105+
FieldError queueServiceFieldError = errors.getFieldError("service");
106+
FieldError queueLocationFieldError = errors.getFieldError("location");
107+
assertNull(queueServiceFieldError);
108+
assertNull(queueLocationFieldError);
109+
}
93110
}

0 commit comments

Comments
 (0)