private List<Predicate> getValuePredicate(StoredQueryParam param, StringPath valuePath) { List<Predicate> predicates = new ArrayList<Predicate>(); List<String> values; for (int i = 0, len = param.getNumberOfANDElements(); i < len; i++) { values = param.isMultiValue() ? param.getMultiValues(i) : Arrays.asList(param.getStringValue()); BooleanBuilder predicate = new BooleanBuilder(); List<String> eqValues = new ArrayList<String>(); for (String v : values) { if (v.indexOf('%') != -1 || v.indexOf('_') != -1) { predicate.or(valuePath.like(v)); } else { eqValues.add(v); } } if (eqValues.size() > 0) { if (eqValues.size() > 1) { predicate.or(valuePath.in(eqValues)); } else { predicate.or(valuePath.eq(eqValues.get(0))); } } predicates.add(predicate); } return predicates; }
/** * Adds a match against RegistryObjectIndex, i.e. the indexed fields from the blob xml. </br> Uses * OR for multi values and LIKE to match. */ protected void addIndexMatch( BooleanBuilder builder, NumberPath<Long> registryObjectPk, StoredQueryParam param, XDSSearchIndexKey key) { // No match needed if param not specified if (param == null) return; QRegistryObjectIndex index = QRegistryObjectIndex.registryObjectIndex; // perform an OR for the list of values in QueryParam BooleanExpression orExpr; BooleanBuilder andBuilder = new BooleanBuilder(); List<String> values; for (int i = 0, len = param.getNumberOfANDElements(); i < len; i++) { orExpr = null; if (param.isMultiValue()) { values = param.getMultiValues(i); for (String val : values) orExpr = orExpr == null ? index.value.like(val) : orExpr.or(index.value.like(val)); } else { orExpr = index.value.like(param.getStringValue()); } andBuilder.and(orExpr); } // add this expression as subquery JPASubQuery subq = new JPASubQuery() .from(index) .where(index.subject.pk.eq(registryObjectPk).and(index.key.eq(key)).and(andBuilder)); builder.and(subq.exists()); }
protected XDSDocumentEntry getDocumentEntry() throws XDSException { StoredQueryParam param; XDSDocumentEntry doc; if ((param = getQueryParam(XDSConstants.QRY_DOCUMENT_UNIQUE_ID)) != null) { if (getQueryParam(XDSConstants.QRY_DOCUMENT_ENTRY_UUID) != null) { throw new XDSException( XDSException.XDS_ERR_REGISTRY_ERROR, "Both $XDSDocumentEntryUUID and $XDSDocumentEntryUniqueId are specified!", null); } doc = getSession().getDocumentEntryByUniqueId(param.getStringValue()); } else { param = getQueryParam(XDSConstants.QRY_DOCUMENT_ENTRY_UUID); doc = getSession().getDocumentEntryByUUID(param.getStringValue()); } log.debug("#### Found Document:" + doc); return doc; }
protected void addStatusMatch( BooleanBuilder builder, StringPath status, StoredQueryParam statusParam) { List<String> stati = statusParam.getMultiValues(0); if (stati == null) { builder.and(status.eq(statusParam.getStringValue())); } else if (stati.size() == 1) { builder.and(status.eq(stati.get(0))); } else if (stati.size() > 1) { builder.and(status.in(stati)); } }
protected void addFromToMatch( BooleanBuilder builder, StoredQueryParam fromParam, StoredQueryParam toParam, NumberPath<Long> subselectJoinPk, String slotName) { String from = fromParam == null ? null : XDSUtil.normalizeDTM(fromParam.getStringValue(), false); String to = toParam == null ? null : XDSUtil.normalizeDTM(toParam.getStringValue(), true); if (from != null || to != null) { Predicate fromTo = from == null ? QSlot.slot.value.loe(to) : to != null ? ExpressionUtils.allOf(QSlot.slot.value.goe(from), QSlot.slot.value.loe(to)) : QSlot.slot.value.goe(from); builder.and( new JPASubQuery() .from(QSlot.slot) .where(QSlot.slot.parent.pk.eq(subselectJoinPk), QSlot.slot.name.eq(slotName), fromTo) .exists()); } }
protected void addPatientIdMatch(BooleanBuilder builder, StoredQueryParam pid) throws XDSException { if (pid.isMultiValue()) throw new XDSException( XDSException.XDS_ERR_STORED_QUERY_PARAM_NUMBER, this.getClass().getSimpleName() + " - " + pid.getName() + " only accepts a single value but is coded with multiple values!", null); try { XADPatient qryPat = new XADPatient(pid.getStringValue()); patID = qryPat.getCXPatientID(); builder.and(QXADPatient.xADPatient.patientID.eq(qryPat.getPatientID())); builder.and( QXADIssuer.xADIssuer.universalID.eq(qryPat.getIssuerOfPatientID().getUniversalID())); builder.and(QXADPatient.xADPatient.linkedPatient.isNull()); } catch (Exception x) { throw new XDSException( XDSException.XDS_ERR_PATID_DOESNOT_MATCH, "PatientID is not correct! " + x.getMessage(), null); } }