Skip to content

Commit

Permalink
Hopefully less mess, i.e., it compiles
Browse files Browse the repository at this point in the history
  • Loading branch information
ibacher authored and mherman22 committed Dec 18, 2023
1 parent 439baf1 commit fe8d558
Show file tree
Hide file tree
Showing 49 changed files with 1,553 additions and 1,255 deletions.
816 changes: 441 additions & 375 deletions api/src/main/java/org/openmrs/module/fhir2/api/dao/impl/BaseDao.java

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

import javax.persistence.criteria.JoinType;
import javax.persistence.criteria.Predicate;

import java.util.HashSet;
import java.util.Set;

Expand Down Expand Up @@ -43,11 +44,12 @@ protected void setupSearchParams(OpenmrsFhirCriteriaContext<T> criteriaContext,
break;
case FhirConstants.LOCATION_REFERENCE_SEARCH_HANDLER:
entry.getValue().forEach(param -> {
handleLocationReference(criteriaContext,"l", (ReferenceAndListParam) param.getParam()).ifPresent(l -> {
criteriaContext.getRoot().join("location", JoinType.INNER).alias("l");
criteriaContext.addPredicate(l);
criteriaContext.finalizeQuery();
});
handleLocationReference(criteriaContext, "l", (ReferenceAndListParam) param.getParam())
.ifPresent(l -> {
criteriaContext.getRoot().join("location", JoinType.INNER).alias("l");
criteriaContext.addPredicate(l);
criteriaContext.finalizeQuery();
});
});
break;
case FhirConstants.PARTICIPANT_REFERENCE_SEARCH_HANDLER:
Expand Down Expand Up @@ -101,18 +103,22 @@ protected void handleHasAndListParam(OpenmrsFhirCriteriaContext<T> criteriaConte
if (MedicationRequest.SP_ENCOUNTER.equals(hasParam.getReferenceFieldName())) {
if (lacksAlias(criteriaContext, "orders")) {
if (Encounter.class.isAssignableFrom(typeToken.getRawType())) {
criteriaContext.getRoot().join("orders").alias("orders");
criteriaContext.addJoin("orders", "orders");
} else {
if (lacksAlias(criteriaContext, "en")) {
criteriaContext.getRoot().join("encounters").alias("en");
criteriaContext.addJoin("encounters", "en");
}
criteriaContext.getRoot().join("en.orders").alias("orders");
criteriaContext.addJoin("en.orders", "orders");
}
}
// Constrain only on non-voided Drug Orders
criteriaContext.addPredicate(criteriaContext.getCriteriaBuilder().equal(criteriaContext.getRoot().get("orders.class"), DrugOrder.class));
criteriaContext.addPredicate(criteriaContext.getCriteriaBuilder().equal(criteriaContext.getRoot().get("orders.voided"), false));
criteriaContext.addPredicate(criteriaContext.getCriteriaBuilder().notEqual(criteriaContext.getRoot().get("orders.action"), Order.Action.DISCONTINUE));
criteriaContext.addPredicate(criteriaContext.getCriteriaBuilder()
.equal(criteriaContext.getRoot().get("orders.class"), DrugOrder.class));
// TODO Do these criteria still work?
criteriaContext.addPredicate(criteriaContext.getCriteriaBuilder()
.equal(criteriaContext.getRoot().get("orders.voided"), false));
criteriaContext.addPredicate(criteriaContext.getCriteriaBuilder()
.notEqual(criteriaContext.getRoot().get("orders.action"), Order.Action.DISCONTINUE));

String paramName = hasParam.getParameterName();
String paramValue = hasParam.getParameterValue();
Expand All @@ -126,15 +132,17 @@ protected void handleHasAndListParam(OpenmrsFhirCriteriaContext<T> criteriaConte
if (paramValue != null) {
if (MedicationRequest.MedicationRequestStatus.ACTIVE.toString()
.equalsIgnoreCase(paramValue)) {
criteriaContext.getCriteriaBuilder().and(generateActiveOrderQuery(criteriaContext,"orders"));
criteriaContext.getCriteriaBuilder()
.and(generateActiveOrderQuery(criteriaContext, "orders"));
}
}
handled = true;
} else if ((MedicationRequest.SP_STATUS + ":not").equalsIgnoreCase(paramName)) {
if (paramValue != null) {
if (MedicationRequest.MedicationRequestStatus.CANCELLED.toString()
.equalsIgnoreCase(paramValue)) {
criteriaContext.getCriteriaBuilder().and(generateNotCancelledOrderQuery(criteriaContext, "orders"));
criteriaContext.getCriteriaBuilder()
.and(generateNotCancelledOrderQuery(criteriaContext, "orders"));
}
if (MedicationRequest.MedicationRequestStatus.COMPLETED.toString()
.equalsIgnoreCase(paramValue)) {
Expand All @@ -147,11 +155,13 @@ protected void handleHasAndListParam(OpenmrsFhirCriteriaContext<T> criteriaConte
handled = true;
} else if ((FhirConstants.SP_FULFILLER_STATUS).equalsIgnoreCase(paramName)) {
if (paramValue != null) {
criteriaContext.getCriteriaBuilder().and(generateFulfillerStatusRestriction("orders", paramValue));
criteriaContext.getCriteriaBuilder()
.and(generateFulfillerStatusRestriction("orders", paramValue));
}
} else if ((FhirConstants.SP_FULFILLER_STATUS + ":not").equalsIgnoreCase(paramName)) {
if (paramValue != null) {
criteriaContext.getCriteriaBuilder().and(generateNotFulfillerStatusRestriction("orders", paramValue));
criteriaContext.getCriteriaBuilder()
.and(generateNotFulfillerStatusRestriction("orders", paramValue));
}
}
criteriaContext.finalizeQuery();
Expand All @@ -168,9 +178,11 @@ protected void handleHasAndListParam(OpenmrsFhirCriteriaContext<T> criteriaConte

protected abstract void handleDate(OpenmrsFhirCriteriaContext<T> criteriaContext, DateRangeParam dateRangeParam);

protected abstract void handleEncounterType(OpenmrsFhirCriteriaContext<T> criteriaContext, TokenAndListParam tokenAndListParam);
protected abstract void handleEncounterType(OpenmrsFhirCriteriaContext<T> criteriaContext,
TokenAndListParam tokenAndListParam);

protected abstract void handleParticipant(OpenmrsFhirCriteriaContext<T> criteriaContext, ReferenceAndListParam referenceAndListParam);
protected abstract void handleParticipant(OpenmrsFhirCriteriaContext<T> criteriaContext,
ReferenceAndListParam referenceAndListParam);

protected Predicate generateNotCompletedOrderQuery(String path) {
// not implemented in Core until 2.2; see override in FhirEncounterDaoImpl_2_2
Expand Down
Loading

0 comments on commit fe8d558

Please sign in to comment.