Merge branch 'hl7org_dstu21' of github.com:jamesagnew/hapi-fhir into hl7org_dstu21

This commit is contained in:
James Agnew 2015-12-23 17:34:14 -05:00
commit 47721ddf54
1387 changed files with 230785 additions and 128889 deletions

1
.gitignore vendored
View File

@ -16,6 +16,7 @@ nohup.out
tmp.txt
*.hprof
tmp.txt
ca.uhn.fhir.jpa.entity.ResourceIndexedSearchParamString/
# Vagrant stuff.
.vagrant

View File

@ -214,8 +214,8 @@ public abstract class BaseRuntimeElementDefinition<T extends IBase> {
/**
* HL7.org style.
*/
PRIMITIVE_XHTML_HL7ORG
PRIMITIVE_XHTML_HL7ORG,
}
}

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.IBaseEnumeration;
import org.hl7.fhir.instance.model.api.IBaseExtension;
import org.hl7.fhir.instance.model.api.IBaseMetaType;
import org.hl7.fhir.instance.model.api.IBaseReference;
import org.hl7.fhir.instance.model.api.IBaseResource;
import org.hl7.fhir.instance.model.api.IBaseXhtml;
@ -192,7 +193,7 @@ class ModelScanner {
Map<String, Class<? extends IBaseResource>> resourceTypes = myNameToResourceType;
myVersionTypes = scanVersionPropertyFile(theDatatypes, resourceTypes, myVersion);
// toScan.add(DateDt.class);
// toScan.add(CodeDt.class);
// toScan.add(DecimalDt.class);
@ -245,58 +246,58 @@ class ModelScanner {
private <T extends Annotation> T pullAnnotation(Class<?> theContainer, AnnotatedElement theTarget, Class<T> 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;
// }
//
// 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 {
@ -366,6 +367,8 @@ class ModelScanner {
RuntimeCompositeDatatypeDefinition resourceDef;
if (theClass.equals(ExtensionDt.class)) {
resourceDef = new RuntimeExtensionDtDefinition(theDatatypeDefinition, theClass, true);
// } else if (IBaseMetaType.class.isAssignableFrom(theClass)) {
// resourceDef = new RuntimeMetaDefinition(theDatatypeDefinition, theClass, isStandardType(theClass));
} else {
resourceDef = new RuntimeCompositeDatatypeDefinition(theDatatypeDefinition, theClass, isStandardType(theClass));
}

View File

@ -109,22 +109,26 @@ public class RuntimeChildChoiceDefinition extends BaseRuntimeDeclaredChildDefini
} else {
nextDef = theClassToElementDefinitions.get(next);
BaseRuntimeElementDefinition<?> nextDefForChoice = nextDef;
if (nextDef instanceof IRuntimeDatatypeDefinition) {
IRuntimeDatatypeDefinition nextDefDatatype = (IRuntimeDatatypeDefinition) nextDef;
if (nextDefDatatype.getProfileOf() != null) {
/*
* Elements which are called foo[x] and have a choice which is a profiled datatype must use the
* unprofiled datatype as the element name. E.g. if foo[x] allows markdown as a datatype, it calls the
* element fooString when encoded, because markdown is a profile of string. This is according to the
* FHIR spec
*/
nextDefForChoice = null;
nonPreferred = true;
Class<? extends IBaseDatatype> profileType = nextDefDatatype.getProfileOf();
BaseRuntimeElementDefinition<?> elementDef = theClassToElementDefinitions.get(profileType);
elementName = getElementName() + StringUtils.capitalize(elementDef.getName());
}
}
/*
* In HAPI 1.3 the following applied:
* Elements which are called foo[x] and have a choice which is a profiled datatype must use the
* unprofiled datatype as the element name. E.g. if foo[x] allows markdown as a datatype, it calls the
* element fooString when encoded, because markdown is a profile of string. This is according to the
* FHIR spec
*
* As of HAPI 1.4 this has been disabled after conversation with Grahame. It appears
* that it is not correct behaviour.
*/
// if (nextDef instanceof IRuntimeDatatypeDefinition) {
// IRuntimeDatatypeDefinition nextDefDatatype = (IRuntimeDatatypeDefinition) nextDef;
// if (nextDefDatatype.getProfileOf() != null) {
// nextDefForChoice = null;
// nonPreferred = true;
// Class<? extends IBaseDatatype> profileType = nextDefDatatype.getProfileOf();
// BaseRuntimeElementDefinition<?> elementDef = theClassToElementDefinitions.get(profileType);
// elementName = getElementName() + StringUtils.capitalize(elementDef.getName());
// }
// }
if (nextDefForChoice != null) {
elementName = getElementName() + StringUtils.capitalize(nextDefForChoice.getName());
}

View File

@ -26,6 +26,7 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeSet;
import org.apache.commons.lang3.text.WordUtils;
import org.hl7.fhir.instance.model.api.IBase;
@ -34,6 +35,7 @@ import org.hl7.fhir.instance.model.api.IBaseResource;
import ca.uhn.fhir.model.api.ExtensionDt;
import ca.uhn.fhir.model.api.IDatatype;
import ca.uhn.fhir.model.base.composite.BaseResourceReferenceDt;
import ca.uhn.fhir.model.primitive.CodeDt;
public class RuntimeChildUndeclaredExtensionDefinition extends BaseRuntimeChildDefinition {
@ -153,13 +155,8 @@ public class RuntimeChildUndeclaredExtensionDefinition extends BaseRuntimeChildD
myDatatypeToAttributeName = new HashMap<Class<? extends IBase>, String>();
myDatatypeToDefinition = new HashMap<Class<? extends IBase>, BaseRuntimeElementDefinition<?>>();
// for (theContext.get)
for (BaseRuntimeElementDefinition<?> next : theClassToElementDefinitions.values()) {
if (next instanceof IRuntimeDatatypeDefinition) {
// if (next.getName().equals("CodeableConcept")) {
// System.out.println();
// }
myDatatypeToDefinition.put(next.getImplementingClass(), next);
@ -178,7 +175,7 @@ public class RuntimeChildUndeclaredExtensionDefinition extends BaseRuntimeChildD
* type.
*/
if (!qualifiedName.startsWith("ca.uhn.fhir.model")) {
if (!qualifiedName.startsWith("org.hl7.fhir.instance.model")) {
if (!qualifiedName.startsWith("org.hl7.fhir")) {
continue;
}
}
@ -198,12 +195,6 @@ public class RuntimeChildUndeclaredExtensionDefinition extends BaseRuntimeChildD
myAttributeNameToDefinition = datatypeAttributeNameToDefinition;
// for (Entry<String, BaseRuntimeElementDefinition<?>> next : myAttributeNameToDefinition.entrySet()) {
// @SuppressWarnings("unchecked")
// Class<? extends IDatatype> type = (Class<? extends IDatatype>) next.getValue().getImplementingClass();
// myDatatypeToDefinition.put(type, next.getValue());
// }
/*
* Resource reference - The correct name is 'valueReference' in DSTU2 and 'valueResource' in DSTU1
*/

View File

@ -74,7 +74,14 @@ public class RuntimePrimitiveDatatypeDefinition extends BaseRuntimeElementDefini
if (myProfileOfType != null) {
myProfileOf = theClassToElementDefinitions.get(myProfileOfType);
if (myProfileOf == null) {
throw new ConfigurationException("Unknown profileOf value: " + myProfileOfType + " in type " + getImplementingClass().getName());
StringBuilder b = new StringBuilder();
b.append("Unknown profileOf value: ");
b.append(myProfileOfType);
b.append(" in type ");
b.append(getImplementingClass().getName());
b.append(" - Valid types: ");
b.append(theClassToElementDefinitions.keySet());
throw new ConfigurationException(b.toString());
}
}
}

View File

@ -25,6 +25,7 @@ import java.util.Date;
import org.hl7.fhir.instance.model.api.IBase;
import org.hl7.fhir.instance.model.api.IBaseResource;
import org.hl7.fhir.instance.model.api.IIdType;
import org.hl7.fhir.instance.model.api.IPrimitiveType;
import ca.uhn.fhir.context.FhirContext;
@ -59,4 +60,6 @@ public interface IFhirVersion {
IPrimitiveType<Date> getLastUpdated(IBaseResource theResource);
IIdType newIdType();
}

View File

@ -40,15 +40,6 @@ import ca.uhn.fhir.model.primitive.IdDt;
* </p>
*/
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.

View File

@ -1,5 +1,8 @@
package ca.uhn.fhir.model.api;
import static org.apache.commons.lang3.StringUtils.isBlank;
import static org.apache.commons.lang3.StringUtils.isNotBlank;
import org.apache.commons.lang3.builder.ToStringBuilder;
/*
@ -32,9 +35,9 @@ import org.apache.commons.lang3.builder.ToStringBuilder;
*/
public class Include {
private final boolean myImmutable;
private boolean myRecurse;
private String myValue;
private boolean myImmutable;
/**
* Constructor for <b>non-recursive</b> include
@ -44,10 +47,11 @@ public class Include {
*/
public Include(String theValue) {
myValue = theValue;
myImmutable = false;
}
/**
* Constructor for <b>non-recursive</b> include
* Constructor for an include
*
* @param theValue
* The <code>_include</code> value, e.g. "Patient:name"
@ -57,6 +61,21 @@ public class Include {
public Include(String theValue, boolean theRecurse) {
myValue = theValue;
myRecurse = theRecurse;
myImmutable = false;
}
/**
* Constructor for an include
*
* @param theValue
* The <code>_include</code> value, e.g. "Patient:name"
* @param theRecurse
* Should the include recurse
*/
public Include(String theValue, boolean theRecurse, boolean theImmutable) {
myValue = theValue;
myRecurse = theRecurse;
myImmutable = theImmutable;
}
/**
@ -73,22 +92,6 @@ public class Include {
return new Include(myValue, true);
}
public String getValue() {
return myValue;
}
/**
* See the note on equality on the {@link Include class documentation}
*/
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + (myRecurse ? 1231 : 1237);
result = prime * result + ((myValue == null) ? 0 : myValue.hashCode());
return result;
}
/**
* See the note on equality on the {@link Include class documentation}
*/
@ -117,6 +120,73 @@ public class Include {
return true;
}
/**
* Returns the portion of the value before the first colon
*/
public String getParamType() {
int firstColon = myValue.indexOf(':');
if (firstColon == -1 || firstColon == myValue.length() - 1) {
return null;
}
return myValue.substring(0, firstColon);
}
/**
* Returns the portion of the value after the first colon but before the second colon
*/
public String getParamName() {
int firstColon = myValue.indexOf(':');
if (firstColon == -1 || firstColon == myValue.length() - 1) {
return null;
}
int secondColon = myValue.indexOf(':', firstColon + 1);
if (secondColon != -1) {
return myValue.substring(firstColon + 1, secondColon);
} else {
return myValue.substring(firstColon + 1);
}
}
/**
* Returns the portion of the string after the second colon, or null if there are not two colons in the value.
*/
public String getParamTargetType() {
int firstColon = myValue.indexOf(':');
if (firstColon == -1 || firstColon == myValue.length() - 1) {
return null;
}
int secondColon = myValue.indexOf(':', firstColon + 1);
if (secondColon != -1) {
return myValue.substring(secondColon + 1);
} else {
return null;
}
}
public String getValue() {
return myValue;
}
/**
* See the note on equality on the {@link Include class documentation}
*/
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + (myRecurse ? 1231 : 1237);
result = prime * result + ((myValue == null) ? 0 : myValue.hashCode());
return result;
}
/**
* Is this object {@link #toLocked() locked}?
*/
public boolean isLocked() {
return myImmutable;
}
public boolean isRecurse() {
return myRecurse;
}
@ -132,12 +202,14 @@ public class Include {
myValue = theValue;
}
/**
* Return a new
*/
public Include toLocked() {
Include retVal = new Include(myValue, myRecurse);
retVal.myImmutable = true;
Include retVal = new Include(myValue, myRecurse, true);
return retVal;
}
@Override
public String toString() {
ToStringBuilder builder = new ToStringBuilder(this);
@ -145,4 +217,56 @@ public class Include {
builder.append("recurse", myRecurse);
return builder.toString();
}
/**
* Creates and returns a new copy of this Include with the given type. The following table shows what will be
* returned:
* <table>
* <tr>
* <th>Initial Contents</th>
* <th>theResourceType</th>
* <th>Output</th>
* </tr>
* <tr>
* <td>Patient:careProvider</th>
* <th>Organization</th>
* <th>Patient:careProvider:Organization</th>
* </tr>
* <tr>
* <td>Patient:careProvider:Practitioner</th>
* <th>Organization</th>
* <th>Patient:careProvider:Organization</th>
* </tr>
* <tr>
* <td>Patient</th>
* <th>(any)</th>
* <th>{@link IllegalStateException}</th>
* </tr>
* </table>
*
* @param theResourceType
* The resource type (e.g. "Organization")
* @return A new copy of the include. Note that if this include is {@link #toLocked() locked}, the returned include
* will be too
*/
public Include withType(String theResourceType) {
StringBuilder b = new StringBuilder();
String paramType = getParamType();
String paramName = getParamName();
if (isBlank(paramType) || isBlank(paramName)) {
throw new IllegalStateException("This include does not contain a value in the format [ResourceType]:[paramName]");
}
b.append(paramType);
b.append(":");
b.append(paramName);
if (isNotBlank(theResourceType)) {
b.append(':');
b.append(theResourceType);
}
Include retVal = new Include(b.toString(), myRecurse, myImmutable);
return retVal;
}
}

View File

@ -30,6 +30,7 @@ import java.util.Map;
import org.apache.commons.lang3.StringUtils;
import org.hl7.fhir.instance.model.api.IAnyResource;
import org.hl7.fhir.instance.model.api.IPrimitiveType;
import ca.uhn.fhir.model.base.composite.BaseCodingDt;
import ca.uhn.fhir.model.primitive.DecimalDt;
@ -72,7 +73,7 @@ public abstract class ResourceMetadataKeyEnum<T> implements Serializable {
* Values for this key are of type <b>{@link InstantDt}</b>
* </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;
@Override
@ -84,6 +85,17 @@ public abstract class ResourceMetadataKeyEnum<T> implements Serializable {
public void put(IResource theResource, InstantDt 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);
}
};
/**
@ -121,7 +133,7 @@ public abstract class ResourceMetadataKeyEnum<T> implements Serializable {
* Values for this key are of type <b>{@link BundleEntrySearchModeEnum}</b>
* </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;
@Override
public BundleEntrySearchModeEnum get(IResource theResource) {
@ -132,6 +144,16 @@ public abstract class ResourceMetadataKeyEnum<T> implements Serializable {
public void put(IResource theResource, BundleEntrySearchModeEnum theObject) {
theResource.getResourceMetadata().put(ENTRY_SEARCH_MODE, theObject);
}
@Override
public String get(IAnyResource theResource) {
return (String) theResource.getUserData(ENTRY_SEARCH_MODE.name());
}
@Override
public void put(IAnyResource theResource, String theObject) {
theResource.setUserData(ENTRY_SEARCH_MODE.name(), theObject);
}
};
/**
@ -146,7 +168,7 @@ public abstract class ResourceMetadataKeyEnum<T> implements Serializable {
* Values for this key are of type <b>{@link BundleEntryTransactionMethodEnum}</b>
* </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") {
private static final long serialVersionUID = 1L;
@ -160,6 +182,16 @@ public abstract class ResourceMetadataKeyEnum<T> implements Serializable {
public void put(IResource theResource, BundleEntryTransactionMethodEnum theObject) {
theResource.getResourceMetadata().put(ENTRY_TRANSACTION_METHOD, theObject);
}
@Override
public String get(IAnyResource theResource) {
return (String) theResource.getUserData(ENTRY_TRANSACTION_METHOD.name());
}
@Override
public void put(IAnyResource theResource, String theObject) {
theResource.setUserData(ENTRY_TRANSACTION_METHOD.name(), theObject);
}
};
@ -575,4 +607,19 @@ public abstract class ResourceMetadataKeyEnum<T> implements Serializable {
+ 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

@ -21,6 +21,7 @@ package ca.uhn.fhir.model.base.composite;
*/
import org.apache.commons.lang3.StringUtils;
import org.hl7.fhir.instance.model.api.IBaseCoding;
import ca.uhn.fhir.model.api.BaseIdentifiableElement;
import ca.uhn.fhir.model.api.ICompositeDatatype;

View File

@ -675,4 +675,25 @@ public class IdDt extends UriDt implements IPrimitiveDatatype<String>, IIdType {
return theIdPart.toString();
}
@Override
public IIdType setParts(String theBaseUrl, String theResourceType, String theIdPart, String theVersionIdPart) {
if (isNotBlank(theVersionIdPart)) {
Validate.notBlank(theResourceType, "If theVersionIdPart is populated, theResourceType and theIdPart must be populated");
Validate.notBlank(theIdPart, "If theVersionIdPart is populated, theResourceType and theIdPart must be populated");
}
if (isNotBlank(theBaseUrl) && isNotBlank(theIdPart)) {
Validate.notBlank(theResourceType, "If theBaseUrl is populated and theIdPart is populated, theResourceType must be populated");
}
setValue(null);
myBaseUrl = theBaseUrl;
myResourceType = theResourceType;
myUnqualifiedId = theIdPart;
myUnqualifiedVersionId = StringUtils.defaultIfBlank(theVersionIdPart, null);
myHaveComponentParts = true;
return this;
}
}

View File

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

View File

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

View File

@ -28,6 +28,7 @@ import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeSet;
import javax.xml.stream.events.StartElement;
import javax.xml.stream.events.XMLEvent;

View File

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

View File

@ -23,8 +23,9 @@ package ca.uhn.fhir.rest.annotation;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import org.hl7.fhir.instance.model.api.IBaseResource;
import ca.uhn.fhir.model.api.IQueryParameterType;
import ca.uhn.fhir.model.api.IResource;
import ca.uhn.fhir.rest.param.CompositeParam;
import ca.uhn.fhir.rest.param.ReferenceParam;
//import ca.uhn.fhir.testmodel.Patient; // TODO: qualify this correctly
@ -116,5 +117,5 @@ public @interface OptionalParam {
* this value must not be populated.
* </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.RetentionPolicy;
import org.hl7.fhir.instance.model.api.IBaseResource;
import ca.uhn.fhir.model.api.IQueryParameterType;
import ca.uhn.fhir.model.api.IResource;
import ca.uhn.fhir.rest.param.CompositeParam;
import ca.uhn.fhir.rest.param.ReferenceParam;
//import ca.uhn.fhir.testmodel.Patient; // TODO: qualify this correctly
@ -97,6 +98,6 @@ public @interface RequiredParam {
* If the parameter annotated with this annotation is not a {@link ReferenceParam}, this value must not be populated.
* </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
* whether the result was a creation or an update. However, it can be useful if you are implementing an update method that does a create if the ID doesn't already exist.
*/
public MethodOutcome(IdDt theId, Boolean theCreated) {
public MethodOutcome(IIdType theId, Boolean theCreated) {
myId = theId;
myCreated = theCreated;
}
@ -64,7 +64,7 @@ public class MethodOutcome {
* @param theBaseOperationOutcome
* The operation outcome to return with the response (or null for none)
*/
public MethodOutcome(IdDt theId, IBaseOperationOutcome theBaseOperationOutcome) {
public MethodOutcome(IIdType theId, IBaseOperationOutcome theBaseOperationOutcome) {
myId = theId;
myOperationOutcome = theBaseOperationOutcome;
}
@ -82,17 +82,17 @@ public class MethodOutcome {
* If not null, indicates whether the resource was created (as opposed to being updated). This is generally not needed, since the server can assume based on the method being called
* whether the result was a creation or an update. However, it can be useful if you are implementing an update method that does a create if the ID doesn't already exist.
*/
public MethodOutcome(IdDt theId, IBaseOperationOutcome theBaseOperationOutcome, Boolean theCreated) {
public MethodOutcome(IIdType theId, IBaseOperationOutcome theBaseOperationOutcome, Boolean theCreated) {
myId = theId;
myOperationOutcome = theBaseOperationOutcome;
myCreated = theCreated;
}
/**
* @deprecated Use the constructor which accepts a single IdDt parameter, and include the logical ID and version ID in that IdDt instance
* @deprecated Use the constructor which accepts a single IIdType parameter, and include the logical ID and version ID in that IIdType instance
*/
@Deprecated
public MethodOutcome(IdDt theId, IdDt theVersionId) {
public MethodOutcome(IIdType theId, IdDt theVersionId) {
myId = theId;
myVersionId = theVersionId;
}
@ -101,7 +101,7 @@ public class MethodOutcome {
* @deprecated Use the constructor which accepts a single IdDt parameter, and include the logical ID and version ID in that IdDt instance
*/
@Deprecated
public MethodOutcome(IdDt theId, IdDt theVersionId, IBaseOperationOutcome theBaseOperationOutcome) {
public MethodOutcome(IIdType theId, IdDt theVersionId, IBaseOperationOutcome theBaseOperationOutcome) {
myId = theId;
myVersionId = theVersionId;
myOperationOutcome = theBaseOperationOutcome;
@ -175,7 +175,7 @@ public class MethodOutcome {
* @param theId
* The ID of the created/updated resource
*/
public void setId(IdDt theId) {
public void setId(IIdType theId) {
myId = theId;
}
@ -200,7 +200,7 @@ public class MethodOutcome {
}
/**
* @deprecated Put the ID and version ID into the same IdDt instance and pass it to {@link #setId(IdDt)}
* @deprecated Put the ID and version ID into the same IdDt instance and pass it to {@link #setId(IIdType)}
*/
@Deprecated
public void setVersionId(IdDt theVersionId) {

View File

@ -853,10 +853,10 @@ public class GenericClient extends BaseClient implements IGenericClient {
}
@Override
public IDeleteTyped resource(IResource theResource) {
public IDeleteTyped resource(IBaseResource theResource) {
Validate.notNull(theResource, "theResource can not be null");
IdDt id = theResource.getId();
Validate.notNull(id, "theResource.getId() can not be null");
IIdType id = theResource.getIdElement();
Validate.notNull(id, "theResource.getIdElement() can not be null");
if (id.hasResourceType() == false || id.hasIdPart() == false) {
throw new IllegalArgumentException("theResource.getId() must contain a resource type and logical ID at a minimum (e.g. Patient/1234), found: " + id.getValue());
}
@ -1798,7 +1798,7 @@ public class GenericClient extends BaseClient implements IGenericClient {
}
}
if (myReturnBundleType == null && myContext.getVersion().getVersion().equals(FhirVersionEnum.DSTU2_HL7ORG)) {
if (myReturnBundleType == null && myContext.getVersion().getVersion().isRi()) {
throw new IllegalArgumentException("When using the client with HL7.org structures, you must specify "
+ "the bundle return type for the client by adding \".returnBundle(org.hl7.fhir.instance.model.Bundle.class)\" to your search method call before the \".execute()\" method");
}

View File

@ -1,5 +1,25 @@
package ca.uhn.fhir.rest.client.interceptor;
/*
* #%L
* HAPI FHIR - Core Library
* %%
* Copyright (C) 2014 - 2015 University Health Network
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* #L%
*/
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.zip.GZIPOutputStream;

View File

@ -3,8 +3,6 @@ package ca.uhn.fhir.rest.gclient;
import org.hl7.fhir.instance.model.api.IBaseResource;
import org.hl7.fhir.instance.model.api.IIdType;
import ca.uhn.fhir.model.api.IResource;
/*
* #%L
* HAPI FHIR - Core Library
@ -27,7 +25,7 @@ import ca.uhn.fhir.model.api.IResource;
public interface IDelete {
IDeleteTyped resource(IResource theResource);
IDeleteTyped resource(IBaseResource theResource);
IDeleteTyped resourceById(IIdType theId);

View File

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

View File

@ -732,7 +732,7 @@ public class MethodUtil {
MethodOutcome retVal = new MethodOutcome();
if (locationHeaders != null && locationHeaders.size() > 0) {
String locationHeader = locationHeaders.get(0);
BaseOutcomeReturningMethodBinding.parseContentLocation(retVal, theResourceName, locationHeader);
BaseOutcomeReturningMethodBinding.parseContentLocation(theContext, retVal, theResourceName, locationHeader);
}
if (theResponseStatusCode != Constants.STATUS_HTTP_204_NO_CONTENT) {
EncodingEnum ct = EncodingEnum.forContentType(theResponseMimeType);

View File

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

View File

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

View File

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

View File

@ -1,6 +1,5 @@
package ca.uhn.fhir.rest.method;
import static org.apache.commons.lang3.StringUtils.isBlank;
/*
* #%L
* HAPI FHIR - Core Library
@ -26,6 +25,8 @@ import java.lang.reflect.Method;
import java.util.Collections;
import java.util.Set;
import org.hl7.fhir.instance.model.api.IIdType;
import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.model.api.IResource;
import ca.uhn.fhir.model.primitive.IdDt;
@ -59,9 +60,9 @@ public class UpdateMethodBinding extends BaseOutcomeReturningMethodBindingWithRe
* Content-Location header, but we allow it in the PUT URL as well..
*/
String locationHeader = theRequest.getHeader(Constants.HEADER_CONTENT_LOCATION);
IdDt id = theRequest.getId();
IIdType id = theRequest.getId();
if (isNotBlank(locationHeader)) {
id = new IdDt(locationHeader);
id.setValue(locationHeader);
if (isNotBlank(id.getResourceType())) {
if (!getResourceName().equals(id.getResourceType())) {
throw new InvalidRequestException("Attempting to update '" + getResourceName() + "' but content-location header specifies different resource type '" + id.getResourceType() + "' - header value: " + locationHeader);
@ -85,7 +86,7 @@ public class UpdateMethodBinding extends BaseOutcomeReturningMethodBindingWithRe
if (isNotBlank(locationHeader)) {
MethodOutcome mo = new MethodOutcome();
parseContentLocation(mo, getResourceName(), locationHeader);
parseContentLocation(getContext(), mo, getResourceName(), locationHeader);
if (mo.getId() == null || mo.getId().isEmpty()) {
throw new InvalidRequestException("Invalid Content-Location header for resource " + getResourceName() + ": " + locationHeader);
}

View File

@ -25,6 +25,7 @@ import java.util.Date;
import java.util.List;
import org.apache.commons.lang3.Validate;
import org.hl7.fhir.instance.model.api.IPrimitiveType;
import ca.uhn.fhir.model.api.IQueryParameterOr;
import ca.uhn.fhir.model.api.IQueryParameterType;
@ -63,6 +64,14 @@ public class DateParam extends DateTimeDt implements IQueryParameterType, IQuery
setValueAsString(theDate != null ? theDate.getValueAsString() : null);
}
/**
* Constructor
*/
public DateParam(QuantityCompararatorEnum theComparator, IPrimitiveType<Date> theDate) {
myComparator = theComparator;
setValueAsString(theDate != null ? theDate.getValueAsString() : null);
}
/**
* Constructor
*/

View File

@ -24,6 +24,8 @@ import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import org.hl7.fhir.instance.model.api.IPrimitiveType;
import ca.uhn.fhir.model.api.IQueryParameterAnd;
import ca.uhn.fhir.model.dstu.valueset.QuantityCompararatorEnum;
import ca.uhn.fhir.model.primitive.DateTimeDt;
@ -106,6 +108,20 @@ public class DateRangeParam implements IQueryParameterAnd<DateParam> {
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)
*
@ -272,6 +288,21 @@ public class DateRangeParam implements IQueryParameterAnd<DateParam> {
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
*

View File

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

View File

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

View File

@ -24,6 +24,8 @@ import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.hl7.fhir.instance.model.api.IPrimitiveType;
import ca.uhn.fhir.model.primitive.StringDt;
public class DatatypeUtil {
@ -46,9 +48,9 @@ public class DatatypeUtil {
/**
* 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();
for (StringDt next : theStrings) {
for (IPrimitiveType<String> next : theStrings) {
if (next.isEmpty()) {
continue;
}

View File

@ -30,8 +30,12 @@ import java.util.TreeSet;
import org.apache.commons.lang3.Validate;
import org.hl7.fhir.instance.model.api.IBase;
import org.hl7.fhir.instance.model.api.IBaseExtension;
import org.hl7.fhir.instance.model.api.IBaseHasExtensions;
import org.hl7.fhir.instance.model.api.IBaseHasModifierExtensions;
import org.hl7.fhir.instance.model.api.IBaseReference;
import org.hl7.fhir.instance.model.api.IBaseResource;
import org.hl7.fhir.instance.model.api.IDomainResource;
import org.hl7.fhir.instance.model.api.IPrimitiveType;
import ca.uhn.fhir.context.BaseRuntimeChildDefinition;
@ -68,6 +72,21 @@ public class FhirTerser {
addUndeclaredExtensions(nextExt, theDefinition, theChildDefinition, theCallback);
}
}
if (theElement instanceof IBaseHasExtensions) {
for (IBaseExtension<?, ?> nextExt : ((IBaseHasExtensions)theElement).getExtension()) {
theCallback.acceptElement(nextExt.getValue(), null, theChildDefinition, theDefinition);
addUndeclaredExtensions(nextExt, theDefinition, theChildDefinition, theCallback);
}
}
if (theElement instanceof IBaseHasModifierExtensions) {
for (IBaseExtension<?, ?> nextExt : ((IBaseHasModifierExtensions)theElement).getModifierExtension()) {
theCallback.acceptElement(nextExt.getValue(), null, theChildDefinition, theDefinition);
addUndeclaredExtensions(nextExt, theDefinition, theChildDefinition, theCallback);
}
}
}
/**

View File

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

View File

@ -1,6 +1,7 @@
package org.hl7.fhir.instance.model.api;
import java.util.HashMap;
import ca.uhn.fhir.model.api.annotation.SearchParamDefinition;
import ca.uhn.fhir.rest.gclient.StringClientParam;
/*
* #%L
@ -24,14 +25,41 @@ import java.util.HashMap;
public interface IAnyResource extends IBaseResource {
/**
* Search parameter constant for <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();
@Override
IIdType getIdElement();
IPrimitiveType<String> getLanguageElement();
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;
import ca.uhn.fhir.model.api.IElement;
/*
* #%L
* HAPI FHIR - Core Library
@ -21,6 +23,6 @@ package org.hl7.fhir.instance.model.api;
*/
public interface IBaseBackboneElement extends IBase, IBaseHasExtensions, IBaseHasModifierExtensions {
public interface IBaseBackboneElement extends IElement, IBaseHasExtensions, IBaseHasModifierExtensions {
}

View File

@ -1,5 +1,7 @@
package org.hl7.fhir.instance.model.api;
import ca.uhn.fhir.model.api.IElement;
/*
* #%L
* HAPI FHIR - Core Library
@ -21,6 +23,6 @@ package org.hl7.fhir.instance.model.api;
*/
public interface IBaseDatatype extends IBase {
public interface IBaseDatatype extends IElement {
}

View File

@ -45,4 +45,16 @@ public interface IBaseMetaType extends ICompositeType {
IBaseMetaType setVersionId(String theVersionId);
/**
* Returns the first tag (if any) that has the given system and code, or returns
* <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,7 +1,13 @@
package org.hl7.fhir.instance.model.api;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
import ca.uhn.fhir.context.FhirVersionEnum;
import ca.uhn.fhir.model.api.IElement;
import ca.uhn.fhir.model.api.Include;
/*
* #%L
@ -33,6 +39,16 @@ import ca.uhn.fhir.model.api.IElement;
*/
public interface IBaseResource extends IBase, IElement {
/**
* Include constant for <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();
IBaseResource setId(String theId);

View File

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

View File

@ -135,4 +135,20 @@ public interface IIdType {
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,5 +1,25 @@
package ca.uhn.fhir.jaxrs.server;
/*
* #%L
* HAPI FHIR JAX-RS Server
* %%
* Copyright (C) 2014 - 2015 University Health Network
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* #L%
*/
import java.io.IOException;
import java.lang.annotation.Annotation;
import java.lang.reflect.Method;

View File

@ -1,5 +1,25 @@
package ca.uhn.fhir.jaxrs.server;
/*
* #%L
* HAPI FHIR JAX-RS Server
* %%
* Copyright (C) 2014 - 2015 University Health Network
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* #L%
*/
import java.io.IOException;
import java.util.Collections;
import java.util.List;

View File

@ -1,5 +1,25 @@
package ca.uhn.fhir.jaxrs.server;
/*
* #%L
* HAPI FHIR JAX-RS Server
* %%
* Copyright (C) 2014 - 2015 University Health Network
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* #L%
*/
import java.util.HashMap;
import java.util.List;
import java.util.Map;

View File

@ -1,5 +1,25 @@
package ca.uhn.fhir.jaxrs.server;
/*
* #%L
* HAPI FHIR JAX-RS Server
* %%
* Copyright (C) 2014 - 2015 University Health Network
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* #L%
*/
import java.io.IOException;
import java.net.URL;
import java.util.Collections;

View File

@ -1,5 +1,25 @@
package ca.uhn.fhir.jaxrs.server.interceptor;
/*
* #%L
* HAPI FHIR JAX-RS Server
* %%
* Copyright (C) 2014 - 2015 University Health Network
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* #L%
*/
import java.io.IOException;
import javax.interceptor.AroundInvoke;

View File

@ -1,5 +1,25 @@
package ca.uhn.fhir.jaxrs.server.interceptor;
/*
* #%L
* HAPI FHIR JAX-RS Server
* %%
* Copyright (C) 2014 - 2015 University Health Network
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* #L%
*/
import javax.ejb.ApplicationException;
import ca.uhn.fhir.rest.server.exceptions.BaseServerResponseException;

View File

@ -1,5 +1,25 @@
package ca.uhn.fhir.jaxrs.server.util;
/*
* #%L
* HAPI FHIR JAX-RS Server
* %%
* Copyright (C) 2014 - 2015 University Health Network
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* #L%
*/
import java.lang.reflect.Method;
import java.util.concurrent.ConcurrentHashMap;

View File

@ -1,5 +1,25 @@
package ca.uhn.fhir.jaxrs.server.util;
/*
* #%L
* HAPI FHIR JAX-RS Server
* %%
* Copyright (C) 2014 - 2015 University Health Network
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* #L%
*/
import java.io.IOException;
import java.io.InputStream;
import java.io.Reader;

View File

@ -1,5 +1,25 @@
package ca.uhn.fhir.jaxrs.server.util;
/*
* #%L
* HAPI FHIR JAX-RS Server
* %%
* Copyright (C) 2014 - 2015 University Health Network
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* #L%
*/
import java.io.IOException;
import java.io.StringWriter;
import java.io.UnsupportedEncodingException;

View File

@ -404,6 +404,11 @@
<artifactId>hapi-fhir-structures-dstu2.1</artifactId>
<version>1.4-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>ca.uhn.hapi.fhir</groupId>
<artifactId>hapi-fhir-validation-resources-dstu2.1</artifactId>
<version>1.4-SNAPSHOT</version>
</dependency>
</dependencies>
</plugin>
</plugins>
@ -436,6 +441,7 @@
<skip-hib4>true</skip-hib4>
</properties>
</profile>
<!--
<profile>
<id>DIST</id>
<build>
@ -448,9 +454,13 @@
<target>SCRIPT</target>
<skip>${skip-hib4}</skip>
</configuration>
<!-- This needs to be uncommented in order for this plugin to work with Hibernate 4.3+ (as of hibernate4-maven-plugin version 1.0.5) -->
<dependencies> <dependency> <groupId>org.hibernate</groupId> <artifactId>hibernate-core</artifactId>
<version>${hibernate_version}</version> </dependency> </dependencies>
<dependencies>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>${hibernate_version}</version>
</dependency>
</dependencies>
<executions>
<execution>
<id>o10g</id>
@ -501,6 +511,7 @@
</plugins>
</build>
</profile>
-->
</profiles>
</project>

View File

@ -42,7 +42,7 @@ public class BaseDstu21Config extends BaseConfig {
}
@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();
return retVal;
}
@ -55,7 +55,7 @@ public class BaseDstu21Config extends BaseConfig {
}
@Bean(name = "myJpaValidationSupportDstu21", autowire = Autowire.BY_NAME)
public ca.uhn.fhir.jpa.dao.IJpaValidationSupport jpaValidationSupportDstu2() {
public ca.uhn.fhir.jpa.dao.IJpaValidationSupportDstu21 jpaValidationSupportDstu2() {
ca.uhn.fhir.jpa.dao.JpaValidationSupportDstu21 retVal = new ca.uhn.fhir.jpa.dao.JpaValidationSupportDstu21();
return retVal;
}

View File

@ -56,7 +56,7 @@ public class BaseDstu2Config extends BaseConfig {
}
@Bean(name = "myJpaValidationSupportDstu2", autowire = Autowire.BY_NAME)
public ca.uhn.fhir.jpa.dao.IJpaValidationSupport jpaValidationSupportDstu2() {
public ca.uhn.fhir.jpa.dao.IJpaValidationSupportDstu2 jpaValidationSupportDstu2() {
ca.uhn.fhir.jpa.dao.JpaValidationSupportDstu2 retVal = new ca.uhn.fhir.jpa.dao.JpaValidationSupportDstu2();
return retVal;
}

View File

@ -53,8 +53,15 @@ import org.apache.commons.lang3.NotImplementedException;
import org.apache.commons.lang3.StringUtils;
import org.apache.http.NameValuePair;
import org.apache.http.client.utils.URLEncodedUtils;
import org.hl7.fhir.dstu21.model.IdType;
import org.hl7.fhir.dstu21.model.StringType;
import org.hl7.fhir.dstu21.model.Bundle.HTTPVerb;
import org.hl7.fhir.instance.model.api.IAnyResource;
import org.hl7.fhir.instance.model.api.IBaseCoding;
import org.hl7.fhir.instance.model.api.IBaseOperationOutcome;
import org.hl7.fhir.instance.model.api.IBaseReference;
import org.hl7.fhir.instance.model.api.IBaseResource;
import org.hl7.fhir.instance.model.api.IDomainResource;
import org.hl7.fhir.instance.model.api.IIdType;
import org.hl7.fhir.instance.model.api.IPrimitiveType;
import org.springframework.beans.factory.annotation.Autowired;
@ -108,6 +115,7 @@ import ca.uhn.fhir.model.dstu.resource.BaseResource;
import ca.uhn.fhir.model.primitive.IdDt;
import ca.uhn.fhir.model.primitive.InstantDt;
import ca.uhn.fhir.model.primitive.StringDt;
import ca.uhn.fhir.model.primitive.XhtmlDt;
import ca.uhn.fhir.model.valueset.BundleEntryTransactionMethodEnum;
import ca.uhn.fhir.parser.DataFormatException;
import ca.uhn.fhir.parser.IParser;
@ -167,7 +175,6 @@ public abstract class BaseHapiFhirDao<T extends IBaseResource> implements IDao {
RESOURCE_META_AND_PARAMS = Collections.unmodifiableMap(resourceMetaAndParams);
}
public static final long INDEX_STATUS_INDEXED = Long.valueOf(1L);
public static final long INDEX_STATUS_INDEXING_FAILED = Long.valueOf(2L);
public static final String NS_JPA_PROFILE = "https://github.com/jamesagnew/hapi-fhir/ns/jpa/profile";
@ -225,13 +232,12 @@ public abstract class BaseHapiFhirDao<T extends IBaseResource> implements IDao {
myPlatformTransactionManager = thePlatformTransactionManager;
}
// @Override
// public void setResourceDaos(List<IFhirResourceDao<?>> theResourceDaos) {
// myResourceDaos = theResourceDaos;
// }
// @Override
// public void setResourceDaos(List<IFhirResourceDao<?>> theResourceDaos) {
// myResourceDaos = theResourceDaos;
// }
protected Set<ResourceLink> extractResourceLinks(ResourceTable theEntity, IResource theResource) {
protected Set<ResourceLink> extractResourceLinks(ResourceTable theEntity, IBaseResource theResource) {
Set<ResourceLink> retVal = new HashSet<ResourceLink>();
RuntimeResourceDefinition def = getContext().getResourceDefinition(theResource);
@ -262,31 +268,31 @@ public abstract class BaseHapiFhirDao<T extends IBaseResource> implements IDao {
}
ResourceLink nextEntity;
if (nextObject instanceof BaseResourceReferenceDt) {
BaseResourceReferenceDt nextValue = (BaseResourceReferenceDt) nextObject;
if (nextObject instanceof IBaseReference) {
IBaseReference nextValue = (IBaseReference) nextObject;
if (nextValue.isEmpty()) {
continue;
}
if (nextValue.getReference().isEmpty() || nextValue.getReference().getValue().startsWith("#")) {
if (nextValue.getReferenceElement().isEmpty() || nextValue.getReferenceElement().getValue().startsWith("#")) {
// This is a blank or contained resource reference
continue;
}
String typeString = nextValue.getReference().getResourceType();
String typeString = nextValue.getReferenceElement().getResourceType();
if (isBlank(typeString)) {
throw new InvalidRequestException("Invalid resource reference found at path[" + nextPathsUnsplit + "] - Does not contain resource type - " + nextValue.getReference().getValue());
throw new InvalidRequestException("Invalid resource reference found at path[" + nextPathsUnsplit + "] - Does not contain resource type - " + nextValue.getReferenceElement().getValue());
}
RuntimeResourceDefinition resourceDefinition;
try {
resourceDefinition = getContext().getResourceDefinition(typeString);
} catch (DataFormatException e) {
throw new InvalidRequestException("Invalid resource reference found at path[" + nextPathsUnsplit + "] - Resource type is unknown or not supported on this server - " + nextValue.getReference().getValue());
throw new InvalidRequestException("Invalid resource reference found at path[" + nextPathsUnsplit + "] - Resource type is unknown or not supported on this server - " + nextValue.getReferenceElement().getValue());
}
Class<? extends IBaseResource> type = resourceDefinition.getImplementingClass();
String id = nextValue.getReference().getIdPart();
String id = nextValue.getReferenceElement().getIdPart();
if (StringUtils.isBlank(id)) {
throw new InvalidRequestException("Invalid resource reference found at path[" + nextPathsUnsplit + "] - Does not contain resource ID - " + nextValue.getReference().getValue());
throw new InvalidRequestException("Invalid resource reference found at path[" + nextPathsUnsplit + "] - Does not contain resource ID - " + nextValue.getReferenceElement().getValue());
}
IFhirResourceDao<?> dao = getDao(type);
@ -295,7 +301,7 @@ public abstract class BaseHapiFhirDao<T extends IBaseResource> implements IDao {
b.append("This server (version ");
b.append(myContext.getVersion().getVersion());
b.append(") is not able to handle resources of type[");
b.append(nextValue.getReference().getResourceType());
b.append(nextValue.getReferenceElement().getResourceType());
b.append("] - Valid resource types for this server: ");
b.append(myResourceTypeToDao.keySet().toString());
@ -303,7 +309,7 @@ public abstract class BaseHapiFhirDao<T extends IBaseResource> implements IDao {
}
Long valueOf;
try {
valueOf = translateForcedIdToPid(nextValue.getReference());
valueOf = translateForcedIdToPid(nextValue.getReferenceElement());
} catch (ResourceNotFoundException e) {
String resName = getContext().getResourceDefinition(type).getName();
throw new InvalidRequestException("Resource " + resName + "/" + id + " not found, specified in path: " + nextPathsUnsplit);
@ -316,7 +322,7 @@ public abstract class BaseHapiFhirDao<T extends IBaseResource> implements IDao {
}
if (!typeString.equals(target.getResourceType())) {
throw new UnprocessableEntityException("Resource contains reference to " + nextValue.getReference().getValue() + " but resource with ID " + nextValue.getReference().getIdPart() + " is actually of type " + target.getResourceType());
throw new UnprocessableEntityException("Resource contains reference to " + nextValue.getReferenceElement().getValue() + " but resource with ID " + nextValue.getReferenceElement().getIdPart() + " is actually of type " + target.getResourceType());
}
/*
@ -366,35 +372,35 @@ public abstract class BaseHapiFhirDao<T extends IBaseResource> implements IDao {
return retVal;
}
protected Set<ResourceIndexedSearchParamDate> extractSearchParamDates(ResourceTable theEntity, IResource theResource) {
protected Set<ResourceIndexedSearchParamDate> extractSearchParamDates(ResourceTable theEntity, IBaseResource 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);
}
protected Set<ResourceIndexedSearchParamUri> extractSearchParamUri(ResourceTable theEntity, IResource theResource) {
protected Set<ResourceIndexedSearchParamUri> extractSearchParamUri(ResourceTable theEntity, IBaseResource 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);
}
protected Set<ResourceIndexedSearchParamQuantity> extractSearchParamQuantity(ResourceTable theEntity, IResource theResource) {
protected Set<ResourceIndexedSearchParamQuantity> extractSearchParamQuantity(ResourceTable theEntity, IBaseResource 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);
}
protected Set<BaseResourceIndexedSearchParam> extractSearchParamTokens(ResourceTable theEntity, IResource theResource) {
protected Set<BaseResourceIndexedSearchParam> extractSearchParamTokens(ResourceTable theEntity, IBaseResource 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>();
FhirTerser t = getContext().newTerser();
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;
if (theResourceType != null) {
resourceName = toResourceName(theResourceType);
if (theResourceId != null && theResourceId.hasVersionIdPart()) {
IFhirResourceDao<? extends IResource> dao = getDao(theResourceType);
IFhirResourceDao<? extends IBaseResource> dao = getDao(theResourceType);
BaseHasResource entity = dao.readEntity(theResourceId);
TagList retVal = new TagList();
for (BaseTag next : entity.getTags()) {
@ -622,7 +628,7 @@ public abstract class BaseHapiFhirDao<T extends IBaseResource> implements IDao {
}
throw e;
}
IResource resource = (IResource) toResource(type.getImplementingClass(), next, true);
IBaseResource resource = (IBaseResource) toResource(type.getImplementingClass(), next, true);
retVal.add(resource);
}
return retVal;
@ -656,7 +662,7 @@ public abstract class BaseHapiFhirDao<T extends IBaseResource> implements IDao {
return true;
}
protected void populateResourceIntoEntity(IResource theResource, ResourceTable theEntity) {
protected void populateResourceIntoEntity(IBaseResource theResource, ResourceTable theEntity) {
theEntity.setResourceType(toResourceName(theResource));
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);
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);
if (tagList != null) {
for (Tag next : tagList) {
@ -718,26 +754,38 @@ public abstract class BaseHapiFhirDao<T extends IBaseResource> implements IDao {
theEntity.setHasTags(true);
}
}
}
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);
}
private void extractTagsRi(IAnyResource theResource, ResourceTable theEntity, Set<TagDefinition> allDefs) {
List<? extends IBaseCoding> tagList = theResource.getMeta().getTag();
if (tagList != null) {
for (IBaseCoding next : tagList) {
TagDefinition tag = getTag(TagTypeEnum.TAG, next.getSystem(), next.getCode(), next.getDisplay());
allDefs.add(tag);
theEntity.addTag(tag);
theEntity.setHasTags(true);
}
}
String title = ResourceMetadataKeyEnum.TITLE.get(theResource);
if (title != null && title.length() > BaseHasResource.MAX_TITLE_LENGTH) {
title = title.substring(0, BaseHasResource.MAX_TITLE_LENGTH);
List<? extends IBaseCoding> securityLabels = theResource.getMeta().getSecurity();
if (securityLabels != null) {
for (IBaseCoding next : securityLabels) {
TagDefinition tag = getTag(TagTypeEnum.SECURITY_LABEL, next.getSystem(), next.getCode(), next.getDisplay());
allDefs.add(tag);
theEntity.addTag(tag);
theEntity.setHasTags(true);
}
}
theEntity.setTitle(title);
List<? 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;
}
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);
SearchParameterMap paramMap = translateMatchUrl(theMatchUrl, resourceDef);
@ -1034,23 +1082,23 @@ public abstract class BaseHapiFhirDao<T extends IBaseResource> implements IDao {
}
}
// protected MetaDt toMetaDt(Collection<TagDefinition> tagDefinitions) {
// MetaDt retVal = new MetaDt();
// for (TagDefinition next : tagDefinitions) {
// switch (next.getTagType()) {
// case PROFILE:
// retVal.addProfile(next.getCode());
// break;
// case SECURITY_LABEL:
// retVal.addSecurity().setSystem(next.getSystem()).setCode(next.getCode()).setDisplay(next.getDisplay());
// break;
// case TAG:
// retVal.addTag().setSystem(next.getSystem()).setCode(next.getCode()).setDisplay(next.getDisplay());
// break;
// }
// }
// return retVal;
// }
// protected MetaDt toMetaDt(Collection<TagDefinition> tagDefinitions) {
// MetaDt retVal = new MetaDt();
// for (TagDefinition next : tagDefinitions) {
// switch (next.getTagType()) {
// case PROFILE:
// retVal.addProfile(next.getCode());
// break;
// case SECURITY_LABEL:
// retVal.addSecurity().setSystem(next.getSystem()).setCode(next.getCode()).setDisplay(next.getDisplay());
// break;
// case TAG:
// retVal.addTag().setSystem(next.getSystem()).setCode(next.getCode()).setDisplay(next.getDisplay());
// break;
// }
// }
// return retVal;
// }
@Autowired
public void setContext(FhirContext theContext) {
@ -1066,7 +1114,6 @@ public abstract class BaseHapiFhirDao<T extends IBaseResource> implements IDao {
mySearchParamExtractor = new SearchParamExtractorDstu21(theContext);
break;
case DSTU2_HL7ORG:
case DEV:
throw new IllegalStateException("Don't know how to handle version: " + myContext.getVersion().getVersion());
}
}
@ -1079,13 +1126,15 @@ public abstract class BaseHapiFhirDao<T extends IBaseResource> implements IDao {
return retVal;
}
protected IBaseResource toResource(BaseHasResource theEntity, boolean theForHistoryOperation) {
@Override
public IBaseResource toResource(BaseHasResource theEntity, boolean theForHistoryOperation) {
RuntimeResourceDefinition type = myContext.getResourceDefinition(theEntity.getResourceType());
return toResource(type.getImplementingClass(), theEntity, theForHistoryOperation);
}
@Override
@SuppressWarnings("unchecked")
protected <R extends IBaseResource> R toResource(Class<R> theResourceType, BaseHasResource theEntity, boolean theForHistoryOperation) {
public <R extends IBaseResource> R toResource(Class<R> theResourceType, BaseHasResource theEntity, boolean theForHistoryOperation) {
String resourceText = null;
switch (theEntity.getEncoding()) {
case JSON:
@ -1121,7 +1170,18 @@ public abstract class BaseHapiFhirDao<T extends IBaseResource> implements IDao {
throw new DataFormatException(msg, e);
}
IResource res = (IResource) retVal;
if (retVal instanceof IResource) {
IResource res = (IResource) retVal;
retVal = populateResourceMetadataHapi(theResourceType, theEntity, theForHistoryOperation, res);
} else {
IAnyResource res = (IAnyResource) retVal;
retVal = populateResourceMetadataRi(theResourceType, theEntity, theForHistoryOperation, res);
}
return retVal;
}
private <R extends IBaseResource> R populateResourceMetadataHapi(Class<R> theResourceType, BaseHasResource theEntity, boolean theForHistoryOperation, IResource res) {
R retVal = (R) res;
if (theEntity.getDeleted() != null) {
res = (IResource) myContext.getResourceDefinition(theResourceType).newInstance();
retVal = (R) res;
@ -1157,7 +1217,7 @@ public abstract class BaseHapiFhirDao<T extends IBaseResource> implements IDao {
Collection<? extends BaseTag> tags = theEntity.getTags();
if (theEntity.isHasTags()) {
TagList tagList = new TagList();
List<BaseCodingDt> securityLabels = new ArrayList<BaseCodingDt>();
List<IBaseCoding> securityLabels = new ArrayList<IBaseCoding>();
List<IdDt> profiles = new ArrayList<IdDt>();
for (BaseTag next : tags) {
switch (next.getTag().getTagType()) {
@ -1165,7 +1225,7 @@ public abstract class BaseHapiFhirDao<T extends IBaseResource> implements IDao {
profiles.add(new IdDt(next.getTag().getCode()));
break;
case SECURITY_LABEL:
BaseCodingDt secLabel = myContext.getVersion().newCodingDt();
IBaseCoding secLabel = (IBaseCoding) myContext.getVersion().newCodingDt();
secLabel.setSystem(next.getTag().getSystem());
secLabel.setCode(next.getTag().getCode());
secLabel.setDisplay(next.getTag().getDisplay());
@ -1180,21 +1240,88 @@ public abstract class BaseHapiFhirDao<T extends IBaseResource> implements IDao {
ResourceMetadataKeyEnum.TAG_LIST.put(res, tagList);
}
if (securityLabels.size() > 0) {
ResourceMetadataKeyEnum.SECURITY_LABELS.put(res, securityLabels);
ResourceMetadataKeyEnum.SECURITY_LABELS.put(res, toBaseCodingList(securityLabels));
}
if (profiles.size() > 0) {
ResourceMetadataKeyEnum.PROFILES.put(res, profiles);
}
}
return retVal;
}
protected String toResourceName(Class<? 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();
}
protected String toResourceName(IResource theResource) {
protected String toResourceName(IBaseResource theResource) {
return myContext.getResourceDefinition(theResource).getName();
}
@ -1236,7 +1363,7 @@ public abstract class BaseHapiFhirDao<T extends IBaseResource> implements IDao {
}
@SuppressWarnings("unchecked")
protected ResourceTable updateEntity(final IResource theResource, ResourceTable theEntity, boolean theUpdateHistory, Date theDeletedTimestampOrNull, boolean thePerformIndexing, boolean theUpdateVersion, Date theUpdateTime) {
protected ResourceTable updateEntity(final IBaseResource theResource, ResourceTable theEntity, boolean theUpdateHistory, Date theDeletedTimestampOrNull, boolean thePerformIndexing, boolean theUpdateVersion, Date theUpdateTime) {
/*
* This should be the very first thing..
@ -1348,22 +1475,26 @@ public abstract class BaseHapiFhirDao<T extends IBaseResource> implements IDao {
links = extractResourceLinks(theEntity, theResource);
/*
* If the existing resource already has links and those match links we still want,
* use them instead of removing them and re adding them
/*
* If the existing resource already has links and those match links we still want, use them instead of
* removing them and re adding them
*/
for (Iterator<ResourceLink> existingLinkIter = existingResourceLinks.iterator(); existingLinkIter.hasNext(); ) {
for (Iterator<ResourceLink> existingLinkIter = existingResourceLinks.iterator(); existingLinkIter.hasNext();) {
ResourceLink nextExisting = existingLinkIter.next();
if (links.remove(nextExisting)) {
existingLinkIter.remove();
links.add(nextExisting);
}
}
populateResourceIntoEntity(theResource, theEntity);
theEntity.setUpdated(theUpdateTime);
theEntity.setLanguage(theResource.getLanguage().getValue());
if (theResource instanceof IResource) {
theEntity.setLanguage(((IResource) theResource).getLanguage().getValue());
} else {
theEntity.setLanguage(((IAnyResource) theResource).getLanguageElement().getValue());
}
theEntity.setParamsString(stringParams);
theEntity.setParamsStringPopulated(stringParams.isEmpty() == false);
theEntity.setParamsToken(tokenParams);
@ -1388,13 +1519,13 @@ public abstract class BaseHapiFhirDao<T extends IBaseResource> implements IDao {
populateResourceIntoEntity(theResource, theEntity);
theEntity.setUpdated(theUpdateTime);
theEntity.setLanguage(theResource.getLanguage().getValue());
// theEntity.setLanguage(theResource.getLanguage().getValue());
theEntity.setIndexStatus(null);
}
}
if (theEntity.getId() == null) {
myEntityManager.persist(theEntity);
@ -1479,12 +1610,20 @@ public abstract class BaseHapiFhirDao<T extends IBaseResource> implements IDao {
myEntityManager.flush();
if (theResource != null) {
theResource.setId(theEntity.getIdDt());
populateResourceId(theResource, theEntity);
}
return theEntity;
}
private void populateResourceId(final IBaseResource theResource, BaseHasResource theEntity) {
IIdType id = theEntity.getIdDt();
if (getContext().getVersion().getVersion().isRi()) {
id = new IdType(id.getValue());
}
theResource.setId(id);
}
/**
* Subclasses may override to provide behaviour. Called when a resource has been inserved into the database for the
* first time.
@ -1522,13 +1661,20 @@ public abstract class BaseHapiFhirDao<T extends IBaseResource> implements IDao {
* TODO
*/
protected void validateResourceForStorage(T theResource, ResourceTable theEntityToSave) {
IResource res = (IResource) theResource;
TagList tagList = ResourceMetadataKeyEnum.TAG_LIST.get(res);
if (tagList != null) {
Tag tag = tagList.getTag(Constants.TAG_SUBSETTED_SYSTEM, Constants.TAG_SUBSETTED_CODE);
if (tag != null) {
throw new UnprocessableEntityException("Resource contains the 'subsetted' tag, and must not be stored as it may contain a subset of available data");
Object tag = null;
if (theResource instanceof IResource) {
IResource res = (IResource) theResource;
TagList tagList = ResourceMetadataKeyEnum.TAG_LIST.get(res);
if (tagList != null) {
tag = tagList.getTag(Constants.TAG_SUBSETTED_SYSTEM, Constants.TAG_SUBSETTED_CODE);
}
} else {
IAnyResource res = (IAnyResource)theResource;
tag = res.getMeta().getTag(Constants.TAG_SUBSETTED_SYSTEM, Constants.TAG_SUBSETTED_CODE);
}
if (tag != null) {
throw new UnprocessableEntityException("Resource contains the 'subsetted' tag, and must not be stored as it may contain a subset of available data");
}
}
@ -1545,26 +1691,49 @@ public abstract class BaseHapiFhirDao<T extends IBaseResource> implements IDao {
return new String(out).toUpperCase();
}
private static String parseNarrativeTextIntoWords(IResource theResource) {
private static String parseNarrativeTextIntoWords(IBaseResource theResource) {
StringBuilder b = new StringBuilder();
List<XMLEvent> xmlEvents = theResource.getText().getDiv().getValue();
if (xmlEvents != null) {
for (XMLEvent next : xmlEvents) {
if (next.isCharacters()) {
Characters characters = next.asCharacters();
b.append(characters.getData()).append(" ");
if (theResource instanceof IResource) {
IResource resource = (IResource) theResource;
List<XMLEvent> xmlEvents = resource.getText().getDiv().getValue();
if (xmlEvents != null) {
for (XMLEvent next : xmlEvents) {
if (next.isCharacters()) {
Characters characters = next.asCharacters();
b.append(characters.getData()).append(" ");
}
}
}
} else if (theResource instanceof IDomainResource) {
IDomainResource resource = (IDomainResource) theResource;
try {
String divAsString = resource.getText().getDivAsString();
XhtmlDt xhtml = new XhtmlDt(divAsString);
List<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();
}
private String parseContentTextIntoWords(IResource theResource) {
StringBuilder retVal = new StringBuilder();
private String parseContentTextIntoWords(IBaseResource theResource) {
StringBuilder retVal = new StringBuilder();
@SuppressWarnings("rawtypes")
List<IPrimitiveType> childElements = getContext().newTerser().getAllPopulatedChildElementsOfType(theResource, IPrimitiveType.class);
for (@SuppressWarnings("rawtypes") IPrimitiveType nextType : childElements) {
if (nextType instanceof StringDt) {
for (@SuppressWarnings("rawtypes")
IPrimitiveType nextType : childElements) {
if (nextType instanceof StringDt || nextType.getClass().equals(StringType.class)) {
String nextValue = nextType.getValueAsString();
if (isNotBlank(nextValue)) {
retVal.append(nextValue.replace("\n", " ").replace("\r", " "));
@ -1582,10 +1751,11 @@ public abstract class BaseHapiFhirDao<T extends IBaseResource> implements IDao {
IBaseOperationOutcome oo = OperationOutcomeUtil.newInstance(getContext());
for (DeleteConflict next : theDeleteConflicts) {
String msg = "Unable to delete " + next.getTargetId().toUnqualifiedVersionless().getValue() + " because at least one resource has a reference to this resource. First reference found was resource " + next.getTargetId().toUnqualifiedVersionless().getValue() + " in path " + next.getSourcePath();
String msg = "Unable to delete " + next.getTargetId().toUnqualifiedVersionless().getValue() + " because at least one resource has a reference to this resource. First reference found was resource " + next.getTargetId().toUnqualifiedVersionless().getValue() + " in path "
+ next.getSourcePath();
OperationOutcomeUtil.addIssue(getContext(), oo, OO_SEVERITY_ERROR, msg, null, "processing");
}
throw new ResourceVersionConflictException("Delete failed because of constraint failure", oo);
}

View File

@ -33,13 +33,12 @@ import java.util.Map.Entry;
import java.util.Set;
import javax.annotation.PostConstruct;
import javax.persistence.EntityManager;
import javax.persistence.NoResultException;
import javax.persistence.PersistenceContext;
import javax.persistence.PersistenceContextType;
import javax.persistence.TemporalType;
import javax.persistence.TypedQuery;
import org.hl7.fhir.dstu21.model.IdType;
import org.hl7.fhir.instance.model.api.IAnyResource;
import org.hl7.fhir.instance.model.api.IBaseCoding;
import org.hl7.fhir.instance.model.api.IBaseMetaType;
import org.hl7.fhir.instance.model.api.IBaseOperationOutcome;
@ -90,16 +89,13 @@ import ca.uhn.fhir.util.FhirTerser;
import ca.uhn.fhir.util.ObjectUtil;
@Transactional(propagation = Propagation.REQUIRED)
public abstract class BaseHapiFhirResourceDao<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);
@Autowired
private DaoConfig myDaoConfig;
@PersistenceContext(type = PersistenceContextType.TRANSACTION)
protected EntityManager myEntityManager;
@Autowired
protected PlatformTransactionManager myPlatformTransactionManager;
@ -154,14 +150,14 @@ public abstract class BaseHapiFhirResourceDao<T extends IResource> extends BaseH
@Override
public DaoMethodOutcome create(T theResource, String theIfNoneExist, boolean thePerformIndexing) {
if (isNotBlank(theResource.getId().getIdPart())) {
if (isNotBlank(theResource.getIdElement().getIdPart())) {
if (getContext().getVersion().getVersion().equals(FhirVersionEnum.DSTU1)) {
if (theResource.getId().isIdPartValidLong()) {
String message = getContext().getLocalizer().getMessage(BaseHapiFhirResourceDao.class, "failedToCreateWithClientAssignedNumericId", theResource.getId().getIdPart());
if (theResource.getIdElement().isIdPartValidLong()) {
String message = getContext().getLocalizer().getMessage(BaseHapiFhirResourceDao.class, "failedToCreateWithClientAssignedNumericId", theResource.getIdElement().getIdPart());
throw new InvalidRequestException(message, createErrorOperationOutcome(message));
}
} else {
String message = getContext().getLocalizer().getMessage(BaseHapiFhirResourceDao.class, "failedToCreateWithClientAssignedId", theResource.getId().getIdPart());
String message = getContext().getLocalizer().getMessage(BaseHapiFhirResourceDao.class, "failedToCreateWithClientAssignedId", theResource.getIdElement().getIdPart());
throw new InvalidRequestException(message, createErrorOperationOutcome(message));
}
}
@ -183,11 +179,11 @@ public abstract class BaseHapiFhirResourceDao<T extends IResource> extends BaseH
public DaoMethodOutcome delete(IIdType theId) {
List<DeleteConflict> deleteConflicts = new ArrayList<DeleteConflict>();
StopWatch w = new StopWatch();
ResourceTable savedEntity = delete(theId, deleteConflicts);
validateDeleteConflictsEmptyOrThrowException(deleteConflicts);
ourLog.info("Processed delete on {} in {}ms", theId.getValue(), w.getMillisAndRestart());
return toMethodOutcome(savedEntity, null);
}
@ -226,9 +222,9 @@ public abstract class BaseHapiFhirResourceDao<T extends IResource> extends BaseH
List<DeleteConflict> deleteConflicts = new ArrayList<DeleteConflict>();
List<ResourceTable> deletedResources = deleteByUrl(theUrl, deleteConflicts);
validateDeleteConflictsEmptyOrThrowException(deleteConflicts);
if (deletedResources.isEmpty()) {
throw new ResourceNotFoundException(getContext().getLocalizer().getMessage(BaseHapiFhirResourceDao.class, "unableToDeleteNotFound", theUrl));
}
@ -250,7 +246,7 @@ public abstract class BaseHapiFhirResourceDao<T extends IResource> extends BaseH
for (Long pid : resource) {
ResourceTable entity = myEntityManager.find(ResourceTable.class, pid);
retVal.add(entity);
validateOkToDelete(deleteConflicts, entity);
// Notify interceptors
@ -270,7 +266,7 @@ public abstract class BaseHapiFhirResourceDao<T extends IResource> extends BaseH
}
}
return retVal;
}
@ -294,16 +290,16 @@ public abstract class BaseHapiFhirResourceDao<T extends IResource> extends BaseH
}
}
if (isNotBlank(theResource.getId().getIdPart())) {
if (isValidPid(theResource.getId())) {
if (isNotBlank(theResource.getIdElement().getIdPart())) {
if (isValidPid(theResource.getIdElement())) {
throw new UnprocessableEntityException("This server cannot create an entity with a user-specified numeric ID - Client should not specify an ID when creating a new resource, or should include at least one letter in the ID to force a client-defined ID");
}
createForcedIdIfNeeded(entity, theResource.getId());
createForcedIdIfNeeded(entity, theResource.getIdElement());
if (entity.getForcedId() != null) {
try {
translateForcedIdToPid(theResource.getId());
throw new UnprocessableEntityException(getContext().getLocalizer().getMessage(BaseHapiFhirResourceDao.class, "duplicateCreateForcedId", theResource.getId().getIdPart()));
translateForcedIdToPid(theResource.getIdElement());
throw new UnprocessableEntityException(getContext().getLocalizer().getMessage(BaseHapiFhirResourceDao.class, "duplicateCreateForcedId", theResource.getIdElement().getIdPart()));
} catch (ResourceNotFoundException e) {
// good, this ID doesn't exist so we can create it
}
@ -312,7 +308,7 @@ public abstract class BaseHapiFhirResourceDao<T extends IResource> extends BaseH
}
// Notify interceptors
ActionRequestDetails requestDetails = new ActionRequestDetails(theResource.getId(), toResourceName(theResource), theResource);
ActionRequestDetails requestDetails = new ActionRequestDetails(theResource.getIdElement(), toResourceName(theResource), theResource);
notifyInterceptors(RestOperationTypeEnum.CREATE, requestDetails);
// Perform actual DB update
@ -395,7 +391,13 @@ public abstract class BaseHapiFhirResourceDao<T extends IResource> extends BaseH
BaseHasResource entity = readEntity(theId.toVersionless(), false);
validateResourceType(entity);
currentTmp = toResource(myResourceType, entity, true);
if (ResourceMetadataKeyEnum.UPDATED.get(currentTmp).after(end.getValue())) {
Date lastUpdated;
if (currentTmp instanceof IResource) {
lastUpdated = ResourceMetadataKeyEnum.UPDATED.get((IResource) currentTmp).getValue();
} else {
lastUpdated = ((IAnyResource) currentTmp).getMeta().getLastUpdated();
}
if (lastUpdated.after(end.getValue())) {
currentTmp = null;
}
} catch (ResourceNotFoundException e) {
@ -666,7 +668,7 @@ public abstract class BaseHapiFhirResourceDao<T extends IResource> extends BaseH
ourLog.info("Processed metaDeleteOperation on {} in {}ms", new Object[] { theResourceId.getValue(), w.getMillisAndRestart() });
@SuppressWarnings("unchecked")
MT retVal = (MT)metaGetOperation(theMetaDel.getClass(), theResourceId);
MT retVal = (MT) metaGetOperation(theMetaDel.getClass(), theResourceId);
return retVal;
}
@ -685,7 +687,7 @@ public abstract class BaseHapiFhirResourceDao<T extends IResource> extends BaseH
return retVal;
}
protected <MT extends IBaseMetaType> MT toMetaDt(Class<MT> theType, Collection<TagDefinition> tagDefinitions) {
MT retVal;
try {
@ -752,9 +754,9 @@ public abstract class BaseHapiFhirResourceDao<T extends IResource> extends BaseH
* The resource that is about to be stored
*/
protected void preProcessResourceForStorage(T theResource) {
if (theResource.getId().hasIdPart()) {
if (!theResource.getId().isIdPartValid()) {
throw new InvalidRequestException(getContext().getLocalizer().getMessage(BaseHapiFhirResourceDao.class, "failedToCreateWithInvalidId", theResource.getId().getIdPart()));
if (theResource.getIdElement().hasIdPart()) {
if (!theResource.getIdElement().isIdPartValid()) {
throw new InvalidRequestException(getContext().getLocalizer().getMessage(BaseHapiFhirResourceDao.class, "failedToCreateWithInvalidId", theResource.getIdElement().getIdPart()));
}
}
}
@ -779,7 +781,12 @@ public abstract class BaseHapiFhirResourceDao<T extends IResource> extends BaseH
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()) {
throw new ResourceGoneException("Resource was deleted at " + deleted.getValueAsString());
}
@ -893,7 +900,7 @@ public abstract class BaseHapiFhirResourceDao<T extends IResource> extends BaseH
}
return search(map);
}
@Override
public IBundleProvider search(final SearchParameterMap theParams) {
// Notify interceptors
@ -933,7 +940,7 @@ public abstract class BaseHapiFhirResourceDao<T extends IResource> extends BaseH
@SuppressWarnings("unchecked")
@Required
public void setResourceType(Class<? extends IResource> theTableType) {
public void setResourceType(Class<? extends IBaseResource> theTableType) {
myResourceType = (Class<T>) theTableType;
}
@ -945,18 +952,29 @@ public abstract class BaseHapiFhirResourceDao<T extends IResource> extends BaseH
mySecondaryPrimaryKeyParamName = theSecondaryPrimaryKeyParamName;
}
private DaoMethodOutcome toMethodOutcome(final BaseHasResource theEntity, IResource theResource) {
private DaoMethodOutcome toMethodOutcome(final BaseHasResource theEntity, IBaseResource theResource) {
DaoMethodOutcome outcome = new DaoMethodOutcome();
outcome.setId(theEntity.getIdDt());
IIdType id = theEntity.getIdDt();
if (getContext().getVersion().getVersion().isRi()) {
id = new IdType(id.getValue());
}
outcome.setId(id);
outcome.setResource(theResource);
if (theResource != null) {
theResource.setId(theEntity.getIdDt());
ResourceMetadataKeyEnum.UPDATED.put(theResource, theEntity.getUpdated());
theResource.setId(id);
if (theResource instanceof IResource) {
ResourceMetadataKeyEnum.UPDATED.put((IResource) theResource, theEntity.getUpdated());
} else {
IBaseMetaType meta = ((IAnyResource) theResource).getMeta();
meta.setLastUpdated(theEntity.getUpdatedDate());
}
}
return outcome;
}
private DaoMethodOutcome toMethodOutcome(final ResourceTable theEntity, IResource theResource) {
private DaoMethodOutcome toMethodOutcome(final ResourceTable theEntity, IBaseResource theResource) {
DaoMethodOutcome retVal = toMethodOutcome((BaseHasResource) theEntity, theResource);
retVal.setEntity(theEntity);
return retVal;
@ -978,9 +996,6 @@ public abstract class BaseHapiFhirResourceDao<T extends IResource> extends BaseH
return retVal;
}
@Override
public DaoMethodOutcome update(T theResource) {
return update(theResource, null);
@ -1013,7 +1028,7 @@ public abstract class BaseHapiFhirResourceDao<T extends IResource> extends BaseH
return create(theResource, null, thePerformIndexing);
}
} else {
resourceId = theResource.getId();
resourceId = theResource.getIdElement();
if (resourceId == null || isBlank(resourceId.getIdPart())) {
throw new InvalidRequestException("Can not update a resource with no ID");
}
@ -1021,7 +1036,7 @@ public abstract class BaseHapiFhirResourceDao<T extends IResource> extends BaseH
entity = readEntityLatestVersion(resourceId);
} catch (ResourceNotFoundException e) {
if (resourceId.isIdPartValidLong()) {
throw new InvalidRequestException(getContext().getLocalizer().getMessage(BaseHapiFhirResourceDao.class, "failedToCreateWithClientAssignedNumericId", theResource.getId().getIdPart()));
throw new InvalidRequestException(getContext().getLocalizer().getMessage(BaseHapiFhirResourceDao.class, "failedToCreateWithClientAssignedNumericId", theResource.getIdElement().getIdPart()));
}
return doCreate(theResource, null, thePerformIndexing, new Date());
}
@ -1087,8 +1102,6 @@ public abstract class BaseHapiFhirResourceDao<T extends IResource> extends BaseH
theDeleteConflicts.add(new DeleteConflict(sourceId, sourcePath, targetId));
}
private void validateResourceType(BaseHasResource entity) {
validateResourceType(entity, myResourceName);
}

View File

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

View File

@ -1,5 +1,9 @@
package ca.uhn.fhir.jpa.dao;
import org.hl7.fhir.dstu21.model.Bundle;
import org.hl7.fhir.dstu21.model.Bundle.BundleEntryComponent;
import org.hl7.fhir.dstu21.model.Bundle.BundleType;
/*
* #%L
* HAPI FHIR JPA Server
@ -20,9 +24,6 @@ package ca.uhn.fhir.jpa.dao;
* #L%
*/
import ca.uhn.fhir.model.dstu21.resource.Bundle;
import ca.uhn.fhir.model.dstu21.resource.Bundle.Entry;
import ca.uhn.fhir.model.dstu21.valueset.BundleTypeEnum;
import ca.uhn.fhir.rest.server.exceptions.UnprocessableEntityException;
public class FhirResourceDaoBundleDstu21 extends FhirResourceDaoDstu21<Bundle> {
@ -31,12 +32,12 @@ public class FhirResourceDaoBundleDstu21 extends FhirResourceDaoDstu21<Bundle> {
protected void preProcessResourceForStorage(Bundle theResource) {
super.preProcessResourceForStorage(theResource);
if (theResource.getTypeElement().getValueAsEnum() != BundleTypeEnum.DOCUMENT) {
String message = "Unable to store a Bundle resource on this server with a Bundle.type value other than '" + BundleTypeEnum.DOCUMENT.getCode() + "' - Value was: " + (theResource.getTypeElement().getValueAsEnum() != null ? theResource.getTypeElement().getValueAsEnum().getCode() : "(missing)");
if (theResource.getType() != BundleType.DOCUMENT) {
String message = "Unable to store a Bundle resource on this server with a Bundle.type value other than '" + BundleType.DOCUMENT.toCode() + "' - Value was: " + (theResource.getType() != null ? theResource.getType().toCode() : "(missing)");
throw new UnprocessableEntityException(message);
}
for (Entry next : theResource.getEntry()) {
for (BundleEntryComponent next : theResource.getEntry()) {
next.setFullUrl((String)null);
}
}

View File

@ -1,11 +1,37 @@
package ca.uhn.fhir.jpa.dao;
/*
* #%L
* HAPI FHIR JPA Server
* %%
* Copyright (C) 2014 - 2015 University Health Network
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* #L%
*/
import static org.apache.commons.lang3.StringUtils.isNotBlank;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.hl7.fhir.dstu21.hapi.validation.IValidationSupport;
import org.hl7.fhir.dstu21.model.IdType;
import org.hl7.fhir.dstu21.model.OperationOutcome;
import org.hl7.fhir.dstu21.model.OperationOutcome.IssueSeverity;
import org.hl7.fhir.dstu21.model.OperationOutcome.OperationOutcomeIssueComponent;
import org.hl7.fhir.instance.model.api.IAnyResource;
import org.hl7.fhir.instance.model.api.IBaseOperationOutcome;
import org.hl7.fhir.instance.model.api.IBaseResource;
import org.hl7.fhir.instance.model.api.IIdType;
@ -21,9 +47,6 @@ import ca.uhn.fhir.model.api.Bundle;
import ca.uhn.fhir.model.api.IResource;
import ca.uhn.fhir.model.api.Include;
import ca.uhn.fhir.model.base.composite.BaseResourceReferenceDt;
import ca.uhn.fhir.model.dstu21.resource.OperationOutcome;
import ca.uhn.fhir.model.dstu21.valueset.IssueSeverityEnum;
import ca.uhn.fhir.model.primitive.IdDt;
import ca.uhn.fhir.rest.api.MethodOutcome;
import ca.uhn.fhir.rest.api.RestOperationTypeEnum;
import ca.uhn.fhir.rest.api.ValidationModeEnum;
@ -36,13 +59,12 @@ import ca.uhn.fhir.validation.DefaultProfileValidationSupport;
import ca.uhn.fhir.validation.FhirInstanceValidator;
import ca.uhn.fhir.validation.FhirValidator;
import ca.uhn.fhir.validation.IValidationContext;
import ca.uhn.fhir.validation.IValidationSupport;
import ca.uhn.fhir.validation.IValidatorModule;
import ca.uhn.fhir.validation.ValidationResult;
import ca.uhn.fhir.validation.ValidationSupportChain;
import net.sourceforge.cobertura.CoverageIgnore;
public class FhirResourceDaoDstu21<T extends IResource> extends BaseHapiFhirResourceDao<T> {
public class FhirResourceDaoDstu21<T extends IAnyResource> extends BaseHapiFhirResourceDao<T> {
@Autowired()
@Qualifier("myJpaValidationSupportDstu21")
@ -70,8 +92,9 @@ public class FhirResourceDaoDstu21<T extends IResource> extends BaseHapiFhirReso
@Override
protected IBaseOperationOutcome createOperationOutcome(String theSeverity, String theMessage) {
OperationOutcome oo = new OperationOutcome();
oo.getIssueFirstRep().getSeverityElement().setValue(theSeverity);
oo.getIssueFirstRep().getDiagnosticsElement().setValue(theMessage);
OperationOutcomeIssueComponent issue = oo.addIssue();
issue.getSeverityElement().setValueAsString(theSeverity);
issue.setDiagnostics(theMessage);
return oo;
}
@ -93,15 +116,15 @@ public class FhirResourceDaoDstu21<T extends IResource> extends BaseHapiFhirReso
validateDeleteConflictsEmptyOrThrowException(deleteConflicts);
OperationOutcome oo = new OperationOutcome();
oo.addIssue().setSeverity(IssueSeverityEnum.INFORMATION).setDiagnostics("Ok to delete");
return new MethodOutcome(new IdDt(theId.getValue()), oo);
oo.addIssue().setSeverity(IssueSeverity.INFORMATION).setDiagnostics("Ok to delete");
return new MethodOutcome(new IdType(theId.getValue()), oo);
}
FhirValidator validator = getContext().newValidator();
FhirInstanceValidator val = new FhirInstanceValidator();
val.setBestPracticeWarningLevel(BestPracticeWarningLevel.Warning);
val.setValidationSupport(new ValidationSupportChain(new DefaultProfileValidationSupport(), myJpaValidationSupport));
// val.setValidationSupport(new ValidationSupportChain(new DefaultProfileValidationSupport(), myJpaValidationSupport));
validator.registerValidatorModule(val);
validator.registerValidatorModule(new IdChecker(theMode));

View File

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

View File

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

View File

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

View File

@ -24,12 +24,12 @@ import java.util.Collections;
import javax.servlet.http.HttpServletRequest;
import org.hl7.fhir.dstu21.model.Patient;
import org.hl7.fhir.instance.model.api.IIdType;
import org.hl7.fhir.instance.model.api.IPrimitiveType;
import ca.uhn.fhir.jpa.dao.SearchParameterMap.EverythingModeEnum;
import ca.uhn.fhir.model.api.IResource;
import ca.uhn.fhir.model.dstu21.resource.Patient;
import ca.uhn.fhir.model.primitive.UnsignedIntDt;
import ca.uhn.fhir.rest.api.RestOperationTypeEnum;
import ca.uhn.fhir.rest.api.SortSpec;
import ca.uhn.fhir.rest.param.DateRangeParam;
@ -41,7 +41,7 @@ import ca.uhn.fhir.rest.server.interceptor.IServerInterceptor.ActionRequestDetai
public class FhirResourceDaoPatientDstu21 extends 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();
if (theCount != null) {
paramMap.setCount(theCount.getValue());
@ -66,7 +66,7 @@ public class FhirResourceDaoPatientDstu21 extends FhirResourceDaoDstu21<Patient>
}
@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
ActionRequestDetails requestDetails = new ActionRequestDetails(null, getResourceName());
notifyInterceptors(RestOperationTypeEnum.EXTENDED_OPERATION_INSTANCE, requestDetails);
@ -75,7 +75,7 @@ public class FhirResourceDaoPatientDstu21 extends FhirResourceDaoDstu21<Patient>
}
@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
ActionRequestDetails requestDetails = new ActionRequestDetails(null, getResourceName());
notifyInterceptors(RestOperationTypeEnum.EXTENDED_OPERATION_TYPE, requestDetails);

View File

@ -22,6 +22,10 @@ package ca.uhn.fhir.jpa.dao;
import javax.annotation.PostConstruct;
import org.hl7.fhir.dstu21.model.OperationOutcome;
import org.hl7.fhir.dstu21.model.Questionnaire;
import org.hl7.fhir.dstu21.model.QuestionnaireResponse;
import org.hl7.fhir.dstu21.model.ValueSet;
import org.hl7.fhir.instance.model.api.IBaseOperationOutcome;
import org.hl7.fhir.instance.model.api.IBaseResource;
import org.hl7.fhir.instance.model.api.IIdType;
@ -30,10 +34,6 @@ import org.springframework.beans.factory.annotation.Qualifier;
import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.jpa.entity.ResourceTable;
import ca.uhn.fhir.model.dstu21.resource.OperationOutcome;
import ca.uhn.fhir.model.dstu21.resource.Questionnaire;
import ca.uhn.fhir.model.dstu21.resource.QuestionnaireResponse;
import ca.uhn.fhir.model.dstu21.resource.ValueSet;
import ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException;
import ca.uhn.fhir.rest.server.exceptions.UnprocessableEntityException;
import ca.uhn.fhir.validation.FhirQuestionnaireResponseValidator;

View File

@ -21,17 +21,16 @@ package ca.uhn.fhir.jpa.dao;
*/
import org.apache.commons.lang3.time.DateUtils;
import org.hl7.fhir.dstu21.model.Bundle;
import org.hl7.fhir.dstu21.model.Meta;
import org.hl7.fhir.dstu21.model.SearchParameter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import ca.uhn.fhir.model.dstu21.composite.MetaDt;
import ca.uhn.fhir.model.dstu21.resource.Bundle;
import ca.uhn.fhir.model.dstu21.resource.SearchParameter;
public class FhirResourceDaoSearchParameterDstu21 extends FhirResourceDaoDstu21<SearchParameter>implements IFhirResourceDaoSearchParameter<SearchParameter> {
@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

View File

@ -258,7 +258,7 @@ public class FhirResourceDaoSubscriptionDstu2 extends FhirResourceDaoDstu2<Subsc
}
@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) {
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 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.IIdType;
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.SubscriptionFlaggedResource;
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.dstu21.resource.Subscription;
import ca.uhn.fhir.model.dstu21.valueset.SubscriptionStatusEnum;
import ca.uhn.fhir.model.dstu2.valueset.SubscriptionStatusEnum;
import ca.uhn.fhir.model.primitive.IdDt;
import ca.uhn.fhir.model.primitive.InstantDt;
import ca.uhn.fhir.parser.DataFormatException;
@ -85,7 +85,7 @@ public class FhirResourceDaoSubscriptionDstu21 extends FhirResourceDaoDstu21<Sub
subscriptionEntity.setSubscriptionResource(theEntity);
subscriptionEntity.setNextCheck(theEntity.getPublished().getValue());
subscriptionEntity.setMostRecentMatch(theEntity.getPublished().getValue());
subscriptionEntity.setStatus(theSubscription.getStatusElement().getValue());
subscriptionEntity.setStatus(theSubscription.getStatusElement().getValueAsString());
myEntityManager.persist(subscriptionEntity);
}
@ -157,7 +157,7 @@ public class FhirResourceDaoSubscriptionDstu21 extends FhirResourceDaoDstu21<Sub
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();
range.setLowerBound(new DateParam(QuantityCompararatorEnum.GREATERTHAN, start));
@ -170,13 +170,14 @@ public class FhirResourceDaoSubscriptionDstu21 extends FhirResourceDaoDstu21<Sub
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>();
Date mostRecentMatch = null;
for (IBaseResource next : results.getResources(0, results.size())) {
for (IBaseResource nextBase : results.getResources(0, results.size())) {
IAnyResource next = (IAnyResource)nextBase;
Date updated = ResourceMetadataKeyEnum.UPDATED.get((IResource) next).getValue();
Date updated = next.getMeta().getLastUpdated();
if (mostRecentMatch == null) {
mostRecentMatch = updated;
} else {
@ -188,7 +189,7 @@ public class FhirResourceDaoSubscriptionDstu21 extends FhirResourceDaoDstu21<Sub
}
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);
@ -200,7 +201,7 @@ public class FhirResourceDaoSubscriptionDstu21 extends FhirResourceDaoDstu21<Sub
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);
mySubscriptionTableDao.save(theSubscriptionTable);
@ -258,7 +259,7 @@ public class FhirResourceDaoSubscriptionDstu21 extends FhirResourceDaoDstu21<Sub
}
@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) {
ResourceTable retVal = super.updateEntity(theResource, theEntity, theUpdateHistory, theDeletedTimestampOrNull, thePerformIndexing, theUpdateVersion, theUpdateTime);
@ -273,9 +274,9 @@ public class FhirResourceDaoSubscriptionDstu21 extends FhirResourceDaoDstu21<Sub
} else {
Query q = myEntityManager.createNamedQuery("Q_HFJ_SUBSCRIPTION_SET_STATUS");
q.setParameter("res_id", resourceId);
q.setParameter("status", resource.getStatusElement().getValue());
q.setParameter("status", resource.getStatusElement().getValueAsString());
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 {
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");
}
SubscriptionStatusEnum status = theResource.getStatusElement().getValueAsEnum();
SubscriptionStatus status = theResource.getStatus();
if (status == null) {
throw new UnprocessableEntityException("Subscription.status must be populated on this server");
}

View File

@ -45,11 +45,8 @@ 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.ComposeIncludeConcept;
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.IdDt;
import ca.uhn.fhir.model.primitive.StringDt;
import ca.uhn.fhir.model.primitive.UriDt;
import ca.uhn.fhir.rest.param.TokenParam;
import ca.uhn.fhir.rest.param.UriParam;
import ca.uhn.fhir.rest.server.IBundleProvider;
@ -61,7 +58,7 @@ import ca.uhn.fhir.validation.ValidationSupportChain;
public class FhirResourceDaoValueSetDstu2 extends FhirResourceDaoDstu2<ValueSet>implements IFhirResourceDaoValueSet<ValueSet, CodingDt, CodeableConceptDt> {
@Autowired
private IJpaValidationSupport myJpaValidationSupport;
private IJpaValidationSupportDstu2 myJpaValidationSupport;
private ValidationSupportChain myValidationSupport;
@ -181,8 +178,7 @@ public class FhirResourceDaoValueSetDstu2 extends FhirResourceDaoDstu2<ValueSet>
}
@Override
public ca.uhn.fhir.jpa.dao.IFhirResourceDaoValueSet.ValidateCodeResult validateCode(UriDt theValueSetIdentifier, IIdType theId, CodeDt theCode, UriDt theSystem, StringDt theDisplay,
CodingDt theCoding, CodeableConceptDt theCodeableConcept) {
public ca.uhn.fhir.jpa.dao.IFhirResourceDaoValueSet.ValidateCodeResult validateCode(IPrimitiveType<String> theValueSetIdentifier, IIdType theId, IPrimitiveType<String> theCode, IPrimitiveType<String> theSystem, IPrimitiveType<String> theDisplay, CodingDt theCoding, CodeableConceptDt theCodeableConcept) {
List<IIdType> valueSetIds;
boolean haveCodeableConcept = theCodeableConcept != null && theCodeableConcept.getCoding().size() > 0;
@ -292,7 +288,7 @@ public class FhirResourceDaoValueSetDstu2 extends FhirResourceDaoDstu2<ValueSet>
}
@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 haveCode = theCode != null && theCode.isEmpty() == false;
boolean haveSystem = theSystem != null && theSystem.isEmpty() == false;

View File

@ -25,12 +25,21 @@ import static org.apache.commons.lang3.StringUtils.isNotBlank;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.List;
import java.util.Set;
import javax.annotation.PostConstruct;
import org.apache.commons.codec.binary.StringUtils;
import org.hl7.fhir.dstu21.model.CodeableConcept;
import org.hl7.fhir.dstu21.model.Coding;
import org.hl7.fhir.dstu21.model.IdType;
import org.hl7.fhir.dstu21.model.ValueSet;
import org.hl7.fhir.dstu21.model.ValueSet.ConceptDefinitionComponent;
import org.hl7.fhir.dstu21.model.ValueSet.ConceptReferenceComponent;
import org.hl7.fhir.dstu21.model.ValueSet.ConceptSetComponent;
import org.hl7.fhir.dstu21.model.ValueSet.ValueSetExpansionContainsComponent;
import org.hl7.fhir.instance.model.api.IIdType;
import org.hl7.fhir.instance.model.api.IPrimitiveType;
import org.springframework.beans.factory.annotation.Autowired;
@ -38,18 +47,6 @@ import org.springframework.beans.factory.annotation.Qualifier;
import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.jpa.entity.BaseHasResource;
import ca.uhn.fhir.model.dstu21.composite.CodeableConceptDt;
import ca.uhn.fhir.model.dstu21.composite.CodingDt;
import ca.uhn.fhir.model.dstu21.resource.ValueSet;
import ca.uhn.fhir.model.dstu21.resource.ValueSet.CodeSystemConcept;
import ca.uhn.fhir.model.dstu21.resource.ValueSet.ComposeInclude;
import ca.uhn.fhir.model.dstu21.resource.ValueSet.ComposeIncludeConcept;
import ca.uhn.fhir.model.dstu21.resource.ValueSet.ExpansionContains;
import ca.uhn.fhir.model.primitive.CodeDt;
import ca.uhn.fhir.model.primitive.DateTimeDt;
import ca.uhn.fhir.model.primitive.IdDt;
import ca.uhn.fhir.model.primitive.StringDt;
import ca.uhn.fhir.model.primitive.UriDt;
import ca.uhn.fhir.rest.param.TokenParam;
import ca.uhn.fhir.rest.param.UriParam;
import ca.uhn.fhir.rest.server.IBundleProvider;
@ -58,10 +55,10 @@ import ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException;
import ca.uhn.fhir.validation.DefaultProfileValidationSupport;
import ca.uhn.fhir.validation.ValidationSupportChain;
public class FhirResourceDaoValueSetDstu21 extends FhirResourceDaoDstu21<ValueSet>implements IFhirResourceDaoValueSet<ValueSet, CodingDt, CodeableConceptDt> {
public class FhirResourceDaoValueSetDstu21 extends FhirResourceDaoDstu21<ValueSet>implements IFhirResourceDaoValueSet<ValueSet, Coding, CodeableConcept> {
@Autowired
private IJpaValidationSupport myJpaValidationSupport;
private IJpaValidationSupportDstu21 myJpaValidationSupport;
private ValidationSupportChain myValidationSupport;
@ -75,8 +72,8 @@ public class FhirResourceDaoValueSetDstu21 extends FhirResourceDaoDstu21<ValueSe
@PostConstruct
public void postConstruct() {
super.postConstruct();
myDefaultProfileValidationSupport = new DefaultProfileValidationSupport();
myValidationSupport = new ValidationSupportChain(myDefaultProfileValidationSupport, myJpaValidationSupport);
// myDefaultProfileValidationSupport = new DefaultProfileValidationSupport();
// myValidationSupport = new ValidationSupportChain(myDefaultProfileValidationSupport, myJpaValidationSupport);
}
@Override
@ -126,14 +123,14 @@ public class FhirResourceDaoValueSetDstu21 extends FhirResourceDaoDstu21<ValueSe
@Override
public ValueSet expand(ValueSet source, String theFilter) {
ValueSet retVal = new ValueSet();
retVal.setDate(DateTimeDt.withCurrentTime());
retVal.setDate(new Date());
/*
* Add composed concepts
*/
for (ComposeInclude nextInclude : source.getCompose().getInclude()) {
for (ComposeIncludeConcept next : nextInclude.getConcept()) {
for (ConceptSetComponent nextInclude : source.getCompose().getInclude()) {
for (ConceptReferenceComponent next : nextInclude.getConcept()) {
if (isBlank(theFilter)) {
addCompose(retVal, nextInclude.getSystem(), next.getCode(), next.getDisplay());
} else {
@ -149,14 +146,14 @@ public class FhirResourceDaoValueSetDstu21 extends FhirResourceDaoDstu21<ValueSe
* Add defined concepts
*/
for (CodeSystemConcept next : source.getCodeSystem().getConcept()) {
for (ConceptDefinitionComponent next : source.getCodeSystem().getConcept()) {
addCompose(theFilter, retVal, source, next);
}
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)) {
addCompose(theValueSetToPopulate, theSourceValueSet.getCodeSystem().getSystem(), theConcept.getCode(), theConcept.getDisplay());
} else {
@ -165,7 +162,7 @@ public class FhirResourceDaoValueSetDstu21 extends FhirResourceDaoDstu21<ValueSe
addCompose(theValueSetToPopulate, theSourceValueSet.getCodeSystem().getSystem(), theConcept.getCode(), theConcept.getDisplay());
}
}
for (CodeSystemConcept nextChild : theConcept.getConcept()) {
for (ConceptDefinitionComponent nextChild : theConcept.getConcept()) {
addCompose(theFilter, theValueSetToPopulate, theSourceValueSet, nextChild);
}
}
@ -174,15 +171,14 @@ public class FhirResourceDaoValueSetDstu21 extends FhirResourceDaoDstu21<ValueSe
if (isBlank(theCode)) {
return;
}
ExpansionContains contains = retVal.getExpansion().addContains();
ValueSetExpansionContainsComponent contains = retVal.getExpansion().addContains();
contains.setSystem(theSystem);
contains.setCode(theCode);
contains.setDisplay(theDisplay);
}
@Override
public ca.uhn.fhir.jpa.dao.IFhirResourceDaoValueSet.ValidateCodeResult validateCode(UriDt theValueSetIdentifier, IIdType theId, CodeDt theCode, UriDt theSystem, StringDt theDisplay,
CodingDt theCoding, CodeableConceptDt theCodeableConcept) {
public ca.uhn.fhir.jpa.dao.IFhirResourceDaoValueSet.ValidateCodeResult validateCode(IPrimitiveType<String> theValueSetIdentifier, IIdType theId, IPrimitiveType<String> theCode, IPrimitiveType<String> theSystem, IPrimitiveType<String> theDisplay, Coding theCoding, CodeableConcept theCodeableConcept) {
List<IIdType> valueSetIds;
boolean haveCodeableConcept = theCodeableConcept != null && theCodeableConcept.getCoding().size() > 0;
@ -203,7 +199,7 @@ public class FhirResourceDaoValueSetDstu21 extends FhirResourceDaoDstu21<ValueSe
Set<Long> ids = searchForIds(ValueSet.SP_IDENTIFIER, new TokenParam(null, theValueSetIdentifier.getValue()));
valueSetIds = new ArrayList<IIdType>();
for (Long next : ids) {
valueSetIds.add(new IdDt("ValueSet", next));
valueSetIds.add(new IdType("ValueSet", next));
}
} else {
if (theCode == null || theCode.isEmpty()) {
@ -216,7 +212,7 @@ public class FhirResourceDaoValueSetDstu21 extends FhirResourceDaoDstu21<ValueSe
for (IIdType nextId : valueSetIds) {
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);
if (result != null) {
if (theDisplay != null && isNotBlank(theDisplay.getValue()) && isNotBlank(result.getDisplay())) {
@ -233,14 +229,14 @@ public class FhirResourceDaoValueSetDstu21 extends FhirResourceDaoDstu21<ValueSe
private List<IIdType> findValueSetIdsContainingSystemAndCode(String theCode, String theSystem) {
if (theSystem != null && theSystem.startsWith("http://hl7.org/fhir/")) {
return Collections.singletonList((IIdType)new IdDt(theSystem));
return Collections.singletonList((IIdType)new IdType(theSystem));
}
List<IIdType> valueSetIds;
Set<Long> ids = searchForIds(ValueSet.SP_CODE, new TokenParam(theSystem, theCode));
valueSetIds = new ArrayList<IIdType>();
for (Long next : ids) {
valueSetIds.add(new IdDt("ValueSet", next));
valueSetIds.add(new IdType("ValueSet", next));
}
return valueSetIds;
}
@ -259,9 +255,9 @@ public class FhirResourceDaoValueSetDstu21 extends FhirResourceDaoDstu21<ValueSe
return thePrimitive != null ? thePrimitive.getValue() : null;
}
private ca.uhn.fhir.jpa.dao.IFhirResourceDaoValueSet.ValidateCodeResult validateCodeIsInContains(List<ExpansionContains> contains, String theSystem, String theCode, CodingDt theCoding,
CodeableConceptDt theCodeableConcept) {
for (ExpansionContains nextCode : contains) {
private ca.uhn.fhir.jpa.dao.IFhirResourceDaoValueSet.ValidateCodeResult validateCodeIsInContains(List<ValueSetExpansionContainsComponent> contains, String theSystem, String theCode, Coding theCoding,
CodeableConcept theCodeableConcept) {
for (ValueSetExpansionContainsComponent nextCode : contains) {
ca.uhn.fhir.jpa.dao.IFhirResourceDaoValueSet.ValidateCodeResult result = validateCodeIsInContains(nextCode.getContains(), theSystem, theCode, theCoding, theCodeableConcept);
if (result != null) {
return result;
@ -279,7 +275,7 @@ public class FhirResourceDaoValueSetDstu21 extends FhirResourceDaoDstu21<ValueSe
return new ValidateCodeResult(true, "Validation succeeded", nextCode.getDisplay());
}
} else {
for (CodingDt next : theCodeableConcept.getCoding()) {
for (Coding next : theCodeableConcept.getCoding()) {
if (StringUtils.equals(system, next.getSystem()) && StringUtils.equals(code, next.getCode())) {
return new ValidateCodeResult(true, "Validation succeeded", nextCode.getDisplay());
}
@ -292,7 +288,7 @@ public class FhirResourceDaoValueSetDstu21 extends FhirResourceDaoDstu21<ValueSe
}
@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 haveCode = theCode != null && theCode.isEmpty() == false;
boolean haveSystem = theSystem != null && theSystem.isEmpty() == false;
@ -317,7 +313,7 @@ public class FhirResourceDaoValueSetDstu21 extends FhirResourceDaoDstu21<ValueSe
List<IIdType> valueSetIds = findValueSetIdsContainingSystemAndCode(code, system);
for (IIdType nextId : valueSetIds) {
ValueSet expansion = expand(nextId, null);
List<ExpansionContains> contains = expansion.getExpansion().getContains();
List<ValueSetExpansionContainsComponent> contains = expansion.getExpansion().getContains();
ca.uhn.fhir.jpa.dao.IFhirResourceDaoValueSet.LookupCodeResult result = lookup(contains, system, code);
if (result != null) {
return result;
@ -331,8 +327,8 @@ public class FhirResourceDaoValueSetDstu21 extends FhirResourceDaoDstu21<ValueSe
return retVal;
}
private ca.uhn.fhir.jpa.dao.IFhirResourceDaoValueSet.LookupCodeResult lookup(List<ExpansionContains> theContains, String theSystem, String theCode) {
for (ExpansionContains nextCode : theContains) {
private ca.uhn.fhir.jpa.dao.IFhirResourceDaoValueSet.LookupCodeResult lookup(List<ValueSetExpansionContainsComponent> theContains, String theSystem, String theCode) {
for (ValueSetExpansionContainsComponent nextCode : theContains) {
String system = nextCode.getSystem();
String code = nextCode.getCode();
@ -341,8 +337,8 @@ public class FhirResourceDaoValueSetDstu21 extends FhirResourceDaoDstu21<ValueSe
retVal.setSearchedForCode(code);
retVal.setSearchedForSystem(system);
retVal.setFound(true);
if (nextCode.getAbstract() != null) {
retVal.setCodeIsAbstract(nextCode.getAbstract().booleanValue());
if (nextCode.getAbstractElement() != null) {
retVal.setCodeIsAbstract(nextCode.getAbstractElement().booleanValue());
}
retVal.setCodeDisplay(nextCode.getDisplay());
retVal.setCodeSystemVersion(nextCode.getVersion());

View File

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

View File

@ -1,7 +1,12 @@
package ca.uhn.fhir.jpa.dao;
import org.hl7.fhir.instance.model.api.IAnyResource;
import org.hl7.fhir.instance.model.api.IBaseResource;
import ca.uhn.fhir.jpa.entity.BaseHasResource;
import ca.uhn.fhir.model.api.IResource;
import ca.uhn.fhir.model.api.ResourceMetadataKeyEnum;
import ca.uhn.fhir.model.api.ResourceMetadataKeyEnum.ResourceMetadataKeySupportingAnyResource;
/*
* #%L
@ -25,7 +30,7 @@ import ca.uhn.fhir.model.api.ResourceMetadataKeyEnum;
public interface IDao {
public static final ResourceMetadataKeyEnum<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;
@ -38,7 +43,21 @@ public interface IDao {
public void put(IResource theResource, Long theObject) {
theResource.getResourceMetadata().put(RESOURCE_PID, theObject);
}
@Override
public Long get(IAnyResource theResource) {
return (Long) theResource.getUserData(RESOURCE_PID.name());
}
@Override
public void put(IAnyResource theResource, Long theObject) {
theResource.setUserData(RESOURCE_PID.name(), theObject);
}
};
IBaseResource toResource(BaseHasResource theEntity, boolean theForHistoryOperation);
<R extends IBaseResource> R toResource(Class<R> theResourceType, 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.IIdType;
import org.hl7.fhir.instance.model.api.IPrimitiveType;
import ca.uhn.fhir.model.primitive.IdDt;
import ca.uhn.fhir.model.primitive.UnsignedIntDt;
import ca.uhn.fhir.rest.api.SortSpec;
import ca.uhn.fhir.rest.param.DateRangeParam;
import ca.uhn.fhir.rest.server.IBundleProvider;
public interface IFhirResourceDaoEncounter<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.IIdType;
import org.hl7.fhir.instance.model.api.IPrimitiveType;
import ca.uhn.fhir.model.primitive.UnsignedIntDt;
import ca.uhn.fhir.rest.api.SortSpec;
import ca.uhn.fhir.rest.param.DateRangeParam;
import ca.uhn.fhir.rest.param.StringAndListParam;
@ -33,8 +33,8 @@ import ca.uhn.fhir.rest.server.IBundleProvider;
public interface IFhirResourceDaoPatient<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.IIdType;
import ca.uhn.fhir.model.primitive.CodeDt;
import ca.uhn.fhir.model.primitive.StringDt;
import ca.uhn.fhir.model.primitive.UriDt;
import org.hl7.fhir.instance.model.api.IPrimitiveType;
public interface IFhirResourceDaoValueSet<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);
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 {
private String myCodeDisplay;

View File

@ -22,6 +22,6 @@ package ca.uhn.fhir.jpa.dao;
import ca.uhn.fhir.validation.IValidationSupport;
public interface IJpaValidationSupport extends IValidationSupport {
public interface IJpaValidationSupportDstu2 extends IValidationSupport {
}

View File

@ -1,11 +1,10 @@
package ca.uhn.fhir.model.dstu21.composite;
package ca.uhn.fhir.jpa.dao;
import ca.uhn.fhir.model.api.annotation.DatatypeDef;
import ca.uhn.fhir.model.dstu21.composite.QuantityDt;
import org.hl7.fhir.dstu21.hapi.validation.IValidationSupport;
/*
* #%L
* HAPI FHIR Structures - DSTU2 (FHIR v1.0.0)
* HAPI FHIR JPA Server
* %%
* Copyright (C) 2014 - 2015 University Health Network
* %%
@ -23,7 +22,6 @@ import ca.uhn.fhir.model.dstu21.composite.QuantityDt;
* #L%
*/
@DatatypeDef(name="Money", profileOf=QuantityDt.class)
public class MoneyDt extends QuantityDt {
public interface IJpaValidationSupportDstu21 extends IValidationSupport {
}

View File

@ -22,6 +22,8 @@ package ca.uhn.fhir.jpa.dao;
import java.util.Set;
import org.hl7.fhir.instance.model.api.IBaseResource;
import ca.uhn.fhir.jpa.entity.BaseResourceIndexedSearchParam;
import ca.uhn.fhir.jpa.entity.ResourceIndexedSearchParamCoords;
import ca.uhn.fhir.jpa.entity.ResourceIndexedSearchParamDate;
@ -30,22 +32,21 @@ import ca.uhn.fhir.jpa.entity.ResourceIndexedSearchParamQuantity;
import ca.uhn.fhir.jpa.entity.ResourceIndexedSearchParamString;
import ca.uhn.fhir.jpa.entity.ResourceIndexedSearchParamUri;
import ca.uhn.fhir.jpa.entity.ResourceTable;
import ca.uhn.fhir.model.api.IResource;
interface ISearchParamExtractor {
public abstract Set<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.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);

View File

@ -1,5 +1,10 @@
package ca.uhn.fhir.jpa.dao;
import org.hl7.fhir.dstu21.model.StructureDefinition;
import org.hl7.fhir.dstu21.model.ValueSet;
import org.hl7.fhir.dstu21.model.ValueSet.ConceptSetComponent;
import org.hl7.fhir.dstu21.model.ValueSet.ValueSetExpansionComponent;
/*
* #%L
* HAPI FHIR JPA Server
@ -20,9 +25,6 @@ package ca.uhn.fhir.jpa.dao;
* #L%
*/
import org.hl7.fhir.instance.model.ValueSet;
import org.hl7.fhir.instance.model.ValueSet.ConceptSetComponent;
import org.hl7.fhir.instance.model.ValueSet.ValueSetExpansionComponent;
import org.hl7.fhir.instance.model.api.IBaseResource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
@ -31,7 +33,7 @@ import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.rest.param.UriParam;
import ca.uhn.fhir.rest.server.IBundleProvider;
public class JpaValidationSupportDstu21 implements IJpaValidationSupport {
public class JpaValidationSupportDstu21 implements IJpaValidationSupportDstu21 {
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(JpaValidationSupportDstu21.class);
@ -41,11 +43,11 @@ public class JpaValidationSupportDstu21 implements IJpaValidationSupport {
@Autowired
@Qualifier("myStructureDefinitionDaoDstu21")
private IFhirResourceDao<ca.uhn.fhir.model.dstu21.resource.StructureDefinition> myStructureDefinitionDao;
private IFhirResourceDao<StructureDefinition> myStructureDefinitionDao;
@Autowired
@Qualifier("myValueSetDaoDstu21")
private IFhirResourceDao<ca.uhn.fhir.model.dstu21.resource.ValueSet> myValueSetDao;
private IFhirResourceDao<ValueSet> myValueSetDao;
@Autowired
@Qualifier("myFhirContextDstu21")

View File

@ -1,5 +1,7 @@
package ca.uhn.fhir.jpa.dao;
import static org.apache.commons.lang3.StringUtils.defaultString;
/*
* #%L
* HAPI FHIR JPA Server
@ -53,6 +55,7 @@ import javax.persistence.criteria.Root;
import javax.persistence.criteria.Subquery;
import org.apache.commons.lang3.StringUtils;
import org.hl7.fhir.instance.model.api.IAnyResource;
import org.hl7.fhir.instance.model.api.IBaseResource;
import org.hl7.fhir.instance.model.api.IIdType;
import org.springframework.transaction.PlatformTransactionManager;
@ -1300,17 +1303,25 @@ public class SearchBuilder {
for (ResourceTable next : q.getResultList()) {
Class<? 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());
if (index == null) {
ourLog.warn("Got back unexpected resource PID {}", next.getId());
continue;
}
if (theRevIncludedPids.contains(next.getId())) {
ResourceMetadataKeyEnum.ENTRY_SEARCH_MODE.put(resource, BundleEntrySearchModeEnum.INCLUDE);
if (resource instanceof IResource) {
if (theRevIncludedPids.contains(next.getId())) {
ResourceMetadataKeyEnum.ENTRY_SEARCH_MODE.put((IResource)resource, BundleEntrySearchModeEnum.INCLUDE);
} else {
ResourceMetadataKeyEnum.ENTRY_SEARCH_MODE.put((IResource)resource, BundleEntrySearchModeEnum.MATCH);
}
} else {
ResourceMetadataKeyEnum.ENTRY_SEARCH_MODE.put(resource, BundleEntrySearchModeEnum.MATCH);
if (theRevIncludedPids.contains(next.getId())) {
ResourceMetadataKeyEnum.ENTRY_SEARCH_MODE.put((IAnyResource)resource, BundleEntrySearchModeEnum.INCLUDE.getCode());
} else {
ResourceMetadataKeyEnum.ENTRY_SEARCH_MODE.put((IAnyResource)resource, BundleEntrySearchModeEnum.MATCH.getCode());
}
}
theResourceListToPopulate.set(index, resource);
@ -1322,7 +1333,7 @@ public class SearchBuilder {
*
* @param theLastUpdated
*/
private HashSet<Long> loadReverseIncludes(Collection<Long> theMatches, Set<Include> theRevIncludes, boolean theReverseMode, EverythingModeEnum theEverythingModeEnum, DateRangeParam theLastUpdated) {
private HashSet<Long> loadReverseIncludes(Collection<Long> theMatches, Set<Include> theRevIncludes, boolean theReverseMode, DateRangeParam theLastUpdated) {
if (theMatches.size() == 0) {
return new HashSet<Long>();
}
@ -1378,19 +1389,18 @@ public class SearchBuilder {
if (myContext.getVersion().getVersion() == FhirVersionEnum.DSTU1) {
paths = Collections.singletonList(nextInclude.getValue());
} else {
int colonIdx = nextInclude.getValue().indexOf(':');
if (colonIdx < 2) {
String resType = nextInclude.getParamType();
if (isBlank(resType)) {
continue;
}
String resType = nextInclude.getValue().substring(0, colonIdx);
RuntimeResourceDefinition def = myContext.getResourceDefinition(resType);
if (def == null) {
ourLog.warn("Unknown resource type in include/revinclude=" + nextInclude.getValue());
continue;
}
String paramName = nextInclude.getValue().substring(colonIdx + 1);
RuntimeSearchParam param = def.getSearchParam(paramName);
String paramName = nextInclude.getParamName();
RuntimeSearchParam param = isNotBlank(paramName) ? def.getSearchParam(paramName) : null;
if (param == null) {
ourLog.warn("Unknown param name in include/revinclude=" + nextInclude.getValue());
continue;
@ -1399,11 +1409,20 @@ public class SearchBuilder {
paths = param.getPathsSplit();
}
String targetResourceType = defaultString(nextInclude.getParamTargetType(), null);
for (String nextPath : paths) {
String sql = "SELECT r FROM ResourceLink r WHERE r.mySourcePath = :src_path AND r." + searchFieldName + " IN (:target_pids)";
String sql;
if (targetResourceType != null) {
sql = "SELECT r FROM ResourceLink r WHERE r.mySourcePath = :src_path AND r." + searchFieldName + " IN (:target_pids) AND r.myTargetResourceType = :target_resource_type";
} else {
sql = "SELECT r FROM ResourceLink r WHERE r.mySourcePath = :src_path AND r." + searchFieldName + " IN (:target_pids)";
}
TypedQuery<ResourceLink> q = myEntityManager.createQuery(sql, ResourceLink.class);
q.setParameter("src_path", nextPath);
q.setParameter("target_pids", nextRoundMatches);
if (targetResourceType != null) {
q.setParameter("target_resource_type", targetResourceType);
}
List<ResourceLink> results = q.getResultList();
for (ResourceLink resourceLink : results) {
if (theReverseMode) {
@ -1595,7 +1614,7 @@ public class SearchBuilder {
final Set<Long> revIncludedPids;
if (theParams.getEverythingMode() == null) {
if (theParams.getRevIncludes() != null && theParams.getRevIncludes().isEmpty() == false) {
revIncludedPids = loadReverseIncludes(pids, theParams.getRevIncludes(), true, null, lu);
revIncludedPids = loadReverseIncludes(pids, theParams.getRevIncludes(), true, lu);
} else {
revIncludedPids = new HashSet<Long>();
}
@ -1623,7 +1642,7 @@ public class SearchBuilder {
// Load includes
pidsSubList = new ArrayList<Long>(pidsSubList);
revIncludedPids.addAll(loadReverseIncludes(pidsSubList, theParams.getIncludes(), false, null, theParams.getLastUpdated()));
revIncludedPids.addAll(loadReverseIncludes(pidsSubList, theParams.getIncludes(), false, theParams.getLastUpdated()));
// Execute the query and make sure we return distinct results
List<IBaseResource> resources = new ArrayList<IBaseResource>();

View File

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

View File

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

View File

@ -36,6 +36,7 @@ import javax.persistence.Table;
import org.apache.commons.lang3.Validate;
import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;
import org.hibernate.annotations.ColumnDefault;
import org.hibernate.search.annotations.Field;
@Entity
@ -64,6 +65,11 @@ public class ResourceLink implements Serializable {
@Column(name = "SRC_RESOURCE_ID", insertable = false, updatable = false, nullable = false)
private Long mySourceResourcePid;
@Column(name = "SOURCE_RESOURCE_TYPE", nullable=false, length=ResourceTable.RESTYPE_LEN)
@ColumnDefault("''") // TODO: remove this (it's only here for simplifying upgrades of 1.3 -> 1.4)
@Field()
private String mySourceResourceType;
@ManyToOne(optional = false, fetch=FetchType.LAZY)
@JoinColumn(name = "TARGET_RESOURCE_ID", referencedColumnName = "RES_ID", nullable = false)
private ResourceTable myTargetResource;
@ -71,18 +77,21 @@ public class ResourceLink implements Serializable {
@Column(name = "TARGET_RESOURCE_ID", insertable = false, updatable = false, nullable = false)
@Field()
private Long myTargetResourcePid;
@Column(name = "TARGET_RESOURCE_TYPE", nullable=false, length=ResourceTable.RESTYPE_LEN)
@ColumnDefault("''") // TODO: remove this (it's only here for simplifying upgrades of 1.3 -> 1.4)
@Field()
private String myTargetResourceType;
public ResourceLink() {
super();
}
public ResourceLink(String theSourcePath, ResourceTable theSourceResource, ResourceTable theTargetResource) {
super();
mySourcePath = theSourcePath;
mySourceResource = theSourceResource;
mySourceResourcePid = theSourceResource.getId();
myTargetResource = theTargetResource;
myTargetResourcePid = theTargetResource.getId();
setSourcePath(theSourcePath);
setSourceResource(theSourceResource);
setTargetResource(theTargetResource);
}
@Override
@ -140,12 +149,14 @@ public class ResourceLink implements Serializable {
public void setSourceResource(ResourceTable theSourceResource) {
mySourceResource = theSourceResource;
mySourceResourcePid = theSourceResource.getId();
mySourceResourceType = theSourceResource.getResourceType();
}
public void setTargetResource(ResourceTable theTargetResource) {
Validate.notNull(theTargetResource);
myTargetResource = theTargetResource;
myTargetResourcePid = theTargetResource.getId();
myTargetResourceType = theTargetResource.getResourceType();
}
@Override

View File

@ -24,13 +24,10 @@ import java.util.Date;
import javax.servlet.http.HttpServletRequest;
import net.sourceforge.cobertura.CoverageIgnore;
import org.hl7.fhir.instance.model.api.IBaseResource;
import org.springframework.beans.factory.annotation.Required;
import ca.uhn.fhir.context.FhirContext;
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.primitive.IdDt;
import ca.uhn.fhir.rest.annotation.GetTags;
@ -40,8 +37,9 @@ import ca.uhn.fhir.rest.annotation.Read;
import ca.uhn.fhir.rest.annotation.Since;
import ca.uhn.fhir.rest.server.IBundleProvider;
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;
@ -79,7 +77,7 @@ public abstract class BaseJpaResourceProvider<T extends IResource> extends BaseJ
}
@Override
public Class<? extends IResource> getResourceType() {
public Class<? extends IBaseResource> getResourceType() {
return myDao.getResourceType();
}

View File

@ -1,5 +1,9 @@
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
* 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.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.Operation;
import ca.uhn.fhir.rest.annotation.OperationParam;
@ -43,11 +46,11 @@ public class BaseJpaResourceProviderEncounterDstu21 extends JpaResourceProviderD
javax.servlet.http.HttpServletRequest theServletRequest,
@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.")
@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")
@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.")
@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")
@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 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
* HAPI FHIR JPA Server
@ -26,8 +31,6 @@ import java.util.List;
import ca.uhn.fhir.jpa.dao.IFhirResourceDaoPatient;
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.Operation;
import ca.uhn.fhir.rest.annotation.OperationParam;
@ -51,11 +54,11 @@ public class BaseJpaResourceProviderPatientDstu21 extends JpaResourceProviderDst
javax.servlet.http.HttpServletRequest theServletRequest,
@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.")
@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")
@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)")
@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)")
@OperationParam(name = Constants.PARAM_TEXT, min=0, max=OperationParam.MAX_UNLIMITED)
List<StringDt> theNarrative,
List<StringType> theNarrative,
@Sort
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.")
@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")
@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)")
@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)")
@OperationParam(name = Constants.PARAM_TEXT, min=0, max=OperationParam.MAX_UNLIMITED)
List<StringDt> theNarrative,
List<StringType> theNarrative,
@Sort
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();
if (theNarrative != null) {
for (StringDt next : theNarrative) {
for (StringType next : theNarrative) {
if (isNotBlank(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 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.LookupCodeResult;
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.Operation;
import ca.uhn.fhir.rest.annotation.OperationParam;
import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException;
import ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException;
public class BaseJpaResourceProviderValueSetDstu21 extends JpaResourceProviderDstu2<ValueSet> {
public class BaseJpaResourceProviderValueSetDstu21 extends JpaResourceProviderDstu21<ValueSet> {
//@formatter:off
@Operation(name = "$expand", idempotent = true)
public ValueSet expand(
HttpServletRequest theServletRequest,
@IdParam(optional=true) IdDt theId,
@IdParam(optional=true) IdType theId,
@OperationParam(name="valueSet", min=0, max=1) ValueSet theValueSet,
@OperationParam(name="identifier", min=0, max=1) UriDt theIdentifier,
@OperationParam(name = "filter", min=0, max=1) StringDt theFilter) {
@OperationParam(name="identifier", min=0, max=1) UriType theIdentifier,
@OperationParam(name = "filter", min=0, max=1) StringType theFilter) {
//@formatter:on
boolean haveId = theId != null && theId.hasIdPart();
@ -70,7 +69,7 @@ public class BaseJpaResourceProviderValueSetDstu21 extends JpaResourceProviderDs
startRequest(theServletRequest);
try {
IFhirResourceDaoValueSet<ValueSet, CodingDt, CodeableConceptDt> dao = (IFhirResourceDaoValueSet<ValueSet, CodingDt, CodeableConceptDt>) getDao();
IFhirResourceDaoValueSet<ValueSet, Coding, CodeableConcept> dao = (IFhirResourceDaoValueSet<ValueSet, Coding, CodeableConcept>) getDao();
if (haveId) {
return dao.expand(theId, toFilterString(theFilter));
} 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;
}
//@formatter:off
@Operation(name = "$lookup", idempotent = true, returnParameters= {
@OperationParam(name="name", type=StringDt.class, min=1),
@OperationParam(name="version", type=StringDt.class, min=0),
@OperationParam(name="display", type=StringDt.class, min=1),
@OperationParam(name="abstract", type=BooleanDt.class, min=1),
@OperationParam(name="name", type=StringType.class, min=1),
@OperationParam(name="version", type=StringType.class, min=0),
@OperationParam(name="display", type=StringType.class, min=1),
@OperationParam(name="abstract", type=BooleanType.class, min=1),
})
public Parameters lookup(
HttpServletRequest theServletRequest,
@OperationParam(name="code", min=0, max=1) CodeDt theCode,
@OperationParam(name="system", min=0, max=1) UriDt theSystem,
@OperationParam(name="coding", min=0, max=1) CodingDt theCoding
@OperationParam(name="code", min=0, max=1) CodeType theCode,
@OperationParam(name="system", min=0, max=1) UriType theSystem,
@OperationParam(name="coding", min=0, max=1) Coding theCoding
) {
//@formatter:on
startRequest(theServletRequest);
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);
if (result.isFound()==false) {
throw new ResourceNotFoundException("Unable to find code[" + result.getSearchedForCode() + "] in system[" + result.getSearchedForSystem() + "]");
}
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())) {
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("abstract").setValue(new BooleanDt(result.isCodeIsAbstract()));
retVal.addParameter().setName("display").setValue(new StringType(result.getCodeDisplay()));
retVal.addParameter().setName("abstract").setValue(new BooleanType(result.isCodeIsAbstract()));
return retVal;
} finally {
endRequest(theServletRequest);
@ -142,33 +141,33 @@ public class BaseJpaResourceProviderValueSetDstu21 extends JpaResourceProviderDs
//@formatter:off
@Operation(name = "$validate-code", idempotent = true, returnParameters= {
@OperationParam(name="result", type=BooleanDt.class, min=1),
@OperationParam(name="message", type=StringDt.class),
@OperationParam(name="display", type=StringDt.class)
@OperationParam(name="result", type=BooleanType.class, min=1),
@OperationParam(name="message", type=StringType.class),
@OperationParam(name="display", type=StringType.class)
})
public Parameters validateCode(
HttpServletRequest theServletRequest,
@IdParam(optional=true) IdDt theId,
@OperationParam(name="identifier", min=0, max=1) UriDt theValueSetIdentifier,
@OperationParam(name="code", min=0, max=1) CodeDt theCode,
@OperationParam(name="system", min=0, max=1) UriDt theSystem,
@OperationParam(name="display", min=0, max=1) StringDt theDisplay,
@OperationParam(name="coding", min=0, max=1) CodingDt theCoding,
@OperationParam(name="codeableConcept", min=0, max=1) CodeableConceptDt theCodeableConcept
@IdParam(optional=true) IdType theId,
@OperationParam(name="identifier", min=0, max=1) UriType theValueSetIdentifier,
@OperationParam(name="code", min=0, max=1) CodeType theCode,
@OperationParam(name="system", min=0, max=1) UriType theSystem,
@OperationParam(name="display", min=0, max=1) StringType theDisplay,
@OperationParam(name="coding", min=0, max=1) Coding theCoding,
@OperationParam(name="codeableConcept", min=0, max=1) CodeableConcept theCodeableConcept
) {
//@formatter:on
startRequest(theServletRequest);
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);
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())) {
retVal.addParameter().setName("message").setValue(new StringDt(result.getMessage()));
retVal.addParameter().setName("message").setValue(new StringType(result.getMessage()));
}
if (isNotBlank(result.getDisplay())) {
retVal.addParameter().setName("display").setValue(new StringDt(result.getDisplay()));
retVal.addParameter().setName("display").setValue(new StringType(result.getDisplay()));
}
return retVal;
} finally {

View File

@ -25,34 +25,34 @@ import java.util.Map;
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.RuntimeResourceDefinition;
import ca.uhn.fhir.context.RuntimeSearchParam;
import ca.uhn.fhir.jpa.dao.DaoConfig;
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.provider.dstu21.ServerConformanceProvider;
import ca.uhn.fhir.util.ExtensionConstants;
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 DaoConfig myDaoConfig;
private String myImplementationDescription;
private RestfulServer myRestfulServer;
private IFhirSystemDao<Bundle, MetaDt> mySystemDao;
private IFhirSystemDao<Bundle, Meta> mySystemDao;
/**
* Constructor
@ -66,7 +66,7 @@ public class JpaConformanceProviderDstu21 extends ServerConformanceProvider {
/**
* Constructor
*/
public JpaConformanceProviderDstu21(RestfulServer theRestfulServer, IFhirSystemDao<Bundle, MetaDt> theSystemDao, DaoConfig theDaoConfig) {
public JpaConformanceProviderDstu21(RestfulServer theRestfulServer, IFhirSystemDao<Bundle, Meta> theSystemDao, DaoConfig theDaoConfig) {
super(theRestfulServer);
myRestfulServer = theRestfulServer;
mySystemDao = theSystemDao;
@ -83,26 +83,26 @@ public class JpaConformanceProviderDstu21 extends ServerConformanceProvider {
FhirContext ctx = myRestfulServer.getFhirContext();
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();
if (conditionalDelete == ConditionalDeleteStatusEnum.MULTIPLE_DELETES_SUPPORTED && myDaoConfig.isAllowMultipleDelete() == false) {
nextResource.setConditionalDelete(ConditionalDeleteStatusEnum.SINGLE_DELETES_SUPPORTED);
ConditionalDeleteStatus conditionalDelete = nextResource.getConditionalDelete();
if (conditionalDelete == ConditionalDeleteStatus.MULTIPLE && myDaoConfig.isAllowMultipleDelete() == false) {
nextResource.setConditionalDelete(ConditionalDeleteStatus.SINGLE);
}
// Add resource counts
Long count = counts.get(nextResource.getTypeElement().getValueAsString());
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
for (RestResourceSearchParam nextParam : nextResource.getSearchParam()) {
if (nextParam.getTypeElement().getValueAsEnum() == SearchParamTypeEnum.REFERENCE) {
List<BoundCodeDt<ResourceTypeEnum>> targets = nextParam.getTarget();
for (BoundCodeDt<ResourceTypeEnum> next : targets) {
for (ConformanceRestResourceSearchParamComponent nextParam : nextResource.getSearchParam()) {
if (nextParam.getType() == SearchParamType.REFERENCE) {
List<CodeType> targets = nextParam.getTarget();
for (CodeType next : targets) {
RuntimeResourceDefinition def = ctx.getResourceDefinition(next.getValue());
for (RuntimeSearchParam nextChainedParam : def.getSearchParams()) {
nextParam.addChain(nextChainedParam.getName());
@ -135,7 +135,7 @@ public class JpaConformanceProviderDstu21 extends ServerConformanceProvider {
}
@CoverageIgnore
public void setSystemDao(IFhirSystemDao<Bundle, MetaDt> mySystemDao) {
public void setSystemDao(IFhirSystemDao<Bundle, Meta> mySystemDao) {
this.mySystemDao = mySystemDao;
}
}

View File

@ -22,11 +22,12 @@ package ca.uhn.fhir.jpa.provider;
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.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.Create;
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.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_DELETE = "$meta-delete";
@ -70,7 +71,7 @@ public class JpaResourceProviderDstu21<T extends IResource> extends BaseJpaResou
}
@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);
try {
if (theConditional != null) {
@ -85,49 +86,49 @@ public class JpaResourceProviderDstu21<T extends IResource> extends BaseJpaResou
//@formatter:off
@Operation(name=OPERATION_NAME_META, idempotent=true, returnParameters= {
@OperationParam(name="return", type=MetaDt.class)
@OperationParam(name="return", type=Meta.class)
})
//@formatter:on
public Parameters meta() {
Parameters parameters = new Parameters();
MetaDt metaGetOperation = getDao().metaGetOperation(MetaDt.class);
Meta metaGetOperation = getDao().metaGetOperation(Meta.class);
parameters.addParameter().setName("return").setValue(metaGetOperation);
return parameters;
}
//@formatter:off
@Operation(name=OPERATION_NAME_META, idempotent=true, returnParameters= {
@OperationParam(name="return", type=MetaDt.class)
@OperationParam(name="return", type=Meta.class)
})
//@formatter:on
public Parameters meta(@IdParam IdDt theId) {
public Parameters meta(@IdParam IdType theId) {
Parameters parameters = new Parameters();
MetaDt metaGetOperation = getDao().metaGetOperation(MetaDt.class, theId);
Meta metaGetOperation = getDao().metaGetOperation(Meta.class, theId);
parameters.addParameter().setName("return").setValue(metaGetOperation);
return parameters;
}
//@formatter:off
@Operation(name=OPERATION_NAME_META_ADD, idempotent=true, returnParameters= {
@OperationParam(name="return", type=MetaDt.class)
@OperationParam(name="return", type=Meta.class)
})
//@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) {
throw new InvalidRequestException("Input contains no parameter with name 'meta'");
}
Parameters parameters = new Parameters();
MetaDt metaAddOperation = getDao().metaAddOperation(theId, theMeta);
Meta metaAddOperation = getDao().metaAddOperation(theId, theMeta);
parameters.addParameter().setName("return").setValue(metaAddOperation);
return parameters;
}
//@formatter:off
@Operation(name=OPERATION_NAME_META_DELETE, idempotent=true, returnParameters= {
@OperationParam(name="return", type=MetaDt.class)
@OperationParam(name="return", type=Meta.class)
})
//@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) {
throw new InvalidRequestException("Input contains no parameter with name 'meta'");
}
@ -137,7 +138,7 @@ public class JpaResourceProviderDstu21<T extends IResource> extends BaseJpaResou
}
@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);
try {
if (theConditional != null) {
@ -158,7 +159,7 @@ public class JpaResourceProviderDstu21<T extends IResource> extends BaseJpaResou
}
@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) {
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.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.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.ISearchDao;
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.StringDt;
import ca.uhn.fhir.rest.annotation.Operation;
import ca.uhn.fhir.rest.annotation.OperationParam;
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.servlet.ServletRequestDetails;
public class JpaSystemProviderDstu21 extends BaseJpaSystemProvider<Bundle, MetaDt> {
public class JpaSystemProviderDstu21 extends BaseJpaSystemProvider<Bundle, Meta> {
@Autowired()
@Qualifier("mySystemDaoDstu21")
private IFhirSystemDao<Bundle, MetaDt> mySystemDao;
private IFhirSystemDao<Bundle, Meta> mySystemDao;
@Autowired
private ISearchDao mySearchDao;
@ -163,7 +164,7 @@ public class JpaSystemProviderDstu21 extends BaseJpaSystemProvider<Bundle, MetaD
Map<String, Long> counts = mySystemDao.getResourceCounts();
counts = new TreeMap<String, Long>(counts);
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;
@ -178,13 +179,13 @@ public class JpaSystemProviderDstu21 extends BaseJpaSystemProvider<Bundle, MetaD
int count = mySystemDao.markAllResourcesForReindexing();
Parameters retVal = new Parameters();
retVal.addParameter().setName("count").setValue(new IntegerDt(count));
retVal.addParameter().setName("count").setValue(new IntegerType(count));
return retVal;
}
//@formatter:off
@Operation(name="$meta", idempotent=true, returnParameters= {
@OperationParam(name="return", type=MetaDt.class)
@OperationParam(name="return", type=Meta.class)
})
//@formatter:on
public Parameters meta() {
@ -216,8 +217,8 @@ public class JpaSystemProviderDstu21 extends BaseJpaSystemProvider<Bundle, MetaD
for (Suggestion next : keywords) {
//@formatter:off
retVal.addParameter()
.addPart(new Parameter().setName("keyword").setValue(new StringDt(next.getTerm())))
.addPart(new Parameter().setName("score").setValue(new DecimalDt(next.getScore())));
.addPart(new ParametersParameterComponent().setName("keyword").setValue(new StringType(next.getTerm())))
.addPart(new ParametersParameterComponent().setName("score").setValue(new DecimalType(next.getScore())));
//@formatter:on
}

View File

@ -1,5 +1,25 @@
package ca.uhn.fhir.jpa.provider;
/*
* #%L
* HAPI FHIR JPA Server
* %%
* Copyright (C) 2014 - 2015 University Health Network
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* #L%
*/
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

View File

@ -2,6 +2,10 @@ package ca.uhn.fhir.jpa.util;
import static org.apache.commons.lang3.StringUtils.isNotBlank;
import org.hl7.fhir.dstu21.model.Subscription;
import org.hl7.fhir.dstu21.model.Subscription.SubscriptionChannelType;
import org.hl7.fhir.dstu21.model.Subscription.SubscriptionStatus;
/*
* #%L
* HAPI FHIR JPA Server
@ -26,13 +30,10 @@ import org.hl7.fhir.instance.model.api.IIdType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import ca.uhn.fhir.jpa.dao.FhirResourceDaoSubscriptionDstu2;
import ca.uhn.fhir.jpa.dao.FhirResourceDaoSubscriptionDstu21;
import ca.uhn.fhir.jpa.dao.IFhirResourceDao;
import ca.uhn.fhir.model.api.IResource;
import ca.uhn.fhir.model.api.ResourceMetadataKeyEnum;
import ca.uhn.fhir.model.dstu21.resource.Subscription;
import ca.uhn.fhir.model.dstu21.valueset.SubscriptionChannelTypeEnum;
import ca.uhn.fhir.model.dstu21.valueset.SubscriptionStatusEnum;
import ca.uhn.fhir.rest.api.RestOperationTypeEnum;
import ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException;
import ca.uhn.fhir.rest.server.exceptions.UnprocessableEntityException;
@ -41,11 +42,11 @@ import net.sourceforge.cobertura.CoverageIgnore;
/**
* Interceptor which requires newly created {@link Subscription subscriptions} to be in
* {@link SubscriptionStatusEnum#REQUESTED} state and prevents clients from changing the status.
* {@link SubscriptionStatus#REQUESTED} state and prevents clients from changing the status.
*/
public class SubscriptionsRequireManualActivationInterceptorDstu21 extends InterceptorAdapter {
public static final ResourceMetadataKeyEnum<Object> ALLOW_STATUS_CHANGE = new ResourceMetadataKeyEnum<Object>(FhirResourceDaoSubscriptionDstu2.class.getName() + "_ALLOW_STATUS_CHANGE") {
public static final ResourceMetadataKeyEnum<Object> ALLOW_STATUS_CHANGE = new ResourceMetadataKeyEnum<Object>(FhirResourceDaoSubscriptionDstu21.class.getName() + "_ALLOW_STATUS_CHANGE") {
private static final long serialVersionUID = 1;
@CoverageIgnore
@ -85,9 +86,9 @@ public class SubscriptionsRequireManualActivationInterceptorDstu21 extends Inter
private void verifyStatusOk(RestOperationTypeEnum theOperation, ActionRequestDetails theRequestDetails) {
Subscription subscription = (Subscription) theRequestDetails.getResource();
SubscriptionStatusEnum newStatus = subscription.getStatusElement().getValueAsEnum();
SubscriptionStatus newStatus = subscription.getStatusElement().getValue();
if (newStatus == SubscriptionStatusEnum.REQUESTED || newStatus == SubscriptionStatusEnum.OFF) {
if (newStatus == SubscriptionStatus.REQUESTED || newStatus == SubscriptionStatus.OFF) {
return;
}
@ -101,7 +102,7 @@ public class SubscriptionsRequireManualActivationInterceptorDstu21 extends Inter
Subscription existing;
try {
existing = myDao.read(requestId);
SubscriptionStatusEnum existingStatus = existing.getStatusElement().getValueAsEnum();
SubscriptionStatus existingStatus = existing.getStatusElement().getValue();
if (existingStatus != newStatus) {
verifyActiveStatus(subscription, newStatus, existingStatus);
}
@ -113,14 +114,14 @@ public class SubscriptionsRequireManualActivationInterceptorDstu21 extends Inter
}
}
private void verifyActiveStatus(Subscription theSubscription, SubscriptionStatusEnum newStatus, SubscriptionStatusEnum theExistingStatus) {
SubscriptionChannelTypeEnum channelType = theSubscription.getChannel().getTypeElement().getValueAsEnum();
private void verifyActiveStatus(Subscription theSubscription, SubscriptionStatus newStatus, SubscriptionStatus theExistingStatus) {
SubscriptionChannelType channelType = theSubscription.getChannel().getTypeElement().getValue();
if (channelType == null) {
throw new UnprocessableEntityException("Subscription.channel.type must be populated");
}
if (channelType == SubscriptionChannelTypeEnum.WEBSOCKET) {
if (channelType == SubscriptionChannelType.WEBSOCKET) {
return;
}
@ -128,13 +129,13 @@ public class SubscriptionsRequireManualActivationInterceptorDstu21 extends Inter
throw new UnprocessableEntityException("Subscription.status can not be changed from " + describeStatus(theExistingStatus) + " to " + describeStatus(newStatus));
}
throw new UnprocessableEntityException("Subscription.status must be '" + SubscriptionStatusEnum.OFF.getCode() + "' or '" + SubscriptionStatusEnum.REQUESTED.getCode() + "' on a newly created subscription");
throw new UnprocessableEntityException("Subscription.status must be '" + SubscriptionStatus.OFF.toCode() + "' or '" + SubscriptionStatus.REQUESTED.toCode() + "' on a newly created subscription");
}
private String describeStatus(SubscriptionStatusEnum existingStatus) {
private String describeStatus(SubscriptionStatus existingStatus) {
String existingStatusString;
if (existingStatus != null) {
existingStatusString = '\'' + existingStatus.getCode() + '\'';
existingStatusString = '\'' + existingStatus.toCode() + '\'';
} else {
existingStatusString = "null";
}

View File

@ -7,6 +7,7 @@ import java.util.ArrayList;
import java.util.List;
import org.apache.commons.io.IOUtils;
import org.hl7.fhir.dstu21.model.Bundle.BundleEntryComponent;
import org.hl7.fhir.instance.model.api.IBaseResource;
import org.hl7.fhir.instance.model.api.IIdType;
import org.junit.AfterClass;
@ -35,6 +36,16 @@ public class BaseJpaTest {
return retVal;
}
protected List<IIdType> toUnqualifiedVersionlessIds(org.hl7.fhir.dstu21.model.Bundle theFound) {
List<IIdType> retVal = new ArrayList<IIdType>();
for (BundleEntryComponent next : theFound.getEntry()) {
// if (next.getResource()!= null) {
retVal.add(next.getResource().getIdElement().toUnqualifiedVersionless());
// }
}
return retVal;
}
protected List<IIdType> toUnqualifiedVersionlessIds(IBundleProvider theFound) {
List<IIdType> retVal = new ArrayList<IIdType>();
int size = theFound.size();
@ -45,6 +56,25 @@ public class BaseJpaTest {
}
return retVal;
}
protected String[] toValues(IIdType... theValues) {
ArrayList<String> retVal = new ArrayList<String>();
for (IIdType next : theValues) {
retVal.add(next.getValue());
}
return retVal.toArray(new String[retVal.size()]);
}
protected List<String> toUnqualifiedVersionlessIdValues(IBundleProvider theFound) {
List<String> retVal = new ArrayList<String>();
int size = theFound.size();
ourLog.info("Found {} results", size);
List<IBaseResource> resources = theFound.getResources(0, size);
for (IBaseResource next : resources) {
retVal.add(next.getIdElement().toUnqualifiedVersionless().getValue());
}
return retVal;
}
protected List<IIdType> toUnqualifiedVersionlessIds(List<IBaseResource> theFound) {
List<IIdType> retVal = new ArrayList<IIdType>();

View File

@ -4,7 +4,9 @@ import static org.hamcrest.Matchers.contains;
import static org.hamcrest.Matchers.containsInAnyOrder;
import static org.hamcrest.Matchers.empty;
import static org.hamcrest.Matchers.not;
import static org.junit.Assert.*;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertThat;
import static org.mockito.Mockito.mock;
import java.util.List;
@ -14,9 +16,8 @@ import javax.servlet.http.HttpServletRequest;
import org.hl7.fhir.instance.model.api.IIdType;
import org.junit.Test;
import ca.uhn.fhir.jpa.dao.FhirSearchDao;
import ca.uhn.fhir.jpa.dao.SearchParameterMap;
import ca.uhn.fhir.jpa.dao.FhirSearchDao.Suggestion;
import ca.uhn.fhir.jpa.dao.SearchParameterMap;
import ca.uhn.fhir.model.dstu2.resource.Device;
import ca.uhn.fhir.model.dstu2.resource.Media;
import ca.uhn.fhir.model.dstu2.resource.Observation;

View File

@ -1430,27 +1430,45 @@ public class FhirResourceDaoDstu2SearchNoFtTest extends BaseJpaDstu2Test {
{
Organization org = new Organization();
org.getNameElement().setValue(methodName + "_O1Parent");
parentOrgId = myOrganizationDao.create(org).getId();
parentOrgId = myOrganizationDao.create(org).getId().toUnqualifiedVersionless();
}
IIdType orgId;
IIdType patientId;
{
Organization org = new Organization();
org.getNameElement().setValue(methodName + "_O1");
org.setPartOf(new ResourceReferenceDt(parentOrgId));
IIdType orgId = myOrganizationDao.create(org).getId();
orgId = myOrganizationDao.create(org).getId().toUnqualifiedVersionless();
Patient patient = new Patient();
patient.addIdentifier().setSystem("urn:system").setValue("001");
patient.addName().addFamily("Tester_" + methodName + "_P1").addGiven("Joe");
patient.getManagingOrganization().setReference(orgId);
myPatientDao.create(patient);
patient.addCareProvider().setReference(orgId);
patientId = myPatientDao.create(patient).getId().toUnqualifiedVersionless();
}
IIdType practId2;
{
Practitioner pract = new Practitioner();
pract.getName().addFamily(methodName + "_PRACT1");
practId2 = myPractitionerDao.create(pract).getId().toUnqualifiedVersionless();
}
IIdType patientId2;
{
Patient patient = new Patient();
patient.addIdentifier().setSystem("urn:system").setValue("002");
patient.addName().addFamily("Tester_" + methodName + "_P2").addGiven("John");
myPatientDao.create(patient);
patient.addCareProvider().setReference(practId2);
patientId2 = myPatientDao.create(patient).getId().toUnqualifiedVersionless();
}
{
// Typed include
SearchParameterMap params = new SearchParameterMap();
params.addInclude(Patient.INCLUDE_CAREPROVIDER.withType("Practitioner"));
List<IIdType> ids = toUnqualifiedVersionlessIds(myPatientDao.search(params));
assertThat(ids, containsInAnyOrder(patientId, patientId2, practId2));
}
{
// No includes
SearchParameterMap params = new SearchParameterMap();
@ -1527,6 +1545,13 @@ public class FhirResourceDaoDstu2SearchNoFtTest extends BaseJpaDstu2Test {
assertEquals(1, patients.size());
assertEquals(Patient.class, patients.get(0).getClass());
}
{
// Untyped include
SearchParameterMap params = new SearchParameterMap();
params.addInclude(Patient.INCLUDE_CAREPROVIDER);
List<IIdType> ids = toUnqualifiedVersionlessIds(myPatientDao.search(params));
assertThat(ids, containsInAnyOrder(orgId, patientId, patientId2, practId2));
}
}
@SuppressWarnings("unused")

View File

@ -11,6 +11,30 @@ import javax.persistence.EntityManager;
import org.apache.commons.io.IOUtils;
import org.hibernate.search.jpa.FullTextEntityManager;
import org.hibernate.search.jpa.Search;
import org.hl7.fhir.dstu21.model.Bundle;
import org.hl7.fhir.dstu21.model.CodeableConcept;
import org.hl7.fhir.dstu21.model.Coding;
import org.hl7.fhir.dstu21.model.ConceptMap;
import org.hl7.fhir.dstu21.model.Device;
import org.hl7.fhir.dstu21.model.DiagnosticOrder;
import org.hl7.fhir.dstu21.model.DiagnosticReport;
import org.hl7.fhir.dstu21.model.Encounter;
import org.hl7.fhir.dstu21.model.Immunization;
import org.hl7.fhir.dstu21.model.Location;
import org.hl7.fhir.dstu21.model.Media;
import org.hl7.fhir.dstu21.model.Medication;
import org.hl7.fhir.dstu21.model.MedicationOrder;
import org.hl7.fhir.dstu21.model.Meta;
import org.hl7.fhir.dstu21.model.Observation;
import org.hl7.fhir.dstu21.model.Organization;
import org.hl7.fhir.dstu21.model.Patient;
import org.hl7.fhir.dstu21.model.Practitioner;
import org.hl7.fhir.dstu21.model.Questionnaire;
import org.hl7.fhir.dstu21.model.QuestionnaireResponse;
import org.hl7.fhir.dstu21.model.StructureDefinition;
import org.hl7.fhir.dstu21.model.Subscription;
import org.hl7.fhir.dstu21.model.Substance;
import org.hl7.fhir.dstu21.model.ValueSet;
import org.hl7.fhir.instance.model.api.IBaseResource;
import org.junit.Before;
import org.junit.runner.RunWith;
@ -53,30 +77,6 @@ import ca.uhn.fhir.jpa.entity.SubscriptionFlaggedResource;
import ca.uhn.fhir.jpa.entity.SubscriptionTable;
import ca.uhn.fhir.jpa.entity.TagDefinition;
import ca.uhn.fhir.jpa.provider.JpaSystemProviderDstu21;
import ca.uhn.fhir.model.dstu21.composite.CodeableConceptDt;
import ca.uhn.fhir.model.dstu21.composite.CodingDt;
import ca.uhn.fhir.model.dstu21.composite.MetaDt;
import ca.uhn.fhir.model.dstu21.resource.Bundle;
import ca.uhn.fhir.model.dstu21.resource.ConceptMap;
import ca.uhn.fhir.model.dstu21.resource.Device;
import ca.uhn.fhir.model.dstu21.resource.DiagnosticOrder;
import ca.uhn.fhir.model.dstu21.resource.DiagnosticReport;
import ca.uhn.fhir.model.dstu21.resource.Encounter;
import ca.uhn.fhir.model.dstu21.resource.Immunization;
import ca.uhn.fhir.model.dstu21.resource.Location;
import ca.uhn.fhir.model.dstu21.resource.Media;
import ca.uhn.fhir.model.dstu21.resource.Medication;
import ca.uhn.fhir.model.dstu21.resource.MedicationOrder;
import ca.uhn.fhir.model.dstu21.resource.Observation;
import ca.uhn.fhir.model.dstu21.resource.Organization;
import ca.uhn.fhir.model.dstu21.resource.Patient;
import ca.uhn.fhir.model.dstu21.resource.Practitioner;
import ca.uhn.fhir.model.dstu21.resource.Questionnaire;
import ca.uhn.fhir.model.dstu21.resource.QuestionnaireResponse;
import ca.uhn.fhir.model.dstu21.resource.StructureDefinition;
import ca.uhn.fhir.model.dstu21.resource.Subscription;
import ca.uhn.fhir.model.dstu21.resource.Substance;
import ca.uhn.fhir.model.dstu21.resource.ValueSet;
import ca.uhn.fhir.parser.IParser;
import ca.uhn.fhir.rest.method.MethodUtil;
import ca.uhn.fhir.rest.server.interceptor.IServerInterceptor;
@ -164,7 +164,7 @@ public abstract class BaseJpaDstu21Test extends BaseJpaTest {
protected IFhirResourceDao<Substance> mySubstanceDao;
@Autowired
@Qualifier("mySystemDaoDstu21")
protected IFhirSystemDao<Bundle, MetaDt> mySystemDao;
protected IFhirSystemDao<Bundle, Meta> mySystemDao;
@Autowired
@Qualifier("mySystemProviderDstu21")
protected JpaSystemProviderDstu21 mySystemProvider;
@ -172,7 +172,7 @@ public abstract class BaseJpaDstu21Test extends BaseJpaTest {
protected PlatformTransactionManager myTxManager;
@Autowired
@Qualifier("myValueSetDaoDstu21")
protected IFhirResourceDaoValueSet<ValueSet, CodingDt, CodeableConceptDt> myValueSetDao;
protected IFhirResourceDaoValueSet<ValueSet, Coding, CodeableConcept> myValueSetDao;
@Before
public void beforeCreateInterceptor() {

View File

@ -7,6 +7,8 @@ import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import org.hl7.fhir.dstu21.model.IdType;
import org.hl7.fhir.dstu21.model.Patient;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@ -15,8 +17,6 @@ import org.mockito.ArgumentCaptor;
import ca.uhn.fhir.jpa.entity.ResourceTable;
import ca.uhn.fhir.jpa.interceptor.IJpaServerInterceptor;
import ca.uhn.fhir.jpa.interceptor.JpaServerInterceptorAdapter;
import ca.uhn.fhir.model.dstu21.resource.Patient;
import ca.uhn.fhir.model.primitive.IdDt;
import ca.uhn.fhir.rest.server.interceptor.IServerInterceptor.ActionRequestDetails;
public class FhirResourceDaoDstu21InterceptorTest extends BaseJpaDstu21Test {
@ -84,7 +84,7 @@ public class FhirResourceDaoDstu21InterceptorTest extends BaseJpaDstu21Test {
p.addName().addFamily("PATIENT");
Long id = myPatientDao.create(p).getId().getIdPartAsLong();
myPatientDao.delete(new IdDt("Patient", id));
myPatientDao.delete(new IdType("Patient", id));
ArgumentCaptor<ActionRequestDetails> detailsCapt;
ArgumentCaptor<ResourceTable> tableCapt;
@ -105,7 +105,7 @@ public class FhirResourceDaoDstu21InterceptorTest extends BaseJpaDstu21Test {
Long id = myPatientDao.create(p).getId().getIdPartAsLong();
p = new Patient();
p.setId(new IdDt(id));
p.setId(new IdType(id));
p.addName().addFamily("PATIENT1");
Long id2 = myPatientDao.update(p).getId().getIdPartAsLong();
assertEquals(id, id2);
@ -124,7 +124,7 @@ public class FhirResourceDaoDstu21InterceptorTest extends BaseJpaDstu21Test {
*/
p = new Patient();
p.setId(new IdDt(id));
p.setId(new IdType(id));
p.addName().addFamily("PATIENT2");
id2 = myPatientDao.update(p, "Patient?family=PATIENT1").getId().getIdPartAsLong();
assertEquals(id, id2);

View File

@ -13,20 +13,20 @@ import java.util.List;
import javax.servlet.http.HttpServletRequest;
import org.hl7.fhir.dstu21.model.Base64BinaryType;
import org.hl7.fhir.dstu21.model.Device;
import org.hl7.fhir.dstu21.model.Media;
import org.hl7.fhir.dstu21.model.Observation;
import org.hl7.fhir.dstu21.model.Observation.ObservationStatus;
import org.hl7.fhir.dstu21.model.Patient;
import org.hl7.fhir.dstu21.model.Quantity;
import org.hl7.fhir.dstu21.model.StringType;
import org.hl7.fhir.instance.model.api.IIdType;
import org.junit.Ignore;
import org.junit.Test;
import ca.uhn.fhir.jpa.dao.FhirSearchDao.Suggestion;
import ca.uhn.fhir.jpa.dao.SearchParameterMap;
import ca.uhn.fhir.model.dstu21.composite.QuantityDt;
import ca.uhn.fhir.model.dstu21.resource.Device;
import ca.uhn.fhir.model.dstu21.resource.Media;
import ca.uhn.fhir.model.dstu21.resource.Observation;
import ca.uhn.fhir.model.dstu21.resource.Patient;
import ca.uhn.fhir.model.dstu21.valueset.ObservationStatusEnum;
import ca.uhn.fhir.model.primitive.Base64BinaryDt;
import ca.uhn.fhir.model.primitive.StringDt;
import ca.uhn.fhir.rest.param.StringAndListParam;
import ca.uhn.fhir.rest.param.StringOrListParam;
import ca.uhn.fhir.rest.param.StringParam;
@ -42,31 +42,31 @@ public class FhirResourceDaoDstu21SearchFtTest extends BaseJpaDstu21Test {
public void testCodeTextSearch() {
Observation obs1 = new Observation();
obs1.getCode().setText("Systolic Blood Pressure");
obs1.setStatus(ObservationStatusEnum.FINAL);
obs1.setValue(new QuantityDt(123));
obs1.setStatus(ObservationStatus.FINAL);
obs1.setValue(new Quantity(123));
obs1.setComments("obs1");
IIdType id1 = myObservationDao.create(obs1).getId().toUnqualifiedVersionless();
Observation obs2 = new Observation();
obs2.getCode().setText("Diastolic Blood Pressure");
obs2.setStatus(ObservationStatusEnum.FINAL);
obs2.setValue(new QuantityDt(81));
obs2.setStatus(ObservationStatus.FINAL);
obs2.setValue(new Quantity(81));
IIdType id2 = myObservationDao.create(obs2).getId().toUnqualifiedVersionless();
SearchParameterMap map;
map = new SearchParameterMap();
map.add(Observation.SP_CODE, new TokenParam(null, "blood").setText(true));
assertThat(toUnqualifiedVersionlessIds(myObservationDao.search(map)), containsInAnyOrder(id1, id2));
assertThat(toUnqualifiedVersionlessIdValues(myObservationDao.search(map)), containsInAnyOrder(toValues(id1, id2)));
map = new SearchParameterMap();
map.add(Observation.SP_CODE, new TokenParam(null, "blood").setText(true));
assertThat(toUnqualifiedVersionlessIds(myPatientDao.search(map)), empty());
assertThat(toUnqualifiedVersionlessIdValues(myPatientDao.search(map)), empty());
map = new SearchParameterMap();
map.add(Observation.SP_CODE, new TokenParam(null, "blood").setText(true));
map.add(Constants.PARAM_CONTENT, new StringParam("obs1"));
assertThat(toUnqualifiedVersionlessIds(myObservationDao.search(map)), containsInAnyOrder(id1));
assertThat(toUnqualifiedVersionlessIdValues(myObservationDao.search(map)), containsInAnyOrder(toValues(id1)));
}
@ -75,21 +75,21 @@ public class FhirResourceDaoDstu21SearchFtTest extends BaseJpaDstu21Test {
public void testStringTextSearch() {
Observation obs1 = new Observation();
obs1.getCode().setText("AAAAA");
obs1.setValue(new StringDt("Systolic Blood Pressure"));
obs1.setStatus(ObservationStatusEnum.FINAL);
obs1.setValue(new StringType("Systolic Blood Pressure"));
obs1.setStatus(ObservationStatus.FINAL);
IIdType id1 = myObservationDao.create(obs1).getId().toUnqualifiedVersionless();
Observation obs2 = new Observation();
obs1.getCode().setText("AAAAA");
obs1.setValue(new StringDt("Diastolic Blood Pressure"));
obs2.setStatus(ObservationStatusEnum.FINAL);
obs1.setValue(new StringType("Diastolic Blood Pressure"));
obs2.setStatus(ObservationStatus.FINAL);
IIdType id2 = myObservationDao.create(obs2).getId().toUnqualifiedVersionless();
SearchParameterMap map;
map = new SearchParameterMap();
map.add(Observation.SP_VALUE_STRING, new StringParam("sure").setContains(true));
assertThat(toUnqualifiedVersionlessIds(myObservationDao.search(map)), containsInAnyOrder(id1, id2));
assertThat(toUnqualifiedVersionlessIdValues(myObservationDao.search(map)), containsInAnyOrder(toValues(id1, id2)));
}
@ -101,10 +101,10 @@ public class FhirResourceDaoDstu21SearchFtTest extends BaseJpaDstu21Test {
IIdType ptId = myPatientDao.create(patient).getId().toUnqualifiedVersionless();
Media med = new Media();
med.getSubject().setReference(ptId);
med.getSubject().setReferenceElement(ptId);
med.getSubtype().setText("Systolic Blood Pressure");
med.getContent().setContentType("LCws");
med.getContent().setData(new Base64BinaryDt(new byte[] {44,44,44,44,44,44,44,44}));
med.getContent().setDataElement(new Base64BinaryType(new byte[] {44,44,44,44,44,44,44,44}));
med.getContent().setTitle("bbbb syst");
myMediaDao.create(med);
ourLog.info(myFhirCtx.newJsonParser().encodeResourceToString(med));
@ -141,17 +141,17 @@ public class FhirResourceDaoDstu21SearchFtTest extends BaseJpaDstu21Test {
IIdType ptId = myPatientDao.create(patient).getId().toUnqualifiedVersionless();
Observation obs = new Observation();
obs.getSubject().setReference(ptId);
obs.getSubject().setReferenceElement(ptId);
obs.getCode().setText("ZXCVBNM ASDFGHJKL QWERTYUIOPASDFGHJKL");
myObservationDao.create(obs);
obs = new Observation();
obs.getSubject().setReference(ptId);
obs.getSubject().setReferenceElement(ptId);
obs.getCode().setText("MNBVCXZ");
myObservationDao.create(obs);
obs = new Observation();
obs.getSubject().setReference(ptId);
obs.getSubject().setReferenceElement(ptId);
obs.getCode().setText("ZXC HELLO");
obs.addComponent().getCode().setText("HHHHHHHHHH");
myObservationDao.create(obs);
@ -164,7 +164,7 @@ public class FhirResourceDaoDstu21SearchFtTest extends BaseJpaDstu21Test {
IIdType ptId2 = myPatientDao.create(patient).getId().toUnqualifiedVersionless();
Observation obs2 = new Observation();
obs2.getSubject().setReference(ptId2);
obs2.getSubject().setReferenceElement(ptId2);
obs2.getCode().setText("ZXCVBNMZZ");
myObservationDao.create(obs2);
@ -209,17 +209,17 @@ public class FhirResourceDaoDstu21SearchFtTest extends BaseJpaDstu21Test {
SearchParameterMap map;
patient = new Patient();
patient.getText().setDiv("<div>DIVAAA</div>");
patient.getText().setDivAsString("<div>DIVAAA</div>");
patient.addName().addGiven("NAMEAAA");
IIdType pId1 = myPatientDao.create(patient).getId().toUnqualifiedVersionless();
map = new SearchParameterMap();
map.add(Constants.PARAM_CONTENT, new StringParam("NAMEAAA"));
assertThat(toUnqualifiedVersionlessIds(myPatientDao.search(map)), contains(pId1));
assertThat(toUnqualifiedVersionlessIdValues(myPatientDao.search(map)), contains(toValues(pId1)));
map = new SearchParameterMap();
map.add(Constants.PARAM_TEXT, new StringParam("DIVAAA"));
assertThat(toUnqualifiedVersionlessIds(myPatientDao.search(map)), contains(pId1));
assertThat(toUnqualifiedVersionlessIdValues(myPatientDao.search(map)), contains(toValues(pId1)));
/*
* Reindex
@ -227,25 +227,25 @@ public class FhirResourceDaoDstu21SearchFtTest extends BaseJpaDstu21Test {
patient = new Patient();
patient.setId(pId1);
patient.getText().setDiv("<div>DIVBBB</div>");
patient.getText().setDivAsString("<div>DIVBBB</div>");
patient.addName().addGiven("NAMEBBB");
myPatientDao.update(patient);
map = new SearchParameterMap();
map.add(Constants.PARAM_CONTENT, new StringParam("NAMEAAA"));
assertThat(toUnqualifiedVersionlessIds(myPatientDao.search(map)), empty());
assertThat(toUnqualifiedVersionlessIdValues(myPatientDao.search(map)), empty());
map = new SearchParameterMap();
map.add(Patient.SP_NAME, new StringParam("NAMEBBB"));
assertThat(toUnqualifiedVersionlessIds(myPatientDao.search(map)), contains(pId1));
assertThat(toUnqualifiedVersionlessIdValues(myPatientDao.search(map)), contains(toValues(pId1)));
map = new SearchParameterMap();
map.add(Constants.PARAM_CONTENT, new StringParam("NAMEBBB"));
assertThat(toUnqualifiedVersionlessIds(myPatientDao.search(map)), contains(pId1));
assertThat(toUnqualifiedVersionlessIdValues(myPatientDao.search(map)), contains(toValues(pId1)));
map = new SearchParameterMap();
map.add(Constants.PARAM_TEXT, new StringParam("DIVBBB"));
assertThat(toUnqualifiedVersionlessIds(myPatientDao.search(map)), contains(pId1));
assertThat(toUnqualifiedVersionlessIdValues(myPatientDao.search(map)), contains(toValues(pId1)));
}
@ -268,27 +268,27 @@ public class FhirResourceDaoDstu21SearchFtTest extends BaseJpaDstu21Test {
myDeviceDao.create(dev2).getId().toUnqualifiedVersionless();
Observation obs1 = new Observation();
obs1.getText().setDiv("<div>OBSTEXT1</div>");
obs1.getSubject().setReference(ptId1);
obs1.getText().setDivAsString("<div>OBSTEXT1</div>");
obs1.getSubject().setReferenceElement(ptId1);
obs1.getCode().addCoding().setCode("CODE1");
obs1.setValue(new StringDt("obsvalue1"));
obs1.getDevice().setReference(devId1);
obs1.setValue(new StringType("obsvalue1"));
obs1.getDevice().setReferenceElement(devId1);
IIdType obsId1 = myObservationDao.create(obs1).getId().toUnqualifiedVersionless();
Observation obs2 = new Observation();
obs2.getSubject().setReference(ptId1);
obs2.getSubject().setReferenceElement(ptId1);
obs2.getCode().addCoding().setCode("CODE2");
obs2.setValue(new StringDt("obsvalue2"));
obs2.setValue(new StringType("obsvalue2"));
IIdType obsId2 = myObservationDao.create(obs2).getId().toUnqualifiedVersionless();
Observation obs3 = new Observation();
obs3.getSubject().setReference(ptId2);
obs3.getSubject().setReferenceElement(ptId2);
obs3.getCode().addCoding().setCode("CODE3");
obs3.setValue(new StringDt("obsvalue3"));
obs3.setValue(new StringType("obsvalue3"));
IIdType obsId3 = myObservationDao.create(obs3).getId().toUnqualifiedVersionless();
HttpServletRequest request;
List<IIdType> actual;
List<String> actual;
request = mock(HttpServletRequest.class);
StringAndListParam param;
@ -296,33 +296,33 @@ public class FhirResourceDaoDstu21SearchFtTest extends BaseJpaDstu21Test {
param = new StringAndListParam();
param.addAnd(new StringOrListParam().addOr(new StringParam("obsvalue1")));
actual = toUnqualifiedVersionlessIds(myPatientDao.patientInstanceEverything(request, ptId1, null, null, null, param, null));
assertThat(actual, containsInAnyOrder(ptId1, obsId1, devId1));
actual = toUnqualifiedVersionlessIdValues(myPatientDao.patientInstanceEverything(request, ptId1, null, null, null, param, null));
assertThat(actual, containsInAnyOrder(toValues(ptId1, obsId1, devId1)));
param = new StringAndListParam();
param.addAnd(new StringOrListParam().addOr(new StringParam("obstext1")));
actual = toUnqualifiedVersionlessIds(myPatientDao.patientInstanceEverything(request, ptId1, null, null, null, null, param));
assertThat(actual, containsInAnyOrder(ptId1, obsId1, devId1));
actual = toUnqualifiedVersionlessIdValues(myPatientDao.patientInstanceEverything(request, ptId1, null, null, null, null, param));
assertThat(actual, containsInAnyOrder(toValues(ptId1, obsId1, devId1)));
request = mock(HttpServletRequest.class);
actual = toUnqualifiedVersionlessIds(myPatientDao.patientInstanceEverything(request, ptId1, null, null, null, null, null));
assertThat(actual, containsInAnyOrder(ptId1, obsId1, obsId2, devId1));
actual = toUnqualifiedVersionlessIdValues(myPatientDao.patientInstanceEverything(request, ptId1, null, null, null, null, null));
assertThat(actual, containsInAnyOrder(toValues(ptId1, obsId1, obsId2, devId1)));
/*
* Add another match
*/
Observation obs4 = new Observation();
obs4.getSubject().setReference(ptId1);
obs4.getSubject().setReferenceElement(ptId1);
obs4.getCode().addCoding().setCode("CODE1");
obs4.setValue(new StringDt("obsvalue1"));
obs4.setValue(new StringType("obsvalue1"));
IIdType obsId4 = myObservationDao.create(obs4).getId().toUnqualifiedVersionless();
assertNotEquals(obsId1.getIdPart(), obsId4.getIdPart(), devId1);
param = new StringAndListParam();
param.addAnd(new StringOrListParam().addOr(new StringParam("obsvalue1")));
actual = toUnqualifiedVersionlessIds(myPatientDao.patientInstanceEverything(request, ptId1, null, null, null, param, null));
assertThat(actual, containsInAnyOrder(ptId1, obsId1, obsId4, devId1));
actual = toUnqualifiedVersionlessIdValues(myPatientDao.patientInstanceEverything(request, ptId1, null, null, null, param, null));
assertThat(actual, containsInAnyOrder(toValues(ptId1, obsId1, obsId4, devId1)));
/*
* Make one previous match no longer match
@ -330,15 +330,15 @@ public class FhirResourceDaoDstu21SearchFtTest extends BaseJpaDstu21Test {
obs1 = new Observation();
obs1.setId(obsId1);
obs1.getSubject().setReference(ptId1);
obs1.getSubject().setReferenceElement(ptId1);
obs1.getCode().addCoding().setCode("CODE2");
obs1.setValue(new StringDt("obsvalue2"));
obs1.setValue(new StringType("obsvalue2"));
myObservationDao.update(obs1);
param = new StringAndListParam();
param.addAnd(new StringOrListParam().addOr(new StringParam("obsvalue1")));
actual = toUnqualifiedVersionlessIds(myPatientDao.patientInstanceEverything(request, ptId1, null, null, null, param, null));
assertThat(actual, containsInAnyOrder(ptId1, obsId4));
actual = toUnqualifiedVersionlessIdValues(myPatientDao.patientInstanceEverything(request, ptId1, null, null, null, param, null));
assertThat(actual, containsInAnyOrder(toValues(ptId1, obsId4)));
}
@ -361,26 +361,26 @@ public class FhirResourceDaoDstu21SearchFtTest extends BaseJpaDstu21Test {
IIdType devId2 = myDeviceDao.create(dev2).getId().toUnqualifiedVersionless();
Observation obs1 = new Observation();
obs1.getSubject().setReference(ptId1);
obs1.getSubject().setReferenceElement(ptId1);
obs1.getCode().addCoding().setCode("CODE1");
obs1.setValue(new StringDt("obsvalue1"));
obs1.getDevice().setReference(devId1);
obs1.setValue(new StringType("obsvalue1"));
obs1.getDevice().setReferenceElement(devId1);
IIdType obsId1 = myObservationDao.create(obs1).getId().toUnqualifiedVersionless();
Observation obs2 = new Observation();
obs2.getSubject().setReference(ptId1);
obs2.getSubject().setReferenceElement(ptId1);
obs2.getCode().addCoding().setCode("CODE2");
obs2.setValue(new StringDt("obsvalue2"));
obs2.setValue(new StringType("obsvalue2"));
IIdType obsId2 = myObservationDao.create(obs2).getId().toUnqualifiedVersionless();
Observation obs3 = new Observation();
obs3.getSubject().setReference(ptId2);
obs3.getSubject().setReferenceElement(ptId2);
obs3.getCode().addCoding().setCode("CODE3");
obs3.setValue(new StringDt("obsvalue3"));
obs3.setValue(new StringType("obsvalue3"));
IIdType obsId3 = myObservationDao.create(obs3).getId().toUnqualifiedVersionless();
HttpServletRequest request;
List<IIdType> actual;
List<String> actual;
request = mock(HttpServletRequest.class);
StringAndListParam param;
@ -388,28 +388,28 @@ public class FhirResourceDaoDstu21SearchFtTest extends BaseJpaDstu21Test {
param = new StringAndListParam();
param.addAnd(new StringOrListParam().addOr(new StringParam("obsvalue1")));
actual = toUnqualifiedVersionlessIds(myPatientDao.patientTypeEverything(request, null, null, null, param, null));
assertThat(actual, containsInAnyOrder(ptId1, obsId1, devId1));
actual = toUnqualifiedVersionlessIdValues(myPatientDao.patientTypeEverything(request, null, null, null, param, null));
assertThat(actual, containsInAnyOrder(toValues(ptId1, obsId1, devId1)));
request = mock(HttpServletRequest.class);
actual = toUnqualifiedVersionlessIds(myPatientDao.patientTypeEverything(request, null, null, null, null, null));
assertThat(actual, containsInAnyOrder(ptId1, obsId1, obsId2, devId1, ptId2, obsId3));
actual = toUnqualifiedVersionlessIdValues(myPatientDao.patientTypeEverything(request, null, null, null, null, null));
assertThat(actual, containsInAnyOrder(toValues(ptId1, obsId1, obsId2, devId1, ptId2, obsId3)));
/*
* Add another match
*/
Observation obs4 = new Observation();
obs4.getSubject().setReference(ptId1);
obs4.getSubject().setReferenceElement(ptId1);
obs4.getCode().addCoding().setCode("CODE1");
obs4.setValue(new StringDt("obsvalue1"));
obs4.setValue(new StringType("obsvalue1"));
IIdType obsId4 = myObservationDao.create(obs4).getId().toUnqualifiedVersionless();
assertNotEquals(obsId1.getIdPart(), obsId4.getIdPart(), devId1);
param = new StringAndListParam();
param.addAnd(new StringOrListParam().addOr(new StringParam("obsvalue1")));
actual = toUnqualifiedVersionlessIds(myPatientDao.patientTypeEverything(request, null, null, null, param, null));
assertThat(actual, containsInAnyOrder(ptId1, obsId1, obsId4, devId1));
actual = toUnqualifiedVersionlessIdValues(myPatientDao.patientTypeEverything(request, null, null, null, param, null));
assertThat(actual, containsInAnyOrder(toValues(ptId1, obsId1, obsId4, devId1)));
/*
* Make one previous match no longer match
@ -417,15 +417,15 @@ public class FhirResourceDaoDstu21SearchFtTest extends BaseJpaDstu21Test {
obs1 = new Observation();
obs1.setId(obsId1);
obs1.getSubject().setReference(ptId1);
obs1.getSubject().setReferenceElement(ptId1);
obs1.getCode().addCoding().setCode("CODE2");
obs1.setValue(new StringDt("obsvalue2"));
obs1.setValue(new StringType("obsvalue2"));
myObservationDao.update(obs1);
param = new StringAndListParam();
param.addAnd(new StringOrListParam().addOr(new StringParam("obsvalue1")));
actual = toUnqualifiedVersionlessIds(myPatientDao.patientTypeEverything(request, null, null, null, param, null));
assertThat(actual, containsInAnyOrder(ptId1, obsId4));
actual = toUnqualifiedVersionlessIdValues(myPatientDao.patientTypeEverything(request, null, null, null, param, null));
assertThat(actual, containsInAnyOrder(toValues(ptId1, obsId4)));
}
@ -440,17 +440,17 @@ public class FhirResourceDaoDstu21SearchFtTest extends BaseJpaDstu21Test {
SearchParameterMap map;
patient = new Patient();
patient.getText().setDiv("<div>DIVAAA</div>");
patient.getText().setDivAsString("<div>DIVAAA</div>");
patient.addName().addGiven("NAMEAAA");
IIdType pId1 = myPatientDao.create(patient).getId().toUnqualifiedVersionless();
map = new SearchParameterMap();
map.add(Constants.PARAM_CONTENT, new StringParam("NAMEAAA"));
assertThat(toUnqualifiedVersionlessIds(myPatientDao.search(map)), contains(pId1));
assertThat(toUnqualifiedVersionlessIdValues(myPatientDao.search(map)), contains(toValues(pId1)));
map = new SearchParameterMap();
map.add(Constants.PARAM_TEXT, new StringParam("DIVAAA"));
assertThat(toUnqualifiedVersionlessIds(myPatientDao.search(map)), contains(pId1));
assertThat(toUnqualifiedVersionlessIdValues(myPatientDao.search(map)), contains(toValues(pId1)));
/*
* Update but don't reindex
@ -458,34 +458,34 @@ public class FhirResourceDaoDstu21SearchFtTest extends BaseJpaDstu21Test {
patient = new Patient();
patient.setId(pId1);
patient.getText().setDiv("<div>DIVBBB</div>");
patient.getText().setDivAsString("<div>DIVBBB</div>");
patient.addName().addGiven("NAMEBBB");
myPatientDao.update(patient, null, false);
map = new SearchParameterMap();
map.add(Constants.PARAM_CONTENT, new StringParam("NAMEAAA"));
assertThat(toUnqualifiedVersionlessIds(myPatientDao.search(map)), contains(pId1));
assertThat(toUnqualifiedVersionlessIdValues(myPatientDao.search(map)), contains(toValues(pId1)));
map = new SearchParameterMap();
map.add(Constants.PARAM_CONTENT, new StringParam("NAMEBBB"));
assertThat(toUnqualifiedVersionlessIds(myPatientDao.search(map)), not(contains(pId1)));
assertThat(toUnqualifiedVersionlessIdValues(myPatientDao.search(map)), not(contains(toValues(pId1))));
myPatientDao.update(patient, null, true);
map = new SearchParameterMap();
map.add(Constants.PARAM_CONTENT, new StringParam("NAMEAAA"));
assertThat(toUnqualifiedVersionlessIds(myPatientDao.search(map)), empty());
assertThat(toUnqualifiedVersionlessIdValues(myPatientDao.search(map)), empty());
map = new SearchParameterMap();
map.add(Patient.SP_NAME, new StringParam("NAMEBBB"));
assertThat(toUnqualifiedVersionlessIds(myPatientDao.search(map)), contains(pId1));
assertThat(toUnqualifiedVersionlessIdValues(myPatientDao.search(map)), contains(toValues(pId1)));
map = new SearchParameterMap();
map.add(Constants.PARAM_CONTENT, new StringParam("NAMEBBB"));
assertThat(toUnqualifiedVersionlessIds(myPatientDao.search(map)), contains(pId1));
assertThat(toUnqualifiedVersionlessIdValues(myPatientDao.search(map)), contains(toValues(pId1)));
map = new SearchParameterMap();
map.add(Constants.PARAM_TEXT, new StringParam("DIVBBB"));
assertThat(toUnqualifiedVersionlessIds(myPatientDao.search(map)), contains(pId1));
assertThat(toUnqualifiedVersionlessIdValues(myPatientDao.search(map)), contains(toValues(pId1)));
}
@ -501,27 +501,27 @@ public class FhirResourceDaoDstu21SearchFtTest extends BaseJpaDstu21Test {
}
Observation obs = new Observation();
obs.getSubject().setReference(pId1);
obs.setValue(new StringDt("This is the FULLtext of the observation"));
obs.getSubject().setReferenceElement(pId1);
obs.setValue(new StringType("This is the FULLtext of the observation"));
IIdType oId1 = myObservationDao.create(obs).getId().toUnqualifiedVersionless();
obs = new Observation();
obs.getSubject().setReference(pId1);
obs.setValue(new StringDt("Another fullText"));
obs.getSubject().setReferenceElement(pId1);
obs.setValue(new StringType("Another fullText"));
IIdType oId2 = myObservationDao.create(obs).getId().toUnqualifiedVersionless();
List<IIdType> patients;
List<String> patients;
SearchParameterMap params;
params = new SearchParameterMap();
params.add(Constants.PARAM_CONTENT, new StringParam("fulltext"));
patients = toUnqualifiedVersionlessIds(myPatientDao.search(params));
assertThat(patients, containsInAnyOrder(pId1));
patients = toUnqualifiedVersionlessIdValues(myPatientDao.search(params));
assertThat(patients, containsInAnyOrder(toValues(pId1)));
params = new SearchParameterMap();
params.add(Constants.PARAM_CONTENT, new StringParam("FULLTEXT"));
patients = toUnqualifiedVersionlessIds(myObservationDao.search(params));
assertThat(patients, containsInAnyOrder(oId1, oId2));
patients = toUnqualifiedVersionlessIdValues(myObservationDao.search(params));
assertThat(patients, containsInAnyOrder(toValues(oId1, oId2)));
}

View File

@ -14,7 +14,6 @@ import static org.junit.Assert.fail;
import static org.mockito.Mockito.mock;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
@ -24,6 +23,35 @@ import java.util.Set;
import javax.servlet.http.HttpServletRequest;
import org.apache.commons.lang3.StringUtils;
import org.hl7.fhir.dstu21.model.BaseResource;
import org.hl7.fhir.dstu21.model.CodeType;
import org.hl7.fhir.dstu21.model.ConceptMap;
import org.hl7.fhir.dstu21.model.ContactPoint.ContactPointSystem;
import org.hl7.fhir.dstu21.model.DateTimeType;
import org.hl7.fhir.dstu21.model.DateType;
import org.hl7.fhir.dstu21.model.Device;
import org.hl7.fhir.dstu21.model.DiagnosticOrder;
import org.hl7.fhir.dstu21.model.DiagnosticReport;
import org.hl7.fhir.dstu21.model.Encounter;
import org.hl7.fhir.dstu21.model.IdType;
import org.hl7.fhir.dstu21.model.Immunization;
import org.hl7.fhir.dstu21.model.Location;
import org.hl7.fhir.dstu21.model.Medication;
import org.hl7.fhir.dstu21.model.MedicationOrder;
import org.hl7.fhir.dstu21.model.Observation;
import org.hl7.fhir.dstu21.model.Organization;
import org.hl7.fhir.dstu21.model.Patient;
import org.hl7.fhir.dstu21.model.Period;
import org.hl7.fhir.dstu21.model.Practitioner;
import org.hl7.fhir.dstu21.model.Quantity;
import org.hl7.fhir.dstu21.model.Reference;
import org.hl7.fhir.dstu21.model.StringType;
import org.hl7.fhir.dstu21.model.Subscription;
import org.hl7.fhir.dstu21.model.Subscription.SubscriptionChannelType;
import org.hl7.fhir.dstu21.model.Subscription.SubscriptionStatus;
import org.hl7.fhir.dstu21.model.Substance;
import org.hl7.fhir.dstu21.model.TemporalPrecisionEnum;
import org.hl7.fhir.dstu21.model.ValueSet;
import org.hl7.fhir.instance.model.api.IBaseResource;
import org.hl7.fhir.instance.model.api.IIdType;
import org.junit.Ignore;
@ -39,44 +67,8 @@ import ca.uhn.fhir.jpa.entity.ResourceIndexedSearchParamToken;
import ca.uhn.fhir.jpa.entity.ResourceIndexedSearchParamUri;
import ca.uhn.fhir.jpa.entity.ResourceLink;
import ca.uhn.fhir.model.api.IQueryParameterType;
import ca.uhn.fhir.model.api.IResource;
import ca.uhn.fhir.model.api.Include;
import ca.uhn.fhir.model.api.ResourceMetadataKeyEnum;
import ca.uhn.fhir.model.api.TagList;
import ca.uhn.fhir.model.api.TemporalPrecisionEnum;
import ca.uhn.fhir.model.base.composite.BaseCodingDt;
import ca.uhn.fhir.model.dstu.resource.BaseResource;
import ca.uhn.fhir.model.dstu.valueset.QuantityCompararatorEnum;
import ca.uhn.fhir.model.dstu21.composite.CodingDt;
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.composite.ResourceReferenceDt;
import ca.uhn.fhir.model.dstu21.resource.ConceptMap;
import ca.uhn.fhir.model.dstu21.resource.Device;
import ca.uhn.fhir.model.dstu21.resource.DiagnosticOrder;
import ca.uhn.fhir.model.dstu21.resource.DiagnosticReport;
import ca.uhn.fhir.model.dstu21.resource.Encounter;
import ca.uhn.fhir.model.dstu21.resource.Immunization;
import ca.uhn.fhir.model.dstu21.resource.Location;
import ca.uhn.fhir.model.dstu21.resource.Medication;
import ca.uhn.fhir.model.dstu21.resource.MedicationOrder;
import ca.uhn.fhir.model.dstu21.resource.Observation;
import ca.uhn.fhir.model.dstu21.resource.Organization;
import ca.uhn.fhir.model.dstu21.resource.Patient;
import ca.uhn.fhir.model.dstu21.resource.Practitioner;
import ca.uhn.fhir.model.dstu21.resource.Subscription;
import ca.uhn.fhir.model.dstu21.resource.Substance;
import ca.uhn.fhir.model.dstu21.resource.ValueSet;
import ca.uhn.fhir.model.dstu21.valueset.ContactPointSystemEnum;
import ca.uhn.fhir.model.dstu21.valueset.SubscriptionChannelTypeEnum;
import ca.uhn.fhir.model.dstu21.valueset.SubscriptionStatusEnum;
import ca.uhn.fhir.model.primitive.CodeDt;
import ca.uhn.fhir.model.primitive.DateDt;
import ca.uhn.fhir.model.primitive.DateTimeDt;
import ca.uhn.fhir.model.primitive.IdDt;
import ca.uhn.fhir.model.primitive.InstantDt;
import ca.uhn.fhir.model.primitive.StringDt;
import ca.uhn.fhir.rest.api.SortOrderEnum;
import ca.uhn.fhir.rest.api.SortSpec;
import ca.uhn.fhir.rest.param.CompositeParam;
@ -104,14 +96,14 @@ public class FhirResourceDaoDstu21SearchNoFtTest extends BaseJpaDstu21Test {
@Test
public void testCodeSearch() {
Subscription subs = new Subscription();
subs.setStatus(SubscriptionStatusEnum.ACTIVE);
subs.getChannel().setType(SubscriptionChannelTypeEnum.WEBSOCKET);
subs.setStatus(SubscriptionStatus.ACTIVE);
subs.getChannel().setType(SubscriptionChannelType.WEBSOCKET);
subs.setCriteria("Observation?");
IIdType id = mySubscriptionDao.create(subs).getId().toUnqualifiedVersionless();
SearchParameterMap map = new SearchParameterMap();
map.add(Subscription.SP_TYPE, new TokenParam(null, SubscriptionChannelTypeEnum.WEBSOCKET.getCode()));
map.add(Subscription.SP_STATUS, new TokenParam(null, SubscriptionStatusEnum.ACTIVE.getCode()));
map.add(Subscription.SP_TYPE, new TokenParam(null, SubscriptionChannelType.WEBSOCKET.toCode()));
map.add(Subscription.SP_STATUS, new TokenParam(null, SubscriptionStatus.ACTIVE.toCode()));
assertThat(toUnqualifiedVersionlessIds(mySubscriptionDao.search(map)), contains(id));
}
@ -129,17 +121,17 @@ public class FhirResourceDaoDstu21SearchNoFtTest extends BaseJpaDstu21Test {
Patient pat = new Patient();
pat.addAddress().addLine(methodName);
pat.getManagingOrganization().setReference(orgId);
pat.getManagingOrganization().setReferenceElement(orgId);
IIdType patId = myPatientDao.create(pat).getId().toUnqualifiedVersionless();
Patient pat2 = new Patient();
pat2.addAddress().addLine(methodName);
pat2.getManagingOrganization().setReference(orgId);
pat2.getManagingOrganization().setReferenceElement(orgId);
IIdType patId2 = myPatientDao.create(pat2).getId().toUnqualifiedVersionless();
MedicationOrder mo = new MedicationOrder();
mo.getPatient().setReference(patId);
mo.setMedication(new ResourceReferenceDt(medId));
mo.getPatient().setReferenceElement(patId);
mo.setMedication(new Reference(medId));
IIdType moId = myMedicationOrderDao.create(mo).getId().toUnqualifiedVersionless();
HttpServletRequest request = mock(HttpServletRequest.class);
@ -154,12 +146,12 @@ public class FhirResourceDaoDstu21SearchNoFtTest extends BaseJpaDstu21Test {
@Test
public void testIndexNoDuplicatesDate() {
DiagnosticOrder order = new DiagnosticOrder();
order.addItem().addEvent().setDateTime(new DateTimeDt("2011-12-11T11:12:12Z"));
order.addItem().addEvent().setDateTime(new DateTimeDt("2011-12-11T11:12:12Z"));
order.addItem().addEvent().setDateTime(new DateTimeDt("2011-12-11T11:12:12Z"));
order.addItem().addEvent().setDateTime(new DateTimeDt("2011-12-12T11:12:12Z"));
order.addItem().addEvent().setDateTime(new DateTimeDt("2011-12-12T11:12:12Z"));
order.addItem().addEvent().setDateTime(new DateTimeDt("2011-12-12T11:12:12Z"));
order.addItem().addEvent().setDateTimeElement(new DateTimeType("2011-12-11T11:12:12Z"));
order.addItem().addEvent().setDateTimeElement(new DateTimeType("2011-12-11T11:12:12Z"));
order.addItem().addEvent().setDateTimeElement(new DateTimeType("2011-12-11T11:12:12Z"));
order.addItem().addEvent().setDateTimeElement(new DateTimeType("2011-12-12T11:12:12Z"));
order.addItem().addEvent().setDateTimeElement(new DateTimeType("2011-12-12T11:12:12Z"));
order.addItem().addEvent().setDateTimeElement(new DateTimeType("2011-12-12T11:12:12Z"));
IIdType id = myDiagnosticOrderDao.create(order).getId().toUnqualifiedVersionless();
@ -224,10 +216,10 @@ public class FhirResourceDaoDstu21SearchNoFtTest extends BaseJpaDstu21Test {
myPractitionerDao.update(pract2);
DiagnosticOrder res = new DiagnosticOrder();
res.addEvent().setActor(new ResourceReferenceDt("Practitioner/somepract"));
res.addEvent().setActor(new ResourceReferenceDt("Practitioner/somepract"));
res.addEvent().setActor(new ResourceReferenceDt("Practitioner/somepract2"));
res.addEvent().setActor(new ResourceReferenceDt("Practitioner/somepract2"));
res.addEvent().setActor(new Reference("Practitioner/somepract"));
res.addEvent().setActor(new Reference("Practitioner/somepract"));
res.addEvent().setActor(new Reference("Practitioner/somepract2"));
res.addEvent().setActor(new Reference("Practitioner/somepract2"));
IIdType id = myDiagnosticOrderDao.create(res).getId().toUnqualifiedVersionless();
@ -335,13 +327,13 @@ public class FhirResourceDaoDstu21SearchNoFtTest extends BaseJpaDstu21Test {
}
Map<String, IQueryParameterType> params = new HashMap<String, IQueryParameterType>();
params.put("_id", new StringDt(id1.getIdPart()));
params.put("_id", new StringParam(id1.getIdPart()));
assertEquals(1, toList(myPatientDao.search(params)).size());
params.put("_id", new StringDt("9999999999999999"));
params.put("_id", new StringParam("9999999999999999"));
assertEquals(0, toList(myPatientDao.search(params)).size());
params.put("_id", new StringDt(id2.getIdPart()));
params.put("_id", new StringParam(id2.getIdPart()));
assertEquals(0, toList(myPatientDao.search(params)).size());
}
@ -456,12 +448,12 @@ public class FhirResourceDaoDstu21SearchNoFtTest extends BaseJpaDstu21Test {
public void testSearchCompositeParam() {
Observation o1 = new Observation();
o1.getCode().addCoding().setSystem("foo").setCode("testSearchCompositeParamN01");
o1.setValue(new StringDt("testSearchCompositeParamS01"));
o1.setValue(new StringType("testSearchCompositeParamS01"));
IIdType id1 = myObservationDao.create(o1).getId();
Observation o2 = new Observation();
o2.getCode().addCoding().setSystem("foo").setCode("testSearchCompositeParamN01");
o2.setValue(new StringDt("testSearchCompositeParamS02"));
o2.setValue(new StringType("testSearchCompositeParamS02"));
IIdType id2 = myObservationDao.create(o2).getId();
{
@ -486,12 +478,12 @@ public class FhirResourceDaoDstu21SearchNoFtTest extends BaseJpaDstu21Test {
public void testSearchCompositeParamDate() {
Observation o1 = new Observation();
o1.getCode().addCoding().setSystem("foo").setCode("testSearchCompositeParamDateN01");
o1.setValue(new PeriodDt().setStart(new DateTimeDt("2001-01-01T11:11:11")));
o1.setValue(new Period().setStartElement(new DateTimeType("2001-01-01T11:11:11")));
IIdType id1 = myObservationDao.create(o1).getId().toUnqualifiedVersionless();
Observation o2 = new Observation();
o2.getCode().addCoding().setSystem("foo").setCode("testSearchCompositeParamDateN01");
o2.setValue(new PeriodDt().setStart(new DateTimeDt("2001-01-01T12:12:12")));
o2.setValue(new Period().setStartElement(new DateTimeType("2001-01-01T12:12:12")));
IIdType id2 = myObservationDao.create(o2).getId().toUnqualifiedVersionless();
{
@ -524,14 +516,14 @@ public class FhirResourceDaoDstu21SearchNoFtTest extends BaseJpaDstu21Test {
{
Patient patient = new Patient();
patient.setId("TEST");
patient.setLanguage(new CodeDt("TEST"));
patient.setLanguageElement(new CodeType("TEST"));
patient.addName().addFamily("TEST");
patient.addIdentifier().setSystem("TEST").setValue("TEST");
myPatientDao.update(patient);
}
Map<String, IQueryParameterType> params = new HashMap<String, IQueryParameterType>();
params.put("_id", new StringDt("TEST"));
params.put("_id", new StringParam("TEST"));
assertEquals(1, toList(myPatientDao.search(params)).size());
params.put("_language", new StringParam("TEST"));
@ -543,10 +535,10 @@ public class FhirResourceDaoDstu21SearchNoFtTest extends BaseJpaDstu21Test {
params.put(Patient.SP_NAME, new StringParam("TEST"));
assertEquals(1, toList(myPatientDao.search(params)).size());
myPatientDao.delete(new IdDt("Patient/TEST"));
myPatientDao.delete(new IdType("Patient/TEST"));
params = new HashMap<String, IQueryParameterType>();
params.put("_id", new StringDt("TEST"));
params.put("_id", new StringParam("TEST"));
assertEquals(0, toList(myPatientDao.search(params)).size());
params.put("_language", new StringParam("TEST"));
@ -576,7 +568,7 @@ public class FhirResourceDaoDstu21SearchNoFtTest extends BaseJpaDstu21Test {
IIdType id1;
{
Patient patient = new Patient();
patient.getLanguage().setValue("en_CA");
patient.getLanguageElement().setValue("en_CA");
patient.addIdentifier().setSystem("urn:system").setValue("001");
patient.addName().addFamily("testSearchLanguageParam").addGiven("Joe");
id1 = myPatientDao.create(patient).getId();
@ -584,7 +576,7 @@ public class FhirResourceDaoDstu21SearchNoFtTest extends BaseJpaDstu21Test {
IIdType id2;
{
Patient patient = new Patient();
patient.getLanguage().setValue("en_US");
patient.getLanguageElement().setValue("en_US");
patient.addIdentifier().setSystem("urn:system").setValue("002");
patient.addName().addFamily("testSearchLanguageParam").addGiven("John");
id2 = myPatientDao.create(patient).getId();
@ -592,16 +584,16 @@ public class FhirResourceDaoDstu21SearchNoFtTest extends BaseJpaDstu21Test {
{
Map<String, IQueryParameterType> params = new HashMap<String, IQueryParameterType>();
params.put(BaseResource.SP_RES_LANGUAGE, new StringParam("en_CA"));
List<IResource> patients = toList(myPatientDao.search(params));
List<IBaseResource> patients = toList(myPatientDao.search(params));
assertEquals(1, patients.size());
assertEquals(id1.toUnqualifiedVersionless(), patients.get(0).getId().toUnqualifiedVersionless());
assertEquals(id1.toUnqualifiedVersionless(), patients.get(0).getIdElement().toUnqualifiedVersionless());
}
{
Map<String, IQueryParameterType> params = new HashMap<String, IQueryParameterType>();
params.put(BaseResource.SP_RES_LANGUAGE, new StringParam("en_US"));
List<Patient> patients = toList(myPatientDao.search(params));
assertEquals(1, patients.size());
assertEquals(id2.toUnqualifiedVersionless(), patients.get(0).getId().toUnqualifiedVersionless());
assertEquals(id2.toUnqualifiedVersionless(), patients.get(0).getIdElement().toUnqualifiedVersionless());
}
{
Map<String, IQueryParameterType> params = new HashMap<String, IQueryParameterType>();
@ -616,7 +608,7 @@ public class FhirResourceDaoDstu21SearchNoFtTest extends BaseJpaDstu21Test {
IIdType id1;
{
Patient patient = new Patient();
patient.getLanguage().setValue("en_CA");
patient.getLanguageElement().setValue("en_CA");
patient.addIdentifier().setSystem("urn:system").setValue("001");
patient.addName().addFamily("testSearchLanguageParam").addGiven("Joe");
id1 = myPatientDao.create(patient).getId().toUnqualifiedVersionless();
@ -627,7 +619,7 @@ public class FhirResourceDaoDstu21SearchNoFtTest extends BaseJpaDstu21Test {
IIdType id2;
{
Patient patient = new Patient();
patient.getLanguage().setValue("en_US");
patient.getLanguageElement().setValue("en_US");
patient.addIdentifier().setSystem("urn:system").setValue("002");
patient.addName().addFamily("testSearchLanguageParam").addGiven("John");
id2 = myPatientDao.create(patient).getId().toUnqualifiedVersionless();
@ -708,7 +700,7 @@ public class FhirResourceDaoDstu21SearchNoFtTest extends BaseJpaDstu21Test {
int sleep = 100;
Thread.sleep(sleep);
DateTimeDt beforeAny = new DateTimeDt(new Date(), TemporalPrecisionEnum.MILLI);
DateTimeType beforeAny = new DateTimeType(new Date(), TemporalPrecisionEnum.MILLI);
IIdType id1a;
{
Patient patient = new Patient();
@ -725,7 +717,7 @@ public class FhirResourceDaoDstu21SearchNoFtTest extends BaseJpaDstu21Test {
}
Thread.sleep(1100);
DateTimeDt beforeR2 = new DateTimeDt(new Date(), TemporalPrecisionEnum.MILLI);
DateTimeType beforeR2 = new DateTimeType(new Date(), TemporalPrecisionEnum.MILLI);
Thread.sleep(1100);
IIdType id2;
@ -786,7 +778,7 @@ public class FhirResourceDaoDstu21SearchNoFtTest extends BaseJpaDstu21Test {
long start = System.currentTimeMillis();
Thread.sleep(sleep);
DateTimeDt beforeAny = new DateTimeDt(new Date(), TemporalPrecisionEnum.MILLI);
DateTimeType beforeAny = new DateTimeType(new Date(), TemporalPrecisionEnum.MILLI);
IIdType id1a;
{
Patient patient = new Patient();
@ -800,10 +792,9 @@ public class FhirResourceDaoDstu21SearchNoFtTest extends BaseJpaDstu21Test {
id1b = myPatientDao.create(patient).getId().toUnqualifiedVersionless();
}
ourLog.info("Res 1: {}", ResourceMetadataKeyEnum.PUBLISHED.get(myPatientDao.read(id0)).getValueAsString());
ourLog.info("Res 2: {}", ResourceMetadataKeyEnum.PUBLISHED.get(myPatientDao.read(id1a)).getValueAsString());
InstantDt id1bpublished = ResourceMetadataKeyEnum.PUBLISHED.get(myPatientDao.read(id1b));
ourLog.info("Res 3: {}", id1bpublished.getValueAsString());
ourLog.info("Res 1: {}", myPatientDao.read(id0).getMeta().getLastUpdatedElement().getValueAsString());
ourLog.info("Res 2: {}", myPatientDao.read(id1a).getMeta().getLastUpdatedElement().getValueAsString());
ourLog.info("Res 3: {}", myPatientDao.read(id1b).getMeta().getLastUpdatedElement().getValueAsString());
Thread.sleep(sleep);
@ -812,8 +803,8 @@ public class FhirResourceDaoDstu21SearchNoFtTest extends BaseJpaDstu21Test {
SearchParameterMap map;
Date startDate = new Date(start);
Date endDate = new Date(end);
DateTimeDt startDateTime = new DateTimeDt(startDate, TemporalPrecisionEnum.MILLI);
DateTimeDt endDateTime = new DateTimeDt(endDate, TemporalPrecisionEnum.MILLI);
DateTimeType startDateTime = new DateTimeType(startDate, TemporalPrecisionEnum.MILLI);
DateTimeType endDateTime = new DateTimeType(endDate, TemporalPrecisionEnum.MILLI);
map = new SearchParameterMap();
map.setLastUpdated(new DateRangeParam(startDateTime, endDateTime));
@ -831,7 +822,7 @@ public class FhirResourceDaoDstu21SearchNoFtTest extends BaseJpaDstu21Test {
assertThat(toUnqualifiedVersionlessIds(myPatientDao.search(map)), containsInAnyOrder(id1a, id1b));
map = new SearchParameterMap();
map.setLastUpdated(new DateRangeParam(new DateParam(QuantityCompararatorEnum.GREATERTHAN, startDateTime.getValue()), new DateParam(QuantityCompararatorEnum.LESSTHAN, id1bpublished.getValue())));
map.setLastUpdated(new DateRangeParam(new DateParam(QuantityCompararatorEnum.GREATERTHAN, startDateTime.getValue()), new DateParam(QuantityCompararatorEnum.LESSTHAN, myPatientDao.read(id1b).getMeta().getLastUpdatedElement().getValue())));
ourLog.info("Searching: {}", map.getLastUpdated());
assertThat(toUnqualifiedVersionlessIds(myPatientDao.search(map)), containsInAnyOrder(id1a));
}
@ -842,7 +833,6 @@ public class FhirResourceDaoDstu21SearchNoFtTest extends BaseJpaDstu21Test {
Patient patient = new Patient();
patient.addIdentifier().setSystem("urn:system").setValue("001");
patient.addName().addFamily("testSearchNameParam01Fam").addGiven("testSearchNameParam01Giv");
ResourceMetadataKeyEnum.TITLE.put(patient, "P1TITLE");
id1 = myPatientDao.create(patient).getId();
}
{
@ -853,32 +843,31 @@ public class FhirResourceDaoDstu21SearchNoFtTest extends BaseJpaDstu21Test {
}
Map<String, IQueryParameterType> params = new HashMap<String, IQueryParameterType>();
params.put(Patient.SP_FAMILY, new StringDt("testSearchNameParam01Fam"));
params.put(Patient.SP_FAMILY, new StringParam("testSearchNameParam01Fam"));
List<Patient> patients = toList(myPatientDao.search(params));
assertEquals(1, patients.size());
assertEquals(id1.getIdPart(), patients.get(0).getId().getIdPart());
assertEquals("P1TITLE", ResourceMetadataKeyEnum.TITLE.get(patients.get(0)));
assertEquals(id1.getIdPart(), patients.get(0).getIdElement().getIdPart());
// Given name shouldn't return for family param
params = new HashMap<String, IQueryParameterType>();
params.put(Patient.SP_FAMILY, new StringDt("testSearchNameParam01Giv"));
params.put(Patient.SP_FAMILY, new StringParam("testSearchNameParam01Giv"));
patients = toList(myPatientDao.search(params));
assertEquals(0, patients.size());
params = new HashMap<String, IQueryParameterType>();
params.put(Patient.SP_NAME, new StringDt("testSearchNameParam01Fam"));
params.put(Patient.SP_NAME, new StringParam("testSearchNameParam01Fam"));
patients = toList(myPatientDao.search(params));
assertEquals(1, patients.size());
assertEquals(id1.getIdPart(), patients.get(0).getId().getIdPart());
assertEquals(id1.getIdPart(), patients.get(0).getIdElement().getIdPart());
params = new HashMap<String, IQueryParameterType>();
params.put(Patient.SP_NAME, new StringDt("testSearchNameParam01Giv"));
params.put(Patient.SP_NAME, new StringParam("testSearchNameParam01Giv"));
patients = toList(myPatientDao.search(params));
assertEquals(1, patients.size());
assertEquals(id1.getIdPart(), patients.get(0).getId().getIdPart());
assertEquals(id1.getIdPart(), patients.get(0).getIdElement().getIdPart());
params = new HashMap<String, IQueryParameterType>();
params.put(Patient.SP_FAMILY, new StringDt("testSearchNameParam01Foo"));
params.put(Patient.SP_FAMILY, new StringParam("testSearchNameParam01Foo"));
patients = toList(myPatientDao.search(params));
assertEquals(0, patients.size());
@ -937,7 +926,7 @@ public class FhirResourceDaoDstu21SearchNoFtTest extends BaseJpaDstu21Test {
}
Map<String, IQueryParameterType> params = new HashMap<String, IQueryParameterType>();
params.put(Patient.SP_FAMILY, new StringDt(name));
params.put(Patient.SP_FAMILY, new StringParam(name));
List<IIdType> patients = toUnqualifiedVersionlessIds(myPatientDao.search(params));
assertThat(patients, contains(id));
@ -947,7 +936,7 @@ public class FhirResourceDaoDstu21SearchNoFtTest extends BaseJpaDstu21Test {
myPatientDao.update(patient);
params = new HashMap<String, IQueryParameterType>();
params.put(Patient.SP_FAMILY, new StringDt(name));
params.put(Patient.SP_FAMILY, new StringParam(name));
patients = toUnqualifiedVersionlessIds(myPatientDao.search(params));
assertThat(patients, not(contains(id)));
@ -960,14 +949,14 @@ public class FhirResourceDaoDstu21SearchNoFtTest extends BaseJpaDstu21Test {
{
Practitioner patient = new Practitioner();
patient.getName().addFamily(methodName);
patient.addTelecom().setSystem(ContactPointSystemEnum.PHONE).setValue("123");
patient.addTelecom().setSystem(ContactPointSystem.PHONE).setValue("123");
id1 = myPractitionerDao.create(patient).getId().toUnqualifiedVersionless();
}
IIdType id2;
{
Practitioner patient = new Practitioner();
patient.getName().addFamily(methodName);
patient.addTelecom().setSystem(ContactPointSystemEnum.EMAIL).setValue("abc");
patient.addTelecom().setSystem(ContactPointSystem.EMAIL).setValue("abc");
id2 = myPractitionerDao.create(patient).getId().toUnqualifiedVersionless();
}
@ -975,7 +964,7 @@ public class FhirResourceDaoDstu21SearchNoFtTest extends BaseJpaDstu21Test {
List<IIdType> patients;
params = new HashMap<String, IQueryParameterType>();
params.put(Practitioner.SP_FAMILY, new StringDt(methodName));
params.put(Practitioner.SP_FAMILY, new StringParam(methodName));
patients = toUnqualifiedVersionlessIds(myPractitionerDao.search(params));
assertEquals(2, patients.size());
assertThat(patients, containsInAnyOrder(id1, id2));
@ -1015,25 +1004,25 @@ public class FhirResourceDaoDstu21SearchNoFtTest extends BaseJpaDstu21Test {
IIdType patientId02 = myPatientDao.create(patient02).getId();
Observation obs01 = new Observation();
obs01.setEffective(new DateTimeDt(new Date()));
obs01.setSubject(new ResourceReferenceDt(patientId01));
obs01.setEffective(new DateTimeType(new Date()));
obs01.setSubject(new Reference(patientId01));
IIdType obsId01 = myObservationDao.create(obs01).getId();
Observation obs02 = new Observation();
obs02.setEffective(new DateTimeDt(new Date()));
obs02.setSubject(new ResourceReferenceDt(patientId02));
obs02.setEffective(new DateTimeType(new Date()));
obs02.setSubject(new Reference(patientId02));
IIdType obsId02 = myObservationDao.create(obs02).getId();
// Create another type, that shouldn't be returned
DiagnosticReport dr01 = new DiagnosticReport();
dr01.setSubject(new ResourceReferenceDt(patientId01));
dr01.setSubject(new Reference(patientId01));
IIdType drId01 = myDiagnosticReportDao.create(dr01).getId();
ourLog.info("P1[{}] P2[{}] O1[{}] O2[{}] D1[{}]", new Object[] { patientId01, patientId02, obsId01, obsId02, drId01 });
List<Observation> result = toList(myObservationDao.search(Observation.SP_SUBJECT, new ReferenceParam(Patient.SP_IDENTIFIER, "urn:system|testSearchResourceLinkWithChain01")));
assertEquals(1, result.size());
assertEquals(obsId01.getIdPart(), result.get(0).getId().getIdPart());
assertEquals(obsId01.getIdPart(), result.get(0).getIdElement().getIdPart());
result = toList(myObservationDao.search(Observation.SP_PATIENT, new ReferenceParam(patientId01.getIdPart())));
assertEquals(1, result.size());
@ -1064,15 +1053,15 @@ public class FhirResourceDaoDstu21SearchNoFtTest extends BaseJpaDstu21Test {
IIdType orgId01 = myOrganizationDao.create(org).getId().toUnqualifiedVersionless();
Location locParent = new Location();
locParent.setManagingOrganization(new ResourceReferenceDt(orgId01));
locParent.setManagingOrganization(new Reference(orgId01));
IIdType locParentId = myLocationDao.create(locParent).getId().toUnqualifiedVersionless();
Location locChild = new Location();
locChild.setPartOf(new ResourceReferenceDt(locParentId));
locChild.setPartOf(new Reference(locParentId));
IIdType locChildId = myLocationDao.create(locChild).getId().toUnqualifiedVersionless();
Location locGrandchild = new Location();
locGrandchild.setPartOf(new ResourceReferenceDt(locChildId));
locGrandchild.setPartOf(new Reference(locChildId));
IIdType locGrandchildId = myLocationDao.create(locGrandchild).getId().toUnqualifiedVersionless();
IBundleProvider found;
@ -1113,13 +1102,13 @@ public class FhirResourceDaoDstu21SearchNoFtTest extends BaseJpaDstu21Test {
IIdType locId01 = myLocationDao.create(loc01).getId();
Observation obs01 = new Observation();
obs01.setEffective(new DateTimeDt(new Date()));
obs01.setSubject(new ResourceReferenceDt(patientId01));
obs01.setEffective(new DateTimeType(new Date()));
obs01.setSubject(new Reference(patientId01));
IIdType obsId01 = myObservationDao.create(obs01).getId();
Observation obs02 = new Observation();
obs02.setEffective(new DateTimeDt(new Date()));
obs02.setSubject(new ResourceReferenceDt(locId01));
obs02.setEffective(new DateTimeType(new Date()));
obs02.setSubject(new Reference(locId01));
IIdType obsId02 = myObservationDao.create(obs02).getId();
ourLog.info("P1[{}] L1[{}] Obs1[{}] Obs2[{}]", new Object[] { patientId01, locId01, obsId01, obsId02 });
@ -1128,7 +1117,7 @@ public class FhirResourceDaoDstu21SearchNoFtTest extends BaseJpaDstu21Test {
result = toList(myObservationDao.search(Observation.SP_SUBJECT, new ReferenceParam("Patient", Patient.SP_NAME, "testSearchResourceLinkWithChainWithMultipleTypes01")));
assertEquals(1, result.size());
assertEquals(obsId01.getIdPart(), result.get(0).getId().getIdPart());
assertEquals(obsId01.getIdPart(), result.get(0).getIdElement().getIdPart());
result = toList(myObservationDao.search(Observation.SP_SUBJECT, new ReferenceParam(Patient.SP_NAME, "testSearchResourceLinkWithChainWithMultipleTypes01")));
assertEquals(2, result.size());
@ -1156,25 +1145,25 @@ public class FhirResourceDaoDstu21SearchNoFtTest extends BaseJpaDstu21Test {
IIdType patientId02 = myPatientDao.update(patient02).getId();
Observation obs01 = new Observation();
obs01.setEffective(new DateTimeDt(new Date()));
obs01.setSubject(new ResourceReferenceDt(patientId01));
obs01.setEffective(new DateTimeType(new Date()));
obs01.setSubject(new Reference(patientId01));
IIdType obsId01 = myObservationDao.create(obs01).getId();
Observation obs02 = new Observation();
obs02.setEffective(new DateTimeDt(new Date()));
obs02.setSubject(new ResourceReferenceDt(patientId02));
obs02.setEffective(new DateTimeType(new Date()));
obs02.setSubject(new Reference(patientId02));
IIdType obsId02 = myObservationDao.create(obs02).getId();
// Create another type, that shouldn't be returned
DiagnosticReport dr01 = new DiagnosticReport();
dr01.setSubject(new ResourceReferenceDt(patientId01));
dr01.setSubject(new Reference(patientId01));
IIdType drId01 = myDiagnosticReportDao.create(dr01).getId();
ourLog.info("P1[{}] P2[{}] O1[{}] O2[{}] D1[{}]", new Object[] { patientId01, patientId02, obsId01, obsId02, drId01 });
List<Observation> result = toList(myObservationDao.search(Observation.SP_SUBJECT, new ReferenceParam("testSearchResourceLinkWithTextLogicalId01")));
assertEquals(1, result.size());
assertEquals(obsId01.getIdPart(), result.get(0).getId().getIdPart());
assertEquals(obsId01.getIdPart(), result.get(0).getIdElement().getIdPart());
try {
myObservationDao.search(Observation.SP_SUBJECT, new ReferenceParam("testSearchResourceLinkWithTextLogicalId99"));
@ -1209,11 +1198,11 @@ public class FhirResourceDaoDstu21SearchNoFtTest extends BaseJpaDstu21Test {
}
Map<String, IQueryParameterType> params = new HashMap<String, IQueryParameterType>();
params.put(Patient.SP_FAMILY, new StringDt("Tester_testSearchStringParam"));
params.put(Patient.SP_FAMILY, new StringParam("Tester_testSearchStringParam"));
List<Patient> patients = toList(myPatientDao.search(params));
assertEquals(2, patients.size());
params.put(Patient.SP_FAMILY, new StringDt("FOO_testSearchStringParam"));
params.put(Patient.SP_FAMILY, new StringParam("FOO_testSearchStringParam"));
patients = toList(myPatientDao.search(params));
assertEquals(0, patients.size());
@ -1264,7 +1253,7 @@ public class FhirResourceDaoDstu21SearchNoFtTest extends BaseJpaDstu21Test {
}
Map<String, IQueryParameterType> params = new HashMap<String, IQueryParameterType>();
params.put(Patient.SP_GIVEN, new StringDt("testSearchStringParamWithNonNormalized_hora"));
params.put(Patient.SP_GIVEN, new StringParam("testSearchStringParamWithNonNormalized_hora"));
List<Patient> patients = toList(myPatientDao.search(params));
assertEquals(2, patients.size());
@ -1291,19 +1280,19 @@ public class FhirResourceDaoDstu21SearchNoFtTest extends BaseJpaDstu21Test {
{
SearchParameterMap map = new SearchParameterMap();
map.add(Patient.SP_IDENTIFIER, new IdentifierDt("urn:system", "testSearchTokenParam001"));
map.add(Patient.SP_IDENTIFIER, new TokenParam("urn:system", "testSearchTokenParam001"));
IBundleProvider retrieved = myPatientDao.search(map);
assertEquals(1, retrieved.size());
}
{
SearchParameterMap map = new SearchParameterMap();
map.add(Patient.SP_IDENTIFIER, new IdentifierDt(null, "testSearchTokenParam001"));
map.add(Patient.SP_IDENTIFIER, new TokenParam(null, "testSearchTokenParam001"));
IBundleProvider retrieved = myPatientDao.search(map);
assertEquals(1, retrieved.size());
}
{
SearchParameterMap map = new SearchParameterMap();
map.add(Patient.SP_LANGUAGE, new IdentifierDt("testSearchTokenParamSystem", "testSearchTokenParamCode"));
map.add(Patient.SP_LANGUAGE, new TokenParam("testSearchTokenParamSystem", "testSearchTokenParamCode"));
assertEquals(1, myPatientDao.search(map).size());
}
{
@ -1332,8 +1321,8 @@ public class FhirResourceDaoDstu21SearchNoFtTest extends BaseJpaDstu21Test {
{
SearchParameterMap map = new SearchParameterMap();
TokenOrListParam listParam = new TokenOrListParam();
listParam.add(new IdentifierDt("urn:system", "testSearchTokenParam001"));
listParam.add(new IdentifierDt("urn:system", "testSearchTokenParam002"));
listParam.add("urn:system", "testSearchTokenParam001");
listParam.add("urn:system", "testSearchTokenParam002");
map.add(Patient.SP_IDENTIFIER, listParam);
IBundleProvider retrieved = myPatientDao.search(map);
assertEquals(2, retrieved.size());
@ -1341,8 +1330,8 @@ public class FhirResourceDaoDstu21SearchNoFtTest extends BaseJpaDstu21Test {
{
SearchParameterMap map = new SearchParameterMap();
TokenOrListParam listParam = new TokenOrListParam();
listParam.add(new IdentifierDt(null, "testSearchTokenParam001"));
listParam.add(new IdentifierDt("urn:system", "testSearchTokenParam002"));
listParam.add(null, "testSearchTokenParam001");
listParam.add("urn:system", "testSearchTokenParam002");
map.add(Patient.SP_IDENTIFIER, listParam);
IBundleProvider retrieved = myPatientDao.search(map);
assertEquals(2, retrieved.size());
@ -1353,7 +1342,7 @@ public class FhirResourceDaoDstu21SearchNoFtTest extends BaseJpaDstu21Test {
@Ignore
public void testSearchUnknownContentParam() {
SearchParameterMap params = new SearchParameterMap();
params.add(Constants.PARAM_CONTENT, new StringDt("fulltext"));
params.add(Constants.PARAM_CONTENT, new StringParam("fulltext"));
try {
myPatientDao.search(params);
fail();
@ -1366,7 +1355,7 @@ public class FhirResourceDaoDstu21SearchNoFtTest extends BaseJpaDstu21Test {
@Ignore
public void testSearchUnknownTextParam() {
SearchParameterMap params = new SearchParameterMap();
params.add(Constants.PARAM_TEXT, new StringDt("fulltext"));
params.add(Constants.PARAM_TEXT, new StringParam("fulltext"));
try {
myPatientDao.search(params);
fail();
@ -1387,7 +1376,7 @@ public class FhirResourceDaoDstu21SearchNoFtTest extends BaseJpaDstu21Test {
Observation o = new Observation();
o.getCode().addCoding().setSystem("urn:foo").setCode(methodName + "code");
QuantityDt q = new QuantityDt().setSystem("urn:bar:" + methodName).setCode(methodName + "units").setValue(100);
Quantity q = new Quantity().setSystem("urn:bar:" + methodName).setCode(methodName + "units").setValue(100);
o.setValue(q);
myObservationDao.create(o);
@ -1434,13 +1423,13 @@ public class FhirResourceDaoDstu21SearchNoFtTest extends BaseJpaDstu21Test {
{
Organization org = new Organization();
org.getNameElement().setValue(methodName + "_O1");
org.setPartOf(new ResourceReferenceDt(parentOrgId));
org.setPartOf(new Reference(parentOrgId));
IIdType orgId = myOrganizationDao.create(org).getId();
Patient patient = new Patient();
patient.addIdentifier().setSystem("urn:system").setValue("001");
patient.addName().addFamily("Tester_" + methodName + "_P1").addGiven("Joe");
patient.getManagingOrganization().setReference(orgId);
patient.getManagingOrganization().setReferenceElement(orgId);
myPatientDao.create(patient);
}
{
@ -1453,14 +1442,14 @@ public class FhirResourceDaoDstu21SearchNoFtTest extends BaseJpaDstu21Test {
{
// No includes
SearchParameterMap params = new SearchParameterMap();
params.add(Patient.SP_FAMILY, new StringDt("Tester_" + methodName + "_P1"));
params.add(Patient.SP_FAMILY, new StringParam("Tester_" + methodName + "_P1"));
List<IBaseResource> patients = toList(myPatientDao.search(params));
assertEquals(1, patients.size());
}
{
// Named include
SearchParameterMap params = new SearchParameterMap();
params.add(Patient.SP_FAMILY, new StringDt("Tester_" + methodName + "_P1"));
params.add(Patient.SP_FAMILY, new StringParam("Tester_" + methodName + "_P1"));
params.addInclude(Patient.INCLUDE_ORGANIZATION.asNonRecursive());
IBundleProvider search = myPatientDao.search(params);
List<IBaseResource> patients = toList(search);
@ -1471,11 +1460,11 @@ public class FhirResourceDaoDstu21SearchNoFtTest extends BaseJpaDstu21Test {
{
// Named include with parent non-recursive
SearchParameterMap params = new SearchParameterMap();
params.add(Patient.SP_FAMILY, new StringDt("Tester_" + methodName + "_P1"));
params.add(Patient.SP_FAMILY, new StringParam("Tester_" + methodName + "_P1"));
params.addInclude(Patient.INCLUDE_ORGANIZATION);
params.addInclude(Organization.INCLUDE_PARTOF.asNonRecursive());
IBundleProvider search = myPatientDao.search(params);
List<IResource> patients = toList(search);
List<IBaseResource> patients = toList(search);
assertEquals(2, patients.size());
assertEquals(Patient.class, patients.get(0).getClass());
assertEquals(Organization.class, patients.get(1).getClass());
@ -1483,11 +1472,11 @@ public class FhirResourceDaoDstu21SearchNoFtTest extends BaseJpaDstu21Test {
{
// Named include with parent recursive
SearchParameterMap params = new SearchParameterMap();
params.add(Patient.SP_FAMILY, new StringDt("Tester_" + methodName + "_P1"));
params.add(Patient.SP_FAMILY, new StringParam("Tester_" + methodName + "_P1"));
params.addInclude(Patient.INCLUDE_ORGANIZATION);
params.addInclude(Organization.INCLUDE_PARTOF.asRecursive());
IBundleProvider search = myPatientDao.search(params);
List<IResource> patients = toList(search);
List<IBaseResource> patients = toList(search);
assertEquals(3, patients.size());
assertEquals(Patient.class, patients.get(0).getClass());
assertEquals(Organization.class, patients.get(1).getClass());
@ -1496,10 +1485,10 @@ public class FhirResourceDaoDstu21SearchNoFtTest extends BaseJpaDstu21Test {
{
// * include non recursive
SearchParameterMap params = new SearchParameterMap();
params.add(Patient.SP_FAMILY, new StringDt("Tester_" + methodName + "_P1"));
params.addInclude(IResource.INCLUDE_ALL.asNonRecursive());
params.add(Patient.SP_FAMILY, new StringParam("Tester_" + methodName + "_P1"));
params.addInclude(IBaseResource.INCLUDE_ALL.asNonRecursive());
IBundleProvider search = myPatientDao.search(params);
List<IResource> patients = toList(search);
List<IBaseResource> patients = toList(search);
assertEquals(2, patients.size());
assertEquals(Patient.class, patients.get(0).getClass());
assertEquals(Organization.class, patients.get(1).getClass());
@ -1507,10 +1496,10 @@ public class FhirResourceDaoDstu21SearchNoFtTest extends BaseJpaDstu21Test {
{
// * include recursive
SearchParameterMap params = new SearchParameterMap();
params.add(Patient.SP_FAMILY, new StringDt("Tester_" + methodName + "_P1"));
params.addInclude(IResource.INCLUDE_ALL.asRecursive());
params.add(Patient.SP_FAMILY, new StringParam("Tester_" + methodName + "_P1"));
params.addInclude(IBaseResource.INCLUDE_ALL.asRecursive());
IBundleProvider search = myPatientDao.search(params);
List<IResource> patients = toList(search);
List<IBaseResource> patients = toList(search);
assertEquals(3, patients.size());
assertEquals(Patient.class, patients.get(0).getClass());
assertEquals(Organization.class, patients.get(1).getClass());
@ -1519,10 +1508,10 @@ public class FhirResourceDaoDstu21SearchNoFtTest extends BaseJpaDstu21Test {
{
// Irrelevant include
SearchParameterMap params = new SearchParameterMap();
params.add(Patient.SP_FAMILY, new StringDt("Tester_" + methodName + "_P1"));
params.add(Patient.SP_FAMILY, new StringParam("Tester_" + methodName + "_P1"));
params.addInclude(Encounter.INCLUDE_INDICATION);
IBundleProvider search = myPatientDao.search(params);
List<IResource> patients = toList(search);
List<IBaseResource> patients = toList(search);
assertEquals(1, patients.size());
assertEquals(Patient.class, patients.get(0).getClass());
}
@ -1542,14 +1531,14 @@ public class FhirResourceDaoDstu21SearchNoFtTest extends BaseJpaDstu21Test {
{
Organization org = new Organization();
org.getNameElement().setValue(methodName + "_O1Parent");
org.setPartOf(new ResourceReferenceDt(parentParentOrgId));
org.setPartOf(new Reference(parentParentOrgId));
parentOrgId = myOrganizationDao.create(org).getId().toUnqualifiedVersionless();
}
IIdType orgId;
{
Organization org = new Organization();
org.getNameElement().setValue(methodName + "_O1");
org.setPartOf(new ResourceReferenceDt(parentOrgId));
org.setPartOf(new Reference(parentOrgId));
orgId = myOrganizationDao.create(org).getId().toUnqualifiedVersionless();
}
IIdType patientId;
@ -1557,13 +1546,13 @@ public class FhirResourceDaoDstu21SearchNoFtTest extends BaseJpaDstu21Test {
Patient patient = new Patient();
patient.addIdentifier().setSystem("urn:system").setValue("001");
patient.addName().addFamily("Tester_" + methodName + "_P1").addGiven("Joe");
patient.getManagingOrganization().setReference(orgId);
patient.getManagingOrganization().setReferenceElement(orgId);
patientId = myPatientDao.create(patient).getId().toUnqualifiedVersionless();
}
{
SearchParameterMap params = new SearchParameterMap();
params.add(ca.uhn.fhir.model.dstu21.resource.BaseResource.SP_RES_ID, new StringDt(orgId.getIdPart()));
params.add(BaseResource.SP_RES_ID, new StringParam(orgId.getIdPart()));
params.addInclude(Organization.INCLUDE_PARTOF.asNonRecursive());
List<IIdType> resources = toUnqualifiedVersionlessIds(myOrganizationDao.search(params));
assertThat(resources, contains(orgId, parentOrgId));
@ -1584,14 +1573,14 @@ public class FhirResourceDaoDstu21SearchNoFtTest extends BaseJpaDstu21Test {
{
Organization org = new Organization();
org.getNameElement().setValue(methodName + "_O1Parent");
org.setPartOf(new ResourceReferenceDt(parentParentOrgId));
org.setPartOf(new Reference(parentParentOrgId));
parentOrgId = myOrganizationDao.create(org).getId().toUnqualifiedVersionless();
}
IIdType orgId;
{
Organization org = new Organization();
org.getNameElement().setValue(methodName + "_O1");
org.setPartOf(new ResourceReferenceDt(parentOrgId));
org.setPartOf(new Reference(parentOrgId));
orgId = myOrganizationDao.create(org).getId().toUnqualifiedVersionless();
}
IIdType patientId;
@ -1599,13 +1588,13 @@ public class FhirResourceDaoDstu21SearchNoFtTest extends BaseJpaDstu21Test {
Patient patient = new Patient();
patient.addIdentifier().setSystem("urn:system").setValue("001");
patient.addName().addFamily("Tester_" + methodName + "_P1").addGiven("Joe");
patient.getManagingOrganization().setReference(orgId);
patient.getManagingOrganization().setReferenceElement(orgId);
patientId = myPatientDao.create(patient).getId().toUnqualifiedVersionless();
}
{
SearchParameterMap params = new SearchParameterMap();
params.add(Organization.SP_RES_ID, new StringDt(orgId.getIdPart()));
params.add(Organization.SP_RES_ID, new StringParam(orgId.getIdPart()));
params.addInclude(Organization.INCLUDE_PARTOF.asRecursive());
List<IIdType> resources = toUnqualifiedVersionlessIds(myOrganizationDao.search(params));
ourLog.info(resources.toString());
@ -1626,14 +1615,14 @@ public class FhirResourceDaoDstu21SearchNoFtTest extends BaseJpaDstu21Test {
{
Organization org = new Organization();
org.getNameElement().setValue(methodName + "_O1Parent");
org.setPartOf(new ResourceReferenceDt(parentParentOrgId));
org.setPartOf(new Reference(parentParentOrgId));
parentOrgId = myOrganizationDao.create(org).getId().toUnqualifiedVersionless();
}
IIdType orgId;
{
Organization org = new Organization();
org.getNameElement().setValue(methodName + "_O1");
org.setPartOf(new ResourceReferenceDt(parentOrgId));
org.setPartOf(new Reference(parentOrgId));
orgId = myOrganizationDao.create(org).getId().toUnqualifiedVersionless();
}
IIdType patientId;
@ -1641,13 +1630,13 @@ public class FhirResourceDaoDstu21SearchNoFtTest extends BaseJpaDstu21Test {
Patient patient = new Patient();
patient.addIdentifier().setSystem("urn:system").setValue("001");
patient.addName().addFamily("Tester_" + methodName + "_P1").addGiven("Joe");
patient.getManagingOrganization().setReference(orgId);
patient.getManagingOrganization().setReferenceElement(orgId);
patientId = myPatientDao.create(patient).getId().toUnqualifiedVersionless();
}
{
SearchParameterMap params = new SearchParameterMap();
params.add(Patient.SP_FAMILY, new StringDt("Tester_" + methodName + "_P1"));
params.add(Patient.SP_FAMILY, new StringParam("Tester_" + methodName + "_P1"));
params.addInclude(new Include("*").asNonRecursive());
List<IIdType> resources = toUnqualifiedVersionlessIds(myPatientDao.search(params));
assertThat(resources, contains(patientId, orgId));
@ -1667,14 +1656,14 @@ public class FhirResourceDaoDstu21SearchNoFtTest extends BaseJpaDstu21Test {
{
Organization org = new Organization();
org.getNameElement().setValue(methodName + "_O1Parent");
org.setPartOf(new ResourceReferenceDt(parentParentOrgId));
org.setPartOf(new Reference(parentParentOrgId));
parentOrgId = myOrganizationDao.create(org).getId().toUnqualifiedVersionless();
}
IIdType orgId;
{
Organization org = new Organization();
org.getNameElement().setValue(methodName + "_O1");
org.setPartOf(new ResourceReferenceDt(parentOrgId));
org.setPartOf(new Reference(parentOrgId));
orgId = myOrganizationDao.create(org).getId().toUnqualifiedVersionless();
}
IIdType patientId;
@ -1682,13 +1671,13 @@ public class FhirResourceDaoDstu21SearchNoFtTest extends BaseJpaDstu21Test {
Patient patient = new Patient();
patient.addIdentifier().setSystem("urn:system").setValue("001");
patient.addName().addFamily("Tester_" + methodName + "_P1").addGiven("Joe");
patient.getManagingOrganization().setReference(orgId);
patient.getManagingOrganization().setReferenceElement(orgId);
patientId = myPatientDao.create(patient).getId().toUnqualifiedVersionless();
}
{
SearchParameterMap params = new SearchParameterMap();
params.add(Patient.SP_FAMILY, new StringDt("Tester_" + methodName + "_P1"));
params.add(Patient.SP_FAMILY, new StringParam("Tester_" + methodName + "_P1"));
params.addInclude(new Include("*").asRecursive());
List<IIdType> resources = toUnqualifiedVersionlessIds(myPatientDao.search(params));
assertThat(resources, contains(patientId, orgId, parentOrgId, parentParentOrgId));
@ -1710,7 +1699,7 @@ public class FhirResourceDaoDstu21SearchNoFtTest extends BaseJpaDstu21Test {
Patient patient = new Patient();
patient.addIdentifier().setSystem("urn:system").setValue("001");
patient.addName().addFamily("Tester_testSearchWithIncludesThatHaveTextId_P1").addGiven("Joe");
patient.getManagingOrganization().setReference(orgId);
patient.getManagingOrganization().setReferenceElement(orgId);
myPatientDao.create(patient);
}
{
@ -1721,16 +1710,16 @@ public class FhirResourceDaoDstu21SearchNoFtTest extends BaseJpaDstu21Test {
}
SearchParameterMap params = new SearchParameterMap();
params.add(Patient.SP_FAMILY, new StringDt("Tester_testSearchWithIncludesThatHaveTextId_P1"));
params.add(Patient.SP_FAMILY, new StringParam("Tester_testSearchWithIncludesThatHaveTextId_P1"));
params.addInclude(Patient.INCLUDE_ORGANIZATION);
IBundleProvider search = myPatientDao.search(params);
List<IResource> patients = toList(search);
List<IBaseResource> patients = toList(search);
assertEquals(2, patients.size());
assertEquals(Patient.class, patients.get(0).getClass());
assertEquals(Organization.class, patients.get(1).getClass());
params = new SearchParameterMap();
params.add(Patient.SP_FAMILY, new StringDt("Tester_testSearchWithIncludesThatHaveTextId_P1"));
params.add(Patient.SP_FAMILY, new StringParam("Tester_testSearchWithIncludesThatHaveTextId_P1"));
patients = toList(myPatientDao.search(params));
assertEquals(1, patients.size());
@ -1750,8 +1739,8 @@ public class FhirResourceDaoDstu21SearchNoFtTest extends BaseJpaDstu21Test {
Patient patient = new Patient();
patient.addIdentifier().setSystem("urn:system").setValue("002");
patient.addName().addFamily("Tester_testSearchStringParam").addGiven("John");
patient.setBirthDate(new DateDt("2011-01-01"));
patient.getManagingOrganization().setReference(orgId);
patient.setBirthDateElement(new DateType("2011-01-01"));
patient.getManagingOrganization().setReferenceElement(orgId);
notMissing = myPatientDao.create(patient).getId().toUnqualifiedVersionless();
}
// Date Param
@ -1787,7 +1776,7 @@ public class FhirResourceDaoDstu21SearchNoFtTest extends BaseJpaDstu21Test {
{
Observation obs = new Observation();
obs.addIdentifier().setSystem("urn:system").setValue("002");
obs.setValue(new QuantityDt(123));
obs.setValue(new Quantity(123));
notMissing = myObservationDao.create(obs).getId().toUnqualifiedVersionless();
}
// Quantity Param
@ -1825,8 +1814,8 @@ public class FhirResourceDaoDstu21SearchNoFtTest extends BaseJpaDstu21Test {
Patient patient = new Patient();
patient.addIdentifier().setSystem("urn:system").setValue("002");
patient.addName().addFamily("Tester_testSearchStringParam").addGiven("John");
patient.setBirthDate(new DateDt("2011-01-01"));
patient.getManagingOrganization().setReference(orgId);
patient.setBirthDateElement(new DateType("2011-01-01"));
patient.getManagingOrganization().setReferenceElement(orgId);
notMissing = myPatientDao.create(patient).getId().toUnqualifiedVersionless();
}
// Reference Param
@ -1865,8 +1854,8 @@ public class FhirResourceDaoDstu21SearchNoFtTest extends BaseJpaDstu21Test {
Patient patient = new Patient();
patient.addIdentifier().setSystem("urn:system").setValue("002");
patient.addName().addFamily("Tester_testSearchStringParam").addGiven("John");
patient.setBirthDate(new DateDt("2011-01-01"));
patient.getManagingOrganization().setReference(orgId);
patient.setBirthDateElement(new DateType("2011-01-01"));
patient.getManagingOrganization().setReferenceElement(orgId);
notMissing = myPatientDao.create(patient).getId().toUnqualifiedVersionless();
}
// String Param
@ -1923,18 +1912,14 @@ public class FhirResourceDaoDstu21SearchNoFtTest extends BaseJpaDstu21Test {
{
Organization org = new Organization();
org.getNameElement().setValue("FOO");
List<BaseCodingDt> security = new ArrayList<BaseCodingDt>();
security.add(new CodingDt("urn:taglist", methodName + "1a"));
ResourceMetadataKeyEnum.SECURITY_LABELS.put(org, security);
org.getMeta().addSecurity("urn:taglist", methodName + "1a", null);
tag1id = myOrganizationDao.create(org).getId().toUnqualifiedVersionless();
}
IIdType tag2id;
{
Organization org = new Organization();
org.getNameElement().setValue("FOO");
List<IdDt> security = new ArrayList<IdDt>();
security.add(new IdDt("http://" + methodName));
ResourceMetadataKeyEnum.PROFILES.put(org, security);
org.getMeta().addProfile("http://" + methodName);
tag2id = myOrganizationDao.create(org).getId().toUnqualifiedVersionless();
}
{
@ -1959,10 +1944,8 @@ public class FhirResourceDaoDstu21SearchNoFtTest extends BaseJpaDstu21Test {
{
Organization org = new Organization();
org.getNameElement().setValue("FOO");
TagList tagList = new TagList();
tagList.addTag("urn:taglist", methodName + "1a");
tagList.addTag("urn:taglist", methodName + "1b");
ResourceMetadataKeyEnum.TAG_LIST.put(org, tagList);
org.getMeta().addTag("urn:taglist", methodName + "1a", null);
org.getMeta().addTag("urn:taglist", methodName + "1b", null);
tag1id = myOrganizationDao.create(org).getId().toUnqualifiedVersionless();
}
@ -1972,10 +1955,8 @@ public class FhirResourceDaoDstu21SearchNoFtTest extends BaseJpaDstu21Test {
{
Organization org = new Organization();
org.getNameElement().setValue("FOO");
TagList tagList = new TagList();
tagList.addTag("urn:taglist", methodName + "2a");
tagList.addTag("urn:taglist", methodName + "2b");
ResourceMetadataKeyEnum.TAG_LIST.put(org, tagList);
org.getMeta().addTag("urn:taglist", methodName + "2a",null);
org.getMeta().addTag("urn:taglist", methodName + "2b",null);
tag2id = myOrganizationDao.create(org).getId().toUnqualifiedVersionless();
}
@ -2083,7 +2064,7 @@ public class FhirResourceDaoDstu21SearchNoFtTest extends BaseJpaDstu21Test {
myValueSetDao.update(vs);
IBundleProvider result = myValueSetDao.search(ValueSet.SP_URL, new UriParam("http://hl7.org/fhir/ValueSet/basic-resource-type"));
assertThat(toUnqualifiedVersionlessIds(result), contains((IIdType)new IdDt("ValueSet/testSearchWithUriParam")));
assertThat(toUnqualifiedVersionlessIds(result), contains((IIdType)new IdType("ValueSet/testSearchWithUriParam")));
}
private String toStringMultiline(List<?> theResults) {

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