use of org.hibernate.criterion.MatchMode in project openmrs-core by openmrs.
the class PatientSearchCriteria method getCriterionForLongName.
private Criterion getCriterionForLongName(String name, boolean includeVoided) {
MatchMode matchMode = getMatchMode();
Criterion criterion = Restrictions.disjunction().add(Restrictions.like("name.givenName", name, matchMode)).add(Restrictions.like("name.middleName", name, matchMode)).add(Restrictions.like("name.familyName", name, matchMode)).add(Restrictions.like("name.familyName2", name, matchMode));
if (!includeVoided) {
return Restrictions.conjunction().add(Restrictions.eq("name.voided", false)).add(criterion);
}
return criterion;
}
use of org.hibernate.criterion.MatchMode in project openmrs-core by openmrs.
the class PatientSearchCriteria method getCriterionForNoExactName.
private Criterion getCriterionForNoExactName(String name, boolean includeVoided) {
MatchMode matchMode = getMatchMode();
Criterion criterion = Restrictions.conjunction().add(Restrictions.disjunction().add(Restrictions.conjunction().add(Restrictions.isNotNull("name.givenName")).add(Restrictions.like("name.givenName", name, matchMode))).add(Restrictions.conjunction().add(Restrictions.isNotNull("name.middleName")).add(Restrictions.like("name.middleName", name, matchMode))).add(Restrictions.conjunction().add(Restrictions.isNotNull("name.familyName")).add(Restrictions.like("name.familyName", name, matchMode))).add(Restrictions.conjunction().add(Restrictions.isNotNull("name.familyName2")).add(Restrictions.like("name.familyName2", name, matchMode)))).add(Restrictions.disjunction().add(Restrictions.isNull("name.givenName")).add(Restrictions.ne("name.givenName", name))).add(Restrictions.disjunction().add(Restrictions.isNull("name.middleName")).add(Restrictions.ne("name.middleName", name))).add(Restrictions.disjunction().add(Restrictions.isNull("name.familyName")).add(Restrictions.ne("name.familyName", name))).add(Restrictions.disjunction().add(Restrictions.isNull("name.familyName2")).add(Restrictions.ne("name.familyName2", name)));
if (!includeVoided) {
return Restrictions.conjunction().add(Restrictions.eq("name.voided", false)).add(criterion);
}
return criterion;
}
use of org.hibernate.criterion.MatchMode in project openmrs-core by openmrs.
the class HibernateProviderDAO method getNameSearchExpression.
/**
* Creates or that matches the input name with Provider-Person-Names (not voided)
*
* @param name
* @return Junction
*/
private Junction getNameSearchExpression(String name) {
MatchMode mode = MatchMode.ANYWHERE;
Conjunction and = Restrictions.conjunction();
and.add(Restrictions.eq("personName.voided", false));
Disjunction or = Restrictions.disjunction();
and.add(or);
or.add(Restrictions.ilike("personName.givenName", name, mode));
or.add(Restrictions.ilike("personName.middleName", name, mode));
or.add(Restrictions.ilike("personName.familyName", name, mode));
or.add(Restrictions.ilike("personName.familyName2", name, mode));
return and;
}
use of org.hibernate.criterion.MatchMode in project openmrs-core by openmrs.
the class PatientSearchCriteria method prepareCriterionForAttribute.
private Criterion prepareCriterionForAttribute(String query, boolean includeVoided) {
query = HibernateUtil.escapeSqlWildcards(query, sessionFactory);
Conjunction conjunction = Restrictions.conjunction();
MatchMode matchMode = personSearchCriteria.getAttributeMatchMode();
String[] queryParts = getQueryParts(query);
for (String queryPart : queryParts) {
conjunction.add(personSearchCriteria.prepareCriterionForAttribute(queryPart, includeVoided, matchMode));
}
return conjunction;
}
use of org.hibernate.criterion.MatchMode in project openmrs-core by openmrs.
the class HibernateEncounterDAO method createEncounterByQueryCriteria.
/**
* Utility method that returns a criteria for searching for patient encounters that match the
* specified search phrase
*
* @param query patient name or identifier
* @param patientId the patient id
* @param includeVoided Specifies whether voided encounters should be included
* @param orderByNames specifies whether the encounters should be ordered by person names
* @return Criteria
*/
private Criteria createEncounterByQueryCriteria(String query, Integer patientId, boolean includeVoided, boolean orderByNames) {
Criteria criteria = sessionFactory.getCurrentSession().createCriteria(Encounter.class, "enc");
if (!includeVoided) {
criteria.add(Restrictions.eq("enc.voided", false));
}
criteria = criteria.createCriteria("patient", "pat");
if (patientId != null) {
criteria.add(Restrictions.eq("pat.patientId", patientId));
if (StringUtils.isNotBlank(query)) {
criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
// match on location.name, encounterType.name, form.name
// provider.name, provider.identifier, provider.person.names
MatchMode mode = MatchMode.ANYWHERE;
criteria.createAlias("enc.location", "loc");
criteria.createAlias("enc.encounterType", "encType");
criteria.createAlias("enc.form", "form");
criteria.createAlias("enc.encounterProviders", "enc_prov");
criteria.createAlias("enc_prov.provider", "prov");
criteria.createAlias("prov.person", "person", JoinType.LEFT_OUTER_JOIN);
criteria.createAlias("person.names", "personName", JoinType.LEFT_OUTER_JOIN);
Disjunction or = Restrictions.disjunction();
or.add(Restrictions.ilike("loc.name", query, mode));
or.add(Restrictions.ilike("encType.name", query, mode));
or.add(Restrictions.ilike("form.name", query, mode));
or.add(Restrictions.ilike("prov.name", query, mode));
or.add(Restrictions.ilike("prov.identifier", query, mode));
String[] splitNames = query.split(" ");
Disjunction nameOr = Restrictions.disjunction();
for (String splitName : splitNames) {
nameOr.add(Restrictions.ilike("personName.givenName", splitName, mode));
nameOr.add(Restrictions.ilike("personName.middleName", splitName, mode));
nameOr.add(Restrictions.ilike("personName.familyName", splitName, mode));
nameOr.add(Restrictions.ilike("personName.familyName2", splitName, mode));
}
// OUTPUT for provider criteria:
// prov.name like '%query%' OR prov.identifier like '%query%'
// OR ( personName.voided = false
// AND ( personName.givenName like '%query%'
// OR personName.middleName like '%query%'
// OR personName.familyName like '%query%'
// OR personName.familyName2 like '%query%'
// )
// )
Conjunction personNameConjuction = Restrictions.conjunction();
personNameConjuction.add(Restrictions.eq("personName.voided", false));
personNameConjuction.add(nameOr);
or.add(personNameConjuction);
criteria.add(or);
}
} else {
// As identifier could be all alpha, no heuristic here will work in determining intent of user for querying by name versus identifier
// So search by both!
criteria = new PatientSearchCriteria(sessionFactory, criteria).prepareCriteria(query, query, new ArrayList<>(), true, orderByNames, true);
}
return criteria;
}
Aggregations