diff --git a/.gitignore b/.gitignore index a717ce95fa7..0bc1caebc61 100644 --- a/.gitignore +++ b/.gitignore @@ -16,6 +16,7 @@ nohup.out tmp.txt *.hprof tmp.txt +ca.uhn.fhir.jpa.entity.ResourceIndexedSearchParamString/ # Vagrant stuff. .vagrant diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/BaseRuntimeElementDefinition.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/BaseRuntimeElementDefinition.java index 33df42b4d08..8bcde256ae0 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/BaseRuntimeElementDefinition.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/BaseRuntimeElementDefinition.java @@ -214,8 +214,8 @@ public abstract class BaseRuntimeElementDefinition { /** * HL7.org style. */ - PRIMITIVE_XHTML_HL7ORG - + PRIMITIVE_XHTML_HL7ORG, + } } diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/ModelScanner.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/ModelScanner.java index d1841005d44..e35c919b778 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/ModelScanner.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/ModelScanner.java @@ -54,6 +54,7 @@ import org.hl7.fhir.instance.model.api.IBaseDatatype; import org.hl7.fhir.instance.model.api.IBaseDatatypeElement; import org.hl7.fhir.instance.model.api.IBaseEnumeration; import org.hl7.fhir.instance.model.api.IBaseExtension; +import org.hl7.fhir.instance.model.api.IBaseMetaType; import org.hl7.fhir.instance.model.api.IBaseReference; import org.hl7.fhir.instance.model.api.IBaseResource; import org.hl7.fhir.instance.model.api.IBaseXhtml; @@ -192,7 +193,7 @@ class ModelScanner { Map> resourceTypes = myNameToResourceType; myVersionTypes = scanVersionPropertyFile(theDatatypes, resourceTypes, myVersion); - + // toScan.add(DateDt.class); // toScan.add(CodeDt.class); // toScan.add(DecimalDt.class); @@ -245,58 +246,58 @@ class ModelScanner { private T pullAnnotation(Class theContainer, AnnotatedElement theTarget, Class theAnnotationType) { T retVal = theTarget.getAnnotation(theAnnotationType); - if (myContext.getVersion().getVersion() != FhirVersionEnum.DSTU2_HL7ORG) { +// if (myContext.getVersion().getVersion() != FhirVersionEnum.DSTU2_HL7ORG) { return retVal; - } - - if (retVal == null) { - final Class altAnnotationClass; - /* - * Use a cache to minimize Class.forName calls, since they are slow and expensive.. - */ - if (myAnnotationForwards.containsKey(theAnnotationType) == false) { - String sourceClassName = theAnnotationType.getName(); - String candidateAltClassName = sourceClassName.replace("ca.uhn.fhir.model.api.annotation", "org.hl7.fhir.instance.model.annotations"); - if (!sourceClassName.equals(candidateAltClassName)) { - Class forName; - try { - forName = Class.forName(candidateAltClassName); - ourLog.debug("Forwarding annotation request for [{}] to class [{}]", theAnnotationType, forName); - } catch (ClassNotFoundException e) { - forName = null; - } - altAnnotationClass = (Class) forName; - } else { - altAnnotationClass = null; - } - myAnnotationForwards.put(theAnnotationType, altAnnotationClass); - } else { - altAnnotationClass = myAnnotationForwards.get(theAnnotationType); - } - - if (altAnnotationClass == null) { - return null; - } - - final Annotation altAnnotation; - altAnnotation = theTarget.getAnnotation(altAnnotationClass); - if (altAnnotation == null) { - return null; - } - - InvocationHandler h = new InvocationHandler() { - - @Override - public Object invoke(Object theProxy, Method theMethod, Object[] theArgs) throws Throwable { - Method altMethod = altAnnotationClass.getMethod(theMethod.getName(), theMethod.getParameterTypes()); - return altMethod.invoke(altAnnotation, theArgs); - } - }; - retVal = (T) Proxy.newProxyInstance(theAnnotationType.getClassLoader(), new Class[] { theAnnotationType }, h); - - } - - return retVal; +// } +// +// if (retVal == null) { +// final Class altAnnotationClass; +// /* +// * Use a cache to minimize Class.forName calls, since they are slow and expensive.. +// */ +// if (myAnnotationForwards.containsKey(theAnnotationType) == false) { +// String sourceClassName = theAnnotationType.getName(); +// String candidateAltClassName = sourceClassName.replace("ca.uhn.fhir.model.api.annotation", "org.hl7.fhir.instance.model.annotations"); +// if (!sourceClassName.equals(candidateAltClassName)) { +// Class forName; +// try { +// forName = Class.forName(candidateAltClassName); +// ourLog.debug("Forwarding annotation request for [{}] to class [{}]", theAnnotationType, forName); +// } catch (ClassNotFoundException e) { +// forName = null; +// } +// altAnnotationClass = (Class) forName; +// } else { +// altAnnotationClass = null; +// } +// myAnnotationForwards.put(theAnnotationType, altAnnotationClass); +// } else { +// altAnnotationClass = myAnnotationForwards.get(theAnnotationType); +// } +// +// if (altAnnotationClass == null) { +// return null; +// } +// +// final Annotation altAnnotation; +// altAnnotation = theTarget.getAnnotation(altAnnotationClass); +// if (altAnnotation == null) { +// return null; +// } +// +// InvocationHandler h = new InvocationHandler() { +// +// @Override +// public Object invoke(Object theProxy, Method theMethod, Object[] theArgs) throws Throwable { +// Method altMethod = altAnnotationClass.getMethod(theMethod.getName(), theMethod.getParameterTypes()); +// return altMethod.invoke(altAnnotation, theArgs); +// } +// }; +// retVal = (T) Proxy.newProxyInstance(theAnnotationType.getClassLoader(), new Class[] { theAnnotationType }, h); +// +// } +// +// return retVal; } private void scan(Class theClass) throws ConfigurationException { @@ -366,6 +367,8 @@ class ModelScanner { RuntimeCompositeDatatypeDefinition resourceDef; if (theClass.equals(ExtensionDt.class)) { resourceDef = new RuntimeExtensionDtDefinition(theDatatypeDefinition, theClass, true); +// } else if (IBaseMetaType.class.isAssignableFrom(theClass)) { +// resourceDef = new RuntimeMetaDefinition(theDatatypeDefinition, theClass, isStandardType(theClass)); } else { resourceDef = new RuntimeCompositeDatatypeDefinition(theDatatypeDefinition, theClass, isStandardType(theClass)); } diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeChildChoiceDefinition.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeChildChoiceDefinition.java index e4fa19185aa..940e1e09027 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeChildChoiceDefinition.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeChildChoiceDefinition.java @@ -109,22 +109,26 @@ public class RuntimeChildChoiceDefinition extends BaseRuntimeDeclaredChildDefini } else { nextDef = theClassToElementDefinitions.get(next); BaseRuntimeElementDefinition nextDefForChoice = nextDef; - if (nextDef instanceof IRuntimeDatatypeDefinition) { - IRuntimeDatatypeDefinition nextDefDatatype = (IRuntimeDatatypeDefinition) nextDef; - if (nextDefDatatype.getProfileOf() != null) { - /* - * Elements which are called foo[x] and have a choice which is a profiled datatype must use the - * unprofiled datatype as the element name. E.g. if foo[x] allows markdown as a datatype, it calls the - * element fooString when encoded, because markdown is a profile of string. This is according to the - * FHIR spec - */ - nextDefForChoice = null; - nonPreferred = true; - Class profileType = nextDefDatatype.getProfileOf(); - BaseRuntimeElementDefinition elementDef = theClassToElementDefinitions.get(profileType); - elementName = getElementName() + StringUtils.capitalize(elementDef.getName()); - } - } + /* + * In HAPI 1.3 the following applied: + * Elements which are called foo[x] and have a choice which is a profiled datatype must use the + * unprofiled datatype as the element name. E.g. if foo[x] allows markdown as a datatype, it calls the + * element fooString when encoded, because markdown is a profile of string. This is according to the + * FHIR spec + * + * As of HAPI 1.4 this has been disabled after conversation with Grahame. It appears + * that it is not correct behaviour. + */ +// if (nextDef instanceof IRuntimeDatatypeDefinition) { +// IRuntimeDatatypeDefinition nextDefDatatype = (IRuntimeDatatypeDefinition) nextDef; +// if (nextDefDatatype.getProfileOf() != null) { +// nextDefForChoice = null; +// nonPreferred = true; +// Class profileType = nextDefDatatype.getProfileOf(); +// BaseRuntimeElementDefinition elementDef = theClassToElementDefinitions.get(profileType); +// elementName = getElementName() + StringUtils.capitalize(elementDef.getName()); +// } +// } if (nextDefForChoice != null) { elementName = getElementName() + StringUtils.capitalize(nextDefForChoice.getName()); } diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeChildUndeclaredExtensionDefinition.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeChildUndeclaredExtensionDefinition.java index 2aa52514c92..c9da31aaf5c 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeChildUndeclaredExtensionDefinition.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeChildUndeclaredExtensionDefinition.java @@ -26,6 +26,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Set; +import java.util.TreeSet; import org.apache.commons.lang3.text.WordUtils; import org.hl7.fhir.instance.model.api.IBase; @@ -34,6 +35,7 @@ import org.hl7.fhir.instance.model.api.IBaseResource; import ca.uhn.fhir.model.api.ExtensionDt; import ca.uhn.fhir.model.api.IDatatype; import ca.uhn.fhir.model.base.composite.BaseResourceReferenceDt; +import ca.uhn.fhir.model.primitive.CodeDt; public class RuntimeChildUndeclaredExtensionDefinition extends BaseRuntimeChildDefinition { @@ -153,13 +155,8 @@ public class RuntimeChildUndeclaredExtensionDefinition extends BaseRuntimeChildD myDatatypeToAttributeName = new HashMap, String>(); myDatatypeToDefinition = new HashMap, BaseRuntimeElementDefinition>(); -// for (theContext.get) - for (BaseRuntimeElementDefinition next : theClassToElementDefinitions.values()) { if (next instanceof IRuntimeDatatypeDefinition) { - // if (next.getName().equals("CodeableConcept")) { - // System.out.println(); - // } myDatatypeToDefinition.put(next.getImplementingClass(), next); @@ -178,7 +175,7 @@ public class RuntimeChildUndeclaredExtensionDefinition extends BaseRuntimeChildD * type. */ if (!qualifiedName.startsWith("ca.uhn.fhir.model")) { - if (!qualifiedName.startsWith("org.hl7.fhir.instance.model")) { + if (!qualifiedName.startsWith("org.hl7.fhir")) { continue; } } @@ -198,12 +195,6 @@ public class RuntimeChildUndeclaredExtensionDefinition extends BaseRuntimeChildD myAttributeNameToDefinition = datatypeAttributeNameToDefinition; -// for (Entry> next : myAttributeNameToDefinition.entrySet()) { -// @SuppressWarnings("unchecked") -// Class type = (Class) next.getValue().getImplementingClass(); -// myDatatypeToDefinition.put(type, next.getValue()); -// } - /* * Resource reference - The correct name is 'valueReference' in DSTU2 and 'valueResource' in DSTU1 */ diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimePrimitiveDatatypeDefinition.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimePrimitiveDatatypeDefinition.java index 619c87a16bb..ee4a3999dd2 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimePrimitiveDatatypeDefinition.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimePrimitiveDatatypeDefinition.java @@ -74,7 +74,14 @@ public class RuntimePrimitiveDatatypeDefinition extends BaseRuntimeElementDefini if (myProfileOfType != null) { myProfileOf = theClassToElementDefinitions.get(myProfileOfType); if (myProfileOf == null) { - throw new ConfigurationException("Unknown profileOf value: " + myProfileOfType + " in type " + getImplementingClass().getName()); + StringBuilder b = new StringBuilder(); + b.append("Unknown profileOf value: "); + b.append(myProfileOfType); + b.append(" in type "); + b.append(getImplementingClass().getName()); + b.append(" - Valid types: "); + b.append(theClassToElementDefinitions.keySet()); + throw new ConfigurationException(b.toString()); } } } diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/model/api/IFhirVersion.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/model/api/IFhirVersion.java index b03cecb7ce8..eadf9a77d24 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/model/api/IFhirVersion.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/model/api/IFhirVersion.java @@ -25,6 +25,7 @@ import java.util.Date; import org.hl7.fhir.instance.model.api.IBase; import org.hl7.fhir.instance.model.api.IBaseResource; +import org.hl7.fhir.instance.model.api.IIdType; import org.hl7.fhir.instance.model.api.IPrimitiveType; import ca.uhn.fhir.context.FhirContext; @@ -59,4 +60,6 @@ public interface IFhirVersion { IPrimitiveType getLastUpdated(IBaseResource theResource); + IIdType newIdType(); + } diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/model/api/IResource.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/model/api/IResource.java index c912e957cc7..b4d3a6d7ba3 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/model/api/IResource.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/model/api/IResource.java @@ -40,15 +40,6 @@ import ca.uhn.fhir.model.primitive.IdDt; *

