From 7f09d48a216bccfa943b6929fda357a28a432998 Mon Sep 17 00:00:00 2001 From: mherman22 Date: Sun, 18 Feb 2024 12:53:02 +0300 Subject: [PATCH] workaround for negative results --- .../module/fhir2/api/dao/impl/BaseFhirDao.java | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/api/src/main/java/org/openmrs/module/fhir2/api/dao/impl/BaseFhirDao.java b/api/src/main/java/org/openmrs/module/fhir2/api/dao/impl/BaseFhirDao.java index b0222df20..4fe7807ea 100644 --- a/api/src/main/java/org/openmrs/module/fhir2/api/dao/impl/BaseFhirDao.java +++ b/api/src/main/java/org/openmrs/module/fhir2/api/dao/impl/BaseFhirDao.java @@ -175,12 +175,20 @@ public List getSearchResults(@Nonnull SearchParameterMap theParams) { TypedQuery executableQuery = (TypedQuery) criteriaContext.getEntityManager() .createQuery(criteriaContext.getCriteriaQuery()); + executableQuery.setFirstResult(theParams.getFromIndex()); if (theParams.getToIndex() != Integer.MAX_VALUE) { int maxResults = theParams.getToIndex() - theParams.getFromIndex(); - executableQuery.setMaxResults(maxResults); + if (maxResults >= 0) { + executableQuery.setMaxResults(maxResults); + } else { + // TODO: this is really just a workaround, we can find a better way of handling the negative results + int negative = theParams.getFromIndex() - theParams.getToIndex(); + executableQuery.setMaxResults(negative); + } } - + + if (hasDistinctResults()) { results = (List) criteriaContext.getEntityManager().createQuery(criteriaContext.getCriteriaQuery()) .getResultList();