Criteria criteria = new Criteria();
if(StringUtils.isNotEmpty(payeeIdentifier)){
criteria.orOperator(Criteria.where(MAPPING + "." + NPI).is(payeeIdentifier),
Criteria.where(MAPPING + "." + GROUP_NAME).regex(CriteriaBuilder.toRegexAny(payeeIdentifier), CASE_INSENSITIVE),
Criteria.where(MAPPING + "." + PROVIDER_NAME).regex(CriteriaBuilder.toRegexAny(payeeIdentifier), CASE_INSENSITIVE),
Criteria.where(MAPPING + "." + LAST_NAME).regex(CriteriaBuilder.toRegexAny(payeeIdentifier), CASE_INSENSITIVE),
Criteria.where(MAPPING + "." + PROVIDER_FULL_NAME).regex(CriteriaBuilder.toRegexAny(payeeIdentifier), CASE_INSENSITIVE),
Criteria.where(MAPPING + "." + FEIN).is(payeeIdentifier));
}
if(isSNPI){
criteria.orOperator(
Criteria.where(REQUEST_TYPE).is(GROUP).andOperator(Criteria.where(MAPPING + "." + IS_SNPI_ALLOWED).is(true)),
Criteria.where(REQUEST_TYPE).ne(GROUP)
);
}
final Query query = new Query();
query.addCriteria(criteria);
If payeeIdentifier contains identifying data and isSNPI is also true getting this exception : "InvalidMongoDbApiUsageException: Due to limitations of the com.mongodb.BasicDocument, you can't add a second '$or' expression specified as '$or : [Document{{requestType=group, $and=[Document{{mapping.isSNPIAllowed=true}}]}}, Document{{requestType=Document{{$ne=group}}}}]'. Criteria already contains '$or : [Document{{mapping.npi=g3}}, Document{{mapping.groupName=.\Qg3\E.}}, Document{{mapping.providerName=.\Qg3\E.}}, Document{{mapping.lastName=.\Qg3\E.}}, Document{{mapping.providerFullName=.\Qg3\E.}}, Document{{mapping.fein=g3}}]'." }