@Override public int hashCode() { return Objects.hash(getValue(), getPrefix()); }
@Override public String toString() { ToStringBuilder b = new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE); b.append("prefix", getPrefix()); b.append("value", getValueAsString()); return b.build(); }
@Override String doGetValueAsQueryToken(FhirContext theContext) { StringBuilder b = new StringBuilder(); if (getPrefix() != null) { b.append(ParameterUtil.escapeWithDefault(getPrefix().getValue())); } if (myValue != null) { b.append(ParameterUtil.escapeWithDefault(myValue.getValueAsString())); } return b.toString(); }
/** * Accepts values with or without a prefix (e.g. <code>gt2011-01-01</code> and <code>2011-01-01</code>). * If no prefix is provided in the given value, the {@link #getPrefix() existing prefix} is preserved */ public void setValueAsString(String theDate) { if (isNotBlank(theDate)) { ParamPrefixEnum existingPrefix = getPrefix(); myValue.setValueAsString(super.extractPrefixAndReturnRest(theDate)); if (getPrefix() == null) { setPrefix(existingPrefix); } } else { myValue.setValue(null); } }
@Override public String toString() { StringBuilder b = new StringBuilder(); b.append(getClass().getSimpleName()); b.append("["); if (hasBound(myLowerBound)) { if (myLowerBound.getPrefix() != null) { b.append(myLowerBound.getPrefix().getValue()); } b.append(myLowerBound.getValueAsString()); } if (hasBound(myUpperBound)) { if (hasBound(myLowerBound)) { b.append(" "); } if (myUpperBound.getPrefix() != null) { b.append(myUpperBound.getPrefix().getValue()); } b.append(myUpperBound.getValueAsString()); } else { if (!hasBound(myLowerBound)) { b.append("empty"); } } b.append("]"); return b.toString(); }
@Search() public List<Patient> searchByObservationNames( @RequiredParam(name=Patient.SP_BIRTHDATE) DateParam theDate ) { ParamPrefixEnum prefix = theDate.getPrefix(); // e.g. gt, le, etc.. Date date = theDate.getValue(); // e.g. 2011-01-02 TemporalPrecisionEnum precision = theDate.getPrecision(); // e.g. DAY List<Patient> retVal = new ArrayList<Patient>(); // ...populate... return retVal; } //END SNIPPET: dates
public Date getLowerBoundAsInstant() { if (myLowerBound == null || myLowerBound.getValue() == null) { return null; } Date retVal = myLowerBound.getValue(); if (myLowerBound.getPrecision().ordinal() <= TemporalPrecisionEnum.DAY.ordinal()) { Calendar cal = DateUtils.toCalendar(retVal); cal.setTimeZone(TimeZone.getTimeZone("GMT-11:30")); cal = DateUtils.truncate(cal, Calendar.DATE); retVal = cal.getTime(); } if (myLowerBound.getPrefix() != null) { switch (myLowerBound.getPrefix()) { case GREATERTHAN: case STARTS_AFTER: retVal = myLowerBound.getPrecision().add(retVal, 1); break; case EQUAL: case GREATERTHAN_OR_EQUALS: break; case LESSTHAN: case APPROXIMATE: case LESSTHAN_OR_EQUALS: case ENDS_BEFORE: case NOT_EQUAL: throw new IllegalStateException("Unvalid lower bound comparator: " + myLowerBound.getPrefix()); } } return retVal; }
private void addParam(DateParam theParsed) throws InvalidRequestException { if (theParsed.getPrefix() == null || theParsed.getPrefix() == EQUAL) { if (myLowerBound != null || myUpperBound != null) { throw new InvalidRequestException("Can not have multiple date range parameters for the same param without a qualifier"); switch (theParsed.getPrefix()) { case GREATERTHAN: case GREATERTHAN_OR_EQUALS: break; default: throw new InvalidRequestException("Unknown comparator: " + theParsed.getPrefix());
if (lowerBound.getPrefix() == null) { lowerBound.setPrefix(GREATERTHAN_OR_EQUALS); switch (lowerBound.getPrefix()) { case GREATERTHAN: case GREATERTHAN_OR_EQUALS: case LESSTHAN: case LESSTHAN_OR_EQUALS: throw new DataFormatException("Lower bound comparator must be > or >=, can not be " + lowerBound.getPrefix().getValue()); if (upperBound.getPrefix() == null) { upperBound.setPrefix(LESSTHAN_OR_EQUALS); switch (upperBound.getPrefix()) { case LESSTHAN: case LESSTHAN_OR_EQUALS: case GREATERTHAN: case GREATERTHAN_OR_EQUALS: throw new DataFormatException("Upper bound comparator must be < or <=, can not be " + upperBound.getPrefix().getValue());
throw new IllegalArgumentException("theDateParam can not be empty"); if (theDateParam.getPrefix() == null) { setRangeFromDatesInclusive(theDateParam.getValueAsString(), theDateParam.getValueAsString()); } else { switch (theDateParam.getPrefix()) { case EQUAL: setRangeFromDatesInclusive(theDateParam.getValueAsString(), theDateParam.getValueAsString()); default: throw new InvalidRequestException("Invalid comparator for date range parameter:" + theDateParam.getPrefix() + ". This is a bug.");
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 {
@Override public void setValuesAsQueryTokens(FhirContext theContext, String theParamName, List<QualifiedParamList> theParameters) throws InvalidRequestException { boolean haveHadUnqualifiedParameter = false; for (QualifiedParamList paramList : theParameters) { if (paramList.size() == 0) { continue; } if (paramList.size() > 1) { throw new InvalidRequestException("DateRange parameter does not suppport OR queries"); } String param = paramList.get(0); /* * Since ' ' is escaped as '+' we'll be nice to anyone might have accidentally not * escaped theirs */ param = param.replace(' ', '+'); DateParam parsed = new DateParam(); parsed.setValueAsQueryToken(theContext, theParamName, paramList.getQualifier(), param); addParam(parsed); if (parsed.getPrefix() == null) { if (haveHadUnqualifiedParameter) { throw new InvalidRequestException("Multiple date parameters with the same name and no qualifier (>, <, etc.) is not supported"); } haveHadUnqualifiedParameter = true; } } }
@Override public int hashCode() { return Objects.hash(getValue(), getPrefix()); }
@Override public String toString() { ToStringBuilder b = new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE); b.append("prefix", getPrefix()); b.append("value", getValueAsString()); return b.build(); }
@Override String doGetValueAsQueryToken(FhirContext theContext) { StringBuilder b = new StringBuilder(); if (getPrefix() != null) { b.append(ParameterUtil.escapeWithDefault(getPrefix().getValue())); } if (myValue != null) { b.append(ParameterUtil.escapeWithDefault(myValue.getValueAsString())); } return b.toString(); }
/** * Accepts values with or without a prefix (e.g. <code>gt2011-01-01</code> and <code>2011-01-01</code>). * If no prefix is provided in the given value, the {@link #getPrefix() existing prefix} is preserved */ public void setValueAsString(String theDate) { if (isNotBlank(theDate)) { ParamPrefixEnum existingPrefix = getPrefix(); myValue.setValueAsString(super.extractPrefixAndReturnRest(theDate)); if (getPrefix() == null) { setPrefix(existingPrefix); } } else { myValue.setValue(null); } }
public Date getLowerBoundAsInstant() { if (myLowerBound == null || myLowerBound.getValue() == null) { return null; } Date retVal = myLowerBound.getValue(); if (myLowerBound.getPrecision().ordinal() <= TemporalPrecisionEnum.DAY.ordinal()) { Calendar cal = DateUtils.toCalendar(retVal); cal.setTimeZone(TimeZone.getTimeZone("GMT-11:30")); cal = DateUtils.truncate(cal, Calendar.DATE); retVal = cal.getTime(); } if (myLowerBound.getPrefix() != null) { switch (myLowerBound.getPrefix()) { case GREATERTHAN: case STARTS_AFTER: retVal = myLowerBound.getPrecision().add(retVal, 1); break; case EQUAL: case GREATERTHAN_OR_EQUALS: break; case LESSTHAN: case APPROXIMATE: case LESSTHAN_OR_EQUALS: case ENDS_BEFORE: case NOT_EQUAL: throw new IllegalStateException("Unvalid lower bound comparator: " + myLowerBound.getPrefix()); } } return retVal; }