Skip to content

Commit

Permalink
O3-2861 - Bug fix to ensure sortWeightGenerator is properly initializ…
Browse files Browse the repository at this point in the history
…ed on first usage.
  • Loading branch information
mseaton committed Mar 11, 2024
1 parent be7cc0c commit 840d736
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public class QueueEntryServiceImpl extends BaseOpenmrsService implements QueueEn

private AdministrationService administrationService;

@Setter
private SortWeightGenerator sortWeightGenerator = null;

public void setDao(QueueEntryDao<QueueEntry> dao) {
Expand Down Expand Up @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -77,6 +78,7 @@ protected QueueEntryService getProxiedQueueEntryService() {
};
queueEntryService.setDao(dao);
queueEntryService.setVisitService(visitService);
queueEntryService.setSortWeightGenerator(new ExistingValueSortWeightGenerator());
}

@Test
Expand Down

0 comments on commit 840d736

Please sign in to comment.