@Override public boolean matches(IQueryParameterType theParam) { if (!(theParam instanceof DateParam)) { return false; } DateParam date = (DateParam) theParam; DateRangeParam range = new DateRangeParam(date); Date lowerBound = range.getLowerBoundAsInstant(); Date upperBound = range.getUpperBoundAsInstant(); if (lowerBound == null && upperBound == null) { // should never happen return false; } boolean result = true; if (lowerBound != null) { result &= (myValueLow.after(lowerBound) || myValueLow.equals(lowerBound)); result &= (myValueHigh.after(lowerBound) || myValueHigh.equals(lowerBound)); } if (upperBound != null) { result &= (myValueLow.before(upperBound) || myValueLow.equals(upperBound)); result &= (myValueHigh.before(upperBound) || myValueHigh.equals(upperBound)); } return result; }
public void setLastUpdated(DateRangeParam theLastUpdated) { if (theLastUpdated == null) { myLastUpdatedLow = null; myLastUpdatedHigh = null; } else { myLastUpdatedLow = theLastUpdated.getLowerBoundAsInstant(); myLastUpdatedHigh = theLastUpdated.getUpperBoundAsInstant(); } }
private Predicate createPredicateDateFromRange(CriteriaBuilder theBuilder, From<?, ResourceIndexedSearchParamDate> theFrom, DateRangeParam theRange) { Date lowerBound = theRange.getLowerBoundAsInstant(); Date upperBound = theRange.getUpperBoundAsInstant(); Predicate gt = theBuilder.greaterThanOrEqualTo(theFrom.get("myValueLow"), lowerBound); Predicate lt = theBuilder.greaterThanOrEqualTo(theFrom.get("myValueHigh"), lowerBound); if (theRange.getLowerBound().getPrefix() == ParamPrefixEnum.STARTS_AFTER || theRange.getLowerBound().getPrefix() == ParamPrefixEnum.EQUAL) { lb = gt; } else { Predicate gt = theBuilder.lessThanOrEqualTo(theFrom.get("myValueLow"), upperBound); Predicate lt = theBuilder.lessThanOrEqualTo(theFrom.get("myValueHigh"), upperBound); if (theRange.getUpperBound().getPrefix() == ParamPrefixEnum.ENDS_BEFORE || theRange.getUpperBound().getPrefix() == ParamPrefixEnum.EQUAL) { ub = lt; } else {
parameters.add(QualifiedParamList.singleton(paramValues[1])); DateRangeParam dateRangeParam = new DateRangeParam(); FhirContext ctx = theRequest.getServer().getFhirContext(); dateRangeParam.setValuesAsQueryTokens(ctx, myName, parameters); matchingParamValues.add(dateRangeParam); } else if (String.class.isAssignableFrom(myParameterType)) {
public DateRangeParam getLastUpdated() { if (myLastUpdatedLow == null && myLastUpdatedHigh == null) { return null; } else { return new DateRangeParam(myLastUpdatedLow, myLastUpdatedHigh); } }
DateParam lb = getLastUpdated().getLowerBound(); addLastUpdateParam(b, lb); DateParam ub = getLastUpdated().getUpperBound(); addLastUpdateParam(b, ub);
public boolean isEmpty() { return (getLowerBoundAsInstant() == null) && (getUpperBoundAsInstant() == null); }
private Predicate createPredicateDateFromRange(CriteriaBuilder theBuilder, From<?, ResourceIndexedSearchParamDate> theFrom, DateRangeParam theRange) { Date lowerBound = theRange.getLowerBoundAsInstant(); Date upperBound = theRange.getUpperBoundAsInstant(); Predicate gt = theBuilder.greaterThanOrEqualTo(theFrom.get("myValueLow"), lowerBound); Predicate lt = theBuilder.greaterThanOrEqualTo(theFrom.get("myValueHigh"), lowerBound); if (theRange.getLowerBound().getPrefix() == ParamPrefixEnum.STARTS_AFTER || theRange.getLowerBound().getPrefix() == ParamPrefixEnum.EQUAL) { lb = gt; } else { Predicate gt = theBuilder.lessThanOrEqualTo(theFrom.get("myValueLow"), upperBound); Predicate lt = theBuilder.lessThanOrEqualTo(theFrom.get("myValueHigh"), upperBound); if (theRange.getUpperBound().getPrefix() == ParamPrefixEnum.ENDS_BEFORE || theRange.getUpperBound().getPrefix() == ParamPrefixEnum.EQUAL) { ub = lt; } else {
throw new InvalidRequestException("Failed to parse match URL[" + theMatchUrl + "] - Can not have more than 2 " + Constants.PARAM_LASTUPDATED + " parameter repetitions"); } else { DateRangeParam p1 = new DateRangeParam(); p1.setValuesAsQueryTokens(myContext, nextParamName, paramList); paramMap.setLastUpdated(p1);
private Predicate createPredicateDate(IQueryParameterType theParam, String theResourceName, String theParamName, CriteriaBuilder theBuilder, From<?, ResourceIndexedSearchParamDate> theFrom) { Predicate p; if (theParam instanceof DateParam) { DateParam date = (DateParam) theParam; if (!date.isEmpty()) { DateRangeParam range = new DateRangeParam(date); p = createPredicateDateFromRange(theBuilder, theFrom, range); } else { // TODO: handle missing date param? p = null; } } else if (theParam instanceof DateRangeParam) { DateRangeParam range = (DateRangeParam) theParam; p = createPredicateDateFromRange(theBuilder, theFrom, range); } else { throw new IllegalArgumentException("Invalid token type: " + theParam.getClass()); } return combineParamIndexPredicateWithParamNamePredicate(theResourceName, theParamName, theFrom, p); }
@Search() public List<Observation> searchByDateRange( @RequiredParam(name=Observation.SP_DATE) DateRangeParam theRange ) { Date from = theRange.getLowerBoundAsInstant(); Date to = theRange.getUpperBoundAsInstant(); List<Observation> retVal = new ArrayList<Observation>(); // ...populate... return retVal; } //END SNIPPET: dateRange
protected DateRangeParam processSinceOrAt(Date theSince, DateRangeParam theAt) { boolean haveAt = theAt != null && (theAt.getLowerBoundAsInstant() != null || theAt.getUpperBoundAsInstant() != null); if (haveAt && theSince != null) { String msg = getContext().getLocalizer().getMessage(BaseJpaProvider.class, "cantCombintAtAndSince"); throw new InvalidRequestException(msg); } if (haveAt) { return theAt; } return new DateRangeParam(theSince, null); }
parameters.add(QualifiedParamList.singleton(paramValues[1])); DateRangeParam dateRangeParam = new DateRangeParam(); FhirContext ctx = theRequest.getServer().getFhirContext(); dateRangeParam.setValuesAsQueryTokens(ctx, myName, parameters); matchingParamValues.add(dateRangeParam); } else if (String.class.isAssignableFrom(myParameterType)) {
public DateRangeParam getLastUpdated() { if (myLastUpdatedLow == null && myLastUpdatedHigh == null) { return null; } else { return new DateRangeParam(myLastUpdatedLow, myLastUpdatedHigh); } }
private static List<Predicate> createLastUpdatedPredicates(final DateRangeParam theLastUpdated, CriteriaBuilder builder, From<?, ResourceTable> from) { List<Predicate> lastUpdatedPredicates = new ArrayList<>(); if (theLastUpdated != null) { if (theLastUpdated.getLowerBoundAsInstant() != null) { ourLog.debug("LastUpdated lower bound: {}", new InstantDt(theLastUpdated.getLowerBoundAsInstant())); Predicate predicateLower = builder.greaterThanOrEqualTo(from.get("myUpdated"), theLastUpdated.getLowerBoundAsInstant()); lastUpdatedPredicates.add(predicateLower); } if (theLastUpdated.getUpperBoundAsInstant() != null) { Predicate predicateUpper = builder.lessThanOrEqualTo(from.get("myUpdated"), theLastUpdated.getUpperBoundAsInstant()); lastUpdatedPredicates.add(predicateUpper); } } return lastUpdatedPredicates; }
protected DateRangeParam processSinceOrAt(Date theSince, DateRangeParam theAt) { boolean haveAt = theAt != null && (theAt.getLowerBoundAsInstant() != null || theAt.getUpperBoundAsInstant() != null); if (haveAt && theSince != null) { String msg = getContext().getLocalizer().getMessage(BaseJpaProvider.class, "cantCombintAtAndSince"); throw new InvalidRequestException(msg); } if (haveAt) { return theAt; } return new DateRangeParam(theSince, null); }
private Predicate createPredicateDate(IQueryParameterType theParam, String theResourceName, String theParamName, CriteriaBuilder theBuilder, From<?, ResourceIndexedSearchParamDate> theFrom) { Predicate p; if (theParam instanceof DateParam) { DateParam date = (DateParam) theParam; if (!date.isEmpty()) { DateRangeParam range = new DateRangeParam(date); p = createPredicateDateFromRange(theBuilder, theFrom, range); } else { // TODO: handle missing date param? p = null; } } else if (theParam instanceof DateRangeParam) { DateRangeParam range = (DateRangeParam) theParam; p = createPredicateDateFromRange(theBuilder, theFrom, range); } else { throw new IllegalArgumentException("Invalid token type: " + theParam.getClass()); } return combineParamIndexPredicateWithParamNamePredicate(theResourceName, theParamName, theFrom, p); }
@History public IBundleProvider historyServer(HttpServletRequest theRequest, @Since Date theDate, @At DateRangeParam theAt, RequestDetails theRequestDetails) { startRequest(theRequest); try { DateRangeParam range = super.processSinceOrAt(theDate, theAt); return myDao.history(range.getLowerBoundAsInstant(), range.getUpperBoundAsInstant(), theRequestDetails); } finally { endRequest(theRequest); } }
.include(Patient.INCLUDE_CAREPROVIDER.asNonRecursive()) .revInclude(Provenance.INCLUDE_TARGET) .lastUpdated(new DateRangeParam("2011-01-01", null)) .sort().ascending(Patient.BIRTHDATE) .sort().descending(Patient.NAME).limitTo(123)
@History public IBundleProvider getHistoryForResourceType( HttpServletRequest theRequest, @Since Date theSince, @At DateRangeParam theAt, RequestDetails theRequestDetails) { startRequest(theRequest); try { DateRangeParam sinceOrAt = processSinceOrAt(theSince, theAt); return myDao.history(sinceOrAt.getLowerBoundAsInstant(), sinceOrAt.getUpperBoundAsInstant(), theRequestDetails); } finally { endRequest(theRequest); } }