From f52ed02fa409e781bc5e23c72c2c7fc7217e00c5 Mon Sep 17 00:00:00 2001 From: jamesagnew Date: Tue, 20 May 2014 18:28:13 -0400 Subject: [PATCH] Get all of the tests passing again --- hapi-fhir-base/pom.xml | 7 +- .../fhir/model/api/IQueryParameterType.java | 4 +- .../fhir/model/dstu/composite/CodingDt.java | 3 +- .../model/dstu/composite/IdentifierDt.java | 3 +- .../fhir/model/dstu/composite/QuantityDt.java | 3 +- .../ca/uhn/fhir/model/primitive/StringDt.java | 3 +- .../java/ca/uhn/fhir/rest/api/SortSpec.java | 72 +++++++++++-- .../uhn/fhir/rest/client/GenericClient.java | 2 +- .../fhir/rest/method/QualifiedParamList.java | 2 +- .../uhn/fhir/rest/param/DateRangeParam.java | 8 +- .../fhir/rest/param/QualifiedDateParam.java | 3 +- .../uhn/fhir/rest/param/ReferenceParam.java | 2 +- .../ca/uhn/fhir/rest/param/SortParameter.java | 41 ++++--- .../ca/uhn/fhir/rest/param/StringParam.java | 3 +- .../RestfulPatientResourceProviderMore.java | 44 ++++++++ .../src/site/xdoc/doc_rest_operations.xml | 37 +++++++ .../fhir/rest/client/GenericClientTest.java | 2 +- .../uhn/fhir/rest/client/SortClientTest.java | 101 ++++++++++++++++++ .../rest/server/ResfulServerMethodTest.java | 26 +++-- .../server/ServerConformanceProviderTest.java | 3 +- .../ca/uhn/fhir/rest/server/SortTest.java | 90 ++++++++-------- .../ca/uhn/fhir/testmodel/IdentifierDt.java | 3 +- hapi-fhir-jpaserver-base/pom.xml | 4 +- .../fhir/jpa/entity/BaseResourceTable.java | 2 +- .../ResourceIndexedSearchParamDate.java | 2 +- .../ResourceIndexedSearchParamNumber.java | 2 +- .../ResourceIndexedSearchParamString.java | 2 +- .../ResourceIndexedSearchParamToken.java | 2 +- .../uhn/fhir/jpa/dao/FhirResourceDaoTest.java | 2 +- hapi-fhir-jpaserver-test/.classpath | 1 + hapi-fhir-jpaserver-test/pom.xml | 6 +- .../test/CompleteResourceProviderTest.java | 0 .../java/ca/uhn/fhir/jpa/test/JpaTestApp.java | 0 .../test/QuestionnaireResourceProvider.java | 0 .../fhir/jpa/test/UploadTestResources.java | 0 .../resources/fhir-spring-test-config.xml | 0 .../resources/fhir_jpatest_persistence.xml | 0 hapi-fhir-structures-dstu/pom.xml | 6 +- hapi-tinder-plugin/.classpath | 1 - hapi-tinder-plugin/.project | 33 +++--- .../org.eclipse.core.resources.prefs | 5 + .../.settings/org.eclipse.jdt.core.prefs | 18 ++-- .../.settings/org.eclipse.m2e.core.prefs | 4 + hapi-tinder-plugin/pom.xml | 4 +- .../uhn/fhir/tinder/TinderStructuresMojo.java | 2 +- .../tinder/parser/BaseStructureParser.java | 23 ++-- .../src/main/resources/vm/dt_composite.vm | 77 ++++++++++++- .../src/main/resources/vm/resource.vm | 4 +- hapi-tinder-test/pom.xml | 6 +- pom.xml | 2 +- restful-server-example/pom.xml | 2 +- restful-server-example/pom.xml.versionsBackup | 62 +++++++++++ 52 files changed, 561 insertions(+), 173 deletions(-) create mode 100644 hapi-fhir-base/src/test/java/ca/uhn/fhir/rest/client/SortClientTest.java rename hapi-fhir-jpaserver-test/src/{main => test}/java/ca/uhn/fhir/jpa/test/CompleteResourceProviderTest.java (100%) rename hapi-fhir-jpaserver-test/src/{main => test}/java/ca/uhn/fhir/jpa/test/JpaTestApp.java (100%) rename hapi-fhir-jpaserver-test/src/{main => test}/java/ca/uhn/fhir/jpa/test/QuestionnaireResourceProvider.java (100%) rename hapi-fhir-jpaserver-test/src/{main => test}/java/ca/uhn/fhir/jpa/test/UploadTestResources.java (100%) rename hapi-fhir-jpaserver-test/src/{main => test}/resources/fhir-spring-test-config.xml (100%) rename hapi-fhir-jpaserver-test/src/{main => test}/resources/fhir_jpatest_persistence.xml (100%) create mode 100644 hapi-tinder-plugin/.settings/org.eclipse.core.resources.prefs create mode 100644 hapi-tinder-plugin/.settings/org.eclipse.m2e.core.prefs create mode 100644 restful-server-example/pom.xml.versionsBackup diff --git a/hapi-fhir-base/pom.xml b/hapi-fhir-base/pom.xml index e764babbf50..5457e390169 100644 --- a/hapi-fhir-base/pom.xml +++ b/hapi-fhir-base/pom.xml @@ -5,7 +5,7 @@ ca.uhn.hapi.fhir hapi-fhir - 0.3 + 0.4-SNAPSHOT ../pom.xml @@ -286,6 +286,11 @@ + + org.apache.maven.plugins + maven-linkcheck-plugin + 1.1 + diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/model/api/IQueryParameterType.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/model/api/IQueryParameterType.java index 20a30bfb532..2458e9e2adc 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/model/api/IQueryParameterType.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/model/api/IQueryParameterType.java @@ -1,6 +1,5 @@ package ca.uhn.fhir.model.api; -import ca.uhn.fhir.context.FhirContext; /* * #%L @@ -55,8 +54,7 @@ public interface IQueryParameterType { * This method is generally only called by HAPI itself, and should not need to be called from user code. * * This method will return any qualifier that should be appended to the parameter name (e.g ":exact") - * @param theContext TODO */ - public String getQueryParameterQualifier(FhirContext theContext); + public String getQueryParameterQualifier(); } diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/model/dstu/composite/CodingDt.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/model/dstu/composite/CodingDt.java index 38e739f09b3..c4947031186 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/model/dstu/composite/CodingDt.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/model/dstu/composite/CodingDt.java @@ -38,7 +38,6 @@ package ca.uhn.fhir.model.dstu.composite; import java.util.List; -import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.model.api.BaseElement; import ca.uhn.fhir.model.api.ICompositeDatatype; import ca.uhn.fhir.model.api.IElement; @@ -429,7 +428,7 @@ public class CodingDt } @Override - public String getQueryParameterQualifier(FhirContext theContext) { + public String getQueryParameterQualifier() { return null; } diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/model/dstu/composite/IdentifierDt.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/model/dstu/composite/IdentifierDt.java index c91415cbed7..b7ddb9bfc13 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/model/dstu/composite/IdentifierDt.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/model/dstu/composite/IdentifierDt.java @@ -38,7 +38,6 @@ package ca.uhn.fhir.model.dstu.composite; import java.util.List; -import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.model.api.BaseElement; import ca.uhn.fhir.model.api.ICompositeDatatype; import ca.uhn.fhir.model.api.IElement; @@ -436,7 +435,7 @@ public class IdentifierDt @Override - public String getQueryParameterQualifier(FhirContext theContext) { + public String getQueryParameterQualifier() { return null; } diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/model/dstu/composite/QuantityDt.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/model/dstu/composite/QuantityDt.java index 42fc4fa1b37..3d452f3162c 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/model/dstu/composite/QuantityDt.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/model/dstu/composite/QuantityDt.java @@ -25,7 +25,6 @@ import java.util.List; import org.apache.commons.lang3.StringUtils; -import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.model.api.BaseElement; import ca.uhn.fhir.model.api.ICompositeDatatype; import ca.uhn.fhir.model.api.IElement; @@ -434,7 +433,7 @@ public class QuantityDt extends BaseElement implements ICompositeDatatype, IQuer @Override - public String getQueryParameterQualifier(FhirContext theContext) { + public String getQueryParameterQualifier() { return null; } diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/model/primitive/StringDt.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/model/primitive/StringDt.java index 72784cd0b40..1b32b654a46 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/model/primitive/StringDt.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/model/primitive/StringDt.java @@ -22,7 +22,6 @@ package ca.uhn.fhir.model.primitive; import org.apache.commons.lang3.StringUtils; -import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.model.api.BasePrimitive; import ca.uhn.fhir.model.api.IQueryParameterType; import ca.uhn.fhir.model.api.annotation.DatatypeDef; @@ -131,7 +130,7 @@ public class StringDt extends BasePrimitive implements IQueryParameterTy } @Override - public String getQueryParameterQualifier(FhirContext theContext) { + public String getQueryParameterQualifier() { return null; } diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/api/SortSpec.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/api/SortSpec.java index f98290669a9..2fd05502f6c 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/api/SortSpec.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/api/SortSpec.java @@ -27,9 +27,58 @@ package ca.uhn.fhir.rest.api; public class SortSpec { private SortSpec myChain; - private String myFieldName; + private String myParamName; private SortOrderEnum myOrder; + /** + * Constructor + */ + public SortSpec() { + } + + /** + * Constructor + * + * @param theParamName + * The search name to sort on. See {@link #setParamName(String)} for more information. + */ + public SortSpec(String theParamName) { + super(); + myParamName = theParamName; + } + + /** + * Constructor + * + * @param theParamName + * The search name to sort on. See {@link #setParamName(String)} for more information. + * @param theOrder + * The order, or null. See {@link #setOrder(SortOrderEnum)} for more information. + */ + public SortSpec(String theParamName, SortOrderEnum theOrder) { + super(); + myParamName = theParamName; + myOrder = theOrder; + } + + /** + * Constructor + * + * @param theParamName + * The search name to sort on. See {@link #setParamName(String)} for more information. + * @param theOrder + * The order, or null. See {@link #setOrder(SortOrderEnum)} for more information. + * @param theChain + * The next sorting spec, to be applied only when this spec makes two entries equal. See + * {@link #setChain(SortSpec)} for more information. + */ + public SortSpec(String theParamName, SortOrderEnum theOrder, SortSpec theChain) { + super(); + myParamName = theParamName; + myOrder = theOrder; + myChain = theChain; + } + /** * Gets the chained sort specification, or null if none. If multiple sort parameters are chained * (indicating a sub-sort), the second level sort is chained via this property. @@ -39,14 +88,14 @@ public class SortSpec { } /** - * Returns the actual name of the field to sort by + * Returns the actual name of the search param to sort by */ - public String getFieldName() { - return myFieldName; + public String getParamName() { + return myParamName; } /** - * Returns the sort order specified by this parameter, or null if none is explicitly defined (which + * Returns the sort order specified by this parameter, or null if none is explicitly provided (which * means {@link SortOrderEnum#ASC} according to the FHIR specification) */ @@ -59,19 +108,22 @@ public class SortSpec { * (indicating a sub-sort), the second level sort is chained via this property. */ public void setChain(SortSpec theChain) { + if (theChain == this) { + throw new IllegalArgumentException("Can not chain this to itself"); + } myChain = theChain; } /** - * Sets the actual name of the field to sort by + * Sets the actual name of the search param to sort by */ - public void setFieldName(String theFieldName) { - myFieldName = theFieldName; + public void setParamName(String theFieldName) { + myParamName = theFieldName; } /** - * Sets the sort order specified by this parameter, or null if none is explicitly defined (which means - * {@link SortOrderEnum#ASC} according to the null if none should be explicitly defined (which + * means {@link SortOrderEnum#ASC} according to the FHIR specification) */ public void setOrder(SortOrderEnum theOrder) { diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/client/GenericClient.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/client/GenericClient.java index 7c5e731e7da..572f40672ed 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/client/GenericClient.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/client/GenericClient.java @@ -176,7 +176,7 @@ public class GenericClient extends BaseClient implements IGenericClient { String qualifier = null; for (IQueryParameterType nextValue : nextEntry.getValue()) { valueList.add(nextValue.getValueAsQueryToken()); - qualifier = nextValue.getQueryParameterQualifier(myContext); + qualifier = nextValue.getQueryParameterQualifier(); } qualifier = StringUtils.defaultString(qualifier); params.put(nextEntry.getKey()+qualifier, valueList); diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/method/QualifiedParamList.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/method/QualifiedParamList.java index 47d7efad400..9020dfeb901 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/method/QualifiedParamList.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/method/QualifiedParamList.java @@ -44,7 +44,7 @@ public class QualifiedParamList extends ArrayList { public QualifiedParamList(FhirContext theContext, IQueryParameterOr theNextOr) { for (IQueryParameterType next : theNextOr.getValuesAsQueryTokens()) { if (myQualifier==null) { - myQualifier=next.getQueryParameterQualifier(theContext); + myQualifier=next.getQueryParameterQualifier(); } add(next.getValueAsQueryToken()); } diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/param/DateRangeParam.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/param/DateRangeParam.java index 987d3d8ada1..391b8988fba 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/param/DateRangeParam.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/param/DateRangeParam.java @@ -50,7 +50,7 @@ public class DateRangeParam implements IQueryParameterAnd { * @param theLowerBound * A qualified date param representing the lower date bound (optionally may include time), e.g. * "2011-02-22" or "2011-02-22T13:12:00". Will be treated inclusively. - * @param theLowerBound + * @param theUpperBound * A qualified date param representing the upper date bound (optionally may include time), e.g. * "2011-02-22" or "2011-02-22T13:12:00". Will be treated inclusively. */ @@ -98,7 +98,7 @@ public class DateRangeParam implements IQueryParameterAnd { * @param theLowerBound * A qualified date param representing the lower date bound (optionally may include time), e.g. * "2011-02-22" or "2011-02-22T13:12:00" - * @param theLowerBound + * @param theUpperBound * A qualified date param representing the upper date bound (optionally may include time), e.g. * "2011-02-22" or "2011-02-22T13:12:00" */ @@ -179,7 +179,7 @@ public class DateRangeParam implements IQueryParameterAnd { * @param theLowerBound * A qualified date param representing the lower date bound (optionally may include time), e.g. * "2011-02-22" or "2011-02-22T13:12:00". Will be treated inclusively. - * @param theLowerBound + * @param theUpperBound * A qualified date param representing the upper date bound (optionally may include time), e.g. * "2011-02-22" or "2011-02-22T13:12:00". Will be treated inclusively. */ @@ -195,7 +195,7 @@ public class DateRangeParam implements IQueryParameterAnd { * @param theLowerBound * A qualified date param representing the lower date bound (optionally may include time), e.g. * "2011-02-22" or "2011-02-22T13:12:00". Will be treated inclusively. - * @param theLowerBound + * @param theUpperBound * A qualified date param representing the upper date bound (optionally may include time), e.g. * "2011-02-22" or "2011-02-22T13:12:00". Will be treated inclusively. */ diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/param/QualifiedDateParam.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/param/QualifiedDateParam.java index 37867e55ecd..a475c270421 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/param/QualifiedDateParam.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/param/QualifiedDateParam.java @@ -22,7 +22,6 @@ package ca.uhn.fhir.rest.param; import java.util.Date; -import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.model.api.IQueryParameterType; import ca.uhn.fhir.model.dstu.valueset.QuantityCompararatorEnum; import ca.uhn.fhir.model.primitive.DateTimeDt; @@ -127,7 +126,7 @@ public class QualifiedDateParam extends DateTimeDt implements IQueryParameterTyp @Override - public String getQueryParameterQualifier(FhirContext theContext) { + public String getQueryParameterQualifier() { return null; } diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/param/ReferenceParam.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/param/ReferenceParam.java index b9c5fd9c1e9..1414d5c58ad 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/param/ReferenceParam.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/param/ReferenceParam.java @@ -54,7 +54,7 @@ public class ReferenceParam implements IQueryParameterType { } @Override - public String getQueryParameterQualifier(FhirContext theContext) { + public String getQueryParameterQualifier() { StringBuilder b = new StringBuilder(); if (isNotBlank(myResourceType)) { b.append(':'); diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/param/SortParameter.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/param/SortParameter.java index be156c820d4..7750c39fcc0 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/param/SortParameter.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/param/SortParameter.java @@ -44,25 +44,24 @@ public class SortParameter implements IParameter { @Override public void translateClientArgumentIntoQueryArgument(FhirContext theContext, Object theSourceClientArgument, Map> theTargetQueryArguments, BaseClientInvocation theClientInvocation) throws InternalErrorException { SortSpec ss = (SortSpec) theSourceClientArgument; - if (ss == null) { - return; - } - String name; - if (ss.getOrder() == null) { - name = Constants.PARAM_SORT; - } else if (ss.getOrder() == SortOrderEnum.ASC) { - name = Constants.PARAM_SORT_ASC; - } else { - name = Constants.PARAM_SORT_DESC; - } - - if (ss.getFieldName() != null) { - if (!theTargetQueryArguments.containsKey(name)) { - theTargetQueryArguments.put(name, new ArrayList()); + while (ss != null) { + String name; + if (ss.getOrder() == null) { + name = Constants.PARAM_SORT; + } else if (ss.getOrder() == SortOrderEnum.ASC) { + name = Constants.PARAM_SORT_ASC; + } else { + name = Constants.PARAM_SORT_DESC; } - theTargetQueryArguments.get(name).add(ss.getFieldName()); - } + if (ss.getParamName() != null) { + if (!theTargetQueryArguments.containsKey(name)) { + theTargetQueryArguments.put(name, new ArrayList()); + } + theTargetQueryArguments.get(name).add(ss.getParamName()); + } + ss = ss.getChain(); + } } @Override @@ -95,7 +94,7 @@ public class SortParameter implements IParameter { if (isNotBlank(nextValue)) { SortSpec spec = new SortSpec(); spec.setOrder(order); - spec.setFieldName(nextValue); + spec.setParamName(nextValue); if (innerSpec == null) { outerSpec = spec; innerSpec = spec; @@ -113,11 +112,11 @@ public class SortParameter implements IParameter { @Override public void initializeTypes(Method theMethod, Class> theOuterCollectionType, Class> theInnerCollectionType, Class theParameterType) { - if (theOuterCollectionType != null || theInnerCollectionType!=null) { - throw new ConfigurationException("Method '" + theMethod.getName() + "' in type '" +theMethod.getDeclaringClass().getCanonicalName()+ "' is annotated with @" + Sort.class.getName() + " but can not be of collection type"); + if (theOuterCollectionType != null || theInnerCollectionType != null) { + throw new ConfigurationException("Method '" + theMethod.getName() + "' in type '" + theMethod.getDeclaringClass().getCanonicalName() + "' is annotated with @" + Sort.class.getName() + " but can not be of collection type"); } if (!theParameterType.equals(SortSpec.class)) { - throw new ConfigurationException("Method '" + theMethod.getName() + "' in type '"+theMethod.getDeclaringClass().getCanonicalName() + "' is annotated with @" + Sort.class.getName() + " but is an invalid type, must be: " + SortSpec.class.getCanonicalName()); + throw new ConfigurationException("Method '" + theMethod.getName() + "' in type '" + theMethod.getDeclaringClass().getCanonicalName() + "' is annotated with @" + Sort.class.getName() + " but is an invalid type, must be: " + SortSpec.class.getCanonicalName()); } } diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/param/StringParam.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/param/StringParam.java index 6272f6d1800..f7e5223f0f7 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/param/StringParam.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/param/StringParam.java @@ -20,7 +20,6 @@ package ca.uhn.fhir.rest.param; * #L% */ -import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.model.primitive.StringDt; import ca.uhn.fhir.rest.server.Constants; @@ -51,7 +50,7 @@ public class StringParam extends StringDt { } @Override - public String getQueryParameterQualifier(FhirContext theContext) { + public String getQueryParameterQualifier() { if (isExact()) { return Constants.PARAMQUALIFIER_STRING_EXACT; } else { diff --git a/hapi-fhir-base/src/site/example/java/example/RestfulPatientResourceProviderMore.java b/hapi-fhir-base/src/site/example/java/example/RestfulPatientResourceProviderMore.java index 4b9d6f2bb59..094fada9769 100644 --- a/hapi-fhir-base/src/site/example/java/example/RestfulPatientResourceProviderMore.java +++ b/hapi-fhir-base/src/site/example/java/example/RestfulPatientResourceProviderMore.java @@ -49,10 +49,13 @@ import ca.uhn.fhir.rest.annotation.RequiredParam; import ca.uhn.fhir.rest.annotation.ResourceParam; import ca.uhn.fhir.rest.annotation.Search; import ca.uhn.fhir.rest.annotation.Since; +import ca.uhn.fhir.rest.annotation.Sort; import ca.uhn.fhir.rest.annotation.Update; import ca.uhn.fhir.rest.annotation.Validate; import ca.uhn.fhir.rest.annotation.VersionIdParam; import ca.uhn.fhir.rest.api.MethodOutcome; +import ca.uhn.fhir.rest.api.SortOrderEnum; +import ca.uhn.fhir.rest.api.SortSpec; import ca.uhn.fhir.rest.client.ITestClient; import ca.uhn.fhir.rest.client.api.IBasicClient; import ca.uhn.fhir.rest.client.api.IRestfulClient; @@ -80,6 +83,32 @@ public List getAllOrganizations() { } //END SNIPPET: searchAll +//START SNIPPET: sort +@Search +public List findPatients( + @RequiredParam(name=Patient.SP_IDENTIFIER) StringParam theParameter, + @Sort SortSpec theSort) { + List retVal=new ArrayList(); // populate this + + // theSort is null unless a _sort parameter is actually provided + if (theSort != null) { + + // The name of the param to sort by + String param = theSort.getParamName(); + + // The sort order, or null + SortOrderEnum order = theSort.getOrder(); + + // This will be populated if a second _sort was specified + SortSpec subSort = theSort.getChain(); + + // ...apply the sort... + } + + return retVal; +} +//END SNIPPET: sort + //START SNIPPET: underlyingReq @Search public List findPatients( @@ -259,6 +288,21 @@ List response = client.getPatientByDob(param); //END SNIPPET: dateClient } +//START SNIPPET: dateRange +@Search() +public List searchByDateRange( + @RequiredParam(name=Observation.SP_DATE) DateRangeParam theRange ) { + + Date from = theRange.getLowerBoundAsInstant(); + Date to = theRange.getUpperBoundAsInstant(); + + List retVal = new ArrayList(); + // ...populate... + return retVal; +} +//END SNIPPET: dateRange + + private ITestClient provideTc() { return null; } diff --git a/hapi-fhir-base/src/site/xdoc/doc_rest_operations.xml b/hapi-fhir-base/src/site/xdoc/doc_rest_operations.xml index 93b7496be15..74a90885f67 100644 --- a/hapi-fhir-base/src/site/xdoc/doc_rest_operations.xml +++ b/hapi-fhir-base/src/site/xdoc/doc_rest_operations.xml @@ -915,6 +915,43 @@ + + +

+ FHIR supports + sorting + according to a specific set of rules. +

+ +

+ According to the specification, sorting is requested by the client using a + search param as the sort key. For example, when searching Patient resources, + a sort key of "given" requests the "given" search param as the sort key. That + param maps to the values in the field "Patient.name.given". +

+ +

+ Sort specifications can be passed into handler methods by adding a parameter + of type + SortSpec, + which has been annotated with the + @Sort + annotation, as shown in the following example: +

+ + + + + + +

+ Example URL to invoke this method: +
+ http://fhir.example.com/Patient?_identifier=urn:foo|123&_sort=given +

+ +
+ diff --git a/hapi-fhir-base/src/test/java/ca/uhn/fhir/rest/client/GenericClientTest.java b/hapi-fhir-base/src/test/java/ca/uhn/fhir/rest/client/GenericClientTest.java index 75a95cdc5c2..cef7d244d49 100644 --- a/hapi-fhir-base/src/test/java/ca/uhn/fhir/rest/client/GenericClientTest.java +++ b/hapi-fhir-base/src/test/java/ca/uhn/fhir/rest/client/GenericClientTest.java @@ -303,7 +303,7 @@ public class GenericClientTest { client.search().forResource(Patient.class).execute(); fail(); } catch (InternalErrorException e) { - assertEquals(e.getMessage(), "INTERNAL ERRORS"); + assertEquals(e.getMessage(), "HTTP 500 INTERNAL ERRORS: Server Issues!"); assertEquals(e.getResponseBody(), "Server Issues!"); } diff --git a/hapi-fhir-base/src/test/java/ca/uhn/fhir/rest/client/SortClientTest.java b/hapi-fhir-base/src/test/java/ca/uhn/fhir/rest/client/SortClientTest.java new file mode 100644 index 00000000000..3872388c11f --- /dev/null +++ b/hapi-fhir-base/src/test/java/ca/uhn/fhir/rest/client/SortClientTest.java @@ -0,0 +1,101 @@ +package ca.uhn.fhir.rest.client; + +import static org.junit.Assert.assertEquals; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +import java.io.StringReader; +import java.nio.charset.Charset; +import java.util.List; + +import org.apache.commons.io.input.ReaderInputStream; +import org.apache.http.HttpResponse; +import org.apache.http.ProtocolVersion; +import org.apache.http.client.HttpClient; +import org.apache.http.client.methods.HttpGet; +import org.apache.http.client.methods.HttpUriRequest; +import org.apache.http.message.BasicHeader; +import org.apache.http.message.BasicStatusLine; +import org.junit.Before; +import org.junit.Test; +import org.mockito.ArgumentCaptor; +import org.mockito.internal.stubbing.defaultanswers.ReturnsDeepStubs; + +import ca.uhn.fhir.context.FhirContext; +import ca.uhn.fhir.model.api.Bundle; +import ca.uhn.fhir.model.dstu.resource.Conformance; +import ca.uhn.fhir.model.dstu.resource.Patient; +import ca.uhn.fhir.rest.annotation.RequiredParam; +import ca.uhn.fhir.rest.annotation.Search; +import ca.uhn.fhir.rest.annotation.Sort; +import ca.uhn.fhir.rest.api.SortOrderEnum; +import ca.uhn.fhir.rest.api.SortSpec; +import ca.uhn.fhir.rest.client.api.IBasicClient; +import ca.uhn.fhir.rest.param.StringParam; +import ca.uhn.fhir.rest.server.Constants; + +public class SortClientTest { + + private FhirContext ctx; + private HttpClient httpClient; + private HttpResponse httpResponse; + + // atom-document-large.xml + + @Before + public void before() { + ctx = new FhirContext(Patient.class, Conformance.class); + + httpClient = mock(HttpClient.class, new ReturnsDeepStubs()); + ctx.getRestfulClientFactory().setHttpClient(httpClient); + + httpResponse = mock(HttpResponse.class, new ReturnsDeepStubs()); + } + + + + @Test + public void testSort() throws Exception { + ArgumentCaptor capt = ArgumentCaptor.forClass(HttpUriRequest.class); + when(httpClient.execute(capt.capture())).thenReturn(httpResponse); + when(httpResponse.getStatusLine()).thenReturn(new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), 200, "OK")); + when(httpResponse.getEntity().getContentType()).thenReturn(new BasicHeader("content-type", Constants.CT_ATOM_XML + "; charset=UTF-8")); + when(httpResponse.getEntity().getContent()).thenReturn(new ReaderInputStream(new StringReader(createBundle()), Charset.forName("UTF-8"))); + + IClient client = ctx.newRestfulClient(IClient.class, "http://foo"); + client.searchWithParam(new StringParam("hello"), new SortSpec("given")); + + assertEquals(HttpGet.class, capt.getValue().getClass()); + HttpGet get = (HttpGet) capt.getValue(); + assertEquals("http://foo/Patient?name=hello&_sort=given", get.getURI().toString()); + } + + @Test + public void testSortWithChain() throws Exception { + ArgumentCaptor capt = ArgumentCaptor.forClass(HttpUriRequest.class); + when(httpClient.execute(capt.capture())).thenReturn(httpResponse); + when(httpResponse.getStatusLine()).thenReturn(new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), 200, "OK")); + when(httpResponse.getEntity().getContentType()).thenReturn(new BasicHeader("content-type", Constants.CT_ATOM_XML + "; charset=UTF-8")); + when(httpResponse.getEntity().getContent()).thenReturn(new ReaderInputStream(new StringReader(createBundle()), Charset.forName("UTF-8"))); + + IClient client = ctx.newRestfulClient(IClient.class, "http://foo"); + client.searchWithParam(new StringParam("hello"), new SortSpec("given", SortOrderEnum.DESC, new SortSpec("family", SortOrderEnum.ASC))); + + assertEquals(HttpGet.class, capt.getValue().getClass()); + HttpGet get = (HttpGet) capt.getValue(); + assertEquals("http://foo/Patient?name=hello&_sort%3Adesc=given&_sort%3Aasc=family", get.getURI().toString()); + } + + private String createBundle() { + return ctx.newXmlParser().encodeBundleToString(new Bundle()); + } + + + private interface IClient extends IBasicClient { + + @Search(type=Patient.class) + public List searchWithParam(@RequiredParam(name=Patient.SP_NAME) StringParam theString, @Sort SortSpec theSort); + + } + +} diff --git a/hapi-fhir-base/src/test/java/ca/uhn/fhir/rest/server/ResfulServerMethodTest.java b/hapi-fhir-base/src/test/java/ca/uhn/fhir/rest/server/ResfulServerMethodTest.java index 34615987c46..508b2903c74 100644 --- a/hapi-fhir-base/src/test/java/ca/uhn/fhir/rest/server/ResfulServerMethodTest.java +++ b/hapi-fhir-base/src/test/java/ca/uhn/fhir/rest/server/ResfulServerMethodTest.java @@ -354,7 +354,11 @@ public class ResfulServerMethodTest { IParser p = ourCtx.newXmlParser().setPrettyPrint(true); String enc = p.encodeResourceToString(bundle); ourLog.info("Response:\n{}", enc); - assertTrue(enc.contains(ExtensionConstants.CONF_ADDITIONAL_PARAM)); + + p = ourCtx.newXmlParser().setPrettyPrint(false); + enc = p.encodeResourceToString(bundle); + ourLog.info("Response:\n{}", enc); + assertThat(enc, StringContains.containsString("")); } // { // IParser p = ourCtx.newJsonParser().setPrettyPrint(true); @@ -536,14 +540,14 @@ public class ResfulServerMethodTest { String responseContent = IOUtils.toString(status.getEntity().getContent()); ourLog.info("Response was:\n{}", responseContent); - assertEquals(Constants.STATUS_HTTP_404_NOT_FOUND, status.getStatusLine().getStatusCode()); + assertEquals(Constants.STATUS_HTTP_400_BAD_REQUEST, status.getStatusLine().getStatusCode()); } @Test public void testSearchAll() throws Exception { - HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient"); + HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/AdverseReaction"); HttpResponse status = ourClient.execute(httpGet); String responseContent = IOUtils.toString(status.getEntity().getContent()); @@ -554,7 +558,7 @@ public class ResfulServerMethodTest { assertEquals(2, bundle.getEntries().size()); - HttpPost httpPost = new HttpPost("http://localhost:" + ourPort + "/Patient/_search"); + HttpPost httpPost = new HttpPost("http://localhost:" + ourPort + "/AdverseReaction/_search"); status = ourClient.execute(httpPost); responseContent = IOUtils.toString(status.getEntity().getContent()); @@ -1205,6 +1209,15 @@ public class ResfulServerMethodTest { IdDt version = new IdDt(thePatient.getIdentifier().get(1).getValue().getValue()); return new MethodOutcome(id, version); } + + @Search() + public Collection getAllResources() { + ArrayList retVal = new ArrayList(); + retVal.add(new AdverseReaction()); + retVal.add(new AdverseReaction()); + return retVal; + } + @Override public Class getResourceType() { @@ -1501,11 +1514,6 @@ public class ResfulServerMethodTest { return retVal; } - @Search() - public Collection getResources() { - return getIdToPatient().values(); - } - @Override public Class getResourceType() { return Patient.class; diff --git a/hapi-fhir-base/src/test/java/ca/uhn/fhir/rest/server/ServerConformanceProviderTest.java b/hapi-fhir-base/src/test/java/ca/uhn/fhir/rest/server/ServerConformanceProviderTest.java index 8f45124b7d8..079f0eec394 100644 --- a/hapi-fhir-base/src/test/java/ca/uhn/fhir/rest/server/ServerConformanceProviderTest.java +++ b/hapi-fhir-base/src/test/java/ca/uhn/fhir/rest/server/ServerConformanceProviderTest.java @@ -85,7 +85,8 @@ public class ServerConformanceProviderTest { String conf = new FhirContext().newXmlParser().setPrettyPrint(true).encodeResourceToString(conformance); ourLog.info(conf); - assertThat(conf, containsString("")); + assertThat(conf, containsString("")); + assertThat(conf, containsString("")); assertThat(conf, containsString("")); } diff --git a/hapi-fhir-base/src/test/java/ca/uhn/fhir/rest/server/SortTest.java b/hapi-fhir-base/src/test/java/ca/uhn/fhir/rest/server/SortTest.java index 73194d27d50..a5a468ddd21 100644 --- a/hapi-fhir-base/src/test/java/ca/uhn/fhir/rest/server/SortTest.java +++ b/hapi-fhir-base/src/test/java/ca/uhn/fhir/rest/server/SortTest.java @@ -53,47 +53,47 @@ public class SortTest { assertEquals(1, p.getName().size()); assertEquals("Hello", p.getNameFirstRep().getFamilyFirstRep().getValue()); } - + @Test public void testSingleSort() throws Exception { { - HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient?name=Hello&_sort=given"); - HttpResponse status = ourClient.execute(httpGet); - String responseContent = IOUtils.toString(status.getEntity().getContent()); - assertEquals(200, status.getStatusLine().getStatusCode()); - Bundle bundle = new FhirContext().newXmlParser().parseBundle(responseContent); - assertEquals(1, bundle.size()); + HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient?name=Hello&_sort=given"); + HttpResponse status = ourClient.execute(httpGet); + String responseContent = IOUtils.toString(status.getEntity().getContent()); + assertEquals(200, status.getStatusLine().getStatusCode()); + Bundle bundle = new FhirContext().newXmlParser().parseBundle(responseContent); + assertEquals(1, bundle.size()); - Patient p = bundle.getResources(Patient.class).get(0); - assertEquals(2, p.getName().size()); - assertEquals("Hello", p.getNameFirstRep().getFamilyFirstRep().getValue()); - assertEquals("given|null", p.getName().get(1).getFamilyFirstRep().getValue()); + Patient p = bundle.getResources(Patient.class).get(0); + assertEquals(2, p.getName().size()); + assertEquals("Hello", p.getNameFirstRep().getFamilyFirstRep().getValue()); + assertEquals("given|null", p.getName().get(1).getFamilyFirstRep().getValue()); } { - HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient?name=Hello&_sort:asc=given"); - HttpResponse status = ourClient.execute(httpGet); - String responseContent = IOUtils.toString(status.getEntity().getContent()); - assertEquals(200, status.getStatusLine().getStatusCode()); - Bundle bundle = new FhirContext().newXmlParser().parseBundle(responseContent); - assertEquals(1, bundle.size()); + HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient?name=Hello&_sort:asc=given"); + HttpResponse status = ourClient.execute(httpGet); + String responseContent = IOUtils.toString(status.getEntity().getContent()); + assertEquals(200, status.getStatusLine().getStatusCode()); + Bundle bundle = new FhirContext().newXmlParser().parseBundle(responseContent); + assertEquals(1, bundle.size()); - Patient p = bundle.getResources(Patient.class).get(0); - assertEquals(2, p.getName().size()); - assertEquals("Hello", p.getNameFirstRep().getFamilyFirstRep().getValue()); - assertEquals("given|ASC", p.getName().get(1).getFamilyFirstRep().getValue()); + Patient p = bundle.getResources(Patient.class).get(0); + assertEquals(2, p.getName().size()); + assertEquals("Hello", p.getNameFirstRep().getFamilyFirstRep().getValue()); + assertEquals("given|ASC", p.getName().get(1).getFamilyFirstRep().getValue()); } { - HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient?name=Hello&_sort:desc=given"); - HttpResponse status = ourClient.execute(httpGet); - String responseContent = IOUtils.toString(status.getEntity().getContent()); - assertEquals(200, status.getStatusLine().getStatusCode()); - Bundle bundle = new FhirContext().newXmlParser().parseBundle(responseContent); - assertEquals(1, bundle.size()); + HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient?name=Hello&_sort:desc=given"); + HttpResponse status = ourClient.execute(httpGet); + String responseContent = IOUtils.toString(status.getEntity().getContent()); + assertEquals(200, status.getStatusLine().getStatusCode()); + Bundle bundle = new FhirContext().newXmlParser().parseBundle(responseContent); + assertEquals(1, bundle.size()); - Patient p = bundle.getResources(Patient.class).get(0); - assertEquals(2, p.getName().size()); - assertEquals("Hello", p.getNameFirstRep().getFamilyFirstRep().getValue()); - assertEquals("given|DESC", p.getName().get(1).getFamilyFirstRep().getValue()); + Patient p = bundle.getResources(Patient.class).get(0); + assertEquals(2, p.getName().size()); + assertEquals("Hello", p.getNameFirstRep().getFamilyFirstRep().getValue()); + assertEquals("given|DESC", p.getName().get(1).getFamilyFirstRep().getValue()); } } @@ -101,23 +101,23 @@ public class SortTest { @Test public void testSortChain() throws Exception { { - HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient?name=Hello&_sort=given&_sort=family&_sort=name"); - HttpResponse status = ourClient.execute(httpGet); - String responseContent = IOUtils.toString(status.getEntity().getContent()); - assertEquals(200, status.getStatusLine().getStatusCode()); - Bundle bundle = new FhirContext().newXmlParser().parseBundle(responseContent); - assertEquals(1, bundle.size()); + HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient?name=Hello&_sort=given&_sort=family&_sort=name"); + HttpResponse status = ourClient.execute(httpGet); + String responseContent = IOUtils.toString(status.getEntity().getContent()); + assertEquals(200, status.getStatusLine().getStatusCode()); + Bundle bundle = new FhirContext().newXmlParser().parseBundle(responseContent); + assertEquals(1, bundle.size()); - Patient p = bundle.getResources(Patient.class).get(0); - assertEquals(4, p.getName().size()); - assertEquals("Hello", p.getNameFirstRep().getFamilyFirstRep().getValue()); - assertEquals("given|null", p.getName().get(1).getFamilyFirstRep().getValue()); - assertEquals("family|null", p.getName().get(2).getFamilyFirstRep().getValue()); - assertEquals("name|null", p.getName().get(3).getFamilyFirstRep().getValue()); + Patient p = bundle.getResources(Patient.class).get(0); + assertEquals(4, p.getName().size()); + assertEquals("Hello", p.getNameFirstRep().getFamilyFirstRep().getValue()); + assertEquals("given|null", p.getName().get(1).getFamilyFirstRep().getValue()); + assertEquals("family|null", p.getName().get(2).getFamilyFirstRep().getValue()); + assertEquals("name|null", p.getName().get(3).getFamilyFirstRep().getValue()); } - } + @AfterClass public static void afterClass() throws Exception { ourServer.stop(); @@ -158,7 +158,7 @@ public class SortTest { p.addName().addFamily().setValue(theName.getValue()); SortSpec sort = theSort; while (sort != null) { - p.addName().addFamily().setValue(sort.getFieldName() + "|" + sort.getOrder()); + p.addName().addFamily().setValue(sort.getParamName() + "|" + sort.getOrder()); sort = sort.getChain(); } diff --git a/hapi-fhir-base/src/test/java/ca/uhn/fhir/testmodel/IdentifierDt.java b/hapi-fhir-base/src/test/java/ca/uhn/fhir/testmodel/IdentifierDt.java index e786d2527d8..2e3b925fe7d 100644 --- a/hapi-fhir-base/src/test/java/ca/uhn/fhir/testmodel/IdentifierDt.java +++ b/hapi-fhir-base/src/test/java/ca/uhn/fhir/testmodel/IdentifierDt.java @@ -18,7 +18,6 @@ package ca.uhn.fhir.testmodel; import java.util.List; -import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.model.api.BaseElement; import ca.uhn.fhir.model.api.ICompositeDatatype; import ca.uhn.fhir.model.api.IElement; @@ -399,7 +398,7 @@ public class IdentifierDt } @Override - public String getQueryParameterQualifier(FhirContext theContext) { + public String getQueryParameterQualifier() { return null; } diff --git a/hapi-fhir-jpaserver-base/pom.xml b/hapi-fhir-jpaserver-base/pom.xml index 0801ca5194f..921351e86ad 100644 --- a/hapi-fhir-jpaserver-base/pom.xml +++ b/hapi-fhir-jpaserver-base/pom.xml @@ -4,7 +4,7 @@ ca.uhn.hapi.fhir hapi-fhir - 0.3 + 0.4-SNAPSHOT ../pom.xml @@ -18,7 +18,7 @@ ca.uhn.hapi.fhir hapi-fhir-base - 0.3 + 0.4-SNAPSHOT diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/entity/BaseResourceTable.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/entity/BaseResourceTable.java index abcdf594f0c..429dd21b746 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/entity/BaseResourceTable.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/entity/BaseResourceTable.java @@ -24,7 +24,7 @@ import ca.uhn.fhir.model.primitive.IdDt; @Entity @Table(name = "BASE_RES", uniqueConstraints = {}) -@Inheritance(strategy = InheritanceType.JOINED) +@Inheritance(strategy = InheritanceType.SINGLE_TABLE) @DiscriminatorColumn(name = "SVCVER_TYPE", length = 20, discriminatorType = DiscriminatorType.STRING) public abstract class BaseResourceTable extends BaseHasResource { diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/entity/ResourceIndexedSearchParamDate.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/entity/ResourceIndexedSearchParamDate.java index 3741dfb978d..2636a8ee7c5 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/entity/ResourceIndexedSearchParamDate.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/entity/ResourceIndexedSearchParamDate.java @@ -13,7 +13,7 @@ import javax.persistence.Temporal; import javax.persistence.TemporalType; @Entity -@Table(name = "SPIDX_DATE", indexes= {@Index(name="IDX_SP_DATE", columnList="myValueLow,myValueHigh")}) +@Table(name = "SPIDX_DATE", indexes= {@Index(name="IDX_SP_DATE", columnList="SP_VALUE_LOW,SP_VALUE_HIGH")}) public class ResourceIndexedSearchParamDate extends BaseResourceIndexedSearchParam { private static final long serialVersionUID = 1L; diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/entity/ResourceIndexedSearchParamNumber.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/entity/ResourceIndexedSearchParamNumber.java index a961a306337..5c1d9765565 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/entity/ResourceIndexedSearchParamNumber.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/entity/ResourceIndexedSearchParamNumber.java @@ -11,7 +11,7 @@ import javax.persistence.ManyToOne; import javax.persistence.Table; @Entity -@Table(name = "SPIDX_NUMBER", indexes= {@Index(name="IDX_SP_NUMBER", columnList="myValue")}) +@Table(name = "SPIDX_NUMBER", indexes= {@Index(name="IDX_SP_NUMBER", columnList="SP_VALUE")}) public class ResourceIndexedSearchParamNumber extends BaseResourceIndexedSearchParam { private static final long serialVersionUID = 1L; diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/entity/ResourceIndexedSearchParamString.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/entity/ResourceIndexedSearchParamString.java index a3e430db211..d6481e615c8 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/entity/ResourceIndexedSearchParamString.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/entity/ResourceIndexedSearchParamString.java @@ -10,7 +10,7 @@ import javax.persistence.ManyToOne; import javax.persistence.Table; @Entity -@Table(name = "SPIDX_STRING", indexes= {@Index(name="IDX_SP_STRING", columnList="myValueNormalized")}) +@Table(name = "SPIDX_STRING", indexes= {@Index(name="IDX_SP_STRING", columnList="SP_VALUE_NORMALIZED")}) public class ResourceIndexedSearchParamString extends BaseResourceIndexedSearchParam { private static final long serialVersionUID = 1L; diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/entity/ResourceIndexedSearchParamToken.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/entity/ResourceIndexedSearchParamToken.java index 36112a1b1c7..9faafce2f5f 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/entity/ResourceIndexedSearchParamToken.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/entity/ResourceIndexedSearchParamToken.java @@ -9,7 +9,7 @@ import javax.persistence.ManyToOne; import javax.persistence.Table; @Entity -@Table(name = "SPIDX_TOKEN", indexes= {@Index(name="IDX_SP_STRING", columnList="mySystem,myValue")}) +@Table(name = "SPIDX_TOKEN", indexes= {@Index(name="IDX_SP_STRING", columnList="SP_SYSTEM,SP_VALUE")}) public class ResourceIndexedSearchParamToken extends BaseResourceIndexedSearchParam { private static final long serialVersionUID = 1L; diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/FhirResourceDaoTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/FhirResourceDaoTest.java index 8384f35c7cc..c9979d09eaa 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/FhirResourceDaoTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/FhirResourceDaoTest.java @@ -227,7 +227,7 @@ public class FhirResourceDaoTest { Map params = new HashMap<>(); List patients = ourPatientDao.search(params); - assertEquals(2, patients.size()); + assertTrue(patients.size() >= 2); } @Test diff --git a/hapi-fhir-jpaserver-test/.classpath b/hapi-fhir-jpaserver-test/.classpath index 13d8e1e218a..2c1098968d3 100644 --- a/hapi-fhir-jpaserver-test/.classpath +++ b/hapi-fhir-jpaserver-test/.classpath @@ -4,6 +4,7 @@ + diff --git a/hapi-fhir-jpaserver-test/pom.xml b/hapi-fhir-jpaserver-test/pom.xml index e77d26d3904..b2248c4acc7 100644 --- a/hapi-fhir-jpaserver-test/pom.xml +++ b/hapi-fhir-jpaserver-test/pom.xml @@ -4,7 +4,7 @@ ca.uhn.hapi.fhir hapi-fhir - 0.3 + 0.4-SNAPSHOT ../pom.xml @@ -18,7 +18,7 @@ ca.uhn.hapi.fhir hapi-fhir-jpaserver-base - 0.3 + 0.4-SNAPSHOT @@ -83,7 +83,7 @@ ca.uhn.hapi.fhir hapi-tinder-plugin - 0.3 + 0.4-SNAPSHOT buildclient diff --git a/hapi-fhir-jpaserver-test/src/main/java/ca/uhn/fhir/jpa/test/CompleteResourceProviderTest.java b/hapi-fhir-jpaserver-test/src/test/java/ca/uhn/fhir/jpa/test/CompleteResourceProviderTest.java similarity index 100% rename from hapi-fhir-jpaserver-test/src/main/java/ca/uhn/fhir/jpa/test/CompleteResourceProviderTest.java rename to hapi-fhir-jpaserver-test/src/test/java/ca/uhn/fhir/jpa/test/CompleteResourceProviderTest.java diff --git a/hapi-fhir-jpaserver-test/src/main/java/ca/uhn/fhir/jpa/test/JpaTestApp.java b/hapi-fhir-jpaserver-test/src/test/java/ca/uhn/fhir/jpa/test/JpaTestApp.java similarity index 100% rename from hapi-fhir-jpaserver-test/src/main/java/ca/uhn/fhir/jpa/test/JpaTestApp.java rename to hapi-fhir-jpaserver-test/src/test/java/ca/uhn/fhir/jpa/test/JpaTestApp.java diff --git a/hapi-fhir-jpaserver-test/src/main/java/ca/uhn/fhir/jpa/test/QuestionnaireResourceProvider.java b/hapi-fhir-jpaserver-test/src/test/java/ca/uhn/fhir/jpa/test/QuestionnaireResourceProvider.java similarity index 100% rename from hapi-fhir-jpaserver-test/src/main/java/ca/uhn/fhir/jpa/test/QuestionnaireResourceProvider.java rename to hapi-fhir-jpaserver-test/src/test/java/ca/uhn/fhir/jpa/test/QuestionnaireResourceProvider.java diff --git a/hapi-fhir-jpaserver-test/src/main/java/ca/uhn/fhir/jpa/test/UploadTestResources.java b/hapi-fhir-jpaserver-test/src/test/java/ca/uhn/fhir/jpa/test/UploadTestResources.java similarity index 100% rename from hapi-fhir-jpaserver-test/src/main/java/ca/uhn/fhir/jpa/test/UploadTestResources.java rename to hapi-fhir-jpaserver-test/src/test/java/ca/uhn/fhir/jpa/test/UploadTestResources.java diff --git a/hapi-fhir-jpaserver-test/src/main/resources/fhir-spring-test-config.xml b/hapi-fhir-jpaserver-test/src/test/resources/fhir-spring-test-config.xml similarity index 100% rename from hapi-fhir-jpaserver-test/src/main/resources/fhir-spring-test-config.xml rename to hapi-fhir-jpaserver-test/src/test/resources/fhir-spring-test-config.xml diff --git a/hapi-fhir-jpaserver-test/src/main/resources/fhir_jpatest_persistence.xml b/hapi-fhir-jpaserver-test/src/test/resources/fhir_jpatest_persistence.xml similarity index 100% rename from hapi-fhir-jpaserver-test/src/main/resources/fhir_jpatest_persistence.xml rename to hapi-fhir-jpaserver-test/src/test/resources/fhir_jpatest_persistence.xml diff --git a/hapi-fhir-structures-dstu/pom.xml b/hapi-fhir-structures-dstu/pom.xml index 76ae9c62592..2522dddf629 100644 --- a/hapi-fhir-structures-dstu/pom.xml +++ b/hapi-fhir-structures-dstu/pom.xml @@ -5,7 +5,7 @@ ca.uhn.hapi.fhir hapi-fhir - 0.3 + 0.4-SNAPSHOT ../pom.xml @@ -19,7 +19,7 @@ ca.uhn.hapi.fhir hapi-fhir-base - 0.3 + 0.4-SNAPSHOT @@ -28,7 +28,7 @@ ca.uhn.hapi.fhir hapi-tinder-plugin - 0.3 + 0.4-SNAPSHOT diff --git a/hapi-tinder-plugin/.classpath b/hapi-tinder-plugin/.classpath index 193b2b5da6b..8d568ad96ec 100644 --- a/hapi-tinder-plugin/.classpath +++ b/hapi-tinder-plugin/.classpath @@ -1,7 +1,6 @@ - diff --git a/hapi-tinder-plugin/.project b/hapi-tinder-plugin/.project index a5a3ad1e7e2..410a7cdc035 100644 --- a/hapi-tinder-plugin/.project +++ b/hapi-tinder-plugin/.project @@ -1,14 +1,23 @@ - hapi-tinder-plugin - NO_M2ECLIPSE_SUPPORT: Project files created with the maven-eclipse-plugin are not supported in M2Eclipse. - - - - org.eclipse.jdt.core.javabuilder - - - - org.eclipse.jdt.core.javanature - - \ No newline at end of file + hapi-tinder-plugin + NO_M2ECLIPSE_SUPPORT: Project files created with the maven-eclipse-plugin are not supported in M2Eclipse. + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.jdt.core.javanature + + diff --git a/hapi-tinder-plugin/.settings/org.eclipse.core.resources.prefs b/hapi-tinder-plugin/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 00000000000..989609020a0 --- /dev/null +++ b/hapi-tinder-plugin/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,5 @@ +eclipse.preferences.version=1 +encoding//src/main/java=UTF-8 +encoding//src/main/resources=UTF-8 +encoding//src/test/resources=UTF-8 +encoding/=UTF-8 diff --git a/hapi-tinder-plugin/.settings/org.eclipse.jdt.core.prefs b/hapi-tinder-plugin/.settings/org.eclipse.jdt.core.prefs index 9b5ebfa5836..107056a36e4 100644 --- a/hapi-tinder-plugin/.settings/org.eclipse.jdt.core.prefs +++ b/hapi-tinder-plugin/.settings/org.eclipse.jdt.core.prefs @@ -1,12 +1,12 @@ -#Mon Mar 03 15:01:12 EST 2014 -org.eclipse.jdt.core.compiler.debug.localVariable=generate -org.eclipse.jdt.core.compiler.compliance=1.6 -org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve -org.eclipse.jdt.core.compiler.debug.sourceFile=generate -org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 -org.eclipse.jdt.core.compiler.problem.enumIdentifier=error -org.eclipse.jdt.core.compiler.debug.lineNumber=generate eclipse.preferences.version=1 org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled -org.eclipse.jdt.core.compiler.source=1.6 +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=1.6 +org.eclipse.jdt.core.compiler.debug.lineNumber=generate +org.eclipse.jdt.core.compiler.debug.localVariable=generate +org.eclipse.jdt.core.compiler.debug.sourceFile=generate org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning +org.eclipse.jdt.core.compiler.source=1.6 diff --git a/hapi-tinder-plugin/.settings/org.eclipse.m2e.core.prefs b/hapi-tinder-plugin/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 00000000000..f897a7f1cb2 --- /dev/null +++ b/hapi-tinder-plugin/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/hapi-tinder-plugin/pom.xml b/hapi-tinder-plugin/pom.xml index 4ce15d4bf39..afde8f031e6 100644 --- a/hapi-tinder-plugin/pom.xml +++ b/hapi-tinder-plugin/pom.xml @@ -5,7 +5,7 @@ ca.uhn.hapi.fhir hapi-fhir - 0.3 + 0.4-SNAPSHOT ../pom.xml @@ -20,7 +20,7 @@ ca.uhn.hapi.fhir hapi-fhir-base - 0.3 + 0.4-SNAPSHOT diff --git a/hapi-tinder-plugin/src/main/java/ca/uhn/fhir/tinder/TinderStructuresMojo.java b/hapi-tinder-plugin/src/main/java/ca/uhn/fhir/tinder/TinderStructuresMojo.java index 537afcd9f16..026f1c13018 100644 --- a/hapi-tinder-plugin/src/main/java/ca/uhn/fhir/tinder/TinderStructuresMojo.java +++ b/hapi-tinder-plugin/src/main/java/ca/uhn/fhir/tinder/TinderStructuresMojo.java @@ -195,7 +195,7 @@ public class TinderStructuresMojo extends AbstractMojo { // dtp.writeAll(dtOutputDir); // ResourceGeneratorUsingSpreadsheet rp = new ResourceGeneratorUsingSpreadsheet(); - rp.setBaseResourceNames(Arrays.asList("observation")); + rp.setBaseResourceNames(Arrays.asList("list")); rp.parse(); // rp.bindValueSets(vsp); diff --git a/hapi-tinder-plugin/src/main/java/ca/uhn/fhir/tinder/parser/BaseStructureParser.java b/hapi-tinder-plugin/src/main/java/ca/uhn/fhir/tinder/parser/BaseStructureParser.java index d6855b502aa..6d3ea0c0f74 100644 --- a/hapi-tinder-plugin/src/main/java/ca/uhn/fhir/tinder/parser/BaseStructureParser.java +++ b/hapi-tinder-plugin/src/main/java/ca/uhn/fhir/tinder/parser/BaseStructureParser.java @@ -84,7 +84,8 @@ public abstract class BaseStructureParser { } } - private ca.uhn.fhir.model.api.annotation.SimpleSetter.Parameter findAnnotation(Class theBase, Annotation[] theAnnotations, Class theClass) { + private ca.uhn.fhir.model.api.annotation.SimpleSetter.Parameter findAnnotation(Class theBase, Annotation[] theAnnotations, + Class theClass) { for (Annotation next : theAnnotations) { if (theClass.equals(next.annotationType())) { return (ca.uhn.fhir.model.api.annotation.SimpleSetter.Parameter) next; @@ -279,6 +280,7 @@ public abstract class BaseStructureParser { } else { ctx.put("className", (theResource.getName())); } // HumanName} + ctx.put("elementName", theResource.getElementName()); ctx.put("classNameComplete", (theResource.getName()) + getFilenameSuffix()); // HumanNameDt ctx.put("shortName", defaultString(theResource.getShortName())); ctx.put("definition", defaultString(theResource.getDefinition())); @@ -337,7 +339,8 @@ public abstract class BaseStructureParser { // File f = new File(theOutputDirectory, (next.getDeclaringClassNameComplete()) /*+ getFilenameSuffix()*/ + // ".java"); - File f = new File(theOutputDirectory, (next.getElementName()) + getFilenameSuffix() + ".java"); + String elementName = translateClassName(next.getElementName()); + File f = new File(theOutputDirectory, elementName + getFilenameSuffix() + ".java"); try { write(next, f, thePackageBase); } catch (IOException e) { @@ -346,16 +349,16 @@ public abstract class BaseStructureParser { } } - // private String translateClassName(String theName) { - // if ("List".equals(theName)) { - // return "ListResource"; - // } - // return theName; - // } + private String translateClassName(String theName) { + if ("List".equals(theName)) { + return "ListResource"; + } + return theName; + } /** - * Example: Encounter has an internal block class named "Location", but it also has a reference to the Location - * resource type, so we need to use the fully qualified name for that resource reference + * Example: Encounter has an internal block class named "Location", but it also has a reference to the Location resource type, so we need to use the fully qualified name for that resource + * reference */ private void fixResourceReferenceClassNames(BaseElement theNext, String thePackageBase) { for (BaseElement next : theNext.getChildren()) { diff --git a/hapi-tinder-plugin/src/main/resources/vm/dt_composite.vm b/hapi-tinder-plugin/src/main/resources/vm/dt_composite.vm index d5759a9b4e8..a9757b72d17 100644 --- a/hapi-tinder-plugin/src/main/resources/vm/dt_composite.vm +++ b/hapi-tinder-plugin/src/main/resources/vm/dt_composite.vm @@ -2,6 +2,8 @@ package ${packageBase}.composite; +import java.math.BigDecimal; +import org.apache.commons.lang3.StringUtils; import java.util.*; import ca.uhn.fhir.model.api.*; import ca.uhn.fhir.model.api.annotation.*; @@ -153,6 +155,71 @@ public class ${className} setSystem(theSystem); setUnits(theUnits); } + + @Override + public void setValueAsQueryToken(String theQualifier, String theValue) { + setComparator((BoundCodeDt) null); + setCode((CodeDt) null); + setSystem((UriDt) null); + setUnits((StringDt) null); + setValue((DecimalDt) null); + + if (theValue == null) { + return; + } + String[] parts = theValue.split("\\|"); + if (parts.length > 0 && StringUtils.isNotBlank(parts[0])) { + if (parts[0].startsWith("<=")) { + setComparator(QuantityCompararatorEnum.LESSTHAN_OR_EQUALS); + setValue(new BigDecimal(parts[0].substring(2))); + } else if (parts[0].startsWith("<")) { + setComparator(QuantityCompararatorEnum.LESSTHAN); + setValue(new BigDecimal(parts[0].substring(1))); + } else if (parts[0].startsWith(">=")) { + setComparator(QuantityCompararatorEnum.GREATERTHAN_OR_EQUALS); + setValue(new BigDecimal(parts[0].substring(2))); + } else if (parts[0].startsWith(">")) { + setComparator(QuantityCompararatorEnum.GREATERTHAN); + setValue(new BigDecimal(parts[0].substring(1))); + } else { + setValue(new BigDecimal(parts[0])); + } + } + if (parts.length > 1 && StringUtils.isNotBlank(parts[1])) { + setSystem(parts[1]); + } + if (parts.length > 2 && StringUtils.isNotBlank(parts[2])) { + setUnits(parts[2]); + } + + } + + @Override + public String getValueAsQueryToken() { + StringBuilder b= new StringBuilder(); + if (getComparator() != null) { + b.append(getComparator().getValue()); + } + if (!getValue().isEmpty()) { + b.append(getValue().getValueAsString()); + } + b.append('|'); + if (!getSystem().isEmpty()) { + b.append(getSystem().getValueAsString()); + } + b.append('|'); + if (!getUnits().isEmpty()) { + b.append(getUnits().getValueAsString()); + } + + return b.toString(); + } + + + @Override + public String getQueryParameterQualifier() { + return null; + } #end #if ( ${className} == "ResourceReferenceDt" ) /** @@ -171,7 +238,7 @@ public class ${className} * @param theResourceType The resource type * @param theResourceId The resource ID */ - public ResourceReferenceDt(Class theResourceType, IdDt theResourceId) { + public ResourceReferenceDt(Class theResourceType, ca.uhn.fhir.model.primitive.IdDt theResourceId) { super(theResourceType, theResourceId); } @@ -231,7 +298,7 @@ public class ${className} * {@inheritDoc} */ @Override - public void setValueAsQueryToken(String theParameter) { + public void setValueAsQueryToken(String theQualifier, String theParameter) { int barIndex = theParameter.indexOf('|'); if (barIndex != -1) { setSystem(new UriDt(theParameter.substring(0, barIndex))); @@ -242,7 +309,7 @@ public class ${className} } @Override - public String getQueryParameterQualifier(FhirContext theContext) { + public String getQueryParameterQualifier() { return null; } #end @@ -312,7 +379,7 @@ public class ${className} * {@inheritDoc} */ @Override - public void setValueAsQueryToken(String theParameter) { + public void setValueAsQueryToken(String theQualifier, String theParameter) { int barIndex = theParameter.indexOf('|'); if (barIndex != -1) { setSystem(new UriDt(theParameter.substring(0, barIndex))); @@ -323,7 +390,7 @@ public class ${className} } @Override - public String getQueryParameterQualifier(FhirContext theContext) { + public String getQueryParameterQualifier() { return null; } #end diff --git a/hapi-tinder-plugin/src/main/resources/vm/resource.vm b/hapi-tinder-plugin/src/main/resources/vm/resource.vm index d8189595562..a8fc77eb65e 100644 --- a/hapi-tinder-plugin/src/main/resources/vm/resource.vm +++ b/hapi-tinder-plugin/src/main/resources/vm/resource.vm @@ -16,7 +16,7 @@ import ${import}; ##import ${packageBase}.valueset.*; /** - * HAPI/FHIR ${className} Resource + * HAPI/FHIR ${elementName} Resource * (${shortName}) * *

@@ -37,7 +37,7 @@ import ${import}; * #end */ -@ResourceDef(name="${className}", profile="${profile}", id="${id}") +@ResourceDef(name="${elementName}", profile="${profile}", id="${id}") public class ${className} extends BaseResource implements IResource { #foreach ( $param in $searchParams ) diff --git a/hapi-tinder-test/pom.xml b/hapi-tinder-test/pom.xml index 3b68586a9d0..e2e12493274 100644 --- a/hapi-tinder-test/pom.xml +++ b/hapi-tinder-test/pom.xml @@ -4,7 +4,7 @@ ca.uhn.hapi.fhir hapi-fhir - 0.3 + 0.4-SNAPSHOT ../pom.xml @@ -18,7 +18,7 @@ ca.uhn.hapi.fhir hapi-fhir-base - 0.3 + 0.4-SNAPSHOT @@ -41,7 +41,7 @@ ca.uhn.hapi.fhir hapi-tinder-plugin - 0.3 + 0.4-SNAPSHOT custom-structs diff --git a/pom.xml b/pom.xml index 47baa083aa3..c00a5e0081a 100644 --- a/pom.xml +++ b/pom.xml @@ -11,7 +11,7 @@ ca.uhn.hapi.fhir hapi-fhir pom - 0.3 + 0.4-SNAPSHOT HAPI http://hl7api.sourceforge.net/hapi-fhir/ diff --git a/restful-server-example/pom.xml b/restful-server-example/pom.xml index 8b40d04da96..f8dcf149fb4 100644 --- a/restful-server-example/pom.xml +++ b/restful-server-example/pom.xml @@ -14,7 +14,7 @@ ca.uhn.hapi.fhir hapi-fhir-base - 0.3 + 0.4-SNAPSHOT + + ca.uhn.hapi.fhir + hapi-fhir-base + 0.3 + + + + + ch.qos.logback + logback-classic + 1.1.1 + + + + + javax.servlet + javax.servlet-api + 3.0.1 + provided + + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.1 + + 1.6 + 1.6 + + + + + + org.apache.maven.plugins + maven-deploy-plugin + + true + + + + + + +