Merge branch 'hl7org_dstu21'

This commit is contained in:
jamesagnew 2016-01-01 17:00:58 -05:00
commit 09b0982df1
1316 changed files with 576841 additions and 112776 deletions

View File

@ -8,6 +8,11 @@ import javax.servlet.ServletException;
import org.apache.commons.io.IOUtils; import org.apache.commons.io.IOUtils;
import org.apache.commons.io.filefilter.WildcardFileFilter; import org.apache.commons.io.filefilter.WildcardFileFilter;
import org.hl7.fhir.instance.hapi.validation.DefaultProfileValidationSupport;
import org.hl7.fhir.instance.hapi.validation.FhirInstanceValidator;
import org.hl7.fhir.instance.hapi.validation.IValidationSupport;
import org.hl7.fhir.instance.hapi.validation.IValidationSupport.CodeValidationResult;
import org.hl7.fhir.instance.hapi.validation.ValidationSupportChain;
import org.hl7.fhir.instance.model.ValueSet; import org.hl7.fhir.instance.model.ValueSet;
import org.hl7.fhir.instance.model.ValueSet.ConceptSetComponent; import org.hl7.fhir.instance.model.ValueSet.ConceptSetComponent;
import org.hl7.fhir.instance.model.ValueSet.ValueSetExpansionComponent; import org.hl7.fhir.instance.model.ValueSet.ValueSetExpansionComponent;
@ -23,11 +28,7 @@ import ca.uhn.fhir.parser.IParser;
import ca.uhn.fhir.parser.StrictErrorHandler; import ca.uhn.fhir.parser.StrictErrorHandler;
import ca.uhn.fhir.rest.client.IGenericClient; import ca.uhn.fhir.rest.client.IGenericClient;
import ca.uhn.fhir.rest.server.RestfulServer; import ca.uhn.fhir.rest.server.RestfulServer;
import ca.uhn.fhir.validation.DefaultProfileValidationSupport;
import ca.uhn.fhir.validation.ValidationSupportChain;
import ca.uhn.fhir.validation.FhirInstanceValidator;
import ca.uhn.fhir.validation.FhirValidator; import ca.uhn.fhir.validation.FhirValidator;
import ca.uhn.fhir.validation.IValidationSupport;
import ca.uhn.fhir.validation.SingleValidationMessage; import ca.uhn.fhir.validation.SingleValidationMessage;
import ca.uhn.fhir.validation.ValidationResult; import ca.uhn.fhir.validation.ValidationResult;

View File

@ -43,6 +43,7 @@ public abstract class BaseRuntimeChildDatatypeDefinition extends BaseRuntimeDecl
super(theField, theChildAnnotation, theDescriptionAnnotation, theElementName); super(theField, theChildAnnotation, theDescriptionAnnotation, theElementName);
// should use RuntimeChildAny // should use RuntimeChildAny
assert Modifier.isInterface(theDatatype.getModifiers()) == false : "Type of " + theDatatype + " shouldn't be here"; assert Modifier.isInterface(theDatatype.getModifiers()) == false : "Type of " + theDatatype + " shouldn't be here";
assert Modifier.isAbstract(theDatatype.getModifiers()) == false : "Type of " + theDatatype + " shouldn't be here";
myDatatype = theDatatype; myDatatype = theDatatype;
} }

View File