*/ public interface IResource extends ICompositeElement, org.hl7.fhir.instance.model.api.IBaseResource { - /** - * Include constant for * (return all includes) - */ - public static final Include INCLUDE_ALL = new Include("*", false).toLocked(); - - /** - * Include set containing only {@link #INCLUDE_ALL} - */ - public static final Set WILDCARD_ALL_SET = Collections.unmodifiableSet(new HashSet(Arrays.asList(INCLUDE_ALL))); /** * Returns the contained resource list for this resource. diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/model/api/Include.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/model/api/Include.java index 3da5dd95043..a545745c658 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/model/api/Include.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/model/api/Include.java @@ -1,5 +1,8 @@ package ca.uhn.fhir.model.api; +import static org.apache.commons.lang3.StringUtils.isBlank; +import static org.apache.commons.lang3.StringUtils.isNotBlank; + import org.apache.commons.lang3.builder.ToStringBuilder; /* @@ -32,9 +35,9 @@ import org.apache.commons.lang3.builder.ToStringBuilder; */ public class Include { + private final boolean myImmutable; private boolean myRecurse; private String myValue; - private boolean myImmutable; /** * Constructor for non-recursive include @@ -44,10 +47,11 @@ public class Include { */ public Include(String theValue) { myValue = theValue; + myImmutable = false; } /** - * Constructor for non-recursive include + * Constructor for an include * * @param theValue * The _include value, e.g. "Patient:name" @@ -57,6 +61,21 @@ public class Include { public Include(String theValue, boolean theRecurse) { myValue = theValue; myRecurse = theRecurse; + myImmutable = false; + } + + /** + * Constructor for an include + * + * @param theValue + * The _include value, e.g. "Patient:name" + * @param theRecurse + * Should the include recurse + */ + public Include(String theValue, boolean theRecurse, boolean theImmutable) { + myValue = theValue; + myRecurse = theRecurse; + myImmutable = theImmutable; } /** @@ -73,22 +92,6 @@ public class Include { return new Include(myValue, true); } - public String getValue() { - return myValue; - } - - /** - * See the note on equality on the {@link Include class documentation} - */ - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + (myRecurse ? 1231 : 1237); - result = prime * result + ((myValue == null) ? 0 : myValue.hashCode()); - return result; - } - /** * See the note on equality on the {@link Include class documentation} */ @@ -117,6 +120,73 @@ public class Include { return true; } + /** + * Returns the portion of the value before the first colon + */ + public String getParamType() { + int firstColon = myValue.indexOf(':'); + if (firstColon == -1 || firstColon == myValue.length() - 1) { + return null; + } + return myValue.substring(0, firstColon); + } + + /** + * Returns the portion of the value after the first colon but before the second colon + */ + public String getParamName() { + int firstColon = myValue.indexOf(':'); + if (firstColon == -1 || firstColon == myValue.length() - 1) { + return null; + } + int secondColon = myValue.indexOf(':', firstColon + 1); + if (secondColon != -1) { + return myValue.substring(firstColon + 1, secondColon); + } else { + return myValue.substring(firstColon + 1); + } + } + + /** + * Returns the portion of the string after the second colon, or null if there are not two colons in the value. + */ + public String getParamTargetType() { + int firstColon = myValue.indexOf(':'); + if (firstColon == -1 || firstColon == myValue.length() - 1) { + return null; + } + int secondColon = myValue.indexOf(':', firstColon + 1); + if (secondColon != -1) { + return myValue.substring(secondColon + 1); + } else { + return null; + } + + } + + public String getValue() { + return myValue; + } + + /** + * See the note on equality on the {@link Include class documentation} + */ + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + (myRecurse ? 1231 : 1237); + result = prime * result + ((myValue == null) ? 0 : myValue.hashCode()); + return result; + } + + /** + * Is this object {@link #toLocked() locked}? + */ + public boolean isLocked() { + return myImmutable; + } + public boolean isRecurse() { return myRecurse; } @@ -132,12 +202,14 @@ public class Include { myValue = theValue; } + /** + * Return a new + */ public Include toLocked() { - Include retVal = new Include(myValue, myRecurse); - retVal.myImmutable = true; + Include retVal = new Include(myValue, myRecurse, true); return retVal; } - + @Override public String toString() { ToStringBuilder builder = new ToStringBuilder(this); @@ -145,4 +217,56 @@ public class Include { builder.append("recurse", myRecurse); return builder.toString(); } + + /** + * Creates and returns a new copy of this Include with the given type. The following table shows what will be + * returned: + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + *
Initial ContentstheResourceTypeOutput
Patient:careProvider + * OrganizationPatient:careProvider:Organization
Patient:careProvider:Practitioner + * OrganizationPatient:careProvider:Organization
Patient + * (any){@link IllegalStateException}
+ * + * @param theResourceType + * The resource type (e.g. "Organization") + * @return A new copy of the include. Note that if this include is {@link #toLocked() locked}, the returned include + * will be too + */ + public Include withType(String theResourceType) { + StringBuilder b = new StringBuilder(); + + String paramType = getParamType(); + String paramName = getParamName(); + if (isBlank(paramType) || isBlank(paramName)) { + throw new IllegalStateException("This include does not contain a value in the format [ResourceType]:[paramName]"); + } + b.append(paramType); + b.append(":"); + b.append(paramName); + + if (isNotBlank(theResourceType)) { + b.append(':'); + b.append(theResourceType); + } + Include retVal = new Include(b.toString(), myRecurse, myImmutable); + return retVal; + } + } diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/model/api/ResourceMetadataKeyEnum.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/model/api/ResourceMetadataKeyEnum.java index 1d2572e03ae..7d17e214d9a 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/model/api/ResourceMetadataKeyEnum.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/model/api/ResourceMetadataKeyEnum.java @@ -30,6 +30,7 @@ import java.util.Map; import org.apache.commons.lang3.StringUtils; import org.hl7.fhir.instance.model.api.IAnyResource; +import org.hl7.fhir.instance.model.api.IPrimitiveType; import ca.uhn.fhir.model.base.composite.BaseCodingDt; import ca.uhn.fhir.model.primitive.DecimalDt; @@ -72,7 +73,7 @@ public abstract class ResourceMetadataKeyEnum implements Serializable { * Values for this key are of type {@link InstantDt} *

*/ - public static final ResourceMetadataKeyEnum DELETED_AT = new ResourceMetadataKeyEnum("DELETED_AT") { + public static final ResourceMetadataKeySupportingAnyResource> DELETED_AT = new ResourceMetadataKeySupportingAnyResource>("DELETED_AT") { private static final long serialVersionUID = 1L; @Override @@ -84,6 +85,17 @@ public abstract class ResourceMetadataKeyEnum implements Serializable { public void put(IResource theResource, InstantDt theObject) { theResource.getResourceMetadata().put(DELETED_AT, theObject); } + + @SuppressWarnings("unchecked") + @Override + public IPrimitiveType get(IAnyResource theResource) { + return (IPrimitiveType) theResource.getUserData(DELETED_AT.name()); + } + + @Override + public void put(IAnyResource theResource, IPrimitiveType theObject) { + theResource.setUserData(DELETED_AT.name(), theObject); + } }; /** @@ -121,7 +133,7 @@ public abstract class ResourceMetadataKeyEnum implements Serializable { * Values for this key are of type {@link BundleEntrySearchModeEnum} *

*/ - public static final ResourceMetadataKeyEnum ENTRY_SEARCH_MODE = new ResourceMetadataKeyEnum("ENTRY_SEARCH_MODE") { + public static final ResourceMetadataKeySupportingAnyResource ENTRY_SEARCH_MODE = new ResourceMetadataKeySupportingAnyResource("ENTRY_SEARCH_MODE") { private static final long serialVersionUID = 1L; @Override public BundleEntrySearchModeEnum get(IResource theResource) { @@ -132,6 +144,16 @@ public abstract class ResourceMetadataKeyEnum implements Serializable { public void put(IResource theResource, BundleEntrySearchModeEnum theObject) { theResource.getResourceMetadata().put(ENTRY_SEARCH_MODE, theObject); } + + @Override + public String get(IAnyResource theResource) { + return (String) theResource.getUserData(ENTRY_SEARCH_MODE.name()); + } + + @Override + public void put(IAnyResource theResource, String theObject) { + theResource.setUserData(ENTRY_SEARCH_MODE.name(), theObject); + } }; /** @@ -146,7 +168,7 @@ public abstract class ResourceMetadataKeyEnum implements Serializable { * Values for this key are of type {@link BundleEntryTransactionMethodEnum} *

*/ - public static final ResourceMetadataKeyEnum ENTRY_TRANSACTION_METHOD = new ResourceMetadataKeyEnum( + public static final ResourceMetadataKeySupportingAnyResource ENTRY_TRANSACTION_METHOD = new ResourceMetadataKeySupportingAnyResource( "ENTRY_TRANSACTION_OPERATION") { private static final long serialVersionUID = 1L; @@ -160,6 +182,16 @@ public abstract class ResourceMetadataKeyEnum implements Serializable { public void put(IResource theResource, BundleEntryTransactionMethodEnum theObject) { theResource.getResourceMetadata().put(ENTRY_TRANSACTION_METHOD, theObject); } + + @Override + public String get(IAnyResource theResource) { + return (String) theResource.getUserData(ENTRY_TRANSACTION_METHOD.name()); + } + + @Override + public void put(IAnyResource theResource, String theObject) { + theResource.setUserData(ENTRY_TRANSACTION_METHOD.name(), theObject); + } }; @@ -575,4 +607,19 @@ public abstract class ResourceMetadataKeyEnum implements Serializable { + IdDt.class.getCanonicalName()); } + public static abstract class ResourceMetadataKeySupportingAnyResource extends ResourceMetadataKeyEnum { + + public ResourceMetadataKeySupportingAnyResource(String theValue) { + super(theValue); + } + + private static final long serialVersionUID = 1L; + + + public abstract T2 get(IAnyResource theResource); + + public abstract void put(IAnyResource theResource, T2 theObject); + + } + } diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/model/base/composite/BaseCodingDt.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/model/base/composite/BaseCodingDt.java index 6c297dbe0a6..4669e072368 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/model/base/composite/BaseCodingDt.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/model/base/composite/BaseCodingDt.java @@ -21,6 +21,7 @@ package ca.uhn.fhir.model.base.composite; */ import org.apache.commons.lang3.StringUtils; +import org.hl7.fhir.instance.model.api.IBaseCoding; import ca.uhn.fhir.model.api.BaseIdentifiableElement; import ca.uhn.fhir.model.api.ICompositeDatatype; diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/model/primitive/IdDt.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/model/primitive/IdDt.java index a9e65b40cc0..3446cb699c7 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/model/primitive/IdDt.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/model/primitive/IdDt.java @@ -675,4 +675,25 @@ public class IdDt extends UriDt implements IPrimitiveDatatype, IIdType { return theIdPart.toString(); } + @Override + public IIdType setParts(String theBaseUrl, String theResourceType, String theIdPart, String theVersionIdPart) { + if (isNotBlank(theVersionIdPart)) { + Validate.notBlank(theResourceType, "If theVersionIdPart is populated, theResourceType and theIdPart must be populated"); + Validate.notBlank(theIdPart, "If theVersionIdPart is populated, theResourceType and theIdPart must be populated"); + } + if (isNotBlank(theBaseUrl) && isNotBlank(theIdPart)) { + Validate.notBlank(theResourceType, "If theBaseUrl is populated and theIdPart is populated, theResourceType must be populated"); + } + + setValue(null); + + myBaseUrl = theBaseUrl; + myResourceType = theResourceType; + myUnqualifiedId = theIdPart; + myUnqualifiedVersionId = StringUtils.defaultIfBlank(theVersionIdPart, null); + myHaveComponentParts = true; + + return this; + } + } diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/parser/BaseParser.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/parser/BaseParser.java index 1e0941ee599..9f6141aab8a 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/parser/BaseParser.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/parser/BaseParser.java @@ -41,6 +41,7 @@ import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.Validate; import org.hl7.fhir.instance.model.api.IAnyResource; import org.hl7.fhir.instance.model.api.IBase; +import org.hl7.fhir.instance.model.api.IBaseCoding; import org.hl7.fhir.instance.model.api.IBaseMetaType; import org.hl7.fhir.instance.model.api.IBaseReference; import org.hl7.fhir.instance.model.api.IBaseResource; @@ -374,6 +375,15 @@ public abstract class BaseParser implements IParser { return stringWriter.toString(); } + private void filterCodingsWithNoCodeOrSystem(List tagList) { + for (int i = 0; i < tagList.size(); i++) { + if (isBlank(tagList.get(i).getCode()) && isBlank(tagList.get(i).getSystem())) { + tagList.remove(i); + i--; + } + } + } + protected String fixContainedResourceId(String theValue) { if (StringUtils.isNotBlank(theValue) && theValue.charAt(0) == '#') { return theValue.substring(1); @@ -409,7 +419,7 @@ public abstract class BaseParser implements IParser { TagList tags = ResourceMetadataKeyEnum.TAG_LIST.get(theIResource); if (shouldAddSubsettedTag()) { tags = new TagList(tags); - tags.add(new Tag(Constants.TAG_SUBSETTED_SYSTEM, Constants.TAG_SUBSETTED_CODE, "Resource encoded in summary mode")); + tags.add(new Tag(Constants.TAG_SUBSETTED_SYSTEM, Constants.TAG_SUBSETTED_CODE, subsetDescription())); } return tags; @@ -538,56 +548,51 @@ public abstract class BaseParser implements IParser { } @SuppressWarnings("cast") - protected List preProcessValues(BaseRuntimeChildDefinition metaChildUncast, List theValues) { - if (myContext.getVersion().getVersion().equals(FhirVersionEnum.DSTU2_HL7ORG)) { - if (shouldAddSubsettedTag() && metaChildUncast.getValidChildNames().contains("meta")) { - BaseRuntimeElementDefinition childByName = metaChildUncast.getChildByName("meta"); - if (childByName instanceof BaseRuntimeElementCompositeDefinition) { - BaseRuntimeElementCompositeDefinition metaChildUncast1 = (BaseRuntimeElementCompositeDefinition) childByName; - if (metaChildUncast1 != null) { - if (IBaseMetaType.class.isAssignableFrom(metaChildUncast1.getImplementingClass())) { - IBaseMetaType metaValue; - if (theValues != null && theValues.size() >= 1) { - metaValue = (IBaseMetaType) theValues.iterator().next(); - try { - metaValue = (IBaseMetaType) metaValue.getClass().getMethod("copy").invoke(metaValue); - } catch (Exception e) { - throw new InternalErrorException("Failed to duplicate meta", e); - } - } else { - metaValue = (IBaseMetaType) metaChildUncast1.newInstance(); - } - - ArrayList retVal = new ArrayList(); - retVal.add(metaValue); - - BaseRuntimeChildDefinition tagChild = metaChildUncast1.getChildByName("tag"); - BaseRuntimeElementCompositeDefinition codingDef = (BaseRuntimeElementCompositeDefinition) ((BaseRuntimeElementCompositeDefinition) tagChild.getChildByName("tag")); - IBase coding = codingDef.newInstance(); - tagChild.getMutator().addValue(metaValue, coding); - - BaseRuntimeChildDefinition systemChild = codingDef.getChildByName("system"); - IPrimitiveType system = (IPrimitiveType) myContext.getElementDefinition("uri").newInstance(); - system.setValueAsString(Constants.TAG_SUBSETTED_SYSTEM); - systemChild.getMutator().addValue(coding, system); - - BaseRuntimeChildDefinition codeChild = codingDef.getChildByName("code"); - IPrimitiveType code = (IPrimitiveType) myContext.getElementDefinition("code").newInstance(); - code.setValueAsString(Constants.TAG_SUBSETTED_CODE); - codeChild.getMutator().addValue(coding, code); - - BaseRuntimeChildDefinition displayChild = codingDef.getChildByName("display"); - IPrimitiveType display = (IPrimitiveType) myContext.getElementDefinition("string").newInstance(); - display.setValueAsString("Resource encoded in summary mode"); - displayChild.getMutator().addValue(coding, display); - - return retVal; - } - } + protected List preProcessValues(BaseRuntimeChildDefinition metaChildUncast, IBaseResource theResource, List theValues) { + if (myContext.getVersion().getVersion().isRi()) { + + /* + * If we're encoding the meta tag, we do some massaging of the meta values before + * encoding. Buf if there is no meta element at all, we create one since we're possibly going to be + * adding things to it + */ + if (theValues.isEmpty() && metaChildUncast.getElementName().equals("meta")) { + BaseRuntimeElementDefinition metaChild = metaChildUncast.getChildByName("meta"); + if (IBaseMetaType.class.isAssignableFrom(metaChild.getImplementingClass())) { + IBaseMetaType newType = (IBaseMetaType) metaChild.newInstance(); + theValues = Collections.singletonList(newType); } } + + if (theValues.size() == 1 && theValues.get(0) instanceof IBaseMetaType) { + + IBaseMetaType metaValue = (IBaseMetaType) theValues.get(0); + try { + metaValue = (IBaseMetaType) metaValue.getClass().getMethod("copy").invoke(metaValue); + } catch (Exception e) { + throw new InternalErrorException("Failed to duplicate meta", e); + } + + if (isBlank(metaValue.getVersionId())) { + if (theResource.getIdElement().hasVersionIdPart()) { + metaValue.setVersionId(theResource.getIdElement().getVersionIdPart()); + } + } + + filterCodingsWithNoCodeOrSystem(metaValue.getTag()); + filterCodingsWithNoCodeOrSystem(metaValue.getSecurity()); + + if (shouldAddSubsettedTag()) { + IBaseCoding coding = metaValue.addTag(); + coding.setCode(Constants.TAG_SUBSETTED_CODE); + coding.setSystem(Constants.TAG_SUBSETTED_SYSTEM); + coding.setDisplay(subsetDescription()); + } + + return Collections.singletonList(metaValue); + } } - + return theValues; } @@ -656,6 +661,10 @@ public abstract class BaseParser implements IParser { return isSummaryMode() || isSuppressNarratives(); } + private String subsetDescription() { + return "Resource encoded in summary mode"; + } + protected void throwExceptionForUnknownChildType(BaseRuntimeChildDefinition nextChild, Class theType) { if (nextChild instanceof BaseRuntimeDeclaredChildDefinition) { StringBuilder b = new StringBuilder(); diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/parser/JsonParser.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/parser/JsonParser.java index c29676a95bc..d499f27fbb1 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/parser/JsonParser.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/parser/JsonParser.java @@ -531,7 +531,7 @@ public class JsonParser extends BaseParser implements IParser { BaseRuntimeChildDefinition nextChild = nextChildElem.getDef(); if (nextChild instanceof RuntimeChildNarrativeDefinition) { INarrativeGenerator gen = myContext.getNarrativeGenerator(); - if (gen != null) { + if (gen != null && theResource instanceof IResource) { BaseNarrativeDt narr = ((IResource) theResource).getText(); if (narr.getDiv().isEmpty()) { gen.generateNarrative(theResDef.getResourceProfile(), theResource, narr); @@ -552,7 +552,7 @@ public class JsonParser extends BaseParser implements IParser { } List values = nextChild.getAccessor().getValues(theNextValue); - values = super.preProcessValues(nextChild, values); + values = super.preProcessValues(nextChild, theResource, values); if (values == null || values.isEmpty()) { continue; diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/parser/ParserState.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/parser/ParserState.java index 1f895749867..949e44829ae 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/parser/ParserState.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/parser/ParserState.java @@ -28,6 +28,7 @@ import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set; +import java.util.TreeSet; import javax.xml.stream.events.StartElement; import javax.xml.stream.events.XMLEvent; diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/parser/XmlParser.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/parser/XmlParser.java index 5cf70ca0d32..b6e9c1f04bc 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/parser/XmlParser.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/parser/XmlParser.java @@ -600,7 +600,7 @@ public class XmlParser extends BaseParser implements IParser { } else { List values = nextChild.getAccessor().getValues(theElement); - values = super.preProcessValues(nextChild, values); + values = super.preProcessValues(nextChild, theResource, values); if (values == null || values.isEmpty()) { continue; diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/annotation/OptionalParam.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/annotation/OptionalParam.java index e40a6834266..39c0c0507f2 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/annotation/OptionalParam.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/annotation/OptionalParam.java @@ -23,8 +23,9 @@ package ca.uhn.fhir.rest.annotation; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; +import org.hl7.fhir.instance.model.api.IBaseResource; + import ca.uhn.fhir.model.api.IQueryParameterType; -import ca.uhn.fhir.model.api.IResource; import ca.uhn.fhir.rest.param.CompositeParam; import ca.uhn.fhir.rest.param.ReferenceParam; //import ca.uhn.fhir.testmodel.Patient; // TODO: qualify this correctly @@ -116,5 +117,5 @@ public @interface OptionalParam { * this value must not be populated. *

*/ - Class[] targetTypes() default {}; + Class[] targetTypes() default {}; } diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/annotation/RequiredParam.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/annotation/RequiredParam.java index 110148f8f72..84b93d23171 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/annotation/RequiredParam.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/annotation/RequiredParam.java @@ -23,8 +23,9 @@ package ca.uhn.fhir.rest.annotation; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; +import org.hl7.fhir.instance.model.api.IBaseResource; + import ca.uhn.fhir.model.api.IQueryParameterType; -import ca.uhn.fhir.model.api.IResource; import ca.uhn.fhir.rest.param.CompositeParam; import ca.uhn.fhir.rest.param.ReferenceParam; //import ca.uhn.fhir.testmodel.Patient; // TODO: qualify this correctly @@ -97,6 +98,6 @@ public @interface RequiredParam { * If the parameter annotated with this annotation is not a {@link ReferenceParam}, this value must not be populated. *

*/ - Class[] targetTypes() default {}; + Class[] targetTypes() default {}; } diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/api/MethodOutcome.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/api/MethodOutcome.java index 68962458dfc..d148828dfa7 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/api/MethodOutcome.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/api/MethodOutcome.java @@ -50,7 +50,7 @@ public class MethodOutcome { * If not null, indicates whether the resource was created (as opposed to being updated). This is generally not needed, since the server can assume based on the method being called * whether the result was a creation or an update. However, it can be useful if you are implementing an update method that does a create if the ID doesn't already exist. */ - public MethodOutcome(IdDt theId, Boolean theCreated) { + public MethodOutcome(IIdType theId, Boolean theCreated) { myId = theId; myCreated = theCreated; } @@ -64,7 +64,7 @@ public class MethodOutcome { * @param theBaseOperationOutcome * The operation outcome to return with the response (or null for none) */ - public MethodOutcome(IdDt theId, IBaseOperationOutcome theBaseOperationOutcome) { + public MethodOutcome(IIdType theId, IBaseOperationOutcome theBaseOperationOutcome) { myId = theId; myOperationOutcome = theBaseOperationOutcome; } @@ -82,17 +82,17 @@ public class MethodOutcome { * If not null, indicates whether the resource was created (as opposed to being updated). This is generally not needed, since the server can assume based on the method being called * whether the result was a creation or an update. However, it can be useful if you are implementing an update method that does a create if the ID doesn't already exist. */ - public MethodOutcome(IdDt theId, IBaseOperationOutcome theBaseOperationOutcome, Boolean theCreated) { + public MethodOutcome(IIdType theId, IBaseOperationOutcome theBaseOperationOutcome, Boolean theCreated) { myId = theId; myOperationOutcome = theBaseOperationOutcome; myCreated = theCreated; } /** - * @deprecated Use the constructor which accepts a single IdDt parameter, and include the logical ID and version ID in that IdDt instance + * @deprecated Use the constructor which accepts a single IIdType parameter, and include the logical ID and version ID in that IIdType instance */ @Deprecated - public MethodOutcome(IdDt theId, IdDt theVersionId) { + public MethodOutcome(IIdType theId, IdDt theVersionId) { myId = theId; myVersionId = theVersionId; } @@ -101,7 +101,7 @@ public class MethodOutcome { * @deprecated Use the constructor which accepts a single IdDt parameter, and include the logical ID and version ID in that IdDt instance */ @Deprecated - public MethodOutcome(IdDt theId, IdDt theVersionId, IBaseOperationOutcome theBaseOperationOutcome) { + public MethodOutcome(IIdType theId, IdDt theVersionId, IBaseOperationOutcome theBaseOperationOutcome) { myId = theId; myVersionId = theVersionId; myOperationOutcome = theBaseOperationOutcome; @@ -175,7 +175,7 @@ public class MethodOutcome { * @param theId * The ID of the created/updated resource */ - public void setId(IdDt theId) { + public void setId(IIdType theId) { myId = theId; } @@ -200,7 +200,7 @@ public class MethodOutcome { } /** - * @deprecated Put the ID and version ID into the same IdDt instance and pass it to {@link #setId(IdDt)} + * @deprecated Put the ID and version ID into the same IdDt instance and pass it to {@link #setId(IIdType)} */ @Deprecated public void setVersionId(IdDt theVersionId) { 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 6b568af7fde..9383bdc93b2 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 @@ -853,10 +853,10 @@ public class GenericClient extends BaseClient implements IGenericClient { } @Override - public IDeleteTyped resource(IResource theResource) { + public IDeleteTyped resource(IBaseResource theResource) { Validate.notNull(theResource, "theResource can not be null"); - IdDt id = theResource.getId(); - Validate.notNull(id, "theResource.getId() can not be null"); + IIdType id = theResource.getIdElement(); + Validate.notNull(id, "theResource.getIdElement() can not be null"); if (id.hasResourceType() == false || id.hasIdPart() == false) { throw new IllegalArgumentException("theResource.getId() must contain a resource type and logical ID at a minimum (e.g. Patient/1234), found: " + id.getValue()); } @@ -1798,7 +1798,7 @@ public class GenericClient extends BaseClient implements IGenericClient { } } - if (myReturnBundleType == null && myContext.getVersion().getVersion().equals(FhirVersionEnum.DSTU2_HL7ORG)) { + if (myReturnBundleType == null && myContext.getVersion().getVersion().isRi()) { throw new IllegalArgumentException("When using the client with HL7.org structures, you must specify " + "the bundle return type for the client by adding \".returnBundle(org.hl7.fhir.instance.model.Bundle.class)\" to your search method call before the \".execute()\" method"); } diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/client/interceptor/GZipContentInterceptor.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/client/interceptor/GZipContentInterceptor.java index c4d73341395..c5b7803c647 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/client/interceptor/GZipContentInterceptor.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/client/interceptor/GZipContentInterceptor.java @@ -1,5 +1,25 @@ package ca.uhn.fhir.rest.client.interceptor; +/* + * #%L + * HAPI FHIR - Core Library + * %% + * Copyright (C) 2014 - 2015 University Health Network + * %% + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * #L% + */ + import java.io.ByteArrayOutputStream; import java.io.IOException; import java.util.zip.GZIPOutputStream; diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/gclient/IDelete.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/gclient/IDelete.java index 6c0441897b3..a8f24b7bcc3 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/gclient/IDelete.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/gclient/IDelete.java @@ -3,8 +3,6 @@ package ca.uhn.fhir.rest.gclient; import org.hl7.fhir.instance.model.api.IBaseResource; import org.hl7.fhir.instance.model.api.IIdType; -import ca.uhn.fhir.model.api.IResource; - /* * #%L * HAPI FHIR - Core Library @@ -27,7 +25,7 @@ import ca.uhn.fhir.model.api.IResource; public interface IDelete { - IDeleteTyped resource(IResource theResource); + IDeleteTyped resource(IBaseResource theResource); IDeleteTyped resourceById(IIdType theId); diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/method/BaseOutcomeReturningMethodBinding.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/method/BaseOutcomeReturningMethodBinding.java index 37316520fa4..ee5e66dba83 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/method/BaseOutcomeReturningMethodBinding.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/method/BaseOutcomeReturningMethodBinding.java @@ -33,6 +33,7 @@ import javax.servlet.http.HttpServletResponse; import org.apache.commons.lang3.StringUtils; import org.hl7.fhir.instance.model.api.IBaseResource; +import org.hl7.fhir.instance.model.api.IIdType; import ca.uhn.fhir.context.ConfigurationException; import ca.uhn.fhir.context.FhirContext; @@ -267,12 +268,14 @@ abstract class BaseOutcomeReturningMethodBinding extends BaseMethodBinding 0) { String locationHeader = locationHeaders.get(0); - BaseOutcomeReturningMethodBinding.parseContentLocation(retVal, theResourceName, locationHeader); + BaseOutcomeReturningMethodBinding.parseContentLocation(theContext, retVal, theResourceName, locationHeader); } if (theResponseStatusCode != Constants.STATUS_HTTP_204_NO_CONTENT) { EncodingEnum ct = EncodingEnum.forContentType(theResponseMimeType); diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/method/OperationParameter.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/method/OperationParameter.java index cf9bf56e18a..53b3b562a61 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/method/OperationParameter.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/method/OperationParameter.java @@ -43,6 +43,7 @@ import ca.uhn.fhir.context.RuntimeChildPrimitiveDatatypeDefinition; import ca.uhn.fhir.context.RuntimePrimitiveDatatypeDefinition; import ca.uhn.fhir.context.RuntimeResourceDefinition; import ca.uhn.fhir.i18n.HapiLocalizer; +import ca.uhn.fhir.model.api.IDatatype; import ca.uhn.fhir.rest.annotation.OperationParam; import ca.uhn.fhir.rest.api.RequestTypeEnum; import ca.uhn.fhir.rest.api.ValidationModeEnum; @@ -66,7 +67,7 @@ public class OperationParameter implements IParameter { private final String myOperationName; private Class myParameterType; private String myParamType; - private FhirContext myContext; + private final FhirContext myContext; private boolean myAllowGet; public OperationParameter(FhirContext theCtx, String theOperationName, OperationParam theOperationParam) { @@ -83,6 +84,10 @@ public class OperationParameter implements IParameter { + protected FhirContext getContext() { + return myContext; + } + public int getMax() { return myMax; } @@ -102,6 +107,12 @@ public class OperationParameter implements IParameter { @SuppressWarnings("unchecked") @Override public void initializeTypes(Method theMethod, Class> theOuterCollectionType, Class> theInnerCollectionType, Class theParameterType) { + if (getContext().getVersion().getVersion().isRi()) { + if (IDatatype.class.isAssignableFrom(theParameterType)) { + throw new ConfigurationException("Incorrect use of type " + theParameterType.getSimpleName() + " as parameter type for method when context is for version " + getContext().getVersion().getVersion().name() + " in method: " + theMethod.toString()); + } + } + myParameterType = theParameterType; if (theInnerCollectionType != null) { myInnerCollectionType = CollectionBinder.getInstantiableCollectionType(theInnerCollectionType, myName); diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/method/RequestDetails.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/method/RequestDetails.java index ff60bbe59f4..5d074f8fbe5 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/method/RequestDetails.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/method/RequestDetails.java @@ -31,6 +31,8 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import org.hl7.fhir.instance.model.api.IIdType; + import ca.uhn.fhir.model.primitive.IdDt; import ca.uhn.fhir.rest.api.RequestTypeEnum; import ca.uhn.fhir.rest.api.RestOperationTypeEnum; @@ -43,7 +45,7 @@ public abstract class RequestDetails { private String myCompartmentName; private String myCompleteUrl; private String myFhirServerBase; - private IdDt myId; + private IIdType myId; private String myOperation; private Map myParameters; private String myRequestPath; @@ -72,7 +74,7 @@ public abstract class RequestDetails { return myFhirServerBase; } - public IdDt getId() { + public IIdType getId() { return myId; } @@ -132,7 +134,7 @@ public abstract class RequestDetails { myFhirServerBase = theFhirServerBase; } - public void setId(IdDt theId) { + public void setId(IIdType theId) { myId = theId; } diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/method/SearchParameter.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/method/SearchParameter.java index 17d7710c23d..2a9e2198544 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/method/SearchParameter.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/method/SearchParameter.java @@ -30,13 +30,13 @@ import java.util.List; import java.util.Set; import org.apache.commons.lang3.builder.ToStringBuilder; +import org.hl7.fhir.instance.model.api.IBaseResource; import ca.uhn.fhir.context.ConfigurationException; import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.model.api.IQueryParameterAnd; import ca.uhn.fhir.model.api.IQueryParameterOr; import ca.uhn.fhir.model.api.IQueryParameterType; -import ca.uhn.fhir.model.api.IResource; import ca.uhn.fhir.model.base.composite.BaseIdentifierDt; import ca.uhn.fhir.model.base.composite.BaseQuantityDt; import ca.uhn.fhir.model.primitive.StringDt; @@ -133,7 +133,7 @@ public class SearchParameter extends BaseQueryParameter { } private List> myCompositeTypes; - private List> myDeclaredTypes; + private List> myDeclaredTypes; private String myDescription; private String myName; private IParamBinder myParamBinder; @@ -168,7 +168,7 @@ public class SearchParameter extends BaseQueryParameter { return retVal; } - public List> getDeclaredTypes() { + public List> getDeclaredTypes() { return Collections.unmodifiableList(myDeclaredTypes); } @@ -255,7 +255,7 @@ public class SearchParameter extends BaseQueryParameter { myCompositeTypes = Arrays.asList(theCompositeTypes); } - public void setDeclaredTypes(Class[] theTypes) { + public void setDeclaredTypes(Class[] theTypes) { myDeclaredTypes = Arrays.asList(theTypes); } diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/method/UpdateMethodBinding.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/method/UpdateMethodBinding.java index d463e9c7dc6..1e8578cfef8 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/method/UpdateMethodBinding.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/method/UpdateMethodBinding.java @@ -1,6 +1,5 @@ package ca.uhn.fhir.rest.method; -import static org.apache.commons.lang3.StringUtils.isBlank; /* * #%L * HAPI FHIR - Core Library @@ -26,6 +25,8 @@ import java.lang.reflect.Method; import java.util.Collections; import java.util.Set; +import org.hl7.fhir.instance.model.api.IIdType; + import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.model.api.IResource; import ca.uhn.fhir.model.primitive.IdDt; @@ -59,9 +60,9 @@ public class UpdateMethodBinding extends BaseOutcomeReturningMethodBindingWithRe * Content-Location header, but we allow it in the PUT URL as well.. */ String locationHeader = theRequest.getHeader(Constants.HEADER_CONTENT_LOCATION); - IdDt id = theRequest.getId(); + IIdType id = theRequest.getId(); if (isNotBlank(locationHeader)) { - id = new IdDt(locationHeader); + id.setValue(locationHeader); if (isNotBlank(id.getResourceType())) { if (!getResourceName().equals(id.getResourceType())) { throw new InvalidRequestException("Attempting to update '" + getResourceName() + "' but content-location header specifies different resource type '" + id.getResourceType() + "' - header value: " + locationHeader); @@ -85,7 +86,7 @@ public class UpdateMethodBinding extends BaseOutcomeReturningMethodBindingWithRe if (isNotBlank(locationHeader)) { MethodOutcome mo = new MethodOutcome(); - parseContentLocation(mo, getResourceName(), locationHeader); + parseContentLocation(getContext(), mo, getResourceName(), locationHeader); if (mo.getId() == null || mo.getId().isEmpty()) { throw new InvalidRequestException("Invalid Content-Location header for resource " + getResourceName() + ": " + locationHeader); } diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/param/DateParam.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/param/DateParam.java index a05cb5b41e9..75dc9aed720 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/param/DateParam.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/param/DateParam.java @@ -25,6 +25,7 @@ import java.util.Date; import java.util.List; import org.apache.commons.lang3.Validate; +import org.hl7.fhir.instance.model.api.IPrimitiveType; import ca.uhn.fhir.model.api.IQueryParameterOr; import ca.uhn.fhir.model.api.IQueryParameterType; @@ -63,6 +64,14 @@ public class DateParam extends DateTimeDt implements IQueryParameterType, IQuery setValueAsString(theDate != null ? theDate.getValueAsString() : null); } + /** + * Constructor + */ + public DateParam(QuantityCompararatorEnum theComparator, IPrimitiveType theDate) { + myComparator = theComparator; + setValueAsString(theDate != null ? theDate.getValueAsString() : null); + } + /** * Constructor */ 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 187be2eb313..f48b3cfadc2 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 @@ -24,6 +24,8 @@ import java.util.ArrayList; import java.util.Date; import java.util.List; +import org.hl7.fhir.instance.model.api.IPrimitiveType; + import ca.uhn.fhir.model.api.IQueryParameterAnd; import ca.uhn.fhir.model.dstu.valueset.QuantityCompararatorEnum; import ca.uhn.fhir.model.primitive.DateTimeDt; @@ -106,6 +108,20 @@ public class DateRangeParam implements IQueryParameterAnd { setRangeFromDatesInclusive(theLowerBound, theUpperBound); } + /** + * Constructor which takes two Dates representing the lower and upper bounds of the range (inclusive on both ends) + * + * @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:00Z". Will be treated inclusively. Either theLowerBound or theUpperBound may both be populated, or one may be null, but it is not valid for both to be null. + * @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:00Z". Will be treated inclusively. Either theLowerBound or theUpperBound may both be populated, or one may be null, but it is not valid for both to be null. + */ + public DateRangeParam(IPrimitiveType theLowerBound, IPrimitiveType theUpperBound) { + setRangeFromDatesInclusive(theLowerBound, theUpperBound); + } + /** * Constructor which takes two strings representing the lower and upper bounds of the range (inclusive on both ends) * @@ -272,6 +288,21 @@ public class DateRangeParam implements IQueryParameterAnd { validateAndThrowDataFormatExceptionIfInvalid(); } + /** + * Sets the range from a pair of dates, inclusive on both ends + * + * @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:00Z". Will be treated inclusively. Either theLowerBound or theUpperBound may both be populated, or one may be null, but it is not valid for both to be null. + * @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:00Z". Will be treated inclusively. Either theLowerBound or theUpperBound may both be populated, or one may be null, but it is not valid for both to be null. + */ + public void setRangeFromDatesInclusive(IPrimitiveType theLowerBound, IPrimitiveType theUpperBound) { + myLowerBound = theLowerBound != null ? new DateParam(QuantityCompararatorEnum.GREATERTHAN_OR_EQUALS, theLowerBound) : null; + myUpperBound = theUpperBound != null ? new DateParam(QuantityCompararatorEnum.LESSTHAN_OR_EQUALS, theUpperBound) : null; + validateAndThrowDataFormatExceptionIfInvalid(); + } /** * Sets the range from a pair of dates, inclusive on both ends * diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/param/QuantityParam.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/param/QuantityParam.java index cf9af94e4bc..30dd986fdb8 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/param/QuantityParam.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/param/QuantityParam.java @@ -116,6 +116,16 @@ public class QuantityParam extends BaseParam implements IQueryParameterType { setValueAsQueryToken(null, theQuantity); } + /** + * Constructor + * + * @param theQuantity + * A quantity value (with no system or units), such as 100 + */ + public QuantityParam(long theQuantity) { + setValueAsQueryToken(null, Long.toString(theQuantity)); + } + /** * Constructor * diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/server/RestfulServer.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/server/RestfulServer.java index 3e2fd30ac04..8bb2dccee1f 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/server/RestfulServer.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/server/RestfulServer.java @@ -50,12 +50,12 @@ import org.apache.commons.io.IOUtils; import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.Validate; import org.hl7.fhir.instance.model.api.IBaseResource; +import org.hl7.fhir.instance.model.api.IIdType; import ca.uhn.fhir.context.ConfigurationException; import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.context.ProvidedResourceScanner; import ca.uhn.fhir.context.RuntimeResourceDefinition; -import ca.uhn.fhir.model.primitive.IdDt; import ca.uhn.fhir.parser.IParser; import ca.uhn.fhir.rest.annotation.Destroy; import ca.uhn.fhir.rest.annotation.IdParam; @@ -64,7 +64,6 @@ import ca.uhn.fhir.rest.api.MethodOutcome; import ca.uhn.fhir.rest.api.RequestTypeEnum; import ca.uhn.fhir.rest.method.BaseMethodBinding; import ca.uhn.fhir.rest.method.ConformanceMethodBinding; -import ca.uhn.fhir.rest.method.PageMethodBinding; import ca.uhn.fhir.rest.method.ParseAction; import ca.uhn.fhir.rest.method.RequestDetails; import ca.uhn.fhir.rest.server.exceptions.AuthenticationException; @@ -565,13 +564,14 @@ public class RestfulServer extends HttpServlet implements IRestfulServer params = new HashMap(theRequest.getParameterMap()); requestDetails.setParameters(params); - IdDt id; + IIdType id; populateRequestDetailsFromRequestPath(requestDetails, requestPath); if (theRequestType == RequestTypeEnum.PUT) { String contentLocation = theRequest.getHeader(Constants.HEADER_CONTENT_LOCATION); if (contentLocation != null) { - id = new IdDt(contentLocation); + id = myFhirContext.getVersion().newIdType(); + id.setValue(contentLocation); requestDetails.setId(id); } } @@ -876,7 +876,7 @@ public class RestfulServer extends HttpServlet implements IRestfulServer theStrings) { + public static String joinStringsSpaceSeparated(List> theStrings) { StringBuilder b = new StringBuilder(); - for (StringDt next : theStrings) { + for (IPrimitiveType next : theStrings) { if (next.isEmpty()) { continue; } diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/util/FhirTerser.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/util/FhirTerser.java index e4459467e61..2664349e882 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/util/FhirTerser.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/util/FhirTerser.java @@ -30,8 +30,12 @@ import java.util.TreeSet; import org.apache.commons.lang3.Validate; import org.hl7.fhir.instance.model.api.IBase; +import org.hl7.fhir.instance.model.api.IBaseExtension; +import org.hl7.fhir.instance.model.api.IBaseHasExtensions; +import org.hl7.fhir.instance.model.api.IBaseHasModifierExtensions; import org.hl7.fhir.instance.model.api.IBaseReference; import org.hl7.fhir.instance.model.api.IBaseResource; +import org.hl7.fhir.instance.model.api.IDomainResource; import org.hl7.fhir.instance.model.api.IPrimitiveType; import ca.uhn.fhir.context.BaseRuntimeChildDefinition; @@ -68,6 +72,21 @@ public class FhirTerser { addUndeclaredExtensions(nextExt, theDefinition, theChildDefinition, theCallback); } } + + if (theElement instanceof IBaseHasExtensions) { + for (IBaseExtension nextExt : ((IBaseHasExtensions)theElement).getExtension()) { + theCallback.acceptElement(nextExt.getValue(), null, theChildDefinition, theDefinition); + addUndeclaredExtensions(nextExt, theDefinition, theChildDefinition, theCallback); + } + } + + if (theElement instanceof IBaseHasModifierExtensions) { + for (IBaseExtension nextExt : ((IBaseHasModifierExtensions)theElement).getModifierExtension()) { + theCallback.acceptElement(nextExt.getValue(), null, theChildDefinition, theDefinition); + addUndeclaredExtensions(nextExt, theDefinition, theChildDefinition, theCallback); + } + } + } /** diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/util/IModelVisitor.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/util/IModelVisitor.java index c894b4e9302..3deb1aa1b9a 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/util/IModelVisitor.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/util/IModelVisitor.java @@ -23,6 +23,7 @@ package ca.uhn.fhir.util; import java.util.List; import org.hl7.fhir.instance.model.api.IBase; +import org.hl7.fhir.instance.model.api.IBaseExtension; import org.hl7.fhir.instance.model.api.IBaseResource; import ca.uhn.fhir.context.BaseRuntimeChildDefinition; @@ -52,6 +53,4 @@ public interface IModelVisitor { */ void acceptUndeclaredExtension(ISupportsUndeclaredExtensions theContainingElement, List thePathToElement, BaseRuntimeChildDefinition theChildDefinition, BaseRuntimeElementDefinition theDefinition, ExtensionDt theNextExt); - - } diff --git a/hapi-fhir-base/src/main/java/org/hl7/fhir/instance/model/api/IAnyResource.java b/hapi-fhir-base/src/main/java/org/hl7/fhir/instance/model/api/IAnyResource.java index 263359775b0..6e5ef105ff4 100644 --- a/hapi-fhir-base/src/main/java/org/hl7/fhir/instance/model/api/IAnyResource.java +++ b/hapi-fhir-base/src/main/java/org/hl7/fhir/instance/model/api/IAnyResource.java @@ -1,6 +1,7 @@ package org.hl7.fhir.instance.model.api; -import java.util.HashMap; +import ca.uhn.fhir.model.api.annotation.SearchParamDefinition; +import ca.uhn.fhir.rest.gclient.StringClientParam; /* * #%L @@ -24,14 +25,41 @@ import java.util.HashMap; public interface IAnyResource extends IBaseResource { + /** + * Search parameter constant for _language + */ + @SearchParamDefinition(name="_language", path="", description="The language of the resource", type="string" ) + public static final String SP_RES_LANGUAGE = "_language"; + + + /** + * Search parameter constant for _id + */ + @SearchParamDefinition(name="_id", path="", description="The ID of the resource", type="string" ) + public static final String SP_RES_ID = "_id"; + + /** + * Fluent Client search parameter constant for _id + *

+ * Description: the _id of a resource
+ * Type: string
+ * Path: Resource._id
+ *

+ */ + public static final StringClientParam RES_ID = new StringClientParam(IAnyResource.SP_RES_ID); + String getId(); + @Override IIdType getIdElement(); + IPrimitiveType getLanguageElement(); + IBaseMetaType getMeta(); public Object getUserData(String name); + @Override IAnyResource setId(String theId); public void setUserData(String name, Object value); diff --git a/hapi-fhir-base/src/main/java/org/hl7/fhir/instance/model/api/IBaseBackboneElement.java b/hapi-fhir-base/src/main/java/org/hl7/fhir/instance/model/api/IBaseBackboneElement.java index 2e9a014dc93..871db2deadf 100644 --- a/hapi-fhir-base/src/main/java/org/hl7/fhir/instance/model/api/IBaseBackboneElement.java +++ b/hapi-fhir-base/src/main/java/org/hl7/fhir/instance/model/api/IBaseBackboneElement.java @@ -1,5 +1,7 @@ package org.hl7.fhir.instance.model.api; +import ca.uhn.fhir.model.api.IElement; + /* * #%L * HAPI FHIR - Core Library @@ -21,6 +23,6 @@ package org.hl7.fhir.instance.model.api; */ -public interface IBaseBackboneElement extends IBase, IBaseHasExtensions, IBaseHasModifierExtensions { +public interface IBaseBackboneElement extends IElement, IBaseHasExtensions, IBaseHasModifierExtensions { } diff --git a/hapi-fhir-base/src/main/java/org/hl7/fhir/instance/model/api/IBaseDatatype.java b/hapi-fhir-base/src/main/java/org/hl7/fhir/instance/model/api/IBaseDatatype.java index 1507c3fd6f9..444de8086fd 100644 --- a/hapi-fhir-base/src/main/java/org/hl7/fhir/instance/model/api/IBaseDatatype.java +++ b/hapi-fhir-base/src/main/java/org/hl7/fhir/instance/model/api/IBaseDatatype.java @@ -1,5 +1,7 @@ package org.hl7.fhir.instance.model.api; +import ca.uhn.fhir.model.api.IElement; + /* * #%L * HAPI FHIR - Core Library @@ -21,6 +23,6 @@ package org.hl7.fhir.instance.model.api; */ -public interface IBaseDatatype extends IBase { +public interface IBaseDatatype extends IElement { } diff --git a/hapi-fhir-base/src/main/java/org/hl7/fhir/instance/model/api/IBaseMetaType.java b/hapi-fhir-base/src/main/java/org/hl7/fhir/instance/model/api/IBaseMetaType.java index 6c40da79484..368145a0db7 100644 --- a/hapi-fhir-base/src/main/java/org/hl7/fhir/instance/model/api/IBaseMetaType.java +++ b/hapi-fhir-base/src/main/java/org/hl7/fhir/instance/model/api/IBaseMetaType.java @@ -45,4 +45,16 @@ public interface IBaseMetaType extends ICompositeType { IBaseMetaType setVersionId(String theVersionId); + /** + * Returns the first tag (if any) that has the given system and code, or returns + * null if none + */ + IBaseCoding getTag(String theSystem, String theCode); + + /** + * Returns the first security label (if any) that has the given system and code, or returns + * null if none + */ + IBaseCoding getSecurity(String theSystem, String theCode); + } diff --git a/hapi-fhir-base/src/main/java/org/hl7/fhir/instance/model/api/IBaseResource.java b/hapi-fhir-base/src/main/java/org/hl7/fhir/instance/model/api/IBaseResource.java index e774a67a73f..e9483ebd948 100644 --- a/hapi-fhir-base/src/main/java/org/hl7/fhir/instance/model/api/IBaseResource.java +++ b/hapi-fhir-base/src/main/java/org/hl7/fhir/instance/model/api/IBaseResource.java @@ -1,7 +1,13 @@ package org.hl7.fhir.instance.model.api; +import java.util.Arrays; +import java.util.Collections; +import java.util.HashSet; +import java.util.Set; + import ca.uhn.fhir.context.FhirVersionEnum; import ca.uhn.fhir.model.api.IElement; +import ca.uhn.fhir.model.api.Include; /* * #%L @@ -33,6 +39,16 @@ import ca.uhn.fhir.model.api.IElement; */ public interface IBaseResource extends IBase, IElement { + /** + * Include constant for * (return all includes) + */ + public static final Include INCLUDE_ALL = new Include("*", false).toLocked(); + + /** + * Include set containing only {@link #INCLUDE_ALL} + */ + public static final Set WILDCARD_ALL_SET = Collections.unmodifiableSet(new HashSet(Arrays.asList(INCLUDE_ALL))); + IIdType getIdElement(); IBaseResource setId(String theId); diff --git a/hapi-fhir-base/src/main/java/org/hl7/fhir/instance/model/api/IDomainResource.java b/hapi-fhir-base/src/main/java/org/hl7/fhir/instance/model/api/IDomainResource.java index 24ab6d8e11a..a60790348af 100644 --- a/hapi-fhir-base/src/main/java/org/hl7/fhir/instance/model/api/IDomainResource.java +++ b/hapi-fhir-base/src/main/java/org/hl7/fhir/instance/model/api/IDomainResource.java @@ -22,7 +22,7 @@ package org.hl7.fhir.instance.model.api; import java.util.List; -public interface IDomainResource extends IAnyResource { +public interface IDomainResource extends IAnyResource, IBaseHasExtensions, IBaseHasModifierExtensions { List getContained(); diff --git a/hapi-fhir-base/src/main/java/org/hl7/fhir/instance/model/api/IIdType.java b/hapi-fhir-base/src/main/java/org/hl7/fhir/instance/model/api/IIdType.java index 91b5a7d456f..7f47927a887 100644 --- a/hapi-fhir-base/src/main/java/org/hl7/fhir/instance/model/api/IIdType.java +++ b/hapi-fhir-base/src/main/java/org/hl7/fhir/instance/model/api/IIdType.java @@ -135,4 +135,20 @@ public interface IIdType { IIdType withVersion(String theVersion); + /** + * Sets the value of this ID by combining all of the individual parts. + *

+ * Required parameters: The following rules apply to the parameters of this method (in this case, populated means + * a non-empty string and not populated means null or an empty string) + *

+ *
    + *
  • All values may be not populated
  • + *
  • If theVersionIdPart is populated, theResourceType and theIdPart must be populated
  • + *
  • If theBaseUrl is populated and theIdPart is populated, theResourceType must be populated
  • + *
+ * + * @return Returns a reference to this for easy method chaining + */ + IIdType setParts(String theBaseUrl, String theResourceType, String theIdPart, String theVersionIdPart); + } diff --git a/hapi-fhir-jaxrsserver-base/src/main/java/ca/uhn/fhir/jaxrs/server/AbstractJaxRsConformanceProvider.java b/hapi-fhir-jaxrsserver-base/src/main/java/ca/uhn/fhir/jaxrs/server/AbstractJaxRsConformanceProvider.java index bbef3d408a4..8e5ee0eb7e5 100644 --- a/hapi-fhir-jaxrsserver-base/src/main/java/ca/uhn/fhir/jaxrs/server/AbstractJaxRsConformanceProvider.java +++ b/hapi-fhir-jaxrsserver-base/src/main/java/ca/uhn/fhir/jaxrs/server/AbstractJaxRsConformanceProvider.java @@ -1,5 +1,25 @@ package ca.uhn.fhir.jaxrs.server; +/* + * #%L + * HAPI FHIR JAX-RS Server + * %% + * Copyright (C) 2014 - 2015 University Health Network + * %% + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * #L% + */ + import java.io.IOException; import java.lang.annotation.Annotation; import java.lang.reflect.Method; diff --git a/hapi-fhir-jaxrsserver-base/src/main/java/ca/uhn/fhir/jaxrs/server/AbstractJaxRsPageProvider.java b/hapi-fhir-jaxrsserver-base/src/main/java/ca/uhn/fhir/jaxrs/server/AbstractJaxRsPageProvider.java index b37fa58a482..0ff71ac2b38 100644 --- a/hapi-fhir-jaxrsserver-base/src/main/java/ca/uhn/fhir/jaxrs/server/AbstractJaxRsPageProvider.java +++ b/hapi-fhir-jaxrsserver-base/src/main/java/ca/uhn/fhir/jaxrs/server/AbstractJaxRsPageProvider.java @@ -1,5 +1,25 @@ package ca.uhn.fhir.jaxrs.server; +/* + * #%L + * HAPI FHIR JAX-RS Server + * %% + * Copyright (C) 2014 - 2015 University Health Network + * %% + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * #L% + */ + import java.io.IOException; import java.util.Collections; import java.util.List; diff --git a/hapi-fhir-jaxrsserver-base/src/main/java/ca/uhn/fhir/jaxrs/server/AbstractJaxRsProvider.java b/hapi-fhir-jaxrsserver-base/src/main/java/ca/uhn/fhir/jaxrs/server/AbstractJaxRsProvider.java index 40613f02104..bba5f03b374 100644 --- a/hapi-fhir-jaxrsserver-base/src/main/java/ca/uhn/fhir/jaxrs/server/AbstractJaxRsProvider.java +++ b/hapi-fhir-jaxrsserver-base/src/main/java/ca/uhn/fhir/jaxrs/server/AbstractJaxRsProvider.java @@ -1,5 +1,25 @@ package ca.uhn.fhir.jaxrs.server; +/* + * #%L + * HAPI FHIR JAX-RS Server + * %% + * Copyright (C) 2014 - 2015 University Health Network + * %% + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * #L% + */ + import java.util.HashMap; import java.util.List; import java.util.Map; diff --git a/hapi-fhir-jaxrsserver-base/src/main/java/ca/uhn/fhir/jaxrs/server/AbstractJaxRsResourceProvider.java b/hapi-fhir-jaxrsserver-base/src/main/java/ca/uhn/fhir/jaxrs/server/AbstractJaxRsResourceProvider.java index 0a13cfb697a..b0b21b2c105 100644 --- a/hapi-fhir-jaxrsserver-base/src/main/java/ca/uhn/fhir/jaxrs/server/AbstractJaxRsResourceProvider.java +++ b/hapi-fhir-jaxrsserver-base/src/main/java/ca/uhn/fhir/jaxrs/server/AbstractJaxRsResourceProvider.java @@ -1,5 +1,25 @@ package ca.uhn.fhir.jaxrs.server; +/* + * #%L + * HAPI FHIR JAX-RS Server + * %% + * Copyright (C) 2014 - 2015 University Health Network + * %% + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * #L% + */ + import java.io.IOException; import java.net.URL; import java.util.Collections; diff --git a/hapi-fhir-jaxrsserver-base/src/main/java/ca/uhn/fhir/jaxrs/server/interceptor/JaxRsExceptionInterceptor.java b/hapi-fhir-jaxrsserver-base/src/main/java/ca/uhn/fhir/jaxrs/server/interceptor/JaxRsExceptionInterceptor.java index f4665f8d0b1..fa2e1af41f6 100644 --- a/hapi-fhir-jaxrsserver-base/src/main/java/ca/uhn/fhir/jaxrs/server/interceptor/JaxRsExceptionInterceptor.java +++ b/hapi-fhir-jaxrsserver-base/src/main/java/ca/uhn/fhir/jaxrs/server/interceptor/JaxRsExceptionInterceptor.java @@ -1,5 +1,25 @@ package ca.uhn.fhir.jaxrs.server.interceptor; +/* + * #%L + * HAPI FHIR JAX-RS Server + * %% + * Copyright (C) 2014 - 2015 University Health Network + * %% + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * #L% + */ + import java.io.IOException; import javax.interceptor.AroundInvoke; diff --git a/hapi-fhir-jaxrsserver-base/src/main/java/ca/uhn/fhir/jaxrs/server/interceptor/JaxRsResponseException.java b/hapi-fhir-jaxrsserver-base/src/main/java/ca/uhn/fhir/jaxrs/server/interceptor/JaxRsResponseException.java index 893fd23c1f1..ebc57bcd467 100644 --- a/hapi-fhir-jaxrsserver-base/src/main/java/ca/uhn/fhir/jaxrs/server/interceptor/JaxRsResponseException.java +++ b/hapi-fhir-jaxrsserver-base/src/main/java/ca/uhn/fhir/jaxrs/server/interceptor/JaxRsResponseException.java @@ -1,5 +1,25 @@ package ca.uhn.fhir.jaxrs.server.interceptor; +/* + * #%L + * HAPI FHIR JAX-RS Server + * %% + * Copyright (C) 2014 - 2015 University Health Network + * %% + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * #L% + */ + import javax.ejb.ApplicationException; import ca.uhn.fhir.rest.server.exceptions.BaseServerResponseException; diff --git a/hapi-fhir-jaxrsserver-base/src/main/java/ca/uhn/fhir/jaxrs/server/util/JaxRsMethodBindings.java b/hapi-fhir-jaxrsserver-base/src/main/java/ca/uhn/fhir/jaxrs/server/util/JaxRsMethodBindings.java index 1113ddb5fa6..f7e41277be6 100644 --- a/hapi-fhir-jaxrsserver-base/src/main/java/ca/uhn/fhir/jaxrs/server/util/JaxRsMethodBindings.java +++ b/hapi-fhir-jaxrsserver-base/src/main/java/ca/uhn/fhir/jaxrs/server/util/JaxRsMethodBindings.java @@ -1,5 +1,25 @@ package ca.uhn.fhir.jaxrs.server.util; +/* + * #%L + * HAPI FHIR JAX-RS Server + * %% + * Copyright (C) 2014 - 2015 University Health Network + * %% + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * #L% + */ + import java.lang.reflect.Method; import java.util.concurrent.ConcurrentHashMap; diff --git a/hapi-fhir-jaxrsserver-base/src/main/java/ca/uhn/fhir/jaxrs/server/util/JaxRsRequest.java b/hapi-fhir-jaxrsserver-base/src/main/java/ca/uhn/fhir/jaxrs/server/util/JaxRsRequest.java index 296a5f2faa7..15176703bc6 100644 --- a/hapi-fhir-jaxrsserver-base/src/main/java/ca/uhn/fhir/jaxrs/server/util/JaxRsRequest.java +++ b/hapi-fhir-jaxrsserver-base/src/main/java/ca/uhn/fhir/jaxrs/server/util/JaxRsRequest.java @@ -1,5 +1,25 @@ package ca.uhn.fhir.jaxrs.server.util; +/* + * #%L + * HAPI FHIR JAX-RS Server + * %% + * Copyright (C) 2014 - 2015 University Health Network + * %% + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * #L% + */ + import java.io.IOException; import java.io.InputStream; import java.io.Reader; diff --git a/hapi-fhir-jaxrsserver-base/src/main/java/ca/uhn/fhir/jaxrs/server/util/JaxRsResponse.java b/hapi-fhir-jaxrsserver-base/src/main/java/ca/uhn/fhir/jaxrs/server/util/JaxRsResponse.java index 7239427e5ba..3fa1825f8f5 100644 --- a/hapi-fhir-jaxrsserver-base/src/main/java/ca/uhn/fhir/jaxrs/server/util/JaxRsResponse.java +++ b/hapi-fhir-jaxrsserver-base/src/main/java/ca/uhn/fhir/jaxrs/server/util/JaxRsResponse.java @@ -1,5 +1,25 @@ package ca.uhn.fhir.jaxrs.server.util; +/* + * #%L + * HAPI FHIR JAX-RS Server + * %% + * Copyright (C) 2014 - 2015 University Health Network + * %% + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * #L% + */ + import java.io.IOException; import java.io.StringWriter; import java.io.UnsupportedEncodingException; diff --git a/hapi-fhir-jpaserver-base/pom.xml b/hapi-fhir-jpaserver-base/pom.xml index a1f03e72b3c..5f8a3fc5806 100644 --- a/hapi-fhir-jpaserver-base/pom.xml +++ b/hapi-fhir-jpaserver-base/pom.xml @@ -404,6 +404,11 @@ hapi-fhir-structures-dstu2.1 1.4-SNAPSHOT + + ca.uhn.hapi.fhir + hapi-fhir-validation-resources-dstu2.1 + 1.4-SNAPSHOT + @@ -436,6 +441,7 @@ true + - org.hibernate hibernate-core - ${hibernate_version} + + + org.hibernate + hibernate-core + ${hibernate_version} + + o10g @@ -501,6 +511,7 @@ + --> diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/config/BaseDstu21Config.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/config/BaseDstu21Config.java index c3c0ec76cc1..a42e53a923a 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/config/BaseDstu21Config.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/config/BaseDstu21Config.java @@ -42,7 +42,7 @@ public class BaseDstu21Config extends BaseConfig { } @Bean(name = "mySystemDaoDstu21", autowire = Autowire.BY_NAME) - public IFhirSystemDao systemDaoDstu21() { + public IFhirSystemDao systemDaoDstu21() { ca.uhn.fhir.jpa.dao.FhirSystemDaoDstu21 retVal = new ca.uhn.fhir.jpa.dao.FhirSystemDaoDstu21(); return retVal; } @@ -55,7 +55,7 @@ public class BaseDstu21Config extends BaseConfig { } @Bean(name = "myJpaValidationSupportDstu21", autowire = Autowire.BY_NAME) - public ca.uhn.fhir.jpa.dao.IJpaValidationSupport jpaValidationSupportDstu2() { + public ca.uhn.fhir.jpa.dao.IJpaValidationSupportDstu21 jpaValidationSupportDstu2() { ca.uhn.fhir.jpa.dao.JpaValidationSupportDstu21 retVal = new ca.uhn.fhir.jpa.dao.JpaValidationSupportDstu21(); return retVal; } diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/config/BaseDstu2Config.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/config/BaseDstu2Config.java index 1b53b39389a..c7a490a09bd 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/config/BaseDstu2Config.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/config/BaseDstu2Config.java @@ -56,7 +56,7 @@ public class BaseDstu2Config extends BaseConfig { } @Bean(name = "myJpaValidationSupportDstu2", autowire = Autowire.BY_NAME) - public ca.uhn.fhir.jpa.dao.IJpaValidationSupport jpaValidationSupportDstu2() { + public ca.uhn.fhir.jpa.dao.IJpaValidationSupportDstu2 jpaValidationSupportDstu2() { ca.uhn.fhir.jpa.dao.JpaValidationSupportDstu2 retVal = new ca.uhn.fhir.jpa.dao.JpaValidationSupportDstu2(); return retVal; } diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/BaseHapiFhirDao.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/BaseHapiFhirDao.java index 18fa1b5623f..b10c70af069 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/BaseHapiFhirDao.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/BaseHapiFhirDao.java @@ -53,8 +53,15 @@ import org.apache.commons.lang3.NotImplementedException; import org.apache.commons.lang3.StringUtils; import org.apache.http.NameValuePair; import org.apache.http.client.utils.URLEncodedUtils; +import org.hl7.fhir.dstu21.model.IdType; +import org.hl7.fhir.dstu21.model.StringType; +import org.hl7.fhir.dstu21.model.Bundle.HTTPVerb; +import org.hl7.fhir.instance.model.api.IAnyResource; +import org.hl7.fhir.instance.model.api.IBaseCoding; import org.hl7.fhir.instance.model.api.IBaseOperationOutcome; +import org.hl7.fhir.instance.model.api.IBaseReference; import org.hl7.fhir.instance.model.api.IBaseResource; +import org.hl7.fhir.instance.model.api.IDomainResource; import org.hl7.fhir.instance.model.api.IIdType; import org.hl7.fhir.instance.model.api.IPrimitiveType; import org.springframework.beans.factory.annotation.Autowired; @@ -108,6 +115,7 @@ import ca.uhn.fhir.model.dstu.resource.BaseResource; import ca.uhn.fhir.model.primitive.IdDt; import ca.uhn.fhir.model.primitive.InstantDt; import ca.uhn.fhir.model.primitive.StringDt; +import ca.uhn.fhir.model.primitive.XhtmlDt; import ca.uhn.fhir.model.valueset.BundleEntryTransactionMethodEnum; import ca.uhn.fhir.parser.DataFormatException; import ca.uhn.fhir.parser.IParser; @@ -167,7 +175,6 @@ public abstract class BaseHapiFhirDao implements IDao { RESOURCE_META_AND_PARAMS = Collections.unmodifiableMap(resourceMetaAndParams); } - public static final long INDEX_STATUS_INDEXED = Long.valueOf(1L); public static final long INDEX_STATUS_INDEXING_FAILED = Long.valueOf(2L); public static final String NS_JPA_PROFILE = "https://github.com/jamesagnew/hapi-fhir/ns/jpa/profile"; @@ -225,13 +232,12 @@ public abstract class BaseHapiFhirDao implements IDao { myPlatformTransactionManager = thePlatformTransactionManager; } -// @Override -// public void setResourceDaos(List> theResourceDaos) { -// myResourceDaos = theResourceDaos; -// } + // @Override + // public void setResourceDaos(List> theResourceDaos) { + // myResourceDaos = theResourceDaos; + // } - - protected Set extractResourceLinks(ResourceTable theEntity, IResource theResource) { + protected Set extractResourceLinks(ResourceTable theEntity, IBaseResource theResource) { Set retVal = new HashSet(); RuntimeResourceDefinition def = getContext().getResourceDefinition(theResource); @@ -262,31 +268,31 @@ public abstract class BaseHapiFhirDao implements IDao { } ResourceLink nextEntity; - if (nextObject instanceof BaseResourceReferenceDt) { - BaseResourceReferenceDt nextValue = (BaseResourceReferenceDt) nextObject; + if (nextObject instanceof IBaseReference) { + IBaseReference nextValue = (IBaseReference) nextObject; if (nextValue.isEmpty()) { continue; } - if (nextValue.getReference().isEmpty() || nextValue.getReference().getValue().startsWith("#")) { + if (nextValue.getReferenceElement().isEmpty() || nextValue.getReferenceElement().getValue().startsWith("#")) { // This is a blank or contained resource reference continue; } - String typeString = nextValue.getReference().getResourceType(); + String typeString = nextValue.getReferenceElement().getResourceType(); if (isBlank(typeString)) { - throw new InvalidRequestException("Invalid resource reference found at path[" + nextPathsUnsplit + "] - Does not contain resource type - " + nextValue.getReference().getValue()); + throw new InvalidRequestException("Invalid resource reference found at path[" + nextPathsUnsplit + "] - Does not contain resource type - " + nextValue.getReferenceElement().getValue()); } RuntimeResourceDefinition resourceDefinition; try { resourceDefinition = getContext().getResourceDefinition(typeString); } catch (DataFormatException e) { - throw new InvalidRequestException("Invalid resource reference found at path[" + nextPathsUnsplit + "] - Resource type is unknown or not supported on this server - " + nextValue.getReference().getValue()); + throw new InvalidRequestException("Invalid resource reference found at path[" + nextPathsUnsplit + "] - Resource type is unknown or not supported on this server - " + nextValue.getReferenceElement().getValue()); } Class type = resourceDefinition.getImplementingClass(); - String id = nextValue.getReference().getIdPart(); + String id = nextValue.getReferenceElement().getIdPart(); if (StringUtils.isBlank(id)) { - throw new InvalidRequestException("Invalid resource reference found at path[" + nextPathsUnsplit + "] - Does not contain resource ID - " + nextValue.getReference().getValue()); + throw new InvalidRequestException("Invalid resource reference found at path[" + nextPathsUnsplit + "] - Does not contain resource ID - " + nextValue.getReferenceElement().getValue()); } IFhirResourceDao dao = getDao(type); @@ -295,7 +301,7 @@ public abstract class BaseHapiFhirDao implements IDao { b.append("This server (version "); b.append(myContext.getVersion().getVersion()); b.append(") is not able to handle resources of type["); - b.append(nextValue.getReference().getResourceType()); + b.append(nextValue.getReferenceElement().getResourceType()); b.append("] - Valid resource types for this server: "); b.append(myResourceTypeToDao.keySet().toString()); @@ -303,7 +309,7 @@ public abstract class BaseHapiFhirDao implements IDao { } Long valueOf; try { - valueOf = translateForcedIdToPid(nextValue.getReference()); + valueOf = translateForcedIdToPid(nextValue.getReferenceElement()); } catch (ResourceNotFoundException e) { String resName = getContext().getResourceDefinition(type).getName(); throw new InvalidRequestException("Resource " + resName + "/" + id + " not found, specified in path: " + nextPathsUnsplit); @@ -316,7 +322,7 @@ public abstract class BaseHapiFhirDao implements IDao { } if (!typeString.equals(target.getResourceType())) { - throw new UnprocessableEntityException("Resource contains reference to " + nextValue.getReference().getValue() + " but resource with ID " + nextValue.getReference().getIdPart() + " is actually of type " + target.getResourceType()); + throw new UnprocessableEntityException("Resource contains reference to " + nextValue.getReferenceElement().getValue() + " but resource with ID " + nextValue.getReferenceElement().getIdPart() + " is actually of type " + target.getResourceType()); } /* @@ -366,35 +372,35 @@ public abstract class BaseHapiFhirDao implements IDao { return retVal; } - protected Set extractSearchParamDates(ResourceTable theEntity, IResource theResource) { + protected Set extractSearchParamDates(ResourceTable theEntity, IBaseResource theResource) { return mySearchParamExtractor.extractSearchParamDates(theEntity, theResource); } - protected Set extractSearchParamNumber(ResourceTable theEntity, IResource theResource) { + protected Set extractSearchParamNumber(ResourceTable theEntity, IBaseResource theResource) { return mySearchParamExtractor.extractSearchParamNumber(theEntity, theResource); } - protected Set extractSearchParamUri(ResourceTable theEntity, IResource theResource) { + protected Set extractSearchParamUri(ResourceTable theEntity, IBaseResource theResource) { return mySearchParamExtractor.extractSearchParamUri(theEntity, theResource); } - protected Set extractSearchParamCoords(ResourceTable theEntity, IResource theResource) { + protected Set extractSearchParamCoords(ResourceTable theEntity, IBaseResource theResource) { return mySearchParamExtractor.extractSearchParamCoords(theEntity, theResource); } - protected Set extractSearchParamQuantity(ResourceTable theEntity, IResource theResource) { + protected Set extractSearchParamQuantity(ResourceTable theEntity, IBaseResource theResource) { return mySearchParamExtractor.extractSearchParamQuantity(theEntity, theResource); } - protected Set extractSearchParamStrings(ResourceTable theEntity, IResource theResource) { + protected Set extractSearchParamStrings(ResourceTable theEntity, IBaseResource theResource) { return mySearchParamExtractor.extractSearchParamStrings(theEntity, theResource); } - protected Set extractSearchParamTokens(ResourceTable theEntity, IResource theResource) { + protected Set extractSearchParamTokens(ResourceTable theEntity, IBaseResource theResource) { return mySearchParamExtractor.extractSearchParamTokens(theEntity, theResource); } - private List extractValues(String thePath, IResource theResource) { + private List extractValues(String thePath, IBaseResource theResource) { List values = new ArrayList(); FhirTerser t = getContext().newTerser(); String nextPathTrimmed = thePath.trim(); @@ -516,12 +522,12 @@ public abstract class BaseHapiFhirDao implements IDao { } } - protected TagList getTags(Class theResourceType, IIdType theResourceId) { + protected TagList getTags(Class theResourceType, IIdType theResourceId) { String resourceName = null; if (theResourceType != null) { resourceName = toResourceName(theResourceType); if (theResourceId != null && theResourceId.hasVersionIdPart()) { - IFhirResourceDao dao = getDao(theResourceType); + IFhirResourceDao dao = getDao(theResourceType); BaseHasResource entity = dao.readEntity(theResourceId); TagList retVal = new TagList(); for (BaseTag next : entity.getTags()) { @@ -622,7 +628,7 @@ public abstract class BaseHapiFhirDao implements IDao { } throw e; } - IResource resource = (IResource) toResource(type.getImplementingClass(), next, true); + IBaseResource resource = (IBaseResource) toResource(type.getImplementingClass(), next, true); retVal.add(resource); } return retVal; @@ -656,7 +662,7 @@ public abstract class BaseHapiFhirDao implements IDao { return true; } - protected void populateResourceIntoEntity(IResource theResource, ResourceTable theEntity) { + protected void populateResourceIntoEntity(IBaseResource theResource, ResourceTable theEntity) { theEntity.setResourceType(toResourceName(theResource)); List refs = myContext.newTerser().getAllPopulatedChildElementsOfType(theResource, BaseResourceReferenceDt.class); @@ -689,6 +695,36 @@ public abstract class BaseHapiFhirDao implements IDao { theEntity.setHasTags(false); + if (theResource instanceof IResource) { + extractTagsHapi((IResource) theResource, theEntity, allDefs); + } else { + extractTagsRi((IAnyResource) theResource, theEntity, allDefs); + } + + ArrayList existingTags = new ArrayList(); + if (theEntity.isHasTags()) { + existingTags.addAll(theEntity.getTags()); + } + for (ResourceTag next : existingTags) { + TagDefinition nextDef = next.getTag(); + if (!allDefs.contains(nextDef)) { + if (shouldDroppedTagBeRemovedOnUpdate(theEntity, next)) { + theEntity.getTags().remove(next); + } + } + } + + if (theResource instanceof IResource) { + String title = ResourceMetadataKeyEnum.TITLE.get((IResource) theResource); + if (title != null && title.length() > BaseHasResource.MAX_TITLE_LENGTH) { + title = title.substring(0, BaseHasResource.MAX_TITLE_LENGTH); + } + theEntity.setTitle(title); + } + + } + + private void extractTagsHapi(IResource theResource, ResourceTable theEntity, Set allDefs) { TagList tagList = ResourceMetadataKeyEnum.TAG_LIST.get(theResource); if (tagList != null) { for (Tag next : tagList) { @@ -718,26 +754,38 @@ public abstract class BaseHapiFhirDao implements IDao { theEntity.setHasTags(true); } } + } - ArrayList existingTags = new ArrayList(); - if (theEntity.isHasTags()) { - existingTags.addAll(theEntity.getTags()); - } - for (ResourceTag next : existingTags) { - TagDefinition nextDef = next.getTag(); - if (!allDefs.contains(nextDef)) { - if (shouldDroppedTagBeRemovedOnUpdate(theEntity, next)) { - theEntity.getTags().remove(next); - } + private void extractTagsRi(IAnyResource theResource, ResourceTable theEntity, Set allDefs) { + List tagList = theResource.getMeta().getTag(); + if (tagList != null) { + for (IBaseCoding next : tagList) { + TagDefinition tag = getTag(TagTypeEnum.TAG, next.getSystem(), next.getCode(), next.getDisplay()); + allDefs.add(tag); + theEntity.addTag(tag); + theEntity.setHasTags(true); } } - String title = ResourceMetadataKeyEnum.TITLE.get(theResource); - if (title != null && title.length() > BaseHasResource.MAX_TITLE_LENGTH) { - title = title.substring(0, BaseHasResource.MAX_TITLE_LENGTH); + List securityLabels = theResource.getMeta().getSecurity(); + if (securityLabels != null) { + for (IBaseCoding next : securityLabels) { + TagDefinition tag = getTag(TagTypeEnum.SECURITY_LABEL, next.getSystem(), next.getCode(), next.getDisplay()); + allDefs.add(tag); + theEntity.addTag(tag); + theEntity.setHasTags(true); + } } - theEntity.setTitle(title); + List> profiles = theResource.getMeta().getProfile(); + if (profiles != null) { + for (IPrimitiveType next : profiles) { + TagDefinition tag = getTag(TagTypeEnum.PROFILE, NS_JPA_PROFILE, next.getValue(), null); + allDefs.add(tag); + theEntity.addTag(tag); + theEntity.setHasTags(true); + } + } } /** @@ -787,7 +835,7 @@ public abstract class BaseHapiFhirDao implements IDao { return type; } - protected Set processMatchUrl(String theMatchUrl, Class theResourceType) { + protected Set processMatchUrl(String theMatchUrl, Class theResourceType) { RuntimeResourceDefinition resourceDef = getContext().getResourceDefinition(theResourceType); SearchParameterMap paramMap = translateMatchUrl(theMatchUrl, resourceDef); @@ -1034,23 +1082,23 @@ public abstract class BaseHapiFhirDao implements IDao { } } -// protected MetaDt toMetaDt(Collection tagDefinitions) { -// MetaDt retVal = new MetaDt(); -// for (TagDefinition next : tagDefinitions) { -// switch (next.getTagType()) { -// case PROFILE: -// retVal.addProfile(next.getCode()); -// break; -// case SECURITY_LABEL: -// retVal.addSecurity().setSystem(next.getSystem()).setCode(next.getCode()).setDisplay(next.getDisplay()); -// break; -// case TAG: -// retVal.addTag().setSystem(next.getSystem()).setCode(next.getCode()).setDisplay(next.getDisplay()); -// break; -// } -// } -// return retVal; -// } + // protected MetaDt toMetaDt(Collection tagDefinitions) { + // MetaDt retVal = new MetaDt(); + // for (TagDefinition next : tagDefinitions) { + // switch (next.getTagType()) { + // case PROFILE: + // retVal.addProfile(next.getCode()); + // break; + // case SECURITY_LABEL: + // retVal.addSecurity().setSystem(next.getSystem()).setCode(next.getCode()).setDisplay(next.getDisplay()); + // break; + // case TAG: + // retVal.addTag().setSystem(next.getSystem()).setCode(next.getCode()).setDisplay(next.getDisplay()); + // break; + // } + // } + // return retVal; + // } @Autowired public void setContext(FhirContext theContext) { @@ -1066,7 +1114,6 @@ public abstract class BaseHapiFhirDao implements IDao { mySearchParamExtractor = new SearchParamExtractorDstu21(theContext); break; case DSTU2_HL7ORG: - case DEV: throw new IllegalStateException("Don't know how to handle version: " + myContext.getVersion().getVersion()); } } @@ -1079,13 +1126,15 @@ public abstract class BaseHapiFhirDao implements IDao { return retVal; } - protected IBaseResource toResource(BaseHasResource theEntity, boolean theForHistoryOperation) { + @Override + public IBaseResource toResource(BaseHasResource theEntity, boolean theForHistoryOperation) { RuntimeResourceDefinition type = myContext.getResourceDefinition(theEntity.getResourceType()); return toResource(type.getImplementingClass(), theEntity, theForHistoryOperation); } + @Override @SuppressWarnings("unchecked") - protected R toResource(Class theResourceType, BaseHasResource theEntity, boolean theForHistoryOperation) { + public R toResource(Class theResourceType, BaseHasResource theEntity, boolean theForHistoryOperation) { String resourceText = null; switch (theEntity.getEncoding()) { case JSON: @@ -1121,7 +1170,18 @@ public abstract class BaseHapiFhirDao implements IDao { throw new DataFormatException(msg, e); } - IResource res = (IResource) retVal; + if (retVal instanceof IResource) { + IResource res = (IResource) retVal; + retVal = populateResourceMetadataHapi(theResourceType, theEntity, theForHistoryOperation, res); + } else { + IAnyResource res = (IAnyResource) retVal; + retVal = populateResourceMetadataRi(theResourceType, theEntity, theForHistoryOperation, res); + } + return retVal; + } + + private R populateResourceMetadataHapi(Class theResourceType, BaseHasResource theEntity, boolean theForHistoryOperation, IResource res) { + R retVal = (R) res; if (theEntity.getDeleted() != null) { res = (IResource) myContext.getResourceDefinition(theResourceType).newInstance(); retVal = (R) res; @@ -1157,7 +1217,7 @@ public abstract class BaseHapiFhirDao implements IDao { Collection tags = theEntity.getTags(); if (theEntity.isHasTags()) { TagList tagList = new TagList(); - List securityLabels = new ArrayList(); + List securityLabels = new ArrayList(); List profiles = new ArrayList(); for (BaseTag next : tags) { switch (next.getTag().getTagType()) { @@ -1165,7 +1225,7 @@ public abstract class BaseHapiFhirDao implements IDao { profiles.add(new IdDt(next.getTag().getCode())); break; case SECURITY_LABEL: - BaseCodingDt secLabel = myContext.getVersion().newCodingDt(); + IBaseCoding secLabel = (IBaseCoding) myContext.getVersion().newCodingDt(); secLabel.setSystem(next.getTag().getSystem()); secLabel.setCode(next.getTag().getCode()); secLabel.setDisplay(next.getTag().getDisplay()); @@ -1180,21 +1240,88 @@ public abstract class BaseHapiFhirDao implements IDao { ResourceMetadataKeyEnum.TAG_LIST.put(res, tagList); } if (securityLabels.size() > 0) { - ResourceMetadataKeyEnum.SECURITY_LABELS.put(res, securityLabels); + ResourceMetadataKeyEnum.SECURITY_LABELS.put(res, toBaseCodingList(securityLabels)); } if (profiles.size() > 0) { ResourceMetadataKeyEnum.PROFILES.put(res, profiles); } } - + return retVal; } - protected String toResourceName(Class theResourceType) { + private R populateResourceMetadataRi(Class theResourceType, BaseHasResource theEntity, boolean theForHistoryOperation, IAnyResource res) { + R retVal = (R) res; + if (theEntity.getDeleted() != null) { + res = (IAnyResource) myContext.getResourceDefinition(theResourceType).newInstance(); + retVal = (R) res; + ResourceMetadataKeyEnum.DELETED_AT.put(res, new InstantDt(theEntity.getDeleted())); + if (theForHistoryOperation) { + ResourceMetadataKeyEnum.ENTRY_TRANSACTION_METHOD.put(res, HTTPVerb.DELETE.toCode()); + } + } else if (theForHistoryOperation) { + /* + * If the create and update times match, this was when the resource was created so we should mark it as a POST. + * Otherwise, it's a PUT. + */ + Date published = theEntity.getPublished().getValue(); + Date updated = theEntity.getUpdated().getValue(); + if (published.equals(updated)) { + ResourceMetadataKeyEnum.ENTRY_TRANSACTION_METHOD.put(res, HTTPVerb.POST.toCode()); + } else { + ResourceMetadataKeyEnum.ENTRY_TRANSACTION_METHOD.put(res, HTTPVerb.PUT.toCode()); + } + } + + res.getMeta().getTag().clear(); + res.getMeta().getProfile().clear(); + res.getMeta().getSecurity().clear(); + res.getMeta().setLastUpdated(null); + res.getMeta().setVersionId(null); + + populateResourceId(res, theEntity); + + res.getMeta().setLastUpdated(theEntity.getUpdatedDate()); + IDao.RESOURCE_PID.put(res, theEntity.getId()); + + Collection tags = theEntity.getTags(); + if (theEntity.isHasTags()) { + for (BaseTag next : tags) { + switch (next.getTag().getTagType()) { + case PROFILE: + res.getMeta().addProfile(next.getTag().getCode()); + break; + case SECURITY_LABEL: + IBaseCoding sec = res.getMeta().addSecurity(); + sec.setSystem(next.getTag().getSystem()); + sec.setCode(next.getTag().getCode()); + sec.setDisplay(next.getTag().getDisplay()); + break; + case TAG: + IBaseCoding tag = res.getMeta().addTag(); + tag.setSystem(next.getTag().getSystem()); + tag.setCode(next.getTag().getCode()); + tag.setDisplay(next.getTag().getDisplay()); + break; + } + } + } + return retVal; + } + + private static List toBaseCodingList(List theSecurityLabels) { + ArrayList retVal = new ArrayList(theSecurityLabels.size()); + for (IBaseCoding next : theSecurityLabels) { + retVal.add((BaseCodingDt) next); + } + return retVal; + } + + protected String toResourceName(Class theResourceType) { return myContext.getResourceDefinition(theResourceType).getName(); } - protected String toResourceName(IResource theResource) { + protected String toResourceName(IBaseResource theResource) { return myContext.getResourceDefinition(theResource).getName(); } @@ -1236,7 +1363,7 @@ public abstract class BaseHapiFhirDao implements IDao { } @SuppressWarnings("unchecked") - protected ResourceTable updateEntity(final IResource theResource, ResourceTable theEntity, boolean theUpdateHistory, Date theDeletedTimestampOrNull, boolean thePerformIndexing, boolean theUpdateVersion, Date theUpdateTime) { + protected ResourceTable updateEntity(final IBaseResource theResource, ResourceTable theEntity, boolean theUpdateHistory, Date theDeletedTimestampOrNull, boolean thePerformIndexing, boolean theUpdateVersion, Date theUpdateTime) { /* * This should be the very first thing.. @@ -1348,22 +1475,26 @@ public abstract class BaseHapiFhirDao implements IDao { links = extractResourceLinks(theEntity, theResource); - /* - * If the existing resource already has links and those match links we still want, - * use them instead of removing them and re adding them + /* + * If the existing resource already has links and those match links we still want, use them instead of + * removing them and re adding them */ - for (Iterator existingLinkIter = existingResourceLinks.iterator(); existingLinkIter.hasNext(); ) { + for (Iterator existingLinkIter = existingResourceLinks.iterator(); existingLinkIter.hasNext();) { ResourceLink nextExisting = existingLinkIter.next(); if (links.remove(nextExisting)) { existingLinkIter.remove(); links.add(nextExisting); } } - + populateResourceIntoEntity(theResource, theEntity); theEntity.setUpdated(theUpdateTime); - theEntity.setLanguage(theResource.getLanguage().getValue()); + if (theResource instanceof IResource) { + theEntity.setLanguage(((IResource) theResource).getLanguage().getValue()); + } else { + theEntity.setLanguage(((IAnyResource) theResource).getLanguageElement().getValue()); + } theEntity.setParamsString(stringParams); theEntity.setParamsStringPopulated(stringParams.isEmpty() == false); theEntity.setParamsToken(tokenParams); @@ -1388,13 +1519,13 @@ public abstract class BaseHapiFhirDao implements IDao { populateResourceIntoEntity(theResource, theEntity); theEntity.setUpdated(theUpdateTime); - theEntity.setLanguage(theResource.getLanguage().getValue()); + // theEntity.setLanguage(theResource.getLanguage().getValue()); theEntity.setIndexStatus(null); } } - + if (theEntity.getId() == null) { myEntityManager.persist(theEntity); @@ -1479,12 +1610,20 @@ public abstract class BaseHapiFhirDao implements IDao { myEntityManager.flush(); if (theResource != null) { - theResource.setId(theEntity.getIdDt()); + populateResourceId(theResource, theEntity); } return theEntity; } + private void populateResourceId(final IBaseResource theResource, BaseHasResource theEntity) { + IIdType id = theEntity.getIdDt(); + if (getContext().getVersion().getVersion().isRi()) { + id = new IdType(id.getValue()); + } + theResource.setId(id); + } + /** * Subclasses may override to provide behaviour. Called when a resource has been inserved into the database for the * first time. @@ -1522,13 +1661,20 @@ public abstract class BaseHapiFhirDao implements IDao { * TODO */ protected void validateResourceForStorage(T theResource, ResourceTable theEntityToSave) { - IResource res = (IResource) theResource; - TagList tagList = ResourceMetadataKeyEnum.TAG_LIST.get(res); - if (tagList != null) { - Tag tag = tagList.getTag(Constants.TAG_SUBSETTED_SYSTEM, Constants.TAG_SUBSETTED_CODE); - if (tag != null) { - throw new UnprocessableEntityException("Resource contains the 'subsetted' tag, and must not be stored as it may contain a subset of available data"); + Object tag = null; + if (theResource instanceof IResource) { + IResource res = (IResource) theResource; + TagList tagList = ResourceMetadataKeyEnum.TAG_LIST.get(res); + if (tagList != null) { + tag = tagList.getTag(Constants.TAG_SUBSETTED_SYSTEM, Constants.TAG_SUBSETTED_CODE); } + } else { + IAnyResource res = (IAnyResource)theResource; + tag = res.getMeta().getTag(Constants.TAG_SUBSETTED_SYSTEM, Constants.TAG_SUBSETTED_CODE); + } + + if (tag != null) { + throw new UnprocessableEntityException("Resource contains the 'subsetted' tag, and must not be stored as it may contain a subset of available data"); } } @@ -1545,26 +1691,49 @@ public abstract class BaseHapiFhirDao implements IDao { return new String(out).toUpperCase(); } - private static String parseNarrativeTextIntoWords(IResource theResource) { + private static String parseNarrativeTextIntoWords(IBaseResource theResource) { + StringBuilder b = new StringBuilder(); - List xmlEvents = theResource.getText().getDiv().getValue(); - if (xmlEvents != null) { - for (XMLEvent next : xmlEvents) { - if (next.isCharacters()) { - Characters characters = next.asCharacters(); - b.append(characters.getData()).append(" "); + if (theResource instanceof IResource) { + IResource resource = (IResource) theResource; + List xmlEvents = resource.getText().getDiv().getValue(); + if (xmlEvents != null) { + for (XMLEvent next : xmlEvents) { + if (next.isCharacters()) { + Characters characters = next.asCharacters(); + b.append(characters.getData()).append(" "); + } } } + } else if (theResource instanceof IDomainResource) { + IDomainResource resource = (IDomainResource) theResource; + try { + String divAsString = resource.getText().getDivAsString(); + XhtmlDt xhtml = new XhtmlDt(divAsString); + List xmlEvents = xhtml.getValue(); + if (xmlEvents != null) { + for (XMLEvent next : xmlEvents) { + if (next.isCharacters()) { + Characters characters = next.asCharacters(); + b.append(characters.getData()).append(" "); + } + } + } + } catch (Exception e) { + throw new DataFormatException("Unable to convert DIV to string", e); + } + } return b.toString(); } - private String parseContentTextIntoWords(IResource theResource) { - StringBuilder retVal = new StringBuilder(); + private String parseContentTextIntoWords(IBaseResource theResource) { + StringBuilder retVal = new StringBuilder(); @SuppressWarnings("rawtypes") List childElements = getContext().newTerser().getAllPopulatedChildElementsOfType(theResource, IPrimitiveType.class); - for (@SuppressWarnings("rawtypes") IPrimitiveType nextType : childElements) { - if (nextType instanceof StringDt) { + for (@SuppressWarnings("rawtypes") + IPrimitiveType nextType : childElements) { + if (nextType instanceof StringDt || nextType.getClass().equals(StringType.class)) { String nextValue = nextType.getValueAsString(); if (isNotBlank(nextValue)) { retVal.append(nextValue.replace("\n", " ").replace("\r", " ")); @@ -1582,10 +1751,11 @@ public abstract class BaseHapiFhirDao implements IDao { IBaseOperationOutcome oo = OperationOutcomeUtil.newInstance(getContext()); for (DeleteConflict next : theDeleteConflicts) { - String msg = "Unable to delete " + next.getTargetId().toUnqualifiedVersionless().getValue() + " because at least one resource has a reference to this resource. First reference found was resource " + next.getTargetId().toUnqualifiedVersionless().getValue() + " in path " + next.getSourcePath(); + String msg = "Unable to delete " + next.getTargetId().toUnqualifiedVersionless().getValue() + " because at least one resource has a reference to this resource. First reference found was resource " + next.getTargetId().toUnqualifiedVersionless().getValue() + " in path " + + next.getSourcePath(); OperationOutcomeUtil.addIssue(getContext(), oo, OO_SEVERITY_ERROR, msg, null, "processing"); } - + throw new ResourceVersionConflictException("Delete failed because of constraint failure", oo); } diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/BaseHapiFhirResourceDao.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/BaseHapiFhirResourceDao.java index de093babbc9..bc0b70e448d 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/BaseHapiFhirResourceDao.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/BaseHapiFhirResourceDao.java @@ -33,13 +33,12 @@ import java.util.Map.Entry; import java.util.Set; import javax.annotation.PostConstruct; -import javax.persistence.EntityManager; import javax.persistence.NoResultException; -import javax.persistence.PersistenceContext; -import javax.persistence.PersistenceContextType; import javax.persistence.TemporalType; import javax.persistence.TypedQuery; +import org.hl7.fhir.dstu21.model.IdType; +import org.hl7.fhir.instance.model.api.IAnyResource; import org.hl7.fhir.instance.model.api.IBaseCoding; import org.hl7.fhir.instance.model.api.IBaseMetaType; import org.hl7.fhir.instance.model.api.IBaseOperationOutcome; @@ -90,16 +89,13 @@ import ca.uhn.fhir.util.FhirTerser; import ca.uhn.fhir.util.ObjectUtil; @Transactional(propagation = Propagation.REQUIRED) -public abstract class BaseHapiFhirResourceDao extends BaseHapiFhirDao implements IFhirResourceDao { +public abstract class BaseHapiFhirResourceDao extends BaseHapiFhirDao implements IFhirResourceDao { private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(BaseHapiFhirResourceDao.class); @Autowired private DaoConfig myDaoConfig; - @PersistenceContext(type = PersistenceContextType.TRANSACTION) - protected EntityManager myEntityManager; - @Autowired protected PlatformTransactionManager myPlatformTransactionManager; @@ -154,14 +150,14 @@ public abstract class BaseHapiFhirResourceDao extends BaseH @Override public DaoMethodOutcome create(T theResource, String theIfNoneExist, boolean thePerformIndexing) { - if (isNotBlank(theResource.getId().getIdPart())) { + if (isNotBlank(theResource.getIdElement().getIdPart())) { if (getContext().getVersion().getVersion().equals(FhirVersionEnum.DSTU1)) { - if (theResource.getId().isIdPartValidLong()) { - String message = getContext().getLocalizer().getMessage(BaseHapiFhirResourceDao.class, "failedToCreateWithClientAssignedNumericId", theResource.getId().getIdPart()); + if (theResource.getIdElement().isIdPartValidLong()) { + String message = getContext().getLocalizer().getMessage(BaseHapiFhirResourceDao.class, "failedToCreateWithClientAssignedNumericId", theResource.getIdElement().getIdPart()); throw new InvalidRequestException(message, createErrorOperationOutcome(message)); } } else { - String message = getContext().getLocalizer().getMessage(BaseHapiFhirResourceDao.class, "failedToCreateWithClientAssignedId", theResource.getId().getIdPart()); + String message = getContext().getLocalizer().getMessage(BaseHapiFhirResourceDao.class, "failedToCreateWithClientAssignedId", theResource.getIdElement().getIdPart()); throw new InvalidRequestException(message, createErrorOperationOutcome(message)); } } @@ -183,11 +179,11 @@ public abstract class BaseHapiFhirResourceDao extends BaseH public DaoMethodOutcome delete(IIdType theId) { List deleteConflicts = new ArrayList(); StopWatch w = new StopWatch(); - + ResourceTable savedEntity = delete(theId, deleteConflicts); validateDeleteConflictsEmptyOrThrowException(deleteConflicts); - + ourLog.info("Processed delete on {} in {}ms", theId.getValue(), w.getMillisAndRestart()); return toMethodOutcome(savedEntity, null); } @@ -226,9 +222,9 @@ public abstract class BaseHapiFhirResourceDao extends BaseH List deleteConflicts = new ArrayList(); List deletedResources = deleteByUrl(theUrl, deleteConflicts); - + validateDeleteConflictsEmptyOrThrowException(deleteConflicts); - + if (deletedResources.isEmpty()) { throw new ResourceNotFoundException(getContext().getLocalizer().getMessage(BaseHapiFhirResourceDao.class, "unableToDeleteNotFound", theUrl)); } @@ -250,7 +246,7 @@ public abstract class BaseHapiFhirResourceDao extends BaseH for (Long pid : resource) { ResourceTable entity = myEntityManager.find(ResourceTable.class, pid); retVal.add(entity); - + validateOkToDelete(deleteConflicts, entity); // Notify interceptors @@ -270,7 +266,7 @@ public abstract class BaseHapiFhirResourceDao extends BaseH } } - + return retVal; } @@ -294,16 +290,16 @@ public abstract class BaseHapiFhirResourceDao extends BaseH } } - if (isNotBlank(theResource.getId().getIdPart())) { - if (isValidPid(theResource.getId())) { + if (isNotBlank(theResource.getIdElement().getIdPart())) { + if (isValidPid(theResource.getIdElement())) { throw new UnprocessableEntityException("This server cannot create an entity with a user-specified numeric ID - Client should not specify an ID when creating a new resource, or should include at least one letter in the ID to force a client-defined ID"); } - createForcedIdIfNeeded(entity, theResource.getId()); + createForcedIdIfNeeded(entity, theResource.getIdElement()); if (entity.getForcedId() != null) { try { - translateForcedIdToPid(theResource.getId()); - throw new UnprocessableEntityException(getContext().getLocalizer().getMessage(BaseHapiFhirResourceDao.class, "duplicateCreateForcedId", theResource.getId().getIdPart())); + translateForcedIdToPid(theResource.getIdElement()); + throw new UnprocessableEntityException(getContext().getLocalizer().getMessage(BaseHapiFhirResourceDao.class, "duplicateCreateForcedId", theResource.getIdElement().getIdPart())); } catch (ResourceNotFoundException e) { // good, this ID doesn't exist so we can create it } @@ -312,7 +308,7 @@ public abstract class BaseHapiFhirResourceDao extends BaseH } // Notify interceptors - ActionRequestDetails requestDetails = new ActionRequestDetails(theResource.getId(), toResourceName(theResource), theResource); + ActionRequestDetails requestDetails = new ActionRequestDetails(theResource.getIdElement(), toResourceName(theResource), theResource); notifyInterceptors(RestOperationTypeEnum.CREATE, requestDetails); // Perform actual DB update @@ -395,7 +391,13 @@ public abstract class BaseHapiFhirResourceDao extends BaseH BaseHasResource entity = readEntity(theId.toVersionless(), false); validateResourceType(entity); currentTmp = toResource(myResourceType, entity, true); - if (ResourceMetadataKeyEnum.UPDATED.get(currentTmp).after(end.getValue())) { + Date lastUpdated; + if (currentTmp instanceof IResource) { + lastUpdated = ResourceMetadataKeyEnum.UPDATED.get((IResource) currentTmp).getValue(); + } else { + lastUpdated = ((IAnyResource) currentTmp).getMeta().getLastUpdated(); + } + if (lastUpdated.after(end.getValue())) { currentTmp = null; } } catch (ResourceNotFoundException e) { @@ -666,7 +668,7 @@ public abstract class BaseHapiFhirResourceDao extends BaseH ourLog.info("Processed metaDeleteOperation on {} in {}ms", new Object[] { theResourceId.getValue(), w.getMillisAndRestart() }); @SuppressWarnings("unchecked") - MT retVal = (MT)metaGetOperation(theMetaDel.getClass(), theResourceId); + MT retVal = (MT) metaGetOperation(theMetaDel.getClass(), theResourceId); return retVal; } @@ -685,7 +687,7 @@ public abstract class BaseHapiFhirResourceDao extends BaseH return retVal; } - + protected MT toMetaDt(Class theType, Collection tagDefinitions) { MT retVal; try { @@ -752,9 +754,9 @@ public abstract class BaseHapiFhirResourceDao extends BaseH * The resource that is about to be stored */ protected void preProcessResourceForStorage(T theResource) { - if (theResource.getId().hasIdPart()) { - if (!theResource.getId().isIdPartValid()) { - throw new InvalidRequestException(getContext().getLocalizer().getMessage(BaseHapiFhirResourceDao.class, "failedToCreateWithInvalidId", theResource.getId().getIdPart())); + if (theResource.getIdElement().hasIdPart()) { + if (!theResource.getIdElement().isIdPartValid()) { + throw new InvalidRequestException(getContext().getLocalizer().getMessage(BaseHapiFhirResourceDao.class, "failedToCreateWithInvalidId", theResource.getIdElement().getIdPart())); } } } @@ -779,7 +781,12 @@ public abstract class BaseHapiFhirResourceDao extends BaseH T retVal = toResource(myResourceType, entity, false); - InstantDt deleted = ResourceMetadataKeyEnum.DELETED_AT.get(retVal); + IPrimitiveType deleted; + if (retVal instanceof IResource) { + deleted = ResourceMetadataKeyEnum.DELETED_AT.get((IResource) retVal); + } else { + deleted = ResourceMetadataKeyEnum.DELETED_AT.get((IAnyResource) retVal); + } if (deleted != null && !deleted.isEmpty()) { throw new ResourceGoneException("Resource was deleted at " + deleted.getValueAsString()); } @@ -893,7 +900,7 @@ public abstract class BaseHapiFhirResourceDao extends BaseH } return search(map); } - + @Override public IBundleProvider search(final SearchParameterMap theParams) { // Notify interceptors @@ -933,7 +940,7 @@ public abstract class BaseHapiFhirResourceDao extends BaseH @SuppressWarnings("unchecked") @Required - public void setResourceType(Class theTableType) { + public void setResourceType(Class theTableType) { myResourceType = (Class) theTableType; } @@ -945,18 +952,29 @@ public abstract class BaseHapiFhirResourceDao extends BaseH mySecondaryPrimaryKeyParamName = theSecondaryPrimaryKeyParamName; } - private DaoMethodOutcome toMethodOutcome(final BaseHasResource theEntity, IResource theResource) { + private DaoMethodOutcome toMethodOutcome(final BaseHasResource theEntity, IBaseResource theResource) { DaoMethodOutcome outcome = new DaoMethodOutcome(); - outcome.setId(theEntity.getIdDt()); + + IIdType id = theEntity.getIdDt(); + if (getContext().getVersion().getVersion().isRi()) { + id = new IdType(id.getValue()); + } + + outcome.setId(id); outcome.setResource(theResource); if (theResource != null) { - theResource.setId(theEntity.getIdDt()); - ResourceMetadataKeyEnum.UPDATED.put(theResource, theEntity.getUpdated()); + theResource.setId(id); + if (theResource instanceof IResource) { + ResourceMetadataKeyEnum.UPDATED.put((IResource) theResource, theEntity.getUpdated()); + } else { + IBaseMetaType meta = ((IAnyResource) theResource).getMeta(); + meta.setLastUpdated(theEntity.getUpdatedDate()); + } } return outcome; } - private DaoMethodOutcome toMethodOutcome(final ResourceTable theEntity, IResource theResource) { + private DaoMethodOutcome toMethodOutcome(final ResourceTable theEntity, IBaseResource theResource) { DaoMethodOutcome retVal = toMethodOutcome((BaseHasResource) theEntity, theResource); retVal.setEntity(theEntity); return retVal; @@ -978,9 +996,6 @@ public abstract class BaseHapiFhirResourceDao extends BaseH return retVal; } - - - @Override public DaoMethodOutcome update(T theResource) { return update(theResource, null); @@ -1013,7 +1028,7 @@ public abstract class BaseHapiFhirResourceDao extends BaseH return create(theResource, null, thePerformIndexing); } } else { - resourceId = theResource.getId(); + resourceId = theResource.getIdElement(); if (resourceId == null || isBlank(resourceId.getIdPart())) { throw new InvalidRequestException("Can not update a resource with no ID"); } @@ -1021,7 +1036,7 @@ public abstract class BaseHapiFhirResourceDao extends BaseH entity = readEntityLatestVersion(resourceId); } catch (ResourceNotFoundException e) { if (resourceId.isIdPartValidLong()) { - throw new InvalidRequestException(getContext().getLocalizer().getMessage(BaseHapiFhirResourceDao.class, "failedToCreateWithClientAssignedNumericId", theResource.getId().getIdPart())); + throw new InvalidRequestException(getContext().getLocalizer().getMessage(BaseHapiFhirResourceDao.class, "failedToCreateWithClientAssignedNumericId", theResource.getIdElement().getIdPart())); } return doCreate(theResource, null, thePerformIndexing, new Date()); } @@ -1087,8 +1102,6 @@ public abstract class BaseHapiFhirResourceDao extends BaseH theDeleteConflicts.add(new DeleteConflict(sourceId, sourcePath, targetId)); } - - private void validateResourceType(BaseHasResource entity) { validateResourceType(entity, myResourceName); } diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/BaseSearchParamExtractor.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/BaseSearchParamExtractor.java index c73d2bc9b20..837198c7650 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/BaseSearchParamExtractor.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/BaseSearchParamExtractor.java @@ -23,6 +23,8 @@ package ca.uhn.fhir.jpa.dao; import java.util.ArrayList; import java.util.List; +import org.hl7.fhir.instance.model.api.IBaseResource; + import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.context.RuntimeResourceDefinition; import ca.uhn.fhir.model.api.IResource; @@ -40,7 +42,7 @@ public class BaseSearchParamExtractor { return myContext; } - protected List extractValues(String thePaths, IResource theResource) { + protected List extractValues(String thePaths, IBaseResource theResource) { List values = new ArrayList(); String[] nextPathsSplit = thePaths.split("\\|"); FhirTerser t = myContext.newTerser(); diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/FhirResourceDaoBundleDstu21.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/FhirResourceDaoBundleDstu21.java index cfd882dc3e5..e8ba759b04d 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/FhirResourceDaoBundleDstu21.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/FhirResourceDaoBundleDstu21.java @@ -1,5 +1,9 @@ package ca.uhn.fhir.jpa.dao; +import org.hl7.fhir.dstu21.model.Bundle; +import org.hl7.fhir.dstu21.model.Bundle.BundleEntryComponent; +import org.hl7.fhir.dstu21.model.Bundle.BundleType; + /* * #%L * HAPI FHIR JPA Server @@ -20,9 +24,6 @@ package ca.uhn.fhir.jpa.dao; * #L% */ -import ca.uhn.fhir.model.dstu21.resource.Bundle; -import ca.uhn.fhir.model.dstu21.resource.Bundle.Entry; -import ca.uhn.fhir.model.dstu21.valueset.BundleTypeEnum; import ca.uhn.fhir.rest.server.exceptions.UnprocessableEntityException; public class FhirResourceDaoBundleDstu21 extends FhirResourceDaoDstu21 { @@ -31,12 +32,12 @@ public class FhirResourceDaoBundleDstu21 extends FhirResourceDaoDstu21 { protected void preProcessResourceForStorage(Bundle theResource) { super.preProcessResourceForStorage(theResource); - if (theResource.getTypeElement().getValueAsEnum() != BundleTypeEnum.DOCUMENT) { - String message = "Unable to store a Bundle resource on this server with a Bundle.type value other than '" + BundleTypeEnum.DOCUMENT.getCode() + "' - Value was: " + (theResource.getTypeElement().getValueAsEnum() != null ? theResource.getTypeElement().getValueAsEnum().getCode() : "(missing)"); + if (theResource.getType() != BundleType.DOCUMENT) { + String message = "Unable to store a Bundle resource on this server with a Bundle.type value other than '" + BundleType.DOCUMENT.toCode() + "' - Value was: " + (theResource.getType() != null ? theResource.getType().toCode() : "(missing)"); throw new UnprocessableEntityException(message); } - for (Entry next : theResource.getEntry()) { + for (BundleEntryComponent next : theResource.getEntry()) { next.setFullUrl((String)null); } } diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/FhirResourceDaoDstu21.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/FhirResourceDaoDstu21.java index 2f7fe2765a6..0a383a9abaa 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/FhirResourceDaoDstu21.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/FhirResourceDaoDstu21.java @@ -1,11 +1,37 @@ package ca.uhn.fhir.jpa.dao; +/* + * #%L + * HAPI FHIR JPA Server + * %% + * Copyright (C) 2014 - 2015 University Health Network + * %% + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * #L% + */ + import static org.apache.commons.lang3.StringUtils.isNotBlank; import java.util.ArrayList; import java.util.Collections; import java.util.List; +import org.hl7.fhir.dstu21.hapi.validation.IValidationSupport; +import org.hl7.fhir.dstu21.model.IdType; +import org.hl7.fhir.dstu21.model.OperationOutcome; +import org.hl7.fhir.dstu21.model.OperationOutcome.IssueSeverity; +import org.hl7.fhir.dstu21.model.OperationOutcome.OperationOutcomeIssueComponent; +import org.hl7.fhir.instance.model.api.IAnyResource; import org.hl7.fhir.instance.model.api.IBaseOperationOutcome; import org.hl7.fhir.instance.model.api.IBaseResource; import org.hl7.fhir.instance.model.api.IIdType; @@ -21,9 +47,6 @@ import ca.uhn.fhir.model.api.Bundle; import ca.uhn.fhir.model.api.IResource; import ca.uhn.fhir.model.api.Include; import ca.uhn.fhir.model.base.composite.BaseResourceReferenceDt; -import ca.uhn.fhir.model.dstu21.resource.OperationOutcome; -import ca.uhn.fhir.model.dstu21.valueset.IssueSeverityEnum; -import ca.uhn.fhir.model.primitive.IdDt; import ca.uhn.fhir.rest.api.MethodOutcome; import ca.uhn.fhir.rest.api.RestOperationTypeEnum; import ca.uhn.fhir.rest.api.ValidationModeEnum; @@ -36,13 +59,12 @@ import ca.uhn.fhir.validation.DefaultProfileValidationSupport; import ca.uhn.fhir.validation.FhirInstanceValidator; import ca.uhn.fhir.validation.FhirValidator; import ca.uhn.fhir.validation.IValidationContext; -import ca.uhn.fhir.validation.IValidationSupport; import ca.uhn.fhir.validation.IValidatorModule; import ca.uhn.fhir.validation.ValidationResult; import ca.uhn.fhir.validation.ValidationSupportChain; import net.sourceforge.cobertura.CoverageIgnore; -public class FhirResourceDaoDstu21 extends BaseHapiFhirResourceDao { +public class FhirResourceDaoDstu21 extends BaseHapiFhirResourceDao { @Autowired() @Qualifier("myJpaValidationSupportDstu21") @@ -70,8 +92,9 @@ public class FhirResourceDaoDstu21 extends BaseHapiFhirReso @Override protected IBaseOperationOutcome createOperationOutcome(String theSeverity, String theMessage) { OperationOutcome oo = new OperationOutcome(); - oo.getIssueFirstRep().getSeverityElement().setValue(theSeverity); - oo.getIssueFirstRep().getDiagnosticsElement().setValue(theMessage); + OperationOutcomeIssueComponent issue = oo.addIssue(); + issue.getSeverityElement().setValueAsString(theSeverity); + issue.setDiagnostics(theMessage); return oo; } @@ -93,15 +116,15 @@ public class FhirResourceDaoDstu21 extends BaseHapiFhirReso validateDeleteConflictsEmptyOrThrowException(deleteConflicts); OperationOutcome oo = new OperationOutcome(); - oo.addIssue().setSeverity(IssueSeverityEnum.INFORMATION).setDiagnostics("Ok to delete"); - return new MethodOutcome(new IdDt(theId.getValue()), oo); + oo.addIssue().setSeverity(IssueSeverity.INFORMATION).setDiagnostics("Ok to delete"); + return new MethodOutcome(new IdType(theId.getValue()), oo); } FhirValidator validator = getContext().newValidator(); FhirInstanceValidator val = new FhirInstanceValidator(); val.setBestPracticeWarningLevel(BestPracticeWarningLevel.Warning); - val.setValidationSupport(new ValidationSupportChain(new DefaultProfileValidationSupport(), myJpaValidationSupport)); +// val.setValidationSupport(new ValidationSupportChain(new DefaultProfileValidationSupport(), myJpaValidationSupport)); validator.registerValidatorModule(val); validator.registerValidatorModule(new IdChecker(theMode)); diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/FhirResourceDaoEncounterDstu2.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/FhirResourceDaoEncounterDstu2.java index 3ff761d6103..bfe8a5db673 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/FhirResourceDaoEncounterDstu2.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/FhirResourceDaoEncounterDstu2.java @@ -24,11 +24,12 @@ import java.util.Collections; import javax.servlet.http.HttpServletRequest; +import org.hl7.fhir.instance.model.api.IIdType; +import org.hl7.fhir.instance.model.api.IPrimitiveType; + import ca.uhn.fhir.jpa.dao.SearchParameterMap.EverythingModeEnum; import ca.uhn.fhir.model.api.IResource; import ca.uhn.fhir.model.dstu2.resource.Encounter; -import ca.uhn.fhir.model.primitive.IdDt; -import ca.uhn.fhir.model.primitive.UnsignedIntDt; import ca.uhn.fhir.rest.api.SortSpec; import ca.uhn.fhir.rest.param.DateRangeParam; import ca.uhn.fhir.rest.param.StringParam; @@ -37,7 +38,7 @@ import ca.uhn.fhir.rest.server.IBundleProvider; public class FhirResourceDaoEncounterDstu2 extends FhirResourceDaoDstu2implements IFhirResourceDaoEncounter { @Override - public IBundleProvider encounterInstanceEverything(HttpServletRequest theServletRequest, IdDt theId, UnsignedIntDt theCount, DateRangeParam theLastUpdated, SortSpec theSort) { + public IBundleProvider encounterInstanceEverything(HttpServletRequest theServletRequest, IIdType theId, IPrimitiveType theCount, DateRangeParam theLastUpdated, SortSpec theSort) { SearchParameterMap paramMap = new SearchParameterMap(); if (theCount != null) { paramMap.setCount(theCount.getValue()); @@ -56,7 +57,7 @@ public class FhirResourceDaoEncounterDstu2 extends FhirResourceDaoDstu2 theCount, DateRangeParam theLastUpdated, SortSpec theSort) { return encounterInstanceEverything(theServletRequest, null, theCount, theLastUpdated, theSort); } diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/FhirResourceDaoEncounterDstu21.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/FhirResourceDaoEncounterDstu21.java index b16a275bf5c..dc90eb38aad 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/FhirResourceDaoEncounterDstu21.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/FhirResourceDaoEncounterDstu21.java @@ -24,11 +24,12 @@ import java.util.Collections; import javax.servlet.http.HttpServletRequest; +import org.hl7.fhir.dstu21.model.Encounter; +import org.hl7.fhir.instance.model.api.IIdType; +import org.hl7.fhir.instance.model.api.IPrimitiveType; + import ca.uhn.fhir.jpa.dao.SearchParameterMap.EverythingModeEnum; import ca.uhn.fhir.model.api.IResource; -import ca.uhn.fhir.model.dstu21.resource.Encounter; -import ca.uhn.fhir.model.primitive.IdDt; -import ca.uhn.fhir.model.primitive.UnsignedIntDt; import ca.uhn.fhir.rest.api.SortSpec; import ca.uhn.fhir.rest.param.DateRangeParam; import ca.uhn.fhir.rest.param.StringParam; @@ -37,7 +38,7 @@ import ca.uhn.fhir.rest.server.IBundleProvider; public class FhirResourceDaoEncounterDstu21 extends FhirResourceDaoDstu21implements IFhirResourceDaoEncounter { @Override - public IBundleProvider encounterInstanceEverything(HttpServletRequest theServletRequest, IdDt theId, UnsignedIntDt theCount, DateRangeParam theLastUpdated, SortSpec theSort) { + public IBundleProvider encounterInstanceEverything(HttpServletRequest theServletRequest, IIdType theId, IPrimitiveType theCount, DateRangeParam theLastUpdated, SortSpec theSort) { SearchParameterMap paramMap = new SearchParameterMap(); if (theCount != null) { paramMap.setCount(theCount.getValue()); @@ -56,7 +57,7 @@ public class FhirResourceDaoEncounterDstu21 extends FhirResourceDaoDstu21 theCount, DateRangeParam theLastUpdated, SortSpec theSort) { return encounterInstanceEverything(theServletRequest, null, theCount, theLastUpdated, theSort); } diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/FhirResourceDaoPatientDstu2.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/FhirResourceDaoPatientDstu2.java index ec78f8ac67d..711cd5eebb8 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/FhirResourceDaoPatientDstu2.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/FhirResourceDaoPatientDstu2.java @@ -25,11 +25,11 @@ import java.util.Collections; import javax.servlet.http.HttpServletRequest; import org.hl7.fhir.instance.model.api.IIdType; +import org.hl7.fhir.instance.model.api.IPrimitiveType; import ca.uhn.fhir.jpa.dao.SearchParameterMap.EverythingModeEnum; import ca.uhn.fhir.model.api.IResource; import ca.uhn.fhir.model.dstu2.resource.Patient; -import ca.uhn.fhir.model.primitive.UnsignedIntDt; import ca.uhn.fhir.rest.api.RestOperationTypeEnum; import ca.uhn.fhir.rest.api.SortSpec; import ca.uhn.fhir.rest.param.DateRangeParam; @@ -41,7 +41,7 @@ import ca.uhn.fhir.rest.server.interceptor.IServerInterceptor.ActionRequestDetai public class FhirResourceDaoPatientDstu2 extends FhirResourceDaoDstu2implements IFhirResourceDaoPatient { - private IBundleProvider doEverythingOperation(IIdType theId, UnsignedIntDt theCount, DateRangeParam theLastUpdated, SortSpec theSort, StringAndListParam theContent, StringAndListParam theNarrative) { + private IBundleProvider doEverythingOperation(IIdType theId, IPrimitiveType theCount, DateRangeParam theLastUpdated, SortSpec theSort, StringAndListParam theContent, StringAndListParam theNarrative) { SearchParameterMap paramMap = new SearchParameterMap(); if (theCount != null) { paramMap.setCount(theCount.getValue()); @@ -66,7 +66,7 @@ public class FhirResourceDaoPatientDstu2 extends FhirResourceDaoDstu2im } @Override - public IBundleProvider patientInstanceEverything(HttpServletRequest theServletRequest, IIdType theId, UnsignedIntDt theCount, DateRangeParam theLastUpdated, SortSpec theSort, StringAndListParam theContent, StringAndListParam theNarrative) { + public IBundleProvider patientInstanceEverything(HttpServletRequest theServletRequest, IIdType theId, IPrimitiveType theCount, DateRangeParam theLastUpdated, SortSpec theSort, StringAndListParam theContent, StringAndListParam theNarrative) { // Notify interceptors ActionRequestDetails requestDetails = new ActionRequestDetails(null, getResourceName()); notifyInterceptors(RestOperationTypeEnum.EXTENDED_OPERATION_INSTANCE, requestDetails); @@ -75,7 +75,7 @@ public class FhirResourceDaoPatientDstu2 extends FhirResourceDaoDstu2im } @Override - public IBundleProvider patientTypeEverything(HttpServletRequest theServletRequest, UnsignedIntDt theCount, DateRangeParam theLastUpdated, SortSpec theSort, StringAndListParam theContent, StringAndListParam theNarrative) { + public IBundleProvider patientTypeEverything(HttpServletRequest theServletRequest, IPrimitiveType theCount, DateRangeParam theLastUpdated, SortSpec theSort, StringAndListParam theContent, StringAndListParam theNarrative) { // Notify interceptors ActionRequestDetails requestDetails = new ActionRequestDetails(null, getResourceName()); notifyInterceptors(RestOperationTypeEnum.EXTENDED_OPERATION_TYPE, requestDetails); diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/FhirResourceDaoPatientDstu21.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/FhirResourceDaoPatientDstu21.java index e1b67ef395e..1bc01c21a1b 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/FhirResourceDaoPatientDstu21.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/FhirResourceDaoPatientDstu21.java @@ -24,12 +24,12 @@ import java.util.Collections; import javax.servlet.http.HttpServletRequest; +import org.hl7.fhir.dstu21.model.Patient; import org.hl7.fhir.instance.model.api.IIdType; +import org.hl7.fhir.instance.model.api.IPrimitiveType; import ca.uhn.fhir.jpa.dao.SearchParameterMap.EverythingModeEnum; import ca.uhn.fhir.model.api.IResource; -import ca.uhn.fhir.model.dstu21.resource.Patient; -import ca.uhn.fhir.model.primitive.UnsignedIntDt; import ca.uhn.fhir.rest.api.RestOperationTypeEnum; import ca.uhn.fhir.rest.api.SortSpec; import ca.uhn.fhir.rest.param.DateRangeParam; @@ -41,7 +41,7 @@ import ca.uhn.fhir.rest.server.interceptor.IServerInterceptor.ActionRequestDetai public class FhirResourceDaoPatientDstu21 extends FhirResourceDaoDstu21implements IFhirResourceDaoPatient { - private IBundleProvider doEverythingOperation(IIdType theId, UnsignedIntDt theCount, DateRangeParam theLastUpdated, SortSpec theSort, StringAndListParam theContent, StringAndListParam theNarrative) { + private IBundleProvider doEverythingOperation(IIdType theId, IPrimitiveType theCount, DateRangeParam theLastUpdated, SortSpec theSort, StringAndListParam theContent, StringAndListParam theNarrative) { SearchParameterMap paramMap = new SearchParameterMap(); if (theCount != null) { paramMap.setCount(theCount.getValue()); @@ -66,7 +66,7 @@ public class FhirResourceDaoPatientDstu21 extends FhirResourceDaoDstu21 } @Override - public IBundleProvider patientInstanceEverything(HttpServletRequest theServletRequest, IIdType theId, UnsignedIntDt theCount, DateRangeParam theLastUpdated, SortSpec theSort, StringAndListParam theContent, StringAndListParam theNarrative) { + public IBundleProvider patientInstanceEverything(HttpServletRequest theServletRequest, IIdType theId, IPrimitiveType theCount, DateRangeParam theLastUpdated, SortSpec theSort, StringAndListParam theContent, StringAndListParam theNarrative) { // Notify interceptors ActionRequestDetails requestDetails = new ActionRequestDetails(null, getResourceName()); notifyInterceptors(RestOperationTypeEnum.EXTENDED_OPERATION_INSTANCE, requestDetails); @@ -75,7 +75,7 @@ public class FhirResourceDaoPatientDstu21 extends FhirResourceDaoDstu21 } @Override - public IBundleProvider patientTypeEverything(HttpServletRequest theServletRequest, UnsignedIntDt theCount, DateRangeParam theLastUpdated, SortSpec theSort, StringAndListParam theContent, StringAndListParam theNarrative) { + public IBundleProvider patientTypeEverything(HttpServletRequest theServletRequest, IPrimitiveType theCount, DateRangeParam theLastUpdated, SortSpec theSort, StringAndListParam theContent, StringAndListParam theNarrative) { // Notify interceptors ActionRequestDetails requestDetails = new ActionRequestDetails(null, getResourceName()); notifyInterceptors(RestOperationTypeEnum.EXTENDED_OPERATION_TYPE, requestDetails); diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/FhirResourceDaoQuestionnaireResponseDstu21.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/FhirResourceDaoQuestionnaireResponseDstu21.java index 5431a72894c..ac2f30baac9 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/FhirResourceDaoQuestionnaireResponseDstu21.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/FhirResourceDaoQuestionnaireResponseDstu21.java @@ -22,6 +22,10 @@ package ca.uhn.fhir.jpa.dao; import javax.annotation.PostConstruct; +import org.hl7.fhir.dstu21.model.OperationOutcome; +import org.hl7.fhir.dstu21.model.Questionnaire; +import org.hl7.fhir.dstu21.model.QuestionnaireResponse; +import org.hl7.fhir.dstu21.model.ValueSet; import org.hl7.fhir.instance.model.api.IBaseOperationOutcome; import org.hl7.fhir.instance.model.api.IBaseResource; import org.hl7.fhir.instance.model.api.IIdType; @@ -30,10 +34,6 @@ import org.springframework.beans.factory.annotation.Qualifier; import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.jpa.entity.ResourceTable; -import ca.uhn.fhir.model.dstu21.resource.OperationOutcome; -import ca.uhn.fhir.model.dstu21.resource.Questionnaire; -import ca.uhn.fhir.model.dstu21.resource.QuestionnaireResponse; -import ca.uhn.fhir.model.dstu21.resource.ValueSet; import ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException; import ca.uhn.fhir.rest.server.exceptions.UnprocessableEntityException; import ca.uhn.fhir.validation.FhirQuestionnaireResponseValidator; diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/FhirResourceDaoSearchParameterDstu21.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/FhirResourceDaoSearchParameterDstu21.java index a1bbf860970..2b1d2595ca5 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/FhirResourceDaoSearchParameterDstu21.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/FhirResourceDaoSearchParameterDstu21.java @@ -21,17 +21,16 @@ package ca.uhn.fhir.jpa.dao; */ import org.apache.commons.lang3.time.DateUtils; +import org.hl7.fhir.dstu21.model.Bundle; +import org.hl7.fhir.dstu21.model.Meta; +import org.hl7.fhir.dstu21.model.SearchParameter; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.scheduling.annotation.Scheduled; -import ca.uhn.fhir.model.dstu21.composite.MetaDt; -import ca.uhn.fhir.model.dstu21.resource.Bundle; -import ca.uhn.fhir.model.dstu21.resource.SearchParameter; - public class FhirResourceDaoSearchParameterDstu21 extends FhirResourceDaoDstu21implements IFhirResourceDaoSearchParameter { @Autowired - private IFhirSystemDao mySystemDao; + private IFhirSystemDao mySystemDao; /** * This method is called once per minute to perform any required re-indexing. During most passes this will diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/FhirResourceDaoSubscriptionDstu2.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/FhirResourceDaoSubscriptionDstu2.java index 9bc46a0a405..cadaf43ad5a 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/FhirResourceDaoSubscriptionDstu2.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/FhirResourceDaoSubscriptionDstu2.java @@ -258,7 +258,7 @@ public class FhirResourceDaoSubscriptionDstu2 extends FhirResourceDaoDstu2 flags = new ArrayList(); Date mostRecentMatch = null; - for (IBaseResource next : results.getResources(0, results.size())) { + for (IBaseResource nextBase : results.getResources(0, results.size())) { + IAnyResource next = (IAnyResource)nextBase; - Date updated = ResourceMetadataKeyEnum.UPDATED.get((IResource) next).getValue(); + Date updated = next.getMeta().getLastUpdated(); if (mostRecentMatch == null) { mostRecentMatch = updated; } else { @@ -188,7 +189,7 @@ public class FhirResourceDaoSubscriptionDstu21 extends FhirResourceDaoDstu21 0) { - ourLog.info("Updated subscription status for subscription {} to {}", resourceId, resource.getStatusElement().getValueAsEnum()); + ourLog.info("Updated subscription status for subscription {} to {}", resourceId, resource.getStatus()); } else { createSubscriptionTable(retVal, resource); } @@ -323,7 +324,7 @@ public class FhirResourceDaoSubscriptionDstu21 extends FhirResourceDaoDstu21implements IFhirResourceDaoValueSet { @Autowired - private IJpaValidationSupport myJpaValidationSupport; + private IJpaValidationSupportDstu2 myJpaValidationSupport; private ValidationSupportChain myValidationSupport; @@ -181,8 +178,7 @@ public class FhirResourceDaoValueSetDstu2 extends FhirResourceDaoDstu2 } @Override - public ca.uhn.fhir.jpa.dao.IFhirResourceDaoValueSet.ValidateCodeResult validateCode(UriDt theValueSetIdentifier, IIdType theId, CodeDt theCode, UriDt theSystem, StringDt theDisplay, - CodingDt theCoding, CodeableConceptDt theCodeableConcept) { + public ca.uhn.fhir.jpa.dao.IFhirResourceDaoValueSet.ValidateCodeResult validateCode(IPrimitiveType theValueSetIdentifier, IIdType theId, IPrimitiveType theCode, IPrimitiveType theSystem, IPrimitiveType theDisplay, CodingDt theCoding, CodeableConceptDt theCodeableConcept) { List valueSetIds; boolean haveCodeableConcept = theCodeableConcept != null && theCodeableConcept.getCoding().size() > 0; @@ -292,7 +288,7 @@ public class FhirResourceDaoValueSetDstu2 extends FhirResourceDaoDstu2 } @Override - public ca.uhn.fhir.jpa.dao.IFhirResourceDaoValueSet.LookupCodeResult lookupCode(CodeDt theCode, UriDt theSystem, CodingDt theCoding) { + public ca.uhn.fhir.jpa.dao.IFhirResourceDaoValueSet.LookupCodeResult lookupCode(IPrimitiveType theCode, IPrimitiveType theSystem, CodingDt theCoding) { boolean haveCoding = theCoding != null && isNotBlank(theCoding.getSystem()) && isNotBlank(theCoding.getCode()); boolean haveCode = theCode != null && theCode.isEmpty() == false; boolean haveSystem = theSystem != null && theSystem.isEmpty() == false; diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/FhirResourceDaoValueSetDstu21.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/FhirResourceDaoValueSetDstu21.java index 23a00c4e3c2..d12cf14ccff 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/FhirResourceDaoValueSetDstu21.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/FhirResourceDaoValueSetDstu21.java @@ -25,12 +25,21 @@ import static org.apache.commons.lang3.StringUtils.isNotBlank; import java.util.ArrayList; import java.util.Collections; +import java.util.Date; import java.util.List; import java.util.Set; import javax.annotation.PostConstruct; import org.apache.commons.codec.binary.StringUtils; +import org.hl7.fhir.dstu21.model.CodeableConcept; +import org.hl7.fhir.dstu21.model.Coding; +import org.hl7.fhir.dstu21.model.IdType; +import org.hl7.fhir.dstu21.model.ValueSet; +import org.hl7.fhir.dstu21.model.ValueSet.ConceptDefinitionComponent; +import org.hl7.fhir.dstu21.model.ValueSet.ConceptReferenceComponent; +import org.hl7.fhir.dstu21.model.ValueSet.ConceptSetComponent; +import org.hl7.fhir.dstu21.model.ValueSet.ValueSetExpansionContainsComponent; import org.hl7.fhir.instance.model.api.IIdType; import org.hl7.fhir.instance.model.api.IPrimitiveType; import org.springframework.beans.factory.annotation.Autowired; @@ -38,18 +47,6 @@ import org.springframework.beans.factory.annotation.Qualifier; import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.jpa.entity.BaseHasResource; -import ca.uhn.fhir.model.dstu21.composite.CodeableConceptDt; -import ca.uhn.fhir.model.dstu21.composite.CodingDt; -import ca.uhn.fhir.model.dstu21.resource.ValueSet; -import ca.uhn.fhir.model.dstu21.resource.ValueSet.CodeSystemConcept; -import ca.uhn.fhir.model.dstu21.resource.ValueSet.ComposeInclude; -import ca.uhn.fhir.model.dstu21.resource.ValueSet.ComposeIncludeConcept; -import ca.uhn.fhir.model.dstu21.resource.ValueSet.ExpansionContains; -import ca.uhn.fhir.model.primitive.CodeDt; -import ca.uhn.fhir.model.primitive.DateTimeDt; -import ca.uhn.fhir.model.primitive.IdDt; -import ca.uhn.fhir.model.primitive.StringDt; -import ca.uhn.fhir.model.primitive.UriDt; import ca.uhn.fhir.rest.param.TokenParam; import ca.uhn.fhir.rest.param.UriParam; import ca.uhn.fhir.rest.server.IBundleProvider; @@ -58,10 +55,10 @@ import ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException; import ca.uhn.fhir.validation.DefaultProfileValidationSupport; import ca.uhn.fhir.validation.ValidationSupportChain; -public class FhirResourceDaoValueSetDstu21 extends FhirResourceDaoDstu21implements IFhirResourceDaoValueSet { +public class FhirResourceDaoValueSetDstu21 extends FhirResourceDaoDstu21implements IFhirResourceDaoValueSet { @Autowired - private IJpaValidationSupport myJpaValidationSupport; + private IJpaValidationSupportDstu21 myJpaValidationSupport; private ValidationSupportChain myValidationSupport; @@ -75,8 +72,8 @@ public class FhirResourceDaoValueSetDstu21 extends FhirResourceDaoDstu21 theValueSetIdentifier, IIdType theId, IPrimitiveType theCode, IPrimitiveType theSystem, IPrimitiveType theDisplay, Coding theCoding, CodeableConcept theCodeableConcept) { List valueSetIds; boolean haveCodeableConcept = theCodeableConcept != null && theCodeableConcept.getCoding().size() > 0; @@ -203,7 +199,7 @@ public class FhirResourceDaoValueSetDstu21 extends FhirResourceDaoDstu21 ids = searchForIds(ValueSet.SP_IDENTIFIER, new TokenParam(null, theValueSetIdentifier.getValue())); valueSetIds = new ArrayList(); for (Long next : ids) { - valueSetIds.add(new IdDt("ValueSet", next)); + valueSetIds.add(new IdType("ValueSet", next)); } } else { if (theCode == null || theCode.isEmpty()) { @@ -216,7 +212,7 @@ public class FhirResourceDaoValueSetDstu21 extends FhirResourceDaoDstu21 contains = expansion.getExpansion().getContains(); + List contains = expansion.getExpansion().getContains(); ValidateCodeResult result = validateCodeIsInContains(contains, toStringOrNull(theSystem), toStringOrNull(theCode), theCoding, theCodeableConcept); if (result != null) { if (theDisplay != null && isNotBlank(theDisplay.getValue()) && isNotBlank(result.getDisplay())) { @@ -233,14 +229,14 @@ public class FhirResourceDaoValueSetDstu21 extends FhirResourceDaoDstu21 findValueSetIdsContainingSystemAndCode(String theCode, String theSystem) { if (theSystem != null && theSystem.startsWith("http://hl7.org/fhir/")) { - return Collections.singletonList((IIdType)new IdDt(theSystem)); + return Collections.singletonList((IIdType)new IdType(theSystem)); } List valueSetIds; Set ids = searchForIds(ValueSet.SP_CODE, new TokenParam(theSystem, theCode)); valueSetIds = new ArrayList(); for (Long next : ids) { - valueSetIds.add(new IdDt("ValueSet", next)); + valueSetIds.add(new IdType("ValueSet", next)); } return valueSetIds; } @@ -259,9 +255,9 @@ public class FhirResourceDaoValueSetDstu21 extends FhirResourceDaoDstu21 contains, String theSystem, String theCode, CodingDt theCoding, - CodeableConceptDt theCodeableConcept) { - for (ExpansionContains nextCode : contains) { + private ca.uhn.fhir.jpa.dao.IFhirResourceDaoValueSet.ValidateCodeResult validateCodeIsInContains(List contains, String theSystem, String theCode, Coding theCoding, + CodeableConcept theCodeableConcept) { + for (ValueSetExpansionContainsComponent nextCode : contains) { ca.uhn.fhir.jpa.dao.IFhirResourceDaoValueSet.ValidateCodeResult result = validateCodeIsInContains(nextCode.getContains(), theSystem, theCode, theCoding, theCodeableConcept); if (result != null) { return result; @@ -279,7 +275,7 @@ public class FhirResourceDaoValueSetDstu21 extends FhirResourceDaoDstu21 theCode, IPrimitiveType theSystem, Coding theCoding) { boolean haveCoding = theCoding != null && isNotBlank(theCoding.getSystem()) && isNotBlank(theCoding.getCode()); boolean haveCode = theCode != null && theCode.isEmpty() == false; boolean haveSystem = theSystem != null && theSystem.isEmpty() == false; @@ -317,7 +313,7 @@ public class FhirResourceDaoValueSetDstu21 extends FhirResourceDaoDstu21 valueSetIds = findValueSetIdsContainingSystemAndCode(code, system); for (IIdType nextId : valueSetIds) { ValueSet expansion = expand(nextId, null); - List contains = expansion.getExpansion().getContains(); + List contains = expansion.getExpansion().getContains(); ca.uhn.fhir.jpa.dao.IFhirResourceDaoValueSet.LookupCodeResult result = lookup(contains, system, code); if (result != null) { return result; @@ -331,8 +327,8 @@ public class FhirResourceDaoValueSetDstu21 extends FhirResourceDaoDstu21 theContains, String theSystem, String theCode) { - for (ExpansionContains nextCode : theContains) { + private ca.uhn.fhir.jpa.dao.IFhirResourceDaoValueSet.LookupCodeResult lookup(List theContains, String theSystem, String theCode) { + for (ValueSetExpansionContainsComponent nextCode : theContains) { String system = nextCode.getSystem(); String code = nextCode.getCode(); @@ -341,8 +337,8 @@ public class FhirResourceDaoValueSetDstu21 extends FhirResourceDaoDstu21 { +public class FhirSystemDaoDstu21 extends BaseHapiFhirSystemDao { private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(FhirSystemDaoDstu21.class); @Autowired @@ -104,7 +108,7 @@ public class FhirSystemDaoDstu21 extends BaseHapiFhirSystemDao { txTemplate.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES_NEW); Bundle resp = new Bundle(); - resp.setType(BundleTypeEnum.BATCH_RESPONSE); + resp.setType(BundleType.BATCHRESPONSE); OperationOutcome ooResp = new OperationOutcome(); resp.addEntry().setResource(ooResp); @@ -112,13 +116,13 @@ public class FhirSystemDaoDstu21 extends BaseHapiFhirSystemDao { * For batch, we handle each entry as a mini-transaction in its own database transaction so that if one fails, it doesn't prevent others */ - for (final Entry nextRequestEntry : theRequest.getEntry()) { + for (final BundleEntryComponent nextRequestEntry : theRequest.getEntry()) { TransactionCallback callback = new TransactionCallback() { @Override public Bundle doInTransaction(TransactionStatus theStatus) { Bundle subRequestBundle = new Bundle(); - subRequestBundle.setType(BundleTypeEnum.TRANSACTION); + subRequestBundle.setType(BundleType.TRANSACTION); subRequestBundle.addEntry(nextRequestEntry); Bundle subResponseBundle = transaction((ServletRequestDetails) theRequestDetails, subRequestBundle, "Batch sub-request"); @@ -131,7 +135,7 @@ public class FhirSystemDaoDstu21 extends BaseHapiFhirSystemDao { Bundle nextResponseBundle = txTemplate.execute(callback); caughtEx = null; - Entry subResponseEntry = nextResponseBundle.getEntry().get(0); + BundleEntryComponent subResponseEntry = nextResponseBundle.getEntry().get(0); resp.addEntry(subResponseEntry); /* * If the individual entry didn't have a resource in its response, bring the sub-transaction's OperationOutcome across so the client can see it @@ -148,13 +152,13 @@ public class FhirSystemDaoDstu21 extends BaseHapiFhirSystemDao { } if (caughtEx != null) { - Entry nextEntry = resp.addEntry(); + BundleEntryComponent nextEntry = resp.addEntry(); OperationOutcome oo = new OperationOutcome(); - oo.addIssue().setSeverity(IssueSeverityEnum.ERROR).setDiagnostics(caughtEx.getMessage()); + oo.addIssue().setSeverity(IssueSeverity.ERROR).setDiagnostics(caughtEx.getMessage()); nextEntry.setResource(oo); - EntryResponse nextEntryResp = nextEntry.getResponse(); + BundleEntryResponseComponent nextEntryResp = nextEntry.getResponse(); nextEntryResp.setStatus(toStatusString(caughtEx.getStatusCode())); } @@ -162,12 +166,12 @@ public class FhirSystemDaoDstu21 extends BaseHapiFhirSystemDao { long delay = System.currentTimeMillis() - start; ourLog.info("Batch completed in {}ms", new Object[] { delay }); - ooResp.addIssue().setSeverity(IssueSeverityEnum.INFORMATION).setDiagnostics("Batch completed in " + delay + "ms"); + ooResp.addIssue().setSeverity(IssueSeverity.INFORMATION).setDiagnostics("Batch completed in " + delay + "ms"); return resp; } - private String extractTransactionUrlOrThrowException(Entry nextEntry, HTTPVerbEnum verb) { + private String extractTransactionUrlOrThrowException(BundleEntryComponent nextEntry, HTTPVerb verb) { String url = nextEntry.getRequest().getUrl(); if (isBlank(url)) { throw new InvalidRequestException(getContext().getLocalizer().getMessage(BaseHapiFhirSystemDao.class, "transactionMissingUrl", verb.name())); @@ -189,8 +193,8 @@ public class FhirSystemDaoDstu21 extends BaseHapiFhirSystemDao { return p.parseResource(theResource.getClass(), p.encodeResourceToString(theResource)); } - private IFhirResourceDao getDaoOrThrowException(Class theClass) { - IFhirResourceDao retVal = getDao(theClass); + private IFhirResourceDao getDaoOrThrowException(Class theClass) { + IFhirResourceDao retVal = getDao(theClass); if (retVal == null) { throw new InvalidRequestException("Unable to process request, this server does not know how to handle resources of type " + getContext().getResourceDefinition(theClass).getName()); } @@ -198,7 +202,7 @@ public class FhirSystemDaoDstu21 extends BaseHapiFhirSystemDao { } @Override - public MetaDt metaGetOperation() { + public Meta metaGetOperation() { // Notify interceptors ActionRequestDetails requestDetails = new ActionRequestDetails(null, null); notifyInterceptors(RestOperationTypeEnum.META, requestDetails); @@ -207,13 +211,13 @@ public class FhirSystemDaoDstu21 extends BaseHapiFhirSystemDao { TypedQuery q = myEntityManager.createQuery(sql, TagDefinition.class); List tagDefinitions = q.getResultList(); - MetaDt retVal = toMetaDt(tagDefinitions); + Meta retVal = toMeta(tagDefinitions); return retVal; } - protected MetaDt toMetaDt(Collection tagDefinitions) { - MetaDt retVal = new MetaDt(); + protected Meta toMeta(Collection tagDefinitions) { + Meta retVal = new Meta(); for (TagDefinition next : tagDefinitions) { switch (next.getTagType()) { case PROFILE: @@ -268,18 +272,18 @@ public class FhirSystemDaoDstu21 extends BaseHapiFhirSystemDao { @SuppressWarnings("unchecked") private Bundle transaction(ServletRequestDetails theRequestDetails, Bundle theRequest, String theActionName) { - BundleTypeEnum transactionType = theRequest.getTypeElement().getValueAsEnum(); - if (transactionType == BundleTypeEnum.BATCH) { + BundleType transactionType = theRequest.getTypeElement().getValue(); + if (transactionType == BundleType.BATCH) { return batch(theRequestDetails, theRequest); } if (transactionType == null) { - String message = "Transactiion Bundle did not specify valid Bundle.type, assuming " + BundleTypeEnum.TRANSACTION.getCode(); + String message = "Transactiion Bundle did not specify valid Bundle.type, assuming " + BundleType.TRANSACTION.toCode(); ourLog.warn(message); - transactionType = BundleTypeEnum.TRANSACTION; + transactionType = BundleType.TRANSACTION; } - if (transactionType != BundleTypeEnum.TRANSACTION) { - throw new InvalidRequestException("Unable to process transaction where incoming Bundle.type = " + transactionType.getCode()); + if (transactionType != BundleType.TRANSACTION) { + throw new InvalidRequestException("Unable to process transaction where incoming Bundle.type = " + transactionType.toCode()); } ourLog.info("Beginning {} with {} resources", theActionName, theRequest.getEntry().size()); @@ -287,9 +291,9 @@ public class FhirSystemDaoDstu21 extends BaseHapiFhirSystemDao { long start = System.currentTimeMillis(); Date updateTime = new Date(); - Set allIds = new LinkedHashSet(); - Map idSubstitutions = new HashMap(); - Map idToPersistedOutcome = new HashMap(); + Set allIds = new LinkedHashSet(); + Map idSubstitutions = new HashMap(); + Map idToPersistedOutcome = new HashMap(); /* * We want to execute the transaction request bundle elements in the order @@ -302,12 +306,12 @@ public class FhirSystemDaoDstu21 extends BaseHapiFhirSystemDao { * we want the GET processing to use the final indexing state */ Bundle response = new Bundle(); - List getEntries = new ArrayList(); - IdentityHashMap originalRequestOrder = new IdentityHashMap(); + List getEntries = new ArrayList(); + IdentityHashMap originalRequestOrder = new IdentityHashMap(); for (int i = 0; i < theRequest.getEntry().size(); i++) { originalRequestOrder.put(theRequest.getEntry().get(i), i); response.addEntry(); - if (theRequest.getEntry().get(i).getRequest().getMethodElement().getValueAsEnum() == HTTPVerbEnum.GET) { + if (theRequest.getEntry().get(i).getRequest().getMethodElement().getValue() == HTTPVerb.GET) { getEntries.add(theRequest.getEntry().get(i)); } } @@ -326,16 +330,16 @@ public class FhirSystemDaoDstu21 extends BaseHapiFhirSystemDao { ourLog.info("Processed {} non-GET entries out of {}", i, theRequest.getEntry().size()); } - Entry nextReqEntry = theRequest.getEntry().get(i); - IResource res = nextReqEntry.getResource(); - IdDt nextResourceId = null; + BundleEntryComponent nextReqEntry = theRequest.getEntry().get(i); + Resource res = nextReqEntry.getResource(); + IdType nextResourceId = null; if (res != null) { - nextResourceId = res.getId(); + nextResourceId = res.getIdElement(); if (nextResourceId.hasIdPart() == false) { if (isNotBlank(nextReqEntry.getFullUrl())) { - nextResourceId = new IdDt(nextReqEntry.getFullUrl()); + nextResourceId = new IdType(nextReqEntry.getFullUrl()); } } @@ -344,7 +348,7 @@ public class FhirSystemDaoDstu21 extends BaseHapiFhirSystemDao { } if (nextResourceId.hasIdPart() && !nextResourceId.hasResourceType() && !isPlaceholder(nextResourceId)) { - nextResourceId = new IdDt(toResourceName(res.getClass()), nextResourceId.getIdPart()); + nextResourceId = new IdType(toResourceName(res.getClass()), nextResourceId.getIdPart()); res.setId(nextResourceId); } @@ -356,7 +360,7 @@ public class FhirSystemDaoDstu21 extends BaseHapiFhirSystemDao { throw new InvalidRequestException(getContext().getLocalizer().getMessage(BaseHapiFhirSystemDao.class, "transactionContainsMultipleWithDuplicateId", nextResourceId)); } } else if (nextResourceId.hasResourceType() && nextResourceId.hasIdPart()) { - IdDt nextId = nextResourceId.toUnqualifiedVersionless(); + IdType nextId = nextResourceId.toUnqualifiedVersionless(); if (!allIds.add(nextId)) { throw new InvalidRequestException(getContext().getLocalizer().getMessage(BaseHapiFhirSystemDao.class, "transactionContainsMultipleWithDuplicateId", nextId)); } @@ -364,13 +368,13 @@ public class FhirSystemDaoDstu21 extends BaseHapiFhirSystemDao { } - HTTPVerbEnum verb = nextReqEntry.getRequest().getMethodElement().getValueAsEnum(); + HTTPVerb verb = nextReqEntry.getRequest().getMethodElement().getValue(); if (verb == null) { throw new InvalidRequestException(getContext().getLocalizer().getMessage(BaseHapiFhirSystemDao.class, "transactionEntryHasInvalidVerb", nextReqEntry.getRequest().getMethod())); } String resourceType = res != null ? getContext().getResourceDefinition(res).getName() : null; - Entry nextRespEntry = response.getEntry().get(originalRequestOrder.get(nextReqEntry)); + BundleEntryComponent nextRespEntry = response.getEntry().get(originalRequestOrder.get(nextReqEntry)); switch (verb) { case POST: { @@ -387,10 +391,10 @@ public class FhirSystemDaoDstu21 extends BaseHapiFhirSystemDao { // DELETE String url = extractTransactionUrlOrThrowException(nextReqEntry, verb); UrlParts parts = UrlUtil.parseUrl(url); - ca.uhn.fhir.jpa.dao.IFhirResourceDao dao = toDao(parts, verb.getCode(), url); + ca.uhn.fhir.jpa.dao.IFhirResourceDao dao = toDao(parts, verb.toCode(), url); int status = Constants.STATUS_HTTP_204_NO_CONTENT; if (parts.getResourceId() != null) { - ResourceTable deleted = dao.delete(new IdDt(parts.getResourceType(), parts.getResourceId()), deleteConflicts); + ResourceTable deleted = dao.delete(new IdType(parts.getResourceType(), parts.getResourceId()), deleteConflicts); if (deleted != null) { deletedResources.add(deleted.getIdDt().toUnqualifiedVersionless()); } @@ -418,7 +422,7 @@ public class FhirSystemDaoDstu21 extends BaseHapiFhirSystemDao { UrlParts parts = UrlUtil.parseUrl(url); if (isNotBlank(parts.getResourceId())) { - res.setId(new IdDt(parts.getResourceType(), parts.getResourceId())); + res.setId(new IdType(parts.getResourceType(), parts.getResourceId())); outcome = resourceDao.update(res, null, false); } else { res.setId((String) null); @@ -452,24 +456,24 @@ public class FhirSystemDaoDstu21 extends BaseHapiFhirSystemDao { FhirTerser terser = getContext().newTerser(); for (DaoMethodOutcome nextOutcome : idToPersistedOutcome.values()) { - IResource nextResource = (IResource) nextOutcome.getResource(); + IBaseResource nextResource = (IBaseResource) nextOutcome.getResource(); if (nextResource == null) { continue; } - List allRefs = terser.getAllPopulatedChildElementsOfType(nextResource, BaseResourceReferenceDt.class); - for (BaseResourceReferenceDt nextRef : allRefs) { - IdDt nextId = nextRef.getReference(); + List allRefs = terser.getAllPopulatedChildElementsOfType(nextResource, IBaseReference.class); + for (IBaseReference nextRef : allRefs) { + IIdType nextId = nextRef.getReferenceElement(); if (idSubstitutions.containsKey(nextId)) { - IdDt newId = idSubstitutions.get(nextId); + IdType newId = idSubstitutions.get(nextId); ourLog.info(" * Replacing resource ref {} with {}", nextId, newId); - nextRef.setReference(newId); + nextRef.setReference(newId.getValue()); } else { ourLog.debug(" * Reference [{}] does not exist in bundle", nextId); } } - InstantDt deletedInstantOrNull = ResourceMetadataKeyEnum.DELETED_AT.get(nextResource); + IPrimitiveType deletedInstantOrNull = ResourceMetadataKeyEnum.DELETED_AT.get((IAnyResource) nextResource); Date deletedTimestampOrNull = deletedInstantOrNull != null ? deletedInstantOrNull.getValue() : null; updateEntity(nextResource, nextOutcome.getEntity(), false, deletedTimestampOrNull, true, false, updateTime); } @@ -479,8 +483,8 @@ public class FhirSystemDaoDstu21 extends BaseHapiFhirSystemDao { /* * Double check we didn't allow any duplicates we shouldn't have */ - for (Entry nextEntry : theRequest.getEntry()) { - if (nextEntry.getRequest().getMethodElement().getValueAsEnum() == HTTPVerbEnum.POST) { + for (BundleEntryComponent nextEntry : theRequest.getEntry()) { + if (nextEntry.getRequest().getMethodElement().getValue() == HTTPVerb.POST) { String matchUrl = nextEntry.getRequest().getIfNoneExist(); if (isNotBlank(matchUrl)) { IFhirResourceDao resourceDao = getDao(nextEntry.getResource().getClass()); @@ -493,8 +497,8 @@ public class FhirSystemDaoDstu21 extends BaseHapiFhirSystemDao { } } - for (IdDt next : allIds) { - IdDt replacement = idSubstitutions.get(next); + for (IdType next : allIds) { + IdType replacement = idSubstitutions.get(next); if (replacement == null) { continue; } @@ -508,16 +512,16 @@ public class FhirSystemDaoDstu21 extends BaseHapiFhirSystemDao { * Loop through the request and process any entries of type GET */ for (int i = 0; i < getEntries.size(); i++) { - Entry nextReqEntry = getEntries.get(i); + BundleEntryComponent nextReqEntry = getEntries.get(i); Integer originalOrder = originalRequestOrder.get(nextReqEntry); - Entry nextRespEntry = response.getEntry().get(originalOrder); + BundleEntryComponent nextRespEntry = response.getEntry().get(originalOrder); ServletSubRequestDetails requestDetails = new ServletSubRequestDetails(); requestDetails.setServletRequest(theRequestDetails.getServletRequest()); requestDetails.setRequestType(RequestTypeEnum.GET); requestDetails.setServer(theRequestDetails.getServer()); - String url = extractTransactionUrlOrThrowException(nextReqEntry, HTTPVerbEnum.GET); + String url = extractTransactionUrlOrThrowException(nextReqEntry, HTTPVerb.GET); int qIndex = url.indexOf('?'); ArrayListMultimap paramValues = ArrayListMultimap.create(); @@ -561,7 +565,7 @@ public class FhirSystemDaoDstu21 extends BaseHapiFhirSystemDao { if (paramValues.containsKey(Constants.PARAM_SUMMARY) || paramValues.containsKey(Constants.PARAM_CONTENT)) { resource = filterNestedBundle(requestDetails, resource); } - nextRespEntry.setResource((IResource) resource); + nextRespEntry.setResource((Resource) resource); nextRespEntry.getResponse().setStatus(toStatusString(Constants.STATUS_HTTP_200_OK)); } catch (NotModifiedException e) { nextRespEntry.getResponse().setStatus(toStatusString(Constants.STATUS_HTTP_304_NOT_MODIFIED)); @@ -575,21 +579,21 @@ public class FhirSystemDaoDstu21 extends BaseHapiFhirSystemDao { long delay = System.currentTimeMillis() - start; ourLog.info(theActionName + " completed in {}ms", new Object[] { delay }); - response.setType(BundleTypeEnum.TRANSACTION_RESPONSE); + response.setType(BundleType.TRANSACTIONRESPONSE); return response; } - private static void handleTransactionCreateOrUpdateOutcome(Map idSubstitutions, Map idToPersistedOutcome, IdDt nextResourceId, DaoMethodOutcome outcome, - Entry newEntry, String theResourceType, IResource theRes) { - IdDt newId = (IdDt) outcome.getId().toUnqualifiedVersionless(); - IdDt resourceId = isPlaceholder(nextResourceId) ? nextResourceId : nextResourceId.toUnqualifiedVersionless(); + private static void handleTransactionCreateOrUpdateOutcome(Map idSubstitutions, Map idToPersistedOutcome, IdType nextResourceId, DaoMethodOutcome outcome, + BundleEntryComponent newEntry, String theResourceType, IBaseResource theRes) { + IdType newId = (IdType) outcome.getId().toUnqualifiedVersionless(); + IdType resourceId = isPlaceholder(nextResourceId) ? nextResourceId : nextResourceId.toUnqualifiedVersionless(); if (newId.equals(resourceId) == false) { idSubstitutions.put(resourceId, newId); if (isPlaceholder(resourceId)) { /* * The correct way for substitution IDs to be is to be with no resource type, but we'll accept the qualified kind too just to be lenient. */ - idSubstitutions.put(new IdDt(theResourceType + '/' + resourceId.getValue()), newId); + idSubstitutions.put(new IdType(theResourceType + '/' + resourceId.getValue()), newId); } } idToPersistedOutcome.put(newId, outcome); @@ -600,10 +604,10 @@ public class FhirSystemDaoDstu21 extends BaseHapiFhirSystemDao { } newEntry.getResponse().setLocation(outcome.getId().toUnqualified().getValue()); newEntry.getResponse().setEtag(outcome.getId().getVersionIdPart()); - newEntry.getResponse().setLastModified(ResourceMetadataKeyEnum.UPDATED.get(theRes)); + newEntry.getResponse().setLastModified(((Resource)theRes).getMeta().getLastUpdated()); } - private static boolean isPlaceholder(IdDt theId) { + private static boolean isPlaceholder(IdType theId) { if ("urn:oid:".equals(theId.getBaseUrl()) || "urn:uuid:".equals(theId.getBaseUrl())) { return true; } @@ -624,20 +628,20 @@ public class FhirSystemDaoDstu21 extends BaseHapiFhirSystemDao { * Process any GET interactions */ //@formatter:off - public class TransactionSorter implements Comparator { + public class TransactionSorter implements Comparator { @Override - public int compare(Entry theO1, Entry theO2) { + public int compare(BundleEntryComponent theO1, BundleEntryComponent theO2) { int o1 = toOrder(theO1); int o2 = toOrder(theO2); return o1 - o2; } - private int toOrder(Entry theO1) { + private int toOrder(BundleEntryComponent theO1) { int o1 = 0; - if (theO1.getRequest().getMethodElement().getValueAsEnum() != null) { - switch (theO1.getRequest().getMethodElement().getValueAsEnum()) { + if (theO1.getRequest().getMethodElement().getValue() != null) { + switch (theO1.getRequest().getMethodElement().getValue()) { case DELETE: o1 = 1; break; @@ -650,6 +654,9 @@ public class FhirSystemDaoDstu21 extends BaseHapiFhirSystemDao { case GET: o1 = 4; break; + case NULL: + o1 = 0; + break; } } return o1; diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/IDao.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/IDao.java index 37138dbe796..247d1cb0754 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/IDao.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/IDao.java @@ -1,7 +1,12 @@ package ca.uhn.fhir.jpa.dao; +import org.hl7.fhir.instance.model.api.IAnyResource; +import org.hl7.fhir.instance.model.api.IBaseResource; + +import ca.uhn.fhir.jpa.entity.BaseHasResource; import ca.uhn.fhir.model.api.IResource; import ca.uhn.fhir.model.api.ResourceMetadataKeyEnum; +import ca.uhn.fhir.model.api.ResourceMetadataKeyEnum.ResourceMetadataKeySupportingAnyResource; /* * #%L @@ -25,7 +30,7 @@ import ca.uhn.fhir.model.api.ResourceMetadataKeyEnum; public interface IDao { - public static final ResourceMetadataKeyEnum RESOURCE_PID = new ResourceMetadataKeyEnum("RESOURCE_PID") { + public static final ResourceMetadataKeySupportingAnyResource RESOURCE_PID = new ResourceMetadataKeySupportingAnyResource("RESOURCE_PID") { private static final long serialVersionUID = 1L; @@ -38,7 +43,21 @@ public interface IDao { public void put(IResource theResource, Long theObject) { theResource.getResourceMetadata().put(RESOURCE_PID, theObject); } + + @Override + public Long get(IAnyResource theResource) { + return (Long) theResource.getUserData(RESOURCE_PID.name()); + } + + @Override + public void put(IAnyResource theResource, Long theObject) { + theResource.setUserData(RESOURCE_PID.name(), theObject); + } }; + IBaseResource toResource(BaseHasResource theEntity, boolean theForHistoryOperation); + + R toResource(Class theResourceType, BaseHasResource theEntity, boolean theForHistoryOperation); + } diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/IFhirResourceDaoEncounter.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/IFhirResourceDaoEncounter.java index 176d1069b14..13de6db47c1 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/IFhirResourceDaoEncounter.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/IFhirResourceDaoEncounter.java @@ -23,17 +23,17 @@ import javax.servlet.http.HttpServletRequest; */ import org.hl7.fhir.instance.model.api.IBaseResource; +import org.hl7.fhir.instance.model.api.IIdType; +import org.hl7.fhir.instance.model.api.IPrimitiveType; -import ca.uhn.fhir.model.primitive.IdDt; -import ca.uhn.fhir.model.primitive.UnsignedIntDt; import ca.uhn.fhir.rest.api.SortSpec; import ca.uhn.fhir.rest.param.DateRangeParam; import ca.uhn.fhir.rest.server.IBundleProvider; public interface IFhirResourceDaoEncounter extends IFhirResourceDao { - IBundleProvider encounterInstanceEverything(HttpServletRequest theServletRequest, IdDt theId, UnsignedIntDt theCount, DateRangeParam theLastUpdate, SortSpec theSort); + IBundleProvider encounterInstanceEverything(HttpServletRequest theServletRequest, IIdType theId, IPrimitiveType theCount, DateRangeParam theLastUpdate, SortSpec theSort); - IBundleProvider encounterTypeEverything(HttpServletRequest theServletRequest, UnsignedIntDt theCount, DateRangeParam theLastUpdated, SortSpec theSortSpec); + IBundleProvider encounterTypeEverything(HttpServletRequest theServletRequest, IPrimitiveType theCount, DateRangeParam theLastUpdated, SortSpec theSortSpec); } diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/IFhirResourceDaoPatient.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/IFhirResourceDaoPatient.java index a34d56d2251..0b2afb59556 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/IFhirResourceDaoPatient.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/IFhirResourceDaoPatient.java @@ -24,8 +24,8 @@ import javax.servlet.http.HttpServletRequest; import org.hl7.fhir.instance.model.api.IBaseResource; import org.hl7.fhir.instance.model.api.IIdType; +import org.hl7.fhir.instance.model.api.IPrimitiveType; -import ca.uhn.fhir.model.primitive.UnsignedIntDt; import ca.uhn.fhir.rest.api.SortSpec; import ca.uhn.fhir.rest.param.DateRangeParam; import ca.uhn.fhir.rest.param.StringAndListParam; @@ -33,8 +33,8 @@ import ca.uhn.fhir.rest.server.IBundleProvider; public interface IFhirResourceDaoPatient extends IFhirResourceDao { - IBundleProvider patientInstanceEverything(HttpServletRequest theServletRequest, IIdType theId, UnsignedIntDt theCount, DateRangeParam theLastUpdate, SortSpec theSort, StringAndListParam theContent, StringAndListParam theNarrative); + IBundleProvider patientInstanceEverything(HttpServletRequest theServletRequest, IIdType theId, IPrimitiveType theCount, DateRangeParam theLastUpdate, SortSpec theSort, StringAndListParam theContent, StringAndListParam theNarrative); - IBundleProvider patientTypeEverything(HttpServletRequest theServletRequest, UnsignedIntDt theCount, DateRangeParam theLastUpdated, SortSpec theSortSpec, StringAndListParam theContent, StringAndListParam theNarrative); + IBundleProvider patientTypeEverything(HttpServletRequest theServletRequest, IPrimitiveType theCount, DateRangeParam theLastUpdated, SortSpec theSortSpec, StringAndListParam theContent, StringAndListParam theNarrative); } diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/IFhirResourceDaoValueSet.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/IFhirResourceDaoValueSet.java index fc393e3c5b8..7b57c75f1ad 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/IFhirResourceDaoValueSet.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/IFhirResourceDaoValueSet.java @@ -22,10 +22,7 @@ package ca.uhn.fhir.jpa.dao; import org.hl7.fhir.instance.model.api.IBaseResource; import org.hl7.fhir.instance.model.api.IIdType; - -import ca.uhn.fhir.model.primitive.CodeDt; -import ca.uhn.fhir.model.primitive.StringDt; -import ca.uhn.fhir.model.primitive.UriDt; +import org.hl7.fhir.instance.model.api.IPrimitiveType; public interface IFhirResourceDaoValueSet extends IFhirResourceDao { @@ -35,9 +32,9 @@ public interface IFhirResourceDaoValueSet exten T expandByIdentifier(String theUri, String theFilter); - LookupCodeResult lookupCode(CodeDt theCode, UriDt theSystem, CD theCoding); + LookupCodeResult lookupCode(IPrimitiveType theCode, IPrimitiveType theSystem, CD theCoding); - ValidateCodeResult validateCode(UriDt theValueSetIdentifier, IIdType theId, CodeDt theCode, UriDt theSystem, StringDt theDisplay, CD theCoding, CC theCodeableConcept); + ValidateCodeResult validateCode(IPrimitiveType theValueSetIdentifier, IIdType theId, IPrimitiveType theCode, IPrimitiveType theSystem, IPrimitiveType theDisplay, CD theCoding, CC theCodeableConcept); public class LookupCodeResult { private String myCodeDisplay; diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/IJpaValidationSupport.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/IJpaValidationSupportDstu2.java similarity index 91% rename from hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/IJpaValidationSupport.java rename to hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/IJpaValidationSupportDstu2.java index f22b5a66f63..3dc7d56fca8 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/IJpaValidationSupport.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/IJpaValidationSupportDstu2.java @@ -22,6 +22,6 @@ package ca.uhn.fhir.jpa.dao; import ca.uhn.fhir.validation.IValidationSupport; -public interface IJpaValidationSupport extends IValidationSupport { +public interface IJpaValidationSupportDstu2 extends IValidationSupport { } diff --git a/hapi-fhir-structures-dstu2.1/src/main/java/ca/uhn/fhir/model/dstu21/composite/MoneyDt.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/IJpaValidationSupportDstu21.java similarity index 68% rename from hapi-fhir-structures-dstu2.1/src/main/java/ca/uhn/fhir/model/dstu21/composite/MoneyDt.java rename to hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/IJpaValidationSupportDstu21.java index 0fbd046dfef..d0b24f2add2 100644 --- a/hapi-fhir-structures-dstu2.1/src/main/java/ca/uhn/fhir/model/dstu21/composite/MoneyDt.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/IJpaValidationSupportDstu21.java @@ -1,11 +1,10 @@ -package ca.uhn.fhir.model.dstu21.composite; +package ca.uhn.fhir.jpa.dao; -import ca.uhn.fhir.model.api.annotation.DatatypeDef; -import ca.uhn.fhir.model.dstu21.composite.QuantityDt; +import org.hl7.fhir.dstu21.hapi.validation.IValidationSupport; /* * #%L - * HAPI FHIR Structures - DSTU2 (FHIR v1.0.0) + * HAPI FHIR JPA Server * %% * Copyright (C) 2014 - 2015 University Health Network * %% @@ -23,7 +22,6 @@ import ca.uhn.fhir.model.dstu21.composite.QuantityDt; * #L% */ -@DatatypeDef(name="Money", profileOf=QuantityDt.class) -public class MoneyDt extends QuantityDt { +public interface IJpaValidationSupportDstu21 extends IValidationSupport { } diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/ISearchParamExtractor.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/ISearchParamExtractor.java index d72390b6ab8..04dcaccf95a 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/ISearchParamExtractor.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/ISearchParamExtractor.java @@ -22,6 +22,8 @@ package ca.uhn.fhir.jpa.dao; import java.util.Set; +import org.hl7.fhir.instance.model.api.IBaseResource; + import ca.uhn.fhir.jpa.entity.BaseResourceIndexedSearchParam; import ca.uhn.fhir.jpa.entity.ResourceIndexedSearchParamCoords; import ca.uhn.fhir.jpa.entity.ResourceIndexedSearchParamDate; @@ -30,22 +32,21 @@ import ca.uhn.fhir.jpa.entity.ResourceIndexedSearchParamQuantity; import ca.uhn.fhir.jpa.entity.ResourceIndexedSearchParamString; import ca.uhn.fhir.jpa.entity.ResourceIndexedSearchParamUri; import ca.uhn.fhir.jpa.entity.ResourceTable; -import ca.uhn.fhir.model.api.IResource; interface ISearchParamExtractor { - public abstract Set extractSearchParamCoords(ResourceTable theEntity, IResource theResource); + public abstract Set extractSearchParamCoords(ResourceTable theEntity, IBaseResource theResource); - public abstract Set extractSearchParamDates(ResourceTable theEntity, IResource theResource); + public abstract Set extractSearchParamDates(ResourceTable theEntity, IBaseResource theResource); - public abstract Set extractSearchParamNumber(ResourceTable theEntity, IResource theResource); + public abstract Set extractSearchParamNumber(ResourceTable theEntity, IBaseResource theResource); - public abstract Set extractSearchParamQuantity(ResourceTable theEntity, IResource theResource); + public abstract Set extractSearchParamQuantity(ResourceTable theEntity, IBaseResource theResource); - public abstract Set extractSearchParamStrings(ResourceTable theEntity, IResource theResource); + public abstract Set extractSearchParamStrings(ResourceTable theEntity, IBaseResource theResource); - public abstract Set extractSearchParamTokens(ResourceTable theEntity, IResource theResource); + public abstract Set extractSearchParamTokens(ResourceTable theEntity, IBaseResource theResource); - public abstract Set extractSearchParamUri(ResourceTable theEntity, IResource theResource); + public abstract Set extractSearchParamUri(ResourceTable theEntity, IBaseResource theResource); } diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/JpaValidationSupportDstu2.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/JpaValidationSupportDstu2.java index 5a10218a7fc..09b4b02bcba 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/JpaValidationSupportDstu2.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/JpaValidationSupportDstu2.java @@ -31,7 +31,7 @@ import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.rest.param.UriParam; import ca.uhn.fhir.rest.server.IBundleProvider; -public class JpaValidationSupportDstu2 implements IJpaValidationSupport { +public class JpaValidationSupportDstu2 implements IJpaValidationSupportDstu2 { private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(JpaValidationSupportDstu2.class); diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/JpaValidationSupportDstu21.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/JpaValidationSupportDstu21.java index 06cf30afdd6..65fdfb27ae2 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/JpaValidationSupportDstu21.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/JpaValidationSupportDstu21.java @@ -1,5 +1,10 @@ package ca.uhn.fhir.jpa.dao; +import org.hl7.fhir.dstu21.model.StructureDefinition; +import org.hl7.fhir.dstu21.model.ValueSet; +import org.hl7.fhir.dstu21.model.ValueSet.ConceptSetComponent; +import org.hl7.fhir.dstu21.model.ValueSet.ValueSetExpansionComponent; + /* * #%L * HAPI FHIR JPA Server @@ -20,9 +25,6 @@ package ca.uhn.fhir.jpa.dao; * #L% */ -import org.hl7.fhir.instance.model.ValueSet; -import org.hl7.fhir.instance.model.ValueSet.ConceptSetComponent; -import org.hl7.fhir.instance.model.ValueSet.ValueSetExpansionComponent; import org.hl7.fhir.instance.model.api.IBaseResource; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; @@ -31,7 +33,7 @@ import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.rest.param.UriParam; import ca.uhn.fhir.rest.server.IBundleProvider; -public class JpaValidationSupportDstu21 implements IJpaValidationSupport { +public class JpaValidationSupportDstu21 implements IJpaValidationSupportDstu21 { private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(JpaValidationSupportDstu21.class); @@ -41,11 +43,11 @@ public class JpaValidationSupportDstu21 implements IJpaValidationSupport { @Autowired @Qualifier("myStructureDefinitionDaoDstu21") - private IFhirResourceDao myStructureDefinitionDao; + private IFhirResourceDao myStructureDefinitionDao; @Autowired @Qualifier("myValueSetDaoDstu21") - private IFhirResourceDao myValueSetDao; + private IFhirResourceDao myValueSetDao; @Autowired @Qualifier("myFhirContextDstu21") diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/SearchBuilder.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/SearchBuilder.java index baacd661955..419de4493a8 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/SearchBuilder.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/SearchBuilder.java @@ -1,5 +1,7 @@ package ca.uhn.fhir.jpa.dao; +import static org.apache.commons.lang3.StringUtils.defaultString; + /* * #%L * HAPI FHIR JPA Server @@ -53,6 +55,7 @@ import javax.persistence.criteria.Root; import javax.persistence.criteria.Subquery; import org.apache.commons.lang3.StringUtils; +import org.hl7.fhir.instance.model.api.IAnyResource; import org.hl7.fhir.instance.model.api.IBaseResource; import org.hl7.fhir.instance.model.api.IIdType; import org.springframework.transaction.PlatformTransactionManager; @@ -1300,17 +1303,25 @@ public class SearchBuilder { for (ResourceTable next : q.getResultList()) { Class resourceType = myContext.getResourceDefinition(next.getResourceType()).getImplementingClass(); - IResource resource = (IResource) myCallingDao.toResource(resourceType, next, theForHistoryOperation); + IBaseResource resource = (IBaseResource) myCallingDao.toResource(resourceType, next, theForHistoryOperation); Integer index = position.get(next.getId()); if (index == null) { ourLog.warn("Got back unexpected resource PID {}", next.getId()); continue; } - if (theRevIncludedPids.contains(next.getId())) { - ResourceMetadataKeyEnum.ENTRY_SEARCH_MODE.put(resource, BundleEntrySearchModeEnum.INCLUDE); + if (resource instanceof IResource) { + if (theRevIncludedPids.contains(next.getId())) { + ResourceMetadataKeyEnum.ENTRY_SEARCH_MODE.put((IResource)resource, BundleEntrySearchModeEnum.INCLUDE); + } else { + ResourceMetadataKeyEnum.ENTRY_SEARCH_MODE.put((IResource)resource, BundleEntrySearchModeEnum.MATCH); + } } else { - ResourceMetadataKeyEnum.ENTRY_SEARCH_MODE.put(resource, BundleEntrySearchModeEnum.MATCH); + if (theRevIncludedPids.contains(next.getId())) { + ResourceMetadataKeyEnum.ENTRY_SEARCH_MODE.put((IAnyResource)resource, BundleEntrySearchModeEnum.INCLUDE.getCode()); + } else { + ResourceMetadataKeyEnum.ENTRY_SEARCH_MODE.put((IAnyResource)resource, BundleEntrySearchModeEnum.MATCH.getCode()); + } } theResourceListToPopulate.set(index, resource); @@ -1322,7 +1333,7 @@ public class SearchBuilder { * * @param theLastUpdated */ - private HashSet loadReverseIncludes(Collection theMatches, Set theRevIncludes, boolean theReverseMode, EverythingModeEnum theEverythingModeEnum, DateRangeParam theLastUpdated) { + private HashSet loadReverseIncludes(Collection theMatches, Set theRevIncludes, boolean theReverseMode, DateRangeParam theLastUpdated) { if (theMatches.size() == 0) { return new HashSet(); } @@ -1378,19 +1389,18 @@ public class SearchBuilder { if (myContext.getVersion().getVersion() == FhirVersionEnum.DSTU1) { paths = Collections.singletonList(nextInclude.getValue()); } else { - int colonIdx = nextInclude.getValue().indexOf(':'); - if (colonIdx < 2) { + String resType = nextInclude.getParamType(); + if (isBlank(resType)) { continue; } - String resType = nextInclude.getValue().substring(0, colonIdx); RuntimeResourceDefinition def = myContext.getResourceDefinition(resType); if (def == null) { ourLog.warn("Unknown resource type in include/revinclude=" + nextInclude.getValue()); continue; } - String paramName = nextInclude.getValue().substring(colonIdx + 1); - RuntimeSearchParam param = def.getSearchParam(paramName); + String paramName = nextInclude.getParamName(); + RuntimeSearchParam param = isNotBlank(paramName) ? def.getSearchParam(paramName) : null; if (param == null) { ourLog.warn("Unknown param name in include/revinclude=" + nextInclude.getValue()); continue; @@ -1399,11 +1409,20 @@ public class SearchBuilder { paths = param.getPathsSplit(); } + String targetResourceType = defaultString(nextInclude.getParamTargetType(), null); for (String nextPath : paths) { - String sql = "SELECT r FROM ResourceLink r WHERE r.mySourcePath = :src_path AND r." + searchFieldName + " IN (:target_pids)"; + String sql; + if (targetResourceType != null) { + sql = "SELECT r FROM ResourceLink r WHERE r.mySourcePath = :src_path AND r." + searchFieldName + " IN (:target_pids) AND r.myTargetResourceType = :target_resource_type"; + } else { + sql = "SELECT r FROM ResourceLink r WHERE r.mySourcePath = :src_path AND r." + searchFieldName + " IN (:target_pids)"; + } TypedQuery q = myEntityManager.createQuery(sql, ResourceLink.class); q.setParameter("src_path", nextPath); q.setParameter("target_pids", nextRoundMatches); + if (targetResourceType != null) { + q.setParameter("target_resource_type", targetResourceType); + } List results = q.getResultList(); for (ResourceLink resourceLink : results) { if (theReverseMode) { @@ -1595,7 +1614,7 @@ public class SearchBuilder { final Set revIncludedPids; if (theParams.getEverythingMode() == null) { if (theParams.getRevIncludes() != null && theParams.getRevIncludes().isEmpty() == false) { - revIncludedPids = loadReverseIncludes(pids, theParams.getRevIncludes(), true, null, lu); + revIncludedPids = loadReverseIncludes(pids, theParams.getRevIncludes(), true, lu); } else { revIncludedPids = new HashSet(); } @@ -1623,7 +1642,7 @@ public class SearchBuilder { // Load includes pidsSubList = new ArrayList(pidsSubList); - revIncludedPids.addAll(loadReverseIncludes(pidsSubList, theParams.getIncludes(), false, null, theParams.getLastUpdated())); + revIncludedPids.addAll(loadReverseIncludes(pidsSubList, theParams.getIncludes(), false, theParams.getLastUpdated())); // Execute the query and make sure we return distinct results List resources = new ArrayList(); diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/SearchParamExtractorDstu1.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/SearchParamExtractorDstu1.java index ceff8c5756c..83b89bf0159 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/SearchParamExtractorDstu1.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/SearchParamExtractorDstu1.java @@ -35,6 +35,7 @@ import javax.measure.unit.NonSI; import javax.measure.unit.Unit; import org.apache.commons.lang3.tuple.Pair; +import org.hl7.fhir.instance.model.api.IBaseResource; import ca.uhn.fhir.context.ConfigurationException; import ca.uhn.fhir.context.FhirContext; @@ -51,7 +52,6 @@ import ca.uhn.fhir.jpa.entity.ResourceIndexedSearchParamUri; import ca.uhn.fhir.jpa.entity.ResourceTable; import ca.uhn.fhir.model.api.IDatatype; import ca.uhn.fhir.model.api.IPrimitiveDatatype; -import ca.uhn.fhir.model.api.IResource; import ca.uhn.fhir.model.base.composite.BaseHumanNameDt; import ca.uhn.fhir.model.dstu.composite.AddressDt; import ca.uhn.fhir.model.dstu.composite.CodeableConceptDt; @@ -75,12 +75,12 @@ public class SearchParamExtractorDstu1 extends BaseSearchParamExtractor implemen } @Override - public Set extractSearchParamCoords(ResourceTable theEntity, IResource theResource) { + public Set extractSearchParamCoords(ResourceTable theEntity, IBaseResource theResource) { return Collections.emptySet(); } @Override - public Set extractSearchParamDates(ResourceTable theEntity, IResource theResource) { + public Set extractSearchParamDates(ResourceTable theEntity, IBaseResource theResource) { HashSet retVal = new HashSet(); RuntimeResourceDefinition def = getContext().getResourceDefinition(theResource); @@ -135,7 +135,7 @@ public class SearchParamExtractorDstu1 extends BaseSearchParamExtractor implemen } @Override - public HashSet extractSearchParamNumber(ResourceTable theEntity, IResource theResource) { + public HashSet extractSearchParamNumber(ResourceTable theEntity, IBaseResource theResource) { HashSet retVal = new HashSet(); RuntimeResourceDefinition def = getContext().getResourceDefinition(theResource); @@ -230,7 +230,7 @@ public class SearchParamExtractorDstu1 extends BaseSearchParamExtractor implemen } @Override - public Set extractSearchParamQuantity(ResourceTable theEntity, IResource theResource) { + public Set extractSearchParamQuantity(ResourceTable theEntity, IBaseResource theResource) { HashSet retVal = new HashSet(); RuntimeResourceDefinition def = getContext().getResourceDefinition(theResource); @@ -278,7 +278,7 @@ public class SearchParamExtractorDstu1 extends BaseSearchParamExtractor implemen } @Override - public Set extractSearchParamStrings(ResourceTable theEntity, IResource theResource) { + public Set extractSearchParamStrings(ResourceTable theEntity, IBaseResource theResource) { HashSet retVal = new HashSet(); RuntimeResourceDefinition def = getContext().getResourceDefinition(theResource); @@ -364,7 +364,7 @@ public class SearchParamExtractorDstu1 extends BaseSearchParamExtractor implemen } @Override - public Set extractSearchParamTokens(ResourceTable theEntity, IResource theResource) { + public Set extractSearchParamTokens(ResourceTable theEntity, IBaseResource theResource) { HashSet retVal = new HashSet(); RuntimeResourceDefinition def = getContext().getResourceDefinition(theResource); @@ -472,7 +472,7 @@ public class SearchParamExtractorDstu1 extends BaseSearchParamExtractor implemen } @Override - public Set extractSearchParamUri(ResourceTable theEntity, IResource theResource) { + public Set extractSearchParamUri(ResourceTable theEntity, IBaseResource theResource) { return Collections.emptySet(); } diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/SearchParamExtractorDstu2.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/SearchParamExtractorDstu2.java index 75175161ab4..9e81a657d19 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/SearchParamExtractorDstu2.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/SearchParamExtractorDstu2.java @@ -35,6 +35,7 @@ import javax.measure.unit.Unit; import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.tuple.Pair; +import org.hl7.fhir.instance.model.api.IBaseResource; import ca.uhn.fhir.context.ConfigurationException; import ca.uhn.fhir.context.FhirContext; @@ -51,7 +52,6 @@ import ca.uhn.fhir.jpa.entity.ResourceIndexedSearchParamUri; import ca.uhn.fhir.jpa.entity.ResourceTable; import ca.uhn.fhir.model.api.IDatatype; import ca.uhn.fhir.model.api.IPrimitiveDatatype; -import ca.uhn.fhir.model.api.IResource; import ca.uhn.fhir.model.api.IValueSetEnumBinder; import ca.uhn.fhir.model.base.composite.BaseHumanNameDt; import ca.uhn.fhir.model.dstu2.composite.AddressDt; @@ -109,7 +109,7 @@ public class SearchParamExtractorDstu2 extends BaseSearchParamExtractor implemen } @Override - public Set extractSearchParamCoords(ResourceTable theEntity, IResource theResource) { + public Set extractSearchParamCoords(ResourceTable theEntity, IBaseResource theResource) { // TODO: implement return Collections.emptySet(); } @@ -121,7 +121,7 @@ public class SearchParamExtractorDstu2 extends BaseSearchParamExtractor implemen * ca.uhn.fhir.model.api.IResource) */ @Override - public Set extractSearchParamDates(ResourceTable theEntity, IResource theResource) { + public Set extractSearchParamDates(ResourceTable theEntity, IBaseResource theResource) { HashSet retVal = new HashSet(); RuntimeResourceDefinition def = getContext().getResourceDefinition(theResource); @@ -182,7 +182,7 @@ public class SearchParamExtractorDstu2 extends BaseSearchParamExtractor implemen * ca.uhn.fhir.model.api.IResource) */ @Override - public HashSet extractSearchParamNumber(ResourceTable theEntity, IResource theResource) { + public HashSet extractSearchParamNumber(ResourceTable theEntity, IBaseResource theResource) { HashSet retVal = new HashSet(); RuntimeResourceDefinition def = getContext().getResourceDefinition(theResource); @@ -282,7 +282,7 @@ public class SearchParamExtractorDstu2 extends BaseSearchParamExtractor implemen * ca.uhn.fhir.model.api.IResource) */ @Override - public Set extractSearchParamQuantity(ResourceTable theEntity, IResource theResource) { + public Set extractSearchParamQuantity(ResourceTable theEntity, IBaseResource theResource) { HashSet retVal = new HashSet(); RuntimeResourceDefinition def = getContext().getResourceDefinition(theResource); @@ -336,7 +336,7 @@ public class SearchParamExtractorDstu2 extends BaseSearchParamExtractor implemen * ca.uhn.fhir.model.api.IResource) */ @Override - public Set extractSearchParamStrings(ResourceTable theEntity, IResource theResource) { + public Set extractSearchParamStrings(ResourceTable theEntity, IBaseResource theResource) { HashSet retVal = new HashSet(); RuntimeResourceDefinition def = getContext().getResourceDefinition(theResource); @@ -418,7 +418,7 @@ public class SearchParamExtractorDstu2 extends BaseSearchParamExtractor implemen * ca.uhn.fhir.model.api.IResource) */ @Override - public Set extractSearchParamTokens(ResourceTable theEntity, IResource theResource) { + public Set extractSearchParamTokens(ResourceTable theEntity, IBaseResource theResource) { HashSet retVal = new HashSet(); String useSystem = null; @@ -576,7 +576,7 @@ public class SearchParamExtractorDstu2 extends BaseSearchParamExtractor implemen } @Override - public Set extractSearchParamUri(ResourceTable theEntity, IResource theResource) { + public Set extractSearchParamUri(ResourceTable theEntity, IBaseResource theResource) { HashSet retVal = new HashSet(); RuntimeResourceDefinition def = getContext().getResourceDefinition(theResource); diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/SearchParamExtractorDstu21.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/SearchParamExtractorDstu21.java index ee283931738..3c99b5f3a9c 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/SearchParamExtractorDstu21.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/SearchParamExtractorDstu21.java @@ -29,12 +29,33 @@ import java.util.HashSet; import java.util.List; import java.util.Set; -import javax.measure.quantity.Quantity; import javax.measure.unit.NonSI; import javax.measure.unit.Unit; import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.tuple.Pair; +import org.hl7.fhir.dstu21.model.Address; +import org.hl7.fhir.dstu21.model.BaseDateTimeType; +import org.hl7.fhir.dstu21.model.CodeableConcept; +import org.hl7.fhir.dstu21.model.Coding; +import org.hl7.fhir.dstu21.model.Conformance.ConformanceRestSecurityComponent; +import org.hl7.fhir.dstu21.model.ContactPoint; +import org.hl7.fhir.dstu21.model.Duration; +import org.hl7.fhir.dstu21.model.Enumeration; +import org.hl7.fhir.dstu21.model.HumanName; +import org.hl7.fhir.dstu21.model.Identifier; +import org.hl7.fhir.dstu21.model.IntegerType; +import org.hl7.fhir.dstu21.model.Location.LocationPositionComponent; +import org.hl7.fhir.dstu21.model.Patient.PatientCommunicationComponent; +import org.hl7.fhir.dstu21.model.Period; +import org.hl7.fhir.dstu21.model.Quantity; +import org.hl7.fhir.dstu21.model.Questionnaire; +import org.hl7.fhir.dstu21.model.StringType; +import org.hl7.fhir.dstu21.model.UriType; +import org.hl7.fhir.dstu21.model.ValueSet; +import org.hl7.fhir.instance.model.api.IBase; +import org.hl7.fhir.instance.model.api.IBaseResource; +import org.hl7.fhir.instance.model.api.IPrimitiveType; import ca.uhn.fhir.context.ConfigurationException; import ca.uhn.fhir.context.FhirContext; @@ -49,33 +70,6 @@ import ca.uhn.fhir.jpa.entity.ResourceIndexedSearchParamString; import ca.uhn.fhir.jpa.entity.ResourceIndexedSearchParamToken; import ca.uhn.fhir.jpa.entity.ResourceIndexedSearchParamUri; import ca.uhn.fhir.jpa.entity.ResourceTable; -import ca.uhn.fhir.model.api.IDatatype; -import ca.uhn.fhir.model.api.IPrimitiveDatatype; -import ca.uhn.fhir.model.api.IResource; -import ca.uhn.fhir.model.api.IValueSetEnumBinder; -import ca.uhn.fhir.model.base.composite.BaseHumanNameDt; -import ca.uhn.fhir.model.dstu21.composite.AddressDt; -import ca.uhn.fhir.model.dstu21.composite.BoundCodeableConceptDt; -import ca.uhn.fhir.model.dstu21.composite.CodeableConceptDt; -import ca.uhn.fhir.model.dstu21.composite.CodingDt; -import ca.uhn.fhir.model.dstu21.composite.ContactPointDt; -import ca.uhn.fhir.model.dstu21.composite.DurationDt; -import ca.uhn.fhir.model.dstu21.composite.HumanNameDt; -import ca.uhn.fhir.model.dstu21.composite.IdentifierDt; -import ca.uhn.fhir.model.dstu21.composite.PeriodDt; -import ca.uhn.fhir.model.dstu21.composite.QuantityDt; -import ca.uhn.fhir.model.dstu21.resource.Conformance.RestSecurity; -import ca.uhn.fhir.model.dstu21.resource.Location; -import ca.uhn.fhir.model.dstu21.resource.Patient; -import ca.uhn.fhir.model.dstu21.resource.Patient.Communication; -import ca.uhn.fhir.model.dstu21.resource.Questionnaire; -import ca.uhn.fhir.model.dstu21.resource.ValueSet; -import ca.uhn.fhir.model.dstu21.valueset.RestfulSecurityServiceEnum; -import ca.uhn.fhir.model.primitive.BaseDateTimeDt; -import ca.uhn.fhir.model.primitive.BoundCodeDt; -import ca.uhn.fhir.model.primitive.IntegerDt; -import ca.uhn.fhir.model.primitive.StringDt; -import ca.uhn.fhir.model.primitive.UriDt; import ca.uhn.fhir.rest.method.RestSearchParameterTypeEnum; public class SearchParamExtractorDstu21 extends BaseSearchParamExtractor implements ISearchParamExtractor { @@ -109,7 +103,7 @@ public class SearchParamExtractorDstu21 extends BaseSearchParamExtractor impleme } @Override - public Set extractSearchParamCoords(ResourceTable theEntity, IResource theResource) { + public Set extractSearchParamCoords(ResourceTable theEntity, IBaseResource theResource) { // TODO: implement return Collections.emptySet(); } @@ -118,10 +112,10 @@ public class SearchParamExtractorDstu21 extends BaseSearchParamExtractor impleme * (non-Javadoc) * * @see ca.uhn.fhir.jpa.dao.ISearchParamExtractor#extractSearchParamDates(ca.uhn.fhir.jpa.entity.ResourceTable, - * ca.uhn.fhir.model.api.IResource) + * ca.uhn.fhir.model.api.IBaseResource) */ @Override - public Set extractSearchParamDates(ResourceTable theEntity, IResource theResource) { + public Set extractSearchParamDates(ResourceTable theEntity, IBaseResource theResource) { HashSet retVal = new HashSet(); RuntimeResourceDefinition def = getContext().getResourceDefinition(theResource); @@ -146,14 +140,14 @@ public class SearchParamExtractorDstu21 extends BaseSearchParamExtractor impleme } ResourceIndexedSearchParamDate nextEntity; - if (nextObject instanceof BaseDateTimeDt) { - BaseDateTimeDt nextValue = (BaseDateTimeDt) nextObject; + if (nextObject instanceof BaseDateTimeType) { + BaseDateTimeType nextValue = (BaseDateTimeType) nextObject; if (nextValue.isEmpty()) { continue; } nextEntity = new ResourceIndexedSearchParamDate(nextSpDef.getName(), nextValue.getValue(), nextValue.getValue()); - } else if (nextObject instanceof PeriodDt) { - PeriodDt nextValue = (PeriodDt) nextObject; + } else if (nextObject instanceof Period) { + Period nextValue = (Period) nextObject; if (nextValue.isEmpty()) { continue; } @@ -179,10 +173,10 @@ public class SearchParamExtractorDstu21 extends BaseSearchParamExtractor impleme * (non-Javadoc) * * @see ca.uhn.fhir.jpa.dao.ISearchParamExtractor#extractSearchParamNumber(ca.uhn.fhir.jpa.entity.ResourceTable, - * ca.uhn.fhir.model.api.IResource) + * ca.uhn.fhir.model.api.IBaseResource) */ @Override - public HashSet extractSearchParamNumber(ResourceTable theEntity, IResource theResource) { + public HashSet extractSearchParamNumber(ResourceTable theEntity, IBaseResource theResource) { HashSet retVal = new HashSet(); RuntimeResourceDefinition def = getContext().getResourceDefinition(theResource); @@ -197,7 +191,7 @@ public class SearchParamExtractorDstu21 extends BaseSearchParamExtractor impleme } for (Object nextObject : extractValues(nextPath, theResource)) { - if (nextObject == null || ((IDatatype) nextObject).isEmpty()) { + if (nextObject == null || ((IBase) nextObject).isEmpty()) { continue; } @@ -207,19 +201,19 @@ public class SearchParamExtractorDstu21 extends BaseSearchParamExtractor impleme multiType = true; } - if (nextObject instanceof DurationDt) { - DurationDt nextValue = (DurationDt) nextObject; + if (nextObject instanceof Duration) { + Duration nextValue = (Duration) nextObject; if (nextValue.getValueElement().isEmpty()) { continue; } - if (new UriDt(BaseHapiFhirDao.UCUM_NS).equals(nextValue.getSystemElement())) { + if (BaseHapiFhirDao.UCUM_NS.equals(nextValue.getSystem())) { if (isNotBlank(nextValue.getCode())) { - Unit unit = Unit.valueOf(nextValue.getCode()); + Unit unit = Unit.valueOf(nextValue.getCode()); javax.measure.converter.UnitConverter dayConverter = unit.getConverterTo(NonSI.DAY); double dayValue = dayConverter.convert(nextValue.getValue().doubleValue()); - DurationDt newValue = new DurationDt(); + Duration newValue = new Duration(); newValue.setSystem(BaseHapiFhirDao.UCUM_NS); newValue.setCode(NonSI.DAY.toString()); newValue.setValue(dayValue); @@ -234,8 +228,8 @@ public class SearchParamExtractorDstu21 extends BaseSearchParamExtractor impleme * * @SuppressWarnings("unchecked") PhysicsUnit timeUnit = * (PhysicsUnit