Skip to content

Commit

Permalink
lil mess
Browse files Browse the repository at this point in the history
  • Loading branch information
mherman22 committed Dec 18, 2023
1 parent 7983786 commit 06850a9
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,31 @@ public Concept get(@Nonnull String uuid) {
public Optional<Concept> getConceptWithSameAsMappingInSource(@Nonnull ConceptSource conceptSource,
@Nonnull String mappingCode) {
OpenmrsFhirCriteriaContext<Concept> criteriaContext = createCriteriaContext(Concept.class);
createConceptMapCriteriaBuilder(criteriaContext, conceptSource, mappingCode);

//TODO: Change back to method
OpenmrsFhirCriteriaContext<ConceptMap> xontext = createCriteriaContext(ConceptMap.class);
xontext.getCriteriaQuery().select(xontext.getRoot().get("concept"));
Join<ConceptReferenceTerm, ConceptMap> termJoin = xontext.getRoot().join("conceptReferenceTerm");
Join<ConceptMap, ConceptMapType> mapTypeJoin = xontext.getRoot().join("conceptMapType");
Join<ConceptMap, Concept> conceptJoin = xontext.getRoot().join("concept");

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

xontext.addPredicate(xontext.getCriteriaBuilder().equal(termJoin.get("conceptSource"), conceptSource));
xontext.finalizeQuery();
//TODO: method stops here

criteriaContext.addPredicate(criteriaContext.getCriteriaBuilder()
.or(criteriaContext.getCriteriaBuilder().equal(criteriaContext.getRoot().get("uuid"),
.or(criteriaContext.getCriteriaBuilder().equal(mapTypeJoin.get("uuid"),
ConceptMapType.SAME_AS_MAP_TYPE_UUID),
criteriaContext.getCriteriaBuilder().equal(criteriaContext.getRoot().get("name"), "SAME-AS")));
criteriaContext.getCriteriaBuilder().equal(mapTypeJoin.get("name"), "SAME-AS")));

criteriaContext.addOrder(criteriaContext.getCriteriaBuilder().asc(criteriaContext.getRoot().get("retired")));
criteriaContext.addOrder(criteriaContext.getCriteriaBuilder().asc(conceptJoin.get("retired")));
criteriaContext.finalizeQuery();

return Optional.ofNullable(
Expand All @@ -70,9 +88,26 @@ public List<Concept> getConceptsWithAnyMappingInSource(@Nonnull ConceptSource co
}

OpenmrsFhirCriteriaContext<Concept> criteriaContext = createCriteriaContext(Concept.class);
createConceptMapCriteriaBuilder(criteriaContext, conceptSource, mappingCode);
criteriaContext.getCriteriaQuery()
.orderBy(criteriaContext.getCriteriaBuilder().asc(criteriaContext.getRoot().get("retired"))).distinct(true);

//TODO: Change back to method
OpenmrsFhirCriteriaContext<ConceptMap> xontext = createCriteriaContext(ConceptMap.class);
xontext.getCriteriaQuery().select(xontext.getRoot().get("concept"));
Join<ConceptMap, ConceptReferenceTerm> termJoin = xontext.getRoot().join("conceptReferenceTerm");
Join<ConceptMap, ConceptMapType> mapTypeJoin = xontext.getRoot().join("conceptMapType");
Join<ConceptMap, Concept> conceptJoin = xontext.getRoot().join("concept");

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

xontext.addPredicate(xontext.getCriteriaBuilder().equal(termJoin.get("conceptSource"), conceptSource));
xontext.finalizeQuery();
//TODO: method stops here

criteriaContext.addOrder(criteriaContext.getCriteriaBuilder().asc(conceptJoin.get("retired")));

return criteriaContext.getEntityManager().createQuery(criteriaContext.getCriteriaQuery()).getResultList();
}
Expand All @@ -97,25 +132,21 @@ protected void handleTitle(OpenmrsFhirCriteriaContext<Concept> criteriaContext,
criteriaContext.finalizeQuery();
}

protected void createConceptMapCriteriaBuilder(OpenmrsFhirCriteriaContext<Concept> criteriaContext,
@Nonnull ConceptSource conceptSource, String mappingCode) {
criteriaContext.getCriteriaQuery().select(criteriaContext.getRoot().get("concept"));

Join<ConceptMap, ConceptReferenceTerm> term = criteriaContext.getRoot().join("conceptReferenceTerm");
@SuppressWarnings("unused")
Join<ConceptMap, ConceptMapType> mapType = criteriaContext.getRoot().join("conceptMapType");
@SuppressWarnings("unused")
Join<ConceptMap, Concept> concept = criteriaContext.getRoot().join("concept");

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

criteriaContext.addPredicate(criteriaContext.getCriteriaBuilder().equal(term.get("conceptSource"), conceptSource));
criteriaContext.finalizeQuery();
}

// 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");
// Join<ConceptMap, ConceptMapType> mapTypeJoin = criteriaContext.getRoot().join("conceptMapType");
// Join<ConceptMap, Concept> conceptJoin = criteriaContext.getRoot().join("concept");
//
// if (Context.getAdministrationService().isDatabaseStringComparisonCaseSensitive()) {
// criteriaContext.addPredicate(criteriaContext.getCriteriaBuilder()
// .equal(criteriaContext.getCriteriaBuilder().lower(termJoin.get("code")), mappingCode.toLowerCase()));
// } else {
// criteriaContext.addPredicate(criteriaContext.getCriteriaBuilder().equal(termJoin.get("code"), mappingCode));
// }
//
// criteriaContext.addPredicate(criteriaContext.getCriteriaBuilder().equal(termJoin.get("conceptSource"), conceptSource));
// criteriaContext.finalizeQuery();
// }
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,11 @@ public Collection<FhirConceptSource> getFhirConceptSources() {
public Optional<FhirConceptSource> getFhirConceptSourceByUrl(@Nonnull String url) {
OpenmrsFhirCriteriaContext<FhirConceptSource> criteriaContext = openmrsFhirCriteriaContext();
criteriaContext.getCriteriaQuery().select(criteriaContext.getRoot());

criteriaContext.addPredicate(criteriaContext.getCriteriaBuilder().equal(criteriaContext.getRoot().get("url"), url));
criteriaContext
.addPredicate(criteriaContext.getCriteriaBuilder().equal(criteriaContext.getRoot().get("retired"), false));
criteriaContext.addPredicate(criteriaContext.getCriteriaBuilder().equal(criteriaContext.getRoot().get("retired"), false));

return criteriaContext.getEntityManager().createQuery(criteriaContext.getCriteriaQuery()).setMaxResults(1)
.getResultList().stream().findFirst();
return Optional.ofNullable(criteriaContext.getEntityManager().createQuery(criteriaContext.finalizeQuery()).getSingleResult());
}

@Override
Expand All @@ -70,15 +69,14 @@ public Optional<FhirConceptSource> getFhirConceptSourceByConceptSourceName(@Nonn
OpenmrsFhirCriteriaContext<FhirConceptSource> criteriaContext = openmrsFhirCriteriaContext();
criteriaContext.getCriteriaQuery().select(criteriaContext.getRoot());

Join<FhirConceptSource, ConceptSource> conceptSource = criteriaContext.getRoot().join("conceptSource");
Join<FhirConceptSource, ConceptSource> conceptSourceJoin = criteriaContext.getRoot().join("conceptSource");

criteriaContext.addPredicate(criteriaContext.getCriteriaBuilder().equal(conceptSourceJoin.get("name"), sourceName));
criteriaContext.addPredicate(criteriaContext.getCriteriaBuilder().equal(conceptSourceJoin.get("voided"), false));

criteriaContext.addPredicate(criteriaContext.getCriteriaBuilder().equal(conceptSource.get("name"), sourceName));
criteriaContext.addPredicate(criteriaContext.getCriteriaBuilder().equal(conceptSource.get("voided"), false));
criteriaContext
.addPredicate(criteriaContext.getCriteriaBuilder().equal(criteriaContext.getRoot().get("voided"), false));
criteriaContext.addPredicate(criteriaContext.getCriteriaBuilder().equal(criteriaContext.getRoot().get("voided"), false));

return Optional.ofNullable(
criteriaContext.getEntityManager().createQuery(criteriaContext.getCriteriaQuery()).getSingleResult());
return Optional.ofNullable(criteriaContext.getEntityManager().createQuery(criteriaContext.finalizeQuery()).getSingleResult());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,9 @@ public class FhirContactPointMapDaoImpl implements FhirContactPointMapDao {
@Override
public Optional<FhirContactPointMap> getFhirContactPointMapByUuid(String uuid) {
OpenmrsFhirCriteriaContext<FhirContactPointMap> criteriaContext = openmrsFhirCriteriaContext();
criteriaContext
.addPredicate(criteriaContext.getCriteriaBuilder().equal(criteriaContext.getRoot().get("uuid"), uuid));
criteriaContext.addPredicate(criteriaContext.getCriteriaBuilder().equal(criteriaContext.getRoot().get("uuid"), uuid));

return Optional.ofNullable(
criteriaContext.getEntityManager().createQuery(criteriaContext.getCriteriaQuery()).getSingleResult());
return Optional.ofNullable(criteriaContext.getEntityManager().createQuery(criteriaContext.finalizeQuery()).getSingleResult());
}

@Override
Expand Down

0 comments on commit 06850a9

Please sign in to comment.