@ -66,7 +66,7 @@ public abstract class BaseRuntimeElementDefinition<T extends IBase> {
@Override @Override
public String toString() { public String toString() {
return getClass().getSimpleName()+"[" + getName() + "]"; return getClass().getSimpleName()+"[" + getName() + ", " + getImplementingClass().getSimpleName() + "]";
} }
public void addExtension(RuntimeChildDeclaredExtensionDefinition theExtension) { public void addExtension(RuntimeChildDeclaredExtensionDefinition theExtension) {
@ -214,7 +214,7 @@ public abstract class BaseRuntimeElementDefinition<T extends IBase> {
/** /**
* HL7.org style. * HL7.org style.
*/ */
PRIMITIVE_XHTML_HL7ORG PRIMITIVE_XHTML_HL7ORG,
} }

View File

@ -124,8 +124,6 @@ public class FhirContext {
myVersion = FhirVersionEnum.DSTU2.getVersionImplementation(); myVersion = FhirVersionEnum.DSTU2.getVersionImplementation();
} else if (FhirVersionEnum.DSTU2_HL7ORG.isPresentOnClasspath()) { } else if (FhirVersionEnum.DSTU2_HL7ORG.isPresentOnClasspath()) {
myVersion = FhirVersionEnum.DSTU2_HL7ORG.getVersionImplementation(); myVersion = FhirVersionEnum.DSTU2_HL7ORG.getVersionImplementation();
} else if (FhirVersionEnum.DEV.isPresentOnClasspath()) {
myVersion = FhirVersionEnum.DEV.getVersionImplementation();
} else { } else {
throw new IllegalStateException(getLocalizer().getMessage(FhirContext.class, "noStructures")); throw new IllegalStateException(getLocalizer().getMessage(FhirContext.class, "noStructures"));
} }
@ -483,7 +481,7 @@ public class FhirContext {
myParserErrorHandler = theParserErrorHandler; myParserErrorHandler = theParserErrorHandler;
} }
@SuppressWarnings("unchecked") @SuppressWarnings({ "cast" })
private List<Class<? extends IElement>> toElementList(Collection<Class<? extends IBaseResource>> theResourceTypes) { private List<Class<? extends IElement>> toElementList(Collection<Class<? extends IBaseResource>> theResourceTypes) {
if (theResourceTypes == null) { if (theResourceTypes == null) {
return null; return null;
@ -495,16 +493,6 @@ public class FhirContext {
return resTypes; return resTypes;
} }
/**
* Creates and returns a new FhirContext with version {@link FhirVersionEnum#DEV}
*
* @deprecated Support for DEV resources will be removed, you should use DSTU2 resources instead
*/
@Deprecated
public static FhirContext forDev() {
return new FhirContext(FhirVersionEnum.DEV);
}
/** /**
* Creates and returns a new FhirContext with version {@link FhirVersionEnum#DSTU1} * Creates and returns a new FhirContext with version {@link FhirVersionEnum#DSTU1}
*/ */

View File

@ -34,25 +34,38 @@ public enum FhirVersionEnum {
* *********************** * ***********************
*/ */
DSTU1("ca.uhn.fhir.model.dstu.FhirDstu1", null), DSTU1("ca.uhn.fhir.model.dstu.FhirDstu1", null, false),
DSTU2("ca.uhn.fhir.model.dstu2.FhirDstu2", null), DSTU2("ca.uhn.fhir.model.dstu2.FhirDstu2", null, false),
DEV("ca.uhn.fhir.model.dev.FhirDev", null), DSTU2_1("org.hl7.fhir.dstu21.hapi.ctx.FhirDstu21", null, true),
DSTU2_HL7ORG("org.hl7.fhir.instance.FhirDstu2Hl7Org", DSTU2), DSTU2_HL7ORG("org.hl7.fhir.instance.FhirDstu2Hl7Org", DSTU2, true);
DSTU2_1("ca.uhn.fhir.model.dstu21.FhirDstu21", null);
private final String myVersionClass;
private final FhirVersionEnum myEquivalent; private final FhirVersionEnum myEquivalent;
private final boolean myIsRi;
private volatile Boolean myPresentOnClasspath; private volatile Boolean myPresentOnClasspath;
private final String myVersionClass;
private volatile IFhirVersion myVersionImplementation; private volatile IFhirVersion myVersionImplementation;
FhirVersionEnum(String theVersionClass, FhirVersionEnum theEquivalent) { FhirVersionEnum(String theVersionClass, FhirVersionEnum theEquivalent, boolean theIsRi) {
myVersionClass = theVersionClass; myVersionClass = theVersionClass;
myEquivalent = theEquivalent; myEquivalent = theEquivalent;
myIsRi = theIsRi;
}
public IFhirVersion getVersionImplementation() {
if (!isPresentOnClasspath()) {
throw new IllegalStateException("Version " + name() + " is not present on classpath");
}
if (myVersionImplementation == null) {
try {
myVersionImplementation = (IFhirVersion) Class.forName(myVersionClass).newInstance();
} catch (Exception e) {
throw new InternalErrorException("Failed to instantiate FHIR version " + name(), e);
}
}
return myVersionImplementation;
} }
public boolean isEquivalentTo(FhirVersionEnum theVersion) { public boolean isEquivalentTo(FhirVersionEnum theVersion) {
@ -86,18 +99,11 @@ public enum FhirVersionEnum {
return retVal; return retVal;
} }
public IFhirVersion getVersionImplementation() { /**
if (!isPresentOnClasspath()) { * Is this version using the HL7.org RI structures?
throw new IllegalStateException("Version " + name() + " is not present on classpath"); */
} public boolean isRi() {
if (myVersionImplementation == null) { return myIsRi;
try {
myVersionImplementation = (IFhirVersion) Class.forName(myVersionClass).newInstance();
} catch (Exception e) {
throw new InternalErrorException("Failed to instantiate FHIR version " + name(), e);
}
}
return myVersionImplementation;
} }
} }

View File

@ -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.IBaseDatatypeElement;
import org.hl7.fhir.instance.model.api.IBaseEnumeration; import org.hl7.fhir.instance.model.api.IBaseEnumeration;
import org.hl7.fhir.instance.model.api.IBaseExtension; 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.IBaseReference;
import org.hl7.fhir.instance.model.api.IBaseResource; import org.hl7.fhir.instance.model.api.IBaseResource;
import org.hl7.fhir.instance.model.api.IBaseXhtml; import org.hl7.fhir.instance.model.api.IBaseXhtml;
@ -231,7 +232,8 @@ class ModelScanner {
} }
private boolean isStandardType(Class<? extends IBase> theClass) { private boolean isStandardType(Class<? extends IBase> theClass) {
return myVersionTypes.contains(theClass); boolean retVal = myVersionTypes.contains(theClass);
return retVal;
} }
/** /**
@ -245,58 +247,58 @@ class ModelScanner {
private <T extends Annotation> T pullAnnotation(Class<?> theContainer, AnnotatedElement theTarget, Class<T> theAnnotationType) { private <T extends Annotation> T pullAnnotation(Class<?> theContainer, AnnotatedElement theTarget, Class<T> theAnnotationType) {
T retVal = theTarget.getAnnotation(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<? extends Annotation> 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<? extends Annotation>) 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; return retVal;
// }
//
// if (retVal == null) {
// final Class<? extends Annotation> 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<? extends Annotation>) 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<? extends IBase> theClass) throws ConfigurationException { private void scan(Class<? extends IBase> theClass) throws ConfigurationException {
@ -366,6 +368,8 @@ class ModelScanner {
RuntimeCompositeDatatypeDefinition resourceDef; RuntimeCompositeDatatypeDefinition resourceDef;
if (theClass.equals(ExtensionDt.class)) { if (theClass.equals(ExtensionDt.class)) {
resourceDef = new RuntimeExtensionDtDefinition(theDatatypeDefinition, theClass, true); resourceDef = new RuntimeExtensionDtDefinition(theDatatypeDefinition, theClass, true);
// } else if (IBaseMetaType.class.isAssignableFrom(theClass)) {
// resourceDef = new RuntimeMetaDefinition(theDatatypeDefinition, theClass, isStandardType(theClass));
} else { } else {
resourceDef = new RuntimeCompositeDatatypeDefinition(theDatatypeDefinition, theClass, isStandardType(theClass)); resourceDef = new RuntimeCompositeDatatypeDefinition(theDatatypeDefinition, theClass, isStandardType(theClass));
} }
@ -608,7 +612,7 @@ class ModelScanner {
RuntimeChildResourceBlockDefinition def = new RuntimeChildResourceBlockDefinition(next, childAnnotation, descriptionAnnotation, elementName, blockDef); RuntimeChildResourceBlockDefinition def = new RuntimeChildResourceBlockDefinition(next, childAnnotation, descriptionAnnotation, elementName, blockDef);
orderMap.put(order, def); orderMap.put(order, def);
} else if (IDatatype.class.equals(nextElementType) || IElement.class.equals(nextElementType) || "org.hl7.fhir.instance.model.Type".equals(nextElementType.getName()) || IBaseDatatype.class.equals(nextElementType)) { } else if (IDatatype.class.equals(nextElementType) || IElement.class.equals(nextElementType) || "Type".equals(nextElementType.getSimpleName()) || IBaseDatatype.class.equals(nextElementType)) {
RuntimeChildAny def = new RuntimeChildAny(next, elementName, childAnnotation, descriptionAnnotation); RuntimeChildAny def = new RuntimeChildAny(next, elementName, childAnnotation, descriptionAnnotation);
orderMap.put(order, def); orderMap.put(order, def);
@ -687,8 +691,14 @@ class ModelScanner {
} }
myClassToElementDefinitions.put(theClass, resourceDef); myClassToElementDefinitions.put(theClass, resourceDef);
if (!theDatatypeDefinition.isSpecialization()) { if (!theDatatypeDefinition.isSpecialization()) {
if (myVersion.isRi() && IDatatype.class.isAssignableFrom(theClass)) {
ourLog.debug("Not adding non RI type {} to RI context", theClass);
} else if (!myVersion.isRi() && !IDatatype.class.isAssignableFrom(theClass)) {
ourLog.debug("Not adding RI type {} to non RI context", theClass);
} else {
myNameToElementDefinitions.put(resourceName, resourceDef); myNameToElementDefinitions.put(resourceName, resourceDef);
} }
}
return resourceName; return resourceName;
} }

View File

@ -26,7 +26,6 @@ import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.TreeSet;
import org.apache.commons.lang3.text.WordUtils; import org.apache.commons.lang3.text.WordUtils;
import org.hl7.fhir.instance.model.api.IBase; import org.hl7.fhir.instance.model.api.IBase;
@ -35,7 +34,6 @@ import org.hl7.fhir.instance.model.api.IBaseResource;
import ca.uhn.fhir.model.api.ExtensionDt; import ca.uhn.fhir.model.api.ExtensionDt;
import ca.uhn.fhir.model.api.IDatatype; import ca.uhn.fhir.model.api.IDatatype;
import ca.uhn.fhir.model.base.composite.BaseResourceReferenceDt; import ca.uhn.fhir.model.base.composite.BaseResourceReferenceDt;
import ca.uhn.fhir.model.primitive.CodeDt;
public class RuntimeChildUndeclaredExtensionDefinition extends BaseRuntimeChildDefinition { public class RuntimeChildUndeclaredExtensionDefinition extends BaseRuntimeChildDefinition {
@ -149,6 +147,8 @@ public class RuntimeChildUndeclaredExtensionDefinition extends BaseRuntimeChildD
return false; return false;
} }
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(RuntimeChildUndeclaredExtensionDefinition.class);
@Override @Override
void sealAndInitialize(FhirContext theContext, Map<Class<? extends IBase>, BaseRuntimeElementDefinition<?>> theClassToElementDefinitions) { void sealAndInitialize(FhirContext theContext, Map<Class<? extends IBase>, BaseRuntimeElementDefinition<?>> theClassToElementDefinitions) {
Map<String, BaseRuntimeElementDefinition<?>> datatypeAttributeNameToDefinition = new HashMap<String, BaseRuntimeElementDefinition<?>>(); Map<String, BaseRuntimeElementDefinition<?>> datatypeAttributeNameToDefinition = new HashMap<String, BaseRuntimeElementDefinition<?>>();
@ -160,7 +160,12 @@ public class RuntimeChildUndeclaredExtensionDefinition extends BaseRuntimeChildD
myDatatypeToDefinition.put(next.getImplementingClass(), next); myDatatypeToDefinition.put(next.getImplementingClass(), next);
if (!((IRuntimeDatatypeDefinition) next).isSpecialization()) { boolean isSpecialization = ((IRuntimeDatatypeDefinition) next).isSpecialization();
if (isSpecialization) {
ourLog.trace("Not adding specialization: {}", next.getImplementingClass());
}
if (!isSpecialization) {
if (!next.isStandardType()) { if (!next.isStandardType()) {
continue; continue;

View File

@ -74,7 +74,14 @@ public class RuntimePrimitiveDatatypeDefinition extends BaseRuntimeElementDefini
if (myProfileOfType != null) { if (myProfileOfType != null) {
myProfileOf = theClassToElementDefinitions.get(myProfileOfType); myProfileOf = theClassToElementDefinitions.get(myProfileOfType);
if (myProfileOf == null) { 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());
} }
} }
} }

View File

@ -58,11 +58,8 @@ public class RuntimeResourceDefinition extends BaseRuntimeElementCompositeDefini
try { try {
IBaseResource instance = theClass.newInstance(); IBaseResource instance = theClass.newInstance();
if (instance instanceof IAnyResource) { myStructureVersion = instance.getStructureFhirVersionEnum();
myStructureVersion = FhirVersionEnum.DSTU2_HL7ORG; assert myStructureVersion != null;
} else {
myStructureVersion = ((IResource)instance).getStructureFhirVersionEnum();
}
} catch (Exception e) { } catch (Exception e) {
throw new ConfigurationException(myContext.getLocalizer().getMessage(getClass(), "nonInstantiableType", theClass.getName(), e.toString()), e); throw new ConfigurationException(myContext.getLocalizer().getMessage(getClass(), "nonInstantiableType", theClass.getName(), e.toString()), e);
} }

View File

@ -25,12 +25,12 @@ import java.util.Date;
import org.hl7.fhir.instance.model.api.IBase; import org.hl7.fhir.instance.model.api.IBase;
import org.hl7.fhir.instance.model.api.IBaseResource; 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 org.hl7.fhir.instance.model.api.IPrimitiveType;
import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.context.FhirVersionEnum; import ca.uhn.fhir.context.FhirVersionEnum;
import ca.uhn.fhir.context.RuntimeResourceDefinition; import ca.uhn.fhir.context.RuntimeResourceDefinition;
import ca.uhn.fhir.model.base.composite.BaseCodingDt;
import ca.uhn.fhir.rest.server.IResourceProvider; import ca.uhn.fhir.rest.server.IResourceProvider;
import ca.uhn.fhir.rest.server.IServerConformanceProvider; import ca.uhn.fhir.rest.server.IServerConformanceProvider;
import ca.uhn.fhir.rest.server.IVersionSpecificBundleFactory; import ca.uhn.fhir.rest.server.IVersionSpecificBundleFactory;
@ -54,10 +54,12 @@ public interface IFhirVersion {
Class<?> getContainedType(); Class<?> getContainedType();
BaseCodingDt newCodingDt(); IBase newCodingDt();
IVersionSpecificBundleFactory newBundleFactory(FhirContext theContext); IVersionSpecificBundleFactory newBundleFactory(FhirContext theContext);
IPrimitiveType<Date> getLastUpdated(IBaseResource theResource); IPrimitiveType<Date> getLastUpdated(IBaseResource theResource);
IIdType newIdType();
} }

View File

@ -40,15 +40,6 @@ import ca.uhn.fhir.model.primitive.IdDt;
* </p> * </p>
*/ */
public interface IResource extends ICompositeElement, org.hl7.fhir.instance.model.api.IBaseResource { public interface IResource extends ICompositeElement, org.hl7.fhir.instance.model.api.IBaseResource {
/**
* Include constant for <code>*</code> (return all includes)
*/
public static final Include INCLUDE_ALL = new Include("*", false).toLocked();
/**
* Include set containing only {@link #INCLUDE_ALL}
*/
public static final Set<Include> WILDCARD_ALL_SET = Collections.unmodifiableSet(new HashSet<Include>(Arrays.asList(INCLUDE_ALL)));
/** /**
* Returns the contained resource list for this resource. * Returns the contained resource list for this resource.

View File

@ -29,6 +29,8 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import org.apache.commons.lang3.StringUtils; 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.base.composite.BaseCodingDt;
import ca.uhn.fhir.model.primitive.DecimalDt; import ca.uhn.fhir.model.primitive.DecimalDt;
@ -71,7 +73,7 @@ public abstract class ResourceMetadataKeyEnum<T> implements Serializable {
* Values for this key are of type <b>{@link InstantDt}</b> * Values for this key are of type <b>{@link InstantDt}</b>
* </p> * </p>
*/ */
public static final ResourceMetadataKeyEnum<InstantDt> DELETED_AT = new ResourceMetadataKeyEnum<InstantDt>("DELETED_AT") { public static final ResourceMetadataKeySupportingAnyResource<InstantDt, IPrimitiveType<Date>> DELETED_AT = new ResourceMetadataKeySupportingAnyResource<InstantDt, IPrimitiveType<Date>>("DELETED_AT") {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
@Override @Override
@ -83,6 +85,17 @@ public abstract class ResourceMetadataKeyEnum<T> implements Serializable {
public void put(IResource theResource, InstantDt theObject) { public void put(IResource theResource, InstantDt theObject) {
theResource.getResourceMetadata().put(DELETED_AT, theObject); theResource.getResourceMetadata().put(DELETED_AT, theObject);
} }
@SuppressWarnings("unchecked")
@Override
public IPrimitiveType<Date> get(IAnyResource theResource) {
return (IPrimitiveType<Date>) theResource.getUserData(DELETED_AT.name());
}
@Override
public void put(IAnyResource theResource, IPrimitiveType<Date> theObject) {
theResource.setUserData(DELETED_AT.name(), theObject);
}
}; };
/** /**
@ -120,7 +133,7 @@ public abstract class ResourceMetadataKeyEnum<T> implements Serializable {
* Values for this key are of type <b>{@link BundleEntrySearchModeEnum}</b> * Values for this key are of type <b>{@link BundleEntrySearchModeEnum}</b>
* </p> * </p>
*/ */
public static final ResourceMetadataKeyEnum<BundleEntrySearchModeEnum> ENTRY_SEARCH_MODE = new ResourceMetadataKeyEnum<BundleEntrySearchModeEnum>("ENTRY_SEARCH_MODE") { public static final ResourceMetadataKeySupportingAnyResource<BundleEntrySearchModeEnum, String> ENTRY_SEARCH_MODE = new ResourceMetadataKeySupportingAnyResource<BundleEntrySearchModeEnum, String>("ENTRY_SEARCH_MODE") {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
@Override @Override
public BundleEntrySearchModeEnum get(IResource theResource) { public BundleEntrySearchModeEnum get(IResource theResource) {
@ -131,6 +144,16 @@ public abstract class ResourceMetadataKeyEnum<T> implements Serializable {
public void put(IResource theResource, BundleEntrySearchModeEnum theObject) { public void put(IResource theResource, BundleEntrySearchModeEnum theObject) {
theResource.getResourceMetadata().put(ENTRY_SEARCH_MODE, 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);
}
}; };
/** /**
@ -145,7 +168,7 @@ public abstract class ResourceMetadataKeyEnum<T> implements Serializable {
* Values for this key are of type <b>{@link BundleEntryTransactionMethodEnum}</b> * Values for this key are of type <b>{@link BundleEntryTransactionMethodEnum}</b>
* </p> * </p>
*/ */
public static final ResourceMetadataKeyEnum<BundleEntryTransactionMethodEnum> ENTRY_TRANSACTION_METHOD = new ResourceMetadataKeyEnum<BundleEntryTransactionMethodEnum>( public static final ResourceMetadataKeySupportingAnyResource<BundleEntryTransactionMethodEnum, String> ENTRY_TRANSACTION_METHOD = new ResourceMetadataKeySupportingAnyResource<BundleEntryTransactionMethodEnum, String>(
"ENTRY_TRANSACTION_OPERATION") { "ENTRY_TRANSACTION_OPERATION") {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
@ -159,6 +182,17 @@ public abstract class ResourceMetadataKeyEnum<T> implements Serializable {
public void put(IResource theResource, BundleEntryTransactionMethodEnum theObject) { public void put(IResource theResource, BundleEntryTransactionMethodEnum theObject) {
theResource.getResourceMetadata().put(ENTRY_TRANSACTION_METHOD, 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);
}
}; };
/** /**
@ -444,7 +478,7 @@ public abstract class ResourceMetadataKeyEnum<T> implements Serializable {
return result; return result;
} }
private String name() { public String name() {
return myValue; return myValue;
} }
@ -573,4 +607,19 @@ public abstract class ResourceMetadataKeyEnum<T> implements Serializable {
+ IdDt.class.getCanonicalName()); + IdDt.class.getCanonicalName());
} }
public static abstract class ResourceMetadataKeySupportingAnyResource<T, T2> extends ResourceMetadataKeyEnum<T> {
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);
}
} }

View File

@ -51,9 +51,8 @@ public @interface ResourceDef {
String id() default ""; String id() default "";
/** /**
* The URL indicating the profile for this resource definition, if known. If this value is set * The URL indicating the profile for this resource definition. If specified, this URL will be
* on a custom profile definition class in a server, the profile is assumed to be external to * automatically added to the meta tag when the resource is serialized.
* the server, so the server will not export a profile for it.
*/ */
String profile() default ""; String profile() default "";

View File

@ -21,6 +21,7 @@ package ca.uhn.fhir.model.base.composite;
*/ */
import org.apache.commons.lang3.StringUtils; 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.BaseIdentifiableElement;
import ca.uhn.fhir.model.api.ICompositeDatatype; import ca.uhn.fhir.model.api.ICompositeDatatype;

View File

@ -675,4 +675,25 @@ public class IdDt extends UriDt implements IPrimitiveDatatype<String>, IIdType {
return theIdPart.toString(); 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;
}
} }

View File

@ -41,6 +41,7 @@ import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.Validate; import org.apache.commons.lang3.Validate;
import org.hl7.fhir.instance.model.api.IAnyResource; import org.hl7.fhir.instance.model.api.IAnyResource;
import org.hl7.fhir.instance.model.api.IBase; 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.IBaseMetaType;
import org.hl7.fhir.instance.model.api.IBaseReference; import org.hl7.fhir.instance.model.api.IBaseReference;
import org.hl7.fhir.instance.model.api.IBaseResource; import org.hl7.fhir.instance.model.api.IBaseResource;
@ -374,6 +375,15 @@ public abstract class BaseParser implements IParser {
return stringWriter.toString(); return stringWriter.toString();
} }
private void filterCodingsWithNoCodeOrSystem(List<? extends IBaseCoding> 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) { protected String fixContainedResourceId(String theValue) {
if (StringUtils.isNotBlank(theValue) && theValue.charAt(0) == '#') { if (StringUtils.isNotBlank(theValue) && theValue.charAt(0) == '#') {
return theValue.substring(1); return theValue.substring(1);
@ -409,7 +419,7 @@ public abstract class BaseParser implements IParser {
TagList tags = ResourceMetadataKeyEnum.TAG_LIST.get(theIResource); TagList tags = ResourceMetadataKeyEnum.TAG_LIST.get(theIResource);
if (shouldAddSubsettedTag()) { if (shouldAddSubsettedTag()) {
tags = new TagList(tags); 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; return tags;
@ -538,53 +548,48 @@ public abstract class BaseParser implements IParser {
} }
@SuppressWarnings("cast") @SuppressWarnings("cast")
protected List<? extends IBase> preProcessValues(BaseRuntimeChildDefinition metaChildUncast, List<? extends IBase> theValues) { protected List<? extends IBase> preProcessValues(BaseRuntimeChildDefinition metaChildUncast, IBaseResource theResource, List<? extends IBase> theValues) {
if (myContext.getVersion().getVersion().equals(FhirVersionEnum.DSTU2_HL7ORG)) { if (myContext.getVersion().getVersion().isRi()) {
if (shouldAddSubsettedTag() && metaChildUncast.getValidChildNames().contains("meta")) {
BaseRuntimeElementDefinition<?> childByName = metaChildUncast.getChildByName("meta"); /*
if (childByName instanceof BaseRuntimeElementCompositeDefinition<?>) { * If we're encoding the meta tag, we do some massaging of the meta values before
BaseRuntimeElementCompositeDefinition<?> metaChildUncast1 = (BaseRuntimeElementCompositeDefinition<?>) childByName; * encoding. Buf if there is no meta element at all, we create one since we're possibly going to be
if (metaChildUncast1 != null) { * adding things to it
if (IBaseMetaType.class.isAssignableFrom(metaChildUncast1.getImplementingClass())) { */
IBaseMetaType metaValue; if (theValues.isEmpty() && metaChildUncast.getElementName().equals("meta")) {
if (theValues != null && theValues.size() >= 1) { BaseRuntimeElementDefinition<?> metaChild = metaChildUncast.getChildByName("meta");
metaValue = (IBaseMetaType) theValues.iterator().next(); 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 { try {
metaValue = (IBaseMetaType) metaValue.getClass().getMethod("copy").invoke(metaValue); metaValue = (IBaseMetaType) metaValue.getClass().getMethod("copy").invoke(metaValue);
} catch (Exception e) { } catch (Exception e) {
throw new InternalErrorException("Failed to duplicate meta", e); throw new InternalErrorException("Failed to duplicate meta", e);
} }
} else {
metaValue = (IBaseMetaType) metaChildUncast1.newInstance();
}
ArrayList<IBase> retVal = new ArrayList<IBase>(); if (isBlank(metaValue.getVersionId())) {
retVal.add(metaValue); if (theResource.getIdElement().hasVersionIdPart()) {
metaValue.setVersionId(theResource.getIdElement().getVersionIdPart());
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;
} }
} }
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);
} }
} }
@ -656,6 +661,10 @@ public abstract class BaseParser implements IParser {
return isSummaryMode() || isSuppressNarratives(); return isSummaryMode() || isSuppressNarratives();
} }
private String subsetDescription() {
return "Resource encoded in summary mode";
}
protected void throwExceptionForUnknownChildType(BaseRuntimeChildDefinition nextChild, Class<? extends IBase> theType) { protected void throwExceptionForUnknownChildType(BaseRuntimeChildDefinition nextChild, Class<? extends IBase> theType) {
if (nextChild instanceof BaseRuntimeDeclaredChildDefinition) { if (nextChild instanceof BaseRuntimeDeclaredChildDefinition) {
StringBuilder b = new StringBuilder(); StringBuilder b = new StringBuilder();

View File

@ -531,7 +531,7 @@ public class JsonParser extends BaseParser implements IParser {
BaseRuntimeChildDefinition nextChild = nextChildElem.getDef(); BaseRuntimeChildDefinition nextChild = nextChildElem.getDef();
if (nextChild instanceof RuntimeChildNarrativeDefinition) { if (nextChild instanceof RuntimeChildNarrativeDefinition) {
INarrativeGenerator gen = myContext.getNarrativeGenerator(); INarrativeGenerator gen = myContext.getNarrativeGenerator();
if (gen != null) { if (gen != null && theResource instanceof IResource) {
BaseNarrativeDt<?> narr = ((IResource) theResource).getText(); BaseNarrativeDt<?> narr = ((IResource) theResource).getText();
if (narr.getDiv().isEmpty()) { if (narr.getDiv().isEmpty()) {
gen.generateNarrative(theResDef.getResourceProfile(), theResource, narr); gen.generateNarrative(theResDef.getResourceProfile(), theResource, narr);
@ -552,7 +552,7 @@ public class JsonParser extends BaseParser implements IParser {
} }
List<? extends IBase> values = nextChild.getAccessor().getValues(theNextValue); List<? extends IBase> values = nextChild.getAccessor().getValues(theNextValue);
values = super.preProcessValues(nextChild, values); values = super.preProcessValues(nextChild, theResource, values);
if (values == null || values.isEmpty()) { if (values == null || values.isEmpty()) {
continue; continue;

View File

@ -35,8 +35,11 @@ import javax.xml.stream.events.XMLEvent;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.Validate; 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.IBase;
import org.hl7.fhir.instance.model.api.IBaseBackboneElement;
import org.hl7.fhir.instance.model.api.IBaseBinary; import org.hl7.fhir.instance.model.api.IBaseBinary;
import org.hl7.fhir.instance.model.api.IBaseCoding;
import org.hl7.fhir.instance.model.api.IBaseElement; import org.hl7.fhir.instance.model.api.IBaseElement;
import org.hl7.fhir.instance.model.api.IBaseExtension; import org.hl7.fhir.instance.model.api.IBaseExtension;
import org.hl7.fhir.instance.model.api.IBaseHasExtensions; import org.hl7.fhir.instance.model.api.IBaseHasExtensions;
@ -147,11 +150,7 @@ class ParserState<T> {
IBase newChildInstance; IBase newChildInstance;
try { try {
IFhirVersion version; IFhirVersion version;
if (theTarget instanceof IResource) { version = theTarget.getStructureFhirVersionEnum().getVersionImplementation();
version = ((IResource) theTarget).getStructureFhirVersionEnum().getVersionImplementation();
} else {
version = FhirVersionEnum.DSTU2_HL7ORG.getVersionImplementation();
}
newChildInstance = version.getResourceReferenceType().newInstance(); newChildInstance = version.getResourceReferenceType().newInstance();
} catch (InstantiationException e) { } catch (InstantiationException e) {
throw new ConfigurationException("Failed to instantiate " + myContext.getVersion().getResourceReferenceType(), e); throw new ConfigurationException("Failed to instantiate " + myContext.getVersion().getResourceReferenceType(), e);
@ -234,10 +233,10 @@ class ParserState<T> {
throws DataFormatException { throws DataFormatException {
ParserState<T> retVal = new ParserState<T>(theContext, theJsonMode, theErrorHandler); ParserState<T> retVal = new ParserState<T>(theContext, theJsonMode, theErrorHandler);
if (theResourceType == null) { if (theResourceType == null) {
if (theContext.getVersion().getVersion() != FhirVersionEnum.DSTU2_HL7ORG) { if (theContext.getVersion().getVersion().isRi()) {
retVal.push(retVal.new PreResourceStateHapi(theResourceType));
} else {
retVal.push(retVal.new PreResourceStateHl7Org(theResourceType)); retVal.push(retVal.new PreResourceStateHl7Org(theResourceType));
} else {
retVal.push(retVal.new PreResourceStateHapi(theResourceType));
} }
} else { } else {
if (IResource.class.isAssignableFrom(theResourceType)) { if (IResource.class.isAssignableFrom(theResourceType)) {
@ -1409,7 +1408,7 @@ class ParserState<T> {
private class ContainedResourcesStateHl7Org extends PreResourceState { private class ContainedResourcesStateHl7Org extends PreResourceState {
public ContainedResourcesStateHl7Org(PreResourceState thePreResourcesState) { public ContainedResourcesStateHl7Org(PreResourceState thePreResourcesState) {
super(thePreResourcesState, FhirVersionEnum.DSTU2_HL7ORG); super(thePreResourcesState, thePreResourcesState.myParentVersion);
} }
@Override @Override
@ -1664,11 +1663,11 @@ class ParserState<T> {
return; return;
} }
case RESOURCE: { case RESOURCE: {
if (myInstance instanceof IResource || myInstance instanceof IElement) { if (myInstance instanceof IAnyResource || myInstance instanceof IBaseBackboneElement) {
ParserState<T>.PreResourceStateHapi state = new PreResourceStateHapi(myInstance, child.getMutator(), null); ParserState<T>.PreResourceStateHl7Org state = new PreResourceStateHl7Org(myInstance, child.getMutator(), null);
push(state); push(state);
} else { } else {
ParserState<T>.PreResourceStateHl7Org state = new PreResourceStateHl7Org(myInstance, child.getMutator(), null); ParserState<T>.PreResourceStateHapi state = new PreResourceStateHapi(myInstance, child.getMutator(), null);
push(state); push(state);
} }
return; return;
@ -1757,7 +1756,7 @@ class ParserState<T> {
case RESOURCE_REF: { case RESOURCE_REF: {
ICompositeType newChildInstance = (ICompositeType) newResourceReferenceDt(getPreResourceState().myInstance); ICompositeType newChildInstance = (ICompositeType) newResourceReferenceDt(getPreResourceState().myInstance);
myExtension.setValue(newChildInstance); myExtension.setValue(newChildInstance);
if (myContext.getVersion().getVersion().equals(FhirVersionEnum.DSTU2_HL7ORG)) { if (myContext.getVersion().getVersion().isRi()) {
ParserState<T>.ResourceReferenceStateHl7Org newState = new ResourceReferenceStateHl7Org(getPreResourceState(), (IBaseReference) newChildInstance); ParserState<T>.ResourceReferenceStateHl7Org newState = new ResourceReferenceStateHl7Org(getPreResourceState(), (IBaseReference) newChildInstance);
push(newState); push(newState);
} else { } else {
@ -1788,7 +1787,7 @@ class ParserState<T> {
private class SecurityLabelElementStateHapi extends ElementCompositeState { private class SecurityLabelElementStateHapi extends ElementCompositeState {
public SecurityLabelElementStateHapi(ParserState<T>.PreResourceState thePreResourceState, BaseRuntimeElementCompositeDefinition<?> theDef, BaseCodingDt codingDt) { public SecurityLabelElementStateHapi(ParserState<T>.PreResourceState thePreResourceState, BaseRuntimeElementCompositeDefinition<?> theDef, IBase codingDt) {
super(thePreResourceState, theDef, codingDt); super(thePreResourceState, theDef, codingDt);
} }
@ -1824,12 +1823,12 @@ class ParserState<T> {
myMap.put(ResourceMetadataKeyEnum.UPDATED, updated); myMap.put(ResourceMetadataKeyEnum.UPDATED, updated);
} else if (theLocalPart.equals("security")) { } else if (theLocalPart.equals("security")) {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
List<BaseCodingDt> securityLabels = (List<BaseCodingDt>) myMap.get(ResourceMetadataKeyEnum.SECURITY_LABELS); List<IBase> securityLabels = (List<IBase>) myMap.get(ResourceMetadataKeyEnum.SECURITY_LABELS);
if (securityLabels == null) { if (securityLabels == null) {
securityLabels = new ArrayList<BaseCodingDt>(); securityLabels = new ArrayList<IBase>();
myMap.put(ResourceMetadataKeyEnum.SECURITY_LABELS, securityLabels); myMap.put(ResourceMetadataKeyEnum.SECURITY_LABELS, securityLabels);
} }
BaseCodingDt securityLabel = myContext.getVersion().newCodingDt(); IBase securityLabel = myContext.getVersion().newCodingDt();
BaseRuntimeElementCompositeDefinition<?> codinfDef = (BaseRuntimeElementCompositeDefinition<?>) myContext.getElementDefinition(securityLabel.getClass()); BaseRuntimeElementCompositeDefinition<?> codinfDef = (BaseRuntimeElementCompositeDefinition<?>) myContext.getElementDefinition(securityLabel.getClass());
push(new SecurityLabelElementStateHapi(getPreResourceState(), codinfDef, securityLabel)); push(new SecurityLabelElementStateHapi(getPreResourceState(), codinfDef, securityLabel));
securityLabels.add(securityLabel); securityLabels.add(securityLabel);

View File

@ -600,7 +600,7 @@ public class XmlParser extends BaseParser implements IParser {
} else { } else {
List<? extends IBase> values = nextChild.getAccessor().getValues(theElement); List<? extends IBase> values = nextChild.getAccessor().getValues(theElement);
values = super.preProcessValues(nextChild, values); values = super.preProcessValues(nextChild, theResource, values);
if (values == null || values.isEmpty()) { if (values == null || values.isEmpty()) {
continue; continue;

View File

@ -23,8 +23,9 @@ package ca.uhn.fhir.rest.annotation;
import java.lang.annotation.Retention; import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy; 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.IQueryParameterType;
import ca.uhn.fhir.model.api.IResource;
import ca.uhn.fhir.rest.param.CompositeParam; import ca.uhn.fhir.rest.param.CompositeParam;
import ca.uhn.fhir.rest.param.ReferenceParam; import ca.uhn.fhir.rest.param.ReferenceParam;
//import ca.uhn.fhir.testmodel.Patient; // TODO: qualify this correctly //import ca.uhn.fhir.testmodel.Patient; // TODO: qualify this correctly
@ -116,5 +117,5 @@ public @interface OptionalParam {
* this value must not be populated. * this value must not be populated.
* </p> * </p>
*/ */
Class<? extends IResource>[] targetTypes() default {}; Class<? extends IBaseResource>[] targetTypes() default {};
} }

View File

@ -23,8 +23,9 @@ package ca.uhn.fhir.rest.annotation;
import java.lang.annotation.Retention; import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy; 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.IQueryParameterType;
import ca.uhn.fhir.model.api.IResource;
import ca.uhn.fhir.rest.param.CompositeParam; import ca.uhn.fhir.rest.param.CompositeParam;
import ca.uhn.fhir.rest.param.ReferenceParam; import ca.uhn.fhir.rest.param.ReferenceParam;
//import ca.uhn.fhir.testmodel.Patient; // TODO: qualify this correctly //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. * If the parameter annotated with this annotation is not a {@link ReferenceParam}, this value must not be populated.
* </p> * </p>
*/ */
Class<? extends IResource>[] targetTypes() default {}; Class<? extends IBaseResource>[] targetTypes() default {};
} }

View File

@ -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 * 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. * 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; myId = theId;
myCreated = theCreated; myCreated = theCreated;
} }
@ -64,7 +64,7 @@ public class MethodOutcome {
* @param theBaseOperationOutcome * @param theBaseOperationOutcome
* The operation outcome to return with the response (or null for none) * 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; myId = theId;
myOperationOutcome = theBaseOperationOutcome; 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 * 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. * 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; myId = theId;
myOperationOutcome = theBaseOperationOutcome; myOperationOutcome = theBaseOperationOutcome;
myCreated = theCreated; 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 @Deprecated
public MethodOutcome(IdDt theId, IdDt theVersionId) { public MethodOutcome(IIdType theId, IdDt theVersionId) {
myId = theId; myId = theId;
myVersionId = theVersionId; 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 Use the constructor which accepts a single IdDt parameter, and include the logical ID and version ID in that IdDt instance
*/ */
@Deprecated @Deprecated
public MethodOutcome(IdDt theId, IdDt theVersionId, IBaseOperationOutcome theBaseOperationOutcome) { public MethodOutcome(IIdType theId, IdDt theVersionId, IBaseOperationOutcome theBaseOperationOutcome) {
myId = theId; myId = theId;
myVersionId = theVersionId; myVersionId = theVersionId;
myOperationOutcome = theBaseOperationOutcome; myOperationOutcome = theBaseOperationOutcome;
@ -175,7 +175,7 @@ public class MethodOutcome {
* @param theId * @param theId
* The ID of the created/updated resource * The ID of the created/updated resource
*/ */
public void setId(IdDt theId) { public void setId(IIdType theId) {
myId = 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 @Deprecated
public void setVersionId(IdDt theVersionId) { public void setVersionId(IdDt theVersionId) {

View File

@ -1,5 +1,7 @@
package ca.uhn.fhir.rest.client; package ca.uhn.fhir.rest.client;
import static org.apache.commons.lang3.StringUtils.isNotBlank;
/* /*
* #%L * #%L
* HAPI FHIR - Core Library * HAPI FHIR - Core Library
@ -47,6 +49,7 @@ import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpRequestBase; import org.apache.http.client.methods.HttpRequestBase;
import org.apache.http.entity.ContentType; import org.apache.http.entity.ContentType;
import org.hl7.fhir.instance.model.api.IBase; import org.hl7.fhir.instance.model.api.IBase;
import org.hl7.fhir.instance.model.api.IBaseOperationOutcome;
import org.hl7.fhir.instance.model.api.IBaseResource; import org.hl7.fhir.instance.model.api.IBaseResource;
import org.hl7.fhir.instance.model.api.IIdType; import org.hl7.fhir.instance.model.api.IIdType;
import org.hl7.fhir.instance.model.api.IPrimitiveType; import org.hl7.fhir.instance.model.api.IPrimitiveType;
@ -71,6 +74,7 @@ import ca.uhn.fhir.rest.method.MethodUtil;
import ca.uhn.fhir.rest.server.Constants; import ca.uhn.fhir.rest.server.Constants;
import ca.uhn.fhir.rest.server.EncodingEnum; import ca.uhn.fhir.rest.server.EncodingEnum;
import ca.uhn.fhir.rest.server.exceptions.BaseServerResponseException; import ca.uhn.fhir.rest.server.exceptions.BaseServerResponseException;
import ca.uhn.fhir.util.OperationOutcomeUtil;
public abstract class BaseClient implements IRestfulClient { public abstract class BaseClient implements IRestfulClient {
@ -284,7 +288,7 @@ public abstract class BaseClient implements IRestfulClient {
} }
String message = "HTTP " + response.getStatusLine().getStatusCode() + " " + response.getStatusLine().getReasonPhrase(); String message = "HTTP " + response.getStatusLine().getStatusCode() + " " + response.getStatusLine().getReasonPhrase();
BaseOperationOutcome oo = null; IBaseOperationOutcome oo = null;
if (Constants.CT_TEXT.equals(mimeType)) { if (Constants.CT_TEXT.equals(mimeType)) {
message = message + ": " + body; message = message + ": " + body;
} else { } else {
@ -293,9 +297,10 @@ public abstract class BaseClient implements IRestfulClient {
IParser p = enc.newParser(theContext); IParser p = enc.newParser(theContext);
try { try {
// TODO: handle if something other than OO comes back // TODO: handle if something other than OO comes back
oo = (BaseOperationOutcome) p.parseResource(body); oo = (IBaseOperationOutcome) p.parseResource(body);
if (oo.getIssueFirstRep().getDetailsElement().isEmpty() == false) { String details = OperationOutcomeUtil.getFirstIssueDetails(getFhirContext(), oo);
message = message + ": " + oo.getIssueFirstRep().getDetailsElement().getValue(); if (isNotBlank(details)) {
message = message + ": " + details;
} }
} catch (Exception e) { } catch (Exception e) {
ourLog.debug("Failed to process OperationOutcome response"); ourLog.debug("Failed to process OperationOutcome response");

View File

@ -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 " 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"); + "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");
} }

View File

@ -75,7 +75,7 @@ abstract class BaseAddOrDeleteTagsMethodBinding extends BaseMethodBinding<Void>
myResourceName = theConetxt.getResourceDefinition(myType).getName(); myResourceName = theConetxt.getResourceDefinition(myType).getName();
myIdParamIndex = MethodUtil.findIdParameterIndex(theMethod); myIdParamIndex = MethodUtil.findIdParameterIndex(theMethod, getContext());
myVersionIdParamIndex = MethodUtil.findVersionIdParameterIndex(theMethod); myVersionIdParamIndex = MethodUtil.findVersionIdParameterIndex(theMethod);
myTagListParamIndex = MethodUtil.findTagListParameterIndex(theMethod); myTagListParamIndex = MethodUtil.findTagListParameterIndex(theMethod);

View File

@ -33,6 +33,7 @@ import javax.servlet.http.HttpServletResponse;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.hl7.fhir.instance.model.api.IBaseResource; 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.ConfigurationException;
import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.context.FhirContext;
@ -267,12 +268,14 @@ abstract class BaseOutcomeReturningMethodBinding extends BaseMethodBinding<Metho
} }
} }
protected static void parseContentLocation(MethodOutcome theOutcomeToPopulate, String theResourceName, String theLocationHeader) { protected static void parseContentLocation(FhirContext theContext, MethodOutcome theOutcomeToPopulate, String theResourceName, String theLocationHeader) {
if (StringUtils.isBlank(theLocationHeader)) { if (StringUtils.isBlank(theLocationHeader)) {
return; return;
} }
theOutcomeToPopulate.setId(new IdDt(theLocationHeader)); IIdType id = theContext.getVersion().newIdType();
id.setValue(theLocationHeader);
theOutcomeToPopulate.setId(id);
String resourceNamePart = "/" + theResourceName + "/"; String resourceNamePart = "/" + theResourceName + "/";
int resourceIndex = theLocationHeader.lastIndexOf(resourceNamePart); int resourceIndex = theLocationHeader.lastIndexOf(resourceNamePart);

View File

@ -75,7 +75,7 @@ abstract class BaseOutcomeReturningMethodBindingWithResourceParam extends BaseOu
} }
myResourceName = theContext.getResourceDefinition(myResourceType).getName(); myResourceName = theContext.getResourceDefinition(myResourceType).getName();
myIdParamIndex = MethodUtil.findIdParameterIndex(theMethod); myIdParamIndex = MethodUtil.findIdParameterIndex(theMethod, getContext());
if (myIdParamIndex != null) { if (myIdParamIndex != null) {
myIdParamType = (Class<? extends IIdType>) theMethod.getParameterTypes()[myIdParamIndex]; myIdParamType = (Class<? extends IIdType>) theMethod.getParameterTypes()[myIdParamIndex];
} }

View File

@ -66,7 +66,7 @@ public class DeleteMethodBinding extends BaseOutcomeReturningMethodBinding {
} }
} }
myIdParameterIndex = MethodUtil.findIdParameterIndex(theMethod); myIdParameterIndex = MethodUtil.findIdParameterIndex(theMethod, getContext());
if (myIdParameterIndex == null) { if (myIdParameterIndex == null) {
throw new ConfigurationException("Method '" + theMethod.getName() + "' on type '" + theMethod.getDeclaringClass().getCanonicalName() + "' has no parameter annotated with the @" + IdParam.class.getSimpleName() + " annotation"); throw new ConfigurationException("Method '" + theMethod.getName() + "' on type '" + theMethod.getDeclaringClass().getCanonicalName() + "' has no parameter annotated with the @" + IdParam.class.getSimpleName() + " annotation");
} }

View File

@ -59,7 +59,7 @@ public class DynamicSearchMethodBinding extends BaseResourceReturningMethodBindi
myParamNames.add(next.getName()); myParamNames.add(next.getName());
} }
myIdParamIndex = MethodUtil.findIdParameterIndex(theMethod); myIdParamIndex = MethodUtil.findIdParameterIndex(theMethod, getContext());
} }

View File

@ -67,7 +67,7 @@ public class GetTagsMethodBinding extends BaseMethodBinding<TagList> {
myResourceName = theConetxt.getResourceDefinition(myType).getName(); myResourceName = theConetxt.getResourceDefinition(myType).getName();
} }
myIdParamIndex = MethodUtil.findIdParameterIndex(theMethod); myIdParamIndex = MethodUtil.findIdParameterIndex(theMethod, getContext());
myVersionIdParamIndex = MethodUtil.findVersionIdParameterIndex(theMethod); myVersionIdParamIndex = MethodUtil.findVersionIdParameterIndex(theMethod);
if (myIdParamIndex != null && myType.equals(IResource.class)) { if (myIdParamIndex != null && myType.equals(IResource.class)) {

View File

@ -55,7 +55,7 @@ public class HistoryMethodBinding extends BaseResourceReturningMethodBinding {
public HistoryMethodBinding(Method theMethod, FhirContext theConetxt, Object theProvider) { public HistoryMethodBinding(Method theMethod, FhirContext theConetxt, Object theProvider) {
super(toReturnType(theMethod, theProvider), theMethod, theConetxt, theProvider); super(toReturnType(theMethod, theProvider), theMethod, theConetxt, theProvider);
myIdParamIndex = MethodUtil.findIdParameterIndex(theMethod); myIdParamIndex = MethodUtil.findIdParameterIndex(theMethod, getContext());
History historyAnnotation = theMethod.getAnnotation(History.class); History historyAnnotation = theMethod.getAnnotation(History.class);
Class<? extends IBaseResource> type = historyAnnotation.type(); Class<? extends IBaseResource> type = historyAnnotation.type();

View File

@ -322,8 +322,20 @@ public class MethodUtil {
return MethodUtil.findParamAnnotationIndex(theMethod, ConditionalUrlParam.class); return MethodUtil.findParamAnnotationIndex(theMethod, ConditionalUrlParam.class);
} }
public static Integer findIdParameterIndex(Method theMethod) { public static Integer findIdParameterIndex(Method theMethod, FhirContext theContext) {
return MethodUtil.findParamAnnotationIndex(theMethod, IdParam.class); Integer index = MethodUtil.findParamAnnotationIndex(theMethod, IdParam.class);
if (index != null) {
Class<?> paramType = theMethod.getParameterTypes()[index];
if (IIdType.class.equals(paramType)) {
return index;
}
boolean isRi = theContext.getVersion().getVersion().isRi();
boolean usesHapiId = IdDt.class.equals(paramType);
if (isRi == usesHapiId) {
throw new ConfigurationException("Method uses the wrong Id datatype (IdDt / IdType) for the given context FHIR version: " + theMethod.toString());
}
}
return index;
} }
public static Integer findParamAnnotationIndex(Method theMethod, Class<?> toFind) { public static Integer findParamAnnotationIndex(Method theMethod, Class<?> toFind) {
@ -732,7 +744,7 @@ public class MethodUtil {
MethodOutcome retVal = new MethodOutcome(); MethodOutcome retVal = new MethodOutcome();
if (locationHeaders != null && locationHeaders.size() > 0) { if (locationHeaders != null && locationHeaders.size() > 0) {
String locationHeader = locationHeaders.get(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) { if (theResponseStatusCode != Constants.STATUS_HTTP_204_NO_CONTENT) {
EncodingEnum ct = EncodingEnum.forContentType(theResponseMimeType); EncodingEnum ct = EncodingEnum.forContentType(theResponseMimeType);

View File

@ -35,6 +35,7 @@ import org.hl7.fhir.instance.model.api.IBase;
import org.hl7.fhir.instance.model.api.IBaseDatatype; import org.hl7.fhir.instance.model.api.IBaseDatatype;
import org.hl7.fhir.instance.model.api.IBaseParameters; import org.hl7.fhir.instance.model.api.IBaseParameters;
import org.hl7.fhir.instance.model.api.IBaseResource; 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 org.hl7.fhir.instance.model.api.IPrimitiveType;
import ca.uhn.fhir.context.ConfigurationException; import ca.uhn.fhir.context.ConfigurationException;
@ -42,7 +43,6 @@ import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.context.FhirVersionEnum; import ca.uhn.fhir.context.FhirVersionEnum;
import ca.uhn.fhir.model.api.Bundle; import ca.uhn.fhir.model.api.Bundle;
import ca.uhn.fhir.model.api.annotation.Description; import ca.uhn.fhir.model.api.annotation.Description;
import ca.uhn.fhir.model.primitive.IdDt;
import ca.uhn.fhir.model.valueset.BundleTypeEnum; import ca.uhn.fhir.model.valueset.BundleTypeEnum;
import ca.uhn.fhir.rest.annotation.IdParam; import ca.uhn.fhir.rest.annotation.IdParam;
import ca.uhn.fhir.rest.annotation.Operation; import ca.uhn.fhir.rest.annotation.Operation;
@ -76,7 +76,7 @@ public class OperationMethodBinding extends BaseResourceReturningMethodBinding {
super(theReturnResourceType, theMethod, theContext, theProvider); super(theReturnResourceType, theMethod, theContext, theProvider);
myIdempotent = theIdempotent; myIdempotent = theIdempotent;
myIdParamIndex = MethodUtil.findIdParameterIndex(theMethod); myIdParamIndex = MethodUtil.findIdParameterIndex(theMethod, getContext());
if (myIdParamIndex != null) { if (myIdParamIndex != null) {
for (Annotation next : theMethod.getParameterAnnotations()[myIdParamIndex]) { for (Annotation next : theMethod.getParameterAnnotations()[myIdParamIndex]) {
if (next instanceof IdParam) { if (next instanceof IdParam) {
@ -230,7 +230,7 @@ public class OperationMethodBinding extends BaseResourceReturningMethodBinding {
public BaseHttpClientInvocation invokeClient(Object[] theArgs) throws InternalErrorException { public BaseHttpClientInvocation invokeClient(Object[] theArgs) throws InternalErrorException {
String id = null; String id = null;
if (myIdParamIndex != null) { if (myIdParamIndex != null) {
IdDt idDt = (IdDt) theArgs[myIdParamIndex]; IIdType idDt = (IIdType) theArgs[myIdParamIndex];
id = idDt.getValue(); id = idDt.getValue();
} }
IBaseParameters parameters = (IBaseParameters) getContext().getResourceDefinition("Parameters").newInstance(); IBaseParameters parameters = (IBaseParameters) getContext().getResourceDefinition("Parameters").newInstance();

View File

@ -43,6 +43,7 @@ import ca.uhn.fhir.context.RuntimeChildPrimitiveDatatypeDefinition;
import ca.uhn.fhir.context.RuntimePrimitiveDatatypeDefinition; import ca.uhn.fhir.context.RuntimePrimitiveDatatypeDefinition;
import ca.uhn.fhir.context.RuntimeResourceDefinition; import ca.uhn.fhir.context.RuntimeResourceDefinition;
import ca.uhn.fhir.i18n.HapiLocalizer; 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.annotation.OperationParam;
import ca.uhn.fhir.rest.api.RequestTypeEnum; import ca.uhn.fhir.rest.api.RequestTypeEnum;
import ca.uhn.fhir.rest.api.ValidationModeEnum; import ca.uhn.fhir.rest.api.ValidationModeEnum;
@ -66,7 +67,7 @@ public class OperationParameter implements IParameter {
private final String myOperationName; private final String myOperationName;
private Class<?> myParameterType; private Class<?> myParameterType;
private String myParamType; private String myParamType;
private FhirContext myContext; private final FhirContext myContext;
private boolean myAllowGet; private boolean myAllowGet;
public OperationParameter(FhirContext theCtx, String theOperationName, OperationParam theOperationParam) { 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() { public int getMax() {
return myMax; return myMax;
} }
@ -102,6 +107,12 @@ public class OperationParameter implements IParameter {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@Override @Override
public void initializeTypes(Method theMethod, Class<? extends Collection<?>> theOuterCollectionType, Class<? extends Collection<?>> theInnerCollectionType, Class<?> theParameterType) { public void initializeTypes(Method theMethod, Class<? extends Collection<?>> theOuterCollectionType, Class<? extends Collection<?>> 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; myParameterType = theParameterType;
if (theInnerCollectionType != null) { if (theInnerCollectionType != null) {
myInnerCollectionType = CollectionBinder.getInstantiableCollectionType(theInnerCollectionType, myName); myInnerCollectionType = CollectionBinder.getInstantiableCollectionType(theInnerCollectionType, myName);

View File

@ -72,7 +72,7 @@ public class ReadMethodBinding extends BaseResourceReturningMethodBinding implem
Validate.notNull(theMethod, "Method must not be null"); Validate.notNull(theMethod, "Method must not be null");
Integer idIndex = MethodUtil.findIdParameterIndex(theMethod); Integer idIndex = MethodUtil.findIdParameterIndex(theMethod, getContext());
Integer versionIdIndex = MethodUtil.findVersionIdParameterIndex(theMethod); Integer versionIdIndex = MethodUtil.findVersionIdParameterIndex(theMethod);
Class<?>[] parameterTypes = theMethod.getParameterTypes(); Class<?>[] parameterTypes = theMethod.getParameterTypes();

View File

@ -31,6 +31,8 @@ import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import org.hl7.fhir.instance.model.api.IIdType;
import ca.uhn.fhir.model.primitive.IdDt; import ca.uhn.fhir.model.primitive.IdDt;
import ca.uhn.fhir.rest.api.RequestTypeEnum; import ca.uhn.fhir.rest.api.RequestTypeEnum;
import ca.uhn.fhir.rest.api.RestOperationTypeEnum; import ca.uhn.fhir.rest.api.RestOperationTypeEnum;
@ -43,7 +45,7 @@ public abstract class RequestDetails {
private String myCompartmentName; private String myCompartmentName;
private String myCompleteUrl; private String myCompleteUrl;
private String myFhirServerBase; private String myFhirServerBase;
private IdDt myId; private IIdType myId;
private String myOperation; private String myOperation;
private Map<String, String[]> myParameters; private Map<String, String[]> myParameters;
private String myRequestPath; private String myRequestPath;
@ -72,7 +74,7 @@ public abstract class RequestDetails {
return myFhirServerBase; return myFhirServerBase;
} }
public IdDt getId() { public IIdType getId() {
return myId; return myId;
} }
@ -132,7 +134,7 @@ public abstract class RequestDetails {
myFhirServerBase = theFhirServerBase; myFhirServerBase = theFhirServerBase;
} }
public void setId(IdDt theId) { public void setId(IIdType theId) {
myId = theId; myId = theId;
} }

View File

@ -65,7 +65,7 @@ public class SearchMethodBinding extends BaseResourceReturningMethodBinding {
Search search = theMethod.getAnnotation(Search.class); Search search = theMethod.getAnnotation(Search.class);
this.myQueryName = StringUtils.defaultIfBlank(search.queryName(), null); this.myQueryName = StringUtils.defaultIfBlank(search.queryName(), null);
this.myCompartmentName = StringUtils.defaultIfBlank(search.compartmentName(), null); this.myCompartmentName = StringUtils.defaultIfBlank(search.compartmentName(), null);
this.myIdParamIndex = MethodUtil.findIdParameterIndex(theMethod); this.myIdParamIndex = MethodUtil.findIdParameterIndex(theMethod, getContext());
this.myAllowUnknownParams = search.allowUnknownParams(); this.myAllowUnknownParams = search.allowUnknownParams();
Description desc = theMethod.getAnnotation(Description.class); Description desc = theMethod.getAnnotation(Description.class);

View File

@ -30,13 +30,13 @@ import java.util.List;
import java.util.Set; import java.util.Set;
import org.apache.commons.lang3.builder.ToStringBuilder; 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.ConfigurationException;
import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.model.api.IQueryParameterAnd; import ca.uhn.fhir.model.api.IQueryParameterAnd;
import ca.uhn.fhir.model.api.IQueryParameterOr; import ca.uhn.fhir.model.api.IQueryParameterOr;
import ca.uhn.fhir.model.api.IQueryParameterType; 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.BaseIdentifierDt;
import ca.uhn.fhir.model.base.composite.BaseQuantityDt; import ca.uhn.fhir.model.base.composite.BaseQuantityDt;
import ca.uhn.fhir.model.primitive.StringDt; import ca.uhn.fhir.model.primitive.StringDt;
@ -133,7 +133,7 @@ public class SearchParameter extends BaseQueryParameter {
} }
private List<Class<? extends IQueryParameterType>> myCompositeTypes; private List<Class<? extends IQueryParameterType>> myCompositeTypes;
private List<Class<? extends IResource>> myDeclaredTypes; private List<Class<? extends IBaseResource>> myDeclaredTypes;
private String myDescription; private String myDescription;
private String myName; private String myName;
private IParamBinder<?> myParamBinder; private IParamBinder<?> myParamBinder;
@ -168,7 +168,7 @@ public class SearchParameter extends BaseQueryParameter {
return retVal; return retVal;
} }
public List<Class<? extends IResource>> getDeclaredTypes() { public List<Class<? extends IBaseResource>> getDeclaredTypes() {
return Collections.unmodifiableList(myDeclaredTypes); return Collections.unmodifiableList(myDeclaredTypes);
} }
@ -255,7 +255,7 @@ public class SearchParameter extends BaseQueryParameter {
myCompositeTypes = Arrays.asList(theCompositeTypes); myCompositeTypes = Arrays.asList(theCompositeTypes);
} }
public void setDeclaredTypes(Class<? extends IResource>[] theTypes) { public void setDeclaredTypes(Class<? extends IBaseResource>[] theTypes) {
myDeclaredTypes = Arrays.asList(theTypes); myDeclaredTypes = Arrays.asList(theTypes);
} }

View File

@ -1,6 +1,5 @@
package ca.uhn.fhir.rest.method; package ca.uhn.fhir.rest.method;
import static org.apache.commons.lang3.StringUtils.isBlank;
/* /*
* #%L * #%L
* HAPI FHIR - Core Library * HAPI FHIR - Core Library
@ -26,6 +25,8 @@ import java.lang.reflect.Method;
import java.util.Collections; import java.util.Collections;
import java.util.Set; import java.util.Set;
import org.hl7.fhir.instance.model.api.IIdType;
import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.model.api.IResource; import ca.uhn.fhir.model.api.IResource;
import ca.uhn.fhir.model.primitive.IdDt; import ca.uhn.fhir.model.primitive.IdDt;
@ -44,7 +45,7 @@ public class UpdateMethodBinding extends BaseOutcomeReturningMethodBindingWithRe
public UpdateMethodBinding(Method theMethod, FhirContext theContext, Object theProvider) { public UpdateMethodBinding(Method theMethod, FhirContext theContext, Object theProvider) {
super(theMethod, theContext, Update.class, theProvider); super(theMethod, theContext, Update.class, theProvider);
myIdParameterIndex = MethodUtil.findIdParameterIndex(theMethod); myIdParameterIndex = MethodUtil.findIdParameterIndex(theMethod, getContext());
} }
@Override @Override
@ -59,9 +60,9 @@ public class UpdateMethodBinding extends BaseOutcomeReturningMethodBindingWithRe
* Content-Location header, but we allow it in the PUT URL as well.. * Content-Location header, but we allow it in the PUT URL as well..
*/ */
String locationHeader = theRequest.getHeader(Constants.HEADER_CONTENT_LOCATION); String locationHeader = theRequest.getHeader(Constants.HEADER_CONTENT_LOCATION);
IdDt id = theRequest.getId(); IIdType id = theRequest.getId();
if (isNotBlank(locationHeader)) { if (isNotBlank(locationHeader)) {
id = new IdDt(locationHeader); id.setValue(locationHeader);
if (isNotBlank(id.getResourceType())) { if (isNotBlank(id.getResourceType())) {
if (!getResourceName().equals(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); 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)) { if (isNotBlank(locationHeader)) {
MethodOutcome mo = new MethodOutcome(); MethodOutcome mo = new MethodOutcome();
parseContentLocation(mo, getResourceName(), locationHeader); parseContentLocation(getContext(), mo, getResourceName(), locationHeader);
if (mo.getId() == null || mo.getId().isEmpty()) { if (mo.getId() == null || mo.getId().isEmpty()) {
throw new InvalidRequestException("Invalid Content-Location header for resource " + getResourceName() + ": " + locationHeader); throw new InvalidRequestException("Invalid Content-Location header for resource " + getResourceName() + ": " + locationHeader);
} }

View File

@ -40,7 +40,7 @@ public class ValidateMethodBindingDstu1 extends BaseOutcomeReturningMethodBindin
public ValidateMethodBindingDstu1(Method theMethod, FhirContext theContext, Object theProvider) { public ValidateMethodBindingDstu1(Method theMethod, FhirContext theContext, Object theProvider) {
super(theMethod, theContext, Validate.class, theProvider); super(theMethod, theContext, Validate.class, theProvider);
myIdParameterIndex = MethodUtil.findIdParameterIndex(theMethod); myIdParameterIndex = MethodUtil.findIdParameterIndex(theMethod, getContext());
} }
@Override @Override

View File

@ -25,6 +25,7 @@ import java.util.Date;
import java.util.List; import java.util.List;
import org.apache.commons.lang3.Validate; 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.IQueryParameterOr;
import ca.uhn.fhir.model.api.IQueryParameterType; 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); setValueAsString(theDate != null ? theDate.getValueAsString() : null);
} }
/**
* Constructor
*/
public DateParam(QuantityCompararatorEnum theComparator, IPrimitiveType<Date> theDate) {
myComparator = theComparator;
setValueAsString(theDate != null ? theDate.getValueAsString() : null);
}
/** /**
* Constructor * Constructor
*/ */

View File

@ -24,6 +24,8 @@ import java.util.ArrayList;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import org.hl7.fhir.instance.model.api.IPrimitiveType;
import ca.uhn.fhir.model.api.IQueryParameterAnd; import ca.uhn.fhir.model.api.IQueryParameterAnd;
import ca.uhn.fhir.model.dstu.valueset.QuantityCompararatorEnum; import ca.uhn.fhir.model.dstu.valueset.QuantityCompararatorEnum;
import ca.uhn.fhir.model.primitive.DateTimeDt; import ca.uhn.fhir.model.primitive.DateTimeDt;
@ -106,6 +108,20 @@ public class DateRangeParam implements IQueryParameterAnd<DateParam> {
setRangeFromDatesInclusive(theLowerBound, theUpperBound); 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<Date> theLowerBound, IPrimitiveType<Date> theUpperBound) {
setRangeFromDatesInclusive(theLowerBound, theUpperBound);
}
/** /**
* Constructor which takes two strings representing the lower and upper bounds of the range (inclusive on both ends) * 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<DateParam> {
validateAndThrowDataFormatExceptionIfInvalid(); 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<Date> theLowerBound, IPrimitiveType<Date> 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 * Sets the range from a pair of dates, inclusive on both ends
* *

View File

@ -116,6 +116,16 @@ public class QuantityParam extends BaseParam implements IQueryParameterType {
setValueAsQueryToken(null, theQuantity); setValueAsQueryToken(null, theQuantity);
} }
/**
* Constructor
*
* @param theQuantity
* A quantity value (with no system or units), such as <code>100</code>
*/
public QuantityParam(long theQuantity) {
setValueAsQueryToken(null, Long.toString(theQuantity));
}
/** /**
* Constructor * Constructor
* *

View File

@ -50,12 +50,12 @@ import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.Validate; import org.apache.commons.lang3.Validate;
import org.hl7.fhir.instance.model.api.IBaseResource; 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.ConfigurationException;
import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.context.ProvidedResourceScanner; import ca.uhn.fhir.context.ProvidedResourceScanner;
import ca.uhn.fhir.context.RuntimeResourceDefinition; import ca.uhn.fhir.context.RuntimeResourceDefinition;
import ca.uhn.fhir.model.primitive.IdDt;
import ca.uhn.fhir.parser.IParser; import ca.uhn.fhir.parser.IParser;
import ca.uhn.fhir.rest.annotation.Destroy; import ca.uhn.fhir.rest.annotation.Destroy;
import ca.uhn.fhir.rest.annotation.IdParam; 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.api.RequestTypeEnum;
import ca.uhn.fhir.rest.method.BaseMethodBinding; import ca.uhn.fhir.rest.method.BaseMethodBinding;
import ca.uhn.fhir.rest.method.ConformanceMethodBinding; 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.ParseAction;
import ca.uhn.fhir.rest.method.RequestDetails; import ca.uhn.fhir.rest.method.RequestDetails;
import ca.uhn.fhir.rest.server.exceptions.AuthenticationException; import ca.uhn.fhir.rest.server.exceptions.AuthenticationException;
@ -565,13 +564,14 @@ public class RestfulServer extends HttpServlet implements IRestfulServer<Servlet
Map<String, String[]> params = new HashMap<String, String[]>(theRequest.getParameterMap()); Map<String, String[]> params = new HashMap<String, String[]>(theRequest.getParameterMap());
requestDetails.setParameters(params); requestDetails.setParameters(params);
IdDt id; IIdType id;
populateRequestDetailsFromRequestPath(requestDetails, requestPath); populateRequestDetailsFromRequestPath(requestDetails, requestPath);
if (theRequestType == RequestTypeEnum.PUT) { if (theRequestType == RequestTypeEnum.PUT) {
String contentLocation = theRequest.getHeader(Constants.HEADER_CONTENT_LOCATION); String contentLocation = theRequest.getHeader(Constants.HEADER_CONTENT_LOCATION);
if (contentLocation != null) { if (contentLocation != null) {
id = new IdDt(contentLocation); id = myFhirContext.getVersion().newIdType();
id.setValue(contentLocation);
requestDetails.setId(id); requestDetails.setId(id);
} }
} }
@ -876,7 +876,7 @@ public class RestfulServer extends HttpServlet implements IRestfulServer<Servlet
StringTokenizer tok = new StringTokenizer(theRequestPath, "/"); StringTokenizer tok = new StringTokenizer(theRequestPath, "/");
String resourceName = null; String resourceName = null;
IdDt id = null; IIdType id = null;
String operation = null; String operation = null;
String compartment = null; String compartment = null;
if (tok.hasMoreTokens()) { if (tok.hasMoreTokens()) {
@ -893,7 +893,8 @@ public class RestfulServer extends HttpServlet implements IRestfulServer<Servlet
if (partIsOperation(nextString)) { if (partIsOperation(nextString)) {
operation = nextString; operation = nextString;
} else { } else {
id = new IdDt(resourceName, UrlUtil.unescape(nextString)); id = myFhirContext.getVersion().newIdType();
id.setParts(null, resourceName, UrlUtil.unescape(nextString), null);
} }
} }
@ -905,7 +906,7 @@ public class RestfulServer extends HttpServlet implements IRestfulServer<Servlet
if (id == null) { if (id == null) {
throw new InvalidRequestException("Don't know how to handle request path: " + theRequestPath); throw new InvalidRequestException("Don't know how to handle request path: " + theRequestPath);
} }
id = new IdDt(resourceName, id.getIdPart(), UrlUtil.unescape(versionString)); id.setParts(null, resourceName, id.getIdPart(), UrlUtil.unescape(versionString));
} else { } else {
operation = Constants.PARAM_HISTORY; operation = Constants.PARAM_HISTORY;
} }

View File

@ -24,6 +24,8 @@ import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
import org.hl7.fhir.instance.model.api.IPrimitiveType;
import ca.uhn.fhir.model.primitive.StringDt; import ca.uhn.fhir.model.primitive.StringDt;
public class DatatypeUtil { public class DatatypeUtil {
@ -46,9 +48,9 @@ public class DatatypeUtil {
/** /**
* Joins a list of strings with a single space (' ') between each string * Joins a list of strings with a single space (' ') between each string
*/ */
public static String joinStringsSpaceSeparated(List<StringDt> theStrings) { public static String joinStringsSpaceSeparated(List<? extends IPrimitiveType<String>> theStrings) {
StringBuilder b = new StringBuilder(); StringBuilder b = new StringBuilder();
for (StringDt next : theStrings) { for (IPrimitiveType<String> next : theStrings) {
if (next.isEmpty()) { if (next.isEmpty()) {
continue; continue;
} }

View File

@ -30,8 +30,12 @@ import java.util.TreeSet;
import org.apache.commons.lang3.Validate; import org.apache.commons.lang3.Validate;
import org.hl7.fhir.instance.model.api.IBase; 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.IBaseReference;
import org.hl7.fhir.instance.model.api.IBaseResource; 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 org.hl7.fhir.instance.model.api.IPrimitiveType;
import ca.uhn.fhir.context.BaseRuntimeChildDefinition; import ca.uhn.fhir.context.BaseRuntimeChildDefinition;
@ -68,6 +72,21 @@ public class FhirTerser {
addUndeclaredExtensions(nextExt, theDefinition, theChildDefinition, theCallback); 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);
}
}
} }
/** /**

View File

@ -23,6 +23,7 @@ package ca.uhn.fhir.util;
import java.util.List; import java.util.List;
import org.hl7.fhir.instance.model.api.IBase; 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 org.hl7.fhir.instance.model.api.IBaseResource;
import ca.uhn.fhir.context.BaseRuntimeChildDefinition; import ca.uhn.fhir.context.BaseRuntimeChildDefinition;
@ -52,6 +53,4 @@ public interface IModelVisitor {
*/ */
void acceptUndeclaredExtension(ISupportsUndeclaredExtensions theContainingElement, List<String> thePathToElement, BaseRuntimeChildDefinition theChildDefinition, BaseRuntimeElementDefinition<?> theDefinition, ExtensionDt theNextExt); void acceptUndeclaredExtension(ISupportsUndeclaredExtensions theContainingElement, List<String> thePathToElement, BaseRuntimeChildDefinition theChildDefinition, BaseRuntimeElementDefinition<?> theDefinition, ExtensionDt theNextExt);
} }

View File

@ -160,7 +160,8 @@ public class OperationOutcomeUtil {
} else { } else {
detailsChild = issueElement.getChildByName("details"); detailsChild = issueElement.getChildByName("details");
} }
BaseRuntimeElementDefinition<?> stringDef = theCtx.getElementDefinition("string");
BaseRuntimeElementDefinition<?> stringDef = detailsChild.getChildByName(detailsChild.getElementName());
BaseRuntimeChildDefinition severityChild = issueElement.getChildByName("severity"); BaseRuntimeChildDefinition severityChild = issueElement.getChildByName("severity");
BaseRuntimeChildDefinition locationChild = issueElement.getChildByName("location"); BaseRuntimeChildDefinition locationChild = issueElement.getChildByName("location");

View File

@ -69,7 +69,7 @@ public class ParametersUtil {
IBase parameter = paramChildElem.newInstance(); IBase parameter = paramChildElem.newInstance();
paramChild.getMutator().addValue(theTargetResource, parameter); paramChild.getMutator().addValue(theTargetResource, parameter);
IPrimitiveType<?> value; IPrimitiveType<?> value;
if (theContext.getVersion().getVersion().equals(FhirVersionEnum.DSTU2_HL7ORG)) { if (theContext.getVersion().getVersion().isRi()) {
value = (IPrimitiveType<?>) theContext.getElementDefinition("string").newInstance(theName); value = (IPrimitiveType<?>) theContext.getElementDefinition("string").newInstance(theName);
} else { } else {
value = new StringDt(theName); value = new StringDt(theName);

View File

@ -1,5 +1,8 @@
package org.hl7.fhir.instance.model.api; package org.hl7.fhir.instance.model.api;
import ca.uhn.fhir.model.api.annotation.SearchParamDefinition;
import ca.uhn.fhir.rest.gclient.StringClientParam;
/* /*
* #%L * #%L
* HAPI FHIR - Core Library * HAPI FHIR - Core Library
@ -20,15 +23,45 @@ package org.hl7.fhir.instance.model.api;
* #L% * #L%
*/ */
public interface IAnyResource extends IBaseResource { public interface IAnyResource extends IBaseResource {
/**
* Search parameter constant for <b>_language</b>
*/
@SearchParamDefinition(name="_language", path="", description="The language of the resource", type="string" )
public static final String SP_RES_LANGUAGE = "_language";
/**
* Search parameter constant for <b>_id</b>
*/
@SearchParamDefinition(name="_id", path="", description="The ID of the resource", type="string" )
public static final String SP_RES_ID = "_id";
/**
* <b>Fluent Client</b> search parameter constant for <b>_id</b>
* <p>
* Description: <b>the _id of a resource</b><br>
* Type: <b>string</b><br>
* Path: <b>Resource._id</b><br>
* </p>
*/
public static final StringClientParam RES_ID = new StringClientParam(IAnyResource.SP_RES_ID);
String getId(); String getId();
IAnyResource setId(String theId); @Override
IIdType getIdElement(); IIdType getIdElement();
IPrimitiveType<String> getLanguageElement();
IBaseMetaType getMeta(); IBaseMetaType getMeta();
public Object getUserData(String name);
@Override
IAnyResource setId(String theId);
public void setUserData(String name, Object value);
} }

View File

@ -1,5 +1,7 @@
package org.hl7.fhir.instance.model.api; package org.hl7.fhir.instance.model.api;
import ca.uhn.fhir.model.api.IElement;
/* /*
* #%L * #%L
* HAPI FHIR - Core Library * 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 {
} }

View File

@ -20,7 +20,7 @@ package org.hl7.fhir.instance.model.api;
* #L% * #L%
*/ */
public interface IBaseCoding { public interface IBaseCoding extends IBase {
String getCode(); String getCode();

View File

@ -1,5 +1,7 @@
package org.hl7.fhir.instance.model.api; package org.hl7.fhir.instance.model.api;
import ca.uhn.fhir.model.api.IElement;
/* /*
* #%L * #%L
* HAPI FHIR - Core Library * 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 {
} }

View File

@ -45,4 +45,16 @@ public interface IBaseMetaType extends ICompositeType {
IBaseMetaType setVersionId(String theVersionId); IBaseMetaType setVersionId(String theVersionId);
/**
* Returns the first tag (if any) that has the given system and code, or returns
* <code>null</code> if none
*/
IBaseCoding getTag(String theSystem, String theCode);
/**
* Returns the first security label (if any) that has the given system and code, or returns
* <code>null</code> if none
*/
IBaseCoding getSecurity(String theSystem, String theCode);
} }

View File

@ -1,5 +1,13 @@
package org.hl7.fhir.instance.model.api; 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 * #%L
@ -29,7 +37,17 @@ package org.hl7.fhir.instance.model.api;
* the second are HAPI's Resource structures, e.g. * the second are HAPI's Resource structures, e.g.
* <code>ca.uhn.fhir.model.dstu.resource.Patient</code>) * <code>ca.uhn.fhir.model.dstu.resource.Patient</code>)
*/ */
public interface IBaseResource extends IBase { public interface IBaseResource extends IBase, IElement {
/**
* Include constant for <code>*</code> (return all includes)
*/
public static final Include INCLUDE_ALL = new Include("*", false).toLocked();
/**
* Include set containing only {@link #INCLUDE_ALL}
*/
public static final Set<Include> WILDCARD_ALL_SET = Collections.unmodifiableSet(new HashSet<Include>(Arrays.asList(INCLUDE_ALL)));
IIdType getIdElement(); IIdType getIdElement();
@ -37,4 +55,6 @@ public interface IBaseResource extends IBase {
IBaseResource setId(IIdType theId); IBaseResource setId(IIdType theId);
FhirVersionEnum getStructureFhirVersionEnum();
} }

View File

@ -22,7 +22,7 @@ package org.hl7.fhir.instance.model.api;
import java.util.List; import java.util.List;
public interface IDomainResource extends IAnyResource { public interface IDomainResource extends IAnyResource, IBaseHasExtensions, IBaseHasModifierExtensions {
List<? extends IAnyResource> getContained(); List<? extends IAnyResource> getContained();

View File

@ -135,4 +135,20 @@ public interface IIdType {
IIdType withVersion(String theVersion); IIdType withVersion(String theVersion);
/**
* Sets the value of this ID by combining all of the individual parts.
* <p>
* <b>Required parameters:</b> The following rules apply to the parameters of this method (in this case, populated means
* a non-empty string and not populated means <code>null</code> or an empty string)
* </p>
* <ul>
* <li>All values may be not populated</li>
* <li>If <b>theVersionIdPart</b> is populated, <b>theResourceType</b> and <b>theIdPart</b> must be populated</li>
* <li>If <b>theBaseUrl</b> is populated and <b>theIdPart</b> is populated, <b>theResourceType</b> must be populated</li>
* </ul>
*
* @return Returns a reference to <code>this</code> for easy method chaining
*/
IIdType setParts(String theBaseUrl, String theResourceType, String theIdPart, String theVersionIdPart);
} }

View File

@ -1,15 +1,15 @@
package ca.uhn.fhir.cli; package ca.uhn.fhir.cli;
import org.hl7.fhir.instance.model.ValueSet; import org.hl7.fhir.dstu21.hapi.validation.IValidationSupport;
import org.hl7.fhir.instance.model.ValueSet.ConceptSetComponent; import org.hl7.fhir.dstu21.model.ValueSet;
import org.hl7.fhir.instance.model.ValueSet.ValueSetExpansionComponent; import org.hl7.fhir.dstu21.model.ValueSet.ConceptSetComponent;
import org.hl7.fhir.dstu21.model.ValueSet.ValueSetExpansionComponent;
import org.hl7.fhir.instance.model.api.IBaseResource; import org.hl7.fhir.instance.model.api.IBaseResource;
import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.rest.client.IGenericClient; import ca.uhn.fhir.rest.client.IGenericClient;
import ca.uhn.fhir.rest.client.ServerValidationModeEnum; import ca.uhn.fhir.rest.client.ServerValidationModeEnum;
import ca.uhn.fhir.rest.server.exceptions.BaseServerResponseException; import ca.uhn.fhir.rest.server.exceptions.BaseServerResponseException;
import ca.uhn.fhir.validation.IValidationSupport;
public class LoadingValidationSupport implements IValidationSupport { public class LoadingValidationSupport implements IValidationSupport {

View File

@ -4,15 +4,13 @@ import static org.apache.commons.lang3.StringUtils.defaultString;
import static org.apache.commons.lang3.StringUtils.isBlank; import static org.apache.commons.lang3.StringUtils.isBlank;
import static org.apache.commons.lang3.StringUtils.isNotBlank; import static org.apache.commons.lang3.StringUtils.isNotBlank;
import static org.apache.commons.lang3.StringUtils.leftPad; import static org.apache.commons.lang3.StringUtils.leftPad;
import static org.fusesource.jansi.Ansi.*; import static org.fusesource.jansi.Ansi.ansi;
import java.io.File; import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.FileReader; import java.io.FileReader;
import java.io.IOException; import java.io.IOException;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.Map;
import org.apache.commons.cli.CommandLine; import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.Option; import org.apache.commons.cli.Option;
@ -21,24 +19,20 @@ import org.apache.commons.cli.Options;
import org.apache.commons.cli.ParseException; import org.apache.commons.cli.ParseException;
import org.apache.commons.io.IOUtils; import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.text.WordUtils; import org.apache.commons.lang3.text.WordUtils;
import org.fusesource.jansi.Ansi; import org.fusesource.jansi.Ansi.Color;
import org.hl7.fhir.dstu21.hapi.validation.DefaultProfileValidationSupport;
import org.hl7.fhir.dstu21.hapi.validation.FhirInstanceValidator;
import org.hl7.fhir.dstu21.hapi.validation.ValidationSupportChain;
import org.hl7.fhir.dstu21.model.StructureDefinition;
import com.phloc.commons.io.file.FileUtils; import com.phloc.commons.io.file.FileUtils;
import com.sun.tools.corba.se.idl.ParameterEntry;
import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.model.dstu2.resource.StructureDefinition;
import ca.uhn.fhir.rest.method.MethodUtil; import ca.uhn.fhir.rest.method.MethodUtil;
import ca.uhn.fhir.rest.param.ParameterUtil;
import ca.uhn.fhir.rest.server.EncodingEnum; import ca.uhn.fhir.rest.server.EncodingEnum;
import ca.uhn.fhir.validation.DefaultProfileValidationSupport;
import ca.uhn.fhir.validation.FhirInstanceValidator;
import ca.uhn.fhir.validation.FhirValidator; import ca.uhn.fhir.validation.FhirValidator;
import ca.uhn.fhir.validation.SingleValidationMessage; import ca.uhn.fhir.validation.SingleValidationMessage;
import ca.uhn.fhir.validation.ValidationResult; import ca.uhn.fhir.validation.ValidationResult;
import ca.uhn.fhir.validation.ValidationSupportChain;
import net.sf.saxon.expr.instruct.LocalParam;
import net.sf.saxon.om.Chain;
public class ValidateCommand extends BaseCommand { public class ValidateCommand extends BaseCommand {
@ -112,7 +106,7 @@ public class ValidateCommand extends BaseCommand {
throw new ParseException("Failed to load file '" + localProfile + "' - Error: " + e.toString()); throw new ParseException("Failed to load file '" + localProfile + "' - Error: " + e.toString());
} }
org.hl7.fhir.instance.model.StructureDefinition sd = (org.hl7.fhir.instance.model.StructureDefinition) MethodUtil.detectEncodingNoDefault(input).newParser(FhirContext.forDstu2Hl7Org()).parseResource(input); StructureDefinition sd = (StructureDefinition) MethodUtil.detectEncodingNoDefault(input).newParser(getFhirCtx()).parseResource(input);
instanceValidator.setStructureDefintion(sd); instanceValidator.setStructureDefintion(sd);
} }
if (theCommandLine.hasOption("r")) { if (theCommandLine.hasOption("r")) {

View File

@ -404,6 +404,11 @@
<artifactId>hapi-fhir-structures-dstu2.1</artifactId> <artifactId>hapi-fhir-structures-dstu2.1</artifactId>
<version>1.4-SNAPSHOT</version> <version>1.4-SNAPSHOT</version>
</dependency> </dependency>
<dependency>
<groupId>ca.uhn.hapi.fhir</groupId>
<artifactId>hapi-fhir-validation-resources-dstu2.1</artifactId>
<version>1.4-SNAPSHOT</version>
</dependency>
</dependencies> </dependencies>
</plugin> </plugin>
</plugins> </plugins>

View File

@ -42,7 +42,7 @@ public class BaseDstu21Config extends BaseConfig {
} }
@Bean(name = "mySystemDaoDstu21", autowire = Autowire.BY_NAME) @Bean(name = "mySystemDaoDstu21", autowire = Autowire.BY_NAME)
public IFhirSystemDao<ca.uhn.fhir.model.dstu21.resource.Bundle, ca.uhn.fhir.model.dstu21.composite.MetaDt> systemDaoDstu21() { public IFhirSystemDao<org.hl7.fhir.dstu21.model.Bundle, org.hl7.fhir.dstu21.model.Meta> systemDaoDstu21() {
ca.uhn.fhir.jpa.dao.FhirSystemDaoDstu21 retVal = new ca.uhn.fhir.jpa.dao.FhirSystemDaoDstu21(); ca.uhn.fhir.jpa.dao.FhirSystemDaoDstu21 retVal = new ca.uhn.fhir.jpa.dao.FhirSystemDaoDstu21();
return retVal; return retVal;
} }
@ -55,7 +55,7 @@ public class BaseDstu21Config extends BaseConfig {
} }
@Bean(name = "myJpaValidationSupportDstu21", autowire = Autowire.BY_NAME) @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(); ca.uhn.fhir.jpa.dao.JpaValidationSupportDstu21 retVal = new ca.uhn.fhir.jpa.dao.JpaValidationSupportDstu21();
return retVal; return retVal;
} }

View File

@ -56,7 +56,7 @@ public class BaseDstu2Config extends BaseConfig {
} }
@Bean(name = "myJpaValidationSupportDstu2", autowire = Autowire.BY_NAME) @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(); ca.uhn.fhir.jpa.dao.JpaValidationSupportDstu2 retVal = new ca.uhn.fhir.jpa.dao.JpaValidationSupportDstu2();
return retVal; return retVal;
} }

View File

@ -53,8 +53,15 @@ import org.apache.commons.lang3.NotImplementedException;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.apache.http.NameValuePair; import org.apache.http.NameValuePair;
import org.apache.http.client.utils.URLEncodedUtils; 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.IBaseOperationOutcome;
import org.hl7.fhir.instance.model.api.IBaseReference;
import org.hl7.fhir.instance.model.api.IBaseResource; 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.IIdType;
import org.hl7.fhir.instance.model.api.IPrimitiveType; import org.hl7.fhir.instance.model.api.IPrimitiveType;
import org.springframework.beans.factory.annotation.Autowired; 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.IdDt;
import ca.uhn.fhir.model.primitive.InstantDt; import ca.uhn.fhir.model.primitive.InstantDt;
import ca.uhn.fhir.model.primitive.StringDt; 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.model.valueset.BundleEntryTransactionMethodEnum;
import ca.uhn.fhir.parser.DataFormatException; import ca.uhn.fhir.parser.DataFormatException;
import ca.uhn.fhir.parser.IParser; import ca.uhn.fhir.parser.IParser;
@ -167,7 +175,6 @@ public abstract class BaseHapiFhirDao<T extends IBaseResource> implements IDao {
RESOURCE_META_AND_PARAMS = Collections.unmodifiableMap(resourceMetaAndParams); RESOURCE_META_AND_PARAMS = Collections.unmodifiableMap(resourceMetaAndParams);
} }
public static final long INDEX_STATUS_INDEXED = Long.valueOf(1L); public static final long INDEX_STATUS_INDEXED = Long.valueOf(1L);
public static final long INDEX_STATUS_INDEXING_FAILED = Long.valueOf(2L); 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"; public static final String NS_JPA_PROFILE = "https://github.com/jamesagnew/hapi-fhir/ns/jpa/profile";
@ -230,8 +237,7 @@ public abstract class BaseHapiFhirDao<T extends IBaseResource> implements IDao {
// myResourceDaos = theResourceDaos; // myResourceDaos = theResourceDaos;
// } // }
protected Set<ResourceLink> extractResourceLinks(ResourceTable theEntity, IBaseResource theResource) {
protected Set<ResourceLink> extractResourceLinks(ResourceTable theEntity, IResource theResource) {
Set<ResourceLink> retVal = new HashSet<ResourceLink>(); Set<ResourceLink> retVal = new HashSet<ResourceLink>();
RuntimeResourceDefinition def = getContext().getResourceDefinition(theResource); RuntimeResourceDefinition def = getContext().getResourceDefinition(theResource);
@ -262,31 +268,31 @@ public abstract class BaseHapiFhirDao<T extends IBaseResource> implements IDao {
} }
ResourceLink nextEntity; ResourceLink nextEntity;
if (nextObject instanceof BaseResourceReferenceDt) { if (nextObject instanceof IBaseReference) {
BaseResourceReferenceDt nextValue = (BaseResourceReferenceDt) nextObject; IBaseReference nextValue = (IBaseReference) nextObject;
if (nextValue.isEmpty()) { if (nextValue.isEmpty()) {
continue; 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 // This is a blank or contained resource reference
continue; continue;
} }
String typeString = nextValue.getReference().getResourceType(); String typeString = nextValue.getReferenceElement().getResourceType();
if (isBlank(typeString)) { 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; RuntimeResourceDefinition resourceDefinition;
try { try {
resourceDefinition = getContext().getResourceDefinition(typeString); resourceDefinition = getContext().getResourceDefinition(typeString);
} catch (DataFormatException e) { } 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<? extends IBaseResource> type = resourceDefinition.getImplementingClass(); Class<? extends IBaseResource> type = resourceDefinition.getImplementingClass();
String id = nextValue.getReference().getIdPart(); String id = nextValue.getReferenceElement().getIdPart();
if (StringUtils.isBlank(id)) { 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); IFhirResourceDao<?> dao = getDao(type);
@ -295,7 +301,7 @@ public abstract class BaseHapiFhirDao<T extends IBaseResource> implements IDao {
b.append("This server (version "); b.append("This server (version ");
b.append(myContext.getVersion().getVersion()); b.append(myContext.getVersion().getVersion());
b.append(") is not able to handle resources of type["); 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("] - Valid resource types for this server: ");
b.append(myResourceTypeToDao.keySet().toString()); b.append(myResourceTypeToDao.keySet().toString());
@ -303,7 +309,7 @@ public abstract class BaseHapiFhirDao<T extends IBaseResource> implements IDao {
} }
Long valueOf; Long valueOf;
try { try {
valueOf = translateForcedIdToPid(nextValue.getReference()); valueOf = translateForcedIdToPid(nextValue.getReferenceElement());
} catch (ResourceNotFoundException e) { } catch (ResourceNotFoundException e) {
String resName = getContext().getResourceDefinition(type).getName(); String resName = getContext().getResourceDefinition(type).getName();
throw new InvalidRequestException("Resource " + resName + "/" + id + " not found, specified in path: " + nextPathsUnsplit); throw new InvalidRequestException("Resource " + resName + "/" + id + " not found, specified in path: " + nextPathsUnsplit);
@ -316,7 +322,7 @@ public abstract class BaseHapiFhirDao<T extends IBaseResource> implements IDao {
} }
if (!typeString.equals(target.getResourceType())) { 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<T extends IBaseResource> implements IDao {
return retVal; return retVal;
} }
protected Set<ResourceIndexedSearchParamDate> extractSearchParamDates(ResourceTable theEntity, IResource theResource) { protected Set<ResourceIndexedSearchParamDate> extractSearchParamDates(ResourceTable theEntity, IBaseResource theResource) {
return mySearchParamExtractor.extractSearchParamDates(theEntity, theResource); return mySearchParamExtractor.extractSearchParamDates(theEntity, theResource);
} }
protected Set<ResourceIndexedSearchParamNumber> extractSearchParamNumber(ResourceTable theEntity, IResource theResource) { protected Set<ResourceIndexedSearchParamNumber> extractSearchParamNumber(ResourceTable theEntity, IBaseResource theResource) {
return mySearchParamExtractor.extractSearchParamNumber(theEntity, theResource); return mySearchParamExtractor.extractSearchParamNumber(theEntity, theResource);
} }
protected Set<ResourceIndexedSearchParamUri> extractSearchParamUri(ResourceTable theEntity, IResource theResource) { protected Set<ResourceIndexedSearchParamUri> extractSearchParamUri(ResourceTable theEntity, IBaseResource theResource) {
return mySearchParamExtractor.extractSearchParamUri(theEntity, theResource); return mySearchParamExtractor.extractSearchParamUri(theEntity, theResource);
} }
protected Set<ResourceIndexedSearchParamCoords> extractSearchParamCoords(ResourceTable theEntity, IResource theResource) { protected Set<ResourceIndexedSearchParamCoords> extractSearchParamCoords(ResourceTable theEntity, IBaseResource theResource) {
return mySearchParamExtractor.extractSearchParamCoords(theEntity, theResource); return mySearchParamExtractor.extractSearchParamCoords(theEntity, theResource);
} }
protected Set<ResourceIndexedSearchParamQuantity> extractSearchParamQuantity(ResourceTable theEntity, IResource theResource) { protected Set<ResourceIndexedSearchParamQuantity> extractSearchParamQuantity(ResourceTable theEntity, IBaseResource theResource) {
return mySearchParamExtractor.extractSearchParamQuantity(theEntity, theResource); return mySearchParamExtractor.extractSearchParamQuantity(theEntity, theResource);
} }
protected Set<ResourceIndexedSearchParamString> extractSearchParamStrings(ResourceTable theEntity, IResource theResource) { protected Set<ResourceIndexedSearchParamString> extractSearchParamStrings(ResourceTable theEntity, IBaseResource theResource) {
return mySearchParamExtractor.extractSearchParamStrings(theEntity, theResource); return mySearchParamExtractor.extractSearchParamStrings(theEntity, theResource);
} }
protected Set<BaseResourceIndexedSearchParam> extractSearchParamTokens(ResourceTable theEntity, IResource theResource) { protected Set<BaseResourceIndexedSearchParam> extractSearchParamTokens(ResourceTable theEntity, IBaseResource theResource) {
return mySearchParamExtractor.extractSearchParamTokens(theEntity, theResource); return mySearchParamExtractor.extractSearchParamTokens(theEntity, theResource);
} }
private List<Object> extractValues(String thePath, IResource theResource) { private List<Object> extractValues(String thePath, IBaseResource theResource) {
List<Object> values = new ArrayList<Object>(); List<Object> values = new ArrayList<Object>();
FhirTerser t = getContext().newTerser(); FhirTerser t = getContext().newTerser();
String nextPathTrimmed = thePath.trim(); String nextPathTrimmed = thePath.trim();
@ -516,12 +522,12 @@ public abstract class BaseHapiFhirDao<T extends IBaseResource> implements IDao {
} }
} }
protected TagList getTags(Class<? extends IResource> theResourceType, IIdType theResourceId) { protected TagList getTags(Class<? extends IBaseResource> theResourceType, IIdType theResourceId) {
String resourceName = null; String resourceName = null;
if (theResourceType != null) { if (theResourceType != null) {
resourceName = toResourceName(theResourceType); resourceName = toResourceName(theResourceType);
if (theResourceId != null && theResourceId.hasVersionIdPart()) { if (theResourceId != null && theResourceId.hasVersionIdPart()) {
IFhirResourceDao<? extends IResource> dao = getDao(theResourceType); IFhirResourceDao<? extends IBaseResource> dao = getDao(theResourceType);
BaseHasResource entity = dao.readEntity(theResourceId); BaseHasResource entity = dao.readEntity(theResourceId);
TagList retVal = new TagList(); TagList retVal = new TagList();
for (BaseTag next : entity.getTags()) { for (BaseTag next : entity.getTags()) {
@ -622,7 +628,7 @@ public abstract class BaseHapiFhirDao<T extends IBaseResource> implements IDao {
} }
throw e; throw e;
} }
IResource resource = (IResource) toResource(type.getImplementingClass(), next, true); IBaseResource resource = (IBaseResource) toResource(type.getImplementingClass(), next, true);
retVal.add(resource); retVal.add(resource);
} }
return retVal; return retVal;
@ -656,7 +662,7 @@ public abstract class BaseHapiFhirDao<T extends IBaseResource> implements IDao {
return true; return true;
} }
protected void populateResourceIntoEntity(IResource theResource, ResourceTable theEntity) { protected void populateResourceIntoEntity(IBaseResource theResource, ResourceTable theEntity) {
theEntity.setResourceType(toResourceName(theResource)); theEntity.setResourceType(toResourceName(theResource));
List<BaseResourceReferenceDt> refs = myContext.newTerser().getAllPopulatedChildElementsOfType(theResource, BaseResourceReferenceDt.class); List<BaseResourceReferenceDt> refs = myContext.newTerser().getAllPopulatedChildElementsOfType(theResource, BaseResourceReferenceDt.class);
@ -689,6 +695,36 @@ public abstract class BaseHapiFhirDao<T extends IBaseResource> implements IDao {
theEntity.setHasTags(false); theEntity.setHasTags(false);
if (theResource instanceof IResource) {
extractTagsHapi((IResource) theResource, theEntity, allDefs);
} else {
extractTagsRi((IAnyResource) theResource, theEntity, allDefs);
}
ArrayList<ResourceTag> existingTags = new ArrayList<ResourceTag>();
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<TagDefinition> allDefs) {
TagList tagList = ResourceMetadataKeyEnum.TAG_LIST.get(theResource); TagList tagList = ResourceMetadataKeyEnum.TAG_LIST.get(theResource);
if (tagList != null) { if (tagList != null) {
for (Tag next : tagList) { for (Tag next : tagList) {
@ -718,26 +754,38 @@ public abstract class BaseHapiFhirDao<T extends IBaseResource> implements IDao {
theEntity.setHasTags(true); theEntity.setHasTags(true);
} }
} }
}
ArrayList<ResourceTag> existingTags = new ArrayList<ResourceTag>(); private void extractTagsRi(IAnyResource theResource, ResourceTable theEntity, Set<TagDefinition> allDefs) {
if (theEntity.isHasTags()) { List<? extends IBaseCoding> tagList = theResource.getMeta().getTag();
existingTags.addAll(theEntity.getTags()); if (tagList != null) {
} for (IBaseCoding next : tagList) {
for (ResourceTag next : existingTags) { TagDefinition tag = getTag(TagTypeEnum.TAG, next.getSystem(), next.getCode(), next.getDisplay());
TagDefinition nextDef = next.getTag(); allDefs.add(tag);
if (!allDefs.contains(nextDef)) { theEntity.addTag(tag);
if (shouldDroppedTagBeRemovedOnUpdate(theEntity, next)) { theEntity.setHasTags(true);
theEntity.getTags().remove(next);
}
} }
} }
String title = ResourceMetadataKeyEnum.TITLE.get(theResource); List<? extends IBaseCoding> securityLabels = theResource.getMeta().getSecurity();
if (title != null && title.length() > BaseHasResource.MAX_TITLE_LENGTH) { if (securityLabels != null) {
title = title.substring(0, BaseHasResource.MAX_TITLE_LENGTH); 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<? extends IPrimitiveType<String>> profiles = theResource.getMeta().getProfile();
if (profiles != null) {
for (IPrimitiveType<String> 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<T extends IBaseResource> implements IDao {
return type; return type;
} }
protected <R extends IResource> Set<Long> processMatchUrl(String theMatchUrl, Class<R> theResourceType) { protected <R extends IBaseResource> Set<Long> processMatchUrl(String theMatchUrl, Class<R> theResourceType) {
RuntimeResourceDefinition resourceDef = getContext().getResourceDefinition(theResourceType); RuntimeResourceDefinition resourceDef = getContext().getResourceDefinition(theResourceType);
SearchParameterMap paramMap = translateMatchUrl(theMatchUrl, resourceDef); SearchParameterMap paramMap = translateMatchUrl(theMatchUrl, resourceDef);
@ -1066,7 +1114,6 @@ public abstract class BaseHapiFhirDao<T extends IBaseResource> implements IDao {
mySearchParamExtractor = new SearchParamExtractorDstu21(theContext); mySearchParamExtractor = new SearchParamExtractorDstu21(theContext);
break; break;
case DSTU2_HL7ORG: case DSTU2_HL7ORG:
case DEV:
throw new IllegalStateException("Don't know how to handle version: " + myContext.getVersion().getVersion()); throw new IllegalStateException("Don't know how to handle version: " + myContext.getVersion().getVersion());
} }
} }
@ -1123,7 +1170,18 @@ public abstract class BaseHapiFhirDao<T extends IBaseResource> implements IDao {
throw new DataFormatException(msg, e); throw new DataFormatException(msg, e);
} }
if (retVal instanceof IResource) {
IResource res = (IResource) retVal; 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 extends IBaseResource> R populateResourceMetadataHapi(Class<R> theResourceType, BaseHasResource theEntity, boolean theForHistoryOperation, IResource res) {
R retVal = (R) res;
if (theEntity.getDeleted() != null) { if (theEntity.getDeleted() != null) {
res = (IResource) myContext.getResourceDefinition(theResourceType).newInstance(); res = (IResource) myContext.getResourceDefinition(theResourceType).newInstance();
retVal = (R) res; retVal = (R) res;
@ -1159,7 +1217,7 @@ public abstract class BaseHapiFhirDao<T extends IBaseResource> implements IDao {
Collection<? extends BaseTag> tags = theEntity.getTags(); Collection<? extends BaseTag> tags = theEntity.getTags();
if (theEntity.isHasTags()) { if (theEntity.isHasTags()) {
TagList tagList = new TagList(); TagList tagList = new TagList();
List<BaseCodingDt> securityLabels = new ArrayList<BaseCodingDt>(); List<IBaseCoding> securityLabels = new ArrayList<IBaseCoding>();
List<IdDt> profiles = new ArrayList<IdDt>(); List<IdDt> profiles = new ArrayList<IdDt>();
for (BaseTag next : tags) { for (BaseTag next : tags) {
switch (next.getTag().getTagType()) { switch (next.getTag().getTagType()) {
@ -1167,7 +1225,7 @@ public abstract class BaseHapiFhirDao<T extends IBaseResource> implements IDao {
profiles.add(new IdDt(next.getTag().getCode())); profiles.add(new IdDt(next.getTag().getCode()));
break; break;
case SECURITY_LABEL: case SECURITY_LABEL:
BaseCodingDt secLabel = myContext.getVersion().newCodingDt(); IBaseCoding secLabel = (IBaseCoding) myContext.getVersion().newCodingDt();
secLabel.setSystem(next.getTag().getSystem()); secLabel.setSystem(next.getTag().getSystem());
secLabel.setCode(next.getTag().getCode()); secLabel.setCode(next.getTag().getCode());
secLabel.setDisplay(next.getTag().getDisplay()); secLabel.setDisplay(next.getTag().getDisplay());
@ -1182,7 +1240,7 @@ public abstract class BaseHapiFhirDao<T extends IBaseResource> implements IDao {
ResourceMetadataKeyEnum.TAG_LIST.put(res, tagList); ResourceMetadataKeyEnum.TAG_LIST.put(res, tagList);
} }
if (securityLabels.size() > 0) { if (securityLabels.size() > 0) {
ResourceMetadataKeyEnum.SECURITY_LABELS.put(res, securityLabels); ResourceMetadataKeyEnum.SECURITY_LABELS.put(res, toBaseCodingList(securityLabels));
} }
if (profiles.size() > 0) { if (profiles.size() > 0) {
ResourceMetadataKeyEnum.PROFILES.put(res, profiles); ResourceMetadataKeyEnum.PROFILES.put(res, profiles);
@ -1192,11 +1250,78 @@ public abstract class BaseHapiFhirDao<T extends IBaseResource> implements IDao {
return retVal; return retVal;
} }
protected String toResourceName(Class<? extends IResource> theResourceType) { private <R extends IBaseResource> R populateResourceMetadataRi(Class<R> 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<? extends BaseTag> 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<BaseCodingDt> toBaseCodingList(List<IBaseCoding> theSecurityLabels) {
ArrayList<BaseCodingDt> retVal = new ArrayList<BaseCodingDt>(theSecurityLabels.size());
for (IBaseCoding next : theSecurityLabels) {
retVal.add((BaseCodingDt) next);
}
return retVal;
}
protected String toResourceName(Class<? extends IBaseResource> theResourceType) {
return myContext.getResourceDefinition(theResourceType).getName(); return myContext.getResourceDefinition(theResourceType).getName();
} }
protected String toResourceName(IResource theResource) { protected String toResourceName(IBaseResource theResource) {
return myContext.getResourceDefinition(theResource).getName(); return myContext.getResourceDefinition(theResource).getName();
} }
@ -1238,7 +1363,7 @@ public abstract class BaseHapiFhirDao<T extends IBaseResource> implements IDao {
} }
@SuppressWarnings("unchecked") @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.. * This should be the very first thing..
@ -1351,8 +1476,8 @@ public abstract class BaseHapiFhirDao<T extends IBaseResource> implements IDao {
links = extractResourceLinks(theEntity, theResource); links = extractResourceLinks(theEntity, theResource);
/* /*
* If the existing resource already has links and those match links we still want, * If the existing resource already has links and those match links we still want, use them instead of
* use them instead of removing them and re adding them * removing them and re adding them
*/ */
for (Iterator<ResourceLink> existingLinkIter = existingResourceLinks.iterator(); existingLinkIter.hasNext();) { for (Iterator<ResourceLink> existingLinkIter = existingResourceLinks.iterator(); existingLinkIter.hasNext();) {
ResourceLink nextExisting = existingLinkIter.next(); ResourceLink nextExisting = existingLinkIter.next();
@ -1365,7 +1490,11 @@ public abstract class BaseHapiFhirDao<T extends IBaseResource> implements IDao {
populateResourceIntoEntity(theResource, theEntity); populateResourceIntoEntity(theResource, theEntity);
theEntity.setUpdated(theUpdateTime); 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.setParamsString(stringParams);
theEntity.setParamsStringPopulated(stringParams.isEmpty() == false); theEntity.setParamsStringPopulated(stringParams.isEmpty() == false);
theEntity.setParamsToken(tokenParams); theEntity.setParamsToken(tokenParams);
@ -1390,7 +1519,7 @@ public abstract class BaseHapiFhirDao<T extends IBaseResource> implements IDao {
populateResourceIntoEntity(theResource, theEntity); populateResourceIntoEntity(theResource, theEntity);
theEntity.setUpdated(theUpdateTime); theEntity.setUpdated(theUpdateTime);
theEntity.setLanguage(theResource.getLanguage().getValue()); // theEntity.setLanguage(theResource.getLanguage().getValue());
theEntity.setIndexStatus(null); theEntity.setIndexStatus(null);
} }
@ -1481,12 +1610,20 @@ public abstract class BaseHapiFhirDao<T extends IBaseResource> implements IDao {
myEntityManager.flush(); myEntityManager.flush();
if (theResource != null) { if (theResource != null) {
theResource.setId(theEntity.getIdDt()); populateResourceId(theResource, theEntity);
} }
return 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 * Subclasses may override to provide behaviour. Called when a resource has been inserved into the database for the
* first time. * first time.
@ -1524,15 +1661,22 @@ public abstract class BaseHapiFhirDao<T extends IBaseResource> implements IDao {
* TODO * TODO
*/ */
protected void validateResourceForStorage(T theResource, ResourceTable theEntityToSave) { protected void validateResourceForStorage(T theResource, ResourceTable theEntityToSave) {
Object tag = null;
if (theResource instanceof IResource) {
IResource res = (IResource) theResource; IResource res = (IResource) theResource;
TagList tagList = ResourceMetadataKeyEnum.TAG_LIST.get(res); TagList tagList = ResourceMetadataKeyEnum.TAG_LIST.get(res);
if (tagList != null) { if (tagList != null) {
Tag tag = tagList.getTag(Constants.TAG_SUBSETTED_SYSTEM, Constants.TAG_SUBSETTED_CODE); 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) { 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"); throw new UnprocessableEntityException("Resource contains the 'subsetted' tag, and must not be stored as it may contain a subset of available data");
} }
} }
}
static String normalizeString(String theString) { static String normalizeString(String theString) {
char[] out = new char[theString.length()]; char[] out = new char[theString.length()];
@ -1547,9 +1691,12 @@ public abstract class BaseHapiFhirDao<T extends IBaseResource> implements IDao {
return new String(out).toUpperCase(); return new String(out).toUpperCase();
} }
private static String parseNarrativeTextIntoWords(IResource theResource) { private static String parseNarrativeTextIntoWords(IBaseResource theResource) {
StringBuilder b = new StringBuilder(); StringBuilder b = new StringBuilder();
List<XMLEvent> xmlEvents = theResource.getText().getDiv().getValue(); if (theResource instanceof IResource) {
IResource resource = (IResource) theResource;
List<XMLEvent> xmlEvents = resource.getText().getDiv().getValue();
if (xmlEvents != null) { if (xmlEvents != null) {
for (XMLEvent next : xmlEvents) { for (XMLEvent next : xmlEvents) {
if (next.isCharacters()) { if (next.isCharacters()) {
@ -1558,15 +1705,35 @@ public abstract class BaseHapiFhirDao<T extends IBaseResource> implements IDao {
} }
} }
} }
} else if (theResource instanceof IDomainResource) {
IDomainResource resource = (IDomainResource) theResource;
try {
String divAsString = resource.getText().getDivAsString();
XhtmlDt xhtml = new XhtmlDt(divAsString);
List<XMLEvent> 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(); return b.toString();
} }
private String parseContentTextIntoWords(IResource theResource) { private String parseContentTextIntoWords(IBaseResource theResource) {
StringBuilder retVal = new StringBuilder(); StringBuilder retVal = new StringBuilder();
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
List<IPrimitiveType> childElements = getContext().newTerser().getAllPopulatedChildElementsOfType(theResource, IPrimitiveType.class); List<IPrimitiveType> childElements = getContext().newTerser().getAllPopulatedChildElementsOfType(theResource, IPrimitiveType.class);
for (@SuppressWarnings("rawtypes") IPrimitiveType nextType : childElements) { for (@SuppressWarnings("rawtypes")
if (nextType instanceof StringDt) { IPrimitiveType nextType : childElements) {
if (nextType instanceof StringDt || nextType.getClass().equals(StringType.class)) {
String nextValue = nextType.getValueAsString(); String nextValue = nextType.getValueAsString();
if (isNotBlank(nextValue)) { if (isNotBlank(nextValue)) {
retVal.append(nextValue.replace("\n", " ").replace("\r", " ")); retVal.append(nextValue.replace("\n", " ").replace("\r", " "));
@ -1584,7 +1751,8 @@ public abstract class BaseHapiFhirDao<T extends IBaseResource> implements IDao {
IBaseOperationOutcome oo = OperationOutcomeUtil.newInstance(getContext()); IBaseOperationOutcome oo = OperationOutcomeUtil.newInstance(getContext());
for (DeleteConflict next : theDeleteConflicts) { 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"); OperationOutcomeUtil.addIssue(getContext(), oo, OO_SEVERITY_ERROR, msg, null, "processing");
} }

View File

@ -37,6 +37,8 @@ import javax.persistence.NoResultException;
import javax.persistence.TemporalType; import javax.persistence.TemporalType;
import javax.persistence.TypedQuery; 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.IBaseCoding;
import org.hl7.fhir.instance.model.api.IBaseMetaType; import org.hl7.fhir.instance.model.api.IBaseMetaType;
import org.hl7.fhir.instance.model.api.IBaseOperationOutcome; import org.hl7.fhir.instance.model.api.IBaseOperationOutcome;
@ -87,7 +89,7 @@ import ca.uhn.fhir.util.FhirTerser;
import ca.uhn.fhir.util.ObjectUtil; import ca.uhn.fhir.util.ObjectUtil;
@Transactional(propagation = Propagation.REQUIRED) @Transactional(propagation = Propagation.REQUIRED)
public abstract class BaseHapiFhirResourceDao<T extends IResource> extends BaseHapiFhirDao<T> implements IFhirResourceDao<T> { public abstract class BaseHapiFhirResourceDao<T extends IBaseResource> extends BaseHapiFhirDao<T> implements IFhirResourceDao<T> {
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(BaseHapiFhirResourceDao.class); private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(BaseHapiFhirResourceDao.class);
@ -148,14 +150,14 @@ public abstract class BaseHapiFhirResourceDao<T extends IResource> extends BaseH
@Override @Override
public DaoMethodOutcome create(T theResource, String theIfNoneExist, boolean thePerformIndexing) { 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 (getContext().getVersion().getVersion().equals(FhirVersionEnum.DSTU1)) {
if (theResource.getId().isIdPartValidLong()) { if (theResource.getIdElement().isIdPartValidLong()) {
String message = getContext().getLocalizer().getMessage(BaseHapiFhirResourceDao.class, "failedToCreateWithClientAssignedNumericId", theResource.getId().getIdPart()); String message = getContext().getLocalizer().getMessage(BaseHapiFhirResourceDao.class, "failedToCreateWithClientAssignedNumericId", theResource.getIdElement().getIdPart());
throw new InvalidRequestException(message, createErrorOperationOutcome(message)); throw new InvalidRequestException(message, createErrorOperationOutcome(message));
} }
} else { } 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)); throw new InvalidRequestException(message, createErrorOperationOutcome(message));
} }
} }
@ -288,16 +290,16 @@ public abstract class BaseHapiFhirResourceDao<T extends IResource> extends BaseH
} }
} }
if (isNotBlank(theResource.getId().getIdPart())) { if (isNotBlank(theResource.getIdElement().getIdPart())) {
if (isValidPid(theResource.getId())) { 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"); 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) { if (entity.getForcedId() != null) {
try { try {
translateForcedIdToPid(theResource.getId()); translateForcedIdToPid(theResource.getIdElement());
throw new UnprocessableEntityException(getContext().getLocalizer().getMessage(BaseHapiFhirResourceDao.class, "duplicateCreateForcedId", theResource.getId().getIdPart())); throw new UnprocessableEntityException(getContext().getLocalizer().getMessage(BaseHapiFhirResourceDao.class, "duplicateCreateForcedId", theResource.getIdElement().getIdPart()));
} catch (ResourceNotFoundException e) { } catch (ResourceNotFoundException e) {
// good, this ID doesn't exist so we can create it // good, this ID doesn't exist so we can create it
} }
@ -306,7 +308,7 @@ public abstract class BaseHapiFhirResourceDao<T extends IResource> extends BaseH
} }
// Notify interceptors // Notify interceptors
ActionRequestDetails requestDetails = new ActionRequestDetails(theResource.getId(), toResourceName(theResource), theResource); ActionRequestDetails requestDetails = new ActionRequestDetails(theResource.getIdElement(), toResourceName(theResource), theResource);
notifyInterceptors(RestOperationTypeEnum.CREATE, requestDetails); notifyInterceptors(RestOperationTypeEnum.CREATE, requestDetails);
// Perform actual DB update // Perform actual DB update
@ -389,7 +391,13 @@ public abstract class BaseHapiFhirResourceDao<T extends IResource> extends BaseH
BaseHasResource entity = readEntity(theId.toVersionless(), false); BaseHasResource entity = readEntity(theId.toVersionless(), false);
validateResourceType(entity); validateResourceType(entity);
currentTmp = toResource(myResourceType, entity, true); 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; currentTmp = null;
} }
} catch (ResourceNotFoundException e) { } catch (ResourceNotFoundException e) {
@ -746,9 +754,9 @@ public abstract class BaseHapiFhirResourceDao<T extends IResource> extends BaseH
* The resource that is about to be stored * The resource that is about to be stored
*/ */
protected void preProcessResourceForStorage(T theResource) { protected void preProcessResourceForStorage(T theResource) {
if (theResource.getId().hasIdPart()) { if (theResource.getIdElement().hasIdPart()) {
if (!theResource.getId().isIdPartValid()) { if (!theResource.getIdElement().isIdPartValid()) {
throw new InvalidRequestException(getContext().getLocalizer().getMessage(BaseHapiFhirResourceDao.class, "failedToCreateWithInvalidId", theResource.getId().getIdPart())); throw new InvalidRequestException(getContext().getLocalizer().getMessage(BaseHapiFhirResourceDao.class, "failedToCreateWithInvalidId", theResource.getIdElement().getIdPart()));
} }
} }
} }
@ -773,7 +781,12 @@ public abstract class BaseHapiFhirResourceDao<T extends IResource> extends BaseH
T retVal = toResource(myResourceType, entity, false); T retVal = toResource(myResourceType, entity, false);
InstantDt deleted = ResourceMetadataKeyEnum.DELETED_AT.get(retVal); IPrimitiveType<Date> 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()) { if (deleted != null && !deleted.isEmpty()) {
throw new ResourceGoneException("Resource was deleted at " + deleted.getValueAsString()); throw new ResourceGoneException("Resource was deleted at " + deleted.getValueAsString());
} }
@ -927,7 +940,7 @@ public abstract class BaseHapiFhirResourceDao<T extends IResource> extends BaseH
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@Required @Required
public void setResourceType(Class<? extends IResource> theTableType) { public void setResourceType(Class<? extends IBaseResource> theTableType) {
myResourceType = (Class<T>) theTableType; myResourceType = (Class<T>) theTableType;
} }
@ -939,18 +952,29 @@ public abstract class BaseHapiFhirResourceDao<T extends IResource> extends BaseH
mySecondaryPrimaryKeyParamName = theSecondaryPrimaryKeyParamName; mySecondaryPrimaryKeyParamName = theSecondaryPrimaryKeyParamName;
} }
private DaoMethodOutcome toMethodOutcome(final BaseHasResource theEntity, IResource theResource) { private DaoMethodOutcome toMethodOutcome(final BaseHasResource theEntity, IBaseResource theResource) {
DaoMethodOutcome outcome = new DaoMethodOutcome(); 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); outcome.setResource(theResource);
if (theResource != null) { if (theResource != null) {
theResource.setId(theEntity.getIdDt()); theResource.setId(id);
ResourceMetadataKeyEnum.UPDATED.put(theResource, theEntity.getUpdated()); if (theResource instanceof IResource) {
ResourceMetadataKeyEnum.UPDATED.put((IResource) theResource, theEntity.getUpdated());
} else {
IBaseMetaType meta = ((IAnyResource) theResource).getMeta();
meta.setLastUpdated(theEntity.getUpdatedDate());
}
} }
return outcome; return outcome;
} }
private DaoMethodOutcome toMethodOutcome(final ResourceTable theEntity, IResource theResource) { private DaoMethodOutcome toMethodOutcome(final ResourceTable theEntity, IBaseResource theResource) {
DaoMethodOutcome retVal = toMethodOutcome((BaseHasResource) theEntity, theResource); DaoMethodOutcome retVal = toMethodOutcome((BaseHasResource) theEntity, theResource);
retVal.setEntity(theEntity); retVal.setEntity(theEntity);
return retVal; return retVal;
@ -972,9 +996,6 @@ public abstract class BaseHapiFhirResourceDao<T extends IResource> extends BaseH
return retVal; return retVal;
} }
@Override @Override
public DaoMethodOutcome update(T theResource) { public DaoMethodOutcome update(T theResource) {
return update(theResource, null); return update(theResource, null);
@ -1007,7 +1028,7 @@ public abstract class BaseHapiFhirResourceDao<T extends IResource> extends BaseH
return create(theResource, null, thePerformIndexing); return create(theResource, null, thePerformIndexing);
} }
} else { } else {
resourceId = theResource.getId(); resourceId = theResource.getIdElement();
if (resourceId == null || isBlank(resourceId.getIdPart())) { if (resourceId == null || isBlank(resourceId.getIdPart())) {
throw new InvalidRequestException("Can not update a resource with no ID"); throw new InvalidRequestException("Can not update a resource with no ID");
} }
@ -1015,7 +1036,7 @@ public abstract class BaseHapiFhirResourceDao<T extends IResource> extends BaseH
entity = readEntityLatestVersion(resourceId); entity = readEntityLatestVersion(resourceId);
} catch (ResourceNotFoundException e) { } catch (ResourceNotFoundException e) {
if (resourceId.isIdPartValidLong()) { 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()); return doCreate(theResource, null, thePerformIndexing, new Date());
} }
@ -1081,8 +1102,6 @@ public abstract class BaseHapiFhirResourceDao<T extends IResource> extends BaseH
theDeleteConflicts.add(new DeleteConflict(sourceId, sourcePath, targetId)); theDeleteConflicts.add(new DeleteConflict(sourceId, sourcePath, targetId));
} }
private void validateResourceType(BaseHasResource entity) { private void validateResourceType(BaseHasResource entity) {
validateResourceType(entity, myResourceName); validateResourceType(entity, myResourceName);
} }

View File

@ -23,6 +23,8 @@ package ca.uhn.fhir.jpa.dao;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import org.hl7.fhir.instance.model.api.IBaseResource;
import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.context.RuntimeResourceDefinition; import ca.uhn.fhir.context.RuntimeResourceDefinition;
import ca.uhn.fhir.model.api.IResource; import ca.uhn.fhir.model.api.IResource;
@ -40,7 +42,7 @@ public class BaseSearchParamExtractor {
return myContext; return myContext;
} }
protected List<Object> extractValues(String thePaths, IResource theResource) { protected List<Object> extractValues(String thePaths, IBaseResource theResource) {
List<Object> values = new ArrayList<Object>(); List<Object> values = new ArrayList<Object>();
String[] nextPathsSplit = thePaths.split("\\|"); String[] nextPathsSplit = thePaths.split("\\|");
FhirTerser t = myContext.newTerser(); FhirTerser t = myContext.newTerser();

View File

@ -1,5 +1,9 @@
package ca.uhn.fhir.jpa.dao; 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 * #%L
* HAPI FHIR JPA Server * HAPI FHIR JPA Server
@ -20,9 +24,6 @@ package ca.uhn.fhir.jpa.dao;
* #L% * #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; import ca.uhn.fhir.rest.server.exceptions.UnprocessableEntityException;
public class FhirResourceDaoBundleDstu21 extends FhirResourceDaoDstu21<Bundle> { public class FhirResourceDaoBundleDstu21 extends FhirResourceDaoDstu21<Bundle> {
@ -31,12 +32,12 @@ public class FhirResourceDaoBundleDstu21 extends FhirResourceDaoDstu21<Bundle> {
protected void preProcessResourceForStorage(Bundle theResource) { protected void preProcessResourceForStorage(Bundle theResource) {
super.preProcessResourceForStorage(theResource); super.preProcessResourceForStorage(theResource);
if (theResource.getTypeElement().getValueAsEnum() != BundleTypeEnum.DOCUMENT) { if (theResource.getType() != BundleType.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)"); 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); throw new UnprocessableEntityException(message);
} }
for (Entry next : theResource.getEntry()) { for (BundleEntryComponent next : theResource.getEntry()) {
next.setFullUrl((String)null); next.setFullUrl((String)null);
} }
} }

View File

@ -27,6 +27,10 @@ import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import org.hl7.fhir.instance.hapi.validation.DefaultProfileValidationSupport;
import org.hl7.fhir.instance.hapi.validation.FhirInstanceValidator;
import org.hl7.fhir.instance.hapi.validation.IValidationSupport;
import org.hl7.fhir.instance.hapi.validation.ValidationSupportChain;
import org.hl7.fhir.instance.model.api.IBaseOperationOutcome; import org.hl7.fhir.instance.model.api.IBaseOperationOutcome;
import org.hl7.fhir.instance.model.api.IBaseResource; import org.hl7.fhir.instance.model.api.IBaseResource;
import org.hl7.fhir.instance.model.api.IIdType; import org.hl7.fhir.instance.model.api.IIdType;
@ -51,17 +55,12 @@ import ca.uhn.fhir.rest.api.ValidationModeEnum;
import ca.uhn.fhir.rest.server.EncodingEnum; import ca.uhn.fhir.rest.server.EncodingEnum;
import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException; import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException;
import ca.uhn.fhir.rest.server.exceptions.PreconditionFailedException; import ca.uhn.fhir.rest.server.exceptions.PreconditionFailedException;
import ca.uhn.fhir.rest.server.exceptions.ResourceVersionConflictException;
import ca.uhn.fhir.rest.server.interceptor.IServerInterceptor.ActionRequestDetails; import ca.uhn.fhir.rest.server.interceptor.IServerInterceptor.ActionRequestDetails;
import ca.uhn.fhir.util.FhirTerser; import ca.uhn.fhir.util.FhirTerser;
import ca.uhn.fhir.validation.DefaultProfileValidationSupport;
import ca.uhn.fhir.validation.FhirInstanceValidator;
import ca.uhn.fhir.validation.FhirValidator; import ca.uhn.fhir.validation.FhirValidator;
import ca.uhn.fhir.validation.IValidationContext; import ca.uhn.fhir.validation.IValidationContext;
import ca.uhn.fhir.validation.IValidationSupport;
import ca.uhn.fhir.validation.IValidatorModule; import ca.uhn.fhir.validation.IValidatorModule;
import ca.uhn.fhir.validation.ValidationResult; import ca.uhn.fhir.validation.ValidationResult;
import ca.uhn.fhir.validation.ValidationSupportChain;
import net.sourceforge.cobertura.CoverageIgnore; import net.sourceforge.cobertura.CoverageIgnore;
public class FhirResourceDaoDstu2<T extends IResource> extends BaseHapiFhirResourceDao<T> { public class FhirResourceDaoDstu2<T extends IResource> extends BaseHapiFhirResourceDao<T> {

View File

@ -26,10 +26,17 @@ import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import org.hl7.fhir.dstu21.hapi.validation.FhirInstanceValidator;
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.dstu21.validation.IResourceValidator.BestPracticeWarningLevel;
import org.hl7.fhir.instance.model.api.IAnyResource;
import org.hl7.fhir.instance.model.api.IBaseOperationOutcome; import org.hl7.fhir.instance.model.api.IBaseOperationOutcome;
import org.hl7.fhir.instance.model.api.IBaseResource; import org.hl7.fhir.instance.model.api.IBaseResource;
import org.hl7.fhir.instance.model.api.IIdType; import org.hl7.fhir.instance.model.api.IIdType;
import org.hl7.fhir.instance.validation.IResourceValidator.BestPracticeWarningLevel;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.beans.factory.annotation.Qualifier;
@ -38,12 +45,8 @@ import ca.uhn.fhir.context.RuntimeSearchParam;
import ca.uhn.fhir.jpa.entity.ResourceTable; import ca.uhn.fhir.jpa.entity.ResourceTable;
import ca.uhn.fhir.jpa.util.DeleteConflict; import ca.uhn.fhir.jpa.util.DeleteConflict;
import ca.uhn.fhir.model.api.Bundle; 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.api.Include;
import ca.uhn.fhir.model.base.composite.BaseResourceReferenceDt; 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.MethodOutcome;
import ca.uhn.fhir.rest.api.RestOperationTypeEnum; import ca.uhn.fhir.rest.api.RestOperationTypeEnum;
import ca.uhn.fhir.rest.api.ValidationModeEnum; import ca.uhn.fhir.rest.api.ValidationModeEnum;
@ -52,17 +55,13 @@ import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException;
import ca.uhn.fhir.rest.server.exceptions.PreconditionFailedException; import ca.uhn.fhir.rest.server.exceptions.PreconditionFailedException;
import ca.uhn.fhir.rest.server.interceptor.IServerInterceptor.ActionRequestDetails; import ca.uhn.fhir.rest.server.interceptor.IServerInterceptor.ActionRequestDetails;
import ca.uhn.fhir.util.FhirTerser; import ca.uhn.fhir.util.FhirTerser;
import ca.uhn.fhir.validation.DefaultProfileValidationSupport;
import ca.uhn.fhir.validation.FhirInstanceValidator;
import ca.uhn.fhir.validation.FhirValidator; import ca.uhn.fhir.validation.FhirValidator;
import ca.uhn.fhir.validation.IValidationContext; import ca.uhn.fhir.validation.IValidationContext;
import ca.uhn.fhir.validation.IValidationSupport;
import ca.uhn.fhir.validation.IValidatorModule; import ca.uhn.fhir.validation.IValidatorModule;
import ca.uhn.fhir.validation.ValidationResult; import ca.uhn.fhir.validation.ValidationResult;
import ca.uhn.fhir.validation.ValidationSupportChain;
import net.sourceforge.cobertura.CoverageIgnore; import net.sourceforge.cobertura.CoverageIgnore;
public class FhirResourceDaoDstu21<T extends IResource> extends BaseHapiFhirResourceDao<T> { public class FhirResourceDaoDstu21<T extends IAnyResource> extends BaseHapiFhirResourceDao<T> {
@Autowired() @Autowired()
@Qualifier("myJpaValidationSupportDstu21") @Qualifier("myJpaValidationSupportDstu21")
@ -90,8 +89,9 @@ public class FhirResourceDaoDstu21<T extends IResource> extends BaseHapiFhirReso
@Override @Override
protected IBaseOperationOutcome createOperationOutcome(String theSeverity, String theMessage) { protected IBaseOperationOutcome createOperationOutcome(String theSeverity, String theMessage) {
OperationOutcome oo = new OperationOutcome(); OperationOutcome oo = new OperationOutcome();
oo.getIssueFirstRep().getSeverityElement().setValue(theSeverity); OperationOutcomeIssueComponent issue = oo.addIssue();
oo.getIssueFirstRep().getDiagnosticsElement().setValue(theMessage); issue.getSeverityElement().setValueAsString(theSeverity);
issue.setDiagnostics(theMessage);
return oo; return oo;
} }
@ -113,15 +113,15 @@ public class FhirResourceDaoDstu21<T extends IResource> extends BaseHapiFhirReso
validateDeleteConflictsEmptyOrThrowException(deleteConflicts); validateDeleteConflictsEmptyOrThrowException(deleteConflicts);
OperationOutcome oo = new OperationOutcome(); OperationOutcome oo = new OperationOutcome();
oo.addIssue().setSeverity(IssueSeverityEnum.INFORMATION).setDiagnostics("Ok to delete"); oo.addIssue().setSeverity(IssueSeverity.INFORMATION).setDiagnostics("Ok to delete");
return new MethodOutcome(new IdDt(theId.getValue()), oo); return new MethodOutcome(new IdType(theId.getValue()), oo);
} }
FhirValidator validator = getContext().newValidator(); FhirValidator validator = getContext().newValidator();
FhirInstanceValidator val = new FhirInstanceValidator(); FhirInstanceValidator val = new FhirInstanceValidator();
val.setBestPracticeWarningLevel(BestPracticeWarningLevel.Warning); val.setBestPracticeWarningLevel(BestPracticeWarningLevel.Warning);
val.setValidationSupport(new ValidationSupportChain(new DefaultProfileValidationSupport(), myJpaValidationSupport)); // val.setValidationSupport(new ValidationSupportChain(new DefaultProfileValidationSupport(), myJpaValidationSupport));
validator.registerValidatorModule(val); validator.registerValidatorModule(val);
validator.registerValidatorModule(new IdChecker(theMode)); validator.registerValidatorModule(new IdChecker(theMode));

View File

@ -24,11 +24,12 @@ import java.util.Collections;
import javax.servlet.http.HttpServletRequest; 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.jpa.dao.SearchParameterMap.EverythingModeEnum;
import ca.uhn.fhir.model.api.IResource; import ca.uhn.fhir.model.api.IResource;
import ca.uhn.fhir.model.dstu2.resource.Encounter; 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.api.SortSpec;
import ca.uhn.fhir.rest.param.DateRangeParam; import ca.uhn.fhir.rest.param.DateRangeParam;
import ca.uhn.fhir.rest.param.StringParam; import ca.uhn.fhir.rest.param.StringParam;
@ -37,7 +38,7 @@ import ca.uhn.fhir.rest.server.IBundleProvider;
public class FhirResourceDaoEncounterDstu2 extends FhirResourceDaoDstu2<Encounter>implements IFhirResourceDaoEncounter<Encounter> { public class FhirResourceDaoEncounterDstu2 extends FhirResourceDaoDstu2<Encounter>implements IFhirResourceDaoEncounter<Encounter> {
@Override @Override
public IBundleProvider encounterInstanceEverything(HttpServletRequest theServletRequest, IdDt theId, UnsignedIntDt theCount, DateRangeParam theLastUpdated, SortSpec theSort) { public IBundleProvider encounterInstanceEverything(HttpServletRequest theServletRequest, IIdType theId, IPrimitiveType<Integer> theCount, DateRangeParam theLastUpdated, SortSpec theSort) {
SearchParameterMap paramMap = new SearchParameterMap(); SearchParameterMap paramMap = new SearchParameterMap();
if (theCount != null) { if (theCount != null) {
paramMap.setCount(theCount.getValue()); paramMap.setCount(theCount.getValue());
@ -56,7 +57,7 @@ public class FhirResourceDaoEncounterDstu2 extends FhirResourceDaoDstu2<Encounte
} }
@Override @Override
public IBundleProvider encounterTypeEverything(HttpServletRequest theServletRequest, UnsignedIntDt theCount, DateRangeParam theLastUpdated, SortSpec theSort) { public IBundleProvider encounterTypeEverything(HttpServletRequest theServletRequest, IPrimitiveType<Integer> theCount, DateRangeParam theLastUpdated, SortSpec theSort) {
return encounterInstanceEverything(theServletRequest, null, theCount, theLastUpdated, theSort); return encounterInstanceEverything(theServletRequest, null, theCount, theLastUpdated, theSort);
} }

View File

@ -24,11 +24,12 @@ import java.util.Collections;
import javax.servlet.http.HttpServletRequest; 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.jpa.dao.SearchParameterMap.EverythingModeEnum;
import ca.uhn.fhir.model.api.IResource; 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.api.SortSpec;
import ca.uhn.fhir.rest.param.DateRangeParam; import ca.uhn.fhir.rest.param.DateRangeParam;
import ca.uhn.fhir.rest.param.StringParam; import ca.uhn.fhir.rest.param.StringParam;
@ -37,7 +38,7 @@ import ca.uhn.fhir.rest.server.IBundleProvider;
public class FhirResourceDaoEncounterDstu21 extends FhirResourceDaoDstu21<Encounter>implements IFhirResourceDaoEncounter<Encounter> { public class FhirResourceDaoEncounterDstu21 extends FhirResourceDaoDstu21<Encounter>implements IFhirResourceDaoEncounter<Encounter> {
@Override @Override
public IBundleProvider encounterInstanceEverything(HttpServletRequest theServletRequest, IdDt theId, UnsignedIntDt theCount, DateRangeParam theLastUpdated, SortSpec theSort) { public IBundleProvider encounterInstanceEverything(HttpServletRequest theServletRequest, IIdType theId, IPrimitiveType<Integer> theCount, DateRangeParam theLastUpdated, SortSpec theSort) {
SearchParameterMap paramMap = new SearchParameterMap(); SearchParameterMap paramMap = new SearchParameterMap();
if (theCount != null) { if (theCount != null) {
paramMap.setCount(theCount.getValue()); paramMap.setCount(theCount.getValue());
@ -56,7 +57,7 @@ public class FhirResourceDaoEncounterDstu21 extends FhirResourceDaoDstu21<Encoun
} }
@Override @Override
public IBundleProvider encounterTypeEverything(HttpServletRequest theServletRequest, UnsignedIntDt theCount, DateRangeParam theLastUpdated, SortSpec theSort) { public IBundleProvider encounterTypeEverything(HttpServletRequest theServletRequest, IPrimitiveType<Integer> theCount, DateRangeParam theLastUpdated, SortSpec theSort) {
return encounterInstanceEverything(theServletRequest, null, theCount, theLastUpdated, theSort); return encounterInstanceEverything(theServletRequest, null, theCount, theLastUpdated, theSort);
} }

View File

@ -25,11 +25,11 @@ import java.util.Collections;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import org.hl7.fhir.instance.model.api.IIdType; 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.jpa.dao.SearchParameterMap.EverythingModeEnum;
import ca.uhn.fhir.model.api.IResource; import ca.uhn.fhir.model.api.IResource;
import ca.uhn.fhir.model.dstu2.resource.Patient; 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.RestOperationTypeEnum;
import ca.uhn.fhir.rest.api.SortSpec; import ca.uhn.fhir.rest.api.SortSpec;
import ca.uhn.fhir.rest.param.DateRangeParam; import ca.uhn.fhir.rest.param.DateRangeParam;
@ -41,7 +41,7 @@ import ca.uhn.fhir.rest.server.interceptor.IServerInterceptor.ActionRequestDetai
public class FhirResourceDaoPatientDstu2 extends FhirResourceDaoDstu2<Patient>implements IFhirResourceDaoPatient<Patient> { public class FhirResourceDaoPatientDstu2 extends FhirResourceDaoDstu2<Patient>implements IFhirResourceDaoPatient<Patient> {
private IBundleProvider doEverythingOperation(IIdType theId, UnsignedIntDt theCount, DateRangeParam theLastUpdated, SortSpec theSort, StringAndListParam theContent, StringAndListParam theNarrative) { private IBundleProvider doEverythingOperation(IIdType theId, IPrimitiveType<Integer> theCount, DateRangeParam theLastUpdated, SortSpec theSort, StringAndListParam theContent, StringAndListParam theNarrative) {
SearchParameterMap paramMap = new SearchParameterMap(); SearchParameterMap paramMap = new SearchParameterMap();
if (theCount != null) { if (theCount != null) {
paramMap.setCount(theCount.getValue()); paramMap.setCount(theCount.getValue());
@ -66,7 +66,7 @@ public class FhirResourceDaoPatientDstu2 extends FhirResourceDaoDstu2<Patient>im
} }
@Override @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<Integer> theCount, DateRangeParam theLastUpdated, SortSpec theSort, StringAndListParam theContent, StringAndListParam theNarrative) {
// Notify interceptors // Notify interceptors
ActionRequestDetails requestDetails = new ActionRequestDetails(null, getResourceName()); ActionRequestDetails requestDetails = new ActionRequestDetails(null, getResourceName());
notifyInterceptors(RestOperationTypeEnum.EXTENDED_OPERATION_INSTANCE, requestDetails); notifyInterceptors(RestOperationTypeEnum.EXTENDED_OPERATION_INSTANCE, requestDetails);
@ -75,7 +75,7 @@ public class FhirResourceDaoPatientDstu2 extends FhirResourceDaoDstu2<Patient>im
} }
@Override @Override
public IBundleProvider patientTypeEverything(HttpServletRequest theServletRequest, UnsignedIntDt theCount, DateRangeParam theLastUpdated, SortSpec theSort, StringAndListParam theContent, StringAndListParam theNarrative) { public IBundleProvider patientTypeEverything(HttpServletRequest theServletRequest, IPrimitiveType<Integer> theCount, DateRangeParam theLastUpdated, SortSpec theSort, StringAndListParam theContent, StringAndListParam theNarrative) {
// Notify interceptors // Notify interceptors
ActionRequestDetails requestDetails = new ActionRequestDetails(null, getResourceName()); ActionRequestDetails requestDetails = new ActionRequestDetails(null, getResourceName());
notifyInterceptors(RestOperationTypeEnum.EXTENDED_OPERATION_TYPE, requestDetails); notifyInterceptors(RestOperationTypeEnum.EXTENDED_OPERATION_TYPE, requestDetails);

View File

@ -24,12 +24,12 @@ import java.util.Collections;
import javax.servlet.http.HttpServletRequest; 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.IIdType;
import org.hl7.fhir.instance.model.api.IPrimitiveType;
import ca.uhn.fhir.jpa.dao.SearchParameterMap.EverythingModeEnum; import ca.uhn.fhir.jpa.dao.SearchParameterMap.EverythingModeEnum;
import ca.uhn.fhir.model.api.IResource; 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.RestOperationTypeEnum;
import ca.uhn.fhir.rest.api.SortSpec; import ca.uhn.fhir.rest.api.SortSpec;
import ca.uhn.fhir.rest.param.DateRangeParam; import ca.uhn.fhir.rest.param.DateRangeParam;
@ -41,7 +41,7 @@ import ca.uhn.fhir.rest.server.interceptor.IServerInterceptor.ActionRequestDetai
public class FhirResourceDaoPatientDstu21 extends FhirResourceDaoDstu21<Patient>implements IFhirResourceDaoPatient<Patient> { public class FhirResourceDaoPatientDstu21 extends FhirResourceDaoDstu21<Patient>implements IFhirResourceDaoPatient<Patient> {
private IBundleProvider doEverythingOperation(IIdType theId, UnsignedIntDt theCount, DateRangeParam theLastUpdated, SortSpec theSort, StringAndListParam theContent, StringAndListParam theNarrative) { private IBundleProvider doEverythingOperation(IIdType theId, IPrimitiveType<Integer> theCount, DateRangeParam theLastUpdated, SortSpec theSort, StringAndListParam theContent, StringAndListParam theNarrative) {
SearchParameterMap paramMap = new SearchParameterMap(); SearchParameterMap paramMap = new SearchParameterMap();
if (theCount != null) { if (theCount != null) {
paramMap.setCount(theCount.getValue()); paramMap.setCount(theCount.getValue());
@ -66,7 +66,7 @@ public class FhirResourceDaoPatientDstu21 extends FhirResourceDaoDstu21<Patient>
} }
@Override @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<Integer> theCount, DateRangeParam theLastUpdated, SortSpec theSort, StringAndListParam theContent, StringAndListParam theNarrative) {
// Notify interceptors // Notify interceptors
ActionRequestDetails requestDetails = new ActionRequestDetails(null, getResourceName()); ActionRequestDetails requestDetails = new ActionRequestDetails(null, getResourceName());
notifyInterceptors(RestOperationTypeEnum.EXTENDED_OPERATION_INSTANCE, requestDetails); notifyInterceptors(RestOperationTypeEnum.EXTENDED_OPERATION_INSTANCE, requestDetails);
@ -75,7 +75,7 @@ public class FhirResourceDaoPatientDstu21 extends FhirResourceDaoDstu21<Patient>
} }
@Override @Override
public IBundleProvider patientTypeEverything(HttpServletRequest theServletRequest, UnsignedIntDt theCount, DateRangeParam theLastUpdated, SortSpec theSort, StringAndListParam theContent, StringAndListParam theNarrative) { public IBundleProvider patientTypeEverything(HttpServletRequest theServletRequest, IPrimitiveType<Integer> theCount, DateRangeParam theLastUpdated, SortSpec theSort, StringAndListParam theContent, StringAndListParam theNarrative) {
// Notify interceptors // Notify interceptors
ActionRequestDetails requestDetails = new ActionRequestDetails(null, getResourceName()); ActionRequestDetails requestDetails = new ActionRequestDetails(null, getResourceName());
notifyInterceptors(RestOperationTypeEnum.EXTENDED_OPERATION_TYPE, requestDetails); notifyInterceptors(RestOperationTypeEnum.EXTENDED_OPERATION_TYPE, requestDetails);

View File

@ -22,6 +22,7 @@ package ca.uhn.fhir.jpa.dao;
import javax.annotation.PostConstruct; import javax.annotation.PostConstruct;
import org.hl7.fhir.instance.hapi.validation.FhirQuestionnaireResponseValidator;
import org.hl7.fhir.instance.model.api.IBaseOperationOutcome; import org.hl7.fhir.instance.model.api.IBaseOperationOutcome;
import org.hl7.fhir.instance.model.api.IBaseResource; import org.hl7.fhir.instance.model.api.IBaseResource;
import org.hl7.fhir.instance.model.api.IIdType; import org.hl7.fhir.instance.model.api.IIdType;
@ -36,7 +37,6 @@ import ca.uhn.fhir.model.dstu2.resource.QuestionnaireResponse;
import ca.uhn.fhir.model.dstu2.resource.ValueSet; import ca.uhn.fhir.model.dstu2.resource.ValueSet;
import ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException; import ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException;
import ca.uhn.fhir.rest.server.exceptions.UnprocessableEntityException; import ca.uhn.fhir.rest.server.exceptions.UnprocessableEntityException;
import ca.uhn.fhir.validation.FhirQuestionnaireResponseValidator;
import ca.uhn.fhir.validation.FhirValidator; import ca.uhn.fhir.validation.FhirValidator;
import ca.uhn.fhir.validation.IResourceLoader; import ca.uhn.fhir.validation.IResourceLoader;
import ca.uhn.fhir.validation.ValidationResult; import ca.uhn.fhir.validation.ValidationResult;

View File

@ -22,33 +22,30 @@ package ca.uhn.fhir.jpa.dao;
import javax.annotation.PostConstruct; import javax.annotation.PostConstruct;
import org.hl7.fhir.dstu21.hapi.validation.FhirQuestionnaireResponseValidator;
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.IBaseOperationOutcome;
import org.hl7.fhir.instance.model.api.IBaseResource; import org.hl7.fhir.instance.model.api.IBaseResource;
import org.hl7.fhir.instance.model.api.IIdType; import org.hl7.fhir.instance.model.api.IIdType;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.jpa.entity.ResourceTable; 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.ResourceNotFoundException;
import ca.uhn.fhir.rest.server.exceptions.UnprocessableEntityException; import ca.uhn.fhir.rest.server.exceptions.UnprocessableEntityException;
import ca.uhn.fhir.validation.FhirQuestionnaireResponseValidator;
import ca.uhn.fhir.validation.FhirValidator; import ca.uhn.fhir.validation.FhirValidator;
import ca.uhn.fhir.validation.IResourceLoader; import ca.uhn.fhir.validation.IResourceLoader;
import ca.uhn.fhir.validation.ValidationResult; import ca.uhn.fhir.validation.ValidationResult;
public class FhirResourceDaoQuestionnaireResponseDstu21 extends FhirResourceDaoDstu21<QuestionnaireResponse> { public class FhirResourceDaoQuestionnaireResponseDstu21 extends FhirResourceDaoDstu21<QuestionnaireResponse> {
@Autowired
@Qualifier("myFhirContextDstu2Hl7Org")
private FhirContext myRefImplCtx;
private Boolean myValidateResponses; private Boolean myValidateResponses;
@Autowired
private IJpaValidationSupportDstu21 myValidationSupport;
/** /**
* Initialize the bean * Initialize the bean
*/ */
@ -74,17 +71,17 @@ public class FhirResourceDaoQuestionnaireResponseDstu21 extends FhirResourceDaoD
return; return;
} }
FhirValidator val = myRefImplCtx.newValidator(); FhirValidator val = getContext().newValidator();
val.setValidateAgainstStandardSchema(false); val.setValidateAgainstStandardSchema(false);
val.setValidateAgainstStandardSchematron(false); val.setValidateAgainstStandardSchematron(false);
FhirQuestionnaireResponseValidator module = new FhirQuestionnaireResponseValidator(); FhirQuestionnaireResponseValidator module = new FhirQuestionnaireResponseValidator();
module.setResourceLoader(new JpaResourceLoader()); module.setValidationSupport(myValidationSupport);
val.registerValidatorModule(module); val.registerValidatorModule(module);
ValidationResult result = val.validateWithResult(myRefImplCtx.newJsonParser().parseResource(getContext().newJsonParser().encodeResourceToString(qa))); ValidationResult result = val.validateWithResult(getContext().newJsonParser().parseResource(getContext().newJsonParser().encodeResourceToString(qa)));
if (!result.isSuccessful()) { if (!result.isSuccessful()) {
IBaseOperationOutcome oo = getContext().newJsonParser().parseResource(OperationOutcome.class, myRefImplCtx.newJsonParser().encodeResourceToString(result.toOperationOutcome())); IBaseOperationOutcome oo = getContext().newJsonParser().parseResource(OperationOutcome.class, getContext().newJsonParser().encodeResourceToString(result.toOperationOutcome()));
throw new UnprocessableEntityException(getContext(), oo); throw new UnprocessableEntityException(getContext(), oo);
} }
} }
@ -101,16 +98,11 @@ public class FhirResourceDaoQuestionnaireResponseDstu21 extends FhirResourceDaoD
if ("ValueSet".equals(theType.getSimpleName())) { if ("ValueSet".equals(theType.getSimpleName())) {
IFhirResourceDao<ValueSet> dao = getDao(ValueSet.class); IFhirResourceDao<ValueSet> dao = getDao(ValueSet.class);
ValueSet in = dao.read(theId); ValueSet in = dao.read(theId);
String encoded = getContext().newJsonParser().encodeResourceToString(in); return (T) in;
// TODO: this is temporary until structures-dstu2 catches up to structures-hl7org.dstu2
encoded = encoded.replace("\"define\"", "\"codeSystem\"");
return myRefImplCtx.newJsonParser().parseResource(theType, encoded);
} else if ("Questionnaire".equals(theType.getSimpleName())) { } else if ("Questionnaire".equals(theType.getSimpleName())) {
IFhirResourceDao<Questionnaire> dao = getDao(Questionnaire.class); IFhirResourceDao<Questionnaire> dao = getDao(Questionnaire.class);
Questionnaire vs = dao.read(theId); Questionnaire vs = dao.read(theId);
return myRefImplCtx.newJsonParser().parseResource(theType, getContext().newJsonParser().encodeResourceToString(vs)); return (T) vs;
} else { } else {
// Should not happen, validator will only ask for these two // Should not happen, validator will only ask for these two
throw new IllegalStateException("Unexpected request to load resource of type " + theType); throw new IllegalStateException("Unexpected request to load resource of type " + theType);

View File

@ -21,17 +21,16 @@ package ca.uhn.fhir.jpa.dao;
*/ */
import org.apache.commons.lang3.time.DateUtils; 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.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled; 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 FhirResourceDaoDstu21<SearchParameter>implements IFhirResourceDaoSearchParameter<SearchParameter> { public class FhirResourceDaoSearchParameterDstu21 extends FhirResourceDaoDstu21<SearchParameter>implements IFhirResourceDaoSearchParameter<SearchParameter> {
@Autowired @Autowired
private IFhirSystemDao<Bundle, MetaDt> mySystemDao; private IFhirSystemDao<Bundle, Meta> mySystemDao;
/** /**
* This method is called once per minute to perform any required re-indexing. During most passes this will * This method is called once per minute to perform any required re-indexing. During most passes this will

View File

@ -258,7 +258,7 @@ public class FhirResourceDaoSubscriptionDstu2 extends FhirResourceDaoDstu2<Subsc
} }
@Override @Override
protected ResourceTable updateEntity(IResource theResource, ResourceTable theEntity, boolean theUpdateHistory, Date theDeletedTimestampOrNull, boolean thePerformIndexing, boolean theUpdateVersion, protected ResourceTable updateEntity(IBaseResource theResource, ResourceTable theEntity, boolean theUpdateHistory, Date theDeletedTimestampOrNull, boolean thePerformIndexing, boolean theUpdateVersion,
Date theUpdateTime) { Date theUpdateTime) {
ResourceTable retVal = super.updateEntity(theResource, theEntity, theUpdateHistory, theDeletedTimestampOrNull, thePerformIndexing, theUpdateVersion, theUpdateTime); ResourceTable retVal = super.updateEntity(theResource, theEntity, theUpdateHistory, theDeletedTimestampOrNull, thePerformIndexing, theUpdateVersion, theUpdateTime);

View File

@ -30,6 +30,9 @@ import java.util.List;
import javax.persistence.Query; import javax.persistence.Query;
import org.apache.commons.lang3.time.DateUtils; import org.apache.commons.lang3.time.DateUtils;
import org.hl7.fhir.dstu21.model.Subscription;
import org.hl7.fhir.dstu21.model.Subscription.SubscriptionStatus;
import org.hl7.fhir.instance.model.api.IAnyResource;
import org.hl7.fhir.instance.model.api.IBaseResource; import org.hl7.fhir.instance.model.api.IBaseResource;
import org.hl7.fhir.instance.model.api.IIdType; import org.hl7.fhir.instance.model.api.IIdType;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@ -50,11 +53,8 @@ import ca.uhn.fhir.jpa.dao.data.ISubscriptionTableDao;
import ca.uhn.fhir.jpa.entity.ResourceTable; import ca.uhn.fhir.jpa.entity.ResourceTable;
import ca.uhn.fhir.jpa.entity.SubscriptionFlaggedResource; import ca.uhn.fhir.jpa.entity.SubscriptionFlaggedResource;
import ca.uhn.fhir.jpa.entity.SubscriptionTable; import ca.uhn.fhir.jpa.entity.SubscriptionTable;
import ca.uhn.fhir.model.api.IResource;
import ca.uhn.fhir.model.api.ResourceMetadataKeyEnum;
import ca.uhn.fhir.model.dstu.valueset.QuantityCompararatorEnum; import ca.uhn.fhir.model.dstu.valueset.QuantityCompararatorEnum;
import ca.uhn.fhir.model.dstu21.resource.Subscription; import ca.uhn.fhir.model.dstu2.valueset.SubscriptionStatusEnum;
import ca.uhn.fhir.model.dstu21.valueset.SubscriptionStatusEnum;
import ca.uhn.fhir.model.primitive.IdDt; import ca.uhn.fhir.model.primitive.IdDt;
import ca.uhn.fhir.model.primitive.InstantDt; import ca.uhn.fhir.model.primitive.InstantDt;
import ca.uhn.fhir.parser.DataFormatException; import ca.uhn.fhir.parser.DataFormatException;
@ -85,7 +85,7 @@ public class FhirResourceDaoSubscriptionDstu21 extends FhirResourceDaoDstu21<Sub
subscriptionEntity.setSubscriptionResource(theEntity); subscriptionEntity.setSubscriptionResource(theEntity);
subscriptionEntity.setNextCheck(theEntity.getPublished().getValue()); subscriptionEntity.setNextCheck(theEntity.getPublished().getValue());
subscriptionEntity.setMostRecentMatch(theEntity.getPublished().getValue()); subscriptionEntity.setMostRecentMatch(theEntity.getPublished().getValue());
subscriptionEntity.setStatus(theSubscription.getStatusElement().getValue()); subscriptionEntity.setStatus(theSubscription.getStatusElement().getValueAsString());
myEntityManager.persist(subscriptionEntity); myEntityManager.persist(subscriptionEntity);
} }
@ -157,7 +157,7 @@ public class FhirResourceDaoSubscriptionDstu21 extends FhirResourceDaoDstu21<Sub
return 0; return 0;
} }
ourLog.debug("Subscription {} search from {} to {}", new Object[] { subscription.getId().getIdPart(), new InstantDt(new Date(start)), new InstantDt(new Date(end)) }); ourLog.debug("Subscription {} search from {} to {}", new Object[] { subscription.getIdElement().getIdPart(), new InstantDt(new Date(start)), new InstantDt(new Date(end)) });
DateRangeParam range = new DateRangeParam(); DateRangeParam range = new DateRangeParam();
range.setLowerBound(new DateParam(QuantityCompararatorEnum.GREATERTHAN, start)); range.setLowerBound(new DateParam(QuantityCompararatorEnum.GREATERTHAN, start));
@ -170,13 +170,14 @@ public class FhirResourceDaoSubscriptionDstu21 extends FhirResourceDaoDstu21<Sub
return 0; return 0;
} }
ourLog.info("Found {} new results for Subscription {}", results.size(), subscription.getId().getIdPart()); ourLog.info("Found {} new results for Subscription {}", results.size(), subscription.getIdElement().getIdPart());
List<SubscriptionFlaggedResource> flags = new ArrayList<SubscriptionFlaggedResource>(); List<SubscriptionFlaggedResource> flags = new ArrayList<SubscriptionFlaggedResource>();
Date mostRecentMatch = null; 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) { if (mostRecentMatch == null) {
mostRecentMatch = updated; mostRecentMatch = updated;
} else { } else {
@ -188,7 +189,7 @@ public class FhirResourceDaoSubscriptionDstu21 extends FhirResourceDaoDstu21<Sub
} }
SubscriptionFlaggedResource nextFlag = new SubscriptionFlaggedResource(); SubscriptionFlaggedResource nextFlag = new SubscriptionFlaggedResource();
Long pid = IDao.RESOURCE_PID.get((IResource) next); Long pid = IDao.RESOURCE_PID.get(next);
ourLog.info("New resource for subscription: {}", pid); ourLog.info("New resource for subscription: {}", pid);
@ -200,7 +201,7 @@ public class FhirResourceDaoSubscriptionDstu21 extends FhirResourceDaoDstu21<Sub
mySubscriptionFlaggedResourceDataDao.save(flags); mySubscriptionFlaggedResourceDataDao.save(flags);
ourLog.debug("Updating most recent match for subcription {} to {}", subscription.getId().getIdPart(), new InstantDt(mostRecentMatch)); ourLog.debug("Updating most recent match for subcription {} to {}", subscription.getIdElement().getIdPart(), new InstantDt(mostRecentMatch));
theSubscriptionTable.setMostRecentMatch(mostRecentMatch); theSubscriptionTable.setMostRecentMatch(mostRecentMatch);
mySubscriptionTableDao.save(theSubscriptionTable); mySubscriptionTableDao.save(theSubscriptionTable);
@ -258,7 +259,7 @@ public class FhirResourceDaoSubscriptionDstu21 extends FhirResourceDaoDstu21<Sub
} }
@Override @Override
protected ResourceTable updateEntity(IResource theResource, ResourceTable theEntity, boolean theUpdateHistory, Date theDeletedTimestampOrNull, boolean thePerformIndexing, boolean theUpdateVersion, protected ResourceTable updateEntity(IBaseResource theResource, ResourceTable theEntity, boolean theUpdateHistory, Date theDeletedTimestampOrNull, boolean thePerformIndexing, boolean theUpdateVersion,
Date theUpdateTime) { Date theUpdateTime) {
ResourceTable retVal = super.updateEntity(theResource, theEntity, theUpdateHistory, theDeletedTimestampOrNull, thePerformIndexing, theUpdateVersion, theUpdateTime); ResourceTable retVal = super.updateEntity(theResource, theEntity, theUpdateHistory, theDeletedTimestampOrNull, thePerformIndexing, theUpdateVersion, theUpdateTime);
@ -273,9 +274,9 @@ public class FhirResourceDaoSubscriptionDstu21 extends FhirResourceDaoDstu21<Sub
} else { } else {
Query q = myEntityManager.createNamedQuery("Q_HFJ_SUBSCRIPTION_SET_STATUS"); Query q = myEntityManager.createNamedQuery("Q_HFJ_SUBSCRIPTION_SET_STATUS");
q.setParameter("res_id", resourceId); q.setParameter("res_id", resourceId);
q.setParameter("status", resource.getStatusElement().getValue()); q.setParameter("status", resource.getStatusElement().getValueAsString());
if (q.executeUpdate() > 0) { if (q.executeUpdate() > 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 { } else {
createSubscriptionTable(retVal, resource); createSubscriptionTable(retVal, resource);
} }
@ -323,7 +324,7 @@ public class FhirResourceDaoSubscriptionDstu21 extends FhirResourceDaoDstu21<Sub
throw new UnprocessableEntityException("Subscription.channel.type must be populated on this server"); throw new UnprocessableEntityException("Subscription.channel.type must be populated on this server");
} }
SubscriptionStatusEnum status = theResource.getStatusElement().getValueAsEnum(); SubscriptionStatus status = theResource.getStatus();
if (status == null) { if (status == null) {
throw new UnprocessableEntityException("Subscription.status must be populated on this server"); throw new UnprocessableEntityException("Subscription.status must be populated on this server");
} }

View File

@ -31,6 +31,8 @@ import java.util.Set;
import javax.annotation.PostConstruct; import javax.annotation.PostConstruct;
import org.apache.commons.codec.binary.StringUtils; import org.apache.commons.codec.binary.StringUtils;
import org.hl7.fhir.instance.hapi.validation.DefaultProfileValidationSupport;
import org.hl7.fhir.instance.hapi.validation.ValidationSupportChain;
import org.hl7.fhir.instance.model.api.IIdType; import org.hl7.fhir.instance.model.api.IIdType;
import org.hl7.fhir.instance.model.api.IPrimitiveType; import org.hl7.fhir.instance.model.api.IPrimitiveType;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@ -45,23 +47,18 @@ import ca.uhn.fhir.model.dstu2.resource.ValueSet.CodeSystemConcept;
import ca.uhn.fhir.model.dstu2.resource.ValueSet.ComposeInclude; import ca.uhn.fhir.model.dstu2.resource.ValueSet.ComposeInclude;
import ca.uhn.fhir.model.dstu2.resource.ValueSet.ComposeIncludeConcept; import ca.uhn.fhir.model.dstu2.resource.ValueSet.ComposeIncludeConcept;
import ca.uhn.fhir.model.dstu2.resource.ValueSet.ExpansionContains; import ca.uhn.fhir.model.dstu2.resource.ValueSet.ExpansionContains;
import ca.uhn.fhir.model.primitive.CodeDt;
import ca.uhn.fhir.model.primitive.DateTimeDt; import ca.uhn.fhir.model.primitive.DateTimeDt;
import ca.uhn.fhir.model.primitive.IdDt; 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.TokenParam;
import ca.uhn.fhir.rest.param.UriParam; import ca.uhn.fhir.rest.param.UriParam;
import ca.uhn.fhir.rest.server.IBundleProvider; import ca.uhn.fhir.rest.server.IBundleProvider;
import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException; import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException;
import ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException; import ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException;
import ca.uhn.fhir.validation.DefaultProfileValidationSupport;
import ca.uhn.fhir.validation.ValidationSupportChain;
public class FhirResourceDaoValueSetDstu2 extends FhirResourceDaoDstu2<ValueSet>implements IFhirResourceDaoValueSet<ValueSet, CodingDt, CodeableConceptDt> { public class FhirResourceDaoValueSetDstu2 extends FhirResourceDaoDstu2<ValueSet>implements IFhirResourceDaoValueSet<ValueSet, CodingDt, CodeableConceptDt> {
@Autowired @Autowired
private IJpaValidationSupport myJpaValidationSupport; private IJpaValidationSupportDstu2 myJpaValidationSupport;
private ValidationSupportChain myValidationSupport; private ValidationSupportChain myValidationSupport;
@ -181,8 +178,7 @@ public class FhirResourceDaoValueSetDstu2 extends FhirResourceDaoDstu2<ValueSet>
} }
@Override @Override
public ca.uhn.fhir.jpa.dao.IFhirResourceDaoValueSet.ValidateCodeResult validateCode(UriDt theValueSetIdentifier, IIdType theId, CodeDt theCode, UriDt theSystem, StringDt theDisplay, public ca.uhn.fhir.jpa.dao.IFhirResourceDaoValueSet.ValidateCodeResult validateCode(IPrimitiveType<String> theValueSetIdentifier, IIdType theId, IPrimitiveType<String> theCode, IPrimitiveType<String> theSystem, IPrimitiveType<String> theDisplay, CodingDt theCoding, CodeableConceptDt theCodeableConcept) {
CodingDt theCoding, CodeableConceptDt theCodeableConcept) {
List<IIdType> valueSetIds; List<IIdType> valueSetIds;
boolean haveCodeableConcept = theCodeableConcept != null && theCodeableConcept.getCoding().size() > 0; boolean haveCodeableConcept = theCodeableConcept != null && theCodeableConcept.getCoding().size() > 0;
@ -292,7 +288,7 @@ public class FhirResourceDaoValueSetDstu2 extends FhirResourceDaoDstu2<ValueSet>
} }
@Override @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<String> theCode, IPrimitiveType<String> theSystem, CodingDt theCoding) {
boolean haveCoding = theCoding != null && isNotBlank(theCoding.getSystem()) && isNotBlank(theCoding.getCode()); boolean haveCoding = theCoding != null && isNotBlank(theCoding.getSystem()) && isNotBlank(theCoding.getCode());
boolean haveCode = theCode != null && theCode.isEmpty() == false; boolean haveCode = theCode != null && theCode.isEmpty() == false;
boolean haveSystem = theSystem != null && theSystem.isEmpty() == false; boolean haveSystem = theSystem != null && theSystem.isEmpty() == false;

View File

@ -25,50 +25,45 @@ import static org.apache.commons.lang3.StringUtils.isNotBlank;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.Date;
import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
import javax.annotation.PostConstruct; import javax.annotation.PostConstruct;
import org.apache.commons.codec.binary.StringUtils; import org.apache.commons.codec.binary.StringUtils;
import org.hl7.fhir.dstu21.hapi.validation.DefaultProfileValidationSupport;
import org.hl7.fhir.dstu21.hapi.validation.HapiWorkerContext;
import org.hl7.fhir.dstu21.hapi.validation.ValidationSupportChain;
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.ValueSetExpansionComponent;
import org.hl7.fhir.dstu21.model.ValueSet.ValueSetExpansionContainsComponent;
import org.hl7.fhir.dstu21.terminologies.ValueSetExpander;
import org.hl7.fhir.dstu21.terminologies.ValueSetExpander.ValueSetExpansionOutcome;
import org.hl7.fhir.instance.model.api.IIdType; import org.hl7.fhir.instance.model.api.IIdType;
import org.hl7.fhir.instance.model.api.IPrimitiveType; import org.hl7.fhir.instance.model.api.IPrimitiveType;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
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.TokenParam;
import ca.uhn.fhir.rest.param.UriParam; import ca.uhn.fhir.rest.param.UriParam;
import ca.uhn.fhir.rest.server.IBundleProvider; import ca.uhn.fhir.rest.server.IBundleProvider;
import ca.uhn.fhir.rest.server.exceptions.InternalErrorException;
import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException; import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException;
import ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException;
import ca.uhn.fhir.validation.DefaultProfileValidationSupport;
import ca.uhn.fhir.validation.ValidationSupportChain;
public class FhirResourceDaoValueSetDstu21 extends FhirResourceDaoDstu21<ValueSet>implements IFhirResourceDaoValueSet<ValueSet, CodingDt, CodeableConceptDt> { public class FhirResourceDaoValueSetDstu21 extends FhirResourceDaoDstu21<ValueSet> implements IFhirResourceDaoValueSet<ValueSet, Coding, CodeableConcept> {
@Autowired @Autowired
private IJpaValidationSupport myJpaValidationSupport; private IJpaValidationSupportDstu21 myJpaValidationSupport;
private ValidationSupportChain myValidationSupport; private ValidationSupportChain myValidationSupport;
@Autowired
@Qualifier("myFhirContextDstu2Hl7Org")
private FhirContext myRiCtx;
private DefaultProfileValidationSupport myDefaultProfileValidationSupport; private DefaultProfileValidationSupport myDefaultProfileValidationSupport;
@Override @Override
@ -81,24 +76,23 @@ public class FhirResourceDaoValueSetDstu21 extends FhirResourceDaoDstu21<ValueSe
@Override @Override
public ValueSet expand(IIdType theId, String theFilter) { public ValueSet expand(IIdType theId, String theFilter) {
ValueSet source = loadValueSetForExpansion(theId); HapiWorkerContext workerContext = new HapiWorkerContext(getContext(), myValidationSupport);
return expand(source, theFilter); ValueSet source = workerContext.fetchResource(ValueSet.class, theId.getValue());
ValueSetExpansionOutcome outcome = workerContext.expand(source);
ValueSetExpansionComponent expansion = outcome.getValueset().getExpansion();
if (isNotBlank(theFilter)) {
for (Iterator<ValueSetExpansionContainsComponent> containsIter = expansion.getContains().iterator(); containsIter.hasNext();) {
ValueSetExpansionContainsComponent nextContains = containsIter.next();
if (!nextContains.getDisplay().toLowerCase().contains(theFilter.toLowerCase())) {
containsIter.remove();
}
}
} }
private ValueSet loadValueSetForExpansion(IIdType theId) { ValueSet retVal = new ValueSet();
if (theId.getValue().startsWith("http://hl7.org/fhir/")) { retVal.setExpansion(expansion);
org.hl7.fhir.instance.model.ValueSet valueSet = myValidationSupport.fetchResource(myRiCtx, org.hl7.fhir.instance.model.ValueSet.class, theId.getValue()); return retVal;
if (valueSet != null) {
return getContext().newJsonParser().parseResource(ValueSet.class, myRiCtx.newJsonParser().encodeResourceToString(valueSet));
}
}
BaseHasResource sourceEntity = readEntity(theId);
if (sourceEntity == null) {
throw new ResourceNotFoundException(theId);
}
ValueSet source = (ValueSet) toResource(sourceEntity, false);
return source;
} }
@Override @Override
@ -108,9 +102,9 @@ public class FhirResourceDaoValueSetDstu21 extends FhirResourceDaoDstu21<ValueSe
} }
ValueSet source; ValueSet source;
org.hl7.fhir.instance.model.ValueSet defaultValueSet = myDefaultProfileValidationSupport.fetchResource(myRiCtx, org.hl7.fhir.instance.model.ValueSet.class, theUri); org.hl7.fhir.instance.model.ValueSet defaultValueSet = myDefaultProfileValidationSupport.fetchResource(getContext(), org.hl7.fhir.instance.model.ValueSet.class, theUri);
if (defaultValueSet != null) { if (defaultValueSet != null) {
source = getContext().newJsonParser().parseResource(ValueSet.class, myRiCtx.newJsonParser().encodeResourceToString(defaultValueSet)); source = getContext().newJsonParser().parseResource(ValueSet.class, getContext().newJsonParser().encodeResourceToString(defaultValueSet));
} else { } else {
IBundleProvider ids = search(ValueSet.SP_URL, new UriParam(theUri)); IBundleProvider ids = search(ValueSet.SP_URL, new UriParam(theUri));
if (ids.size() == 0) { if (ids.size() == 0) {
@ -126,14 +120,14 @@ public class FhirResourceDaoValueSetDstu21 extends FhirResourceDaoDstu21<ValueSe
@Override @Override
public ValueSet expand(ValueSet source, String theFilter) { public ValueSet expand(ValueSet source, String theFilter) {
ValueSet retVal = new ValueSet(); ValueSet retVal = new ValueSet();
retVal.setDate(DateTimeDt.withCurrentTime()); retVal.setDate(new Date());
/* /*
* Add composed concepts * Add composed concepts
*/ */
for (ComposeInclude nextInclude : source.getCompose().getInclude()) { for (ConceptSetComponent nextInclude : source.getCompose().getInclude()) {
for (ComposeIncludeConcept next : nextInclude.getConcept()) { for (ConceptReferenceComponent next : nextInclude.getConcept()) {
if (isBlank(theFilter)) { if (isBlank(theFilter)) {
addCompose(retVal, nextInclude.getSystem(), next.getCode(), next.getDisplay()); addCompose(retVal, nextInclude.getSystem(), next.getCode(), next.getDisplay());
} else { } else {
@ -149,14 +143,14 @@ public class FhirResourceDaoValueSetDstu21 extends FhirResourceDaoDstu21<ValueSe
* Add defined concepts * Add defined concepts
*/ */
for (CodeSystemConcept next : source.getCodeSystem().getConcept()) { for (ConceptDefinitionComponent next : source.getCodeSystem().getConcept()) {
addCompose(theFilter, retVal, source, next); addCompose(theFilter, retVal, source, next);
} }
return retVal; return retVal;
} }
private void addCompose(String theFilter, ValueSet theValueSetToPopulate, ValueSet theSourceValueSet, CodeSystemConcept theConcept) { private void addCompose(String theFilter, ValueSet theValueSetToPopulate, ValueSet theSourceValueSet, ConceptDefinitionComponent theConcept) {
if (isBlank(theFilter)) { if (isBlank(theFilter)) {
addCompose(theValueSetToPopulate, theSourceValueSet.getCodeSystem().getSystem(), theConcept.getCode(), theConcept.getDisplay()); addCompose(theValueSetToPopulate, theSourceValueSet.getCodeSystem().getSystem(), theConcept.getCode(), theConcept.getDisplay());
} else { } else {
@ -165,7 +159,7 @@ public class FhirResourceDaoValueSetDstu21 extends FhirResourceDaoDstu21<ValueSe
addCompose(theValueSetToPopulate, theSourceValueSet.getCodeSystem().getSystem(), theConcept.getCode(), theConcept.getDisplay()); addCompose(theValueSetToPopulate, theSourceValueSet.getCodeSystem().getSystem(), theConcept.getCode(), theConcept.getDisplay());
} }
} }
for (CodeSystemConcept nextChild : theConcept.getConcept()) { for (ConceptDefinitionComponent nextChild : theConcept.getConcept()) {
addCompose(theFilter, theValueSetToPopulate, theSourceValueSet, nextChild); addCompose(theFilter, theValueSetToPopulate, theSourceValueSet, nextChild);
} }
} }
@ -174,15 +168,15 @@ public class FhirResourceDaoValueSetDstu21 extends FhirResourceDaoDstu21<ValueSe
if (isBlank(theCode)) { if (isBlank(theCode)) {
return; return;
} }
ExpansionContains contains = retVal.getExpansion().addContains(); ValueSetExpansionContainsComponent contains = retVal.getExpansion().addContains();
contains.setSystem(theSystem); contains.setSystem(theSystem);
contains.setCode(theCode); contains.setCode(theCode);
contains.setDisplay(theDisplay); contains.setDisplay(theDisplay);
} }
@Override @Override
public ca.uhn.fhir.jpa.dao.IFhirResourceDaoValueSet.ValidateCodeResult validateCode(UriDt theValueSetIdentifier, IIdType theId, CodeDt theCode, UriDt theSystem, StringDt theDisplay, public ca.uhn.fhir.jpa.dao.IFhirResourceDaoValueSet.ValidateCodeResult validateCode(IPrimitiveType<String> theValueSetIdentifier, IIdType theId, IPrimitiveType<String> theCode, IPrimitiveType<String> theSystem, IPrimitiveType<String> theDisplay, Coding theCoding,
CodingDt theCoding, CodeableConceptDt theCodeableConcept) { CodeableConcept theCodeableConcept) {
List<IIdType> valueSetIds; List<IIdType> valueSetIds;
boolean haveCodeableConcept = theCodeableConcept != null && theCodeableConcept.getCoding().size() > 0; boolean haveCodeableConcept = theCodeableConcept != null && theCodeableConcept.getCoding().size() > 0;
@ -203,7 +197,7 @@ public class FhirResourceDaoValueSetDstu21 extends FhirResourceDaoDstu21<ValueSe
Set<Long> ids = searchForIds(ValueSet.SP_IDENTIFIER, new TokenParam(null, theValueSetIdentifier.getValue())); Set<Long> ids = searchForIds(ValueSet.SP_IDENTIFIER, new TokenParam(null, theValueSetIdentifier.getValue()));
valueSetIds = new ArrayList<IIdType>(); valueSetIds = new ArrayList<IIdType>();
for (Long next : ids) { for (Long next : ids) {
valueSetIds.add(new IdDt("ValueSet", next)); valueSetIds.add(new IdType("ValueSet", next));
} }
} else { } else {
if (theCode == null || theCode.isEmpty()) { if (theCode == null || theCode.isEmpty()) {
@ -216,7 +210,7 @@ public class FhirResourceDaoValueSetDstu21 extends FhirResourceDaoDstu21<ValueSe
for (IIdType nextId : valueSetIds) { for (IIdType nextId : valueSetIds) {
ValueSet expansion = expand(nextId, null); ValueSet expansion = expand(nextId, null);
List<ExpansionContains> contains = expansion.getExpansion().getContains(); List<ValueSetExpansionContainsComponent> contains = expansion.getExpansion().getContains();
ValidateCodeResult result = validateCodeIsInContains(contains, toStringOrNull(theSystem), toStringOrNull(theCode), theCoding, theCodeableConcept); ValidateCodeResult result = validateCodeIsInContains(contains, toStringOrNull(theSystem), toStringOrNull(theCode), theCoding, theCodeableConcept);
if (result != null) { if (result != null) {
if (theDisplay != null && isNotBlank(theDisplay.getValue()) && isNotBlank(result.getDisplay())) { if (theDisplay != null && isNotBlank(theDisplay.getValue()) && isNotBlank(result.getDisplay())) {
@ -232,15 +226,15 @@ public class FhirResourceDaoValueSetDstu21 extends FhirResourceDaoDstu21<ValueSe
} }
private List<IIdType> findValueSetIdsContainingSystemAndCode(String theCode, String theSystem) { private List<IIdType> findValueSetIdsContainingSystemAndCode(String theCode, String theSystem) {
if (theSystem != null && theSystem.startsWith("http://hl7.org/fhir/")) { // if (theSystem != null && theSystem.startsWith("http://hl7.org/fhir/ValueSet")) {
return Collections.singletonList((IIdType)new IdDt(theSystem)); // return Collections.singletonList((IIdType) new IdType(theSystem));
} // }
List<IIdType> valueSetIds; List<IIdType> valueSetIds;
Set<Long> ids = searchForIds(ValueSet.SP_CODE, new TokenParam(theSystem, theCode)); Set<Long> ids = searchForIds(ValueSet.SP_CODE, new TokenParam(theSystem, theCode));
valueSetIds = new ArrayList<IIdType>(); valueSetIds = new ArrayList<IIdType>();
for (Long next : ids) { for (Long next : ids) {
valueSetIds.add(new IdDt("ValueSet", next)); valueSetIds.add(new IdType("ValueSet", next));
} }
return valueSetIds; return valueSetIds;
} }
@ -259,9 +253,8 @@ public class FhirResourceDaoValueSetDstu21 extends FhirResourceDaoDstu21<ValueSe
return thePrimitive != null ? thePrimitive.getValue() : null; return thePrimitive != null ? thePrimitive.getValue() : null;
} }
private ca.uhn.fhir.jpa.dao.IFhirResourceDaoValueSet.ValidateCodeResult validateCodeIsInContains(List<ExpansionContains> contains, String theSystem, String theCode, CodingDt theCoding, private ca.uhn.fhir.jpa.dao.IFhirResourceDaoValueSet.ValidateCodeResult validateCodeIsInContains(List<ValueSetExpansionContainsComponent> contains, String theSystem, String theCode, Coding theCoding, CodeableConcept theCodeableConcept) {
CodeableConceptDt theCodeableConcept) { for (ValueSetExpansionContainsComponent nextCode : contains) {
for (ExpansionContains nextCode : contains) {
ca.uhn.fhir.jpa.dao.IFhirResourceDaoValueSet.ValidateCodeResult result = validateCodeIsInContains(nextCode.getContains(), theSystem, theCode, theCoding, theCodeableConcept); ca.uhn.fhir.jpa.dao.IFhirResourceDaoValueSet.ValidateCodeResult result = validateCodeIsInContains(nextCode.getContains(), theSystem, theCode, theCoding, theCodeableConcept);
if (result != null) { if (result != null) {
return result; return result;
@ -279,7 +272,7 @@ public class FhirResourceDaoValueSetDstu21 extends FhirResourceDaoDstu21<ValueSe
return new ValidateCodeResult(true, "Validation succeeded", nextCode.getDisplay()); return new ValidateCodeResult(true, "Validation succeeded", nextCode.getDisplay());
} }
} else { } else {
for (CodingDt next : theCodeableConcept.getCoding()) { for (Coding next : theCodeableConcept.getCoding()) {
if (StringUtils.equals(system, next.getSystem()) && StringUtils.equals(code, next.getCode())) { if (StringUtils.equals(system, next.getSystem()) && StringUtils.equals(code, next.getCode())) {
return new ValidateCodeResult(true, "Validation succeeded", nextCode.getDisplay()); return new ValidateCodeResult(true, "Validation succeeded", nextCode.getDisplay());
} }
@ -292,7 +285,7 @@ public class FhirResourceDaoValueSetDstu21 extends FhirResourceDaoDstu21<ValueSe
} }
@Override @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<String> theCode, IPrimitiveType<String> theSystem, Coding theCoding) {
boolean haveCoding = theCoding != null && isNotBlank(theCoding.getSystem()) && isNotBlank(theCoding.getCode()); boolean haveCoding = theCoding != null && isNotBlank(theCoding.getSystem()) && isNotBlank(theCoding.getCode());
boolean haveCode = theCode != null && theCode.isEmpty() == false; boolean haveCode = theCode != null && theCode.isEmpty() == false;
boolean haveSystem = theSystem != null && theSystem.isEmpty() == false; boolean haveSystem = theSystem != null && theSystem.isEmpty() == false;
@ -314,25 +307,75 @@ public class FhirResourceDaoValueSetDstu21 extends FhirResourceDaoDstu21<ValueSe
system = theSystem.getValue(); system = theSystem.getValue();
} }
List<IIdType> valueSetIds = findValueSetIdsContainingSystemAndCode(code, system); // CodeValidationResult validateOutcome = myJpaValidationSupport.validateCode(getContext(), system, code, null);
for (IIdType nextId : valueSetIds) { //
ValueSet expansion = expand(nextId, null); // LookupCodeResult result = new LookupCodeResult();
List<ExpansionContains> contains = expansion.getExpansion().getContains(); // result.setSearchedForCode(code);
// result.setSearchedForSystem(system);
// result.setFound(false);
// if (validateOutcome.isOk()) {
// result.setFound(true);
// result.setCodeIsAbstract(validateOutcome.asConceptDefinition().getAbstract());
// result.setCodeDisplay(validateOutcome.asConceptDefinition().getDisplay());
// }
// return result;
if (myValidationSupport.isCodeSystemSupported(getContext(), system)) {
HapiWorkerContext ctx = new HapiWorkerContext(getContext(), myValidationSupport);
ValueSetExpander expander = ctx.getExpander();
ValueSet source = new ValueSet();
source.getCompose().addInclude().setSystem(system).addConcept().setCode(code);
ValueSetExpansionOutcome expansion;
try {
expansion = expander.expand(source);
} catch (Exception e) {
throw new InternalErrorException(e);
}
List<ValueSetExpansionContainsComponent> contains = expansion.getValueset().getExpansion().getContains();
ca.uhn.fhir.jpa.dao.IFhirResourceDaoValueSet.LookupCodeResult result = lookup(contains, system, code); ca.uhn.fhir.jpa.dao.IFhirResourceDaoValueSet.LookupCodeResult result = lookup(contains, system, code);
if (result != null) { if (result != null) {
return result; return result;
} }
} else {
/*
* If it's not a built-in code system, use ones from the database
*/
List<IIdType> valueSetIds = findValueSetIdsContainingSystemAndCode(code, system);
for (IIdType nextId : valueSetIds) {
ValueSet expansion = read(nextId);
for (ConceptDefinitionComponent next : expansion.getCodeSystem().getConcept()) {
if (code.equals(next.getCode())) {
ca.uhn.fhir.jpa.dao.IFhirResourceDaoValueSet.LookupCodeResult retVal = new LookupCodeResult();
retVal.setSearchedForCode(code);
retVal.setSearchedForSystem(system);
retVal.setFound(true);
if (next.getAbstractElement().getValue() != null) {
retVal.setCodeIsAbstract(next.getAbstractElement().booleanValue());
}
retVal.setCodeDisplay(next.getDisplay());
retVal.setCodeSystemDisplayName("Unknown"); // TODO: implement
return retVal;
}
}
} }
}
// We didn't find it..
LookupCodeResult retVal = new LookupCodeResult(); LookupCodeResult retVal = new LookupCodeResult();
retVal.setFound(false); retVal.setFound(false);
retVal.setSearchedForCode(code); retVal.setSearchedForCode(code);
retVal.setSearchedForSystem(system); retVal.setSearchedForSystem(system);
return retVal; return retVal;
} }
private ca.uhn.fhir.jpa.dao.IFhirResourceDaoValueSet.LookupCodeResult lookup(List<ExpansionContains> theContains, String theSystem, String theCode) { private ca.uhn.fhir.jpa.dao.IFhirResourceDaoValueSet.LookupCodeResult lookup(List<ValueSetExpansionContainsComponent> theContains, String theSystem, String theCode) {
for (ExpansionContains nextCode : theContains) { for (ValueSetExpansionContainsComponent nextCode : theContains) {
String system = nextCode.getSystem(); String system = nextCode.getSystem();
String code = nextCode.getCode(); String code = nextCode.getCode();
@ -341,8 +384,8 @@ public class FhirResourceDaoValueSetDstu21 extends FhirResourceDaoDstu21<ValueSe
retVal.setSearchedForCode(code); retVal.setSearchedForCode(code);
retVal.setSearchedForSystem(system); retVal.setSearchedForSystem(system);
retVal.setFound(true); retVal.setFound(true);
if (nextCode.getAbstract() != null) { if (nextCode.getAbstractElement().getValue() != null) {
retVal.setCodeIsAbstract(nextCode.getAbstract().booleanValue()); retVal.setCodeIsAbstract(nextCode.getAbstractElement().booleanValue());
} }
retVal.setCodeDisplay(nextCode.getDisplay()); retVal.setCodeDisplay(nextCode.getDisplay());
retVal.setCodeSystemVersion(nextCode.getVersion()); retVal.setCodeSystemVersion(nextCode.getVersion());

View File

@ -39,8 +39,21 @@ import java.util.Set;
import javax.persistence.TypedQuery; import javax.persistence.TypedQuery;
import org.apache.http.NameValuePair; import org.apache.http.NameValuePair;
import org.hl7.fhir.dstu21.model.Bundle;
import org.hl7.fhir.dstu21.model.Bundle.BundleEntryComponent;
import org.hl7.fhir.dstu21.model.Bundle.BundleEntryResponseComponent;
import org.hl7.fhir.dstu21.model.Bundle.BundleType;
import org.hl7.fhir.dstu21.model.Bundle.HTTPVerb;
import org.hl7.fhir.dstu21.model.IdType;
import org.hl7.fhir.dstu21.model.Meta;
import org.hl7.fhir.dstu21.model.OperationOutcome;
import org.hl7.fhir.dstu21.model.OperationOutcome.IssueSeverity;
import org.hl7.fhir.dstu21.model.Resource;
import org.hl7.fhir.instance.model.api.IAnyResource;
import org.hl7.fhir.instance.model.api.IBaseReference;
import org.hl7.fhir.instance.model.api.IBaseResource; import org.hl7.fhir.instance.model.api.IBaseResource;
import org.hl7.fhir.instance.model.api.IIdType; import org.hl7.fhir.instance.model.api.IIdType;
import org.hl7.fhir.instance.model.api.IPrimitiveType;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.PlatformTransactionManager; import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.TransactionDefinition; import org.springframework.transaction.TransactionDefinition;
@ -60,15 +73,6 @@ import ca.uhn.fhir.jpa.util.DeleteConflict;
import ca.uhn.fhir.model.api.IResource; import ca.uhn.fhir.model.api.IResource;
import ca.uhn.fhir.model.api.ResourceMetadataKeyEnum; import ca.uhn.fhir.model.api.ResourceMetadataKeyEnum;
import ca.uhn.fhir.model.base.composite.BaseResourceReferenceDt; import ca.uhn.fhir.model.base.composite.BaseResourceReferenceDt;
import ca.uhn.fhir.model.dstu21.composite.MetaDt;
import ca.uhn.fhir.model.dstu21.resource.Bundle;
import ca.uhn.fhir.model.dstu21.resource.Bundle.Entry;
import ca.uhn.fhir.model.dstu21.resource.Bundle.EntryResponse;
import ca.uhn.fhir.model.dstu21.resource.OperationOutcome;
import ca.uhn.fhir.model.dstu21.valueset.BundleTypeEnum;
import ca.uhn.fhir.model.dstu21.valueset.HTTPVerbEnum;
import ca.uhn.fhir.model.dstu21.valueset.IssueSeverityEnum;
import ca.uhn.fhir.model.primitive.IdDt;
import ca.uhn.fhir.model.primitive.InstantDt; import ca.uhn.fhir.model.primitive.InstantDt;
import ca.uhn.fhir.parser.DataFormatException; import ca.uhn.fhir.parser.DataFormatException;
import ca.uhn.fhir.parser.IParser; import ca.uhn.fhir.parser.IParser;
@ -90,7 +94,7 @@ import ca.uhn.fhir.util.FhirTerser;
import ca.uhn.fhir.util.UrlUtil; import ca.uhn.fhir.util.UrlUtil;
import ca.uhn.fhir.util.UrlUtil.UrlParts; import ca.uhn.fhir.util.UrlUtil.UrlParts;
public class FhirSystemDaoDstu21 extends BaseHapiFhirSystemDao<Bundle, MetaDt> { public class FhirSystemDaoDstu21 extends BaseHapiFhirSystemDao<Bundle, Meta> {
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(FhirSystemDaoDstu21.class); private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(FhirSystemDaoDstu21.class);
@Autowired @Autowired
@ -104,7 +108,7 @@ public class FhirSystemDaoDstu21 extends BaseHapiFhirSystemDao<Bundle, MetaDt> {
txTemplate.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES_NEW); txTemplate.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES_NEW);
Bundle resp = new Bundle(); Bundle resp = new Bundle();
resp.setType(BundleTypeEnum.BATCH_RESPONSE); resp.setType(BundleType.BATCHRESPONSE);
OperationOutcome ooResp = new OperationOutcome(); OperationOutcome ooResp = new OperationOutcome();
resp.addEntry().setResource(ooResp); resp.addEntry().setResource(ooResp);
@ -112,13 +116,13 @@ public class FhirSystemDaoDstu21 extends BaseHapiFhirSystemDao<Bundle, MetaDt> {
* 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 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<Bundle> callback = new TransactionCallback<Bundle>() { TransactionCallback<Bundle> callback = new TransactionCallback<Bundle>() {
@Override @Override
public Bundle doInTransaction(TransactionStatus theStatus) { public Bundle doInTransaction(TransactionStatus theStatus) {
Bundle subRequestBundle = new Bundle(); Bundle subRequestBundle = new Bundle();
subRequestBundle.setType(BundleTypeEnum.TRANSACTION); subRequestBundle.setType(BundleType.TRANSACTION);
subRequestBundle.addEntry(nextRequestEntry); subRequestBundle.addEntry(nextRequestEntry);
Bundle subResponseBundle = transaction((ServletRequestDetails) theRequestDetails, subRequestBundle, "Batch sub-request"); Bundle subResponseBundle = transaction((ServletRequestDetails) theRequestDetails, subRequestBundle, "Batch sub-request");
@ -131,7 +135,7 @@ public class FhirSystemDaoDstu21 extends BaseHapiFhirSystemDao<Bundle, MetaDt> {
Bundle nextResponseBundle = txTemplate.execute(callback); Bundle nextResponseBundle = txTemplate.execute(callback);
caughtEx = null; caughtEx = null;
Entry subResponseEntry = nextResponseBundle.getEntry().get(0); BundleEntryComponent subResponseEntry = nextResponseBundle.getEntry().get(0);
resp.addEntry(subResponseEntry); 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 * 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<Bundle, MetaDt> {
} }
if (caughtEx != null) { if (caughtEx != null) {
Entry nextEntry = resp.addEntry(); BundleEntryComponent nextEntry = resp.addEntry();
OperationOutcome oo = new OperationOutcome(); OperationOutcome oo = new OperationOutcome();
oo.addIssue().setSeverity(IssueSeverityEnum.ERROR).setDiagnostics(caughtEx.getMessage()); oo.addIssue().setSeverity(IssueSeverity.ERROR).setDiagnostics(caughtEx.getMessage());
nextEntry.setResource(oo); nextEntry.setResource(oo);
EntryResponse nextEntryResp = nextEntry.getResponse(); BundleEntryResponseComponent nextEntryResp = nextEntry.getResponse();
nextEntryResp.setStatus(toStatusString(caughtEx.getStatusCode())); nextEntryResp.setStatus(toStatusString(caughtEx.getStatusCode()));
} }
@ -162,12 +166,12 @@ public class FhirSystemDaoDstu21 extends BaseHapiFhirSystemDao<Bundle, MetaDt> {
long delay = System.currentTimeMillis() - start; long delay = System.currentTimeMillis() - start;
ourLog.info("Batch completed in {}ms", new Object[] { delay }); 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; return resp;
} }
private String extractTransactionUrlOrThrowException(Entry nextEntry, HTTPVerbEnum verb) { private String extractTransactionUrlOrThrowException(BundleEntryComponent nextEntry, HTTPVerb verb) {
String url = nextEntry.getRequest().getUrl(); String url = nextEntry.getRequest().getUrl();
if (isBlank(url)) { if (isBlank(url)) {
throw new InvalidRequestException(getContext().getLocalizer().getMessage(BaseHapiFhirSystemDao.class, "transactionMissingUrl", verb.name())); throw new InvalidRequestException(getContext().getLocalizer().getMessage(BaseHapiFhirSystemDao.class, "transactionMissingUrl", verb.name()));
@ -189,8 +193,8 @@ public class FhirSystemDaoDstu21 extends BaseHapiFhirSystemDao<Bundle, MetaDt> {
return p.parseResource(theResource.getClass(), p.encodeResourceToString(theResource)); return p.parseResource(theResource.getClass(), p.encodeResourceToString(theResource));
} }
private IFhirResourceDao<?> getDaoOrThrowException(Class<? extends IResource> theClass) { private IFhirResourceDao<?> getDaoOrThrowException(Class<? extends IBaseResource> theClass) {
IFhirResourceDao<? extends IResource> retVal = getDao(theClass); IFhirResourceDao<? extends IBaseResource> retVal = getDao(theClass);
if (retVal == null) { 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()); 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<Bundle, MetaDt> {
} }
@Override @Override
public MetaDt metaGetOperation() { public Meta metaGetOperation() {
// Notify interceptors // Notify interceptors
ActionRequestDetails requestDetails = new ActionRequestDetails(null, null); ActionRequestDetails requestDetails = new ActionRequestDetails(null, null);
notifyInterceptors(RestOperationTypeEnum.META, requestDetails); notifyInterceptors(RestOperationTypeEnum.META, requestDetails);
@ -207,13 +211,13 @@ public class FhirSystemDaoDstu21 extends BaseHapiFhirSystemDao<Bundle, MetaDt> {
TypedQuery<TagDefinition> q = myEntityManager.createQuery(sql, TagDefinition.class); TypedQuery<TagDefinition> q = myEntityManager.createQuery(sql, TagDefinition.class);
List<TagDefinition> tagDefinitions = q.getResultList(); List<TagDefinition> tagDefinitions = q.getResultList();
MetaDt retVal = toMetaDt(tagDefinitions); Meta retVal = toMeta(tagDefinitions);
return retVal; return retVal;
} }
protected MetaDt toMetaDt(Collection<TagDefinition> tagDefinitions) { protected Meta toMeta(Collection<TagDefinition> tagDefinitions) {
MetaDt retVal = new MetaDt(); Meta retVal = new Meta();
for (TagDefinition next : tagDefinitions) { for (TagDefinition next : tagDefinitions) {
switch (next.getTagType()) { switch (next.getTagType()) {
case PROFILE: case PROFILE:
@ -268,18 +272,18 @@ public class FhirSystemDaoDstu21 extends BaseHapiFhirSystemDao<Bundle, MetaDt> {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
private Bundle transaction(ServletRequestDetails theRequestDetails, Bundle theRequest, String theActionName) { private Bundle transaction(ServletRequestDetails theRequestDetails, Bundle theRequest, String theActionName) {
BundleTypeEnum transactionType = theRequest.getTypeElement().getValueAsEnum(); BundleType transactionType = theRequest.getTypeElement().getValue();
if (transactionType == BundleTypeEnum.BATCH) { if (transactionType == BundleType.BATCH) {
return batch(theRequestDetails, theRequest); return batch(theRequestDetails, theRequest);
} }
if (transactionType == null) { 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); ourLog.warn(message);
transactionType = BundleTypeEnum.TRANSACTION; transactionType = BundleType.TRANSACTION;
} }
if (transactionType != BundleTypeEnum.TRANSACTION) { if (transactionType != BundleType.TRANSACTION) {
throw new InvalidRequestException("Unable to process transaction where incoming Bundle.type = " + transactionType.getCode()); throw new InvalidRequestException("Unable to process transaction where incoming Bundle.type = " + transactionType.toCode());
} }
ourLog.info("Beginning {} with {} resources", theActionName, theRequest.getEntry().size()); ourLog.info("Beginning {} with {} resources", theActionName, theRequest.getEntry().size());
@ -287,9 +291,9 @@ public class FhirSystemDaoDstu21 extends BaseHapiFhirSystemDao<Bundle, MetaDt> {
long start = System.currentTimeMillis(); long start = System.currentTimeMillis();
Date updateTime = new Date(); Date updateTime = new Date();
Set<IdDt> allIds = new LinkedHashSet<IdDt>(); Set<IdType> allIds = new LinkedHashSet<IdType>();
Map<IdDt, IdDt> idSubstitutions = new HashMap<IdDt, IdDt>(); Map<IdType, IdType> idSubstitutions = new HashMap<IdType, IdType>();
Map<IdDt, DaoMethodOutcome> idToPersistedOutcome = new HashMap<IdDt, DaoMethodOutcome>(); Map<IdType, DaoMethodOutcome> idToPersistedOutcome = new HashMap<IdType, DaoMethodOutcome>();
/* /*
* We want to execute the transaction request bundle elements in the order * We want to execute the transaction request bundle elements in the order
@ -302,12 +306,12 @@ public class FhirSystemDaoDstu21 extends BaseHapiFhirSystemDao<Bundle, MetaDt> {
* we want the GET processing to use the final indexing state * we want the GET processing to use the final indexing state
*/ */
Bundle response = new Bundle(); Bundle response = new Bundle();
List<Entry> getEntries = new ArrayList<Entry>(); List<BundleEntryComponent> getEntries = new ArrayList<BundleEntryComponent>();
IdentityHashMap<Entry, Integer> originalRequestOrder = new IdentityHashMap<Bundle.Entry, Integer>(); IdentityHashMap<BundleEntryComponent, Integer> originalRequestOrder = new IdentityHashMap<Bundle.BundleEntryComponent, Integer>();
for (int i = 0; i < theRequest.getEntry().size(); i++) { for (int i = 0; i < theRequest.getEntry().size(); i++) {
originalRequestOrder.put(theRequest.getEntry().get(i), i); originalRequestOrder.put(theRequest.getEntry().get(i), i);
response.addEntry(); 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)); getEntries.add(theRequest.getEntry().get(i));
} }
} }
@ -326,16 +330,16 @@ public class FhirSystemDaoDstu21 extends BaseHapiFhirSystemDao<Bundle, MetaDt> {
ourLog.info("Processed {} non-GET entries out of {}", i, theRequest.getEntry().size()); ourLog.info("Processed {} non-GET entries out of {}", i, theRequest.getEntry().size());
} }
Entry nextReqEntry = theRequest.getEntry().get(i); BundleEntryComponent nextReqEntry = theRequest.getEntry().get(i);
IResource res = nextReqEntry.getResource(); Resource res = nextReqEntry.getResource();
IdDt nextResourceId = null; IdType nextResourceId = null;
if (res != null) { if (res != null) {
nextResourceId = res.getId(); nextResourceId = res.getIdElement();
if (nextResourceId.hasIdPart() == false) { if (nextResourceId.hasIdPart() == false) {
if (isNotBlank(nextReqEntry.getFullUrl())) { if (isNotBlank(nextReqEntry.getFullUrl())) {
nextResourceId = new IdDt(nextReqEntry.getFullUrl()); nextResourceId = new IdType(nextReqEntry.getFullUrl());
} }
} }
@ -344,7 +348,7 @@ public class FhirSystemDaoDstu21 extends BaseHapiFhirSystemDao<Bundle, MetaDt> {
} }
if (nextResourceId.hasIdPart() && !nextResourceId.hasResourceType() && !isPlaceholder(nextResourceId)) { 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); res.setId(nextResourceId);
} }
@ -356,7 +360,7 @@ public class FhirSystemDaoDstu21 extends BaseHapiFhirSystemDao<Bundle, MetaDt> {
throw new InvalidRequestException(getContext().getLocalizer().getMessage(BaseHapiFhirSystemDao.class, "transactionContainsMultipleWithDuplicateId", nextResourceId)); throw new InvalidRequestException(getContext().getLocalizer().getMessage(BaseHapiFhirSystemDao.class, "transactionContainsMultipleWithDuplicateId", nextResourceId));
} }
} else if (nextResourceId.hasResourceType() && nextResourceId.hasIdPart()) { } else if (nextResourceId.hasResourceType() && nextResourceId.hasIdPart()) {
IdDt nextId = nextResourceId.toUnqualifiedVersionless(); IdType nextId = nextResourceId.toUnqualifiedVersionless();
if (!allIds.add(nextId)) { if (!allIds.add(nextId)) {
throw new InvalidRequestException(getContext().getLocalizer().getMessage(BaseHapiFhirSystemDao.class, "transactionContainsMultipleWithDuplicateId", nextId)); throw new InvalidRequestException(getContext().getLocalizer().getMessage(BaseHapiFhirSystemDao.class, "transactionContainsMultipleWithDuplicateId", nextId));
} }
@ -364,13 +368,13 @@ public class FhirSystemDaoDstu21 extends BaseHapiFhirSystemDao<Bundle, MetaDt> {
} }
HTTPVerbEnum verb = nextReqEntry.getRequest().getMethodElement().getValueAsEnum(); HTTPVerb verb = nextReqEntry.getRequest().getMethodElement().getValue();
if (verb == null) { if (verb == null) {
throw new InvalidRequestException(getContext().getLocalizer().getMessage(BaseHapiFhirSystemDao.class, "transactionEntryHasInvalidVerb", nextReqEntry.getRequest().getMethod())); throw new InvalidRequestException(getContext().getLocalizer().getMessage(BaseHapiFhirSystemDao.class, "transactionEntryHasInvalidVerb", nextReqEntry.getRequest().getMethod()));
} }
String resourceType = res != null ? getContext().getResourceDefinition(res).getName() : null; 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) { switch (verb) {
case POST: { case POST: {
@ -387,10 +391,10 @@ public class FhirSystemDaoDstu21 extends BaseHapiFhirSystemDao<Bundle, MetaDt> {
// DELETE // DELETE
String url = extractTransactionUrlOrThrowException(nextReqEntry, verb); String url = extractTransactionUrlOrThrowException(nextReqEntry, verb);
UrlParts parts = UrlUtil.parseUrl(url); UrlParts parts = UrlUtil.parseUrl(url);
ca.uhn.fhir.jpa.dao.IFhirResourceDao<? extends IBaseResource> dao = toDao(parts, verb.getCode(), url); ca.uhn.fhir.jpa.dao.IFhirResourceDao<? extends IBaseResource> dao = toDao(parts, verb.toCode(), url);
int status = Constants.STATUS_HTTP_204_NO_CONTENT; int status = Constants.STATUS_HTTP_204_NO_CONTENT;
if (parts.getResourceId() != null) { 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) { if (deleted != null) {
deletedResources.add(deleted.getIdDt().toUnqualifiedVersionless()); deletedResources.add(deleted.getIdDt().toUnqualifiedVersionless());
} }
@ -418,7 +422,7 @@ public class FhirSystemDaoDstu21 extends BaseHapiFhirSystemDao<Bundle, MetaDt> {
UrlParts parts = UrlUtil.parseUrl(url); UrlParts parts = UrlUtil.parseUrl(url);
if (isNotBlank(parts.getResourceId())) { 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); outcome = resourceDao.update(res, null, false);
} else { } else {
res.setId((String) null); res.setId((String) null);
@ -452,24 +456,24 @@ public class FhirSystemDaoDstu21 extends BaseHapiFhirSystemDao<Bundle, MetaDt> {
FhirTerser terser = getContext().newTerser(); FhirTerser terser = getContext().newTerser();
for (DaoMethodOutcome nextOutcome : idToPersistedOutcome.values()) { for (DaoMethodOutcome nextOutcome : idToPersistedOutcome.values()) {
IResource nextResource = (IResource) nextOutcome.getResource(); IBaseResource nextResource = (IBaseResource) nextOutcome.getResource();
if (nextResource == null) { if (nextResource == null) {
continue; continue;
} }
List<BaseResourceReferenceDt> allRefs = terser.getAllPopulatedChildElementsOfType(nextResource, BaseResourceReferenceDt.class); List<IBaseReference> allRefs = terser.getAllPopulatedChildElementsOfType(nextResource, IBaseReference.class);
for (BaseResourceReferenceDt nextRef : allRefs) { for (IBaseReference nextRef : allRefs) {
IdDt nextId = nextRef.getReference(); IIdType nextId = nextRef.getReferenceElement();
if (idSubstitutions.containsKey(nextId)) { if (idSubstitutions.containsKey(nextId)) {
IdDt newId = idSubstitutions.get(nextId); IdType newId = idSubstitutions.get(nextId);
ourLog.info(" * Replacing resource ref {} with {}", nextId, newId); ourLog.info(" * Replacing resource ref {} with {}", nextId, newId);
nextRef.setReference(newId); nextRef.setReference(newId.getValue());
} else { } else {
ourLog.debug(" * Reference [{}] does not exist in bundle", nextId); ourLog.debug(" * Reference [{}] does not exist in bundle", nextId);
} }
} }
InstantDt deletedInstantOrNull = ResourceMetadataKeyEnum.DELETED_AT.get(nextResource); IPrimitiveType<Date> deletedInstantOrNull = ResourceMetadataKeyEnum.DELETED_AT.get((IAnyResource) nextResource);
Date deletedTimestampOrNull = deletedInstantOrNull != null ? deletedInstantOrNull.getValue() : null; Date deletedTimestampOrNull = deletedInstantOrNull != null ? deletedInstantOrNull.getValue() : null;
updateEntity(nextResource, nextOutcome.getEntity(), false, deletedTimestampOrNull, true, false, updateTime); updateEntity(nextResource, nextOutcome.getEntity(), false, deletedTimestampOrNull, true, false, updateTime);
} }
@ -479,8 +483,8 @@ public class FhirSystemDaoDstu21 extends BaseHapiFhirSystemDao<Bundle, MetaDt> {
/* /*
* Double check we didn't allow any duplicates we shouldn't have * Double check we didn't allow any duplicates we shouldn't have
*/ */
for (Entry nextEntry : theRequest.getEntry()) { for (BundleEntryComponent nextEntry : theRequest.getEntry()) {
if (nextEntry.getRequest().getMethodElement().getValueAsEnum() == HTTPVerbEnum.POST) { if (nextEntry.getRequest().getMethodElement().getValue() == HTTPVerb.POST) {
String matchUrl = nextEntry.getRequest().getIfNoneExist(); String matchUrl = nextEntry.getRequest().getIfNoneExist();
if (isNotBlank(matchUrl)) { if (isNotBlank(matchUrl)) {
IFhirResourceDao<?> resourceDao = getDao(nextEntry.getResource().getClass()); IFhirResourceDao<?> resourceDao = getDao(nextEntry.getResource().getClass());
@ -493,8 +497,8 @@ public class FhirSystemDaoDstu21 extends BaseHapiFhirSystemDao<Bundle, MetaDt> {
} }
} }
for (IdDt next : allIds) { for (IdType next : allIds) {
IdDt replacement = idSubstitutions.get(next); IdType replacement = idSubstitutions.get(next);
if (replacement == null) { if (replacement == null) {
continue; continue;
} }
@ -508,16 +512,16 @@ public class FhirSystemDaoDstu21 extends BaseHapiFhirSystemDao<Bundle, MetaDt> {
* Loop through the request and process any entries of type GET * Loop through the request and process any entries of type GET
*/ */
for (int i = 0; i < getEntries.size(); i++) { for (int i = 0; i < getEntries.size(); i++) {
Entry nextReqEntry = getEntries.get(i); BundleEntryComponent nextReqEntry = getEntries.get(i);
Integer originalOrder = originalRequestOrder.get(nextReqEntry); Integer originalOrder = originalRequestOrder.get(nextReqEntry);
Entry nextRespEntry = response.getEntry().get(originalOrder); BundleEntryComponent nextRespEntry = response.getEntry().get(originalOrder);
ServletSubRequestDetails requestDetails = new ServletSubRequestDetails(); ServletSubRequestDetails requestDetails = new ServletSubRequestDetails();
requestDetails.setServletRequest(theRequestDetails.getServletRequest()); requestDetails.setServletRequest(theRequestDetails.getServletRequest());
requestDetails.setRequestType(RequestTypeEnum.GET); requestDetails.setRequestType(RequestTypeEnum.GET);
requestDetails.setServer(theRequestDetails.getServer()); requestDetails.setServer(theRequestDetails.getServer());
String url = extractTransactionUrlOrThrowException(nextReqEntry, HTTPVerbEnum.GET); String url = extractTransactionUrlOrThrowException(nextReqEntry, HTTPVerb.GET);
int qIndex = url.indexOf('?'); int qIndex = url.indexOf('?');
ArrayListMultimap<String, String> paramValues = ArrayListMultimap.create(); ArrayListMultimap<String, String> paramValues = ArrayListMultimap.create();
@ -561,7 +565,7 @@ public class FhirSystemDaoDstu21 extends BaseHapiFhirSystemDao<Bundle, MetaDt> {
if (paramValues.containsKey(Constants.PARAM_SUMMARY) || paramValues.containsKey(Constants.PARAM_CONTENT)) { if (paramValues.containsKey(Constants.PARAM_SUMMARY) || paramValues.containsKey(Constants.PARAM_CONTENT)) {
resource = filterNestedBundle(requestDetails, resource); resource = filterNestedBundle(requestDetails, resource);
} }
nextRespEntry.setResource((IResource) resource); nextRespEntry.setResource((Resource) resource);
nextRespEntry.getResponse().setStatus(toStatusString(Constants.STATUS_HTTP_200_OK)); nextRespEntry.getResponse().setStatus(toStatusString(Constants.STATUS_HTTP_200_OK));
} catch (NotModifiedException e) { } catch (NotModifiedException e) {
nextRespEntry.getResponse().setStatus(toStatusString(Constants.STATUS_HTTP_304_NOT_MODIFIED)); nextRespEntry.getResponse().setStatus(toStatusString(Constants.STATUS_HTTP_304_NOT_MODIFIED));
@ -575,21 +579,21 @@ public class FhirSystemDaoDstu21 extends BaseHapiFhirSystemDao<Bundle, MetaDt> {
long delay = System.currentTimeMillis() - start; long delay = System.currentTimeMillis() - start;
ourLog.info(theActionName + " completed in {}ms", new Object[] { delay }); ourLog.info(theActionName + " completed in {}ms", new Object[] { delay });
response.setType(BundleTypeEnum.TRANSACTION_RESPONSE); response.setType(BundleType.TRANSACTIONRESPONSE);
return response; return response;
} }
private static void handleTransactionCreateOrUpdateOutcome(Map<IdDt, IdDt> idSubstitutions, Map<IdDt, DaoMethodOutcome> idToPersistedOutcome, IdDt nextResourceId, DaoMethodOutcome outcome, private static void handleTransactionCreateOrUpdateOutcome(Map<IdType, IdType> idSubstitutions, Map<IdType, DaoMethodOutcome> idToPersistedOutcome, IdType nextResourceId, DaoMethodOutcome outcome,
Entry newEntry, String theResourceType, IResource theRes) { BundleEntryComponent newEntry, String theResourceType, IBaseResource theRes) {
IdDt newId = (IdDt) outcome.getId().toUnqualifiedVersionless(); IdType newId = (IdType) outcome.getId().toUnqualifiedVersionless();
IdDt resourceId = isPlaceholder(nextResourceId) ? nextResourceId : nextResourceId.toUnqualifiedVersionless(); IdType resourceId = isPlaceholder(nextResourceId) ? nextResourceId : nextResourceId.toUnqualifiedVersionless();
if (newId.equals(resourceId) == false) { if (newId.equals(resourceId) == false) {
idSubstitutions.put(resourceId, newId); idSubstitutions.put(resourceId, newId);
if (isPlaceholder(resourceId)) { 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. * 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); idToPersistedOutcome.put(newId, outcome);
@ -600,10 +604,10 @@ public class FhirSystemDaoDstu21 extends BaseHapiFhirSystemDao<Bundle, MetaDt> {
} }
newEntry.getResponse().setLocation(outcome.getId().toUnqualified().getValue()); newEntry.getResponse().setLocation(outcome.getId().toUnqualified().getValue());
newEntry.getResponse().setEtag(outcome.getId().getVersionIdPart()); 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())) { if ("urn:oid:".equals(theId.getBaseUrl()) || "urn:uuid:".equals(theId.getBaseUrl())) {
return true; return true;
} }
@ -624,20 +628,20 @@ public class FhirSystemDaoDstu21 extends BaseHapiFhirSystemDao<Bundle, MetaDt> {
* Process any GET interactions * Process any GET interactions
*/ */
//@formatter:off //@formatter:off
public class TransactionSorter implements Comparator<Entry> { public class TransactionSorter implements Comparator<BundleEntryComponent> {
@Override @Override
public int compare(Entry theO1, Entry theO2) { public int compare(BundleEntryComponent theO1, BundleEntryComponent theO2) {
int o1 = toOrder(theO1); int o1 = toOrder(theO1);
int o2 = toOrder(theO2); int o2 = toOrder(theO2);
return o1 - o2; return o1 - o2;
} }
private int toOrder(Entry theO1) { private int toOrder(BundleEntryComponent theO1) {
int o1 = 0; int o1 = 0;
if (theO1.getRequest().getMethodElement().getValueAsEnum() != null) { if (theO1.getRequest().getMethodElement().getValue() != null) {
switch (theO1.getRequest().getMethodElement().getValueAsEnum()) { switch (theO1.getRequest().getMethodElement().getValue()) {
case DELETE: case DELETE:
o1 = 1; o1 = 1;
break; break;
@ -650,6 +654,9 @@ public class FhirSystemDaoDstu21 extends BaseHapiFhirSystemDao<Bundle, MetaDt> {
case GET: case GET:
o1 = 4; o1 = 4;
break; break;
case NULL:
o1 = 0;
break;
} }
} }
return o1; return o1;

View File

@ -1,10 +1,12 @@
package ca.uhn.fhir.jpa.dao; package ca.uhn.fhir.jpa.dao;
import org.hl7.fhir.instance.model.api.IAnyResource;
import org.hl7.fhir.instance.model.api.IBaseResource; import org.hl7.fhir.instance.model.api.IBaseResource;
import ca.uhn.fhir.jpa.entity.BaseHasResource; import ca.uhn.fhir.jpa.entity.BaseHasResource;
import ca.uhn.fhir.model.api.IResource; import ca.uhn.fhir.model.api.IResource;
import ca.uhn.fhir.model.api.ResourceMetadataKeyEnum; import ca.uhn.fhir.model.api.ResourceMetadataKeyEnum;
import ca.uhn.fhir.model.api.ResourceMetadataKeyEnum.ResourceMetadataKeySupportingAnyResource;
/* /*
* #%L * #%L
@ -28,7 +30,7 @@ import ca.uhn.fhir.model.api.ResourceMetadataKeyEnum;
public interface IDao { public interface IDao {
public static final ResourceMetadataKeyEnum<Long> RESOURCE_PID = new ResourceMetadataKeyEnum<Long>("RESOURCE_PID") { public static final ResourceMetadataKeySupportingAnyResource<Long, Long> RESOURCE_PID = new ResourceMetadataKeySupportingAnyResource<Long, Long>("RESOURCE_PID") {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
@ -41,6 +43,16 @@ public interface IDao {
public void put(IResource theResource, Long theObject) { public void put(IResource theResource, Long theObject) {
theResource.getResourceMetadata().put(RESOURCE_PID, 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); IBaseResource toResource(BaseHasResource theEntity, boolean theForHistoryOperation);

View File

@ -23,17 +23,17 @@ import javax.servlet.http.HttpServletRequest;
*/ */
import org.hl7.fhir.instance.model.api.IBaseResource; 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.api.SortSpec;
import ca.uhn.fhir.rest.param.DateRangeParam; import ca.uhn.fhir.rest.param.DateRangeParam;
import ca.uhn.fhir.rest.server.IBundleProvider; import ca.uhn.fhir.rest.server.IBundleProvider;
public interface IFhirResourceDaoEncounter<T extends IBaseResource> extends IFhirResourceDao<T> { public interface IFhirResourceDaoEncounter<T extends IBaseResource> extends IFhirResourceDao<T> {
IBundleProvider encounterInstanceEverything(HttpServletRequest theServletRequest, IdDt theId, UnsignedIntDt theCount, DateRangeParam theLastUpdate, SortSpec theSort); IBundleProvider encounterInstanceEverything(HttpServletRequest theServletRequest, IIdType theId, IPrimitiveType<Integer> theCount, DateRangeParam theLastUpdate, SortSpec theSort);
IBundleProvider encounterTypeEverything(HttpServletRequest theServletRequest, UnsignedIntDt theCount, DateRangeParam theLastUpdated, SortSpec theSortSpec); IBundleProvider encounterTypeEverything(HttpServletRequest theServletRequest, IPrimitiveType<Integer> theCount, DateRangeParam theLastUpdated, SortSpec theSortSpec);
} }

View File

@ -24,8 +24,8 @@ import javax.servlet.http.HttpServletRequest;
import org.hl7.fhir.instance.model.api.IBaseResource; import org.hl7.fhir.instance.model.api.IBaseResource;
import org.hl7.fhir.instance.model.api.IIdType; 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.api.SortSpec;
import ca.uhn.fhir.rest.param.DateRangeParam; import ca.uhn.fhir.rest.param.DateRangeParam;
import ca.uhn.fhir.rest.param.StringAndListParam; import ca.uhn.fhir.rest.param.StringAndListParam;
@ -33,8 +33,8 @@ import ca.uhn.fhir.rest.server.IBundleProvider;
public interface IFhirResourceDaoPatient<T extends IBaseResource> extends IFhirResourceDao<T> { public interface IFhirResourceDaoPatient<T extends IBaseResource> extends IFhirResourceDao<T> {
IBundleProvider patientInstanceEverything(HttpServletRequest theServletRequest, IIdType theId, UnsignedIntDt theCount, DateRangeParam theLastUpdate, SortSpec theSort, StringAndListParam theContent, StringAndListParam theNarrative); IBundleProvider patientInstanceEverything(HttpServletRequest theServletRequest, IIdType theId, IPrimitiveType<Integer> 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<Integer> theCount, DateRangeParam theLastUpdated, SortSpec theSortSpec, StringAndListParam theContent, StringAndListParam theNarrative);
} }

View File

@ -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.IBaseResource;
import org.hl7.fhir.instance.model.api.IIdType; import org.hl7.fhir.instance.model.api.IIdType;
import org.hl7.fhir.instance.model.api.IPrimitiveType;
import ca.uhn.fhir.model.primitive.CodeDt;
import ca.uhn.fhir.model.primitive.StringDt;
import ca.uhn.fhir.model.primitive.UriDt;
public interface IFhirResourceDaoValueSet<T extends IBaseResource, CD, CC> extends IFhirResourceDao<T> { public interface IFhirResourceDaoValueSet<T extends IBaseResource, CD, CC> extends IFhirResourceDao<T> {
@ -35,9 +32,9 @@ public interface IFhirResourceDaoValueSet<T extends IBaseResource, CD, CC> exten
T expandByIdentifier(String theUri, String theFilter); T expandByIdentifier(String theUri, String theFilter);
LookupCodeResult lookupCode(CodeDt theCode, UriDt theSystem, CD theCoding); LookupCodeResult lookupCode(IPrimitiveType<String> theCode, IPrimitiveType<String> theSystem, CD theCoding);
ValidateCodeResult validateCode(UriDt theValueSetIdentifier, IIdType theId, CodeDt theCode, UriDt theSystem, StringDt theDisplay, CD theCoding, CC theCodeableConcept); ValidateCodeResult validateCode(IPrimitiveType<String> theValueSetIdentifier, IIdType theId, IPrimitiveType<String> theCode, IPrimitiveType<String> theSystem, IPrimitiveType<String> theDisplay, CD theCoding, CC theCodeableConcept);
public class LookupCodeResult { public class LookupCodeResult {
private String myCodeDisplay; private String myCodeDisplay;

View File

@ -0,0 +1,7 @@
package ca.uhn.fhir.jpa.dao;
import org.hl7.fhir.instance.hapi.validation.IValidationSupport;
public interface IJpaValidationSupportDstu2 extends IValidationSupport {
}

View File

@ -1,5 +1,7 @@
package ca.uhn.fhir.jpa.dao; package ca.uhn.fhir.jpa.dao;
import org.hl7.fhir.dstu21.hapi.validation.IValidationSupport;
/* /*
* #%L * #%L
* HAPI FHIR JPA Server * HAPI FHIR JPA Server
@ -20,8 +22,6 @@ package ca.uhn.fhir.jpa.dao;
* #L% * #L%
*/ */
import ca.uhn.fhir.validation.IValidationSupport; public interface IJpaValidationSupportDstu21 extends IValidationSupport {
public interface IJpaValidationSupport extends IValidationSupport {
} }

View File

@ -22,6 +22,8 @@ package ca.uhn.fhir.jpa.dao;
import java.util.Set; 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.BaseResourceIndexedSearchParam;
import ca.uhn.fhir.jpa.entity.ResourceIndexedSearchParamCoords; import ca.uhn.fhir.jpa.entity.ResourceIndexedSearchParamCoords;
import ca.uhn.fhir.jpa.entity.ResourceIndexedSearchParamDate; 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.ResourceIndexedSearchParamString;
import ca.uhn.fhir.jpa.entity.ResourceIndexedSearchParamUri; import ca.uhn.fhir.jpa.entity.ResourceIndexedSearchParamUri;
import ca.uhn.fhir.jpa.entity.ResourceTable; import ca.uhn.fhir.jpa.entity.ResourceTable;
import ca.uhn.fhir.model.api.IResource;
interface ISearchParamExtractor { interface ISearchParamExtractor {
public abstract Set<ResourceIndexedSearchParamCoords> extractSearchParamCoords(ResourceTable theEntity, IResource theResource); public abstract Set<ResourceIndexedSearchParamCoords> extractSearchParamCoords(ResourceTable theEntity, IBaseResource theResource);
public abstract Set<ResourceIndexedSearchParamDate> extractSearchParamDates(ResourceTable theEntity, IResource theResource); public abstract Set<ResourceIndexedSearchParamDate> extractSearchParamDates(ResourceTable theEntity, IBaseResource theResource);
public abstract Set<ResourceIndexedSearchParamNumber> extractSearchParamNumber(ResourceTable theEntity, IResource theResource); public abstract Set<ResourceIndexedSearchParamNumber> extractSearchParamNumber(ResourceTable theEntity, IBaseResource theResource);
public abstract Set<ResourceIndexedSearchParamQuantity> extractSearchParamQuantity(ResourceTable theEntity, IResource theResource); public abstract Set<ResourceIndexedSearchParamQuantity> extractSearchParamQuantity(ResourceTable theEntity, IBaseResource theResource);
public abstract Set<ResourceIndexedSearchParamString> extractSearchParamStrings(ResourceTable theEntity, IResource theResource); public abstract Set<ResourceIndexedSearchParamString> extractSearchParamStrings(ResourceTable theEntity, IBaseResource theResource);
public abstract Set<BaseResourceIndexedSearchParam> extractSearchParamTokens(ResourceTable theEntity, IResource theResource); public abstract Set<BaseResourceIndexedSearchParam> extractSearchParamTokens(ResourceTable theEntity, IBaseResource theResource);
public abstract Set<ResourceIndexedSearchParamUri> extractSearchParamUri(ResourceTable theEntity, IResource theResource); public abstract Set<ResourceIndexedSearchParamUri> extractSearchParamUri(ResourceTable theEntity, IBaseResource theResource);
} }

View File

@ -31,7 +31,7 @@ import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.rest.param.UriParam; import ca.uhn.fhir.rest.param.UriParam;
import ca.uhn.fhir.rest.server.IBundleProvider; 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); private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(JpaValidationSupportDstu2.class);

View File

@ -1,5 +1,11 @@
package ca.uhn.fhir.jpa.dao; package ca.uhn.fhir.jpa.dao;
import org.hl7.fhir.dstu21.model.IdType;
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 * #%L
* HAPI FHIR JPA Server * HAPI FHIR JPA Server
@ -20,32 +26,26 @@ package ca.uhn.fhir.jpa.dao;
* #L% * #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.hl7.fhir.instance.model.api.IBaseResource;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.beans.factory.annotation.Qualifier;
import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.rest.param.StringParam;
import ca.uhn.fhir.rest.param.UriParam; import ca.uhn.fhir.rest.param.UriParam;
import ca.uhn.fhir.rest.server.IBundleProvider; 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); private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(JpaValidationSupportDstu21.class);
@Autowired
@Qualifier("myFhirContextDstu2Hl7Org")
private FhirContext myRiCtx;
@Autowired @Autowired
@Qualifier("myStructureDefinitionDaoDstu21") @Qualifier("myStructureDefinitionDaoDstu21")
private IFhirResourceDao<ca.uhn.fhir.model.dstu21.resource.StructureDefinition> myStructureDefinitionDao; private IFhirResourceDao<StructureDefinition> myStructureDefinitionDao;
@Autowired @Autowired
@Qualifier("myValueSetDaoDstu21") @Qualifier("myValueSetDaoDstu21")
private IFhirResourceDao<ca.uhn.fhir.model.dstu21.resource.ValueSet> myValueSetDao; private IFhirResourceDao<ValueSet> myValueSetDao;
@Autowired @Autowired
@Qualifier("myFhirContextDstu21") @Qualifier("myFhirContextDstu21")
@ -63,10 +63,20 @@ public class JpaValidationSupportDstu21 implements IJpaValidationSupport {
@Override @Override
public <T extends IBaseResource> T fetchResource(FhirContext theContext, Class<T> theClass, String theUri) { public <T extends IBaseResource> T fetchResource(FhirContext theContext, Class<T> theClass, String theUri) {
String resourceName = myRiCtx.getResourceDefinition(theClass).getName(); IdType id = new IdType(theUri);
boolean localReference = false;
if (id.hasBaseUrl() == false && id.hasIdPart() == true) {
localReference = true;
}
String resourceName = myDstu21Ctx.getResourceDefinition(theClass).getName();
IBundleProvider search; IBundleProvider search;
if ("ValueSet".equals(resourceName)) { if ("ValueSet".equals(resourceName)) {
if (localReference) {
search = myValueSetDao.search(ca.uhn.fhir.model.dstu2.resource.ValueSet.SP_RES_ID, new StringParam(theUri));
} else {
search = myValueSetDao.search(ca.uhn.fhir.model.dstu2.resource.ValueSet.SP_URL, new UriParam(theUri)); search = myValueSetDao.search(ca.uhn.fhir.model.dstu2.resource.ValueSet.SP_URL, new UriParam(theUri));
}
} else if ("StructureDefinition".equals(resourceName)) { } else if ("StructureDefinition".equals(resourceName)) {
search = myStructureDefinitionDao.search(ca.uhn.fhir.model.dstu2.resource.StructureDefinition.SP_URL, new UriParam(theUri)); search = myStructureDefinitionDao.search(ca.uhn.fhir.model.dstu2.resource.StructureDefinition.SP_URL, new UriParam(theUri));
} else { } else {
@ -81,15 +91,7 @@ public class JpaValidationSupportDstu21 implements IJpaValidationSupport {
ourLog.warn("Found multiple {} instances with URL search value of: {}", resourceName, theUri); ourLog.warn("Found multiple {} instances with URL search value of: {}", resourceName, theUri);
} }
IBaseResource res = search.getResources(0, 1).get(0); return (T) search.getResources(0, 1).get(0);
/*
* Validator wants RI structures and not HAPI ones, so convert
*
* TODO: we really need a more efficient way of converting.. Or maybe this will just go away when we move to RI structures
*/
String encoded = myDstu21Ctx.newJsonParser().encodeResourceToString(res);
return myRiCtx.newJsonParser().parseResource(theClass, encoded);
} }
@Override @Override

View File

@ -55,6 +55,7 @@ import javax.persistence.criteria.Root;
import javax.persistence.criteria.Subquery; import javax.persistence.criteria.Subquery;
import org.apache.commons.lang3.StringUtils; 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.IBaseResource;
import org.hl7.fhir.instance.model.api.IIdType; import org.hl7.fhir.instance.model.api.IIdType;
import org.springframework.transaction.PlatformTransactionManager; import org.springframework.transaction.PlatformTransactionManager;
@ -1302,17 +1303,25 @@ public class SearchBuilder {
for (ResourceTable next : q.getResultList()) { for (ResourceTable next : q.getResultList()) {
Class<? extends IBaseResource> resourceType = myContext.getResourceDefinition(next.getResourceType()).getImplementingClass(); Class<? extends IBaseResource> 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()); Integer index = position.get(next.getId());
if (index == null) { if (index == null) {
ourLog.warn("Got back unexpected resource PID {}", next.getId()); ourLog.warn("Got back unexpected resource PID {}", next.getId());
continue; continue;
} }
if (resource instanceof IResource) {
if (theRevIncludedPids.contains(next.getId())) { if (theRevIncludedPids.contains(next.getId())) {
ResourceMetadataKeyEnum.ENTRY_SEARCH_MODE.put(resource, BundleEntrySearchModeEnum.INCLUDE); ResourceMetadataKeyEnum.ENTRY_SEARCH_MODE.put((IResource)resource, BundleEntrySearchModeEnum.INCLUDE);
} else { } else {
ResourceMetadataKeyEnum.ENTRY_SEARCH_MODE.put(resource, BundleEntrySearchModeEnum.MATCH); ResourceMetadataKeyEnum.ENTRY_SEARCH_MODE.put((IResource)resource, BundleEntrySearchModeEnum.MATCH);
}
} else {
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); theResourceListToPopulate.set(index, resource);

View File

@ -35,6 +35,7 @@ import javax.measure.unit.NonSI;
import javax.measure.unit.Unit; import javax.measure.unit.Unit;
import org.apache.commons.lang3.tuple.Pair; 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.ConfigurationException;
import ca.uhn.fhir.context.FhirContext; 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.jpa.entity.ResourceTable;
import ca.uhn.fhir.model.api.IDatatype; import ca.uhn.fhir.model.api.IDatatype;
import ca.uhn.fhir.model.api.IPrimitiveDatatype; 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.base.composite.BaseHumanNameDt;
import ca.uhn.fhir.model.dstu.composite.AddressDt; import ca.uhn.fhir.model.dstu.composite.AddressDt;
import ca.uhn.fhir.model.dstu.composite.CodeableConceptDt; import ca.uhn.fhir.model.dstu.composite.CodeableConceptDt;
@ -75,12 +75,12 @@ public class SearchParamExtractorDstu1 extends BaseSearchParamExtractor implemen
} }
@Override @Override
public Set<ResourceIndexedSearchParamCoords> extractSearchParamCoords(ResourceTable theEntity, IResource theResource) { public Set<ResourceIndexedSearchParamCoords> extractSearchParamCoords(ResourceTable theEntity, IBaseResource theResource) {
return Collections.emptySet(); return Collections.emptySet();
} }
@Override @Override
public Set<ResourceIndexedSearchParamDate> extractSearchParamDates(ResourceTable theEntity, IResource theResource) { public Set<ResourceIndexedSearchParamDate> extractSearchParamDates(ResourceTable theEntity, IBaseResource theResource) {
HashSet<ResourceIndexedSearchParamDate> retVal = new HashSet<ResourceIndexedSearchParamDate>(); HashSet<ResourceIndexedSearchParamDate> retVal = new HashSet<ResourceIndexedSearchParamDate>();
RuntimeResourceDefinition def = getContext().getResourceDefinition(theResource); RuntimeResourceDefinition def = getContext().getResourceDefinition(theResource);
@ -135,7 +135,7 @@ public class SearchParamExtractorDstu1 extends BaseSearchParamExtractor implemen
} }
@Override @Override
public HashSet<ResourceIndexedSearchParamNumber> extractSearchParamNumber(ResourceTable theEntity, IResource theResource) { public HashSet<ResourceIndexedSearchParamNumber> extractSearchParamNumber(ResourceTable theEntity, IBaseResource theResource) {
HashSet<ResourceIndexedSearchParamNumber> retVal = new HashSet<ResourceIndexedSearchParamNumber>(); HashSet<ResourceIndexedSearchParamNumber> retVal = new HashSet<ResourceIndexedSearchParamNumber>();
RuntimeResourceDefinition def = getContext().getResourceDefinition(theResource); RuntimeResourceDefinition def = getContext().getResourceDefinition(theResource);
@ -230,7 +230,7 @@ public class SearchParamExtractorDstu1 extends BaseSearchParamExtractor implemen
} }
@Override @Override
public Set<ResourceIndexedSearchParamQuantity> extractSearchParamQuantity(ResourceTable theEntity, IResource theResource) { public Set<ResourceIndexedSearchParamQuantity> extractSearchParamQuantity(ResourceTable theEntity, IBaseResource theResource) {
HashSet<ResourceIndexedSearchParamQuantity> retVal = new HashSet<ResourceIndexedSearchParamQuantity>(); HashSet<ResourceIndexedSearchParamQuantity> retVal = new HashSet<ResourceIndexedSearchParamQuantity>();
RuntimeResourceDefinition def = getContext().getResourceDefinition(theResource); RuntimeResourceDefinition def = getContext().getResourceDefinition(theResource);
@ -278,7 +278,7 @@ public class SearchParamExtractorDstu1 extends BaseSearchParamExtractor implemen
} }
@Override @Override
public Set<ResourceIndexedSearchParamString> extractSearchParamStrings(ResourceTable theEntity, IResource theResource) { public Set<ResourceIndexedSearchParamString> extractSearchParamStrings(ResourceTable theEntity, IBaseResource theResource) {
HashSet<ResourceIndexedSearchParamString> retVal = new HashSet<ResourceIndexedSearchParamString>(); HashSet<ResourceIndexedSearchParamString> retVal = new HashSet<ResourceIndexedSearchParamString>();
RuntimeResourceDefinition def = getContext().getResourceDefinition(theResource); RuntimeResourceDefinition def = getContext().getResourceDefinition(theResource);
@ -364,7 +364,7 @@ public class SearchParamExtractorDstu1 extends BaseSearchParamExtractor implemen
} }
@Override @Override
public Set<BaseResourceIndexedSearchParam> extractSearchParamTokens(ResourceTable theEntity, IResource theResource) { public Set<BaseResourceIndexedSearchParam> extractSearchParamTokens(ResourceTable theEntity, IBaseResource theResource) {
HashSet<BaseResourceIndexedSearchParam> retVal = new HashSet<BaseResourceIndexedSearchParam>(); HashSet<BaseResourceIndexedSearchParam> retVal = new HashSet<BaseResourceIndexedSearchParam>();
RuntimeResourceDefinition def = getContext().getResourceDefinition(theResource); RuntimeResourceDefinition def = getContext().getResourceDefinition(theResource);
@ -472,7 +472,7 @@ public class SearchParamExtractorDstu1 extends BaseSearchParamExtractor implemen
} }
@Override @Override
public Set<ResourceIndexedSearchParamUri> extractSearchParamUri(ResourceTable theEntity, IResource theResource) { public Set<ResourceIndexedSearchParamUri> extractSearchParamUri(ResourceTable theEntity, IBaseResource theResource) {
return Collections.emptySet(); return Collections.emptySet();
} }

View File

@ -35,6 +35,7 @@ import javax.measure.unit.Unit;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.tuple.Pair; 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.ConfigurationException;
import ca.uhn.fhir.context.FhirContext; 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.jpa.entity.ResourceTable;
import ca.uhn.fhir.model.api.IDatatype; import ca.uhn.fhir.model.api.IDatatype;
import ca.uhn.fhir.model.api.IPrimitiveDatatype; 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.api.IValueSetEnumBinder;
import ca.uhn.fhir.model.base.composite.BaseHumanNameDt; import ca.uhn.fhir.model.base.composite.BaseHumanNameDt;
import ca.uhn.fhir.model.dstu2.composite.AddressDt; import ca.uhn.fhir.model.dstu2.composite.AddressDt;
@ -109,7 +109,7 @@ public class SearchParamExtractorDstu2 extends BaseSearchParamExtractor implemen
} }
@Override @Override
public Set<ResourceIndexedSearchParamCoords> extractSearchParamCoords(ResourceTable theEntity, IResource theResource) { public Set<ResourceIndexedSearchParamCoords> extractSearchParamCoords(ResourceTable theEntity, IBaseResource theResource) {
// TODO: implement // TODO: implement
return Collections.emptySet(); return Collections.emptySet();
} }
@ -121,7 +121,7 @@ public class SearchParamExtractorDstu2 extends BaseSearchParamExtractor implemen
* ca.uhn.fhir.model.api.IResource) * ca.uhn.fhir.model.api.IResource)
*/ */
@Override @Override
public Set<ResourceIndexedSearchParamDate> extractSearchParamDates(ResourceTable theEntity, IResource theResource) { public Set<ResourceIndexedSearchParamDate> extractSearchParamDates(ResourceTable theEntity, IBaseResource theResource) {
HashSet<ResourceIndexedSearchParamDate> retVal = new HashSet<ResourceIndexedSearchParamDate>(); HashSet<ResourceIndexedSearchParamDate> retVal = new HashSet<ResourceIndexedSearchParamDate>();
RuntimeResourceDefinition def = getContext().getResourceDefinition(theResource); RuntimeResourceDefinition def = getContext().getResourceDefinition(theResource);
@ -182,7 +182,7 @@ public class SearchParamExtractorDstu2 extends BaseSearchParamExtractor implemen
* ca.uhn.fhir.model.api.IResource) * ca.uhn.fhir.model.api.IResource)
*/ */
@Override @Override
public HashSet<ResourceIndexedSearchParamNumber> extractSearchParamNumber(ResourceTable theEntity, IResource theResource) { public HashSet<ResourceIndexedSearchParamNumber> extractSearchParamNumber(ResourceTable theEntity, IBaseResource theResource) {
HashSet<ResourceIndexedSearchParamNumber> retVal = new HashSet<ResourceIndexedSearchParamNumber>(); HashSet<ResourceIndexedSearchParamNumber> retVal = new HashSet<ResourceIndexedSearchParamNumber>();
RuntimeResourceDefinition def = getContext().getResourceDefinition(theResource); RuntimeResourceDefinition def = getContext().getResourceDefinition(theResource);
@ -282,7 +282,7 @@ public class SearchParamExtractorDstu2 extends BaseSearchParamExtractor implemen
* ca.uhn.fhir.model.api.IResource) * ca.uhn.fhir.model.api.IResource)
*/ */
@Override @Override
public Set<ResourceIndexedSearchParamQuantity> extractSearchParamQuantity(ResourceTable theEntity, IResource theResource) { public Set<ResourceIndexedSearchParamQuantity> extractSearchParamQuantity(ResourceTable theEntity, IBaseResource theResource) {
HashSet<ResourceIndexedSearchParamQuantity> retVal = new HashSet<ResourceIndexedSearchParamQuantity>(); HashSet<ResourceIndexedSearchParamQuantity> retVal = new HashSet<ResourceIndexedSearchParamQuantity>();
RuntimeResourceDefinition def = getContext().getResourceDefinition(theResource); RuntimeResourceDefinition def = getContext().getResourceDefinition(theResource);
@ -336,7 +336,7 @@ public class SearchParamExtractorDstu2 extends BaseSearchParamExtractor implemen
* ca.uhn.fhir.model.api.IResource) * ca.uhn.fhir.model.api.IResource)
*/ */
@Override @Override
public Set<ResourceIndexedSearchParamString> extractSearchParamStrings(ResourceTable theEntity, IResource theResource) { public Set<ResourceIndexedSearchParamString> extractSearchParamStrings(ResourceTable theEntity, IBaseResource theResource) {
HashSet<ResourceIndexedSearchParamString> retVal = new HashSet<ResourceIndexedSearchParamString>(); HashSet<ResourceIndexedSearchParamString> retVal = new HashSet<ResourceIndexedSearchParamString>();
RuntimeResourceDefinition def = getContext().getResourceDefinition(theResource); RuntimeResourceDefinition def = getContext().getResourceDefinition(theResource);
@ -418,7 +418,7 @@ public class SearchParamExtractorDstu2 extends BaseSearchParamExtractor implemen
* ca.uhn.fhir.model.api.IResource) * ca.uhn.fhir.model.api.IResource)
*/ */
@Override @Override
public Set<BaseResourceIndexedSearchParam> extractSearchParamTokens(ResourceTable theEntity, IResource theResource) { public Set<BaseResourceIndexedSearchParam> extractSearchParamTokens(ResourceTable theEntity, IBaseResource theResource) {
HashSet<BaseResourceIndexedSearchParam> retVal = new HashSet<BaseResourceIndexedSearchParam>(); HashSet<BaseResourceIndexedSearchParam> retVal = new HashSet<BaseResourceIndexedSearchParam>();
String useSystem = null; String useSystem = null;
@ -576,7 +576,7 @@ public class SearchParamExtractorDstu2 extends BaseSearchParamExtractor implemen
} }
@Override @Override
public Set<ResourceIndexedSearchParamUri> extractSearchParamUri(ResourceTable theEntity, IResource theResource) { public Set<ResourceIndexedSearchParamUri> extractSearchParamUri(ResourceTable theEntity, IBaseResource theResource) {
HashSet<ResourceIndexedSearchParamUri> retVal = new HashSet<ResourceIndexedSearchParamUri>(); HashSet<ResourceIndexedSearchParamUri> retVal = new HashSet<ResourceIndexedSearchParamUri>();
RuntimeResourceDefinition def = getContext().getResourceDefinition(theResource); RuntimeResourceDefinition def = getContext().getResourceDefinition(theResource);

View File

@ -29,12 +29,33 @@ import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
import javax.measure.quantity.Quantity;
import javax.measure.unit.NonSI; import javax.measure.unit.NonSI;
import javax.measure.unit.Unit; import javax.measure.unit.Unit;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.tuple.Pair; 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.ConfigurationException;
import ca.uhn.fhir.context.FhirContext; 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.ResourceIndexedSearchParamToken;
import ca.uhn.fhir.jpa.entity.ResourceIndexedSearchParamUri; import ca.uhn.fhir.jpa.entity.ResourceIndexedSearchParamUri;
import ca.uhn.fhir.jpa.entity.ResourceTable; 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; import ca.uhn.fhir.rest.method.RestSearchParameterTypeEnum;
public class SearchParamExtractorDstu21 extends BaseSearchParamExtractor implements ISearchParamExtractor { public class SearchParamExtractorDstu21 extends BaseSearchParamExtractor implements ISearchParamExtractor {
@ -109,7 +103,7 @@ public class SearchParamExtractorDstu21 extends BaseSearchParamExtractor impleme
} }
@Override @Override
public Set<ResourceIndexedSearchParamCoords> extractSearchParamCoords(ResourceTable theEntity, IResource theResource) { public Set<ResourceIndexedSearchParamCoords> extractSearchParamCoords(ResourceTable theEntity, IBaseResource theResource) {
// TODO: implement // TODO: implement
return Collections.emptySet(); return Collections.emptySet();
} }
@ -118,10 +112,10 @@ public class SearchParamExtractorDstu21 extends BaseSearchParamExtractor impleme
* (non-Javadoc) * (non-Javadoc)
* *
* @see ca.uhn.fhir.jpa.dao.ISearchParamExtractor#extractSearchParamDates(ca.uhn.fhir.jpa.entity.ResourceTable, * @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 @Override
public Set<ResourceIndexedSearchParamDate> extractSearchParamDates(ResourceTable theEntity, IResource theResource) { public Set<ResourceIndexedSearchParamDate> extractSearchParamDates(ResourceTable theEntity, IBaseResource theResource) {
HashSet<ResourceIndexedSearchParamDate> retVal = new HashSet<ResourceIndexedSearchParamDate>(); HashSet<ResourceIndexedSearchParamDate> retVal = new HashSet<ResourceIndexedSearchParamDate>();
RuntimeResourceDefinition def = getContext().getResourceDefinition(theResource); RuntimeResourceDefinition def = getContext().getResourceDefinition(theResource);
@ -146,14 +140,14 @@ public class SearchParamExtractorDstu21 extends BaseSearchParamExtractor impleme
} }
ResourceIndexedSearchParamDate nextEntity; ResourceIndexedSearchParamDate nextEntity;
if (nextObject instanceof BaseDateTimeDt) { if (nextObject instanceof BaseDateTimeType) {
BaseDateTimeDt nextValue = (BaseDateTimeDt) nextObject; BaseDateTimeType nextValue = (BaseDateTimeType) nextObject;
if (nextValue.isEmpty()) { if (nextValue.isEmpty()) {
continue; continue;
} }
nextEntity = new ResourceIndexedSearchParamDate(nextSpDef.getName(), nextValue.getValue(), nextValue.getValue()); nextEntity = new ResourceIndexedSearchParamDate(nextSpDef.getName(), nextValue.getValue(), nextValue.getValue());
} else if (nextObject instanceof PeriodDt) { } else if (nextObject instanceof Period) {
PeriodDt nextValue = (PeriodDt) nextObject; Period nextValue = (Period) nextObject;
if (nextValue.isEmpty()) { if (nextValue.isEmpty()) {
continue; continue;
} }
@ -179,10 +173,10 @@ public class SearchParamExtractorDstu21 extends BaseSearchParamExtractor impleme
* (non-Javadoc) * (non-Javadoc)
* *
* @see ca.uhn.fhir.jpa.dao.ISearchParamExtractor#extractSearchParamNumber(ca.uhn.fhir.jpa.entity.ResourceTable, * @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 @Override
public HashSet<ResourceIndexedSearchParamNumber> extractSearchParamNumber(ResourceTable theEntity, IResource theResource) { public HashSet<ResourceIndexedSearchParamNumber> extractSearchParamNumber(ResourceTable theEntity, IBaseResource theResource) {
HashSet<ResourceIndexedSearchParamNumber> retVal = new HashSet<ResourceIndexedSearchParamNumber>(); HashSet<ResourceIndexedSearchParamNumber> retVal = new HashSet<ResourceIndexedSearchParamNumber>();
RuntimeResourceDefinition def = getContext().getResourceDefinition(theResource); RuntimeResourceDefinition def = getContext().getResourceDefinition(theResource);
@ -197,7 +191,7 @@ public class SearchParamExtractorDstu21 extends BaseSearchParamExtractor impleme
} }
for (Object nextObject : extractValues(nextPath, theResource)) { for (Object nextObject : extractValues(nextPath, theResource)) {
if (nextObject == null || ((IDatatype) nextObject).isEmpty()) { if (nextObject == null || ((IBase) nextObject).isEmpty()) {
continue; continue;
} }
@ -207,19 +201,19 @@ public class SearchParamExtractorDstu21 extends BaseSearchParamExtractor impleme
multiType = true; multiType = true;
} }
if (nextObject instanceof DurationDt) { if (nextObject instanceof Duration) {
DurationDt nextValue = (DurationDt) nextObject; Duration nextValue = (Duration) nextObject;
if (nextValue.getValueElement().isEmpty()) { if (nextValue.getValueElement().isEmpty()) {
continue; continue;
} }
if (new UriDt(BaseHapiFhirDao.UCUM_NS).equals(nextValue.getSystemElement())) { if (BaseHapiFhirDao.UCUM_NS.equals(nextValue.getSystem())) {
if (isNotBlank(nextValue.getCode())) { if (isNotBlank(nextValue.getCode())) {
Unit<? extends Quantity> unit = Unit.valueOf(nextValue.getCode()); Unit<? extends javax.measure.quantity.Quantity> unit = Unit.valueOf(nextValue.getCode());
javax.measure.converter.UnitConverter dayConverter = unit.getConverterTo(NonSI.DAY); javax.measure.converter.UnitConverter dayConverter = unit.getConverterTo(NonSI.DAY);
double dayValue = dayConverter.convert(nextValue.getValue().doubleValue()); double dayValue = dayConverter.convert(nextValue.getValue().doubleValue());
DurationDt newValue = new DurationDt(); Duration newValue = new Duration();
newValue.setSystem(BaseHapiFhirDao.UCUM_NS); newValue.setSystem(BaseHapiFhirDao.UCUM_NS);
newValue.setCode(NonSI.DAY.toString()); newValue.setCode(NonSI.DAY.toString());
newValue.setValue(dayValue); newValue.setValue(dayValue);
@ -234,8 +228,8 @@ public class SearchParamExtractorDstu21 extends BaseSearchParamExtractor impleme
* *
* @SuppressWarnings("unchecked") PhysicsUnit<org.unitsofmeasurement.quantity.Time> timeUnit = * @SuppressWarnings("unchecked") PhysicsUnit<org.unitsofmeasurement.quantity.Time> timeUnit =
* (PhysicsUnit<Time>) unit; UnitConverter conv = timeUnit.getConverterTo(UCUM.DAY); double * (PhysicsUnit<Time>) unit; UnitConverter conv = timeUnit.getConverterTo(UCUM.DAY); double
* dayValue = conv.convert(nextValue.getValue().getValue().doubleValue()); DurationDt newValue = * dayValue = conv.convert(nextValue.getValue().getValue().doubleValue()); Duration newValue =
* new DurationDt(); newValue.setSystem(UCUM_NS); newValue.setCode(UCUM.DAY.getSymbol()); * new Duration(); newValue.setSystem(UCUM_NS); newValue.setCode(UCUM.DAY.getSymbol());
* newValue.setValue(dayValue); nextValue=newValue; } * newValue.setValue(dayValue); nextValue=newValue; }
*/ */
} }
@ -244,8 +238,8 @@ public class SearchParamExtractorDstu21 extends BaseSearchParamExtractor impleme
ResourceIndexedSearchParamNumber nextEntity = new ResourceIndexedSearchParamNumber(resourceName, nextValue.getValue()); ResourceIndexedSearchParamNumber nextEntity = new ResourceIndexedSearchParamNumber(resourceName, nextValue.getValue());
nextEntity.setResource(theEntity); nextEntity.setResource(theEntity);
retVal.add(nextEntity); retVal.add(nextEntity);
} else if (nextObject instanceof QuantityDt) { } else if (nextObject instanceof Quantity) {
QuantityDt nextValue = (QuantityDt) nextObject; Quantity nextValue = (Quantity) nextObject;
if (nextValue.getValueElement().isEmpty()) { if (nextValue.getValueElement().isEmpty()) {
continue; continue;
} }
@ -253,8 +247,8 @@ public class SearchParamExtractorDstu21 extends BaseSearchParamExtractor impleme
ResourceIndexedSearchParamNumber nextEntity = new ResourceIndexedSearchParamNumber(resourceName, nextValue.getValue()); ResourceIndexedSearchParamNumber nextEntity = new ResourceIndexedSearchParamNumber(resourceName, nextValue.getValue());
nextEntity.setResource(theEntity); nextEntity.setResource(theEntity);
retVal.add(nextEntity); retVal.add(nextEntity);
} else if (nextObject instanceof IntegerDt) { } else if (nextObject instanceof IntegerType) {
IntegerDt nextValue = (IntegerDt) nextObject; IntegerType nextValue = (IntegerType) nextObject;
if (nextValue.getValue() == null) { if (nextValue.getValue() == null) {
continue; continue;
} }
@ -279,10 +273,10 @@ public class SearchParamExtractorDstu21 extends BaseSearchParamExtractor impleme
* (non-Javadoc) * (non-Javadoc)
* *
* @see ca.uhn.fhir.jpa.dao.ISearchParamExtractor#extractSearchParamQuantity(ca.uhn.fhir.jpa.entity.ResourceTable, * @see ca.uhn.fhir.jpa.dao.ISearchParamExtractor#extractSearchParamQuantity(ca.uhn.fhir.jpa.entity.ResourceTable,
* ca.uhn.fhir.model.api.IResource) * ca.uhn.fhir.model.api.IBaseResource)
*/ */
@Override @Override
public Set<ResourceIndexedSearchParamQuantity> extractSearchParamQuantity(ResourceTable theEntity, IResource theResource) { public Set<ResourceIndexedSearchParamQuantity> extractSearchParamQuantity(ResourceTable theEntity, IBaseResource theResource) {
HashSet<ResourceIndexedSearchParamQuantity> retVal = new HashSet<ResourceIndexedSearchParamQuantity>(); HashSet<ResourceIndexedSearchParamQuantity> retVal = new HashSet<ResourceIndexedSearchParamQuantity>();
RuntimeResourceDefinition def = getContext().getResourceDefinition(theResource); RuntimeResourceDefinition def = getContext().getResourceDefinition(theResource);
@ -297,7 +291,7 @@ public class SearchParamExtractorDstu21 extends BaseSearchParamExtractor impleme
} }
for (Object nextObject : extractValues(nextPath, theResource)) { for (Object nextObject : extractValues(nextPath, theResource)) {
if (nextObject == null || ((IDatatype) nextObject).isEmpty()) { if (nextObject == null || ((IBase) nextObject).isEmpty()) {
continue; continue;
} }
@ -307,8 +301,8 @@ public class SearchParamExtractorDstu21 extends BaseSearchParamExtractor impleme
multiType = true; multiType = true;
} }
if (nextObject instanceof QuantityDt) { if (nextObject instanceof Quantity) {
QuantityDt nextValue = (QuantityDt) nextObject; Quantity nextValue = (Quantity) nextObject;
if (nextValue.getValueElement().isEmpty()) { if (nextValue.getValueElement().isEmpty()) {
continue; continue;
} }
@ -333,10 +327,10 @@ public class SearchParamExtractorDstu21 extends BaseSearchParamExtractor impleme
* (non-Javadoc) * (non-Javadoc)
* *
* @see ca.uhn.fhir.jpa.dao.ISearchParamExtractor#extractSearchParamStrings(ca.uhn.fhir.jpa.entity.ResourceTable, * @see ca.uhn.fhir.jpa.dao.ISearchParamExtractor#extractSearchParamStrings(ca.uhn.fhir.jpa.entity.ResourceTable,
* ca.uhn.fhir.model.api.IResource) * ca.uhn.fhir.model.api.IBaseResource)
*/ */
@Override @Override
public Set<ResourceIndexedSearchParamString> extractSearchParamStrings(ResourceTable theEntity, IResource theResource) { public Set<ResourceIndexedSearchParamString> extractSearchParamStrings(ResourceTable theEntity, IBaseResource theResource) {
HashSet<ResourceIndexedSearchParamString> retVal = new HashSet<ResourceIndexedSearchParamString>(); HashSet<ResourceIndexedSearchParamString> retVal = new HashSet<ResourceIndexedSearchParamString>();
RuntimeResourceDefinition def = getContext().getResourceDefinition(theResource); RuntimeResourceDefinition def = getContext().getResourceDefinition(theResource);
@ -361,7 +355,7 @@ public class SearchParamExtractorDstu21 extends BaseSearchParamExtractor impleme
} }
for (Object nextObject : extractValues(nextPath, theResource)) { for (Object nextObject : extractValues(nextPath, theResource)) {
if (nextObject == null || ((IDatatype) nextObject).isEmpty()) { if (nextObject == null || ((IBase) nextObject).isEmpty()) {
continue; continue;
} }
@ -370,32 +364,32 @@ public class SearchParamExtractorDstu21 extends BaseSearchParamExtractor impleme
multiType = true; multiType = true;
} }
if (nextObject instanceof IPrimitiveDatatype<?>) { if (nextObject instanceof IPrimitiveType<?>) {
IPrimitiveDatatype<?> nextValue = (IPrimitiveDatatype<?>) nextObject; IPrimitiveType<?> nextValue = (IPrimitiveType<?>) nextObject;
String searchTerm = nextValue.getValueAsString(); String searchTerm = nextValue.getValueAsString();
addSearchTerm(theEntity, retVal, resourceName, searchTerm); addSearchTerm(theEntity, retVal, resourceName, searchTerm);
} else { } else {
if (nextObject instanceof BaseHumanNameDt) { if (nextObject instanceof HumanName) {
ArrayList<StringDt> allNames = new ArrayList<StringDt>(); ArrayList<StringType> allNames = new ArrayList<StringType>();
HumanNameDt nextHumanName = (HumanNameDt) nextObject; HumanName nextHumanName = (HumanName) nextObject;
allNames.addAll(nextHumanName.getFamily()); allNames.addAll(nextHumanName.getFamily());
allNames.addAll(nextHumanName.getGiven()); allNames.addAll(nextHumanName.getGiven());
for (StringDt nextName : allNames) { for (StringType nextName : allNames) {
addSearchTerm(theEntity, retVal, resourceName, nextName.getValue()); addSearchTerm(theEntity, retVal, resourceName, nextName.getValue());
} }
} else if (nextObject instanceof AddressDt) { } else if (nextObject instanceof Address) {
ArrayList<StringDt> allNames = new ArrayList<StringDt>(); ArrayList<StringType> allNames = new ArrayList<StringType>();
AddressDt nextAddress = (AddressDt) nextObject; Address nextAddress = (Address) nextObject;
allNames.addAll(nextAddress.getLine()); allNames.addAll(nextAddress.getLine());
allNames.add(nextAddress.getCityElement()); allNames.add(nextAddress.getCityElement());
allNames.add(nextAddress.getStateElement()); allNames.add(nextAddress.getStateElement());
allNames.add(nextAddress.getCountryElement()); allNames.add(nextAddress.getCountryElement());
allNames.add(nextAddress.getPostalCodeElement()); allNames.add(nextAddress.getPostalCodeElement());
for (StringDt nextName : allNames) { for (StringType nextName : allNames) {
addSearchTerm(theEntity, retVal, resourceName, nextName.getValue()); addSearchTerm(theEntity, retVal, resourceName, nextName.getValue());
} }
} else if (nextObject instanceof ContactPointDt) { } else if (nextObject instanceof ContactPoint) {
ContactPointDt nextContact = (ContactPointDt) nextObject; ContactPoint nextContact = (ContactPoint) nextObject;
if (nextContact.getValueElement().isEmpty() == false) { if (nextContact.getValueElement().isEmpty() == false) {
addSearchTerm(theEntity, retVal, resourceName, nextContact.getValue()); addSearchTerm(theEntity, retVal, resourceName, nextContact.getValue());
} }
@ -415,10 +409,10 @@ public class SearchParamExtractorDstu21 extends BaseSearchParamExtractor impleme
* (non-Javadoc) * (non-Javadoc)
* *
* @see ca.uhn.fhir.jpa.dao.ISearchParamExtractor#extractSearchParamTokens(ca.uhn.fhir.jpa.entity.ResourceTable, * @see ca.uhn.fhir.jpa.dao.ISearchParamExtractor#extractSearchParamTokens(ca.uhn.fhir.jpa.entity.ResourceTable,
* ca.uhn.fhir.model.api.IResource) * ca.uhn.fhir.model.api.IBaseResource)
*/ */
@Override @Override
public Set<BaseResourceIndexedSearchParam> extractSearchParamTokens(ResourceTable theEntity, IResource theResource) { public Set<BaseResourceIndexedSearchParam> extractSearchParamTokens(ResourceTable theEntity, IBaseResource theResource) {
HashSet<BaseResourceIndexedSearchParam> retVal = new HashSet<BaseResourceIndexedSearchParam>(); HashSet<BaseResourceIndexedSearchParam> retVal = new HashSet<BaseResourceIndexedSearchParam>();
String useSystem = null; String useSystem = null;
@ -447,25 +441,25 @@ public class SearchParamExtractorDstu21 extends BaseSearchParamExtractor impleme
List<String> codes = new ArrayList<String>(); List<String> codes = new ArrayList<String>();
String needContactPointSystem = null; String needContactPointSystem = null;
if (nextPath.endsWith("(system=phone)")) { if (nextPath.endsWith(".where(system='phone')")) {
nextPath = nextPath.substring(0, nextPath.length() - "(system=phone)".length()); nextPath = nextPath.substring(0, nextPath.length() - ".where(system='phone')".length());
needContactPointSystem = "phone"; needContactPointSystem = "phone";
} }
if (nextPath.endsWith("(system=email)")) { if (nextPath.endsWith(".where(system='email')")) {
nextPath = nextPath.substring(0, nextPath.length() - "(system=email)".length()); nextPath = nextPath.substring(0, nextPath.length() - ".where(system='email')".length());
needContactPointSystem = "email"; needContactPointSystem = "email";
} }
for (Object nextObject : extractValues(nextPath, theResource)) { for (Object nextObject : extractValues(nextPath, theResource)) {
// Patient:language // Patient:language
if (nextObject instanceof Patient.Communication) { if (nextObject instanceof PatientCommunicationComponent) {
Communication nextValue = (Patient.Communication) nextObject; PatientCommunicationComponent nextValue = (PatientCommunicationComponent) nextObject;
nextObject = nextValue.getLanguage(); nextObject = nextValue.getLanguage();
} }
if (nextObject instanceof IdentifierDt) { if (nextObject instanceof Identifier) {
IdentifierDt nextValue = (IdentifierDt) nextObject; Identifier nextValue = (Identifier) nextObject;
if (nextValue.isEmpty()) { if (nextValue.isEmpty()) {
continue; continue;
} }
@ -480,8 +474,8 @@ public class SearchParamExtractorDstu21 extends BaseSearchParamExtractor impleme
addStringParam(theEntity, retVal, nextSpDef, nextValue.getType().getText()); addStringParam(theEntity, retVal, nextSpDef, nextValue.getType().getText());
} }
} else if (nextObject instanceof ContactPointDt) { } else if (nextObject instanceof ContactPoint) {
ContactPointDt nextValue = (ContactPointDt) nextObject; ContactPoint nextValue = (ContactPoint) nextObject;
if (nextValue.isEmpty()) { if (nextValue.isEmpty()) {
continue; continue;
} }
@ -492,16 +486,16 @@ public class SearchParamExtractorDstu21 extends BaseSearchParamExtractor impleme
} }
systems.add(nextValue.getSystemElement().getValueAsString()); systems.add(nextValue.getSystemElement().getValueAsString());
codes.add(nextValue.getValueElement().getValue()); codes.add(nextValue.getValueElement().getValue());
} else if (nextObject instanceof BoundCodeDt) { } else if (nextObject instanceof Enumeration<?>) {
BoundCodeDt<?> obj = (BoundCodeDt<?>) nextObject; Enumeration<?> obj = (Enumeration<?>) nextObject;
String system = extractSystem(obj); String system = extractSystem(obj);
String code = obj.getValue(); String code = obj.getValueAsString();
if (isNotBlank(code)) { if (isNotBlank(code)) {
systems.add(system); systems.add(system);
codes.add(code); codes.add(code);
} }
} else if (nextObject instanceof IPrimitiveDatatype<?>) { } else if (nextObject instanceof IPrimitiveType<?>) {
IPrimitiveDatatype<?> nextValue = (IPrimitiveDatatype<?>) nextObject; IPrimitiveType<?> nextValue = (IPrimitiveType<?>) nextObject;
if (nextValue.isEmpty()) { if (nextValue.isEmpty()) {
continue; continue;
} }
@ -511,24 +505,24 @@ public class SearchParamExtractorDstu21 extends BaseSearchParamExtractor impleme
systems.add(null); systems.add(null);
} }
codes.add(nextValue.getValueAsString()); codes.add(nextValue.getValueAsString());
} else if (nextObject instanceof CodingDt) { } else if (nextObject instanceof Coding) {
CodingDt nextValue = (CodingDt) nextObject; Coding nextValue = (Coding) nextObject;
extractTokensFromCoding(systems, codes, theEntity, retVal, nextSpDef, nextValue); extractTokensFromCoding(systems, codes, theEntity, retVal, nextSpDef, nextValue);
} else if (nextObject instanceof CodeableConceptDt) { } else if (nextObject instanceof CodeableConcept) {
CodeableConceptDt nextCC = (CodeableConceptDt) nextObject; CodeableConcept nextCC = (CodeableConcept) nextObject;
if (!nextCC.getTextElement().isEmpty()) { if (!nextCC.getTextElement().isEmpty()) {
addStringParam(theEntity, retVal, nextSpDef, nextCC.getTextElement().getValue()); addStringParam(theEntity, retVal, nextSpDef, nextCC.getTextElement().getValue());
} }
extractTokensFromCodeableConcept(systems, codes, nextCC, theEntity, retVal, nextSpDef); extractTokensFromCodeableConcept(systems, codes, nextCC, theEntity, retVal, nextSpDef);
} else if (nextObject instanceof RestSecurity) { } else if (nextObject instanceof ConformanceRestSecurityComponent) {
// Conformance.security search param points to something kind of useless right now - This should probably // Conformance.security search param points to something kind of useless right now - This should probably
// be fixed. // be fixed.
RestSecurity sec = (RestSecurity) nextObject; ConformanceRestSecurityComponent sec = (ConformanceRestSecurityComponent) nextObject;
for (BoundCodeableConceptDt<RestfulSecurityServiceEnum> nextCC : sec.getService()) { for (CodeableConcept nextCC : sec.getService()) {
extractTokensFromCodeableConcept(systems, codes, nextCC, theEntity, retVal, nextSpDef); extractTokensFromCodeableConcept(systems, codes, nextCC, theEntity, retVal, nextSpDef);
} }
} else if (nextObject instanceof Location.Position) { } else if (nextObject instanceof LocationPositionComponent) {
ourLog.warn("Position search not currently supported, not indexing location"); ourLog.warn("Position search not currently supported, not indexing location");
continue; continue;
} else { } else {
@ -576,7 +570,7 @@ public class SearchParamExtractorDstu21 extends BaseSearchParamExtractor impleme
} }
@Override @Override
public Set<ResourceIndexedSearchParamUri> extractSearchParamUri(ResourceTable theEntity, IResource theResource) { public Set<ResourceIndexedSearchParamUri> extractSearchParamUri(ResourceTable theEntity, IBaseResource theResource) {
HashSet<ResourceIndexedSearchParamUri> retVal = new HashSet<ResourceIndexedSearchParamUri>(); HashSet<ResourceIndexedSearchParamUri> retVal = new HashSet<ResourceIndexedSearchParamUri>();
RuntimeResourceDefinition def = getContext().getResourceDefinition(theResource); RuntimeResourceDefinition def = getContext().getResourceDefinition(theResource);
@ -591,7 +585,7 @@ public class SearchParamExtractorDstu21 extends BaseSearchParamExtractor impleme
} }
for (Object nextObject : extractValues(nextPath, theResource)) { for (Object nextObject : extractValues(nextPath, theResource)) {
if (nextObject == null || ((IDatatype) nextObject).isEmpty()) { if (nextObject == null || ((IBase) nextObject).isEmpty()) {
continue; continue;
} }
@ -601,8 +595,8 @@ public class SearchParamExtractorDstu21 extends BaseSearchParamExtractor impleme
multiType = true; multiType = true;
} }
if (nextObject instanceof UriDt) { if (nextObject instanceof UriType) {
UriDt nextValue = (UriDt) nextObject; UriType nextValue = (UriType) nextObject;
if (isBlank(nextValue.getValue())) { if (isBlank(nextValue.getValue())) {
continue; continue;
} }
@ -626,13 +620,13 @@ public class SearchParamExtractorDstu21 extends BaseSearchParamExtractor impleme
return retVal; return retVal;
} }
private void extractTokensFromCodeableConcept(List<String> theSystems, List<String> theCodes, CodeableConceptDt theCodeableConcept, ResourceTable theEntity, Set<BaseResourceIndexedSearchParam> theListToPopulate, RuntimeSearchParam theParameterDef) { private void extractTokensFromCodeableConcept(List<String> theSystems, List<String> theCodes, CodeableConcept theCodeableConcept, ResourceTable theEntity, Set<BaseResourceIndexedSearchParam> theListToPopulate, RuntimeSearchParam theParameterDef) {
for (CodingDt nextCoding : theCodeableConcept.getCoding()) { for (Coding nextCoding : theCodeableConcept.getCoding()) {
extractTokensFromCoding(theSystems, theCodes, theEntity, theListToPopulate, theParameterDef, nextCoding); extractTokensFromCoding(theSystems, theCodes, theEntity, theListToPopulate, theParameterDef, nextCoding);
} }
} }
private void extractTokensFromCoding(List<String> theSystems, List<String> theCodes, ResourceTable theEntity, Set<BaseResourceIndexedSearchParam> theListToPopulate, RuntimeSearchParam theParameterDef, CodingDt nextCoding) { private void extractTokensFromCoding(List<String> theSystems, List<String> theCodes, ResourceTable theEntity, Set<BaseResourceIndexedSearchParam> theListToPopulate, RuntimeSearchParam theParameterDef, Coding nextCoding) {
if (nextCoding != null && !nextCoding.isEmpty()) { if (nextCoding != null && !nextCoding.isEmpty()) {
String nextSystem = nextCoding.getSystemElement().getValueAsString(); String nextSystem = nextCoding.getSystemElement().getValueAsString();
@ -649,10 +643,9 @@ public class SearchParamExtractorDstu21 extends BaseSearchParamExtractor impleme
} }
} }
private static <T extends Enum<?>> String extractSystem(BoundCodeDt<T> theBoundCode) { private static <T extends Enum<?>> String extractSystem(Enumeration<T> theBoundCode) {
if (theBoundCode.getValueAsEnum() != null) { if (theBoundCode.getValue() != null) {
IValueSetEnumBinder<T> binder = theBoundCode.getBinder(); return theBoundCode.getEnumFactory().toSystem(theBoundCode.getValue());
return binder.toSystemString(theBoundCode.getValueAsEnum());
} }
return null; return null;
} }

View File

@ -24,15 +24,12 @@ import java.util.Date;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import net.sourceforge.cobertura.CoverageIgnore; import org.hl7.fhir.instance.model.api.IBaseResource;
import org.hl7.fhir.instance.model.api.IIdType;
import org.springframework.beans.factory.annotation.Required; import org.springframework.beans.factory.annotation.Required;
import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.jpa.dao.IFhirResourceDao; import ca.uhn.fhir.jpa.dao.IFhirResourceDao;
import ca.uhn.fhir.model.api.IResource;
import ca.uhn.fhir.model.api.TagList; import ca.uhn.fhir.model.api.TagList;
import ca.uhn.fhir.model.primitive.IdDt;
import ca.uhn.fhir.rest.annotation.GetTags; import ca.uhn.fhir.rest.annotation.GetTags;
import ca.uhn.fhir.rest.annotation.History; import ca.uhn.fhir.rest.annotation.History;
import ca.uhn.fhir.rest.annotation.IdParam; import ca.uhn.fhir.rest.annotation.IdParam;
@ -40,8 +37,9 @@ import ca.uhn.fhir.rest.annotation.Read;
import ca.uhn.fhir.rest.annotation.Since; import ca.uhn.fhir.rest.annotation.Since;
import ca.uhn.fhir.rest.server.IBundleProvider; import ca.uhn.fhir.rest.server.IBundleProvider;
import ca.uhn.fhir.rest.server.IResourceProvider; import ca.uhn.fhir.rest.server.IResourceProvider;
import net.sourceforge.cobertura.CoverageIgnore;
public abstract class BaseJpaResourceProvider<T extends IResource> extends BaseJpaProvider implements IResourceProvider { public abstract class BaseJpaResourceProvider<T extends IBaseResource> extends BaseJpaProvider implements IResourceProvider {
private IFhirResourceDao<T> myDao; private IFhirResourceDao<T> myDao;
@ -59,7 +57,7 @@ public abstract class BaseJpaResourceProvider<T extends IResource> extends BaseJ
} }
@History @History
public IBundleProvider getHistoryForResourceInstance(HttpServletRequest theRequest, @IdParam IdDt theId, @Since Date theDate) { public IBundleProvider getHistoryForResourceInstance(HttpServletRequest theRequest, @IdParam IIdType theId, @Since Date theDate) {
startRequest(theRequest); startRequest(theRequest);
try { try {
return myDao.history(theId, theDate); return myDao.history(theId, theDate);
@ -79,12 +77,12 @@ public abstract class BaseJpaResourceProvider<T extends IResource> extends BaseJ
} }
@Override @Override
public Class<? extends IResource> getResourceType() { public Class<? extends IBaseResource> getResourceType() {
return myDao.getResourceType(); return myDao.getResourceType();
} }
@GetTags @GetTags
public TagList getTagsForResourceInstance(HttpServletRequest theRequest, @IdParam IdDt theResourceId) { public TagList getTagsForResourceInstance(HttpServletRequest theRequest, @IdParam IIdType theResourceId) {
startRequest(theRequest); startRequest(theRequest);
try { try {
return myDao.getTags(theResourceId); return myDao.getTags(theResourceId);
@ -104,7 +102,7 @@ public abstract class BaseJpaResourceProvider<T extends IResource> extends BaseJ
} }
@Read(version = true) @Read(version = true)
public T read(HttpServletRequest theRequest, @IdParam IdDt theId) { public T read(HttpServletRequest theRequest, @IdParam IIdType theId) {
startRequest(theRequest); startRequest(theRequest);
try { try {
return myDao.read(theId); return myDao.read(theId);

View File

@ -1,5 +1,9 @@
package ca.uhn.fhir.jpa.provider; package ca.uhn.fhir.jpa.provider;
import org.hl7.fhir.dstu21.model.Encounter;
import org.hl7.fhir.dstu21.model.IdType;
import org.hl7.fhir.dstu21.model.UnsignedIntType;
/* /*
* #%L * #%L
* HAPI FHIR JPA Server * HAPI FHIR JPA Server
@ -22,7 +26,6 @@ package ca.uhn.fhir.jpa.provider;
import ca.uhn.fhir.jpa.dao.IFhirResourceDaoEncounter; import ca.uhn.fhir.jpa.dao.IFhirResourceDaoEncounter;
import ca.uhn.fhir.model.api.annotation.Description; import ca.uhn.fhir.model.api.annotation.Description;
import ca.uhn.fhir.model.dstu21.resource.Encounter;
import ca.uhn.fhir.rest.annotation.IdParam; import ca.uhn.fhir.rest.annotation.IdParam;
import ca.uhn.fhir.rest.annotation.Operation; import ca.uhn.fhir.rest.annotation.Operation;
import ca.uhn.fhir.rest.annotation.OperationParam; import ca.uhn.fhir.rest.annotation.OperationParam;
@ -43,11 +46,11 @@ public class BaseJpaResourceProviderEncounterDstu21 extends JpaResourceProviderD
javax.servlet.http.HttpServletRequest theServletRequest, javax.servlet.http.HttpServletRequest theServletRequest,
@IdParam @IdParam
ca.uhn.fhir.model.primitive.IdDt theId, IdType theId,
@Description(formalDefinition="Results from this method are returned across multiple pages. This parameter controls the size of those pages.") @Description(formalDefinition="Results from this method are returned across multiple pages. This parameter controls the size of those pages.")
@OperationParam(name = Constants.PARAM_COUNT) @OperationParam(name = Constants.PARAM_COUNT)
ca.uhn.fhir.model.primitive.UnsignedIntDt theCount, UnsignedIntType theCount,
@Description(shortDefinition="Only return resources which were last updated as specified by the given range") @Description(shortDefinition="Only return resources which were last updated as specified by the given range")
@OperationParam(name = Constants.PARAM_LASTUPDATED, min=0, max=1) @OperationParam(name = Constants.PARAM_LASTUPDATED, min=0, max=1)
@ -76,7 +79,7 @@ public class BaseJpaResourceProviderEncounterDstu21 extends JpaResourceProviderD
@Description(formalDefinition="Results from this method are returned across multiple pages. This parameter controls the size of those pages.") @Description(formalDefinition="Results from this method are returned across multiple pages. This parameter controls the size of those pages.")
@OperationParam(name = Constants.PARAM_COUNT) @OperationParam(name = Constants.PARAM_COUNT)
ca.uhn.fhir.model.primitive.UnsignedIntDt theCount, UnsignedIntType theCount,
@Description(shortDefinition="Only return resources which were last updated as specified by the given range") @Description(shortDefinition="Only return resources which were last updated as specified by the given range")
@OperationParam(name = Constants.PARAM_LASTUPDATED, min=0, max=1) @OperationParam(name = Constants.PARAM_LASTUPDATED, min=0, max=1)

View File

@ -4,6 +4,11 @@ import static org.apache.commons.lang3.StringUtils.isNotBlank;
import java.util.List; import java.util.List;
import org.hl7.fhir.dstu21.model.IdType;
import org.hl7.fhir.dstu21.model.Patient;
import org.hl7.fhir.dstu21.model.StringType;
import org.hl7.fhir.dstu21.model.UnsignedIntType;
/* /*
* #%L * #%L
* HAPI FHIR JPA Server * HAPI FHIR JPA Server
@ -26,8 +31,6 @@ import java.util.List;
import ca.uhn.fhir.jpa.dao.IFhirResourceDaoPatient; import ca.uhn.fhir.jpa.dao.IFhirResourceDaoPatient;
import ca.uhn.fhir.model.api.annotation.Description; import ca.uhn.fhir.model.api.annotation.Description;
import ca.uhn.fhir.model.dstu21.resource.Patient;
import ca.uhn.fhir.model.primitive.StringDt;
import ca.uhn.fhir.rest.annotation.IdParam; import ca.uhn.fhir.rest.annotation.IdParam;
import ca.uhn.fhir.rest.annotation.Operation; import ca.uhn.fhir.rest.annotation.Operation;
import ca.uhn.fhir.rest.annotation.OperationParam; import ca.uhn.fhir.rest.annotation.OperationParam;
@ -51,11 +54,11 @@ public class BaseJpaResourceProviderPatientDstu21 extends JpaResourceProviderDst
javax.servlet.http.HttpServletRequest theServletRequest, javax.servlet.http.HttpServletRequest theServletRequest,
@IdParam @IdParam
ca.uhn.fhir.model.primitive.IdDt theId, IdType theId,
@Description(formalDefinition="Results from this method are returned across multiple pages. This parameter controls the size of those pages.") @Description(formalDefinition="Results from this method are returned across multiple pages. This parameter controls the size of those pages.")
@OperationParam(name = Constants.PARAM_COUNT) @OperationParam(name = Constants.PARAM_COUNT)
ca.uhn.fhir.model.primitive.UnsignedIntDt theCount, UnsignedIntType theCount,
@Description(shortDefinition="Only return resources which were last updated as specified by the given range") @Description(shortDefinition="Only return resources which were last updated as specified by the given range")
@OperationParam(name = Constants.PARAM_LASTUPDATED, min=0, max=1) @OperationParam(name = Constants.PARAM_LASTUPDATED, min=0, max=1)
@ -63,11 +66,11 @@ public class BaseJpaResourceProviderPatientDstu21 extends JpaResourceProviderDst
@Description(shortDefinition="Filter the resources to return only resources matching the given _content filter (note that this filter is applied only to results which link to the given patient, not to the patient itself or to supporting resources linked to by the matched resources)") @Description(shortDefinition="Filter the resources to return only resources matching the given _content filter (note that this filter is applied only to results which link to the given patient, not to the patient itself or to supporting resources linked to by the matched resources)")
@OperationParam(name = Constants.PARAM_CONTENT, min=0, max=OperationParam.MAX_UNLIMITED) @OperationParam(name = Constants.PARAM_CONTENT, min=0, max=OperationParam.MAX_UNLIMITED)
List<StringDt> theContent, List<StringType> theContent,
@Description(shortDefinition="Filter the resources to return only resources matching the given _text filter (note that this filter is applied only to results which link to the given patient, not to the patient itself or to supporting resources linked to by the matched resources)") @Description(shortDefinition="Filter the resources to return only resources matching the given _text filter (note that this filter is applied only to results which link to the given patient, not to the patient itself or to supporting resources linked to by the matched resources)")
@OperationParam(name = Constants.PARAM_TEXT, min=0, max=OperationParam.MAX_UNLIMITED) @OperationParam(name = Constants.PARAM_TEXT, min=0, max=OperationParam.MAX_UNLIMITED)
List<StringDt> theNarrative, List<StringType> theNarrative,
@Sort @Sort
SortSpec theSortSpec SortSpec theSortSpec
@ -93,7 +96,7 @@ public class BaseJpaResourceProviderPatientDstu21 extends JpaResourceProviderDst
@Description(formalDefinition="Results from this method are returned across multiple pages. This parameter controls the size of those pages.") @Description(formalDefinition="Results from this method are returned across multiple pages. This parameter controls the size of those pages.")
@OperationParam(name = Constants.PARAM_COUNT) @OperationParam(name = Constants.PARAM_COUNT)
ca.uhn.fhir.model.primitive.UnsignedIntDt theCount, UnsignedIntType theCount,
@Description(shortDefinition="Only return resources which were last updated as specified by the given range") @Description(shortDefinition="Only return resources which were last updated as specified by the given range")
@OperationParam(name = Constants.PARAM_LASTUPDATED, min=0, max=1) @OperationParam(name = Constants.PARAM_LASTUPDATED, min=0, max=1)
@ -101,11 +104,11 @@ public class BaseJpaResourceProviderPatientDstu21 extends JpaResourceProviderDst
@Description(shortDefinition="Filter the resources to return only resources matching the given _content filter (note that this filter is applied only to results which link to the given patient, not to the patient itself or to supporting resources linked to by the matched resources)") @Description(shortDefinition="Filter the resources to return only resources matching the given _content filter (note that this filter is applied only to results which link to the given patient, not to the patient itself or to supporting resources linked to by the matched resources)")
@OperationParam(name = Constants.PARAM_CONTENT, min=0, max=OperationParam.MAX_UNLIMITED) @OperationParam(name = Constants.PARAM_CONTENT, min=0, max=OperationParam.MAX_UNLIMITED)
List<StringDt> theContent, List<StringType> theContent,
@Description(shortDefinition="Filter the resources to return only resources matching the given _text filter (note that this filter is applied only to results which link to the given patient, not to the patient itself or to supporting resources linked to by the matched resources)") @Description(shortDefinition="Filter the resources to return only resources matching the given _text filter (note that this filter is applied only to results which link to the given patient, not to the patient itself or to supporting resources linked to by the matched resources)")
@OperationParam(name = Constants.PARAM_TEXT, min=0, max=OperationParam.MAX_UNLIMITED) @OperationParam(name = Constants.PARAM_TEXT, min=0, max=OperationParam.MAX_UNLIMITED)
List<StringDt> theNarrative, List<StringType> theNarrative,
@Sort @Sort
SortSpec theSortSpec SortSpec theSortSpec
@ -121,10 +124,10 @@ public class BaseJpaResourceProviderPatientDstu21 extends JpaResourceProviderDst
} }
private StringAndListParam toStringAndList(List<StringDt> theNarrative) { private StringAndListParam toStringAndList(List<StringType> theNarrative) {
StringAndListParam retVal = new StringAndListParam(); StringAndListParam retVal = new StringAndListParam();
if (theNarrative != null) { if (theNarrative != null) {
for (StringDt next : theNarrative) { for (StringType next : theNarrative) {
if (isNotBlank(next.getValue())) { if (isNotBlank(next.getValue())) {
retVal.addAnd(new StringOrListParam().addOr(new StringParam(next.getValue()))); retVal.addAnd(new StringOrListParam().addOr(new StringParam(next.getValue())));
} }

View File

@ -24,36 +24,35 @@ import static org.apache.commons.lang3.StringUtils.isNotBlank;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import org.apache.commons.lang3.BooleanUtils; import org.hl7.fhir.dstu21.model.BooleanType;
import org.hl7.fhir.dstu21.model.CodeType;
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.Parameters;
import org.hl7.fhir.dstu21.model.StringType;
import org.hl7.fhir.dstu21.model.UriType;
import org.hl7.fhir.dstu21.model.ValueSet;
import ca.uhn.fhir.jpa.dao.IFhirResourceDaoValueSet; import ca.uhn.fhir.jpa.dao.IFhirResourceDaoValueSet;
import ca.uhn.fhir.jpa.dao.IFhirResourceDaoValueSet.LookupCodeResult; import ca.uhn.fhir.jpa.dao.IFhirResourceDaoValueSet.LookupCodeResult;
import ca.uhn.fhir.jpa.dao.IFhirResourceDaoValueSet.ValidateCodeResult; import ca.uhn.fhir.jpa.dao.IFhirResourceDaoValueSet.ValidateCodeResult;
import ca.uhn.fhir.model.dstu21.composite.CodeableConceptDt;
import ca.uhn.fhir.model.dstu21.composite.CodingDt;
import ca.uhn.fhir.model.dstu21.resource.Parameters;
import ca.uhn.fhir.model.dstu21.resource.ValueSet;
import ca.uhn.fhir.model.primitive.BooleanDt;
import ca.uhn.fhir.model.primitive.CodeDt;
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.annotation.IdParam; import ca.uhn.fhir.rest.annotation.IdParam;
import ca.uhn.fhir.rest.annotation.Operation; import ca.uhn.fhir.rest.annotation.Operation;
import ca.uhn.fhir.rest.annotation.OperationParam; import ca.uhn.fhir.rest.annotation.OperationParam;
import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException; import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException;
import ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException; import ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException;
public class BaseJpaResourceProviderValueSetDstu21 extends JpaResourceProviderDstu2<ValueSet> { public class BaseJpaResourceProviderValueSetDstu21 extends JpaResourceProviderDstu21<ValueSet> {
//@formatter:off //@formatter:off
@Operation(name = "$expand", idempotent = true) @Operation(name = "$expand", idempotent = true)
public ValueSet expand( public ValueSet expand(
HttpServletRequest theServletRequest, HttpServletRequest theServletRequest,
@IdParam(optional=true) IdDt theId, @IdParam(optional=true) IdType theId,
@OperationParam(name="valueSet", min=0, max=1) ValueSet theValueSet, @OperationParam(name="valueSet", min=0, max=1) ValueSet theValueSet,
@OperationParam(name="identifier", min=0, max=1) UriDt theIdentifier, @OperationParam(name="identifier", min=0, max=1) UriType theIdentifier,
@OperationParam(name = "filter", min=0, max=1) StringDt theFilter) { @OperationParam(name = "filter", min=0, max=1) StringType theFilter) {
//@formatter:on //@formatter:on
boolean haveId = theId != null && theId.hasIdPart(); boolean haveId = theId != null && theId.hasIdPart();
@ -70,7 +69,7 @@ public class BaseJpaResourceProviderValueSetDstu21 extends JpaResourceProviderDs
startRequest(theServletRequest); startRequest(theServletRequest);
try { try {
IFhirResourceDaoValueSet<ValueSet, CodingDt, CodeableConceptDt> dao = (IFhirResourceDaoValueSet<ValueSet, CodingDt, CodeableConceptDt>) getDao(); IFhirResourceDaoValueSet<ValueSet, Coding, CodeableConcept> dao = (IFhirResourceDaoValueSet<ValueSet, Coding, CodeableConcept>) getDao();
if (haveId) { if (haveId) {
return dao.expand(theId, toFilterString(theFilter)); return dao.expand(theId, toFilterString(theFilter));
} else if (haveIdentifier) { } else if (haveIdentifier) {
@ -100,39 +99,39 @@ public class BaseJpaResourceProviderValueSetDstu21 extends JpaResourceProviderDs
} }
private String toFilterString(StringDt theFilter) { private String toFilterString(StringType theFilter) {
return theFilter != null ? theFilter.getValue() : null; return theFilter != null ? theFilter.getValue() : null;
} }
//@formatter:off //@formatter:off
@Operation(name = "$lookup", idempotent = true, returnParameters= { @Operation(name = "$lookup", idempotent = true, returnParameters= {
@OperationParam(name="name", type=StringDt.class, min=1), @OperationParam(name="name", type=StringType.class, min=1),
@OperationParam(name="version", type=StringDt.class, min=0), @OperationParam(name="version", type=StringType.class, min=0),
@OperationParam(name="display", type=StringDt.class, min=1), @OperationParam(name="display", type=StringType.class, min=1),
@OperationParam(name="abstract", type=BooleanDt.class, min=1), @OperationParam(name="abstract", type=BooleanType.class, min=1),
}) })
public Parameters lookup( public Parameters lookup(
HttpServletRequest theServletRequest, HttpServletRequest theServletRequest,
@OperationParam(name="code", min=0, max=1) CodeDt theCode, @OperationParam(name="code", min=0, max=1) CodeType theCode,
@OperationParam(name="system", min=0, max=1) UriDt theSystem, @OperationParam(name="system", min=0, max=1) UriType theSystem,
@OperationParam(name="coding", min=0, max=1) CodingDt theCoding @OperationParam(name="coding", min=0, max=1) Coding theCoding
) { ) {
//@formatter:on //@formatter:on
startRequest(theServletRequest); startRequest(theServletRequest);
try { try {
IFhirResourceDaoValueSet<ValueSet, CodingDt, CodeableConceptDt> dao = (IFhirResourceDaoValueSet<ValueSet, CodingDt, CodeableConceptDt>) getDao(); IFhirResourceDaoValueSet<ValueSet, Coding, CodeableConcept> dao = (IFhirResourceDaoValueSet<ValueSet, Coding, CodeableConcept>) getDao();
LookupCodeResult result = dao.lookupCode(theCode, theSystem, theCoding); LookupCodeResult result = dao.lookupCode(theCode, theSystem, theCoding);
if (result.isFound()==false) { if (result.isFound()==false) {
throw new ResourceNotFoundException("Unable to find code[" + result.getSearchedForCode() + "] in system[" + result.getSearchedForSystem() + "]"); throw new ResourceNotFoundException("Unable to find code[" + result.getSearchedForCode() + "] in system[" + result.getSearchedForSystem() + "]");
} }
Parameters retVal = new Parameters(); Parameters retVal = new Parameters();
retVal.addParameter().setName("name").setValue(new StringDt(result.getCodeSystemDisplayName())); retVal.addParameter().setName("name").setValue(new StringType(result.getCodeSystemDisplayName()));
if (isNotBlank(result.getCodeSystemVersion())) { if (isNotBlank(result.getCodeSystemVersion())) {
retVal.addParameter().setName("version").setValue(new StringDt(result.getCodeSystemVersion())); retVal.addParameter().setName("version").setValue(new StringType(result.getCodeSystemVersion()));
} }
retVal.addParameter().setName("display").setValue(new StringDt(result.getCodeDisplay())); retVal.addParameter().setName("display").setValue(new StringType(result.getCodeDisplay()));
retVal.addParameter().setName("abstract").setValue(new BooleanDt(result.isCodeIsAbstract())); retVal.addParameter().setName("abstract").setValue(new BooleanType(result.isCodeIsAbstract()));
return retVal; return retVal;
} finally { } finally {
endRequest(theServletRequest); endRequest(theServletRequest);
@ -142,33 +141,33 @@ public class BaseJpaResourceProviderValueSetDstu21 extends JpaResourceProviderDs
//@formatter:off //@formatter:off
@Operation(name = "$validate-code", idempotent = true, returnParameters= { @Operation(name = "$validate-code", idempotent = true, returnParameters= {
@OperationParam(name="result", type=BooleanDt.class, min=1), @OperationParam(name="result", type=BooleanType.class, min=1),
@OperationParam(name="message", type=StringDt.class), @OperationParam(name="message", type=StringType.class),
@OperationParam(name="display", type=StringDt.class) @OperationParam(name="display", type=StringType.class)
}) })
public Parameters validateCode( public Parameters validateCode(
HttpServletRequest theServletRequest, HttpServletRequest theServletRequest,
@IdParam(optional=true) IdDt theId, @IdParam(optional=true) IdType theId,
@OperationParam(name="identifier", min=0, max=1) UriDt theValueSetIdentifier, @OperationParam(name="identifier", min=0, max=1) UriType theValueSetIdentifier,
@OperationParam(name="code", min=0, max=1) CodeDt theCode, @OperationParam(name="code", min=0, max=1) CodeType theCode,
@OperationParam(name="system", min=0, max=1) UriDt theSystem, @OperationParam(name="system", min=0, max=1) UriType theSystem,
@OperationParam(name="display", min=0, max=1) StringDt theDisplay, @OperationParam(name="display", min=0, max=1) StringType theDisplay,
@OperationParam(name="coding", min=0, max=1) CodingDt theCoding, @OperationParam(name="coding", min=0, max=1) Coding theCoding,
@OperationParam(name="codeableConcept", min=0, max=1) CodeableConceptDt theCodeableConcept @OperationParam(name="codeableConcept", min=0, max=1) CodeableConcept theCodeableConcept
) { ) {
//@formatter:on //@formatter:on
startRequest(theServletRequest); startRequest(theServletRequest);
try { try {
IFhirResourceDaoValueSet<ValueSet, CodingDt, CodeableConceptDt> dao = (IFhirResourceDaoValueSet<ValueSet, CodingDt, CodeableConceptDt>) getDao(); IFhirResourceDaoValueSet<ValueSet, Coding, CodeableConcept> dao = (IFhirResourceDaoValueSet<ValueSet, Coding, CodeableConcept>) getDao();
ValidateCodeResult result = dao.validateCode(theValueSetIdentifier, theId, theCode, theSystem, theDisplay, theCoding, theCodeableConcept); ValidateCodeResult result = dao.validateCode(theValueSetIdentifier, theId, theCode, theSystem, theDisplay, theCoding, theCodeableConcept);
Parameters retVal = new Parameters(); Parameters retVal = new Parameters();
retVal.addParameter().setName("result").setValue(new BooleanDt(result.isResult())); retVal.addParameter().setName("result").setValue(new BooleanType(result.isResult()));
if (isNotBlank(result.getMessage())) { if (isNotBlank(result.getMessage())) {
retVal.addParameter().setName("message").setValue(new StringDt(result.getMessage())); retVal.addParameter().setName("message").setValue(new StringType(result.getMessage()));
} }
if (isNotBlank(result.getDisplay())) { if (isNotBlank(result.getDisplay())) {
retVal.addParameter().setName("display").setValue(new StringDt(result.getDisplay())); retVal.addParameter().setName("display").setValue(new StringType(result.getDisplay()));
} }
return retVal; return retVal;
} finally { } finally {

View File

@ -25,34 +25,34 @@ import java.util.Map;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import org.hl7.fhir.dstu21.model.Bundle;
import org.hl7.fhir.dstu21.model.CodeType;
import org.hl7.fhir.dstu21.model.Conformance;
import org.hl7.fhir.dstu21.model.Conformance.ConditionalDeleteStatus;
import org.hl7.fhir.dstu21.model.Conformance.ConformanceRestComponent;
import org.hl7.fhir.dstu21.model.Conformance.ConformanceRestResourceComponent;
import org.hl7.fhir.dstu21.model.Conformance.ConformanceRestResourceSearchParamComponent;
import org.hl7.fhir.dstu21.model.DecimalType;
import org.hl7.fhir.dstu21.model.Enumerations.SearchParamType;
import org.hl7.fhir.dstu21.model.Extension;
import org.hl7.fhir.dstu21.model.Meta;
import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.context.RuntimeResourceDefinition; import ca.uhn.fhir.context.RuntimeResourceDefinition;
import ca.uhn.fhir.context.RuntimeSearchParam; import ca.uhn.fhir.context.RuntimeSearchParam;
import ca.uhn.fhir.jpa.dao.DaoConfig; import ca.uhn.fhir.jpa.dao.DaoConfig;
import ca.uhn.fhir.jpa.dao.IFhirSystemDao; import ca.uhn.fhir.jpa.dao.IFhirSystemDao;
import ca.uhn.fhir.model.dstu21.composite.MetaDt;
import ca.uhn.fhir.model.dstu21.resource.Bundle;
import ca.uhn.fhir.model.dstu21.resource.Conformance;
import ca.uhn.fhir.model.dstu21.resource.Conformance.Rest;
import ca.uhn.fhir.model.dstu21.resource.Conformance.RestResource;
import ca.uhn.fhir.model.dstu21.resource.Conformance.RestResourceSearchParam;
import ca.uhn.fhir.model.dstu21.valueset.ConditionalDeleteStatusEnum;
import ca.uhn.fhir.model.dstu21.valueset.ResourceTypeEnum;
import ca.uhn.fhir.model.dstu21.valueset.SearchParamTypeEnum;
import ca.uhn.fhir.model.primitive.BoundCodeDt;
import ca.uhn.fhir.model.primitive.DecimalDt;
import ca.uhn.fhir.rest.server.RestfulServer; import ca.uhn.fhir.rest.server.RestfulServer;
import ca.uhn.fhir.rest.server.provider.dstu21.ServerConformanceProvider;
import ca.uhn.fhir.util.ExtensionConstants; import ca.uhn.fhir.util.ExtensionConstants;
import net.sourceforge.cobertura.CoverageIgnore; import net.sourceforge.cobertura.CoverageIgnore;
public class JpaConformanceProviderDstu21 extends ServerConformanceProvider { public class JpaConformanceProviderDstu21 extends org.hl7.fhir.dstu21.hapi.rest.server.ServerConformanceProvider {
private volatile Conformance myCachedValue; private volatile Conformance myCachedValue;
private DaoConfig myDaoConfig; private DaoConfig myDaoConfig;
private String myImplementationDescription; private String myImplementationDescription;
private RestfulServer myRestfulServer; private RestfulServer myRestfulServer;
private IFhirSystemDao<Bundle, MetaDt> mySystemDao; private IFhirSystemDao<Bundle, Meta> mySystemDao;
/** /**
* Constructor * Constructor
@ -66,7 +66,7 @@ public class JpaConformanceProviderDstu21 extends ServerConformanceProvider {
/** /**
* Constructor * Constructor
*/ */
public JpaConformanceProviderDstu21(RestfulServer theRestfulServer, IFhirSystemDao<Bundle, MetaDt> theSystemDao, DaoConfig theDaoConfig) { public JpaConformanceProviderDstu21(RestfulServer theRestfulServer, IFhirSystemDao<Bundle, Meta> theSystemDao, DaoConfig theDaoConfig) {
super(theRestfulServer); super(theRestfulServer);
myRestfulServer = theRestfulServer; myRestfulServer = theRestfulServer;
mySystemDao = theSystemDao; mySystemDao = theSystemDao;
@ -83,26 +83,26 @@ public class JpaConformanceProviderDstu21 extends ServerConformanceProvider {
FhirContext ctx = myRestfulServer.getFhirContext(); FhirContext ctx = myRestfulServer.getFhirContext();
retVal = super.getServerConformance(theRequest); retVal = super.getServerConformance(theRequest);
for (Rest nextRest : retVal.getRest()) { for (ConformanceRestComponent nextRest : retVal.getRest()) {
for (RestResource nextResource : nextRest.getResource()) { for (ConformanceRestResourceComponent nextResource : nextRest.getResource()) {
ConditionalDeleteStatusEnum conditionalDelete = nextResource.getConditionalDeleteElement().getValueAsEnum(); ConditionalDeleteStatus conditionalDelete = nextResource.getConditionalDelete();
if (conditionalDelete == ConditionalDeleteStatusEnum.MULTIPLE_DELETES_SUPPORTED && myDaoConfig.isAllowMultipleDelete() == false) { if (conditionalDelete == ConditionalDeleteStatus.MULTIPLE && myDaoConfig.isAllowMultipleDelete() == false) {
nextResource.setConditionalDelete(ConditionalDeleteStatusEnum.SINGLE_DELETES_SUPPORTED); nextResource.setConditionalDelete(ConditionalDeleteStatus.SINGLE);
} }
// Add resource counts // Add resource counts
Long count = counts.get(nextResource.getTypeElement().getValueAsString()); Long count = counts.get(nextResource.getTypeElement().getValueAsString());
if (count != null) { if (count != null) {
nextResource.addUndeclaredExtension(false, ExtensionConstants.CONF_RESOURCE_COUNT, new DecimalDt(count)); nextResource.addExtension(new Extension(ExtensionConstants.CONF_RESOURCE_COUNT, new DecimalType(count)));
} }
// Add chained params // Add chained params
for (RestResourceSearchParam nextParam : nextResource.getSearchParam()) { for (ConformanceRestResourceSearchParamComponent nextParam : nextResource.getSearchParam()) {
if (nextParam.getTypeElement().getValueAsEnum() == SearchParamTypeEnum.REFERENCE) { if (nextParam.getType() == SearchParamType.REFERENCE) {
List<BoundCodeDt<ResourceTypeEnum>> targets = nextParam.getTarget(); List<CodeType> targets = nextParam.getTarget();
for (BoundCodeDt<ResourceTypeEnum> next : targets) { for (CodeType next : targets) {
RuntimeResourceDefinition def = ctx.getResourceDefinition(next.getValue()); RuntimeResourceDefinition def = ctx.getResourceDefinition(next.getValue());
for (RuntimeSearchParam nextChainedParam : def.getSearchParams()) { for (RuntimeSearchParam nextChainedParam : def.getSearchParams()) {
nextParam.addChain(nextChainedParam.getName()); nextParam.addChain(nextChainedParam.getName());
@ -135,7 +135,7 @@ public class JpaConformanceProviderDstu21 extends ServerConformanceProvider {
} }
@CoverageIgnore @CoverageIgnore
public void setSystemDao(IFhirSystemDao<Bundle, MetaDt> mySystemDao) { public void setSystemDao(IFhirSystemDao<Bundle, Meta> mySystemDao) {
this.mySystemDao = mySystemDao; this.mySystemDao = mySystemDao;
} }
} }

View File

@ -22,11 +22,12 @@ package ca.uhn.fhir.jpa.provider;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import org.hl7.fhir.dstu21.model.IdType;
import org.hl7.fhir.dstu21.model.Meta;
import org.hl7.fhir.dstu21.model.Parameters;
import org.hl7.fhir.instance.model.api.IAnyResource;
import ca.uhn.fhir.jpa.dao.IFhirResourceDao; import ca.uhn.fhir.jpa.dao.IFhirResourceDao;
import ca.uhn.fhir.model.api.IResource;
import ca.uhn.fhir.model.dstu2.composite.MetaDt;
import ca.uhn.fhir.model.dstu2.resource.Parameters;
import ca.uhn.fhir.model.primitive.IdDt;
import ca.uhn.fhir.rest.annotation.ConditionalUrlParam; import ca.uhn.fhir.rest.annotation.ConditionalUrlParam;
import ca.uhn.fhir.rest.annotation.Create; import ca.uhn.fhir.rest.annotation.Create;
import ca.uhn.fhir.rest.annotation.Delete; import ca.uhn.fhir.rest.annotation.Delete;
@ -41,7 +42,7 @@ import ca.uhn.fhir.rest.api.ValidationModeEnum;
import ca.uhn.fhir.rest.server.EncodingEnum; import ca.uhn.fhir.rest.server.EncodingEnum;
import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException; import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException;
public class JpaResourceProviderDstu21<T extends IResource> extends BaseJpaResourceProvider<T> { public class JpaResourceProviderDstu21<T extends IAnyResource> extends BaseJpaResourceProvider<T> {
public static final String OPERATION_NAME_META = "$meta"; public static final String OPERATION_NAME_META = "$meta";
public static final String OPERATION_NAME_META_DELETE = "$meta-delete"; public static final String OPERATION_NAME_META_DELETE = "$meta-delete";
@ -70,7 +71,7 @@ public class JpaResourceProviderDstu21<T extends IResource> extends BaseJpaResou
} }
@Delete() @Delete()
public MethodOutcome delete(HttpServletRequest theRequest, @IdParam IdDt theResource, @ConditionalUrlParam(supportsMultiple=true) String theConditional) { public MethodOutcome delete(HttpServletRequest theRequest, @IdParam IdType theResource, @ConditionalUrlParam(supportsMultiple=true) String theConditional) {
startRequest(theRequest); startRequest(theRequest);
try { try {
if (theConditional != null) { if (theConditional != null) {
@ -85,49 +86,49 @@ public class JpaResourceProviderDstu21<T extends IResource> extends BaseJpaResou
//@formatter:off //@formatter:off
@Operation(name=OPERATION_NAME_META, idempotent=true, returnParameters= { @Operation(name=OPERATION_NAME_META, idempotent=true, returnParameters= {
@OperationParam(name="return", type=MetaDt.class) @OperationParam(name="return", type=Meta.class)
}) })
//@formatter:on //@formatter:on
public Parameters meta() { public Parameters meta() {
Parameters parameters = new Parameters(); Parameters parameters = new Parameters();
MetaDt metaGetOperation = getDao().metaGetOperation(MetaDt.class); Meta metaGetOperation = getDao().metaGetOperation(Meta.class);
parameters.addParameter().setName("return").setValue(metaGetOperation); parameters.addParameter().setName("return").setValue(metaGetOperation);
return parameters; return parameters;
} }
//@formatter:off //@formatter:off
@Operation(name=OPERATION_NAME_META, idempotent=true, returnParameters= { @Operation(name=OPERATION_NAME_META, idempotent=true, returnParameters= {
@OperationParam(name="return", type=MetaDt.class) @OperationParam(name="return", type=Meta.class)
}) })
//@formatter:on //@formatter:on
public Parameters meta(@IdParam IdDt theId) { public Parameters meta(@IdParam IdType theId) {
Parameters parameters = new Parameters(); Parameters parameters = new Parameters();
MetaDt metaGetOperation = getDao().metaGetOperation(MetaDt.class, theId); Meta metaGetOperation = getDao().metaGetOperation(Meta.class, theId);
parameters.addParameter().setName("return").setValue(metaGetOperation); parameters.addParameter().setName("return").setValue(metaGetOperation);
return parameters; return parameters;
} }
//@formatter:off //@formatter:off
@Operation(name=OPERATION_NAME_META_ADD, idempotent=true, returnParameters= { @Operation(name=OPERATION_NAME_META_ADD, idempotent=true, returnParameters= {
@OperationParam(name="return", type=MetaDt.class) @OperationParam(name="return", type=Meta.class)
}) })
//@formatter:on //@formatter:on
public Parameters metaAdd(@IdParam IdDt theId, @OperationParam(name = "meta") MetaDt theMeta) { public Parameters metaAdd(@IdParam IdType theId, @OperationParam(name = "meta") Meta theMeta) {
if (theMeta == null) { if (theMeta == null) {
throw new InvalidRequestException("Input contains no parameter with name 'meta'"); throw new InvalidRequestException("Input contains no parameter with name 'meta'");
} }
Parameters parameters = new Parameters(); Parameters parameters = new Parameters();
MetaDt metaAddOperation = getDao().metaAddOperation(theId, theMeta); Meta metaAddOperation = getDao().metaAddOperation(theId, theMeta);
parameters.addParameter().setName("return").setValue(metaAddOperation); parameters.addParameter().setName("return").setValue(metaAddOperation);
return parameters; return parameters;
} }
//@formatter:off //@formatter:off
@Operation(name=OPERATION_NAME_META_DELETE, idempotent=true, returnParameters= { @Operation(name=OPERATION_NAME_META_DELETE, idempotent=true, returnParameters= {
@OperationParam(name="return", type=MetaDt.class) @OperationParam(name="return", type=Meta.class)
}) })
//@formatter:on //@formatter:on
public Parameters metaDelete(@IdParam IdDt theId, @OperationParam(name = "meta") MetaDt theMeta) { public Parameters metaDelete(@IdParam IdType theId, @OperationParam(name = "meta") Meta theMeta) {
if (theMeta == null) { if (theMeta == null) {
throw new InvalidRequestException("Input contains no parameter with name 'meta'"); throw new InvalidRequestException("Input contains no parameter with name 'meta'");
} }
@ -137,7 +138,7 @@ public class JpaResourceProviderDstu21<T extends IResource> extends BaseJpaResou
} }
@Update @Update
public MethodOutcome update(HttpServletRequest theRequest, @ResourceParam T theResource, @IdParam IdDt theId, @ConditionalUrlParam String theConditional) { public MethodOutcome update(HttpServletRequest theRequest, @ResourceParam T theResource, @IdParam IdType theId, @ConditionalUrlParam String theConditional) {
startRequest(theRequest); startRequest(theRequest);
try { try {
if (theConditional != null) { if (theConditional != null) {
@ -158,7 +159,7 @@ public class JpaResourceProviderDstu21<T extends IResource> extends BaseJpaResou
} }
@Validate @Validate
public MethodOutcome validate(@ResourceParam T theResource, @IdParam IdDt theId, @ResourceParam String theRawResource, @ResourceParam EncodingEnum theEncoding, @Validate.Mode ValidationModeEnum theMode, public MethodOutcome validate(@ResourceParam T theResource, @IdParam IdType theId, @ResourceParam String theRawResource, @ResourceParam EncodingEnum theEncoding, @Validate.Mode ValidationModeEnum theMode,
@Validate.Profile String theProfile) { @Validate.Profile String theProfile) {
return getDao().validate(theResource, theId, theRawResource, theEncoding, theMode, theProfile); return getDao().validate(theResource, theId, theRawResource, theEncoding, theMode, theProfile);
} }

View File

@ -28,6 +28,13 @@ import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.TreeMap; import java.util.TreeMap;
import org.hl7.fhir.dstu21.model.Bundle;
import org.hl7.fhir.dstu21.model.DecimalType;
import org.hl7.fhir.dstu21.model.IntegerType;
import org.hl7.fhir.dstu21.model.Meta;
import org.hl7.fhir.dstu21.model.Parameters;
import org.hl7.fhir.dstu21.model.Parameters.ParametersParameterComponent;
import org.hl7.fhir.dstu21.model.StringType;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.beans.factory.annotation.Qualifier;
@ -35,13 +42,7 @@ import ca.uhn.fhir.jpa.dao.FhirSearchDao.Suggestion;
import ca.uhn.fhir.jpa.dao.IFhirSystemDao; import ca.uhn.fhir.jpa.dao.IFhirSystemDao;
import ca.uhn.fhir.jpa.dao.ISearchDao; import ca.uhn.fhir.jpa.dao.ISearchDao;
import ca.uhn.fhir.model.api.annotation.Description; import ca.uhn.fhir.model.api.annotation.Description;
import ca.uhn.fhir.model.dstu21.composite.MetaDt;
import ca.uhn.fhir.model.dstu21.resource.Bundle;
import ca.uhn.fhir.model.dstu21.resource.Parameters;
import ca.uhn.fhir.model.dstu21.resource.Parameters.Parameter;
import ca.uhn.fhir.model.primitive.DecimalDt;
import ca.uhn.fhir.model.primitive.IntegerDt; import ca.uhn.fhir.model.primitive.IntegerDt;
import ca.uhn.fhir.model.primitive.StringDt;
import ca.uhn.fhir.rest.annotation.Operation; import ca.uhn.fhir.rest.annotation.Operation;
import ca.uhn.fhir.rest.annotation.OperationParam; import ca.uhn.fhir.rest.annotation.OperationParam;
import ca.uhn.fhir.rest.annotation.Transaction; import ca.uhn.fhir.rest.annotation.Transaction;
@ -50,11 +51,11 @@ import ca.uhn.fhir.rest.method.RequestDetails;
import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException; import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException;
import ca.uhn.fhir.rest.server.servlet.ServletRequestDetails; import ca.uhn.fhir.rest.server.servlet.ServletRequestDetails;
public class JpaSystemProviderDstu21 extends BaseJpaSystemProvider<Bundle, MetaDt> { public class JpaSystemProviderDstu21 extends BaseJpaSystemProvider<Bundle, Meta> {
@Autowired() @Autowired()
@Qualifier("mySystemDaoDstu21") @Qualifier("mySystemDaoDstu21")
private IFhirSystemDao<Bundle, MetaDt> mySystemDao; private IFhirSystemDao<Bundle, Meta> mySystemDao;
@Autowired @Autowired
private ISearchDao mySearchDao; private ISearchDao mySearchDao;
@ -163,7 +164,7 @@ public class JpaSystemProviderDstu21 extends BaseJpaSystemProvider<Bundle, MetaD
Map<String, Long> counts = mySystemDao.getResourceCounts(); Map<String, Long> counts = mySystemDao.getResourceCounts();
counts = new TreeMap<String, Long>(counts); counts = new TreeMap<String, Long>(counts);
for (Entry<String, Long> nextEntry : counts.entrySet()) { for (Entry<String, Long> nextEntry : counts.entrySet()) {
retVal.addParameter().setName(new StringDt(nextEntry.getKey())).setValue(new IntegerDt(nextEntry.getValue().intValue())); retVal.addParameter().setName((nextEntry.getKey())).setValue(new IntegerType(nextEntry.getValue().intValue()));
} }
return retVal; return retVal;
@ -178,13 +179,13 @@ public class JpaSystemProviderDstu21 extends BaseJpaSystemProvider<Bundle, MetaD
int count = mySystemDao.markAllResourcesForReindexing(); int count = mySystemDao.markAllResourcesForReindexing();
Parameters retVal = new Parameters(); Parameters retVal = new Parameters();
retVal.addParameter().setName("count").setValue(new IntegerDt(count)); retVal.addParameter().setName("count").setValue(new IntegerType(count));
return retVal; return retVal;
} }
//@formatter:off //@formatter:off
@Operation(name="$meta", idempotent=true, returnParameters= { @Operation(name="$meta", idempotent=true, returnParameters= {
@OperationParam(name="return", type=MetaDt.class) @OperationParam(name="return", type=Meta.class)
}) })
//@formatter:on //@formatter:on
public Parameters meta() { public Parameters meta() {
@ -216,8 +217,8 @@ public class JpaSystemProviderDstu21 extends BaseJpaSystemProvider<Bundle, MetaD
for (Suggestion next : keywords) { for (Suggestion next : keywords) {
//@formatter:off //@formatter:off
retVal.addParameter() retVal.addParameter()
.addPart(new Parameter().setName("keyword").setValue(new StringDt(next.getTerm()))) .addPart(new ParametersParameterComponent().setName("keyword").setValue(new StringType(next.getTerm())))
.addPart(new Parameter().setName("score").setValue(new DecimalDt(next.getScore()))); .addPart(new ParametersParameterComponent().setName("score").setValue(new DecimalType(next.getScore())));
//@formatter:on //@formatter:on
} }

Some files were not shown because too many files have changed in this diff Show More