Skip to content

Commit

Permalink
not sure
Browse files Browse the repository at this point in the history
  • Loading branch information
mherman22 committed Feb 14, 2024
1 parent 1929c98 commit 7d201bb
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 66 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -702,37 +702,33 @@ protected <T, U> void handleProviderReference(OpenmrsFhirCriteriaContext<T, U> c
}

protected <T, U> Optional<Predicate> handleCodeableConcept(OpenmrsFhirCriteriaContext<T, U> criteriaContext,
TokenAndListParam concepts, @Nonnull From<?, ?> ConceptAliasJoin, @Nonnull String conceptMapAlias,
TokenAndListParam concepts, @Nonnull From<?, ?> conceptAlias, @Nonnull String conceptMapAlias,
@Nonnull String conceptReferenceTermAlias) {
// if (concepts == null) {
// return Optional.empty();
// }
//
// Optional<Join<?, ?>> conceptAliasJoin = criteriaContext.getJoin(ConceptAliasJoin.getAlias());
// return conceptAliasJoin
// .map(join -> handleAndListParamBySystem(criteriaContext.getCriteriaBuilder(), concepts, (system, tokens) -> {
// if (system.isEmpty()) {
// criteriaContext.getCriteriaBuilder()
// .literal(tokensToParams(tokens).map(NumberUtils::toInt).collect(Collectors.toList()));
// return Optional
// .of(criteriaContext.getCriteriaBuilder().or(
// criteriaContext.getCriteriaBuilder()
// .in(join.get("conceptId")
// .in(criteriaContext.getCriteriaBuilder()
// .literal(tokensToParams(tokens).map(NumberUtils::toInt)
// .collect(Collectors.toList())))),
// criteriaContext.getCriteriaBuilder().in(join.get("uuid")
// .in(criteriaContext.getCriteriaBuilder().literal(tokensToList(tokens))))));
//
// } else {
// Join<?, ?> conceptMapAliasJoin = criteriaContext.addJoin(join, "conceptMappings", conceptMapAlias);
// criteriaContext.addJoin(conceptMapAliasJoin, "conceptReferenceTerm", conceptReferenceTermAlias);
//
// return Optional.of(
// generateSystemQuery(criteriaContext, system, tokensToList(tokens), conceptReferenceTermAlias));
// }
// })).orElse(null);
return Optional.empty();
if (concepts == null) {
return Optional.empty();
}

return handleAndListParamBySystem(criteriaContext.getCriteriaBuilder(), concepts, (system, tokens) -> {
if (system.isEmpty()) {
criteriaContext.getCriteriaBuilder()
.literal(tokensToParams(tokens).map(NumberUtils::toInt).collect(Collectors.toList()));
return Optional
.of(criteriaContext
.getCriteriaBuilder().or(
criteriaContext.getCriteriaBuilder()
.in(conceptAlias.get("conceptId")
.in(criteriaContext.getCriteriaBuilder()
.literal(tokensToParams(tokens).map(NumberUtils::toInt)
.collect(Collectors.toList())))),
criteriaContext.getCriteriaBuilder().in(conceptAlias.get("uuid")
.in(criteriaContext.getCriteriaBuilder().literal(tokensToList(tokens))))));
} else {
Join<?, ?> conceptMapAliasJoin = criteriaContext.addJoin(conceptAlias, "conceptMappings", conceptMapAlias);
criteriaContext.addJoin(conceptMapAliasJoin, "conceptReferenceTerm", conceptReferenceTermAlias);

return generateSystemQuery(criteriaContext, system, tokensToList(tokens), conceptReferenceTermAlias);
}
});
}

