Skip to content
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

O3-2454: Queue Module - allow nullable location and service on queue. #67

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions api/src/main/java/org/openmrs/module/queue/model/Queue.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,11 @@ public class Queue extends BaseChangeableOpenmrsMetadata {
private Integer queueId;

@ManyToOne
@JoinColumn(name = "location_id", nullable = false)
@JoinColumn(name = "location_id")
private Location location;

@ManyToOne
@JoinColumn(name = "service", referencedColumnName = "concept_id", nullable = false)
@JoinColumn(name = "service", referencedColumnName = "concept_id")
private Concept service;

@ManyToOne
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,17 @@ public void validate(Object target, Errors errors) {
}
Queue queue = (Queue) target;
ValidationUtils.rejectIfEmptyOrWhitespace(errors, "name", "queue.name.null", "Queue name can't be null");
ValidationUtils.rejectIfEmptyOrWhitespace(errors, "location", "queue.location.null", "Location can't be null");

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

QueueServicesWrapper queueServices = Context.getRegisteredComponents(QueueServicesWrapper.class).get(0);
if (queue.getService() == null) {
errors.rejectValue("service", "QueueEntry.service.null", "The property service should not be null");
} else {
if (!queueServices.getAllowedServices().contains(queue.getService())) {
errors.rejectValue("service", "Queue.service.invalid",
"The property service should be a member of configured queue service conceptSet.");
}
return;
}

if (!queueServices.getAllowedServices().contains(queue.getService())) {
errors.rejectValue("service", "Queue.service.invalid",
"The property service should be a member of configured queue service conceptSet.");
}
}
}
20 changes: 14 additions & 6 deletions api/src/main/resources/liquibase.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,8 @@
<constraints nullable="false"/>
</column>
<column name="description" type="varchar(255)"/>
<column name="location_id" type="int">
<constraints nullable="false"/>
</column>
<column name="service" type="int">
<constraints nullable="false"/>
</column>
<column name="location_id" type="int"/>
<column name="service" type="int"/>
<column name="creator" type="int">
<constraints nullable="false"/>
</column>
Expand Down Expand Up @@ -460,4 +456,16 @@
</sql>
</changeSet>

<changeSet id="nullable_location_and_service_on_queue_20240329" author="mujuzi">
<preConditions onFail="MARK_RAN">
<columnExists tableName="queue" columnName="location_id"/>
<columnExists tableName="queue" columnName="service"/>
</preConditions>
<comment>
Drop Not-Null constraint from columns queue.location_id and queue.service
</comment>
<dropNotNullConstraint tableName="queue" columnName="location_id" columnDataType="int"/>
<dropNotNullConstraint tableName="queue" columnName="service" columnDataType="int"/>
</changeSet>

</databaseChangeLog>
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@
package org.openmrs.module.queue.validators;

import static org.hamcrest.Matchers.equalTo;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertThat;

import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.openmrs.api.context.Context;
import org.openmrs.module.queue.SpringTestConfiguration;
Expand All @@ -22,6 +24,7 @@
import org.springframework.test.context.ContextConfiguration;
import org.springframework.validation.BindException;
import org.springframework.validation.Errors;
import org.springframework.validation.FieldError;

@ContextConfiguration(classes = SpringTestConfiguration.class, inheritLocations = false)
public class QueueValidatorTest extends BaseModuleContextSensitiveTest {
Expand Down Expand Up @@ -83,11 +86,25 @@ public void shouldSucceedForValidLocation() {
}

@Test
@Ignore("O3-2454: Allow nullable location and service on queue")
public void shouldFailForInvalidLocation() {
queue.setName("Test Queue");
queue.setLocation(Context.getLocationService().getLocationByUuid(BAD_LOCATION_UUID));
queue.setService(Context.getConceptService().getConceptByUuid(VALID_SERVICE_CONCEPT));
validator.validate(queue, errors);
assertThat(errors.getAllErrors().size(), equalTo(1));
}

@Test
public void shouldSucceedForNullServiceConceptAndLocation() {
queue.setName("Test Queue");
queue.setLocation(null);
queue.setService(null);
validator.validate(queue, errors);

FieldError queueServiceFieldError = errors.getFieldError("service");
FieldError queueLocationFieldError = errors.getFieldError("location");
assertNull(queueServiceFieldError);
assertNull(queueLocationFieldError);
}
}
Loading