diff --git a/api/src/main/java/org/openmrs/module/queue/api/QueueEntryService.java b/api/src/main/java/org/openmrs/module/queue/api/QueueEntryService.java index 0b3ec57..0b10286 100644 --- a/api/src/main/java/org/openmrs/module/queue/api/QueueEntryService.java +++ b/api/src/main/java/org/openmrs/module/queue/api/QueueEntryService.java @@ -104,4 +104,13 @@ String generateVisitQueueNumber(@NotNull Location location, @NotNull Queue queue * none configured */ SortWeightGenerator getSortWeightGenerator(); + + /** + * Allows explicitly setting the sortWeightGenerator Typical usage would involve configuring the + * sortWeightGenerator via global property but this method exists to enable setting programmatically + * if necessary + * + * @param sortWeightGenerator the SortWeightGenerator to set + */ + void setSortWeightGenerator(SortWeightGenerator sortWeightGenerator); } diff --git a/api/src/main/java/org/openmrs/module/queue/api/impl/QueueEntryServiceImpl.java b/api/src/main/java/org/openmrs/module/queue/api/impl/QueueEntryServiceImpl.java index e2fb8ad..cb36f69 100644 --- a/api/src/main/java/org/openmrs/module/queue/api/impl/QueueEntryServiceImpl.java +++ b/api/src/main/java/org/openmrs/module/queue/api/impl/QueueEntryServiceImpl.java @@ -57,6 +57,7 @@ public class QueueEntryServiceImpl extends BaseOpenmrsService implements QueueEn private AdministrationService administrationService; + @Setter private SortWeightGenerator sortWeightGenerator = null; public void setDao(QueueEntryDao dao) { @@ -111,10 +112,8 @@ public QueueEntry saveQueueEntry(QueueEntry queueEntry) { } } } - if (sortWeightGenerator != null) { - Double sortWeight = sortWeightGenerator.generateSortWeight(queueEntry); - queueEntry.setSortWeight(sortWeight); - } + Double sortWeight = getSortWeightGenerator().generateSortWeight(queueEntry); + queueEntry.setSortWeight(sortWeight); return dao.createOrUpdate(queueEntry); } diff --git a/api/src/test/java/org/openmrs/module/queue/api/QueueEntryServiceTest.java b/api/src/test/java/org/openmrs/module/queue/api/QueueEntryServiceTest.java index ec3a519..743ada7 100644 --- a/api/src/test/java/org/openmrs/module/queue/api/QueueEntryServiceTest.java +++ b/api/src/test/java/org/openmrs/module/queue/api/QueueEntryServiceTest.java @@ -42,6 +42,7 @@ import org.openmrs.module.queue.api.dao.QueueEntryDao; import org.openmrs.module.queue.api.impl.QueueEntryServiceImpl; import org.openmrs.module.queue.api.search.QueueEntrySearchCriteria; +import org.openmrs.module.queue.api.sort.ExistingValueSortWeightGenerator; import org.openmrs.module.queue.exception.DuplicateQueueEntryException; import org.openmrs.module.queue.model.Queue; import org.openmrs.module.queue.model.QueueEntry; @@ -77,6 +78,7 @@ protected QueueEntryService getProxiedQueueEntryService() { }; queueEntryService.setDao(dao); queueEntryService.setVisitService(visitService); + queueEntryService.setSortWeightGenerator(new ExistingValueSortWeightGenerator()); } @Test