protected <T, U> void handleNames(OpenmrsFhirCriteriaContext<T, U> criteriaContext, StringAndListParam name,
Expand Down Expand Up @@ -922,8 +918,7 @@ protected <T, U> Optional<Predicate> handleMedicationRequestReference(OpenmrsFhi
* @param sort the {@link SortSpec} which defines the sorting to be translated
*/
protected <T, U> void handleSort(OpenmrsFhirCriteriaContext<T, U> criteriaContext, SortSpec sort) {
handleSort(criteriaContext, sort, this::paramToProps)
.ifPresent(l -> l.forEach(criteriaContext.getCriteriaQuery()::orderBy));
handleSort(criteriaContext, sort, this::paramToProps).ifPresent(l -> l.forEach(criteriaContext::addOrder));
}

protected <T, U> Optional<List<javax.persistence.criteria.Order>> handleSort(
Expand All @@ -932,8 +927,8 @@ protected <T, U> Optional<List<javax.persistence.criteria.Order>> handleSort(
List<javax.persistence.criteria.Order> orderings = new ArrayList<>();
SortSpec sortSpec = sort;
while (sortSpec != null) {
SortState state = SortState.builder().criteriaBuilder(criteriaContext.getCriteriaBuilder())
.sortOrder(sortSpec.getOrder()).parameter(sortSpec.getParamName().toLowerCase()).build();
SortState state = SortState.builder().context(criteriaContext).sortOrder(sortSpec.getOrder())
.parameter(sortSpec.getParamName().toLowerCase()).build();

Collection<javax.persistence.criteria.Order> orders = paramToProp.apply(criteriaContext, state);
if (orders != null) {
Expand Down Expand Up @@ -1158,7 +1153,7 @@ protected Predicate[] toCriteriaArray(Stream<Optional<? extends Predicate>> pred
@EqualsAndHashCode
public static final class SortState {

private CriteriaBuilder criteriaBuilder;
private OpenmrsFhirCriteriaContext context;

private SortOrderEnum sortOrder;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -317,11 +317,13 @@ protected <V, U> Collection<javax.persistence.criteria.Order> paramToProps(
if (isImmutable) {
switch (sortState.getSortOrder()) {
case ASC:
return Collections.singletonList(
criteriaContext.getCriteriaBuilder().asc(criteriaContext.getRoot().get("dateCreated")));
return Collections
.singletonList((javax.persistence.criteria.Order) criteriaContext.getCriteriaQuery().orderBy(
criteriaContext.getCriteriaBuilder().asc(criteriaContext.getRoot().get("dateCreated"))));
case DESC:
return Collections.singletonList(
criteriaContext.getCriteriaBuilder().desc(criteriaContext.getRoot().get("dateCreated")));
(javax.persistence.criteria.Order) criteriaContext.getCriteriaQuery().orderBy(
criteriaContext.getCriteriaBuilder().desc(criteriaContext.getRoot().get("dateCreated"))));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ protected <U> void setupSearchParams(OpenmrsFhirCriteriaContext<Relationship, U>
break;
case FhirConstants.DATE_RANGE_SEARCH_HANDLER:
entry.getValue().forEach(
param -> handleDateRange(criteriaContext, personJoin,"birthdate", (DateRangeParam) param.getParam())
param -> handleDateRange(criteriaContext, "birthdate", (DateRangeParam) param.getParam())
.ifPresent(c -> criteriaContext.addPredicate(c).finalizeQuery()));
break;
case FhirConstants.ADDRESS_SEARCH_HANDLER:
Expand All @@ -81,10 +81,10 @@ protected <T, U> Collection<Order> paramToProps(OpenmrsFhirCriteriaContext<T, U>
if (param == null) {
return null;
}

From<?, ?> personJoin = criteriaContext.addJoin("personA", "m");
if (param.startsWith("address") && !criteriaContext.getJoin("pad").isPresent()) {
criteriaContext.addJoin(personJoin,"addresses", "pad", javax.persistence.criteria.JoinType.LEFT);
criteriaContext.addJoin(personJoin, "addresses", "pad", javax.persistence.criteria.JoinType.LEFT);
} else if (param.equals(SP_NAME) || param.equals(SP_GIVEN) || param.equals(SP_FAMILY)) {
if (!criteriaContext.getJoin("pn").isPresent()) {
criteriaContext.addJoin(personJoin, "names", "pn", javax.persistence.criteria.JoinType.LEFT);
Expand Down Expand Up @@ -164,32 +164,20 @@ protected <T, U> Collection<Order> paramToProps(OpenmrsFhirCriteriaContext<T, U>
}

@Override
protected <V, U> Path<Object> paramToProp(OpenmrsFhirCriteriaContext<V, U> criteriaContext, @Nonnull String param) {
protected <V, U> String paramToProp(OpenmrsFhirCriteriaContext<V, U> criteriaContext, @Nonnull String param) {
From<?, ?> personJoin = criteriaContext.addJoin("personA", "m");
From<?,?> pad = criteriaContext.addJoin(personJoin, "addresses", "pad", javax.persistence.criteria.JoinType.LEFT);
switch (param) {
case SP_BIRTHDATE: {
From<?, ?> personJoin = criteriaContext.addJoin("personA", "m");
return personJoin.get("birthdate");
}
case SP_ADDRESS_CITY: {
From<?, ?> personJoin = criteriaContext.addJoin("personA", "m");
From<?, ?> pad = criteriaContext.addJoin(personJoin, "addresses", "pad", javax.persistence.criteria.JoinType.LEFT);
return pad.get("cityVillage");
}
case SP_ADDRESS_STATE: {
From<?, ?> personJoin = criteriaContext.addJoin("personA", "m");
From<?, ?> pad = criteriaContext.addJoin(personJoin, "addresses", "pad", javax.persistence.criteria.JoinType.LEFT);
return pad.get("stateProvince");
}
case SP_ADDRESS_POSTALCODE: {
From<?, ?> personJoin = criteriaContext.addJoin("personA", "m");
From<?, ?> pad = criteriaContext.addJoin(personJoin, "addresses", "pad", javax.persistence.criteria.JoinType.LEFT);
return pad.get("postalCode");
}
case SP_ADDRESS_COUNTRY: {
From<?, ?> personJoin = criteriaContext.addJoin("personA", "m");
From<?, ?> pad = criteriaContext.addJoin(personJoin, "addresses", "pad", javax.persistence.criteria.JoinType.LEFT);
return pad.get("country");
}
case SP_BIRTHDATE:
personJoin.get("birthdate");
case SP_ADDRESS_CITY:
pad.get("cityVillage");
case SP_ADDRESS_STATE:
pad.get("stateProvince");
case SP_ADDRESS_POSTALCODE:
pad.get("postalCode");
case SP_ADDRESS_COUNTRY:
pad.get("country");
default:
return super.paramToProp(criteriaContext, param);
}
Expand Down

0 comments on commit 7d201bb

Please sign in to comment.