Skip to content

Commit

Permalink
more changes
Browse files Browse the repository at this point in the history
  • Loading branch information
mherman22 committed Dec 31, 2023
1 parent 6e1f363 commit 31af567
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 56 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public List<Concept> getConceptsWithAnyMappingInSource(@Nonnull ConceptSource co
OpenmrsFhirCriteriaContext<Concept> criteriaContext = createCriteriaContext(Concept.class);
createConceptMapCriteriaBuilder(conceptSource,mappingCode);

criteriaContext.addOrder(criteriaContext.getCriteriaBuilder().asc(criteriaContext.getRoot().join("concept").get("retired")));
criteriaContext.addOrder(criteriaContext.getCriteriaBuilder().asc(criteriaContext.getRoot().get("concept.retired")));

return criteriaContext.getEntityManager().createQuery(criteriaContext.getCriteriaQuery()).getResultList();
}
Expand Down Expand Up @@ -102,16 +102,22 @@ protected void handleTitle(OpenmrsFhirCriteriaContext<Concept> criteriaContext,
protected void createConceptMapCriteriaBuilder(@Nonnull ConceptSource conceptSource, String mappingCode) {
OpenmrsFhirCriteriaContext<ConceptMap> criteriaContext = createCriteriaContext(ConceptMap.class);
criteriaContext.getCriteriaQuery().select(criteriaContext.getRoot().get("concept"));
Join<ConceptMap, ConceptReferenceTerm> termJoin = criteriaContext.getRoot().join("conceptReferenceTerm");

criteriaContext.addJoin("conceptReferenceTerm", "term").finalizeQuery();
criteriaContext.addJoin("conceptMapType", "mapType").finalizeQuery();
criteriaContext.addJoin("concept", "concept").finalizeQuery();


if (Context.getAdministrationService().isDatabaseStringComparisonCaseSensitive()) {
criteriaContext.addPredicate(criteriaContext.getCriteriaBuilder()
.equal(criteriaContext.getCriteriaBuilder().lower(termJoin.get("code")), mappingCode.toLowerCase()));
.equal(criteriaContext.getCriteriaBuilder()
.lower(criteriaContext.getRoot().get("term.code")), mappingCode.toLowerCase()));
} else {
criteriaContext.addPredicate(criteriaContext.getCriteriaBuilder().equal(termJoin.get("code"), mappingCode));
criteriaContext.addPredicate(criteriaContext.getCriteriaBuilder()
.equal(criteriaContext.getRoot().get("term.code"), mappingCode));
}

criteriaContext.addPredicate(criteriaContext.getCriteriaBuilder().equal(termJoin.get("conceptSource"), conceptSource));
criteriaContext.finalizeQuery();
criteriaContext.addPredicate(criteriaContext.getCriteriaBuilder()
.equal(criteriaContext.getRoot().get("term.conceptSource"), conceptSource))
.finalizeQuery();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,55 +50,6 @@ public boolean hasDistinctResults() {
return false;
}

@Override
public List<Encounter> getSearchResults(@NonNull SearchParameterMap theParams) {
OpenmrsFhirCriteriaContext<Encounter> criteriaContext = getSearchResultCriteria(theParams);
handleSort(criteriaContext, theParams.getSortSpec());
criteriaContext.addOrder(criteriaContext.getCriteriaBuilder().asc(criteriaContext.getRoot().get("encounterId")));

criteriaContext.getEntityManager().createQuery(criteriaContext.getCriteriaQuery()).setFirstResult(theParams.getFromIndex());
if (theParams.getToIndex() != Integer.MAX_VALUE) {
int maxResults = theParams.getToIndex() - theParams.getFromIndex();
criteriaContext.getEntityManager().createQuery(criteriaContext.getCriteriaQuery()).setMaxResults(maxResults);
}

List<Encounter> results;
if (hasDistinctResults()) {
results = criteriaContext.getEntityManager().createQuery(criteriaContext.getCriteriaQuery()).getResultList();
} else {
OpenmrsFhirCriteriaContext<Long> longOpenmrsFhirCriteriaContext = createCriteriaContext(Long.class);
longOpenmrsFhirCriteriaContext.getCriteriaQuery().subquery(Long.class).select(longOpenmrsFhirCriteriaContext
.getCriteriaBuilder().countDistinct(longOpenmrsFhirCriteriaContext.getRoot().get("id")));

longOpenmrsFhirCriteriaContext.getCriteriaQuery().select(longOpenmrsFhirCriteriaContext.getRoot())
.where(longOpenmrsFhirCriteriaContext.getCriteriaBuilder()
.in(longOpenmrsFhirCriteriaContext.getRoot().get("id"))
.value(longOpenmrsFhirCriteriaContext.getCriteriaQuery().subquery(Long.class)));

//TODO: gonna come back to it later
// handleSort(projectionCriteriaBuilder, theParams.getSortSpec(), this::paramToProps).ifPresent(
// orders -> orders.forEach(order -> projectionList.add(Projections.property(order.getPropertyName()))));
// criteria.setProjection(projectionList);
// List<Integer> ids = new ArrayList<>();
// if (projectionList.getLength() > 1) {
// for (Object[] o : ((List<Object[]>) criteria.list())) {
// ids.add((Integer) o[0]);
// }
// } else {
// ids = criteria.list();
// }

longOpenmrsFhirCriteriaContext.getCriteriaQuery().select(longOpenmrsFhirCriteriaContext.getRoot()).where(
longOpenmrsFhirCriteriaContext.getCriteriaBuilder().in(longOpenmrsFhirCriteriaContext.getRoot().get("id")));
// Need to reapply ordering
handleSort(criteriaContext, theParams.getSortSpec());
criteriaContext.addOrder(criteriaContext.getCriteriaBuilder().asc(criteriaContext.getRoot().get("id")));

results = criteriaContext.getEntityManager().createQuery(criteriaContext.getCriteriaQuery()).getResultList();
}
return results.stream().map(this::deproxyResult).collect(Collectors.toList());
}

@Override
public List<String> getSearchResultUuids(@Nonnull SearchParameterMap theParams) {
OpenmrsFhirCriteriaContext<Encounter> criteriaContext = createCriteriaContext(Encounter.class);
Expand Down

0 comments on commit 31af567

Please sign in to comment.