More cleanup of legacy code
This commit is contained in:
parent
9ae7295705
commit
defea69aa3
|
@ -1,5 +1,6 @@
|
||||||
package ca.uhn.fhir.rest.client.api;
|
package ca.uhn.fhir.rest.client.api;
|
||||||
|
|
||||||
|
import org.hl7.fhir.instance.model.api.IBaseBundle;
|
||||||
import org.hl7.fhir.instance.model.api.IBaseResource;
|
import org.hl7.fhir.instance.model.api.IBaseResource;
|
||||||
|
|
||||||
import ca.uhn.fhir.model.primitive.IdDt;
|
import ca.uhn.fhir.model.primitive.IdDt;
|
||||||
|
@ -121,7 +122,7 @@ public interface IGenericClient extends IRestfulClient {
|
||||||
* and how it should be returned. See the <a href="http://www.hl7.org/fhir/search.html">specification on search</a>
|
* and how it should be returned. See the <a href="http://www.hl7.org/fhir/search.html">specification on search</a>
|
||||||
* for more information.
|
* for more information.
|
||||||
*/
|
*/
|
||||||
IUntypedQuery search();
|
<T extends IBaseBundle> IUntypedQuery<T> search();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* If set to <code>true</code>, the client will log all requests and all responses. This is probably not a good production setting since it will result in a lot of extra logging, but it can be
|
* If set to <code>true</code>, the client will log all requests and all responses. This is probably not a good production setting since it will result in a lot of extra logging, but it can be
|
||||||
|
|
|
@ -1,5 +1,9 @@
|
||||||
package ca.uhn.fhir.rest.gclient;
|
package ca.uhn.fhir.rest.gclient;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
import ca.uhn.fhir.model.api.IQueryParameterType;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* #%L
|
* #%L
|
||||||
* HAPI FHIR - Core Library
|
* HAPI FHIR - Core Library
|
||||||
|
@ -24,6 +28,8 @@ public interface IBaseQuery<T extends IBaseQuery<?>> {
|
||||||
|
|
||||||
T where(ICriterion<?> theCriterion);
|
T where(ICriterion<?> theCriterion);
|
||||||
|
|
||||||
|
T where(Map<String, List<IQueryParameterType>> theCriterion);
|
||||||
|
|
||||||
T and(ICriterion<?> theCriterion);
|
T and(ICriterion<?> theCriterion);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,7 +27,7 @@ import ca.uhn.fhir.rest.api.SummaryEnum;
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
public interface IClientExecutable<T extends IClientExecutable<?,?>, Y> {
|
public interface IClientExecutable<T extends IClientExecutable<?,Y>, Y> {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* If set to true, the client will log the request and response to the SLF4J logger. This can be useful for
|
* If set to true, the client will log the request and response to the SLF4J logger. This can be useful for
|
||||||
|
|
|
@ -24,5 +24,5 @@ import org.hl7.fhir.instance.model.api.IBaseMetaType;
|
||||||
|
|
||||||
public interface IMetaAddOrDeleteSourced {
|
public interface IMetaAddOrDeleteSourced {
|
||||||
|
|
||||||
<T extends IBaseMetaType> IClientExecutable<IClientExecutable<?, ?>, T> meta(T theMeta);
|
<T extends IBaseMetaType> IClientExecutable<IClientExecutable<?, T>, T> meta(T theMeta);
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,16 +25,16 @@ import org.hl7.fhir.instance.model.api.IIdType;
|
||||||
|
|
||||||
public interface IMetaGetUnsourced<T extends IBaseMetaType> {
|
public interface IMetaGetUnsourced<T extends IBaseMetaType> {
|
||||||
|
|
||||||
IClientExecutable<IClientExecutable<?,?>, T> fromServer();
|
IClientExecutable<IClientExecutable<?, T>, T> fromServer();
|
||||||
|
|
||||||
IClientExecutable<IClientExecutable<?,?>, T> fromType(String theResourceName);
|
IClientExecutable<IClientExecutable<?, T>, T> fromType(String theResourceName);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the meta from a resource instance by ID.
|
* Get the meta from a resource instance by ID.
|
||||||
*
|
*
|
||||||
* @param theId The ID. Must contain both a resource type and an ID part
|
* @param theId
|
||||||
|
* The ID. Must contain both a resource type and an ID part
|
||||||
*/
|
*/
|
||||||
IClientExecutable<IClientExecutable<?,?>, T> fromResource(IIdType theId);
|
IClientExecutable<IClientExecutable<?, T>, T> fromResource(IIdType theId);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,7 +28,7 @@ import ca.uhn.fhir.model.api.Include;
|
||||||
import ca.uhn.fhir.rest.api.SearchStyleEnum;
|
import ca.uhn.fhir.rest.api.SearchStyleEnum;
|
||||||
import ca.uhn.fhir.rest.param.DateRangeParam;
|
import ca.uhn.fhir.rest.param.DateRangeParam;
|
||||||
|
|
||||||
public interface IQuery extends IBaseQuery<IQuery> {
|
public interface IQuery<Y> extends IBaseQuery<IQuery<Y>>, IClientExecutable<IQuery<Y>, Y> {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add an "_include" specification or an "_include:recurse" specification. If you are using
|
* Add an "_include" specification or an "_include:recurse" specification. If you are using
|
||||||
|
@ -39,9 +39,9 @@ public interface IQuery extends IBaseQuery<IQuery> {
|
||||||
* <li><b>No Recurse:</b> <code>.include(Patient.INCLUDE_ORGANIZATION.asNonRecursive())</code>
|
* <li><b>No Recurse:</b> <code>.include(Patient.INCLUDE_ORGANIZATION.asNonRecursive())</code>
|
||||||
* </ul>
|
* </ul>
|
||||||
*/
|
*/
|
||||||
IQuery include(Include theInclude);
|
IQuery<Y> include(Include theInclude);
|
||||||
|
|
||||||
ISort sort();
|
ISort<Y> sort();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Specifies the <code>_count</code> parameter, which indicates to the server how many resources should be returned
|
* Specifies the <code>_count</code> parameter, which indicates to the server how many resources should be returned
|
||||||
|
@ -50,7 +50,7 @@ public interface IQuery extends IBaseQuery<IQuery> {
|
||||||
* @deprecated This parameter is badly named, since FHIR calls this parameter "_count" and not "_limit". Use {@link #count(int)} instead (it also sets the _count parameter)
|
* @deprecated This parameter is badly named, since FHIR calls this parameter "_count" and not "_limit". Use {@link #count(int)} instead (it also sets the _count parameter)
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
IQuery limitTo(int theLimitTo);
|
IQuery<Y> limitTo(int theLimitTo);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Specifies the <code>_count</code> parameter, which indicates to the server how many resources should be returned
|
* Specifies the <code>_count</code> parameter, which indicates to the server how many resources should be returned
|
||||||
|
@ -58,7 +58,7 @@ public interface IQuery extends IBaseQuery<IQuery> {
|
||||||
*
|
*
|
||||||
* @since 1.4
|
* @since 1.4
|
||||||
*/
|
*/
|
||||||
IQuery count(int theCount);
|
IQuery<Y> count(int theCount);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Match only resources where the resource has the given tag. This parameter corresponds to
|
* Match only resources where the resource has the given tag. This parameter corresponds to
|
||||||
|
@ -66,7 +66,7 @@ public interface IQuery extends IBaseQuery<IQuery> {
|
||||||
* @param theSystem The tag code system, or <code>null</code> to match any code system (this may not be supported on all servers)
|
* @param theSystem The tag code system, or <code>null</code> to match any code system (this may not be supported on all servers)
|
||||||
* @param theCode The tag code. Must not be <code>null</code> or empty.
|
* @param theCode The tag code. Must not be <code>null</code> or empty.
|
||||||
*/
|
*/
|
||||||
IQuery withTag(String theSystem, String theCode);
|
IQuery<Y> withTag(String theSystem, String theCode);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Match only resources where the resource has the given security tag. This parameter corresponds to
|
* Match only resources where the resource has the given security tag. This parameter corresponds to
|
||||||
|
@ -74,21 +74,21 @@ public interface IQuery extends IBaseQuery<IQuery> {
|
||||||
* @param theSystem The tag code system, or <code>null</code> to match any code system (this may not be supported on all servers)
|
* @param theSystem The tag code system, or <code>null</code> to match any code system (this may not be supported on all servers)
|
||||||
* @param theCode The tag code. Must not be <code>null</code> or empty.
|
* @param theCode The tag code. Must not be <code>null</code> or empty.
|
||||||
*/
|
*/
|
||||||
IQuery withSecurity(String theSystem, String theCode);
|
IQuery<Y> withSecurity(String theSystem, String theCode);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Match only resources where the resource has the given profile declaration. This parameter corresponds to
|
* Match only resources where the resource has the given profile declaration. This parameter corresponds to
|
||||||
* the <code>_profile</code> URL parameter.
|
* the <code>_profile</code> URL parameter.
|
||||||
* @param theProfileUri The URI of a given profile to search for resources which match
|
* @param theProfileUri The URI of a given profile to search for resources which match
|
||||||
*/
|
*/
|
||||||
IQuery withProfile(String theProfileUri);
|
IQuery<Y> withProfile(String theProfileUri);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Matches any of the profiles given as argument. This would result in an OR search for resources matching one or more profiles.
|
* Matches any of the profiles given as argument. This would result in an OR search for resources matching one or more profiles.
|
||||||
* To do an AND search, make multiple calls to {@link #withProfile(String)}.
|
* To do an AND search, make multiple calls to {@link #withProfile(String)}.
|
||||||
* @param theProfileUris The URIs of a given profile to search for resources which match.
|
* @param theProfileUris The URIs of a given profile to search for resources which match.
|
||||||
*/
|
*/
|
||||||
IQuery withAnyProfile(Collection<String> theProfileUris);
|
IQuery<Y> withAnyProfile(Collection<String> theProfileUris);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Forces the query to perform the search using the given method (allowable methods are described in the
|
* Forces the query to perform the search using the given method (allowable methods are described in the
|
||||||
|
@ -100,44 +100,44 @@ public interface IQuery extends IBaseQuery<IQuery> {
|
||||||
* @see SearchStyleEnum
|
* @see SearchStyleEnum
|
||||||
* @since 0.6
|
* @since 0.6
|
||||||
*/
|
*/
|
||||||
IQuery usingStyle(SearchStyleEnum theStyle);
|
IQuery<Y> usingStyle(SearchStyleEnum theStyle);
|
||||||
|
|
||||||
IQuery withIdAndCompartment(String theResourceId, String theCompartmentName);
|
IQuery<Y> withIdAndCompartment(String theResourceId, String theCompartmentName);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a "_revinclude" specification
|
* Add a "_revinclude" specification
|
||||||
*
|
*
|
||||||
* @since HAPI FHIR 1.0 - Note that option was added to FHIR itself in DSTU2
|
* @since HAPI FHIR 1.0 - Note that option was added to FHIR itself in DSTU2
|
||||||
*/
|
*/
|
||||||
IQuery revInclude(Include theIncludeTarget);
|
IQuery<Y> revInclude(Include theIncludeTarget);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a "_lastUpdated" specification
|
* Add a "_lastUpdated" specification
|
||||||
*
|
*
|
||||||
* @since HAPI FHIR 1.1 - Note that option was added to FHIR itself in DSTU2
|
* @since HAPI FHIR 1.1 - Note that option was added to FHIR itself in DSTU2
|
||||||
*/
|
*/
|
||||||
IQuery lastUpdated(DateRangeParam theLastUpdated);
|
IQuery<Y> lastUpdated(DateRangeParam theLastUpdated);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Request that the client return the specified bundle type, e.g. <code>org.hl7.fhir.instance.model.Bundle.class</code>
|
* Request that the client return the specified bundle type, e.g. <code>org.hl7.fhir.instance.model.Bundle.class</code>
|
||||||
* or <code>ca.uhn.fhir.model.dstu2.resource.Bundle.class</code>
|
* or <code>ca.uhn.fhir.model.dstu2.resource.Bundle.class</code>
|
||||||
*/
|
*/
|
||||||
<B extends IBaseBundle> IQueryTyped<B> returnBundle(Class<B> theClass);
|
<B extends IBaseBundle> IQuery<B> returnBundle(Class<B> theClass);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
*/
|
*/
|
||||||
// This is here as an overridden method to allow mocking clients with Mockito to work
|
// This is here as an overridden method to allow mocking clients with Mockito to work
|
||||||
@Override
|
@Override
|
||||||
IQuery where(ICriterion<?> theCriterion);
|
IQuery<Y> where(ICriterion<?> theCriterion);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
*/
|
*/
|
||||||
// This is here as an overridden method to allow mocking clients with Mockito to work
|
// This is here as an overridden method to allow mocking clients with Mockito to work
|
||||||
@Override
|
@Override
|
||||||
IQuery and(ICriterion<?> theCriterion);
|
IQuery<Y> and(ICriterion<?> theCriterion);
|
||||||
|
|
||||||
// <T extends IBaseBundle> T execute();
|
// Y execute();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +0,0 @@
|
||||||
package ca.uhn.fhir.rest.gclient;
|
|
||||||
|
|
||||||
import org.hl7.fhir.instance.model.api.IBaseBundle;
|
|
||||||
|
|
||||||
public interface IQueryTyped<T extends IBaseBundle> extends IQuery, IClientExecutable<IClientExecutable<?,?>, T> {
|
|
||||||
|
|
||||||
}
|
|
|
@ -20,19 +20,19 @@ package ca.uhn.fhir.rest.gclient;
|
||||||
* #L%
|
* #L%
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public interface ISort {
|
public interface ISort<T> {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sort ascending
|
* Sort ascending
|
||||||
*/
|
*/
|
||||||
IQuery ascending(IParam theParam);
|
IQuery<T> ascending(IParam theParam);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sort ascending
|
* Sort ascending
|
||||||
*
|
*
|
||||||
* @param theParam The param name, e.g. "address"
|
* @param theParam The param name, e.g. "address"
|
||||||
*/
|
*/
|
||||||
IQuery ascending(String theParam);
|
IQuery<T> ascending(String theParam);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sort by the default order. Note that as of STU3, there is no longer
|
* Sort by the default order. Note that as of STU3, there is no longer
|
||||||
|
@ -40,7 +40,7 @@ public interface ISort {
|
||||||
* technically implies "ascending" but it makes more sense to use
|
* technically implies "ascending" but it makes more sense to use
|
||||||
* {@link #ascending(IParam)}
|
* {@link #ascending(IParam)}
|
||||||
*/
|
*/
|
||||||
IQuery defaultOrder(IParam theParam);
|
IQuery<T> defaultOrder(IParam theParam);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sort descending
|
* Sort descending
|
||||||
|
@ -48,13 +48,13 @@ public interface ISort {
|
||||||
* @param theParam A query param - Could be a constant such as <code>Patient.ADDRESS</code> or a custom
|
* @param theParam A query param - Could be a constant such as <code>Patient.ADDRESS</code> or a custom
|
||||||
* param such as <code>new StringClientParam("foo")</code>
|
* param such as <code>new StringClientParam("foo")</code>
|
||||||
*/
|
*/
|
||||||
IQuery descending(IParam theParam);
|
IQuery<T> descending(IParam theParam);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sort ascending
|
* Sort ascending
|
||||||
*
|
*
|
||||||
* @param theParam The param name, e.g. "address"
|
* @param theParam The param name, e.g. "address"
|
||||||
*/
|
*/
|
||||||
IQuery descending(String theParam);
|
IQuery<T> descending(String theParam);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,13 +22,13 @@ package ca.uhn.fhir.rest.gclient;
|
||||||
|
|
||||||
import org.hl7.fhir.instance.model.api.IBaseResource;
|
import org.hl7.fhir.instance.model.api.IBaseResource;
|
||||||
|
|
||||||
public interface IUntypedQuery {
|
public interface IUntypedQuery<T> {
|
||||||
|
|
||||||
IQuery forAllResources();
|
IQuery<T> forAllResources();
|
||||||
|
|
||||||
IQuery forResource(String theResourceName);
|
IQuery<T> forResource(String theResourceName);
|
||||||
|
|
||||||
IQuery forResource(Class<? extends IBaseResource> theClass);
|
IQuery<T> forResource(Class<? extends IBaseResource> theClass);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Perform a search directly by URL. It is usually better to construct the URL using the {@link #forAllResources()}, {@link #forResource(Class)} etc, but sometimes it is useful to simply search by
|
* Perform a search directly by URL. It is usually better to construct the URL using the {@link #forAllResources()}, {@link #forResource(Class)} etc, but sometimes it is useful to simply search by
|
||||||
|
@ -38,6 +38,6 @@ public interface IUntypedQuery {
|
||||||
* The URL to search for. Note that this URL may be complete (e.g. "http://example.com/base/Patient?name=foo") in which case the client's base URL will be ignored. Or it can be relative
|
* The URL to search for. Note that this URL may be complete (e.g. "http://example.com/base/Patient?name=foo") in which case the client's base URL will be ignored. Or it can be relative
|
||||||
* (e.g. "Patient?name=foo") in which case the client's base URL will be used.
|
* (e.g. "Patient?name=foo") in which case the client's base URL will be used.
|
||||||
*/
|
*/
|
||||||
IQuery byUrl(String theSearchUrl);
|
IQuery<T> byUrl(String theSearchUrl);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,11 @@
|
||||||
package ca.uhn.fhir.rest.param;
|
package ca.uhn.fhir.rest.param;
|
||||||
|
|
||||||
|
import static org.apache.commons.lang3.StringUtils.isBlank;
|
||||||
|
|
||||||
public abstract class BaseParamWithPrefix<T extends BaseParam> extends BaseParam {
|
public abstract class BaseParamWithPrefix<T extends BaseParam> extends BaseParam {
|
||||||
|
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(BaseParamWithPrefix.class);
|
||||||
|
|
||||||
private ParamPrefixEnum myPrefix;
|
private ParamPrefixEnum myPrefix;
|
||||||
|
|
||||||
|
@ -32,8 +35,40 @@ public abstract class BaseParamWithPrefix<T extends BaseParam> extends BaseParam
|
||||||
}
|
}
|
||||||
|
|
||||||
String prefix = theString.substring(0, offset);
|
String prefix = theString.substring(0, offset);
|
||||||
|
if (!isBlank(prefix)) {
|
||||||
|
|
||||||
myPrefix = ParamPrefixEnum.forValue(prefix);
|
myPrefix = ParamPrefixEnum.forValue(prefix);
|
||||||
|
|
||||||
|
if (myPrefix == null) {
|
||||||
|
switch (prefix) {
|
||||||
|
case ">=":
|
||||||
|
myPrefix = ParamPrefixEnum.GREATERTHAN_OR_EQUALS;
|
||||||
|
break;
|
||||||
|
case ">":
|
||||||
|
myPrefix = ParamPrefixEnum.GREATERTHAN;
|
||||||
|
break;
|
||||||
|
case "<=":
|
||||||
|
myPrefix = ParamPrefixEnum.LESSTHAN_OR_EQUALS;
|
||||||
|
break;
|
||||||
|
case "<":
|
||||||
|
myPrefix = ParamPrefixEnum.LESSTHAN;
|
||||||
|
break;
|
||||||
|
case "~":
|
||||||
|
myPrefix = ParamPrefixEnum.APPROXIMATE;
|
||||||
|
break;
|
||||||
|
default :
|
||||||
|
ourLog.warn("Invalid prefix being ignored: {}", prefix);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (myPrefix != null) {
|
||||||
|
ourLog.warn("Date parameter has legacy prefix '{}' which has been removed from FHIR. This should be replaced with '{}'", prefix, myPrefix);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
return theString.substring(offset);
|
return theString.substring(offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -143,8 +143,9 @@ public class BundleUtil {
|
||||||
/**
|
/**
|
||||||
* Extract all of the resources of a given type from a given bundle
|
* Extract all of the resources of a given type from a given bundle
|
||||||
*/
|
*/
|
||||||
public static List<IBaseResource> toListOfResourcesOfType(FhirContext theContext, IBaseBundle theBundle, Class<? extends IBaseResource> theTypeToInclude) {
|
@SuppressWarnings("unchecked")
|
||||||
List<IBaseResource> retVal = new ArrayList<IBaseResource>();
|
public static <T extends IBaseResource> List<T> toListOfResourcesOfType(FhirContext theContext, IBaseBundle theBundle, Class<T> theTypeToInclude) {
|
||||||
|
List<T> retVal = new ArrayList<T>();
|
||||||
|
|
||||||
RuntimeResourceDefinition def = theContext.getResourceDefinition(theBundle);
|
RuntimeResourceDefinition def = theContext.getResourceDefinition(theBundle);
|
||||||
BaseRuntimeChildDefinition entryChild = def.getChildByName("entry");
|
BaseRuntimeChildDefinition entryChild = def.getChildByName("entry");
|
||||||
|
@ -157,7 +158,7 @@ public class BundleUtil {
|
||||||
if (theTypeToInclude != null && !theTypeToInclude.isAssignableFrom(next.getClass())) {
|
if (theTypeToInclude != null && !theTypeToInclude.isAssignableFrom(next.getClass())) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
retVal.add((IBaseResource) next);
|
retVal.add((T) next);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -29,10 +29,15 @@ import ca.uhn.fhir.util.ObjectUtil;
|
||||||
abstract class BaseValidationContext<T> implements IValidationContext<T> {
|
abstract class BaseValidationContext<T> implements IValidationContext<T> {
|
||||||
|
|
||||||
protected final FhirContext myFhirContext;
|
protected final FhirContext myFhirContext;
|
||||||
private List<SingleValidationMessage> myMessages = new ArrayList<SingleValidationMessage>();
|
|
||||||
|
|
||||||
|
private List<SingleValidationMessage> myMessages;
|
||||||
BaseValidationContext(FhirContext theFhirContext) {
|
BaseValidationContext(FhirContext theFhirContext) {
|
||||||
|
this(theFhirContext, new ArrayList<SingleValidationMessage>());
|
||||||
|
}
|
||||||
|
|
||||||
|
BaseValidationContext(FhirContext theFhirContext, List<SingleValidationMessage> theMessages) {
|
||||||
myFhirContext = theFhirContext;
|
myFhirContext = theFhirContext;
|
||||||
|
myMessages = theMessages;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -46,6 +51,11 @@ abstract class BaseValidationContext<T> implements IValidationContext<T> {
|
||||||
return myFhirContext;
|
return myFhirContext;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<SingleValidationMessage> getMessages() {
|
||||||
|
return myMessages;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ValidationResult toResult() {
|
public ValidationResult toResult() {
|
||||||
return new ValidationResult(myFhirContext, myMessages);
|
return new ValidationResult(myFhirContext, myMessages);
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
package ca.uhn.fhir.validation;
|
package ca.uhn.fhir.validation;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* #%L
|
* #%L
|
||||||
* HAPI FHIR - Core Library
|
* HAPI FHIR - Core Library
|
||||||
|
@ -35,6 +37,8 @@ public interface IValidationContext<T> {
|
||||||
|
|
||||||
void addValidationMessage(SingleValidationMessage theMessage);
|
void addValidationMessage(SingleValidationMessage theMessage);
|
||||||
|
|
||||||
|
List<SingleValidationMessage> getMessages();
|
||||||
|
|
||||||
ValidationResult toResult();
|
ValidationResult toResult();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,8 @@
|
||||||
package ca.uhn.fhir.validation;
|
package ca.uhn.fhir.validation;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* #%L
|
* #%L
|
||||||
* HAPI FHIR - Core Library
|
* HAPI FHIR - Core Library
|
||||||
|
@ -37,7 +40,11 @@ public class ValidationContext<T> extends BaseValidationContext<T> implements IV
|
||||||
private final EncodingEnum myResourceAsStringEncoding;
|
private final EncodingEnum myResourceAsStringEncoding;
|
||||||
|
|
||||||
private ValidationContext(FhirContext theContext, T theResource, IEncoder theEncoder) {
|
private ValidationContext(FhirContext theContext, T theResource, IEncoder theEncoder) {
|
||||||
super(theContext);
|
this(theContext, theResource, theEncoder, new ArrayList<SingleValidationMessage>());
|
||||||
|
}
|
||||||
|
|
||||||
|
private ValidationContext(FhirContext theContext, T theResource, IEncoder theEncoder, List<SingleValidationMessage> theMessages) {
|
||||||
|
super(theContext, theMessages);
|
||||||
myResource = theResource;
|
myResource = theResource;
|
||||||
myEncoder = theEncoder;
|
myEncoder = theEncoder;
|
||||||
if (theEncoder != null) {
|
if (theEncoder != null) {
|
||||||
|
@ -123,4 +130,18 @@ public class ValidationContext<T> extends BaseValidationContext<T> implements IV
|
||||||
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static IValidationContext<IBaseResource> subContext(final IValidationContext<IBaseResource> theCtx, final IBaseResource theResource) {
|
||||||
|
return new ValidationContext<IBaseResource>(theCtx.getFhirContext(), theResource, new IEncoder() {
|
||||||
|
@Override
|
||||||
|
public String encode() {
|
||||||
|
return theCtx.getFhirContext().newXmlParser().encodeResourceToString(theResource);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public EncodingEnum getEncoding() {
|
||||||
|
return EncodingEnum.XML;
|
||||||
|
}
|
||||||
|
}, theCtx.getMessages());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,6 +27,7 @@ import java.util.*;
|
||||||
import javax.xml.transform.stream.StreamSource;
|
import javax.xml.transform.stream.StreamSource;
|
||||||
|
|
||||||
import org.apache.commons.io.IOUtils;
|
import org.apache.commons.io.IOUtils;
|
||||||
|
import org.hl7.fhir.instance.model.api.IBaseBundle;
|
||||||
import org.hl7.fhir.instance.model.api.IBaseResource;
|
import org.hl7.fhir.instance.model.api.IBaseResource;
|
||||||
import org.oclc.purl.dsdl.svrl.SchematronOutputType;
|
import org.oclc.purl.dsdl.svrl.SchematronOutputType;
|
||||||
|
|
||||||
|
@ -39,6 +40,7 @@ import com.phloc.schematron.xslt.SchematronResourceSCH;
|
||||||
import ca.uhn.fhir.context.FhirContext;
|
import ca.uhn.fhir.context.FhirContext;
|
||||||
import ca.uhn.fhir.rest.api.EncodingEnum;
|
import ca.uhn.fhir.rest.api.EncodingEnum;
|
||||||
import ca.uhn.fhir.rest.server.exceptions.InternalErrorException;
|
import ca.uhn.fhir.rest.server.exceptions.InternalErrorException;
|
||||||
|
import ca.uhn.fhir.util.BundleUtil;
|
||||||
import ca.uhn.fhir.validation.*;
|
import ca.uhn.fhir.validation.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -57,6 +59,14 @@ public class SchematronBaseValidator implements IValidatorModule {
|
||||||
@Override
|
@Override
|
||||||
public void validateResource(IValidationContext<IBaseResource> theCtx) {
|
public void validateResource(IValidationContext<IBaseResource> theCtx) {
|
||||||
|
|
||||||
|
if (theCtx.getResource() instanceof IBaseBundle) {
|
||||||
|
IBaseBundle bundle = (IBaseBundle) theCtx.getResource();
|
||||||
|
List<IBaseResource> subResources = BundleUtil.toListOfResources(myCtx, bundle);
|
||||||
|
for (IBaseResource nextSubResource : subResources) {
|
||||||
|
validateResource(ValidationContext.subContext(theCtx, nextSubResource));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
ISchematronResource sch = getSchematron(theCtx);
|
ISchematronResource sch = getSchematron(theCtx);
|
||||||
String resourceAsString;
|
String resourceAsString;
|
||||||
if (theCtx.getResourceAsStringEncoding() == EncodingEnum.XML) {
|
if (theCtx.getResourceAsStringEncoding() == EncodingEnum.XML) {
|
||||||
|
|
|
@ -25,6 +25,7 @@ import static org.apache.commons.lang3.StringUtils.isNotBlank;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.Reader;
|
import java.io.Reader;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
import java.util.Map.Entry;
|
||||||
|
|
||||||
import org.apache.commons.io.IOUtils;
|
import org.apache.commons.io.IOUtils;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
@ -75,13 +76,11 @@ public class GenericClient extends BaseClient implements IGenericClient {
|
||||||
return new CreateInternal();
|
return new CreateInternal();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IDelete delete() {
|
public IDelete delete() {
|
||||||
return new DeleteInternal();
|
return new DeleteInternal();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private <T extends IBaseResource> T doReadOrVRead(final Class<T> theType, IIdType theId, boolean theVRead, ICallable<T> theNotModifiedHandler, String theIfVersionMatches, Boolean thePrettyPrint,
|
private <T extends IBaseResource> T doReadOrVRead(final Class<T> theType, IIdType theId, boolean theVRead, ICallable<T> theNotModifiedHandler, String theIfVersionMatches, Boolean thePrettyPrint,
|
||||||
SummaryEnum theSummary, EncodingEnum theEncoding, Set<String> theSubsetElements) {
|
SummaryEnum theSummary, EncodingEnum theEncoding, Set<String> theSubsetElements) {
|
||||||
String resName = toResourceName(theType);
|
String resName = toResourceName(theType);
|
||||||
|
@ -165,15 +164,11 @@ public class GenericClient extends BaseClient implements IGenericClient {
|
||||||
return theResource.getIdElement().getIdPart();
|
return theResource.getIdElement().getIdPart();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IHistory history() {
|
public IHistory history() {
|
||||||
return new HistoryInternal();
|
return new HistoryInternal();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// @Override
|
// @Override
|
||||||
// public <T extends IBaseResource> T read(final Class<T> theType, IdDt theId) {
|
// public <T extends IBaseResource> T read(final Class<T> theType, IdDt theId) {
|
||||||
// return doReadOrVRead(theType, theId, false, null, null);
|
// return doReadOrVRead(theType, theId, false, null, null);
|
||||||
|
@ -204,6 +199,11 @@ public class GenericClient extends BaseClient implements IGenericClient {
|
||||||
return new OperationInternal();
|
return new OperationInternal();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public IPatch patch() {
|
||||||
|
return new PatchInternal();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IRead read() {
|
public IRead read() {
|
||||||
return new ReadInternal();
|
return new ReadInternal();
|
||||||
|
@ -234,12 +234,12 @@ public class GenericClient extends BaseClient implements IGenericClient {
|
||||||
return read(def.getImplementingClass(), id);
|
return read(def.getImplementingClass(), id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||||
@Override
|
@Override
|
||||||
public IUntypedQuery search() {
|
public IUntypedQuery search() {
|
||||||
return new SearchInternal();
|
return new SearchInternal();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* For now, this is a part of the internal API of HAPI - Use with caution as this method may change!
|
* For now, this is a part of the internal API of HAPI - Use with caution as this method may change!
|
||||||
*/
|
*/
|
||||||
|
@ -262,12 +262,6 @@ public class GenericClient extends BaseClient implements IGenericClient {
|
||||||
return new TransactionInternal();
|
return new TransactionInternal();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public IPatch patch() {
|
|
||||||
return new PatchInternal();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IUpdate update() {
|
public IUpdate update() {
|
||||||
return new UpdateInternal();
|
return new UpdateInternal();
|
||||||
|
@ -366,18 +360,13 @@ public class GenericClient extends BaseClient implements IGenericClient {
|
||||||
return b.toString();
|
return b.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
private abstract class BaseClientExecutable<T extends IClientExecutable<?, ?>, Y> implements IClientExecutable<T, Y> {
|
private abstract class BaseClientExecutable<T extends IClientExecutable<?, Y>, Y> implements IClientExecutable<T, Y> {
|
||||||
|
|
||||||
protected EncodingEnum myParamEncoding;
|
protected EncodingEnum myParamEncoding;
|
||||||
|
|
||||||
private List<Class<? extends IBaseResource>> myPreferResponseTypes;
|
private List<Class<? extends IBaseResource>> myPreferResponseTypes;
|
||||||
|
|
||||||
protected Boolean myPrettyPrint;
|
protected Boolean myPrettyPrint;
|
||||||
|
|
||||||
private boolean myQueryLogRequestAndResponse;
|
private boolean myQueryLogRequestAndResponse;
|
||||||
|
|
||||||
private HashSet<String> mySubsetElements;
|
private HashSet<String> mySubsetElements;
|
||||||
|
|
||||||
protected SummaryEnum mySummaryMode;
|
protected SummaryEnum mySummaryMode;
|
||||||
|
|
||||||
@Deprecated // override deprecated method
|
@Deprecated // override deprecated method
|
||||||
|
@ -491,25 +480,61 @@ public class GenericClient extends BaseClient implements IGenericClient {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private abstract class BaseSearch<EXEC extends IClientExecutable<?, OUTPUT>, QUERY extends IBaseQuery<QUERY>, OUTPUT> extends BaseClientExecutable<EXEC, OUTPUT> implements IBaseQuery<QUERY> {
|
||||||
|
|
||||||
private class CreateInternal extends BaseClientExecutable<ICreateTyped, MethodOutcome> implements ICreate, ICreateTyped, ICreateWithQuery, ICreateWithQueryTyped {
|
private Map<String, List<String>> myParams = new LinkedHashMap<>();
|
||||||
|
|
||||||
private CriterionList myCriterionList;
|
@Override
|
||||||
|
public QUERY and(ICriterion<?> theCriterion) {
|
||||||
|
return where(theCriterion);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Map<String, List<String>> getParamMap() {
|
||||||
|
return myParams;
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
@Override
|
||||||
|
public QUERY where(ICriterion<?> theCriterion) {
|
||||||
|
ICriterionInternal criterion = (ICriterionInternal) theCriterion;
|
||||||
|
|
||||||
|
String parameterName = criterion.getParameterName();
|
||||||
|
String parameterValue = criterion.getParameterValue(myContext);
|
||||||
|
if (isNotBlank(parameterValue)) {
|
||||||
|
addParam(myParams, parameterName, parameterValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (QUERY) this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
@Override
|
||||||
|
public QUERY where(Map<String, List<IQueryParameterType>> theCriterion) {
|
||||||
|
Validate.notNull(theCriterion, "theCriterion must not be null");
|
||||||
|
for (Entry<String, List<IQueryParameterType>> nextEntry : theCriterion.entrySet()) {
|
||||||
|
String nextKey = nextEntry.getKey();
|
||||||
|
List<IQueryParameterType> nextValues = nextEntry.getValue();
|
||||||
|
for (IQueryParameterType nextValue : nextValues) {
|
||||||
|
addParam(myParams, nextKey, nextValue.getValueAsQueryToken(myContext));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return (QUERY) this;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private class CreateInternal extends BaseSearch<ICreateTyped, ICreateWithQueryTyped, MethodOutcome> implements ICreate, ICreateTyped, ICreateWithQuery, ICreateWithQueryTyped {
|
||||||
|
|
||||||
|
private boolean myConditional;
|
||||||
private String myId;
|
private String myId;
|
||||||
private PreferReturnEnum myPrefer;
|
private PreferReturnEnum myPrefer;
|
||||||
private IBaseResource myResource;
|
private IBaseResource myResource;
|
||||||
private String myResourceBody;
|
private String myResourceBody;
|
||||||
private String mySearchUrl;
|
private String mySearchUrl;
|
||||||
|
|
||||||
@Override
|
|
||||||
public ICreateWithQueryTyped and(ICriterion<?> theCriterion) {
|
|
||||||
myCriterionList.add((ICriterionInternal) theCriterion);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ICreateWithQuery conditional() {
|
public ICreateWithQuery conditional() {
|
||||||
myCriterionList = new CriterionList();
|
myConditional = true;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -534,8 +559,8 @@ public class GenericClient extends BaseClient implements IGenericClient {
|
||||||
BaseHttpClientInvocation invocation;
|
BaseHttpClientInvocation invocation;
|
||||||
if (mySearchUrl != null) {
|
if (mySearchUrl != null) {
|
||||||
invocation = MethodUtil.createCreateInvocation(myResource, myResourceBody, myId, myContext, mySearchUrl);
|
invocation = MethodUtil.createCreateInvocation(myResource, myResourceBody, myId, myContext, mySearchUrl);
|
||||||
} else if (myCriterionList != null) {
|
} else if (myConditional) {
|
||||||
invocation = MethodUtil.createCreateInvocation(myResource, myResourceBody, myId, myContext, myCriterionList.toParamList());
|
invocation = MethodUtil.createCreateInvocation(myResource, myResourceBody, myId, myContext, getParamMap());
|
||||||
} else {
|
} else {
|
||||||
invocation = MethodUtil.createCreateInvocation(myResource, myResourceBody, myId, myContext);
|
invocation = MethodUtil.createCreateInvocation(myResource, myResourceBody, myId, myContext);
|
||||||
}
|
}
|
||||||
|
@ -569,12 +594,6 @@ public class GenericClient extends BaseClient implements IGenericClient {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public ICreateWithQueryTyped where(ICriterion<?> theCriterion) {
|
|
||||||
myCriterionList.add((ICriterionInternal) theCriterion);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CreateInternal withId(IdDt theId) {
|
public CreateInternal withId(IdDt theId) {
|
||||||
myId = theId.getIdPart();
|
myId = theId.getIdPart();
|
||||||
|
@ -589,49 +608,20 @@ public class GenericClient extends BaseClient implements IGenericClient {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private class CriterionList extends ArrayList<ICriterionInternal> {
|
private class DeleteInternal extends BaseSearch<IDeleteTyped, IDeleteWithQueryTyped, IBaseOperationOutcome> implements IDelete, IDeleteTyped, IDeleteWithQuery, IDeleteWithQueryTyped {
|
||||||
|
|
||||||
private static final long serialVersionUID = 1L;
|
private boolean myConditional;
|
||||||
|
|
||||||
public void populateParamList(Map<String, List<String>> theParams) {
|
|
||||||
for (ICriterionInternal next : this) {
|
|
||||||
String parameterName = next.getParameterName();
|
|
||||||
String parameterValue = next.getParameterValue(myContext);
|
|
||||||
if (isNotBlank(parameterValue)) {
|
|
||||||
addParam(theParams, parameterName, parameterValue);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public Map<String, List<String>> toParamList() {
|
|
||||||
LinkedHashMap<String, List<String>> retVal = new LinkedHashMap<String, List<String>>();
|
|
||||||
populateParamList(retVal);
|
|
||||||
return retVal;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private class DeleteInternal extends BaseClientExecutable<IDeleteTyped, IBaseOperationOutcome> implements IDelete, IDeleteTyped, IDeleteWithQuery, IDeleteWithQueryTyped {
|
|
||||||
|
|
||||||
private CriterionList myCriterionList;
|
|
||||||
private IIdType myId;
|
private IIdType myId;
|
||||||
private String myResourceType;
|
private String myResourceType;
|
||||||
private String mySearchUrl;
|
private String mySearchUrl;
|
||||||
|
|
||||||
@Override
|
|
||||||
public IDeleteWithQueryTyped and(ICriterion<?> theCriterion) {
|
|
||||||
myCriterionList.add((ICriterionInternal) theCriterion);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IBaseOperationOutcome execute() {
|
public IBaseOperationOutcome execute() {
|
||||||
HttpDeleteClientInvocation invocation;
|
HttpDeleteClientInvocation invocation;
|
||||||
if (myId != null) {
|
if (myId != null) {
|
||||||
invocation = DeleteMethodBinding.createDeleteInvocation(getFhirContext(), myId);
|
invocation = DeleteMethodBinding.createDeleteInvocation(getFhirContext(), myId);
|
||||||
} else if (myCriterionList != null) {
|
} else if (myConditional) {
|
||||||
Map<String, List<String>> params = myCriterionList.toParamList();
|
invocation = DeleteMethodBinding.createDeleteInvocation(getFhirContext(), myResourceType, getParamMap());
|
||||||
invocation = DeleteMethodBinding.createDeleteInvocation(getFhirContext(), myResourceType, params);
|
|
||||||
} else {
|
} else {
|
||||||
invocation = DeleteMethodBinding.createDeleteInvocation(getFhirContext(), mySearchUrl);
|
invocation = DeleteMethodBinding.createDeleteInvocation(getFhirContext(), mySearchUrl);
|
||||||
}
|
}
|
||||||
|
@ -679,7 +669,7 @@ public class GenericClient extends BaseClient implements IGenericClient {
|
||||||
@Override
|
@Override
|
||||||
public IDeleteWithQuery resourceConditionalByType(Class<? extends IBaseResource> theResourceType) {
|
public IDeleteWithQuery resourceConditionalByType(Class<? extends IBaseResource> theResourceType) {
|
||||||
Validate.notNull(theResourceType, "theResourceType can not be null");
|
Validate.notNull(theResourceType, "theResourceType can not be null");
|
||||||
myCriterionList = new CriterionList();
|
myConditional = true;
|
||||||
myResourceType = myContext.getResourceDefinition(theResourceType).getName();
|
myResourceType = myContext.getResourceDefinition(theResourceType).getName();
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
@ -691,7 +681,7 @@ public class GenericClient extends BaseClient implements IGenericClient {
|
||||||
throw new IllegalArgumentException("Unknown resource type: " + theResourceType);
|
throw new IllegalArgumentException("Unknown resource type: " + theResourceType);
|
||||||
}
|
}
|
||||||
myResourceType = theResourceType;
|
myResourceType = theResourceType;
|
||||||
myCriterionList = new CriterionList();
|
myConditional = true;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -701,11 +691,6 @@ public class GenericClient extends BaseClient implements IGenericClient {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public IDeleteWithQueryTyped where(ICriterion<?> theCriterion) {
|
|
||||||
myCriterionList.add((ICriterionInternal) theCriterion);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||||
|
@ -755,7 +740,6 @@ public class GenericClient extends BaseClient implements IGenericClient {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@SuppressWarnings("rawtypes")
|
@SuppressWarnings("rawtypes")
|
||||||
private class HistoryInternal extends BaseClientExecutable implements IHistory, IHistoryUntyped, IHistoryTyped {
|
private class HistoryInternal extends BaseClientExecutable implements IHistory, IHistoryUntyped, IHistoryTyped {
|
||||||
|
|
||||||
|
@ -854,7 +838,6 @@ public class GenericClient extends BaseClient implements IGenericClient {
|
||||||
return new GetPageInternal(myPageUrl, theBundleType);
|
return new GetPageInternal(myPageUrl, theBundleType);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IGetPageUntyped byUrl(String thePageUrl) {
|
public IGetPageUntyped byUrl(String thePageUrl) {
|
||||||
if (isBlank(thePageUrl)) {
|
if (isBlank(thePageUrl)) {
|
||||||
|
@ -864,7 +847,6 @@ public class GenericClient extends BaseClient implements IGenericClient {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <T extends IBaseBundle> IGetPageTyped<T> next(T theBundle) {
|
public <T extends IBaseBundle> IGetPageTyped<T> next(T theBundle) {
|
||||||
return nextOrPrevious("next", theBundle);
|
return nextOrPrevious("next", theBundle);
|
||||||
|
@ -898,13 +880,11 @@ public class GenericClient extends BaseClient implements IGenericClient {
|
||||||
throw new IllegalArgumentException(myContext.getLocalizer().getMessage(GenericClient.class, "noPagingLinkFoundInBundle", theWantRel));
|
throw new IllegalArgumentException(myContext.getLocalizer().getMessage(GenericClient.class, "noPagingLinkFoundInBundle", theWantRel));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <T extends IBaseBundle> IGetPageTyped<T> previous(T theBundle) {
|
public <T extends IBaseBundle> IGetPageTyped<T> previous(T theBundle) {
|
||||||
return nextOrPrevious(PREVIOUS, theBundle);
|
return nextOrPrevious(PREVIOUS, theBundle);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("rawtypes")
|
@SuppressWarnings("rawtypes")
|
||||||
|
@ -993,7 +973,7 @@ public class GenericClient extends BaseClient implements IGenericClient {
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
@Override
|
@Override
|
||||||
public <T extends IBaseMetaType> IClientExecutable<IClientExecutable<?, ?>, T> meta(T theMeta) {
|
public <T extends IBaseMetaType> IClientExecutable<IClientExecutable<?, T>, T> meta(T theMeta) {
|
||||||
Validate.notNull(theMeta, "theMeta must not be null");
|
Validate.notNull(theMeta, "theMeta must not be null");
|
||||||
myMeta = theMeta;
|
myMeta = theMeta;
|
||||||
myMetaType = myMeta.getClass();
|
myMetaType = myMeta.getClass();
|
||||||
|
@ -1062,56 +1042,15 @@ public class GenericClient extends BaseClient implements IGenericClient {
|
||||||
implements IOperation, IOperationUnnamed, IOperationUntyped, IOperationUntypedWithInput, IOperationUntypedWithInputAndPartialOutput, IOperationProcessMsg, IOperationProcessMsgMode {
|
implements IOperation, IOperationUnnamed, IOperationUntyped, IOperationUntypedWithInput, IOperationUntypedWithInputAndPartialOutput, IOperationProcessMsg, IOperationProcessMsgMode {
|
||||||
|
|
||||||
private IIdType myId;
|
private IIdType myId;
|
||||||
|
private Boolean myIsAsync;
|
||||||
|
private IBaseBundle myMsgBundle;
|
||||||
private String myOperationName;
|
private String myOperationName;
|
||||||
private IBaseParameters myParameters;
|
private IBaseParameters myParameters;
|
||||||
private RuntimeResourceDefinition myParametersDef;
|
private RuntimeResourceDefinition myParametersDef;
|
||||||
|
private String myResponseUrl;
|
||||||
|
private Class myReturnResourceType;
|
||||||
private Class<? extends IBaseResource> myType;
|
private Class<? extends IBaseResource> myType;
|
||||||
private boolean myUseHttpGet;
|
private boolean myUseHttpGet;
|
||||||
private Class myReturnResourceType;
|
|
||||||
private IBaseBundle myMsgBundle;
|
|
||||||
private String myResponseUrl;
|
|
||||||
private Boolean myIsAsync;
|
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
@Override
|
|
||||||
public IOperationProcessMsgMode setMessageBundle(IBaseBundle theMsgBundle) {
|
|
||||||
|
|
||||||
Validate.notNull(theMsgBundle, "theMsgBundle must not be null");
|
|
||||||
/*
|
|
||||||
* Validate.isTrue(theMsgBundle.getType().getValueAsEnum() == BundleTypeEnum.MESSAGE);
|
|
||||||
* Validate.isTrue(theMsgBundle.getEntries().size() > 0);
|
|
||||||
* Validate.notNull(theMsgBundle.getEntries().get(0).getResource(), "Message Bundle first entry must be a MessageHeader resource");
|
|
||||||
* Validate.isTrue(theMsgBundle.getEntries().get(0).getResource().getResourceName().equals("MessageHeader"), "Message Bundle first entry must be a MessageHeader resource");
|
|
||||||
*/
|
|
||||||
myMsgBundle = theMsgBundle;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public IOperationProcessMsg setResponseUrlParam(String responseUrl) {
|
|
||||||
Validate.notEmpty(responseUrl, "responseUrl must not be null");
|
|
||||||
Validate.matchesPattern(responseUrl, "^(https?)://[-a-zA-Z0-9+&@#/%?=~_|!:,.;]*[-a-zA-Z0-9+&@#/%=~_|]", "responseUrl must be a valid URL");
|
|
||||||
myResponseUrl = responseUrl;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public IOperationProcessMsgMode asynchronous(Class theResponseClass) {
|
|
||||||
myIsAsync = true;
|
|
||||||
Validate.notNull(theResponseClass, "theReturnType must not be null");
|
|
||||||
Validate.isTrue(IBaseResource.class.isAssignableFrom(theResponseClass), "theReturnType must be a class which extends from IBaseResource");
|
|
||||||
myReturnResourceType = theResponseClass;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public IOperationProcessMsgMode synchronous(Class theResponseClass) {
|
|
||||||
myIsAsync = false;
|
|
||||||
Validate.notNull(theResponseClass, "theReturnType must not be null");
|
|
||||||
Validate.isTrue(IBaseResource.class.isAssignableFrom(theResponseClass), "theReturnType must be a class which extends from IBaseResource");
|
|
||||||
myReturnResourceType = theResponseClass;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
private void addParam(String theName, IBase theValue) {
|
private void addParam(String theName, IBase theValue) {
|
||||||
|
@ -1143,12 +1082,6 @@ public class GenericClient extends BaseClient implements IGenericClient {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public IOperationProcessMsg processMessage() {
|
|
||||||
myOperationName = Constants.EXTOP_PROCESS_MESSAGE;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void addParam(String theName, IQueryParameterType theValue) {
|
private void addParam(String theName, IQueryParameterType theValue) {
|
||||||
IPrimitiveType<?> stringType = ParametersUtil.createString(myContext, theValue.getValueAsQueryToken(myContext));
|
IPrimitiveType<?> stringType = ParametersUtil.createString(myContext, theValue.getValueAsQueryToken(myContext));
|
||||||
addParam(theName, stringType);
|
addParam(theName, stringType);
|
||||||
|
@ -1169,6 +1102,15 @@ public class GenericClient extends BaseClient implements IGenericClient {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public IOperationProcessMsgMode asynchronous(Class theResponseClass) {
|
||||||
|
myIsAsync = true;
|
||||||
|
Validate.notNull(theResponseClass, "theReturnType must not be null");
|
||||||
|
Validate.isTrue(IBaseResource.class.isAssignableFrom(theResponseClass), "theReturnType must be a class which extends from IBaseResource");
|
||||||
|
myReturnResourceType = theResponseClass;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
@Override
|
@Override
|
||||||
public Object execute() {
|
public Object execute() {
|
||||||
|
@ -1259,6 +1201,52 @@ public class GenericClient extends BaseClient implements IGenericClient {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public IOperationProcessMsg processMessage() {
|
||||||
|
myOperationName = Constants.EXTOP_PROCESS_MESSAGE;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public IOperationUntypedWithInput returnResourceType(Class theReturnType) {
|
||||||
|
Validate.notNull(theReturnType, "theReturnType must not be null");
|
||||||
|
Validate.isTrue(IBaseResource.class.isAssignableFrom(theReturnType), "theReturnType must be a class which extends from IBaseResource");
|
||||||
|
myReturnResourceType = theReturnType;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
@Override
|
||||||
|
public IOperationProcessMsgMode setMessageBundle(IBaseBundle theMsgBundle) {
|
||||||
|
|
||||||
|
Validate.notNull(theMsgBundle, "theMsgBundle must not be null");
|
||||||
|
/*
|
||||||
|
* Validate.isTrue(theMsgBundle.getType().getValueAsEnum() == BundleTypeEnum.MESSAGE);
|
||||||
|
* Validate.isTrue(theMsgBundle.getEntries().size() > 0);
|
||||||
|
* Validate.notNull(theMsgBundle.getEntries().get(0).getResource(), "Message Bundle first entry must be a MessageHeader resource");
|
||||||
|
* Validate.isTrue(theMsgBundle.getEntries().get(0).getResource().getResourceName().equals("MessageHeader"), "Message Bundle first entry must be a MessageHeader resource");
|
||||||
|
*/
|
||||||
|
myMsgBundle = theMsgBundle;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public IOperationProcessMsg setResponseUrlParam(String responseUrl) {
|
||||||
|
Validate.notEmpty(responseUrl, "responseUrl must not be null");
|
||||||
|
Validate.matchesPattern(responseUrl, "^(https?)://[-a-zA-Z0-9+&@#/%?=~_|!:,.;]*[-a-zA-Z0-9+&@#/%=~_|]", "responseUrl must be a valid URL");
|
||||||
|
myResponseUrl = responseUrl;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public IOperationProcessMsgMode synchronous(Class theResponseClass) {
|
||||||
|
myIsAsync = false;
|
||||||
|
Validate.notNull(theResponseClass, "theReturnType must not be null");
|
||||||
|
Validate.isTrue(IBaseResource.class.isAssignableFrom(theResponseClass), "theReturnType must be a class which extends from IBaseResource");
|
||||||
|
myReturnResourceType = theResponseClass;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IOperationUntypedWithInput useHttpGet() {
|
public IOperationUntypedWithInput useHttpGet() {
|
||||||
myUseHttpGet = true;
|
myUseHttpGet = true;
|
||||||
|
@ -1319,14 +1307,6 @@ public class GenericClient extends BaseClient implements IGenericClient {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public IOperationUntypedWithInput returnResourceType(Class theReturnType) {
|
|
||||||
Validate.notNull(theReturnType, "theReturnType must not be null");
|
|
||||||
Validate.isTrue(IBaseResource.class.isAssignableFrom(theReturnType), "theReturnType must be a class which extends from IBaseResource");
|
|
||||||
myReturnResourceType = theReturnType;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private final class OperationOutcomeResponseHandler implements IClientResponseHandler<IBaseOperationOutcome> {
|
private final class OperationOutcomeResponseHandler implements IClientResponseHandler<IBaseOperationOutcome> {
|
||||||
|
@ -1386,6 +1366,119 @@ public class GenericClient extends BaseClient implements IGenericClient {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private class PatchInternal extends BaseSearch<IPatchExecutable, IPatchWithQueryTyped, MethodOutcome> implements IPatch, IPatchWithBody, IPatchExecutable, IPatchWithQuery, IPatchWithQueryTyped {
|
||||||
|
|
||||||
|
private boolean myConditional;
|
||||||
|
private IIdType myId;
|
||||||
|
private String myPatchBody;
|
||||||
|
private PatchTypeEnum myPatchType;
|
||||||
|
private PreferReturnEnum myPrefer;
|
||||||
|
private String myResourceType;
|
||||||
|
private String mySearchUrl;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public IPatchWithQuery conditional(Class<? extends IBaseResource> theClass) {
|
||||||
|
Validate.notNull(theClass, "theClass must not be null");
|
||||||
|
String resourceType = myContext.getResourceDefinition(theClass).getName();
|
||||||
|
return conditional(resourceType);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public IPatchWithQuery conditional(String theResourceType) {
|
||||||
|
Validate.notBlank(theResourceType, "theResourceType must not be null");
|
||||||
|
myResourceType = theResourceType;
|
||||||
|
myConditional = true;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: This is not longer used.. Deprecate it or just remove it?
|
||||||
|
@Override
|
||||||
|
public IPatchWithBody conditionalByUrl(String theSearchUrl) {
|
||||||
|
mySearchUrl = validateAndEscapeConditionalUrl(theSearchUrl);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public MethodOutcome execute() {
|
||||||
|
|
||||||
|
if (myPatchType == null) {
|
||||||
|
throw new InvalidRequestException("No patch type supplied, cannot invoke server");
|
||||||
|
}
|
||||||
|
if (myPatchBody == null) {
|
||||||
|
throw new InvalidRequestException("No patch body supplied, cannot invoke server");
|
||||||
|
}
|
||||||
|
|
||||||
|
BaseHttpClientInvocation invocation;
|
||||||
|
if (isNotBlank(mySearchUrl)) {
|
||||||
|
invocation = MethodUtil.createPatchInvocation(myContext, mySearchUrl, myPatchType, myPatchBody);
|
||||||
|
} else if (myConditional) {
|
||||||
|
invocation = MethodUtil.createPatchInvocation(myContext, myPatchType, myPatchBody, myResourceType, getParamMap());
|
||||||
|
} else {
|
||||||
|
if (myId == null || myId.hasIdPart() == false) {
|
||||||
|
throw new InvalidRequestException("No ID supplied for resource to patch, can not invoke server");
|
||||||
|
}
|
||||||
|
invocation = MethodUtil.createPatchInvocation(myContext, myId, myPatchType, myPatchBody);
|
||||||
|
}
|
||||||
|
|
||||||
|
addPreferHeader(myPrefer, invocation);
|
||||||
|
|
||||||
|
OutcomeResponseHandler binding = new OutcomeResponseHandler(myPrefer);
|
||||||
|
|
||||||
|
Map<String, List<String>> params = new HashMap<String, List<String>>();
|
||||||
|
return invoke(params, binding, invocation);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public IPatchExecutable prefer(PreferReturnEnum theReturn) {
|
||||||
|
myPrefer = theReturn;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public IPatchWithBody withBody(String thePatchBody) {
|
||||||
|
Validate.notBlank(thePatchBody, "thePatchBody must not be blank");
|
||||||
|
|
||||||
|
myPatchBody = thePatchBody;
|
||||||
|
|
||||||
|
EncodingEnum encoding = EncodingEnum.detectEncodingNoDefault(thePatchBody);
|
||||||
|
if (encoding == EncodingEnum.XML) {
|
||||||
|
myPatchType = PatchTypeEnum.XML_PATCH;
|
||||||
|
} else if (encoding == EncodingEnum.JSON) {
|
||||||
|
myPatchType = PatchTypeEnum.JSON_PATCH;
|
||||||
|
} else {
|
||||||
|
throw new IllegalArgumentException("Unable to determine encoding of patch");
|
||||||
|
}
|
||||||
|
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public IPatchExecutable withId(IIdType theId) {
|
||||||
|
if (theId == null) {
|
||||||
|
throw new NullPointerException("theId can not be null");
|
||||||
|
}
|
||||||
|
if (theId.hasIdPart() == false) {
|
||||||
|
throw new NullPointerException("theId must not be blank and must contain an ID, found: " + theId.getValue());
|
||||||
|
}
|
||||||
|
myId = theId;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public IPatchExecutable withId(String theId) {
|
||||||
|
if (theId == null) {
|
||||||
|
throw new NullPointerException("theId can not be null");
|
||||||
|
}
|
||||||
|
if (isBlank(theId)) {
|
||||||
|
throw new NullPointerException("theId must not be blank and must contain an ID, found: " + theId);
|
||||||
|
}
|
||||||
|
myId = new IdDt(theId);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||||
private class ReadInternal extends BaseClientExecutable implements IRead, IReadTyped, IReadExecutable {
|
private class ReadInternal extends BaseClientExecutable implements IRead, IReadTyped, IReadExecutable {
|
||||||
private IIdType myId;
|
private IIdType myId;
|
||||||
|
@ -1533,10 +1626,9 @@ public class GenericClient extends BaseClient implements IGenericClient {
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||||
private class SearchInternal extends BaseClientExecutable implements IQuery, IUntypedQuery, IQueryTyped {
|
private class SearchInternal<OUTPUT> extends BaseSearch<IQuery<OUTPUT>, IQuery<OUTPUT>, OUTPUT> implements IQuery<OUTPUT>, IUntypedQuery<IQuery<OUTPUT>> {
|
||||||
|
|
||||||
private String myCompartmentName;
|
private String myCompartmentName;
|
||||||
private CriterionList myCriterion = new CriterionList();
|
|
||||||
private List<Include> myInclude = new ArrayList<Include>();
|
private List<Include> myInclude = new ArrayList<Include>();
|
||||||
private DateRangeParam myLastUpdated;
|
private DateRangeParam myLastUpdated;
|
||||||
private Integer myParamLimit;
|
private Integer myParamLimit;
|
||||||
|
@ -1558,12 +1650,6 @@ public class GenericClient extends BaseClient implements IGenericClient {
|
||||||
mySearchUrl = null;
|
mySearchUrl = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public IQuery and(ICriterion<?> theCriterion) {
|
|
||||||
myCriterion.add((ICriterionInternal) theCriterion);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IQuery byUrl(String theSearchUrl) {
|
public IQuery byUrl(String theSearchUrl) {
|
||||||
Validate.notBlank(theSearchUrl, "theSearchUrl must not be blank/null");
|
Validate.notBlank(theSearchUrl, "theSearchUrl must not be blank/null");
|
||||||
|
@ -1603,15 +1689,9 @@ public class GenericClient extends BaseClient implements IGenericClient {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object execute() {
|
public OUTPUT execute() {
|
||||||
|
|
||||||
Map<String, List<String>> params = new LinkedHashMap<String, List<String>>();
|
Map<String, List<String>> params = getParamMap();
|
||||||
// Map<String, List<String>> initial = createExtraParams();
|
|
||||||
// if (initial != null) {
|
|
||||||
// params.putAll(initial);
|
|
||||||
// }
|
|
||||||
|
|
||||||
myCriterion.populateParamList(params);
|
|
||||||
|
|
||||||
for (TokenParam next : myTags) {
|
for (TokenParam next : myTags) {
|
||||||
addParam(params, Constants.PARAM_TAG, next.getValueAsQueryToken(myContext));
|
addParam(params, Constants.PARAM_TAG, next.getValueAsQueryToken(myContext));
|
||||||
|
@ -1701,7 +1781,7 @@ public class GenericClient extends BaseClient implements IGenericClient {
|
||||||
invocation = SearchMethodBinding.createSearchInvocation(myContext, myResourceName, params, resourceId, myCompartmentName, mySearchStyle);
|
invocation = SearchMethodBinding.createSearchInvocation(myContext, myResourceName, params, resourceId, myCompartmentName, mySearchStyle);
|
||||||
}
|
}
|
||||||
|
|
||||||
return invoke(params, binding, invocation);
|
return (OUTPUT) invoke(params, binding, invocation);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1711,7 +1791,7 @@ public class GenericClient extends BaseClient implements IGenericClient {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IQuery forResource(Class<? extends IBaseResource> theResourceType) {
|
public IQuery forResource(Class theResourceType) {
|
||||||
setType(theResourceType);
|
setType(theResourceType);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
@ -1741,7 +1821,7 @@ public class GenericClient extends BaseClient implements IGenericClient {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IQueryTyped returnBundle(Class theClass) {
|
public IQuery returnBundle(Class theClass) {
|
||||||
if (theClass == null) {
|
if (theClass == null) {
|
||||||
throw new NullPointerException("theClass must not be null");
|
throw new NullPointerException("theClass must not be null");
|
||||||
}
|
}
|
||||||
|
@ -1780,8 +1860,9 @@ public class GenericClient extends BaseClient implements IGenericClient {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IQuery where(ICriterion<?> theCriterion) {
|
public IQuery withAnyProfile(Collection theProfileUris) {
|
||||||
myCriterion.add((ICriterionInternal) theCriterion);
|
Validate.notEmpty(theProfileUris, "theProfileUris must not be null or empty");
|
||||||
|
myProfiles.add(theProfileUris);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1799,13 +1880,6 @@ public class GenericClient extends BaseClient implements IGenericClient {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public IQuery withAnyProfile(Collection<String> theProfileUris) {
|
|
||||||
Validate.notEmpty(theProfileUris, "theProfileUris must not be null or empty");
|
|
||||||
myProfiles.add(theProfileUris);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IQuery withSecurity(String theSystem, String theCode) {
|
public IQuery withSecurity(String theSystem, String theCode) {
|
||||||
Validate.notBlank(theCode, "theCode must not be null or empty");
|
Validate.notBlank(theCode, "theCode must not be null or empty");
|
||||||
|
@ -1822,12 +1896,13 @@ public class GenericClient extends BaseClient implements IGenericClient {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("rawtypes")
|
||||||
private static class SortInternal implements ISort {
|
private static class SortInternal implements ISort {
|
||||||
|
|
||||||
|
private SortOrderEnum myDirection;
|
||||||
private SearchInternal myFor;
|
private SearchInternal myFor;
|
||||||
private String myParamName;
|
private String myParamName;
|
||||||
private String myParamValue;
|
private String myParamValue;
|
||||||
private SortOrderEnum myDirection;
|
|
||||||
|
|
||||||
public SortInternal(SearchInternal theFor) {
|
public SortInternal(SearchInternal theFor) {
|
||||||
myFor = theFor;
|
myFor = theFor;
|
||||||
|
@ -1896,7 +1971,6 @@ public class GenericClient extends BaseClient implements IGenericClient {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private final class TransactionExecutable<T> extends BaseClientExecutable<ITransactionTyped<T>, T> implements ITransactionTyped<T> {
|
private final class TransactionExecutable<T> extends BaseClientExecutable<ITransactionTyped<T>, T> implements ITransactionTyped<T> {
|
||||||
|
|
||||||
private IBaseBundle myBaseBundle;
|
private IBaseBundle myBaseBundle;
|
||||||
|
@ -1932,7 +2006,7 @@ public class GenericClient extends BaseClient implements IGenericClient {
|
||||||
ResourceResponseHandler binding = new ResourceResponseHandler(myBaseBundle.getClass(), getPreferResponseTypes());
|
ResourceResponseHandler binding = new ResourceResponseHandler(myBaseBundle.getClass(), getPreferResponseTypes());
|
||||||
BaseHttpClientInvocation invocation = TransactionMethodBinding.createTransactionInvocation(myBaseBundle, myContext);
|
BaseHttpClientInvocation invocation = TransactionMethodBinding.createTransactionInvocation(myBaseBundle, myContext);
|
||||||
return (T) invoke(params, binding, invocation);
|
return (T) invoke(params, binding, invocation);
|
||||||
// } else if (myRawBundle != null) {
|
// } else if (myRawBundle != null) {
|
||||||
} else {
|
} else {
|
||||||
StringResponseHandler binding = new StringResponseHandler();
|
StringResponseHandler binding = new StringResponseHandler();
|
||||||
/*
|
/*
|
||||||
|
@ -1953,7 +2027,6 @@ public class GenericClient extends BaseClient implements IGenericClient {
|
||||||
|
|
||||||
private final class TransactionInternal implements ITransaction {
|
private final class TransactionInternal implements ITransaction {
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ITransactionTyped<String> withBundle(String theBundle) {
|
public ITransactionTyped<String> withBundle(String theBundle) {
|
||||||
Validate.notBlank(theBundle, "theBundle must not be null");
|
Validate.notBlank(theBundle, "theBundle must not be null");
|
||||||
|
@ -1974,149 +2047,19 @@ public class GenericClient extends BaseClient implements IGenericClient {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private class PatchInternal extends BaseClientExecutable<IPatchExecutable, MethodOutcome> implements IPatch, IPatchWithBody, IPatchExecutable, IPatchWithQuery, IPatchWithQueryTyped {
|
private class UpdateInternal extends BaseSearch<IUpdateExecutable, IUpdateWithQueryTyped, MethodOutcome>
|
||||||
|
implements IUpdate, IUpdateTyped, IUpdateExecutable, IUpdateWithQuery, IUpdateWithQueryTyped {
|
||||||
|
|
||||||
private CriterionList myCriterionList;
|
private boolean myConditional;
|
||||||
private IIdType myId;
|
|
||||||
private PreferReturnEnum myPrefer;
|
|
||||||
private PatchTypeEnum myPatchType;
|
|
||||||
private String myPatchBody;
|
|
||||||
private String mySearchUrl;
|
|
||||||
private String myResourceType;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public IPatchWithQueryTyped and(ICriterion<?> theCriterion) {
|
|
||||||
myCriterionList.add((ICriterionInternal) theCriterion);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public IPatchWithQuery conditional(String theResourceType) {
|
|
||||||
Validate.notBlank(theResourceType, "theResourceType must not be null");
|
|
||||||
myResourceType = theResourceType;
|
|
||||||
myCriterionList = new CriterionList();
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: This is not longer used.. Deprecate it or just remove it?
|
|
||||||
@Override
|
|
||||||
public IPatchWithBody conditionalByUrl(String theSearchUrl) {
|
|
||||||
mySearchUrl = validateAndEscapeConditionalUrl(theSearchUrl);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public MethodOutcome execute() {
|
|
||||||
|
|
||||||
if (myPatchType == null) {
|
|
||||||
throw new InvalidRequestException("No patch type supplied, cannot invoke server");
|
|
||||||
}
|
|
||||||
if (myPatchBody == null) {
|
|
||||||
throw new InvalidRequestException("No patch body supplied, cannot invoke server");
|
|
||||||
}
|
|
||||||
|
|
||||||
BaseHttpClientInvocation invocation;
|
|
||||||
if (isNotBlank(mySearchUrl)) {
|
|
||||||
invocation = MethodUtil.createPatchInvocation(myContext, mySearchUrl, myPatchType, myPatchBody);
|
|
||||||
} else if (myCriterionList != null) {
|
|
||||||
invocation = MethodUtil.createPatchInvocation(myContext, myPatchType, myPatchBody, myResourceType, myCriterionList.toParamList());
|
|
||||||
} else {
|
|
||||||
if (myId == null || myId.hasIdPart() == false) {
|
|
||||||
throw new InvalidRequestException("No ID supplied for resource to patch, can not invoke server");
|
|
||||||
}
|
|
||||||
invocation = MethodUtil.createPatchInvocation(myContext, myId, myPatchType, myPatchBody);
|
|
||||||
}
|
|
||||||
|
|
||||||
addPreferHeader(myPrefer, invocation);
|
|
||||||
|
|
||||||
OutcomeResponseHandler binding = new OutcomeResponseHandler(myPrefer);
|
|
||||||
|
|
||||||
Map<String, List<String>> params = new HashMap<String, List<String>>();
|
|
||||||
return invoke(params, binding, invocation);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public IPatchExecutable prefer(PreferReturnEnum theReturn) {
|
|
||||||
myPrefer = theReturn;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public IPatchWithQueryTyped where(ICriterion<?> theCriterion) {
|
|
||||||
myCriterionList.add((ICriterionInternal) theCriterion);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public IPatchExecutable withId(IIdType theId) {
|
|
||||||
if (theId == null) {
|
|
||||||
throw new NullPointerException("theId can not be null");
|
|
||||||
}
|
|
||||||
if (theId.hasIdPart() == false) {
|
|
||||||
throw new NullPointerException("theId must not be blank and must contain an ID, found: " + theId.getValue());
|
|
||||||
}
|
|
||||||
myId = theId;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public IPatchExecutable withId(String theId) {
|
|
||||||
if (theId == null) {
|
|
||||||
throw new NullPointerException("theId can not be null");
|
|
||||||
}
|
|
||||||
if (isBlank(theId)) {
|
|
||||||
throw new NullPointerException("theId must not be blank and must contain an ID, found: " + theId);
|
|
||||||
}
|
|
||||||
myId = new IdDt(theId);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public IPatchWithBody withBody(String thePatchBody) {
|
|
||||||
Validate.notBlank(thePatchBody, "thePatchBody must not be blank");
|
|
||||||
|
|
||||||
myPatchBody = thePatchBody;
|
|
||||||
|
|
||||||
EncodingEnum encoding = EncodingEnum.detectEncodingNoDefault(thePatchBody);
|
|
||||||
if (encoding == EncodingEnum.XML) {
|
|
||||||
myPatchType = PatchTypeEnum.XML_PATCH;
|
|
||||||
} else if (encoding == EncodingEnum.JSON) {
|
|
||||||
myPatchType = PatchTypeEnum.JSON_PATCH;
|
|
||||||
} else {
|
|
||||||
throw new IllegalArgumentException("Unable to determine encoding of patch");
|
|
||||||
}
|
|
||||||
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public IPatchWithQuery conditional(Class<? extends IBaseResource> theClass) {
|
|
||||||
Validate.notNull(theClass, "theClass must not be null");
|
|
||||||
String resourceType = myContext.getResourceDefinition(theClass).getName();
|
|
||||||
return conditional(resourceType);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private class UpdateInternal extends BaseClientExecutable<IUpdateExecutable, MethodOutcome> implements IUpdate, IUpdateTyped, IUpdateExecutable, IUpdateWithQuery, IUpdateWithQueryTyped {
|
|
||||||
|
|
||||||
private CriterionList myCriterionList;
|
|
||||||
private IIdType myId;
|
private IIdType myId;
|
||||||
private PreferReturnEnum myPrefer;
|
private PreferReturnEnum myPrefer;
|
||||||
private IBaseResource myResource;
|
private IBaseResource myResource;
|
||||||
private String myResourceBody;
|
private String myResourceBody;
|
||||||
private String mySearchUrl;
|
private String mySearchUrl;
|
||||||
|
|
||||||
@Override
|
|
||||||
public IUpdateWithQueryTyped and(ICriterion<?> theCriterion) {
|
|
||||||
myCriterionList.add((ICriterionInternal) theCriterion);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IUpdateWithQuery conditional() {
|
public IUpdateWithQuery conditional() {
|
||||||
myCriterionList = new CriterionList();
|
myConditional = true;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2140,8 +2083,8 @@ public class GenericClient extends BaseClient implements IGenericClient {
|
||||||
BaseHttpClientInvocation invocation;
|
BaseHttpClientInvocation invocation;
|
||||||
if (mySearchUrl != null) {
|
if (mySearchUrl != null) {
|
||||||
invocation = MethodUtil.createUpdateInvocation(myContext, myResource, myResourceBody, mySearchUrl);
|
invocation = MethodUtil.createUpdateInvocation(myContext, myResource, myResourceBody, mySearchUrl);
|
||||||
} else if (myCriterionList != null) {
|
} else if (myConditional) {
|
||||||
invocation = MethodUtil.createUpdateInvocation(myContext, myResource, myResourceBody, myCriterionList.toParamList());
|
invocation = MethodUtil.createUpdateInvocation(myContext, myResource, myResourceBody, getParamMap());
|
||||||
} else {
|
} else {
|
||||||
if (myId == null) {
|
if (myId == null) {
|
||||||
myId = myResource.getIdElement();
|
myId = myResource.getIdElement();
|
||||||
|
@ -2182,12 +2125,6 @@ public class GenericClient extends BaseClient implements IGenericClient {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public IUpdateWithQueryTyped where(ICriterion<?> theCriterion) {
|
|
||||||
myCriterionList.add((ICriterionInternal) theCriterion);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IUpdateExecutable withId(IIdType theId) {
|
public IUpdateExecutable withId(IIdType theId) {
|
||||||
if (theId == null) {
|
if (theId == null) {
|
||||||
|
|
|
@ -13,7 +13,8 @@ import ca.uhn.fhir.context.RuntimeResourceDefinition;
|
||||||
import ca.uhn.fhir.context.RuntimeSearchParam;
|
import ca.uhn.fhir.context.RuntimeSearchParam;
|
||||||
import ca.uhn.fhir.jpa.entity.ResourceTable;
|
import ca.uhn.fhir.jpa.entity.ResourceTable;
|
||||||
import ca.uhn.fhir.jpa.util.DeleteConflict;
|
import ca.uhn.fhir.jpa.util.DeleteConflict;
|
||||||
import ca.uhn.fhir.model.api.*;
|
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.base.composite.BaseResourceReferenceDt;
|
||||||
import ca.uhn.fhir.model.dstu2.resource.OperationOutcome;
|
import ca.uhn.fhir.model.dstu2.resource.OperationOutcome;
|
||||||
import ca.uhn.fhir.model.dstu2.valueset.IssueSeverityEnum;
|
import ca.uhn.fhir.model.dstu2.valueset.IssueSeverityEnum;
|
||||||
|
@ -22,7 +23,6 @@ import ca.uhn.fhir.rest.api.*;
|
||||||
import ca.uhn.fhir.rest.api.server.RequestDetails;
|
import ca.uhn.fhir.rest.api.server.RequestDetails;
|
||||||
import ca.uhn.fhir.rest.server.exceptions.*;
|
import ca.uhn.fhir.rest.server.exceptions.*;
|
||||||
import ca.uhn.fhir.rest.server.interceptor.IServerInterceptor.ActionRequestDetails;
|
import ca.uhn.fhir.rest.server.interceptor.IServerInterceptor.ActionRequestDetails;
|
||||||
import ca.uhn.fhir.util.CoverageIgnore;
|
|
||||||
import ca.uhn.fhir.util.FhirTerser;
|
import ca.uhn.fhir.util.FhirTerser;
|
||||||
import ca.uhn.fhir.validation.*;
|
import ca.uhn.fhir.validation.*;
|
||||||
|
|
||||||
|
@ -155,12 +155,6 @@ public class FhirResourceDaoDstu2<T extends IResource> extends BaseHapiFhirResou
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@CoverageIgnore
|
|
||||||
@Override
|
|
||||||
public void validateBundle(IValidationContext<Bundle> theContext) {
|
|
||||||
throw new UnsupportedOperationException();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,19 +33,18 @@ import org.hl7.fhir.instance.model.api.*;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.beans.factory.annotation.Qualifier;
|
import org.springframework.beans.factory.annotation.Qualifier;
|
||||||
|
|
||||||
import ca.uhn.fhir.context.*;
|
import ca.uhn.fhir.context.RuntimeResourceDefinition;
|
||||||
|
import ca.uhn.fhir.context.RuntimeSearchParam;
|
||||||
import ca.uhn.fhir.jpa.dao.BaseHapiFhirResourceDao;
|
import ca.uhn.fhir.jpa.dao.BaseHapiFhirResourceDao;
|
||||||
import ca.uhn.fhir.jpa.dao.IFhirResourceDao;
|
import ca.uhn.fhir.jpa.dao.IFhirResourceDao;
|
||||||
import ca.uhn.fhir.jpa.entity.ResourceTable;
|
import ca.uhn.fhir.jpa.entity.ResourceTable;
|
||||||
import ca.uhn.fhir.jpa.util.DeleteConflict;
|
import ca.uhn.fhir.jpa.util.DeleteConflict;
|
||||||
import ca.uhn.fhir.model.api.Bundle;
|
|
||||||
import ca.uhn.fhir.model.api.Include;
|
import ca.uhn.fhir.model.api.Include;
|
||||||
import ca.uhn.fhir.model.base.composite.BaseResourceReferenceDt;
|
import ca.uhn.fhir.model.base.composite.BaseResourceReferenceDt;
|
||||||
import ca.uhn.fhir.rest.api.*;
|
import ca.uhn.fhir.rest.api.*;
|
||||||
import ca.uhn.fhir.rest.api.server.RequestDetails;
|
import ca.uhn.fhir.rest.api.server.RequestDetails;
|
||||||
import ca.uhn.fhir.rest.server.exceptions.*;
|
import ca.uhn.fhir.rest.server.exceptions.*;
|
||||||
import ca.uhn.fhir.rest.server.interceptor.IServerInterceptor.ActionRequestDetails;
|
import ca.uhn.fhir.rest.server.interceptor.IServerInterceptor.ActionRequestDetails;
|
||||||
import ca.uhn.fhir.util.CoverageIgnore;
|
|
||||||
import ca.uhn.fhir.util.FhirTerser;
|
import ca.uhn.fhir.util.FhirTerser;
|
||||||
import ca.uhn.fhir.validation.*;
|
import ca.uhn.fhir.validation.*;
|
||||||
|
|
||||||
|
@ -57,9 +56,6 @@ public class FhirResourceDaoDstu3<T extends IAnyResource> extends BaseHapiFhirRe
|
||||||
@Qualifier("myInstanceValidatorDstu3")
|
@Qualifier("myInstanceValidatorDstu3")
|
||||||
private IValidatorModule myInstanceValidator;
|
private IValidatorModule myInstanceValidator;
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private FhirContext fhirContext;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected IBaseOperationOutcome createOperationOutcome(String theSeverity, String theMessage, String theCode) {
|
protected IBaseOperationOutcome createOperationOutcome(String theSeverity, String theMessage, String theCode) {
|
||||||
OperationOutcome oo = new OperationOutcome();
|
OperationOutcome oo = new OperationOutcome();
|
||||||
|
@ -160,12 +156,6 @@ public class FhirResourceDaoDstu3<T extends IAnyResource> extends BaseHapiFhirRe
|
||||||
myMode = theMode;
|
myMode = theMode;
|
||||||
}
|
}
|
||||||
|
|
||||||
@CoverageIgnore
|
|
||||||
@Override
|
|
||||||
public void validateBundle(IValidationContext<Bundle> theContext) {
|
|
||||||
throw new UnsupportedOperationException();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void validateResource(IValidationContext<IBaseResource> theCtx) {
|
public void validateResource(IValidationContext<IBaseResource> theCtx) {
|
||||||
boolean hasId = theCtx.getResource().getIdElement().hasIdPart();
|
boolean hasId = theCtx.getResource().getIdElement().hasIdPart();
|
||||||
|
|
|
@ -24,28 +24,27 @@ import static org.apache.commons.lang3.StringUtils.isNotBlank;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
|
import org.hl7.fhir.exceptions.FHIRException;
|
||||||
|
import org.hl7.fhir.instance.model.api.*;
|
||||||
import org.hl7.fhir.r4.model.IdType;
|
import org.hl7.fhir.r4.model.IdType;
|
||||||
import org.hl7.fhir.r4.model.OperationOutcome;
|
import org.hl7.fhir.r4.model.OperationOutcome;
|
||||||
import org.hl7.fhir.r4.model.OperationOutcome.IssueSeverity;
|
import org.hl7.fhir.r4.model.OperationOutcome.IssueSeverity;
|
||||||
import org.hl7.fhir.r4.model.OperationOutcome.OperationOutcomeIssueComponent;
|
import org.hl7.fhir.r4.model.OperationOutcome.OperationOutcomeIssueComponent;
|
||||||
import org.hl7.fhir.exceptions.FHIRException;
|
|
||||||
import org.hl7.fhir.instance.model.api.*;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.beans.factory.annotation.Qualifier;
|
import org.springframework.beans.factory.annotation.Qualifier;
|
||||||
|
|
||||||
import ca.uhn.fhir.context.*;
|
import ca.uhn.fhir.context.RuntimeResourceDefinition;
|
||||||
|
import ca.uhn.fhir.context.RuntimeSearchParam;
|
||||||
import ca.uhn.fhir.jpa.dao.BaseHapiFhirResourceDao;
|
import ca.uhn.fhir.jpa.dao.BaseHapiFhirResourceDao;
|
||||||
import ca.uhn.fhir.jpa.dao.IFhirResourceDao;
|
import ca.uhn.fhir.jpa.dao.IFhirResourceDao;
|
||||||
import ca.uhn.fhir.jpa.entity.ResourceTable;
|
import ca.uhn.fhir.jpa.entity.ResourceTable;
|
||||||
import ca.uhn.fhir.jpa.util.DeleteConflict;
|
import ca.uhn.fhir.jpa.util.DeleteConflict;
|
||||||
import ca.uhn.fhir.model.api.Bundle;
|
|
||||||
import ca.uhn.fhir.model.api.Include;
|
import ca.uhn.fhir.model.api.Include;
|
||||||
import ca.uhn.fhir.model.base.composite.BaseResourceReferenceDt;
|
import ca.uhn.fhir.model.base.composite.BaseResourceReferenceDt;
|
||||||
import ca.uhn.fhir.rest.api.*;
|
import ca.uhn.fhir.rest.api.*;
|
||||||
import ca.uhn.fhir.rest.api.server.RequestDetails;
|
import ca.uhn.fhir.rest.api.server.RequestDetails;
|
||||||
import ca.uhn.fhir.rest.server.exceptions.*;
|
import ca.uhn.fhir.rest.server.exceptions.*;
|
||||||
import ca.uhn.fhir.rest.server.interceptor.IServerInterceptor.ActionRequestDetails;
|
import ca.uhn.fhir.rest.server.interceptor.IServerInterceptor.ActionRequestDetails;
|
||||||
import ca.uhn.fhir.util.CoverageIgnore;
|
|
||||||
import ca.uhn.fhir.util.FhirTerser;
|
import ca.uhn.fhir.util.FhirTerser;
|
||||||
import ca.uhn.fhir.validation.*;
|
import ca.uhn.fhir.validation.*;
|
||||||
|
|
||||||
|
@ -57,9 +56,6 @@ public class FhirResourceDaoR4<T extends IAnyResource> extends BaseHapiFhirResou
|
||||||
@Qualifier("myInstanceValidatorDstu3")
|
@Qualifier("myInstanceValidatorDstu3")
|
||||||
private IValidatorModule myInstanceValidator;
|
private IValidatorModule myInstanceValidator;
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private FhirContext fhirContext;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected IBaseOperationOutcome createOperationOutcome(String theSeverity, String theMessage, String theCode) {
|
protected IBaseOperationOutcome createOperationOutcome(String theSeverity, String theMessage, String theCode) {
|
||||||
OperationOutcome oo = new OperationOutcome();
|
OperationOutcome oo = new OperationOutcome();
|
||||||
|
@ -160,12 +156,6 @@ public class FhirResourceDaoR4<T extends IAnyResource> extends BaseHapiFhirResou
|
||||||
myMode = theMode;
|
myMode = theMode;
|
||||||
}
|
}
|
||||||
|
|
||||||
@CoverageIgnore
|
|
||||||
@Override
|
|
||||||
public void validateBundle(IValidationContext<Bundle> theContext) {
|
|
||||||
throw new UnsupportedOperationException();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void validateResource(IValidationContext<IBaseResource> theCtx) {
|
public void validateResource(IValidationContext<IBaseResource> theCtx) {
|
||||||
boolean hasId = theCtx.getResource().getIdElement().hasIdPart();
|
boolean hasId = theCtx.getResource().getIdElement().hasIdPart();
|
||||||
|
|
|
@ -30,7 +30,6 @@ import org.springframework.beans.factory.annotation.Required;
|
||||||
|
|
||||||
import ca.uhn.fhir.jpa.dao.DaoMethodOutcome;
|
import ca.uhn.fhir.jpa.dao.DaoMethodOutcome;
|
||||||
import ca.uhn.fhir.jpa.dao.IFhirResourceDao;
|
import ca.uhn.fhir.jpa.dao.IFhirResourceDao;
|
||||||
import ca.uhn.fhir.model.api.TagList;
|
|
||||||
import ca.uhn.fhir.rest.annotation.*;
|
import ca.uhn.fhir.rest.annotation.*;
|
||||||
import ca.uhn.fhir.rest.api.PatchTypeEnum;
|
import ca.uhn.fhir.rest.api.PatchTypeEnum;
|
||||||
import ca.uhn.fhir.rest.api.server.IBundleProvider;
|
import ca.uhn.fhir.rest.api.server.IBundleProvider;
|
||||||
|
@ -95,26 +94,6 @@ public abstract class BaseJpaResourceProvider<T extends IBaseResource> extends B
|
||||||
return myDao.getResourceType();
|
return myDao.getResourceType();
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetTags
|
|
||||||
public TagList getTagsForResourceInstance(HttpServletRequest theRequest, @IdParam IIdType theResourceId, RequestDetails theRequestDetails) {
|
|
||||||
startRequest(theRequest);
|
|
||||||
try {
|
|
||||||
return myDao.getTags(theResourceId, theRequestDetails);
|
|
||||||
} finally {
|
|
||||||
endRequest(theRequest);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@GetTags
|
|
||||||
public TagList getTagsForResourceType(HttpServletRequest theRequest, RequestDetails theRequestDetails) {
|
|
||||||
startRequest(theRequest);
|
|
||||||
try {
|
|
||||||
return myDao.getAllResourceTags(theRequestDetails);
|
|
||||||
} finally {
|
|
||||||
endRequest(theRequest);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Read(version = true)
|
@Read(version = true)
|
||||||
public T read(HttpServletRequest theRequest, @IdParam IIdType theId, RequestDetails theRequestDetails) {
|
public T read(HttpServletRequest theRequest, @IdParam IIdType theId, RequestDetails theRequestDetails) {
|
||||||
startRequest(theRequest);
|
startRequest(theRequest);
|
||||||
|
|
|
@ -27,7 +27,6 @@ import javax.servlet.http.HttpServletRequest;
|
||||||
import org.springframework.beans.factory.annotation.Required;
|
import org.springframework.beans.factory.annotation.Required;
|
||||||
|
|
||||||
import ca.uhn.fhir.jpa.dao.IFhirSystemDao;
|
import ca.uhn.fhir.jpa.dao.IFhirSystemDao;
|
||||||
import ca.uhn.fhir.model.api.TagList;
|
|
||||||
import ca.uhn.fhir.rest.annotation.*;
|
import ca.uhn.fhir.rest.annotation.*;
|
||||||
import ca.uhn.fhir.rest.api.server.IBundleProvider;
|
import ca.uhn.fhir.rest.api.server.IBundleProvider;
|
||||||
import ca.uhn.fhir.rest.api.server.RequestDetails;
|
import ca.uhn.fhir.rest.api.server.RequestDetails;
|
||||||
|
@ -43,16 +42,6 @@ public class BaseJpaSystemProvider<T, MT> extends BaseJpaProvider {
|
||||||
// nothing
|
// nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetTags
|
|
||||||
public TagList getAllTagsOnServer(HttpServletRequest theRequest, RequestDetails theRequestDetails) {
|
|
||||||
startRequest(theRequest);
|
|
||||||
try {
|
|
||||||
return myDao.getAllTags(theRequestDetails);
|
|
||||||
} finally {
|
|
||||||
endRequest(theRequest);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected IFhirSystemDao<T, MT> getDao() {
|
protected IFhirSystemDao<T, MT> getDao() {
|
||||||
return myDao;
|
return myDao;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,23 @@
|
||||||
package ca.uhn.fhir.jpa.provider;
|
package ca.uhn.fhir.jpa.provider;
|
||||||
|
|
||||||
import static org.hamcrest.Matchers.*;
|
import static org.hamcrest.Matchers.contains;
|
||||||
import static org.junit.Assert.*;
|
import static org.hamcrest.Matchers.containsInAnyOrder;
|
||||||
|
import static org.hamcrest.Matchers.containsInRelativeOrder;
|
||||||
|
import static org.hamcrest.Matchers.containsString;
|
||||||
|
import static org.hamcrest.Matchers.empty;
|
||||||
|
import static org.hamcrest.Matchers.emptyString;
|
||||||
|
import static org.hamcrest.Matchers.greaterThan;
|
||||||
|
import static org.hamcrest.Matchers.hasItems;
|
||||||
|
import static org.hamcrest.Matchers.not;
|
||||||
|
import static org.hamcrest.Matchers.startsWith;
|
||||||
|
import static org.hamcrest.Matchers.stringContainsInOrder;
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertFalse;
|
||||||
|
import static org.junit.Assert.assertNotEquals;
|
||||||
|
import static org.junit.Assert.assertNotNull;
|
||||||
|
import static org.junit.Assert.assertThat;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
import static org.junit.Assert.fail;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.net.*;
|
import java.net.*;
|
||||||
|
@ -34,7 +50,6 @@ import ca.uhn.fhir.model.valueset.BundleTypeEnum;
|
||||||
import ca.uhn.fhir.parser.IParser;
|
import ca.uhn.fhir.parser.IParser;
|
||||||
import ca.uhn.fhir.rest.api.*;
|
import ca.uhn.fhir.rest.api.*;
|
||||||
import ca.uhn.fhir.rest.client.api.IGenericClient;
|
import ca.uhn.fhir.rest.client.api.IGenericClient;
|
||||||
import ca.uhn.fhir.rest.gclient.*;
|
|
||||||
import ca.uhn.fhir.rest.param.*;
|
import ca.uhn.fhir.rest.param.*;
|
||||||
import ca.uhn.fhir.rest.server.exceptions.*;
|
import ca.uhn.fhir.rest.server.exceptions.*;
|
||||||
import ca.uhn.fhir.util.*;
|
import ca.uhn.fhir.util.*;
|
||||||
|
@ -457,6 +472,7 @@ public class ResourceProviderDstu2Test extends BaseResourceProviderDstu2Test {
|
||||||
.forResource(Organization.class)
|
.forResource(Organization.class)
|
||||||
.where(Organization.NAME.matches().value("rpdstu2_testCountParam_01"))
|
.where(Organization.NAME.matches().value("rpdstu2_testCountParam_01"))
|
||||||
.count(10)
|
.count(10)
|
||||||
|
.returnBundle(Bundle.class)
|
||||||
.execute();
|
.execute();
|
||||||
assertEquals(100, found.getTotalElement().getValue().intValue());
|
assertEquals(100, found.getTotalElement().getValue().intValue());
|
||||||
assertEquals(10, found.getEntry().size());
|
assertEquals(10, found.getEntry().size());
|
||||||
|
@ -466,6 +482,7 @@ public class ResourceProviderDstu2Test extends BaseResourceProviderDstu2Test {
|
||||||
.forResource(Organization.class)
|
.forResource(Organization.class)
|
||||||
.where(Organization.NAME.matches().value("rpdstu2_testCountParam_01"))
|
.where(Organization.NAME.matches().value("rpdstu2_testCountParam_01"))
|
||||||
.count(999)
|
.count(999)
|
||||||
|
.returnBundle(Bundle.class)
|
||||||
.execute();
|
.execute();
|
||||||
assertEquals(100, found.getTotalElement().getValue().intValue());
|
assertEquals(100, found.getTotalElement().getValue().intValue());
|
||||||
assertEquals(50, found.getEntry().size());
|
assertEquals(50, found.getEntry().size());
|
||||||
|
@ -704,6 +721,7 @@ public class ResourceProviderDstu2Test extends BaseResourceProviderDstu2Test {
|
||||||
.where(Encounter.IDENTIFIER.exactly().systemAndCode("urn:foo", "testDeepChainingE1"))
|
.where(Encounter.IDENTIFIER.exactly().systemAndCode("urn:foo", "testDeepChainingE1"))
|
||||||
.include(Encounter.INCLUDE_LOCATION.asRecursive())
|
.include(Encounter.INCLUDE_LOCATION.asRecursive())
|
||||||
.include(Location.INCLUDE_PARTOF.asRecursive())
|
.include(Location.INCLUDE_PARTOF.asRecursive())
|
||||||
|
.returnBundle(Bundle.class)
|
||||||
.execute();
|
.execute();
|
||||||
|
|
||||||
assertEquals(3, res.getEntry().size());
|
assertEquals(3, res.getEntry().size());
|
||||||
|
@ -1581,15 +1599,6 @@ public class ResourceProviderDstu2Test extends BaseResourceProviderDstu2Test {
|
||||||
pat = new Patient();
|
pat = new Patient();
|
||||||
pat.addIdentifier().setSystem("urn:system").setValue("testReadAllInstancesOfType_02");
|
pat.addIdentifier().setSystem("urn:system").setValue("testReadAllInstancesOfType_02");
|
||||||
ourClient.create().resource(pat).prettyPrint().encodedXml().execute().getId();
|
ourClient.create().resource(pat).prettyPrint().encodedXml().execute().getId();
|
||||||
{
|
|
||||||
IQuery a = ourClient
|
|
||||||
.search()
|
|
||||||
.forResource(Patient.class);
|
|
||||||
IQueryTyped<Bundle> b = a.returnBundle(Bundle.class);
|
|
||||||
IClientExecutable<?, ?> x = b.encodedXml();
|
|
||||||
x.execute();
|
|
||||||
|
|
||||||
}
|
|
||||||
{
|
{
|
||||||
Bundle returned = ourClient
|
Bundle returned = ourClient
|
||||||
.search()
|
.search()
|
||||||
|
@ -1598,10 +1607,15 @@ public class ResourceProviderDstu2Test extends BaseResourceProviderDstu2Test {
|
||||||
.encodedXml()
|
.encodedXml()
|
||||||
.execute();
|
.execute();
|
||||||
assertThat(returned.getEntry().size(), greaterThan(1));
|
assertThat(returned.getEntry().size(), greaterThan(1));
|
||||||
assertEquals(BundleTypeEnum.SEARCHSET, returned.getType().getValueAsEnum());
|
assertEquals(BundleTypeEnum.SEARCHSET, returned.getTypeElement().getValueAsEnum());
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
Bundle returned = ourClient.search().forResource(Patient.class).encodedJson().execute();
|
Bundle returned = ourClient
|
||||||
|
.search()
|
||||||
|
.forResource(Patient.class)
|
||||||
|
.encodedJson()
|
||||||
|
.returnBundle(Bundle.class)
|
||||||
|
.execute();
|
||||||
assertThat(returned.getEntry().size(), greaterThan(1));
|
assertThat(returned.getEntry().size(), greaterThan(1));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1648,7 +1662,13 @@ public class ResourceProviderDstu2Test extends BaseResourceProviderDstu2Test {
|
||||||
assertEquals(1, actual.getContained().getContainedResources().size());
|
assertEquals(1, actual.getContained().getContainedResources().size());
|
||||||
assertThat(actual.getText().getDiv().getValueAsString(), containsString("<td>Identifier</td><td>testSaveAndRetrieveWithContained01</td>"));
|
assertThat(actual.getText().getDiv().getValueAsString(), containsString("<td>Identifier</td><td>testSaveAndRetrieveWithContained01</td>"));
|
||||||
|
|
||||||
Bundle b = ourClient.search().forResource("Patient").where(Patient.IDENTIFIER.exactly().systemAndCode("urn:system:rpdstu2", "testSaveAndRetrieveWithContained01")).prettyPrint().execute();
|
Bundle b = ourClient
|
||||||
|
.search()
|
||||||
|
.forResource("Patient")
|
||||||
|
.where(Patient.IDENTIFIER.exactly().systemAndCode("urn:system:rpdstu2", "testSaveAndRetrieveWithContained01"))
|
||||||
|
.prettyPrint()
|
||||||
|
.returnBundle(Bundle.class)
|
||||||
|
.execute();
|
||||||
assertEquals(1, b.getEntry().size());
|
assertEquals(1, b.getEntry().size());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1714,7 +1734,13 @@ public class ResourceProviderDstu2Test extends BaseResourceProviderDstu2Test {
|
||||||
p1.addIdentifier().setValue("testSearchByIdentifierWithoutSystem01");
|
p1.addIdentifier().setValue("testSearchByIdentifierWithoutSystem01");
|
||||||
IdDt p1Id = (IdDt) ourClient.create().resource(p1).execute().getId();
|
IdDt p1Id = (IdDt) ourClient.create().resource(p1).execute().getId();
|
||||||
|
|
||||||
Bundle actual = ourClient.search().forResource(Patient.class).where(Patient.IDENTIFIER.exactly().systemAndCode(null, "testSearchByIdentifierWithoutSystem01")).encodedJson().prettyPrint()
|
Bundle actual = ourClient
|
||||||
|
.search()
|
||||||
|
.forResource(Patient.class)
|
||||||
|
.where(Patient.IDENTIFIER.exactly().systemAndCode(null, "testSearchByIdentifierWithoutSystem01"))
|
||||||
|
.encodedJson()
|
||||||
|
.prettyPrint()
|
||||||
|
.returnBundle(Bundle.class)
|
||||||
.execute();
|
.execute();
|
||||||
assertEquals(1, actual.getEntry().size());
|
assertEquals(1, actual.getEntry().size());
|
||||||
assertEquals(p1Id.getIdPart(), actual.getEntry().get(0).getResource().getId().getIdPart());
|
assertEquals(p1Id.getIdPart(), actual.getEntry().get(0).getResource().getId().getIdPart());
|
||||||
|
@ -1736,14 +1762,13 @@ public class ResourceProviderDstu2Test extends BaseResourceProviderDstu2Test {
|
||||||
id2 = myPatientDao.create(patient, mySrd).getId().toUnqualifiedVersionless();
|
id2 = myPatientDao.create(patient, mySrd).getId().toUnqualifiedVersionless();
|
||||||
}
|
}
|
||||||
|
|
||||||
//@formatter:off
|
|
||||||
Bundle found = ourClient
|
Bundle found = ourClient
|
||||||
.search()
|
.search()
|
||||||
.forResource(Patient.class)
|
.forResource(Patient.class)
|
||||||
.where(BaseResource.RES_ID.matches().values(id1.getIdPart(), id2.getIdPart()))
|
.where(BaseResource.RES_ID.matches().values(id1.getIdPart(), id2.getIdPart()))
|
||||||
.and(BaseResource.RES_ID.matches().value(id1.getIdPart()))
|
.and(BaseResource.RES_ID.matches().value(id1.getIdPart()))
|
||||||
|
.returnBundle(Bundle.class)
|
||||||
.execute();
|
.execute();
|
||||||
//@formatter:on
|
|
||||||
|
|
||||||
assertThat(toIdListUnqualifiedVersionless(found), containsInAnyOrder(id1));
|
assertThat(toIdListUnqualifiedVersionless(found), containsInAnyOrder(id1));
|
||||||
}
|
}
|
||||||
|
@ -1761,21 +1786,24 @@ public class ResourceProviderDstu2Test extends BaseResourceProviderDstu2Test {
|
||||||
p1.setManagingOrganization(new ResourceReferenceDt(o1id.toUnqualifiedVersionless()));
|
p1.setManagingOrganization(new ResourceReferenceDt(o1id.toUnqualifiedVersionless()));
|
||||||
IdDt p1Id = (IdDt) ourClient.create().resource(p1).execute().getId();
|
IdDt p1Id = (IdDt) ourClient.create().resource(p1).execute().getId();
|
||||||
|
|
||||||
//@formatter:off
|
|
||||||
Bundle actual = ourClient.search()
|
Bundle actual = ourClient.search()
|
||||||
.forResource(Patient.class)
|
.forResource(Patient.class)
|
||||||
.where(Patient.ORGANIZATION.hasId(o1id.getIdPart()))
|
.where(Patient.ORGANIZATION.hasId(o1id.getIdPart()))
|
||||||
.encodedJson().prettyPrint().execute();
|
.encodedJson()
|
||||||
//@formatter:on
|
.prettyPrint()
|
||||||
|
.returnBundle(Bundle.class)
|
||||||
|
.execute();
|
||||||
assertEquals(1, actual.getEntry().size());
|
assertEquals(1, actual.getEntry().size());
|
||||||
assertEquals(p1Id.getIdPart(), actual.getEntry().get(0).getResource().getId().getIdPart());
|
assertEquals(p1Id.getIdPart(), actual.getEntry().get(0).getResource().getId().getIdPart());
|
||||||
|
|
||||||
//@formatter:off
|
actual = ourClient
|
||||||
actual = ourClient.search()
|
.search()
|
||||||
.forResource(Patient.class)
|
.forResource(Patient.class)
|
||||||
.where(Patient.ORGANIZATION.hasId(o1id.getValue()))
|
.where(Patient.ORGANIZATION.hasId(o1id.getValue()))
|
||||||
.encodedJson().prettyPrint().execute();
|
.encodedJson()
|
||||||
//@formatter:on
|
.prettyPrint()
|
||||||
|
.returnBundle(Bundle.class)
|
||||||
|
.execute();
|
||||||
assertEquals(1, actual.getEntry().size());
|
assertEquals(1, actual.getEntry().size());
|
||||||
assertEquals(p1Id.getIdPart(), actual.getEntry().get(0).getResource().getId().getIdPart());
|
assertEquals(p1Id.getIdPart(), actual.getEntry().get(0).getResource().getId().getIdPart());
|
||||||
|
|
||||||
|
@ -1802,17 +1830,19 @@ public class ResourceProviderDstu2Test extends BaseResourceProviderDstu2Test {
|
||||||
p2.setManagingOrganization(new ResourceReferenceDt(o2id.toUnqualifiedVersionless()));
|
p2.setManagingOrganization(new ResourceReferenceDt(o2id.toUnqualifiedVersionless()));
|
||||||
IdDt p2Id = (IdDt) ourClient.create().resource(p2).execute().getId();
|
IdDt p2Id = (IdDt) ourClient.create().resource(p2).execute().getId();
|
||||||
|
|
||||||
//@formatter:off
|
|
||||||
Bundle actual = ourClient.search()
|
Bundle actual = ourClient.search()
|
||||||
.forResource(Patient.class)
|
.forResource(Patient.class)
|
||||||
.where(Patient.ORGANIZATION.hasAnyOfIds(Arrays.asList(o1id.getIdPart(), o2id.getIdPart())))
|
.where(Patient.ORGANIZATION.hasAnyOfIds(Arrays.asList(o1id.getIdPart(), o2id.getIdPart())))
|
||||||
.encodedJson().prettyPrint().execute();
|
.encodedJson()
|
||||||
//@formatter:on
|
.prettyPrint()
|
||||||
|
.returnBundle(Bundle.class)
|
||||||
|
.execute();
|
||||||
|
|
||||||
Set<String> expectedIds = new HashSet<String>();
|
Set<String> expectedIds = new HashSet<String>();
|
||||||
expectedIds.add(p1Id.getIdPart());
|
expectedIds.add(p1Id.getIdPart());
|
||||||
expectedIds.add(p2Id.getIdPart());
|
expectedIds.add(p2Id.getIdPart());
|
||||||
Set<String> actualIds = new HashSet<String>();
|
Set<String> actualIds = new HashSet<String>();
|
||||||
for (BundleEntry ele : actual.getEntry()) {
|
for (Entry ele : actual.getEntry()) {
|
||||||
actualIds.add(ele.getResource().getId().getIdPart());
|
actualIds.add(ele.getResource().getId().getIdPart());
|
||||||
}
|
}
|
||||||
assertEquals("Expects to retrieve the 2 patients which reference the two different organizations", expectedIds, actualIds);
|
assertEquals("Expects to retrieve the 2 patients which reference the two different organizations", expectedIds, actualIds);
|
||||||
|
@ -1828,40 +1858,49 @@ public class ResourceProviderDstu2Test extends BaseResourceProviderDstu2Test {
|
||||||
o2.setName("testSearchByResourceChainName02");
|
o2.setName("testSearchByResourceChainName02");
|
||||||
o2.getMeta().addProfile("http://profile1").addProfile("http://profile3");
|
o2.getMeta().addProfile("http://profile1").addProfile("http://profile3");
|
||||||
IdDt o2id = (IdDt) ourClient.create().resource(o2).execute().getId().toUnqualifiedVersionless();
|
IdDt o2id = (IdDt) ourClient.create().resource(o2).execute().getId().toUnqualifiedVersionless();
|
||||||
//@formatter:off
|
|
||||||
Bundle actual = ourClient.search()
|
Bundle actual = ourClient.search()
|
||||||
.forResource(Organization.class)
|
.forResource(Organization.class)
|
||||||
.withProfile("http://profile1")
|
.withProfile("http://profile1")
|
||||||
.withProfile("http://profileX")
|
.withProfile("http://profileX")
|
||||||
.encodedJson().prettyPrint().execute();
|
.encodedJson()
|
||||||
//@formatter:on
|
.prettyPrint()
|
||||||
|
.returnBundle(Bundle.class)
|
||||||
|
.execute();
|
||||||
|
|
||||||
assertEquals("nothing matches profile x", Collections.emptyList(), actual.getEntry());
|
assertEquals("nothing matches profile x", Collections.emptyList(), actual.getEntry());
|
||||||
//@formatter:off
|
|
||||||
actual = ourClient.search()
|
actual = ourClient.search()
|
||||||
.forResource(Organization.class)
|
.forResource(Organization.class)
|
||||||
.withProfile("http://profile1")
|
.withProfile("http://profile1")
|
||||||
.withProfile("http://profile2")
|
.withProfile("http://profile2")
|
||||||
.encodedJson().prettyPrint().execute();
|
.returnBundle(Bundle.class)
|
||||||
//@formatter:on
|
.encodedJson()
|
||||||
|
.prettyPrint()
|
||||||
|
.execute();
|
||||||
|
|
||||||
Set<String> expectedIds = new HashSet<String>();
|
Set<String> expectedIds = new HashSet<String>();
|
||||||
expectedIds.add(o1id.getIdPart());
|
expectedIds.add(o1id.getIdPart());
|
||||||
Set<String> actualIds = new HashSet<String>();
|
Set<String> actualIds = new HashSet<String>();
|
||||||
for (BundleEntry ele : actual.getEntry()) {
|
for (Entry ele : actual.getEntry()) {
|
||||||
actualIds.add(ele.getResource().getId().getIdPart());
|
actualIds.add(ele.getResource().getId().getIdPart());
|
||||||
}
|
}
|
||||||
assertEquals("Expects to retrieve the 1 orgination matching on Org1's profiles", expectedIds, actualIds);
|
assertEquals("Expects to retrieve the 1 orgination matching on Org1's profiles", expectedIds, actualIds);
|
||||||
//@formatter:off
|
|
||||||
actual = ourClient.search()
|
actual = ourClient.search()
|
||||||
.forResource(Organization.class)
|
.forResource(Organization.class)
|
||||||
.withProfile("http://profile1")
|
.withProfile("http://profile1")
|
||||||
.withAnyProfile(Arrays.asList("http://profile3", "http://profile2"))
|
.withAnyProfile(Arrays.asList("http://profile3", "http://profile2"))
|
||||||
.encodedJson().prettyPrint().execute();
|
.encodedJson()
|
||||||
//@formatter:on
|
.prettyPrint()
|
||||||
|
.returnBundle(Bundle.class)
|
||||||
|
.execute();
|
||||||
|
|
||||||
expectedIds = new HashSet<String>();
|
expectedIds = new HashSet<String>();
|
||||||
expectedIds.add(o1id.getIdPart());
|
expectedIds.add(o1id.getIdPart());
|
||||||
expectedIds.add(o2id.getIdPart());
|
expectedIds.add(o2id.getIdPart());
|
||||||
actualIds = new HashSet<String>();
|
actualIds = new HashSet<String>();
|
||||||
for (BundleEntry ele : actual.getEntry()) {
|
for (Entry ele : actual.getEntry()) {
|
||||||
actualIds.add(ele.getResource().getId().getIdPart());
|
actualIds.add(ele.getResource().getId().getIdPart());
|
||||||
}
|
}
|
||||||
assertEquals("Expects to retrieve the 2 orginations, since we match on (the common profile AND (Org1's second profile OR org2's second profile))", expectedIds, actualIds);
|
assertEquals("Expects to retrieve the 2 orginations, since we match on (the common profile AND (Org1's second profile OR org2's second profile))", expectedIds, actualIds);
|
||||||
|
@ -1905,60 +1944,58 @@ public class ResourceProviderDstu2Test extends BaseResourceProviderDstu2Test {
|
||||||
|
|
||||||
ourLog.info("Before: {}", beforeAny.getValue());
|
ourLog.info("Before: {}", beforeAny.getValue());
|
||||||
{
|
{
|
||||||
//@formatter:off
|
Bundle found = ourClient
|
||||||
Bundle found = ourClient.search()
|
.search()
|
||||||
.forResource(Patient.class)
|
.forResource(Patient.class)
|
||||||
.where(Patient.NAME.matches().value("testSearchLastUpdatedParamRp"))
|
.where(Patient.NAME.matches().value("testSearchLastUpdatedParamRp"))
|
||||||
.lastUpdated(new DateRangeParam(beforeAny, null))
|
.lastUpdated(new DateRangeParam(beforeAny, null))
|
||||||
|
.returnBundle(Bundle.class)
|
||||||
.execute();
|
.execute();
|
||||||
//@formatter:on
|
|
||||||
List<IdDt> patients = toIdListUnqualifiedVersionless(found);
|
List<IdDt> patients = toIdListUnqualifiedVersionless(found);
|
||||||
assertThat(patients, hasItems(id1a, id1b, id2));
|
assertThat(patients, hasItems(id1a, id1b, id2));
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
//@formatter:off
|
|
||||||
Bundle found = ourClient.search()
|
Bundle found = ourClient.search()
|
||||||
.forResource(Patient.class)
|
.forResource(Patient.class)
|
||||||
.where(Patient.NAME.matches().value("testSearchLastUpdatedParamRp"))
|
.where(Patient.NAME.matches().value("testSearchLastUpdatedParamRp"))
|
||||||
|
.returnBundle(Bundle.class)
|
||||||
.execute();
|
.execute();
|
||||||
//@formatter:on
|
|
||||||
List<IdDt> patients = toIdListUnqualifiedVersionless(found);
|
List<IdDt> patients = toIdListUnqualifiedVersionless(found);
|
||||||
assertThat(patients, hasItems(id1a, id1b, id2));
|
assertThat(patients, hasItems(id1a, id1b, id2));
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
//@formatter:off
|
|
||||||
Bundle found = ourClient.search()
|
Bundle found = ourClient.search()
|
||||||
.forResource(Patient.class)
|
.forResource(Patient.class)
|
||||||
.where(Patient.NAME.matches().value("testSearchLastUpdatedParamRp"))
|
.where(Patient.NAME.matches().value("testSearchLastUpdatedParamRp"))
|
||||||
.lastUpdated(new DateRangeParam(beforeR2, null))
|
.lastUpdated(new DateRangeParam(beforeR2, null))
|
||||||
|
.returnBundle(Bundle.class)
|
||||||
.execute();
|
.execute();
|
||||||
//@formatter:on
|
|
||||||
List<IdDt> patients = toIdListUnqualifiedVersionless(found);
|
List<IdDt> patients = toIdListUnqualifiedVersionless(found);
|
||||||
assertThat(patients, hasItems(id2));
|
assertThat(patients, hasItems(id2));
|
||||||
assertThat(patients, not(hasItems(id1a, id1b)));
|
assertThat(patients, not(hasItems(id1a, id1b)));
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
//@formatter:off
|
|
||||||
Bundle found = ourClient.search()
|
Bundle found = ourClient.search()
|
||||||
.forResource(Patient.class)
|
.forResource(Patient.class)
|
||||||
.where(Patient.NAME.matches().value("testSearchLastUpdatedParamRp"))
|
.where(Patient.NAME.matches().value("testSearchLastUpdatedParamRp"))
|
||||||
.lastUpdated(new DateRangeParam(beforeAny, beforeR2))
|
.lastUpdated(new DateRangeParam(beforeAny, beforeR2))
|
||||||
|
.returnBundle(Bundle.class)
|
||||||
.execute();
|
.execute();
|
||||||
//@formatter:on
|
|
||||||
List<IdDt> patients = toIdListUnqualifiedVersionless(found);
|
List<IdDt> patients = toIdListUnqualifiedVersionless(found);
|
||||||
assertThat(patients.toString(), patients, not(hasItems(id2)));
|
assertThat(patients.toString(), patients, not(hasItems(id2)));
|
||||||
assertThat(patients.toString(), patients, (hasItems(id1a, id1b)));
|
assertThat(patients.toString(), patients, (hasItems(id1a, id1b)));
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
//@formatter:off
|
|
||||||
Bundle found = ourClient.search()
|
Bundle found = ourClient.search()
|
||||||
.forResource(Patient.class)
|
.forResource(Patient.class)
|
||||||
.where(Patient.NAME.matches().value("testSearchLastUpdatedParamRp"))
|
.where(Patient.NAME.matches().value("testSearchLastUpdatedParamRp"))
|
||||||
.lastUpdated(new DateRangeParam(null, beforeR2))
|
.lastUpdated(new DateRangeParam(null, beforeR2))
|
||||||
|
.returnBundle(Bundle.class)
|
||||||
.execute();
|
.execute();
|
||||||
//@formatter:on
|
|
||||||
List<IdDt> patients = toIdListUnqualifiedVersionless(found);
|
List<IdDt> patients = toIdListUnqualifiedVersionless(found);
|
||||||
assertThat(patients, (hasItems(id1a, id1b)));
|
assertThat(patients, (hasItems(id1a, id1b)));
|
||||||
assertThat(patients, not(hasItems(id2)));
|
assertThat(patients, not(hasItems(id2)));
|
||||||
|
@ -1985,14 +2022,12 @@ public class ResourceProviderDstu2Test extends BaseResourceProviderDstu2Test {
|
||||||
Date before = new Date();
|
Date before = new Date();
|
||||||
Thread.sleep(100);
|
Thread.sleep(100);
|
||||||
|
|
||||||
//@formatter:off
|
|
||||||
ca.uhn.fhir.model.dstu2.resource.Bundle found = ourClient
|
ca.uhn.fhir.model.dstu2.resource.Bundle found = ourClient
|
||||||
.search()
|
.search()
|
||||||
.forResource(Patient.class)
|
.forResource(Patient.class)
|
||||||
.prettyPrint()
|
.prettyPrint()
|
||||||
.returnBundle(ca.uhn.fhir.model.dstu2.resource.Bundle.class)
|
.returnBundle(ca.uhn.fhir.model.dstu2.resource.Bundle.class)
|
||||||
.execute();
|
.execute();
|
||||||
//@formatter:on
|
|
||||||
|
|
||||||
Thread.sleep(100);
|
Thread.sleep(100);
|
||||||
Date after = new Date();
|
Date after = new Date();
|
||||||
|
@ -2018,23 +2053,22 @@ public class ResourceProviderDstu2Test extends BaseResourceProviderDstu2Test {
|
||||||
pat.getManagingOrganization().setReference(orgId.toUnqualifiedVersionless());
|
pat.getManagingOrganization().setReference(orgId.toUnqualifiedVersionless());
|
||||||
ourClient.create().resource(pat).prettyPrint().encodedXml().execute().getId();
|
ourClient.create().resource(pat).prettyPrint().encodedXml().execute().getId();
|
||||||
|
|
||||||
//@formatter:off
|
|
||||||
Bundle found = ourClient
|
Bundle found = ourClient
|
||||||
.search()
|
.search()
|
||||||
.forResource(Patient.class)
|
.forResource(Patient.class)
|
||||||
.where(Patient.IDENTIFIER.exactly().systemAndIdentifier("urn:system:rpdstu2","testSearchWithInclude02"))
|
.where(Patient.IDENTIFIER.exactly().systemAndIdentifier("urn:system:rpdstu2","testSearchWithInclude02"))
|
||||||
.include(Patient.INCLUDE_ORGANIZATION)
|
.include(Patient.INCLUDE_ORGANIZATION)
|
||||||
.prettyPrint()
|
.prettyPrint()
|
||||||
|
.returnBundle(Bundle.class)
|
||||||
.execute();
|
.execute();
|
||||||
//@formatter:on
|
|
||||||
|
|
||||||
assertEquals(2, found.getEntry().size());
|
assertEquals(2, found.getEntry().size());
|
||||||
assertEquals(Patient.class, found.getEntry().get(0).getResource().getClass());
|
assertEquals(Patient.class, found.getEntry().get(0).getResource().getClass());
|
||||||
assertEquals(BundleEntrySearchModeEnum.MATCH, found.getEntry().get(0).getSearchMode().getValueAsEnum());
|
assertEquals(BundleEntrySearchModeEnum.MATCH, found.getEntry().get(0).getSearch().getModeElement().getValueAsEnum());
|
||||||
assertEquals(BundleEntrySearchModeEnum.MATCH, found.getEntry().get(0).getResource().getResourceMetadata().get(ResourceMetadataKeyEnum.ENTRY_SEARCH_MODE));
|
assertEquals(BundleEntrySearchModeEnum.MATCH, found.getEntry().get(0).getResource().getResourceMetadata().get(ResourceMetadataKeyEnum.ENTRY_SEARCH_MODE));
|
||||||
assertThat(found.getEntry().get(0).getResource().getText().getDiv().getValueAsString(), containsString("<table class=\"hapiPropertyTable"));
|
assertThat(found.getEntry().get(0).getResource().getText().getDiv().getValueAsString(), containsString("<table class=\"hapiPropertyTable"));
|
||||||
assertEquals(Organization.class, found.getEntry().get(1).getResource().getClass());
|
assertEquals(Organization.class, found.getEntry().get(1).getResource().getClass());
|
||||||
assertEquals(BundleEntrySearchModeEnum.INCLUDE, found.getEntry().get(1).getSearchMode().getValueAsEnum());
|
assertEquals(BundleEntrySearchModeEnum.INCLUDE, found.getEntry().get(1).getSearch().getModeElement().getValueAsEnum());
|
||||||
assertEquals(BundleEntrySearchModeEnum.INCLUDE, found.getEntry().get(1).getResource().getResourceMetadata().get(ResourceMetadataKeyEnum.ENTRY_SEARCH_MODE));
|
assertEquals(BundleEntrySearchModeEnum.INCLUDE, found.getEntry().get(1).getResource().getResourceMetadata().get(ResourceMetadataKeyEnum.ENTRY_SEARCH_MODE));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2043,14 +2077,12 @@ public class ResourceProviderDstu2Test extends BaseResourceProviderDstu2Test {
|
||||||
Observation o = new Observation();
|
Observation o = new Observation();
|
||||||
o.getCode().setText("testSearchWithInvalidSort");
|
o.getCode().setText("testSearchWithInvalidSort");
|
||||||
myObservationDao.create(o, mySrd);
|
myObservationDao.create(o, mySrd);
|
||||||
//@formatter:off
|
|
||||||
ourClient
|
ourClient
|
||||||
.search()
|
.search()
|
||||||
.forResource(Observation.class)
|
.forResource(Observation.class)
|
||||||
.sort().ascending(Observation.CODE_VALUE_QUANTITY) // composite sort not supported yet
|
.sort().ascending(Observation.CODE_VALUE_QUANTITY) // composite sort not supported yet
|
||||||
.prettyPrint()
|
.prettyPrint()
|
||||||
.execute();
|
.execute();
|
||||||
//@formatter:on
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -2086,15 +2118,14 @@ public class ResourceProviderDstu2Test extends BaseResourceProviderDstu2Test {
|
||||||
IdDt orgMissing = (IdDt) ourClient.create().resource(org).prettyPrint().encodedXml().execute().getId().toUnqualifiedVersionless();
|
IdDt orgMissing = (IdDt) ourClient.create().resource(org).prettyPrint().encodedXml().execute().getId().toUnqualifiedVersionless();
|
||||||
|
|
||||||
{
|
{
|
||||||
//@formatter:off
|
|
||||||
Bundle found = ourClient
|
Bundle found = ourClient
|
||||||
.search()
|
.search()
|
||||||
.forResource(Organization.class)
|
.forResource(Organization.class)
|
||||||
.where(Organization.NAME.isMissing(false))
|
.where(Organization.NAME.isMissing(false))
|
||||||
.count(100)
|
.count(100)
|
||||||
.prettyPrint()
|
.prettyPrint()
|
||||||
|
.returnBundle(Bundle.class)
|
||||||
.execute();
|
.execute();
|
||||||
//@formatter:on
|
|
||||||
|
|
||||||
List<IdDt> list = toIdListUnqualifiedVersionless(found);
|
List<IdDt> list = toIdListUnqualifiedVersionless(found);
|
||||||
ourLog.info(methodName + ": " + list.toString());
|
ourLog.info(methodName + ": " + list.toString());
|
||||||
|
@ -2104,15 +2135,14 @@ public class ResourceProviderDstu2Test extends BaseResourceProviderDstu2Test {
|
||||||
assertThat(list, not(containsInRelativeOrder(orgMissing)));
|
assertThat(list, not(containsInRelativeOrder(orgMissing)));
|
||||||
}
|
}
|
||||||
|
|
||||||
//@formatter:off
|
|
||||||
Bundle found = ourClient
|
Bundle found = ourClient
|
||||||
.search()
|
.search()
|
||||||
.forResource(Organization.class)
|
.forResource(Organization.class)
|
||||||
.where(Organization.NAME.isMissing(true))
|
.where(Organization.NAME.isMissing(true))
|
||||||
.count(100)
|
.count(100)
|
||||||
.prettyPrint()
|
.prettyPrint()
|
||||||
|
.returnBundle(Bundle.class)
|
||||||
.execute();
|
.execute();
|
||||||
//@formatter:on
|
|
||||||
|
|
||||||
List<IdDt> list = toIdListUnqualifiedVersionless(found);
|
List<IdDt> list = toIdListUnqualifiedVersionless(found);
|
||||||
ourLog.info(methodName + " found: " + list.toString() + " - Wanted " + orgMissing + " but not " + orgNotMissing);
|
ourLog.info(methodName + " found: " + list.toString() + " - Wanted " + orgMissing + " but not " + orgNotMissing);
|
||||||
|
@ -2236,7 +2266,6 @@ public class ResourceProviderDstu2Test extends BaseResourceProviderDstu2Test {
|
||||||
p.addName().addGiven("Sarah").addFamily("Graham");
|
p.addName().addGiven("Sarah").addFamily("Graham");
|
||||||
ourClient.create().resource(p).execute();
|
ourClient.create().resource(p).execute();
|
||||||
|
|
||||||
//@formatter:off
|
|
||||||
Bundle resp = ourClient
|
Bundle resp = ourClient
|
||||||
.search()
|
.search()
|
||||||
.forResource(Patient.class)
|
.forResource(Patient.class)
|
||||||
|
@ -2244,14 +2273,13 @@ public class ResourceProviderDstu2Test extends BaseResourceProviderDstu2Test {
|
||||||
.sort().ascending(Patient.FAMILY)
|
.sort().ascending(Patient.FAMILY)
|
||||||
.sort().ascending(Patient.GIVEN)
|
.sort().ascending(Patient.GIVEN)
|
||||||
.count(100)
|
.count(100)
|
||||||
|
.returnBundle(Bundle.class)
|
||||||
.execute();
|
.execute();
|
||||||
//@formatter:on
|
|
||||||
|
|
||||||
List<String> names = toNameList(resp);
|
List<String> names = toNameList(resp);
|
||||||
|
|
||||||
ourLog.info(StringUtils.join(names, '\n'));
|
ourLog.info(StringUtils.join(names, '\n'));
|
||||||
|
|
||||||
//@formatter:off
|
|
||||||
assertThat(names, contains( // this matches in order only
|
assertThat(names, contains( // this matches in order only
|
||||||
"Daniel Adams",
|
"Daniel Adams",
|
||||||
"Aaron Alexis",
|
"Aaron Alexis",
|
||||||
|
@ -2269,7 +2297,6 @@ public class ResourceProviderDstu2Test extends BaseResourceProviderDstu2Test {
|
||||||
"Brian Gracia",
|
"Brian Gracia",
|
||||||
"Sarah Graham",
|
"Sarah Graham",
|
||||||
"Stephan Graham"));
|
"Stephan Graham"));
|
||||||
//@formatter:om
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2474,7 +2501,15 @@ public class ResourceProviderDstu2Test extends BaseResourceProviderDstu2Test {
|
||||||
|
|
||||||
assertThat(p1Id.getValue(), containsString("Patient/testUpdateWithClientSuppliedIdWhichDoesntExistRpDstu2/_history"));
|
assertThat(p1Id.getValue(), containsString("Patient/testUpdateWithClientSuppliedIdWhichDoesntExistRpDstu2/_history"));
|
||||||
|
|
||||||
Bundle actual = ourClient.search().forResource(Patient.class).where(Patient.IDENTIFIER.exactly().systemAndCode("urn:system", "testUpdateWithClientSuppliedIdWhichDoesntExistRpDstu2")).encodedJson().prettyPrint().execute();
|
Bundle actual = ourClient
|
||||||
|
.search()
|
||||||
|
.forResource(Patient.class)
|
||||||
|
.where(Patient.IDENTIFIER.exactly().systemAndCode("urn:system", "testUpdateWithClientSuppliedIdWhichDoesntExistRpDstu2"))
|
||||||
|
.encodedJson()
|
||||||
|
.prettyPrint()
|
||||||
|
.returnBundle(Bundle.class)
|
||||||
|
.execute();
|
||||||
|
|
||||||
assertEquals(1, actual.getEntry().size());
|
assertEquals(1, actual.getEntry().size());
|
||||||
assertEquals(p1Id.getIdPart(), actual.getEntry().get(0).getResource().getId().getIdPart());
|
assertEquals(p1Id.getIdPart(), actual.getEntry().get(0).getResource().getId().getIdPart());
|
||||||
|
|
||||||
|
|
|
@ -1,12 +1,13 @@
|
||||||
package ca.uhn.fhir.rest.server;
|
package ca.uhn.fhir.rest.server;
|
||||||
|
|
||||||
import static org.mockito.Matchers.*;
|
import static org.mockito.Matchers.any;
|
||||||
import static org.mockito.Mockito.*;
|
import static org.mockito.Mockito.inOrder;
|
||||||
|
import static org.mockito.Mockito.mock;
|
||||||
|
import static org.mockito.Mockito.times;
|
||||||
|
import static org.mockito.Mockito.verifyNoMoreInteractions;
|
||||||
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.*;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
@ -21,10 +22,7 @@ import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
|
||||||
import org.eclipse.jetty.server.Server;
|
import org.eclipse.jetty.server.Server;
|
||||||
import org.eclipse.jetty.servlet.ServletHandler;
|
import org.eclipse.jetty.servlet.ServletHandler;
|
||||||
import org.eclipse.jetty.servlet.ServletHolder;
|
import org.eclipse.jetty.servlet.ServletHolder;
|
||||||
import org.junit.AfterClass;
|
import org.junit.*;
|
||||||
import org.junit.Before;
|
|
||||||
import org.junit.BeforeClass;
|
|
||||||
import org.junit.Test;
|
|
||||||
import org.mockito.InOrder;
|
import org.mockito.InOrder;
|
||||||
|
|
||||||
import ca.uhn.fhir.context.FhirContext;
|
import ca.uhn.fhir.context.FhirContext;
|
||||||
|
@ -35,10 +33,7 @@ import ca.uhn.fhir.model.dstu.resource.Patient;
|
||||||
import ca.uhn.fhir.model.dstu.valueset.IdentifierUseEnum;
|
import ca.uhn.fhir.model.dstu.valueset.IdentifierUseEnum;
|
||||||
import ca.uhn.fhir.model.primitive.IdDt;
|
import ca.uhn.fhir.model.primitive.IdDt;
|
||||||
import ca.uhn.fhir.model.primitive.UriDt;
|
import ca.uhn.fhir.model.primitive.UriDt;
|
||||||
import ca.uhn.fhir.rest.annotation.IdParam;
|
import ca.uhn.fhir.rest.annotation.*;
|
||||||
import ca.uhn.fhir.rest.annotation.Read;
|
|
||||||
import ca.uhn.fhir.rest.annotation.RequiredParam;
|
|
||||||
import ca.uhn.fhir.rest.annotation.Search;
|
|
||||||
import ca.uhn.fhir.rest.api.RestOperationTypeEnum;
|
import ca.uhn.fhir.rest.api.RestOperationTypeEnum;
|
||||||
import ca.uhn.fhir.rest.method.RequestDetails;
|
import ca.uhn.fhir.rest.method.RequestDetails;
|
||||||
import ca.uhn.fhir.rest.server.interceptor.IServerInterceptor;
|
import ca.uhn.fhir.rest.server.interceptor.IServerInterceptor;
|
||||||
|
|
|
@ -1,700 +0,0 @@
|
||||||
package ca.uhn.fhir.rest.server;
|
|
||||||
|
|
||||||
import static ca.uhn.fhir.util.UrlUtil.escape;
|
|
||||||
import static org.hamcrest.Matchers.containsInAnyOrder;
|
|
||||||
import static org.hamcrest.Matchers.containsString;
|
|
||||||
import static org.hamcrest.Matchers.empty;
|
|
||||||
import static org.hamcrest.Matchers.startsWith;
|
|
||||||
import static org.junit.Assert.assertEquals;
|
|
||||||
import static org.junit.Assert.assertFalse;
|
|
||||||
import static org.junit.Assert.assertThat;
|
|
||||||
import static org.junit.Assert.assertTrue;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Set;
|
|
||||||
import java.util.concurrent.TimeUnit;
|
|
||||||
|
|
||||||
import org.apache.commons.io.IOUtils;
|
|
||||||
import org.apache.http.HttpEntity;
|
|
||||||
import org.apache.http.HttpResponse;
|
|
||||||
import org.apache.http.NameValuePair;
|
|
||||||
import org.apache.http.client.entity.UrlEncodedFormEntity;
|
|
||||||
import org.apache.http.client.methods.CloseableHttpResponse;
|
|
||||||
import org.apache.http.client.methods.HttpGet;
|
|
||||||
import org.apache.http.client.methods.HttpPost;
|
|
||||||
import org.apache.http.entity.ByteArrayEntity;
|
|
||||||
import org.apache.http.impl.client.CloseableHttpClient;
|
|
||||||
import org.apache.http.impl.client.HttpClientBuilder;
|
|
||||||
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
|
|
||||||
import org.apache.http.message.BasicNameValuePair;
|
|
||||||
import org.eclipse.jetty.server.Server;
|
|
||||||
import org.eclipse.jetty.servlet.ServletHandler;
|
|
||||||
import org.eclipse.jetty.servlet.ServletHolder;
|
|
||||||
import org.junit.AfterClass;
|
|
||||||
import org.junit.Before;
|
|
||||||
import org.junit.BeforeClass;
|
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
import com.google.common.net.UrlEscapers;
|
|
||||||
|
|
||||||
import ca.uhn.fhir.context.FhirContext;
|
|
||||||
import ca.uhn.fhir.model.api.Bundle;
|
|
||||||
import ca.uhn.fhir.model.api.IResource;
|
|
||||||
import ca.uhn.fhir.model.api.Include;
|
|
||||||
import ca.uhn.fhir.model.api.ResourceMetadataKeyEnum;
|
|
||||||
import ca.uhn.fhir.model.base.composite.BaseCodingDt;
|
|
||||||
import ca.uhn.fhir.model.dstu.composite.CodingDt;
|
|
||||||
import ca.uhn.fhir.model.dstu.resource.BaseResource;
|
|
||||||
import ca.uhn.fhir.model.dstu.resource.Observation;
|
|
||||||
import ca.uhn.fhir.model.dstu.resource.Patient;
|
|
||||||
import ca.uhn.fhir.model.primitive.IdDt;
|
|
||||||
import ca.uhn.fhir.narrative.DefaultThymeleafNarrativeGenerator;
|
|
||||||
import ca.uhn.fhir.rest.annotation.Create;
|
|
||||||
import ca.uhn.fhir.rest.annotation.IdParam;
|
|
||||||
import ca.uhn.fhir.rest.annotation.IncludeParam;
|
|
||||||
import ca.uhn.fhir.rest.annotation.OptionalParam;
|
|
||||||
import ca.uhn.fhir.rest.annotation.RequiredParam;
|
|
||||||
import ca.uhn.fhir.rest.annotation.ResourceParam;
|
|
||||||
import ca.uhn.fhir.rest.annotation.Search;
|
|
||||||
import ca.uhn.fhir.rest.api.MethodOutcome;
|
|
||||||
import ca.uhn.fhir.rest.client.IGenericClient;
|
|
||||||
import ca.uhn.fhir.rest.param.ReferenceParam;
|
|
||||||
import ca.uhn.fhir.rest.param.StringAndListParam;
|
|
||||||
import ca.uhn.fhir.rest.param.StringOrListParam;
|
|
||||||
import ca.uhn.fhir.rest.param.StringParam;
|
|
||||||
import ca.uhn.fhir.rest.param.TokenOrListParam;
|
|
||||||
import ca.uhn.fhir.rest.param.TokenParam;
|
|
||||||
import ca.uhn.fhir.util.PortUtil;
|
|
||||||
import ca.uhn.fhir.util.TestUtil;
|
|
||||||
|
|
||||||
public class SearchSearchServerDstu1Test {
|
|
||||||
|
|
||||||
private static CloseableHttpClient ourClient;
|
|
||||||
private static FhirContext ourCtx = FhirContext.forDstu1();
|
|
||||||
private static IServerAddressStrategy ourDefaultAddressStrategy;
|
|
||||||
private static StringAndListParam ourLastAndList;
|
|
||||||
|
|
||||||
private static Set<Include> ourLastIncludes;
|
|
||||||
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(SearchSearchServerDstu1Test.class);
|
|
||||||
private static int ourPort;
|
|
||||||
private static Server ourServer;
|
|
||||||
private static RestfulServer ourServlet;
|
|
||||||
|
|
||||||
@Before
|
|
||||||
public void before() {
|
|
||||||
ourServlet.setServerAddressStrategy(ourDefaultAddressStrategy);
|
|
||||||
ourLastIncludes = null;
|
|
||||||
ourLastAndList = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testEncodeConvertsReferencesToRelative() throws Exception {
|
|
||||||
HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient?_query=searchWithRef");
|
|
||||||
HttpResponse status = ourClient.execute(httpGet);
|
|
||||||
String responseContent = IOUtils.toString(status.getEntity().getContent());
|
|
||||||
IOUtils.closeQuietly(status.getEntity().getContent());
|
|
||||||
ourLog.info(responseContent);
|
|
||||||
|
|
||||||
assertEquals(200, status.getStatusLine().getStatusCode());
|
|
||||||
Patient patient = (Patient) ourCtx.newXmlParser().parseBundle(responseContent).getEntries().get(0).getResource();
|
|
||||||
String ref = patient.getManagingOrganization().getReference().getValue();
|
|
||||||
assertEquals("Organization/555", ref);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Try loading the page as a POST just to make sure we get the right error
|
|
||||||
*/
|
|
||||||
@Test
|
|
||||||
public void testGetPagesWithPost() throws Exception {
|
|
||||||
|
|
||||||
HttpPost httpPost = new HttpPost("http://localhost:" + ourPort);
|
|
||||||
List<? extends NameValuePair> parameters = Collections.singletonList(new BasicNameValuePair("_getpages", "AAA"));
|
|
||||||
httpPost.setEntity(new UrlEncodedFormEntity(parameters));
|
|
||||||
|
|
||||||
CloseableHttpResponse status = ourClient.execute(httpPost);
|
|
||||||
String responseContent = IOUtils.toString(status.getEntity().getContent());
|
|
||||||
IOUtils.closeQuietly(status.getEntity().getContent());
|
|
||||||
ourLog.info(responseContent);
|
|
||||||
assertEquals(400, status.getStatusLine().getStatusCode());
|
|
||||||
// assertThat(responseContent, containsString("Requests for _getpages must use HTTP GET"));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testOmitEmptyOptionalParam() throws Exception {
|
|
||||||
HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient?_id=");
|
|
||||||
HttpResponse status = ourClient.execute(httpGet);
|
|
||||||
String responseContent = IOUtils.toString(status.getEntity().getContent());
|
|
||||||
IOUtils.closeQuietly(status.getEntity().getContent());
|
|
||||||
assertEquals(200, status.getStatusLine().getStatusCode());
|
|
||||||
Bundle bundle = ourCtx.newXmlParser().parseBundle(responseContent);
|
|
||||||
assertEquals(1, bundle.getEntries().size());
|
|
||||||
|
|
||||||
Patient p = bundle.getResources(Patient.class).get(0);
|
|
||||||
assertEquals(null, p.getNameFirstRep().getFamilyFirstRep().getValue());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testParseEscapedValues() throws Exception {
|
|
||||||
|
|
||||||
StringBuilder b = new StringBuilder();
|
|
||||||
b.append("http://localhost:");
|
|
||||||
b.append(ourPort);
|
|
||||||
b.append("/Patient?");
|
|
||||||
b.append(escape("findPatientWithAndList")).append('=').append(escape("NE\\,NE,NE\\,NE")).append('&');
|
|
||||||
b.append(escape("findPatientWithAndList")).append('=').append(escape("NE\\\\NE")).append('&');
|
|
||||||
b.append(escape("findPatientWithAndList:exact")).append('=').append(escape("E\\$E")).append('&');
|
|
||||||
b.append(escape("findPatientWithAndList:exact")).append('=').append(escape("E\\|E")).append('&');
|
|
||||||
|
|
||||||
HttpGet httpGet = new HttpGet(b.toString());
|
|
||||||
|
|
||||||
HttpResponse status = ourClient.execute(httpGet);
|
|
||||||
String responseContent = IOUtils.toString(status.getEntity().getContent());
|
|
||||||
IOUtils.closeQuietly(status.getEntity().getContent());
|
|
||||||
ourLog.info(responseContent);
|
|
||||||
|
|
||||||
assertEquals(200, status.getStatusLine().getStatusCode());
|
|
||||||
|
|
||||||
assertEquals(4, ourLastAndList.getValuesAsQueryTokens().size());
|
|
||||||
assertEquals(2, ourLastAndList.getValuesAsQueryTokens().get(0).getValuesAsQueryTokens().size());
|
|
||||||
assertFalse(ourLastAndList.getValuesAsQueryTokens().get(0).getValuesAsQueryTokens().get(0).isExact());
|
|
||||||
assertEquals("NE,NE", ourLastAndList.getValuesAsQueryTokens().get(0).getValuesAsQueryTokens().get(0).getValue());
|
|
||||||
assertEquals("NE,NE", ourLastAndList.getValuesAsQueryTokens().get(0).getValuesAsQueryTokens().get(1).getValue());
|
|
||||||
assertEquals("NE\\NE", ourLastAndList.getValuesAsQueryTokens().get(1).getValuesAsQueryTokens().get(0).getValue());
|
|
||||||
assertTrue(ourLastAndList.getValuesAsQueryTokens().get(2).getValuesAsQueryTokens().get(0).isExact());
|
|
||||||
assertEquals("E$E", ourLastAndList.getValuesAsQueryTokens().get(2).getValuesAsQueryTokens().get(0).getValue());
|
|
||||||
assertEquals("E|E", ourLastAndList.getValuesAsQueryTokens().get(3).getValuesAsQueryTokens().get(0).getValue());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testReturnLinks() throws Exception {
|
|
||||||
HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient?_query=findWithLinks");
|
|
||||||
|
|
||||||
CloseableHttpResponse status = ourClient.execute(httpGet);
|
|
||||||
String responseContent = IOUtils.toString(status.getEntity().getContent());
|
|
||||||
IOUtils.closeQuietly(status.getEntity().getContent());
|
|
||||||
assertEquals(200, status.getStatusLine().getStatusCode());
|
|
||||||
Bundle bundle = ourCtx.newXmlParser().parseBundle(responseContent);
|
|
||||||
assertEquals(10, bundle.getEntries().size());
|
|
||||||
|
|
||||||
Patient p = bundle.getResources(Patient.class).get(0);
|
|
||||||
assertEquals("AAANamed", p.getIdentifierFirstRep().getValue().getValue());
|
|
||||||
assertEquals("http://foo/Patient?_id=1", bundle.getEntries().get(0).getLinkSearch().getValue());
|
|
||||||
assertEquals("http://localhost:" + ourPort + "/Patient/99881", bundle.getEntries().get(0).getLinkAlternate().getValue());
|
|
||||||
|
|
||||||
assertEquals("http://foo/Patient?_id=1", ResourceMetadataKeyEnum.LINK_SEARCH.get(p));
|
|
||||||
assertEquals("http://localhost:" + ourPort + "/Patient/99881", ResourceMetadataKeyEnum.LINK_ALTERNATE.get(p));
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* #149
|
|
||||||
*/
|
|
||||||
@Test
|
|
||||||
public void testReturnLinksWithAddressStrategy() throws Exception {
|
|
||||||
ourServlet.setServerAddressStrategy(new HardcodedServerAddressStrategy("https://blah.com/base"));
|
|
||||||
|
|
||||||
HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient?_query=findWithLinks");
|
|
||||||
|
|
||||||
CloseableHttpResponse status = ourClient.execute(httpGet);
|
|
||||||
String responseContent = IOUtils.toString(status.getEntity().getContent());
|
|
||||||
IOUtils.closeQuietly(status.getEntity().getContent());
|
|
||||||
assertEquals(200, status.getStatusLine().getStatusCode());
|
|
||||||
Bundle bundle = ourCtx.newXmlParser().parseBundle(responseContent);
|
|
||||||
|
|
||||||
ourLog.info(responseContent);
|
|
||||||
|
|
||||||
assertEquals(10, bundle.getEntries().size());
|
|
||||||
assertEquals("https://blah.com/base", bundle.getLinkBase().getValue());
|
|
||||||
assertEquals("https://blah.com/base/Patient?_query=findWithLinks", bundle.getLinkSelf().getValue());
|
|
||||||
|
|
||||||
Patient p = bundle.getResources(Patient.class).get(0);
|
|
||||||
assertEquals("AAANamed", p.getIdentifierFirstRep().getValue().getValue());
|
|
||||||
assertEquals("http://foo/Patient?_id=1", bundle.getEntries().get(0).getLinkSearch().getValue());
|
|
||||||
assertEquals("https://blah.com/base/Patient/99881", bundle.getEntries().get(0).getLinkAlternate().getValue());
|
|
||||||
assertEquals("http://foo/Patient?_id=1", ResourceMetadataKeyEnum.LINK_SEARCH.get(p));
|
|
||||||
assertEquals("https://blah.com/base/Patient/99881", ResourceMetadataKeyEnum.LINK_ALTERNATE.get(p));
|
|
||||||
|
|
||||||
String linkNext = bundle.getLinkNext().getValue();
|
|
||||||
ourLog.info(linkNext);
|
|
||||||
assertThat(linkNext, startsWith("https://blah.com/base?_getpages="));
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Load the second page
|
|
||||||
*/
|
|
||||||
String urlPart = linkNext.substring(linkNext.indexOf('?'));
|
|
||||||
String link = "http://localhost:" + ourPort + urlPart;
|
|
||||||
httpGet = new HttpGet(link);
|
|
||||||
|
|
||||||
status = ourClient.execute(httpGet);
|
|
||||||
responseContent = IOUtils.toString(status.getEntity().getContent());
|
|
||||||
IOUtils.closeQuietly(status.getEntity().getContent());
|
|
||||||
assertEquals(200, status.getStatusLine().getStatusCode());
|
|
||||||
bundle = ourCtx.newXmlParser().parseBundle(responseContent);
|
|
||||||
|
|
||||||
ourLog.info(responseContent);
|
|
||||||
|
|
||||||
assertEquals(10, bundle.getEntries().size());
|
|
||||||
assertEquals("https://blah.com/base", bundle.getLinkBase().getValue());
|
|
||||||
assertEquals(linkNext, bundle.getLinkSelf().getValue());
|
|
||||||
|
|
||||||
p = bundle.getResources(Patient.class).get(0);
|
|
||||||
assertEquals("AAANamed", p.getIdentifierFirstRep().getValue().getValue());
|
|
||||||
assertEquals("http://foo/Patient?_id=11", bundle.getEntries().get(0).getLinkSearch().getValue());
|
|
||||||
assertEquals("https://blah.com/base/Patient/998811", bundle.getEntries().get(0).getLinkAlternate().getValue());
|
|
||||||
assertEquals("http://foo/Patient?_id=11", ResourceMetadataKeyEnum.LINK_SEARCH.get(p));
|
|
||||||
assertEquals("https://blah.com/base/Patient/998811", ResourceMetadataKeyEnum.LINK_ALTERNATE.get(p));
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testSearchById() throws Exception {
|
|
||||||
HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient?_id=aaa");
|
|
||||||
HttpResponse status = ourClient.execute(httpGet);
|
|
||||||
String responseContent = IOUtils.toString(status.getEntity().getContent());
|
|
||||||
IOUtils.closeQuietly(status.getEntity().getContent());
|
|
||||||
assertEquals(200, status.getStatusLine().getStatusCode());
|
|
||||||
Bundle bundle = ourCtx.newXmlParser().parseBundle(responseContent);
|
|
||||||
assertEquals(1, bundle.getEntries().size());
|
|
||||||
|
|
||||||
Patient p = bundle.getResources(Patient.class).get(0);
|
|
||||||
assertEquals("idaaa", p.getNameFirstRep().getFamilyAsSingleString());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testSearchByIdUsingClient() throws Exception {
|
|
||||||
IGenericClient client = ourCtx.newRestfulGenericClient("http://localhost:" + ourPort);
|
|
||||||
|
|
||||||
Bundle bundle = client.search().forResource("Patient").where(BaseResource.RES_ID.matches().value("aaa")).execute();
|
|
||||||
assertEquals(1, bundle.getEntries().size());
|
|
||||||
|
|
||||||
Patient p = bundle.getResources(Patient.class).get(0);
|
|
||||||
assertEquals("idaaa", p.getNameFirstRep().getFamilyAsSingleString());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testSearchByPost() throws Exception {
|
|
||||||
HttpPost filePost = new HttpPost("http://localhost:" + ourPort + "/Patient/_search");
|
|
||||||
|
|
||||||
// add parameters to the post method
|
|
||||||
List<NameValuePair> parameters = new ArrayList<NameValuePair>();
|
|
||||||
parameters.add(new BasicNameValuePair("_id", "aaa"));
|
|
||||||
|
|
||||||
UrlEncodedFormEntity sendentity = new UrlEncodedFormEntity(parameters, "UTF-8");
|
|
||||||
filePost.setEntity(sendentity);
|
|
||||||
|
|
||||||
HttpResponse status = ourClient.execute(filePost);
|
|
||||||
String responseContent = IOUtils.toString(status.getEntity().getContent());
|
|
||||||
IOUtils.closeQuietly(status.getEntity().getContent());
|
|
||||||
assertEquals(200, status.getStatusLine().getStatusCode());
|
|
||||||
Bundle bundle = ourCtx.newXmlParser().parseBundle(responseContent);
|
|
||||||
assertEquals(1, bundle.getEntries().size());
|
|
||||||
|
|
||||||
Patient p = bundle.getResources(Patient.class).get(0);
|
|
||||||
assertEquals("idaaa", p.getNameFirstRep().getFamilyAsSingleString());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* See #164
|
|
||||||
*/
|
|
||||||
@Test
|
|
||||||
public void testSearchByPostWithInvalidPostUrl() throws Exception {
|
|
||||||
HttpPost filePost = new HttpPost("http://localhost:" + ourPort + "/Patient?name=Central"); // should end with
|
|
||||||
// _search
|
|
||||||
|
|
||||||
// add parameters to the post method
|
|
||||||
List<NameValuePair> parameters = new ArrayList<NameValuePair>();
|
|
||||||
parameters.add(new BasicNameValuePair("_id", "aaa"));
|
|
||||||
|
|
||||||
UrlEncodedFormEntity sendentity = new UrlEncodedFormEntity(parameters, "UTF-8");
|
|
||||||
filePost.setEntity(sendentity);
|
|
||||||
|
|
||||||
HttpResponse status = ourClient.execute(filePost);
|
|
||||||
String responseContent = IOUtils.toString(status.getEntity().getContent());
|
|
||||||
IOUtils.closeQuietly(status.getEntity().getContent());
|
|
||||||
ourLog.info(responseContent);
|
|
||||||
assertEquals(400, status.getStatusLine().getStatusCode());
|
|
||||||
assertThat(responseContent, containsString("<details value=\"Incorrect Content-Type header value of "application/x-www-form-urlencoded; charset=UTF-8" was provided in the request. A FHIR Content-Type is required for "CREATE" operation\"/>"));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* See #164
|
|
||||||
*/
|
|
||||||
@Test
|
|
||||||
public void testSearchByPostWithMissingContentType() throws Exception {
|
|
||||||
HttpPost filePost = new HttpPost("http://localhost:" + ourPort + "/Patient?name=Central"); // should end with
|
|
||||||
// _search
|
|
||||||
|
|
||||||
HttpEntity sendentity = new ByteArrayEntity(new byte[] { 1, 2, 3, 4 });
|
|
||||||
filePost.setEntity(sendentity);
|
|
||||||
|
|
||||||
HttpResponse status = ourClient.execute(filePost);
|
|
||||||
String responseContent = IOUtils.toString(status.getEntity().getContent());
|
|
||||||
IOUtils.closeQuietly(status.getEntity().getContent());
|
|
||||||
ourLog.info(responseContent);
|
|
||||||
assertEquals(400, status.getStatusLine().getStatusCode());
|
|
||||||
assertThat(responseContent, containsString("<details value=\"No Content-Type header was provided in the request. This is required for "CREATE" operation\"/>"));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* See #164
|
|
||||||
*/
|
|
||||||
@Test
|
|
||||||
public void testSearchByPostWithParamsInBodyAndUrl() throws Exception {
|
|
||||||
HttpPost filePost = new HttpPost("http://localhost:" + ourPort + "/Patient/_search?name=Central");
|
|
||||||
|
|
||||||
// add parameters to the post method
|
|
||||||
List<NameValuePair> parameters = new ArrayList<NameValuePair>();
|
|
||||||
parameters.add(new BasicNameValuePair("_id", "aaa"));
|
|
||||||
|
|
||||||
UrlEncodedFormEntity sendentity = new UrlEncodedFormEntity(parameters, "UTF-8");
|
|
||||||
filePost.setEntity(sendentity);
|
|
||||||
|
|
||||||
HttpResponse status = ourClient.execute(filePost);
|
|
||||||
String responseContent = IOUtils.toString(status.getEntity().getContent());
|
|
||||||
IOUtils.closeQuietly(status.getEntity().getContent());
|
|
||||||
ourLog.info(responseContent);
|
|
||||||
assertEquals(200, status.getStatusLine().getStatusCode());
|
|
||||||
|
|
||||||
Bundle bundle = ourCtx.newXmlParser().parseBundle(responseContent);
|
|
||||||
assertEquals(1, bundle.getEntries().size());
|
|
||||||
|
|
||||||
Patient p = bundle.getResources(Patient.class).get(0);
|
|
||||||
assertEquals("idaaa", p.getName().get(0).getFamilyAsSingleString());
|
|
||||||
assertEquals("nameCentral", p.getName().get(1).getFamilyAsSingleString());
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testSearchCompartment() throws Exception {
|
|
||||||
HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient/123/fooCompartment");
|
|
||||||
HttpResponse status = ourClient.execute(httpGet);
|
|
||||||
String responseContent = IOUtils.toString(status.getEntity().getContent());
|
|
||||||
ourLog.info(responseContent);
|
|
||||||
IOUtils.closeQuietly(status.getEntity().getContent());
|
|
||||||
assertEquals(200, status.getStatusLine().getStatusCode());
|
|
||||||
Bundle bundle = ourCtx.newXmlParser().parseBundle(responseContent);
|
|
||||||
assertEquals(1, bundle.getEntries().size());
|
|
||||||
|
|
||||||
Patient p = bundle.getResources(Patient.class).get(0);
|
|
||||||
assertEquals("fooCompartment", p.getIdentifierFirstRep().getValue().getValue());
|
|
||||||
assertThat(bundle.getEntries().get(0).getResource().getId().getValue(), containsString("Patient/123"));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testSearchGetWithUnderscoreSearch() throws Exception {
|
|
||||||
HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Observation/_search?subject%3APatient=100&name=3141-9%2C8302-2%2C8287-5%2C39156-5");
|
|
||||||
|
|
||||||
HttpResponse status = ourClient.execute(httpGet);
|
|
||||||
String responseContent = IOUtils.toString(status.getEntity().getContent());
|
|
||||||
IOUtils.closeQuietly(status.getEntity().getContent());
|
|
||||||
|
|
||||||
assertEquals(200, status.getStatusLine().getStatusCode());
|
|
||||||
Bundle bundle = ourCtx.newXmlParser().parseBundle(responseContent);
|
|
||||||
assertEquals(1, bundle.getEntries().size());
|
|
||||||
|
|
||||||
Observation p = bundle.getResources(Observation.class).get(0);
|
|
||||||
assertEquals("Patient/100", p.getSubject().getReference().toString());
|
|
||||||
assertEquals(4, p.getName().getCoding().size());
|
|
||||||
assertEquals("3141-9", p.getName().getCoding().get(0).getCode().getValue());
|
|
||||||
assertEquals("8302-2", p.getName().getCoding().get(1).getCode().getValue());
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testSearchIncludesParametersIncludes() throws Exception {
|
|
||||||
HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient?_query=searchIncludes&_include=foo&_include:recurse=bar");
|
|
||||||
|
|
||||||
CloseableHttpResponse status = ourClient.execute(httpGet);
|
|
||||||
IOUtils.toString(status.getEntity().getContent());
|
|
||||||
IOUtils.closeQuietly(status.getEntity().getContent());
|
|
||||||
assertEquals(200, status.getStatusLine().getStatusCode());
|
|
||||||
|
|
||||||
assertEquals(2, ourLastIncludes.size());
|
|
||||||
assertThat(ourLastIncludes, containsInAnyOrder(new Include("foo", false), new Include("bar", true)));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testSearchIncludesParametersIncludesList() throws Exception {
|
|
||||||
HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient?_query=searchIncludesList&_include=foo&_include:recurse=bar");
|
|
||||||
|
|
||||||
CloseableHttpResponse status = ourClient.execute(httpGet);
|
|
||||||
IOUtils.toString(status.getEntity().getContent());
|
|
||||||
IOUtils.closeQuietly(status.getEntity().getContent());
|
|
||||||
assertEquals(200, status.getStatusLine().getStatusCode());
|
|
||||||
|
|
||||||
assertEquals(2, ourLastIncludes.size());
|
|
||||||
assertThat(ourLastIncludes, containsInAnyOrder(new Include("foo", false), new Include("bar", true)));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testSearchIncludesParametersNone() throws Exception {
|
|
||||||
HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient?_query=searchIncludes");
|
|
||||||
|
|
||||||
CloseableHttpResponse status = ourClient.execute(httpGet);
|
|
||||||
IOUtils.toString(status.getEntity().getContent());
|
|
||||||
IOUtils.closeQuietly(status.getEntity().getContent());
|
|
||||||
assertEquals(200, status.getStatusLine().getStatusCode());
|
|
||||||
|
|
||||||
assertThat(ourLastIncludes, empty());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testSearchWithOrList() throws Exception {
|
|
||||||
HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient?findPatientWithOrList=aaa,bbb");
|
|
||||||
HttpResponse status = ourClient.execute(httpGet);
|
|
||||||
String responseContent = IOUtils.toString(status.getEntity().getContent());
|
|
||||||
IOUtils.closeQuietly(status.getEntity().getContent());
|
|
||||||
assertEquals(200, status.getStatusLine().getStatusCode());
|
|
||||||
Bundle bundle = ourCtx.newXmlParser().parseBundle(responseContent);
|
|
||||||
assertEquals(1, bundle.getEntries().size());
|
|
||||||
|
|
||||||
Patient p = bundle.getResources(Patient.class).get(0);
|
|
||||||
assertEquals("aaa", p.getIdentifier().get(0).getValue().getValue());
|
|
||||||
assertEquals("bbb", p.getIdentifier().get(1).getValue().getValue());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testSearchWithTokenParameter() throws Exception {
|
|
||||||
String token = UrlEscapers.urlFragmentEscaper().asFunction().apply("http://www.dmix.gov/vista/2957|301");
|
|
||||||
HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient?tokenParam=" + token);
|
|
||||||
HttpResponse status = ourClient.execute(httpGet);
|
|
||||||
String responseContent = IOUtils.toString(status.getEntity().getContent());
|
|
||||||
IOUtils.closeQuietly(status.getEntity().getContent());
|
|
||||||
assertEquals(200, status.getStatusLine().getStatusCode());
|
|
||||||
Bundle bundle = ourCtx.newXmlParser().parseBundle(responseContent);
|
|
||||||
assertEquals(1, bundle.getEntries().size());
|
|
||||||
|
|
||||||
Patient p = bundle.getResources(Patient.class).get(0);
|
|
||||||
assertEquals("http://www.dmix.gov/vista/2957", p.getNameFirstRep().getFamilyAsSingleString());
|
|
||||||
assertEquals("301", p.getNameFirstRep().getGivenAsSingleString());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testSpecificallyNamedQueryGetsPrecedence() throws Exception {
|
|
||||||
HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient?AAA=123");
|
|
||||||
|
|
||||||
HttpResponse status = ourClient.execute(httpGet);
|
|
||||||
String responseContent = IOUtils.toString(status.getEntity().getContent());
|
|
||||||
IOUtils.closeQuietly(status.getEntity().getContent());
|
|
||||||
assertEquals(200, status.getStatusLine().getStatusCode());
|
|
||||||
Bundle bundle = ourCtx.newXmlParser().parseBundle(responseContent);
|
|
||||||
assertEquals(1, bundle.getEntries().size());
|
|
||||||
|
|
||||||
Patient p = bundle.getResources(Patient.class).get(0);
|
|
||||||
assertEquals("AAA", p.getIdentifierFirstRep().getValue().getValue());
|
|
||||||
|
|
||||||
// Now the named query
|
|
||||||
|
|
||||||
httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient?_query=findPatientByAAA&AAA=123");
|
|
||||||
|
|
||||||
status = ourClient.execute(httpGet);
|
|
||||||
responseContent = IOUtils.toString(status.getEntity().getContent());
|
|
||||||
IOUtils.closeQuietly(status.getEntity().getContent());
|
|
||||||
assertEquals(200, status.getStatusLine().getStatusCode());
|
|
||||||
bundle = ourCtx.newXmlParser().parseBundle(responseContent);
|
|
||||||
assertEquals(1, bundle.getEntries().size());
|
|
||||||
|
|
||||||
p = bundle.getResources(Patient.class).get(0);
|
|
||||||
assertEquals("AAANamed", p.getIdentifierFirstRep().getValue().getValue());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@AfterClass
|
|
||||||
public static void afterClassClearContext() throws Exception {
|
|
||||||
ourServer.stop();
|
|
||||||
TestUtil.clearAllStaticFieldsForUnitTest();
|
|
||||||
}
|
|
||||||
|
|
||||||
@BeforeClass
|
|
||||||
public static void beforeClass() throws Exception {
|
|
||||||
ourPort = PortUtil.findFreePort();
|
|
||||||
ourServer = new Server(ourPort);
|
|
||||||
|
|
||||||
DummyPatientResourceProvider patientProvider = new DummyPatientResourceProvider();
|
|
||||||
|
|
||||||
ServletHandler proxyHandler = new ServletHandler();
|
|
||||||
ourServlet = new RestfulServer();
|
|
||||||
ourServlet.getFhirContext().setNarrativeGenerator(new DefaultThymeleafNarrativeGenerator());
|
|
||||||
ourServlet.setPagingProvider(new FifoMemoryPagingProvider(10).setDefaultPageSize(10));
|
|
||||||
|
|
||||||
ourServlet.setResourceProviders(patientProvider, new DummyObservationResourceProvider());
|
|
||||||
ServletHolder servletHolder = new ServletHolder(ourServlet);
|
|
||||||
proxyHandler.addServletWithMapping(servletHolder, "/*");
|
|
||||||
ourServer.setHandler(proxyHandler);
|
|
||||||
ourServer.start();
|
|
||||||
|
|
||||||
PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager(5000, TimeUnit.MILLISECONDS);
|
|
||||||
HttpClientBuilder builder = HttpClientBuilder.create();
|
|
||||||
builder.setConnectionManager(connectionManager);
|
|
||||||
ourClient = builder.build();
|
|
||||||
|
|
||||||
ourDefaultAddressStrategy = ourServlet.getServerAddressStrategy();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class DummyObservationResourceProvider implements IResourceProvider {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Class<? extends IResource> getResourceType() {
|
|
||||||
return Observation.class;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Search
|
|
||||||
public Observation search(@RequiredParam(name = "subject") ReferenceParam theSubject, @RequiredParam(name = "name") TokenOrListParam theName) {
|
|
||||||
Observation o = new Observation();
|
|
||||||
o.setId("1");
|
|
||||||
|
|
||||||
o.getSubject().setReference(theSubject.getResourceType() + "/" + theSubject.getIdPart());
|
|
||||||
for (BaseCodingDt next : theName.getListAsCodings()) {
|
|
||||||
o.getName().getCoding().add(new CodingDt(next));
|
|
||||||
}
|
|
||||||
|
|
||||||
return o;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public static class DummyPatientResourceProvider implements IResourceProvider {
|
|
||||||
|
|
||||||
@Search(compartmentName = "fooCompartment")
|
|
||||||
public List<Patient> compartment(@IdParam IdDt theId) {
|
|
||||||
ArrayList<Patient> retVal = new ArrayList<Patient>();
|
|
||||||
|
|
||||||
Patient patient = new Patient();
|
|
||||||
patient.setId(theId);
|
|
||||||
patient.addIdentifier("system", "fooCompartment");
|
|
||||||
retVal.add(patient);
|
|
||||||
return retVal;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Only needed for #164
|
|
||||||
*/
|
|
||||||
@Create
|
|
||||||
public MethodOutcome create(@ResourceParam Patient thePatient) {
|
|
||||||
throw new IllegalArgumentException();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Search
|
|
||||||
public List<Patient> findPatient(@RequiredParam(name = "_id") StringParam theParam, @OptionalParam(name = "name") StringParam theName) {
|
|
||||||
ArrayList<Patient> retVal = new ArrayList<Patient>();
|
|
||||||
|
|
||||||
Patient patient = new Patient();
|
|
||||||
patient.setId("1");
|
|
||||||
patient.addIdentifier("system", "identifier123");
|
|
||||||
if (theParam != null) {
|
|
||||||
patient.addName().addFamily("id" + theParam.getValue());
|
|
||||||
if (theName != null) {
|
|
||||||
patient.addName().addFamily("name" + theName.getValue());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
retVal.add(patient);
|
|
||||||
return retVal;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Search
|
|
||||||
public List<Patient> findPatientByAAA01(@RequiredParam(name = "AAA") StringParam theParam) {
|
|
||||||
ArrayList<Patient> retVal = new ArrayList<Patient>();
|
|
||||||
|
|
||||||
Patient patient = new Patient();
|
|
||||||
patient.setId("1");
|
|
||||||
patient.addIdentifier("system", "AAA");
|
|
||||||
retVal.add(patient);
|
|
||||||
return retVal;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Search(queryName = "findPatientByAAA")
|
|
||||||
public List<Patient> findPatientByAAA02Named(@OptionalParam(name = "AAA") StringParam theParam) {
|
|
||||||
ArrayList<Patient> retVal = new ArrayList<Patient>();
|
|
||||||
|
|
||||||
Patient patient = new Patient();
|
|
||||||
patient.setId("1");
|
|
||||||
patient.addIdentifier("system", "AAANamed");
|
|
||||||
retVal.add(patient);
|
|
||||||
return retVal;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Search()
|
|
||||||
public List<Patient> findPatientWithAndList(@RequiredParam(name = "findPatientWithAndList") StringAndListParam theParam) {
|
|
||||||
ourLastAndList = theParam;
|
|
||||||
ArrayList<Patient> retVal = new ArrayList<Patient>();
|
|
||||||
return retVal;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Search()
|
|
||||||
public List<Patient> findPatientWithOrList(@RequiredParam(name = "findPatientWithOrList") StringOrListParam theParam) {
|
|
||||||
ArrayList<Patient> retVal = new ArrayList<Patient>();
|
|
||||||
|
|
||||||
Patient patient = new Patient();
|
|
||||||
patient.setId("1");
|
|
||||||
for (StringParam next : theParam.getValuesAsQueryTokens()) {
|
|
||||||
patient.addIdentifier("system", next.getValue());
|
|
||||||
}
|
|
||||||
retVal.add(patient);
|
|
||||||
return retVal;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Search()
|
|
||||||
public List<Patient> findPatientWithToken(@RequiredParam(name = "tokenParam") TokenParam theParam) {
|
|
||||||
ArrayList<Patient> retVal = new ArrayList<Patient>();
|
|
||||||
|
|
||||||
Patient patient = new Patient();
|
|
||||||
patient.setId("1");
|
|
||||||
patient.addName().addFamily(theParam.getSystem()).addGiven(theParam.getValue());
|
|
||||||
retVal.add(patient);
|
|
||||||
return retVal;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Search(queryName = "findWithLinks")
|
|
||||||
public List<Patient> findWithLinks() {
|
|
||||||
ArrayList<Patient> retVal = new ArrayList<Patient>();
|
|
||||||
|
|
||||||
for (int i = 1; i <= 20; i++) {
|
|
||||||
Patient patient = new Patient();
|
|
||||||
patient.setId("" + i);
|
|
||||||
patient.addIdentifier("system", "AAANamed");
|
|
||||||
ResourceMetadataKeyEnum.LINK_SEARCH.put(patient, ("http://foo/Patient?_id=" + i));
|
|
||||||
ResourceMetadataKeyEnum.LINK_ALTERNATE.put(patient, ("Patient/9988" + i));
|
|
||||||
retVal.add(patient);
|
|
||||||
}
|
|
||||||
|
|
||||||
return retVal;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Class<? extends IResource> getResourceType() {
|
|
||||||
return Patient.class;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Search(queryName = "searchIncludes")
|
|
||||||
public List<Patient> searchIncludes(@IncludeParam Set<Include> theIncludes) {
|
|
||||||
ourLastIncludes = theIncludes;
|
|
||||||
|
|
||||||
ArrayList<Patient> retVal = new ArrayList<Patient>();
|
|
||||||
return retVal;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Search(queryName = "searchIncludesList")
|
|
||||||
public List<Patient> searchIncludesList(@IncludeParam List<Include> theIncludes) {
|
|
||||||
if (theIncludes != null) {
|
|
||||||
ourLastIncludes = new HashSet<Include>(theIncludes);
|
|
||||||
}
|
|
||||||
|
|
||||||
ArrayList<Patient> retVal = new ArrayList<Patient>();
|
|
||||||
return retVal;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Search(queryName = "searchWithRef")
|
|
||||||
public Patient searchWithRef() {
|
|
||||||
Patient patient = new Patient();
|
|
||||||
patient.setId("Patient/1/_history/1");
|
|
||||||
patient.getManagingOrganization().setReference("http://localhost:" + ourPort + "/Organization/555/_history/666");
|
|
||||||
return patient;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -265,11 +265,6 @@ public class Dstu2_1BundleFactory implements IVersionSpecificBundleFactory {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public ca.uhn.fhir.model.api.Bundle getDstu1Bundle() {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IBaseResource getResourceBundle() {
|
public IBaseResource getResourceBundle() {
|
||||||
return myBundle;
|
return myBundle;
|
||||||
|
|
|
@ -136,6 +136,7 @@ public class GenericClientDstu2_1Test {
|
||||||
OperationOutcome oo = (OperationOutcome) outcome.getOperationOutcome();
|
OperationOutcome oo = (OperationOutcome) outcome.getOperationOutcome();
|
||||||
assertThat(oo.getText().getDivAsString(), containsString("OK!"));
|
assertThat(oo.getText().getDivAsString(), containsString("OK!"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPatchJsonByIdType() throws Exception {
|
public void testPatchJsonByIdType() throws Exception {
|
||||||
OperationOutcome conf = new OperationOutcome();
|
OperationOutcome conf = new OperationOutcome();
|
||||||
|
@ -173,6 +174,7 @@ public class GenericClientDstu2_1Test {
|
||||||
OperationOutcome oo = (OperationOutcome) outcome.getOperationOutcome();
|
OperationOutcome oo = (OperationOutcome) outcome.getOperationOutcome();
|
||||||
assertThat(oo.getText().getDivAsString(), containsString("OK!"));
|
assertThat(oo.getText().getDivAsString(), containsString("OK!"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPatchJsonByConditionalString() throws Exception {
|
public void testPatchJsonByConditionalString() throws Exception {
|
||||||
OperationOutcome conf = new OperationOutcome();
|
OperationOutcome conf = new OperationOutcome();
|
||||||
|
@ -210,6 +212,7 @@ public class GenericClientDstu2_1Test {
|
||||||
OperationOutcome oo = (OperationOutcome) outcome.getOperationOutcome();
|
OperationOutcome oo = (OperationOutcome) outcome.getOperationOutcome();
|
||||||
assertThat(oo.getText().getDivAsString(), containsString("OK!"));
|
assertThat(oo.getText().getDivAsString(), containsString("OK!"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPatchJsonByConditionalParam() throws Exception {
|
public void testPatchJsonByConditionalParam() throws Exception {
|
||||||
OperationOutcome conf = new OperationOutcome();
|
OperationOutcome conf = new OperationOutcome();
|
||||||
|
@ -248,6 +251,7 @@ public class GenericClientDstu2_1Test {
|
||||||
OperationOutcome oo = (OperationOutcome) outcome.getOperationOutcome();
|
OperationOutcome oo = (OperationOutcome) outcome.getOperationOutcome();
|
||||||
assertThat(oo.getText().getDivAsString(), containsString("OK!"));
|
assertThat(oo.getText().getDivAsString(), containsString("OK!"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPatchJsonByConditionalParamResourceType() throws Exception {
|
public void testPatchJsonByConditionalParamResourceType() throws Exception {
|
||||||
OperationOutcome conf = new OperationOutcome();
|
OperationOutcome conf = new OperationOutcome();
|
||||||
|
@ -286,6 +290,7 @@ public class GenericClientDstu2_1Test {
|
||||||
OperationOutcome oo = (OperationOutcome) outcome.getOperationOutcome();
|
OperationOutcome oo = (OperationOutcome) outcome.getOperationOutcome();
|
||||||
assertThat(oo.getText().getDivAsString(), containsString("OK!"));
|
assertThat(oo.getText().getDivAsString(), containsString("OK!"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPatchXmlByIdString() throws Exception {
|
public void testPatchXmlByIdString() throws Exception {
|
||||||
OperationOutcome conf = new OperationOutcome();
|
OperationOutcome conf = new OperationOutcome();
|
||||||
|
@ -357,7 +362,6 @@ public class GenericClientDstu2_1Test {
|
||||||
IGenericClient client = ourCtx.newRestfulGenericClient("http://example.com/fhir");
|
IGenericClient client = ourCtx.newRestfulGenericClient("http://example.com/fhir");
|
||||||
int idx = 0;
|
int idx = 0;
|
||||||
|
|
||||||
|
|
||||||
client.setEncoding(EncodingEnum.JSON);
|
client.setEncoding(EncodingEnum.JSON);
|
||||||
client.search()
|
client.search()
|
||||||
.forResource("Device")
|
.forResource("Device")
|
||||||
|
@ -368,7 +372,6 @@ public class GenericClientDstu2_1Test {
|
||||||
assertEquals(Constants.CT_FHIR_JSON, capt.getAllValues().get(idx).getFirstHeader(Constants.HEADER_ACCEPT).getValue());
|
assertEquals(Constants.CT_FHIR_JSON, capt.getAllValues().get(idx).getFirstHeader(Constants.HEADER_ACCEPT).getValue());
|
||||||
idx++;
|
idx++;
|
||||||
|
|
||||||
|
|
||||||
client.setEncoding(EncodingEnum.XML);
|
client.setEncoding(EncodingEnum.XML);
|
||||||
client.search()
|
client.search()
|
||||||
.forResource("Device")
|
.forResource("Device")
|
||||||
|
@ -460,8 +463,6 @@ public class GenericClientDstu2_1Test {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
@Test
|
@Test
|
||||||
public void testClientFailures() throws Exception {
|
public void testClientFailures() throws Exception {
|
||||||
|
@ -512,14 +513,12 @@ public class GenericClientDstu2_1Test {
|
||||||
IGenericClient client = ourCtx.newRestfulGenericClient("http://example.com/fhir");
|
IGenericClient client = ourCtx.newRestfulGenericClient("http://example.com/fhir");
|
||||||
client.registerInterceptor(new CookieInterceptor("foo=bar"));
|
client.registerInterceptor(new CookieInterceptor("foo=bar"));
|
||||||
|
|
||||||
|
|
||||||
Bundle resp = client
|
Bundle resp = client
|
||||||
.history()
|
.history()
|
||||||
.onType(Patient.class)
|
.onType(Patient.class)
|
||||||
.andReturnBundle(Bundle.class)
|
.andReturnBundle(Bundle.class)
|
||||||
.execute();
|
.execute();
|
||||||
|
|
||||||
|
|
||||||
assertEquals("foo=bar", capt.getAllValues().get(0).getFirstHeader("Cookie").getValue());
|
assertEquals("foo=bar", capt.getAllValues().get(0).getFirstHeader("Cookie").getValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -633,14 +632,12 @@ public class GenericClientDstu2_1Test {
|
||||||
|
|
||||||
IGenericClient client = ourCtx.newRestfulGenericClient("http://example.com/fhir");
|
IGenericClient client = ourCtx.newRestfulGenericClient("http://example.com/fhir");
|
||||||
|
|
||||||
|
|
||||||
Bundle resp = client
|
Bundle resp = client
|
||||||
.history()
|
.history()
|
||||||
.onType(CustomTypeDstu2_1Test.MyCustomPatient.class)
|
.onType(CustomTypeDstu2_1Test.MyCustomPatient.class)
|
||||||
.andReturnBundle(Bundle.class)
|
.andReturnBundle(Bundle.class)
|
||||||
.execute();
|
.execute();
|
||||||
|
|
||||||
|
|
||||||
assertEquals(1, resp.getEntry().size());
|
assertEquals(1, resp.getEntry().size());
|
||||||
assertEquals(CustomTypeDstu2_1Test.MyCustomPatient.class, resp.getEntry().get(0).getResource().getClass());
|
assertEquals(CustomTypeDstu2_1Test.MyCustomPatient.class, resp.getEntry().get(0).getResource().getClass());
|
||||||
assertEquals("http://example.com/fhir/Patient/_history", capt.getAllValues().get(0).getURI().toASCIIString());
|
assertEquals("http://example.com/fhir/Patient/_history", capt.getAllValues().get(0).getURI().toASCIIString());
|
||||||
|
@ -664,26 +661,22 @@ public class GenericClientDstu2_1Test {
|
||||||
Bundle bundle = new Bundle();
|
Bundle bundle = new Bundle();
|
||||||
bundle.addLink().setRelation("next").setUrl("http://foo/next");
|
bundle.addLink().setRelation("next").setUrl("http://foo/next");
|
||||||
|
|
||||||
|
|
||||||
Bundle resp = client
|
Bundle resp = client
|
||||||
.loadPage()
|
.loadPage()
|
||||||
.next(bundle)
|
.next(bundle)
|
||||||
.preferResponseType(MyCustomPatient.class)
|
.preferResponseType(MyCustomPatient.class)
|
||||||
.execute();
|
.execute();
|
||||||
|
|
||||||
|
|
||||||
assertEquals(1, resp.getEntry().size());
|
assertEquals(1, resp.getEntry().size());
|
||||||
assertEquals(CustomTypeDstu2_1Test.MyCustomPatient.class, resp.getEntry().get(0).getResource().getClass());
|
assertEquals(CustomTypeDstu2_1Test.MyCustomPatient.class, resp.getEntry().get(0).getResource().getClass());
|
||||||
assertEquals("http://foo/next", capt.getAllValues().get(0).getURI().toASCIIString());
|
assertEquals("http://foo/next", capt.getAllValues().get(0).getURI().toASCIIString());
|
||||||
|
|
||||||
|
|
||||||
resp = client
|
resp = client
|
||||||
.loadPage()
|
.loadPage()
|
||||||
.next(bundle)
|
.next(bundle)
|
||||||
.preferResponseTypes(toTypeList(MyCustomPatient.class))
|
.preferResponseTypes(toTypeList(MyCustomPatient.class))
|
||||||
.execute();
|
.execute();
|
||||||
|
|
||||||
|
|
||||||
assertEquals(1, resp.getEntry().size());
|
assertEquals(1, resp.getEntry().size());
|
||||||
assertEquals(CustomTypeDstu2_1Test.MyCustomPatient.class, resp.getEntry().get(0).getResource().getClass());
|
assertEquals(CustomTypeDstu2_1Test.MyCustomPatient.class, resp.getEntry().get(0).getResource().getClass());
|
||||||
assertEquals("http://foo/next", capt.getAllValues().get(0).getURI().toASCIIString());
|
assertEquals("http://foo/next", capt.getAllValues().get(0).getURI().toASCIIString());
|
||||||
|
@ -711,7 +704,6 @@ public class GenericClientDstu2_1Test {
|
||||||
|
|
||||||
IGenericClient client = ourCtx.newRestfulGenericClient("http://example.com/fhir");
|
IGenericClient client = ourCtx.newRestfulGenericClient("http://example.com/fhir");
|
||||||
|
|
||||||
|
|
||||||
Parameters resp = client
|
Parameters resp = client
|
||||||
.operation()
|
.operation()
|
||||||
.onServer()
|
.onServer()
|
||||||
|
@ -720,12 +712,10 @@ public class GenericClientDstu2_1Test {
|
||||||
.preferResponseType(MyCustomPatient.class)
|
.preferResponseType(MyCustomPatient.class)
|
||||||
.execute();
|
.execute();
|
||||||
|
|
||||||
|
|
||||||
assertEquals(1, resp.getParameter().size());
|
assertEquals(1, resp.getParameter().size());
|
||||||
assertEquals(CustomTypeDstu2_1Test.MyCustomPatient.class, resp.getParameter().get(0).getResource().getClass());
|
assertEquals(CustomTypeDstu2_1Test.MyCustomPatient.class, resp.getParameter().get(0).getResource().getClass());
|
||||||
assertEquals("http://example.com/fhir/$foo", capt.getAllValues().get(0).getURI().toASCIIString());
|
assertEquals("http://example.com/fhir/$foo", capt.getAllValues().get(0).getURI().toASCIIString());
|
||||||
|
|
||||||
|
|
||||||
resp = client
|
resp = client
|
||||||
.operation()
|
.operation()
|
||||||
.onType(MyCustomPatient.class)
|
.onType(MyCustomPatient.class)
|
||||||
|
@ -733,7 +723,6 @@ public class GenericClientDstu2_1Test {
|
||||||
.withNoParameters(Parameters.class)
|
.withNoParameters(Parameters.class)
|
||||||
.execute();
|
.execute();
|
||||||
|
|
||||||
|
|
||||||
assertEquals(1, resp.getParameter().size());
|
assertEquals(1, resp.getParameter().size());
|
||||||
assertEquals(CustomTypeDstu2_1Test.MyCustomPatient.class, resp.getParameter().get(0).getResource().getClass());
|
assertEquals(CustomTypeDstu2_1Test.MyCustomPatient.class, resp.getParameter().get(0).getResource().getClass());
|
||||||
assertEquals("http://example.com/fhir/Patient/$foo", capt.getAllValues().get(1).getURI().toASCIIString());
|
assertEquals("http://example.com/fhir/Patient/$foo", capt.getAllValues().get(1).getURI().toASCIIString());
|
||||||
|
@ -755,14 +744,12 @@ public class GenericClientDstu2_1Test {
|
||||||
|
|
||||||
IGenericClient client = ourCtx.newRestfulGenericClient("http://example.com/fhir");
|
IGenericClient client = ourCtx.newRestfulGenericClient("http://example.com/fhir");
|
||||||
|
|
||||||
|
|
||||||
Bundle resp = client
|
Bundle resp = client
|
||||||
.search()
|
.search()
|
||||||
.forResource(CustomTypeDstu2_1Test.MyCustomPatient.class)
|
.forResource(CustomTypeDstu2_1Test.MyCustomPatient.class)
|
||||||
.returnBundle(Bundle.class)
|
.returnBundle(Bundle.class)
|
||||||
.execute();
|
.execute();
|
||||||
|
|
||||||
|
|
||||||
assertEquals(1, resp.getEntry().size());
|
assertEquals(1, resp.getEntry().size());
|
||||||
assertEquals(CustomTypeDstu2_1Test.MyCustomPatient.class, resp.getEntry().get(0).getResource().getClass());
|
assertEquals(CustomTypeDstu2_1Test.MyCustomPatient.class, resp.getEntry().get(0).getResource().getClass());
|
||||||
assertEquals("http://example.com/fhir/Patient", capt.getAllValues().get(0).getURI().toASCIIString());
|
assertEquals("http://example.com/fhir/Patient", capt.getAllValues().get(0).getURI().toASCIIString());
|
||||||
|
@ -966,18 +953,6 @@ public class GenericClientDstu2_1Test {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
|
||||||
@Test
|
|
||||||
public void testInvalidConformanceCall() {
|
|
||||||
IGenericClient client = ourCtx.newRestfulGenericClient("http://example.com/fhir");
|
|
||||||
try {
|
|
||||||
client.conformance();
|
|
||||||
fail();
|
|
||||||
} catch (IllegalArgumentException e) {
|
|
||||||
assertEquals("Must call fetchConformance() instead of conformance() for RI/STU3+ structures", e.getMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* See #150
|
* See #150
|
||||||
*/
|
*/
|
||||||
|
@ -988,22 +963,19 @@ public class GenericClientDstu2_1Test {
|
||||||
IGenericClient client = ourCtx.newRestfulGenericClient("http://example.com/fhir");
|
IGenericClient client = ourCtx.newRestfulGenericClient("http://example.com/fhir");
|
||||||
int idx = 0;
|
int idx = 0;
|
||||||
|
|
||||||
|
|
||||||
client
|
client
|
||||||
.search()
|
.search()
|
||||||
.forResource(Patient.class)
|
.forResource(Patient.class)
|
||||||
.where(Patient.FAMILY.matches().value((String)null))
|
.where(Patient.FAMILY.matches().value((String) null))
|
||||||
.and(Patient.BIRTHDATE.exactly().day((Date)null))
|
.and(Patient.BIRTHDATE.exactly().day((Date) null))
|
||||||
.and(Patient.GENDER.exactly().code((String)null))
|
.and(Patient.GENDER.exactly().code((String) null))
|
||||||
.and(Patient.ORGANIZATION.hasId((String)null))
|
.and(Patient.ORGANIZATION.hasId((String) null))
|
||||||
.returnBundle(Bundle.class)
|
.returnBundle(Bundle.class)
|
||||||
.execute();
|
.execute();
|
||||||
|
|
||||||
|
|
||||||
assertEquals("http://example.com/fhir/Patient", capt.getAllValues().get(idx).getURI().toString());
|
assertEquals("http://example.com/fhir/Patient", capt.getAllValues().get(idx).getURI().toString());
|
||||||
idx++;
|
idx++;
|
||||||
|
|
||||||
|
|
||||||
client
|
client
|
||||||
.search()
|
.search()
|
||||||
.forResource(Encounter.class)
|
.forResource(Encounter.class)
|
||||||
|
@ -1011,11 +983,9 @@ public class GenericClientDstu2_1Test {
|
||||||
.returnBundle(Bundle.class)
|
.returnBundle(Bundle.class)
|
||||||
.execute();
|
.execute();
|
||||||
|
|
||||||
|
|
||||||
assertEquals("http://example.com/fhir/Encounter", capt.getAllValues().get(idx).getURI().toString());
|
assertEquals("http://example.com/fhir/Encounter", capt.getAllValues().get(idx).getURI().toString());
|
||||||
idx++;
|
idx++;
|
||||||
|
|
||||||
|
|
||||||
client
|
client
|
||||||
.search()
|
.search()
|
||||||
.forResource(Observation.class)
|
.forResource(Observation.class)
|
||||||
|
@ -1023,7 +993,6 @@ public class GenericClientDstu2_1Test {
|
||||||
.returnBundle(Bundle.class)
|
.returnBundle(Bundle.class)
|
||||||
.execute();
|
.execute();
|
||||||
|
|
||||||
|
|
||||||
assertEquals("http://example.com/fhir/Observation", capt.getAllValues().get(idx).getURI().toString());
|
assertEquals("http://example.com/fhir/Observation", capt.getAllValues().get(idx).getURI().toString());
|
||||||
idx++;
|
idx++;
|
||||||
|
|
||||||
|
@ -1058,7 +1027,6 @@ public class GenericClientDstu2_1Test {
|
||||||
IGenericClient client = ourCtx.newRestfulGenericClient("http://example.com/fhir");
|
IGenericClient client = ourCtx.newRestfulGenericClient("http://example.com/fhir");
|
||||||
int idx = 0;
|
int idx = 0;
|
||||||
|
|
||||||
|
|
||||||
client
|
client
|
||||||
.update()
|
.update()
|
||||||
.resource(bundle)
|
.resource(bundle)
|
||||||
|
@ -1086,7 +1054,9 @@ public class GenericClientDstu2_1Test {
|
||||||
bundle.addEntry().setResource(patient);
|
bundle.addEntry().setResource(patient);
|
||||||
|
|
||||||
final String encoded = p.encodeResourceToString(bundle);
|
final String encoded = p.encodeResourceToString(bundle);
|
||||||
assertEquals("<Bundle xmlns=\"http://hl7.org/fhir\"><id value=\"BUNDLE1\"/><entry><resource><Patient xmlns=\"http://hl7.org/fhir\"><id value=\"PATIENT1\"/><name><family value=\"PATIENT1\"/></name></Patient></resource></entry></Bundle>", encoded);
|
assertEquals(
|
||||||
|
"<Bundle xmlns=\"http://hl7.org/fhir\"><id value=\"BUNDLE1\"/><entry><resource><Patient xmlns=\"http://hl7.org/fhir\"><id value=\"PATIENT1\"/><name><family value=\"PATIENT1\"/></name></Patient></resource></entry></Bundle>",
|
||||||
|
encoded);
|
||||||
|
|
||||||
ArgumentCaptor<HttpUriRequest> capt = ArgumentCaptor.forClass(HttpUriRequest.class);
|
ArgumentCaptor<HttpUriRequest> capt = ArgumentCaptor.forClass(HttpUriRequest.class);
|
||||||
when(myHttpClient.execute(capt.capture())).thenReturn(myHttpResponse);
|
when(myHttpClient.execute(capt.capture())).thenReturn(myHttpResponse);
|
||||||
|
@ -1102,7 +1072,6 @@ public class GenericClientDstu2_1Test {
|
||||||
IGenericClient client = ourCtx.newRestfulGenericClient("http://example.com/fhir");
|
IGenericClient client = ourCtx.newRestfulGenericClient("http://example.com/fhir");
|
||||||
int idx = 0;
|
int idx = 0;
|
||||||
|
|
||||||
|
|
||||||
client
|
client
|
||||||
.update()
|
.update()
|
||||||
.resource(bundle)
|
.resource(bundle)
|
||||||
|
@ -1132,7 +1101,9 @@ public class GenericClientDstu2_1Test {
|
||||||
client.read().resource("Patient").withId("123").elementsSubset("name", "identifier").execute();
|
client.read().resource("Patient").withId("123").elementsSubset("name", "identifier").execute();
|
||||||
fail();
|
fail();
|
||||||
} catch (FhirClientConnectionException e) {
|
} catch (FhirClientConnectionException e) {
|
||||||
assertEquals("Failed to parse response from server when performing GET to URL http://example.com/fhir/Patient/123?_elements=identifier%2Cname - ca.uhn.fhir.parser.DataFormatException: Invalid JSON content detected, missing required element: 'resourceType'", e.getMessage());
|
assertEquals(
|
||||||
|
"Failed to parse response from server when performing GET to URL http://example.com/fhir/Patient/123?_elements=identifier%2Cname - ca.uhn.fhir.parser.DataFormatException: Invalid JSON content detected, missing required element: 'resourceType'",
|
||||||
|
e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1219,67 +1190,60 @@ public class GenericClientDstu2_1Test {
|
||||||
DateTimeDt now = DateTimeDt.withCurrentTime();
|
DateTimeDt now = DateTimeDt.withCurrentTime();
|
||||||
String dateString = now.getValueAsString().substring(0, 10);
|
String dateString = now.getValueAsString().substring(0, 10);
|
||||||
|
|
||||||
|
|
||||||
client.search()
|
client.search()
|
||||||
.forResource("Patient")
|
.forResource("Patient")
|
||||||
.where(Patient.BIRTHDATE.after().day(dateString))
|
.where(Patient.BIRTHDATE.after().day(dateString))
|
||||||
.returnBundle(Bundle.class)
|
.returnBundle(Bundle.class)
|
||||||
.execute();
|
.execute();
|
||||||
|
|
||||||
assertEquals("http://example.com/fhir/Patient?birthdate=gt"+dateString, capt.getAllValues().get(idx).getURI().toString());
|
assertEquals("http://example.com/fhir/Patient?birthdate=gt" + dateString, capt.getAllValues().get(idx).getURI().toString());
|
||||||
idx++;
|
idx++;
|
||||||
|
|
||||||
|
|
||||||
client.search()
|
client.search()
|
||||||
.forResource("Patient")
|
.forResource("Patient")
|
||||||
.where(Patient.BIRTHDATE.after().day(now.getValue()))
|
.where(Patient.BIRTHDATE.after().day(now.getValue()))
|
||||||
.returnBundle(Bundle.class)
|
.returnBundle(Bundle.class)
|
||||||
.execute();
|
.execute();
|
||||||
|
|
||||||
assertEquals("http://example.com/fhir/Patient?birthdate=gt"+dateString, capt.getAllValues().get(idx).getURI().toString());
|
assertEquals("http://example.com/fhir/Patient?birthdate=gt" + dateString, capt.getAllValues().get(idx).getURI().toString());
|
||||||
idx++;
|
idx++;
|
||||||
|
|
||||||
|
|
||||||
client.search()
|
client.search()
|
||||||
.forResource("Patient")
|
.forResource("Patient")
|
||||||
.where(Patient.BIRTHDATE.afterOrEquals().day(dateString))
|
.where(Patient.BIRTHDATE.afterOrEquals().day(dateString))
|
||||||
.returnBundle(Bundle.class)
|
.returnBundle(Bundle.class)
|
||||||
.execute();
|
.execute();
|
||||||
|
|
||||||
assertEquals("http://example.com/fhir/Patient?birthdate=ge"+dateString, capt.getAllValues().get(idx).getURI().toString());
|
assertEquals("http://example.com/fhir/Patient?birthdate=ge" + dateString, capt.getAllValues().get(idx).getURI().toString());
|
||||||
idx++;
|
idx++;
|
||||||
|
|
||||||
|
|
||||||
client.search()
|
client.search()
|
||||||
.forResource("Patient")
|
.forResource("Patient")
|
||||||
.where(Patient.BIRTHDATE.before().day(dateString))
|
.where(Patient.BIRTHDATE.before().day(dateString))
|
||||||
.returnBundle(Bundle.class)
|
.returnBundle(Bundle.class)
|
||||||
.execute();
|
.execute();
|
||||||
|
|
||||||
assertEquals("http://example.com/fhir/Patient?birthdate=lt"+dateString, capt.getAllValues().get(idx).getURI().toString());
|
assertEquals("http://example.com/fhir/Patient?birthdate=lt" + dateString, capt.getAllValues().get(idx).getURI().toString());
|
||||||
idx++;
|
idx++;
|
||||||
|
|
||||||
|
|
||||||
client.search()
|
client.search()
|
||||||
.forResource("Patient")
|
.forResource("Patient")
|
||||||
.where(Patient.BIRTHDATE.beforeOrEquals().day(dateString))
|
.where(Patient.BIRTHDATE.beforeOrEquals().day(dateString))
|
||||||
.returnBundle(Bundle.class)
|
.returnBundle(Bundle.class)
|
||||||
.execute();
|
.execute();
|
||||||
|
|
||||||
assertEquals("http://example.com/fhir/Patient?birthdate=le"+dateString, capt.getAllValues().get(idx).getURI().toString());
|
assertEquals("http://example.com/fhir/Patient?birthdate=le" + dateString, capt.getAllValues().get(idx).getURI().toString());
|
||||||
idx++;
|
idx++;
|
||||||
|
|
||||||
|
|
||||||
client.search()
|
client.search()
|
||||||
.forResource("Patient")
|
.forResource("Patient")
|
||||||
.where(Patient.BIRTHDATE.exactly().day(dateString))
|
.where(Patient.BIRTHDATE.exactly().day(dateString))
|
||||||
.returnBundle(Bundle.class)
|
.returnBundle(Bundle.class)
|
||||||
.execute();
|
.execute();
|
||||||
|
|
||||||
assertEquals("http://example.com/fhir/Patient?birthdate="+dateString, capt.getAllValues().get(idx).getURI().toString());
|
assertEquals("http://example.com/fhir/Patient?birthdate=" + dateString, capt.getAllValues().get(idx).getURI().toString());
|
||||||
idx++;
|
idx++;
|
||||||
|
|
||||||
|
|
||||||
client.search()
|
client.search()
|
||||||
.forResource("Patient")
|
.forResource("Patient")
|
||||||
.where(Patient.BIRTHDATE.after().second("2011-01-02T22:33:01Z"))
|
.where(Patient.BIRTHDATE.after().second("2011-01-02T22:33:01Z"))
|
||||||
|
@ -1289,7 +1253,6 @@ public class GenericClientDstu2_1Test {
|
||||||
assertEquals("http://example.com/fhir/Patient?birthdate=gt2011-01-02T22:33:01Z", UrlUtil.unescape(capt.getAllValues().get(idx).getURI().toString()));
|
assertEquals("http://example.com/fhir/Patient?birthdate=gt2011-01-02T22:33:01Z", UrlUtil.unescape(capt.getAllValues().get(idx).getURI().toString()));
|
||||||
idx++;
|
idx++;
|
||||||
|
|
||||||
|
|
||||||
client.search()
|
client.search()
|
||||||
.forResource("Patient")
|
.forResource("Patient")
|
||||||
.where(Patient.BIRTHDATE.after().second(now.getValueAsString()))
|
.where(Patient.BIRTHDATE.after().second(now.getValueAsString()))
|
||||||
|
@ -1299,7 +1262,6 @@ public class GenericClientDstu2_1Test {
|
||||||
assertEquals("http://example.com/fhir/Patient?birthdate=gt" + now.getValueAsString(), UrlUtil.unescape(capt.getAllValues().get(idx).getURI().toString()));
|
assertEquals("http://example.com/fhir/Patient?birthdate=gt" + now.getValueAsString(), UrlUtil.unescape(capt.getAllValues().get(idx).getURI().toString()));
|
||||||
idx++;
|
idx++;
|
||||||
|
|
||||||
|
|
||||||
client.search()
|
client.search()
|
||||||
.forResource("Patient")
|
.forResource("Patient")
|
||||||
.where(Patient.BIRTHDATE.after().now())
|
.where(Patient.BIRTHDATE.after().now())
|
||||||
|
@ -1332,7 +1294,6 @@ public class GenericClientDstu2_1Test {
|
||||||
IGenericClient client = ourCtx.newRestfulGenericClient("http://example.com/fhir");
|
IGenericClient client = ourCtx.newRestfulGenericClient("http://example.com/fhir");
|
||||||
int idx = 0;
|
int idx = 0;
|
||||||
|
|
||||||
|
|
||||||
client.search()
|
client.search()
|
||||||
.forResource("Observation")
|
.forResource("Observation")
|
||||||
.where(Observation.VALUE_QUANTITY.approximately().number(123).andNoUnits())
|
.where(Observation.VALUE_QUANTITY.approximately().number(123).andNoUnits())
|
||||||
|
@ -1342,7 +1303,6 @@ public class GenericClientDstu2_1Test {
|
||||||
assertEquals("http://example.com/fhir/Observation?value-quantity=ap123||", UrlUtil.unescape(capt.getAllValues().get(idx).getURI().toString()));
|
assertEquals("http://example.com/fhir/Observation?value-quantity=ap123||", UrlUtil.unescape(capt.getAllValues().get(idx).getURI().toString()));
|
||||||
idx++;
|
idx++;
|
||||||
|
|
||||||
|
|
||||||
client.search()
|
client.search()
|
||||||
.forResource("Observation")
|
.forResource("Observation")
|
||||||
.where(Observation.VALUE_QUANTITY.approximately().number("123").andUnits("CODE"))
|
.where(Observation.VALUE_QUANTITY.approximately().number("123").andUnits("CODE"))
|
||||||
|
@ -1352,7 +1312,6 @@ public class GenericClientDstu2_1Test {
|
||||||
assertEquals("http://example.com/fhir/Observation?value-quantity=ap123||CODE", UrlUtil.unescape(capt.getAllValues().get(idx).getURI().toString()));
|
assertEquals("http://example.com/fhir/Observation?value-quantity=ap123||CODE", UrlUtil.unescape(capt.getAllValues().get(idx).getURI().toString()));
|
||||||
idx++;
|
idx++;
|
||||||
|
|
||||||
|
|
||||||
client.search()
|
client.search()
|
||||||
.forResource("Observation")
|
.forResource("Observation")
|
||||||
.where(Observation.VALUE_QUANTITY.approximately().number("123").andUnits("SYSTEM", "CODE"))
|
.where(Observation.VALUE_QUANTITY.approximately().number("123").andUnits("SYSTEM", "CODE"))
|
||||||
|
@ -1362,7 +1321,6 @@ public class GenericClientDstu2_1Test {
|
||||||
assertEquals("http://example.com/fhir/Observation?value-quantity=ap123|SYSTEM|CODE", UrlUtil.unescape(capt.getAllValues().get(idx).getURI().toString()));
|
assertEquals("http://example.com/fhir/Observation?value-quantity=ap123|SYSTEM|CODE", UrlUtil.unescape(capt.getAllValues().get(idx).getURI().toString()));
|
||||||
idx++;
|
idx++;
|
||||||
|
|
||||||
|
|
||||||
client.search()
|
client.search()
|
||||||
.forResource("Observation")
|
.forResource("Observation")
|
||||||
.where(Observation.VALUE_QUANTITY.exactly().number(123).andNoUnits())
|
.where(Observation.VALUE_QUANTITY.exactly().number(123).andNoUnits())
|
||||||
|
@ -1372,7 +1330,6 @@ public class GenericClientDstu2_1Test {
|
||||||
assertEquals("http://example.com/fhir/Observation?value-quantity=123||", UrlUtil.unescape(capt.getAllValues().get(idx).getURI().toString()));
|
assertEquals("http://example.com/fhir/Observation?value-quantity=123||", UrlUtil.unescape(capt.getAllValues().get(idx).getURI().toString()));
|
||||||
idx++;
|
idx++;
|
||||||
|
|
||||||
|
|
||||||
client.search()
|
client.search()
|
||||||
.forResource("Observation")
|
.forResource("Observation")
|
||||||
.where(Observation.VALUE_QUANTITY.exactly().number("123").andUnits("CODE"))
|
.where(Observation.VALUE_QUANTITY.exactly().number("123").andUnits("CODE"))
|
||||||
|
@ -1382,7 +1339,6 @@ public class GenericClientDstu2_1Test {
|
||||||
assertEquals("http://example.com/fhir/Observation?value-quantity=123||CODE", UrlUtil.unescape(capt.getAllValues().get(idx).getURI().toString()));
|
assertEquals("http://example.com/fhir/Observation?value-quantity=123||CODE", UrlUtil.unescape(capt.getAllValues().get(idx).getURI().toString()));
|
||||||
idx++;
|
idx++;
|
||||||
|
|
||||||
|
|
||||||
client.search()
|
client.search()
|
||||||
.forResource("Observation")
|
.forResource("Observation")
|
||||||
.where(Observation.VALUE_QUANTITY.exactly().number("123").andUnits("SYSTEM", "CODE"))
|
.where(Observation.VALUE_QUANTITY.exactly().number("123").andUnits("SYSTEM", "CODE"))
|
||||||
|
@ -1392,7 +1348,6 @@ public class GenericClientDstu2_1Test {
|
||||||
assertEquals("http://example.com/fhir/Observation?value-quantity=123|SYSTEM|CODE", UrlUtil.unescape(capt.getAllValues().get(idx).getURI().toString()));
|
assertEquals("http://example.com/fhir/Observation?value-quantity=123|SYSTEM|CODE", UrlUtil.unescape(capt.getAllValues().get(idx).getURI().toString()));
|
||||||
idx++;
|
idx++;
|
||||||
|
|
||||||
|
|
||||||
client.search()
|
client.search()
|
||||||
.forResource("Observation")
|
.forResource("Observation")
|
||||||
.where(Observation.VALUE_QUANTITY.greaterThan().number(123).andNoUnits())
|
.where(Observation.VALUE_QUANTITY.greaterThan().number(123).andNoUnits())
|
||||||
|
@ -1402,7 +1357,6 @@ public class GenericClientDstu2_1Test {
|
||||||
assertEquals("http://example.com/fhir/Observation?value-quantity=gt123||", UrlUtil.unescape(capt.getAllValues().get(idx).getURI().toString()));
|
assertEquals("http://example.com/fhir/Observation?value-quantity=gt123||", UrlUtil.unescape(capt.getAllValues().get(idx).getURI().toString()));
|
||||||
idx++;
|
idx++;
|
||||||
|
|
||||||
|
|
||||||
client.search()
|
client.search()
|
||||||
.forResource("Observation")
|
.forResource("Observation")
|
||||||
.where(Observation.VALUE_QUANTITY.lessThan().number(123).andNoUnits())
|
.where(Observation.VALUE_QUANTITY.lessThan().number(123).andNoUnits())
|
||||||
|
@ -1412,7 +1366,6 @@ public class GenericClientDstu2_1Test {
|
||||||
assertEquals("http://example.com/fhir/Observation?value-quantity=lt123||", UrlUtil.unescape(capt.getAllValues().get(idx).getURI().toString()));
|
assertEquals("http://example.com/fhir/Observation?value-quantity=lt123||", UrlUtil.unescape(capt.getAllValues().get(idx).getURI().toString()));
|
||||||
idx++;
|
idx++;
|
||||||
|
|
||||||
|
|
||||||
client.search()
|
client.search()
|
||||||
.forResource("Observation")
|
.forResource("Observation")
|
||||||
.where(Observation.VALUE_QUANTITY.greaterThanOrEquals().number(123).andNoUnits())
|
.where(Observation.VALUE_QUANTITY.greaterThanOrEquals().number(123).andNoUnits())
|
||||||
|
@ -1422,7 +1375,6 @@ public class GenericClientDstu2_1Test {
|
||||||
assertEquals("http://example.com/fhir/Observation?value-quantity=ge123||", UrlUtil.unescape(capt.getAllValues().get(idx).getURI().toString()));
|
assertEquals("http://example.com/fhir/Observation?value-quantity=ge123||", UrlUtil.unescape(capt.getAllValues().get(idx).getURI().toString()));
|
||||||
idx++;
|
idx++;
|
||||||
|
|
||||||
|
|
||||||
client.search()
|
client.search()
|
||||||
.forResource("Observation")
|
.forResource("Observation")
|
||||||
.where(Observation.VALUE_QUANTITY.lessThanOrEquals().number(123).andNoUnits())
|
.where(Observation.VALUE_QUANTITY.lessThanOrEquals().number(123).andNoUnits())
|
||||||
|
@ -1432,7 +1384,6 @@ public class GenericClientDstu2_1Test {
|
||||||
assertEquals("http://example.com/fhir/Observation?value-quantity=le123||", UrlUtil.unescape(capt.getAllValues().get(idx).getURI().toString()));
|
assertEquals("http://example.com/fhir/Observation?value-quantity=le123||", UrlUtil.unescape(capt.getAllValues().get(idx).getURI().toString()));
|
||||||
idx++;
|
idx++;
|
||||||
|
|
||||||
|
|
||||||
client.search()
|
client.search()
|
||||||
.forResource("Observation")
|
.forResource("Observation")
|
||||||
.where(Observation.VALUE_QUANTITY.withPrefix(ParamPrefixEnum.GREATERTHAN).number(123).andNoUnits())
|
.where(Observation.VALUE_QUANTITY.withPrefix(ParamPrefixEnum.GREATERTHAN).number(123).andNoUnits())
|
||||||
|
@ -1462,7 +1413,6 @@ public class GenericClientDstu2_1Test {
|
||||||
IGenericClient client = ourCtx.newRestfulGenericClient("http://example.com/fhir");
|
IGenericClient client = ourCtx.newRestfulGenericClient("http://example.com/fhir");
|
||||||
int idx = 0;
|
int idx = 0;
|
||||||
|
|
||||||
|
|
||||||
client.search()
|
client.search()
|
||||||
.forResource("Patient")
|
.forResource("Patient")
|
||||||
.where(Patient.NAME.matches().value("AAA"))
|
.where(Patient.NAME.matches().value("AAA"))
|
||||||
|
@ -1472,7 +1422,6 @@ public class GenericClientDstu2_1Test {
|
||||||
assertEquals("http://example.com/fhir/Patient?name=AAA", capt.getAllValues().get(idx).getURI().toString());
|
assertEquals("http://example.com/fhir/Patient?name=AAA", capt.getAllValues().get(idx).getURI().toString());
|
||||||
idx++;
|
idx++;
|
||||||
|
|
||||||
|
|
||||||
client.search()
|
client.search()
|
||||||
.forResource("Patient")
|
.forResource("Patient")
|
||||||
.where(Patient.NAME.matches().value(new StringDt("AAA")))
|
.where(Patient.NAME.matches().value(new StringDt("AAA")))
|
||||||
|
@ -1482,7 +1431,6 @@ public class GenericClientDstu2_1Test {
|
||||||
assertEquals("http://example.com/fhir/Patient?name=AAA", capt.getAllValues().get(idx).getURI().toString());
|
assertEquals("http://example.com/fhir/Patient?name=AAA", capt.getAllValues().get(idx).getURI().toString());
|
||||||
idx++;
|
idx++;
|
||||||
|
|
||||||
|
|
||||||
client.search()
|
client.search()
|
||||||
.forResource("Patient")
|
.forResource("Patient")
|
||||||
.where(Patient.NAME.matches().values("AAA", "BBB"))
|
.where(Patient.NAME.matches().values("AAA", "BBB"))
|
||||||
|
@ -1492,7 +1440,6 @@ public class GenericClientDstu2_1Test {
|
||||||
assertEquals("http://example.com/fhir/Patient?name=AAA,BBB", UrlUtil.unescape(capt.getAllValues().get(idx).getURI().toString()));
|
assertEquals("http://example.com/fhir/Patient?name=AAA,BBB", UrlUtil.unescape(capt.getAllValues().get(idx).getURI().toString()));
|
||||||
idx++;
|
idx++;
|
||||||
|
|
||||||
|
|
||||||
client.search()
|
client.search()
|
||||||
.forResource("Patient")
|
.forResource("Patient")
|
||||||
.where(Patient.NAME.matches().values(Arrays.asList("AAA", "BBB")))
|
.where(Patient.NAME.matches().values(Arrays.asList("AAA", "BBB")))
|
||||||
|
@ -1502,7 +1449,6 @@ public class GenericClientDstu2_1Test {
|
||||||
assertEquals("http://example.com/fhir/Patient?name=AAA,BBB", UrlUtil.unescape(capt.getAllValues().get(idx).getURI().toString()));
|
assertEquals("http://example.com/fhir/Patient?name=AAA,BBB", UrlUtil.unescape(capt.getAllValues().get(idx).getURI().toString()));
|
||||||
idx++;
|
idx++;
|
||||||
|
|
||||||
|
|
||||||
client.search()
|
client.search()
|
||||||
.forResource("Patient")
|
.forResource("Patient")
|
||||||
.where(Patient.NAME.matchesExactly().value("AAA"))
|
.where(Patient.NAME.matchesExactly().value("AAA"))
|
||||||
|
@ -1512,7 +1458,6 @@ public class GenericClientDstu2_1Test {
|
||||||
assertEquals("http://example.com/fhir/Patient?name%3Aexact=AAA", capt.getAllValues().get(idx).getURI().toString());
|
assertEquals("http://example.com/fhir/Patient?name%3Aexact=AAA", capt.getAllValues().get(idx).getURI().toString());
|
||||||
idx++;
|
idx++;
|
||||||
|
|
||||||
|
|
||||||
client.search()
|
client.search()
|
||||||
.forResource("Patient")
|
.forResource("Patient")
|
||||||
.where(Patient.NAME.matchesExactly().value(new StringDt("AAA")))
|
.where(Patient.NAME.matchesExactly().value(new StringDt("AAA")))
|
||||||
|
@ -1522,7 +1467,6 @@ public class GenericClientDstu2_1Test {
|
||||||
assertEquals("http://example.com/fhir/Patient?name%3Aexact=AAA", capt.getAllValues().get(idx).getURI().toString());
|
assertEquals("http://example.com/fhir/Patient?name%3Aexact=AAA", capt.getAllValues().get(idx).getURI().toString());
|
||||||
idx++;
|
idx++;
|
||||||
|
|
||||||
|
|
||||||
client.search()
|
client.search()
|
||||||
.forResource("Patient")
|
.forResource("Patient")
|
||||||
.where(Patient.NAME.matchesExactly().values("AAA", "BBB"))
|
.where(Patient.NAME.matchesExactly().values("AAA", "BBB"))
|
||||||
|
@ -1532,7 +1476,6 @@ public class GenericClientDstu2_1Test {
|
||||||
assertEquals("http://example.com/fhir/Patient?name:exact=AAA,BBB", UrlUtil.unescape(capt.getAllValues().get(idx).getURI().toString()));
|
assertEquals("http://example.com/fhir/Patient?name:exact=AAA,BBB", UrlUtil.unescape(capt.getAllValues().get(idx).getURI().toString()));
|
||||||
idx++;
|
idx++;
|
||||||
|
|
||||||
|
|
||||||
client.search()
|
client.search()
|
||||||
.forResource("Patient")
|
.forResource("Patient")
|
||||||
.where(Patient.NAME.matchesExactly().values(Arrays.asList("AAA", "BBB")))
|
.where(Patient.NAME.matchesExactly().values(Arrays.asList("AAA", "BBB")))
|
||||||
|
@ -1562,7 +1505,6 @@ public class GenericClientDstu2_1Test {
|
||||||
IGenericClient client = ourCtx.newRestfulGenericClient("http://example.com/fhir");
|
IGenericClient client = ourCtx.newRestfulGenericClient("http://example.com/fhir");
|
||||||
int idx = 0;
|
int idx = 0;
|
||||||
|
|
||||||
|
|
||||||
client.search()
|
client.search()
|
||||||
.forResource("Device")
|
.forResource("Device")
|
||||||
.where(Device.URL.matches().value("http://foo.com"))
|
.where(Device.URL.matches().value("http://foo.com"))
|
||||||
|
@ -1573,7 +1515,6 @@ public class GenericClientDstu2_1Test {
|
||||||
assertEquals("http://example.com/fhir/Device?url=http%3A%2F%2Ffoo.com", capt.getAllValues().get(idx).getURI().toString());
|
assertEquals("http://example.com/fhir/Device?url=http%3A%2F%2Ffoo.com", capt.getAllValues().get(idx).getURI().toString());
|
||||||
idx++;
|
idx++;
|
||||||
|
|
||||||
|
|
||||||
client.search()
|
client.search()
|
||||||
.forResource("Device")
|
.forResource("Device")
|
||||||
.where(Device.URL.matches().value(new StringDt("http://foo.com")))
|
.where(Device.URL.matches().value(new StringDt("http://foo.com")))
|
||||||
|
@ -1585,17 +1526,6 @@ public class GenericClientDstu2_1Test {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testSearchForUnknownType() throws Exception {
|
|
||||||
IGenericClient client = ourCtx.newRestfulGenericClient("http://example.com/fhir");
|
|
||||||
try {
|
|
||||||
client.search(new UriDt("?aaaa"));
|
|
||||||
fail();
|
|
||||||
} catch (IllegalArgumentException e) {
|
|
||||||
assertEquals("Unable to determine the resource type from the given URI: ?aaaa", e.getMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSearchWithMultipleTokens() throws Exception {
|
public void testSearchWithMultipleTokens() throws Exception {
|
||||||
ArgumentCaptor<HttpUriRequest> capt = prepareClientForSearchResponse();
|
ArgumentCaptor<HttpUriRequest> capt = prepareClientForSearchResponse();
|
||||||
|
@ -1605,7 +1535,6 @@ public class GenericClientDstu2_1Test {
|
||||||
|
|
||||||
Collection<String> values = Arrays.asList("VAL1", "VAL2", "VAL3A,B");
|
Collection<String> values = Arrays.asList("VAL1", "VAL2", "VAL3A,B");
|
||||||
|
|
||||||
|
|
||||||
client.search()
|
client.search()
|
||||||
.forResource("Patient")
|
.forResource("Patient")
|
||||||
.where(Patient.IDENTIFIER.exactly().systemAndValues("SYS", values))
|
.where(Patient.IDENTIFIER.exactly().systemAndValues("SYS", values))
|
||||||
|
@ -1643,7 +1572,6 @@ public class GenericClientDstu2_1Test {
|
||||||
IGenericClient client = ourCtx.newRestfulGenericClient("http://example.com/fhir");
|
IGenericClient client = ourCtx.newRestfulGenericClient("http://example.com/fhir");
|
||||||
int idx = 0;
|
int idx = 0;
|
||||||
|
|
||||||
|
|
||||||
client
|
client
|
||||||
.search()
|
.search()
|
||||||
.forResource(Patient.class)
|
.forResource(Patient.class)
|
||||||
|
@ -1708,7 +1636,6 @@ public class GenericClientDstu2_1Test {
|
||||||
assertEquals("Unable to determing encoding of request (body does not appear to be valid XML or JSON)", e.getMessage());
|
assertEquals("Unable to determing encoding of request (body does not appear to be valid XML or JSON)", e.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -1923,14 +1850,12 @@ public class GenericClientDstu2_1Test {
|
||||||
IGenericClient client = ourCtx.newRestfulGenericClient("http://example.com/fhir");
|
IGenericClient client = ourCtx.newRestfulGenericClient("http://example.com/fhir");
|
||||||
client.registerInterceptor(new UserInfoInterceptor("user_id", "user_name", "app-name"));
|
client.registerInterceptor(new UserInfoInterceptor("user_id", "user_name", "app-name"));
|
||||||
|
|
||||||
|
|
||||||
Bundle resp = client
|
Bundle resp = client
|
||||||
.history()
|
.history()
|
||||||
.onType(Patient.class)
|
.onType(Patient.class)
|
||||||
.andReturnBundle(Bundle.class)
|
.andReturnBundle(Bundle.class)
|
||||||
.execute();
|
.execute();
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -2016,7 +1941,6 @@ public class GenericClientDstu2_1Test {
|
||||||
patient.getText().setDivAsString("OK!");
|
patient.getText().setDivAsString("OK!");
|
||||||
b.addEntry().setResource(patient);
|
b.addEntry().setResource(patient);
|
||||||
|
|
||||||
|
|
||||||
final String respString = p.encodeResourceToString(b);
|
final String respString = p.encodeResourceToString(b);
|
||||||
ArgumentCaptor<HttpUriRequest> capt = ArgumentCaptor.forClass(HttpUriRequest.class);
|
ArgumentCaptor<HttpUriRequest> capt = ArgumentCaptor.forClass(HttpUriRequest.class);
|
||||||
when(myHttpClient.execute(capt.capture())).thenReturn(myHttpResponse);
|
when(myHttpClient.execute(capt.capture())).thenReturn(myHttpResponse);
|
||||||
|
@ -2047,8 +1971,6 @@ public class GenericClientDstu2_1Test {
|
||||||
assertEquals(expectedUserAgent(), capt.getAllValues().get(0).getHeaders("User-Agent")[0].getValue());
|
assertEquals(expectedUserAgent(), capt.getAllValues().get(0).getHeaders("User-Agent")[0].getValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@AfterClass
|
@AfterClass
|
||||||
public static void afterClassClearContext() {
|
public static void afterClassClearContext() {
|
||||||
TestUtil.clearAllStaticFieldsForUnitTest();
|
TestUtil.clearAllStaticFieldsForUnitTest();
|
||||||
|
|
|
@ -258,11 +258,6 @@ public class Dstu2BundleFactory implements IVersionSpecificBundleFactory {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public ca.uhn.fhir.model.api.Bundle getDstu1Bundle() {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IResource getResourceBundle() {
|
public IResource getResourceBundle() {
|
||||||
return myBundle;
|
return myBundle;
|
||||||
|
|
|
@ -36,7 +36,6 @@ import com.google.common.collect.Sets;
|
||||||
import ca.uhn.fhir.context.ConfigurationException;
|
import ca.uhn.fhir.context.ConfigurationException;
|
||||||
import ca.uhn.fhir.context.FhirContext;
|
import ca.uhn.fhir.context.FhirContext;
|
||||||
import ca.uhn.fhir.model.api.*;
|
import ca.uhn.fhir.model.api.*;
|
||||||
import ca.uhn.fhir.model.api.Bundle;
|
|
||||||
import ca.uhn.fhir.model.base.composite.BaseCodingDt;
|
import ca.uhn.fhir.model.base.composite.BaseCodingDt;
|
||||||
import ca.uhn.fhir.model.dstu2.composite.*;
|
import ca.uhn.fhir.model.dstu2.composite.*;
|
||||||
import ca.uhn.fhir.model.dstu2.resource.*;
|
import ca.uhn.fhir.model.dstu2.resource.*;
|
||||||
|
@ -145,21 +144,6 @@ public class JsonParserDstu2Test {
|
||||||
assertEquals("ORG", o.getName());
|
assertEquals("ORG", o.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testEncodeBundleOldStyleContainingResourceWithUuidBase() {
|
|
||||||
Patient p = new Patient();
|
|
||||||
p.setId(IdDt.newRandomUuid());
|
|
||||||
p.addName().addFamily("PATIENT");
|
|
||||||
|
|
||||||
Bundle b = new Bundle();
|
|
||||||
b.addEntry().setResource(p);
|
|
||||||
|
|
||||||
String encoded = ourCtx.newJsonParser().setPrettyPrint(true).encodeBundleToString(b);
|
|
||||||
ourLog.info(encoded);
|
|
||||||
assertThat(encoded, stringContainsInOrder("fullUrl", p.getId().getValue(), "Patient"));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* See #308
|
* See #308
|
||||||
*/
|
*/
|
||||||
|
@ -536,43 +520,6 @@ public class JsonParserDstu2Test {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testEncodeBundleOldBundleNoText() {
|
|
||||||
|
|
||||||
Bundle b = new Bundle();
|
|
||||||
|
|
||||||
BundleEntry e = b.addEntry();
|
|
||||||
e.setResource(new Patient());
|
|
||||||
b.addCategory("scheme", "term", "label");
|
|
||||||
|
|
||||||
String val = ourCtx.newJsonParser().setPrettyPrint(false).encodeBundleToString(b);
|
|
||||||
ourLog.info(val);
|
|
||||||
|
|
||||||
assertThat(val, not(containsString("text")));
|
|
||||||
|
|
||||||
b = ourCtx.newJsonParser().parseBundle(val);
|
|
||||||
assertEquals(1, b.getEntries().size());
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Fixing #89
|
|
||||||
*/
|
|
||||||
@Test
|
|
||||||
public void testEncodeBundleWithDeletedEntry() throws ConfigurationException, DataFormatException, IOException {
|
|
||||||
Bundle b = ourCtx.newXmlParser().parseBundle(IOUtils.toString(JsonParserDstu2Test.class.getResourceAsStream("/xml-bundle.xml")));
|
|
||||||
String val = ourCtx.newJsonParser().encodeBundleToString(b);
|
|
||||||
|
|
||||||
ourLog.info(val);
|
|
||||||
|
|
||||||
//@formatter:off
|
|
||||||
assertThat(val, containsString("\"deleted\":{" +
|
|
||||||
"\"type\":\"Patient\"," +
|
|
||||||
"\"resourceId\":\"4384\"," +
|
|
||||||
"\"instant\":\"2015-01-15T11:04:43.054-05:00\"" +
|
|
||||||
"}"));
|
|
||||||
//@formatter:on
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testEncodeDoesntIncludeUuidId() {
|
public void testEncodeDoesntIncludeUuidId() {
|
||||||
|
@ -1055,28 +1002,28 @@ public class JsonParserDstu2Test {
|
||||||
public void testParseAndEncodeBundle() throws Exception {
|
public void testParseAndEncodeBundle() throws Exception {
|
||||||
String content = IOUtils.toString(JsonParserDstu2Test.class.getResourceAsStream("/bundle-example.json"));
|
String content = IOUtils.toString(JsonParserDstu2Test.class.getResourceAsStream("/bundle-example.json"));
|
||||||
|
|
||||||
Bundle parsed = ourCtx.newJsonParser().parseBundle(content);
|
Bundle parsed = ourCtx.newJsonParser().parseResource(Bundle.class, content);
|
||||||
assertEquals("Bundle/example/_history/1", parsed.getId().getValue());
|
assertEquals("Bundle/example/_history/1", parsed.getId().getValue());
|
||||||
assertEquals("1", parsed.getResourceMetadata().get(ResourceMetadataKeyEnum.VERSION));
|
assertEquals("1", parsed.getResourceMetadata().get(ResourceMetadataKeyEnum.VERSION));
|
||||||
assertEquals("1", parsed.getId().getVersionIdPart());
|
assertEquals("1", parsed.getId().getVersionIdPart());
|
||||||
assertEquals(new InstantDt("2014-08-18T01:43:30Z"), parsed.getResourceMetadata().get(ResourceMetadataKeyEnum.UPDATED));
|
assertEquals(new InstantDt("2014-08-18T01:43:30Z"), parsed.getResourceMetadata().get(ResourceMetadataKeyEnum.UPDATED));
|
||||||
assertEquals("searchset", parsed.getType().getValue());
|
assertEquals("searchset", parsed.getTypeElement().getValueAsString());
|
||||||
assertEquals(3, parsed.getTotalResults().getValue().intValue());
|
assertEquals(3, parsed.getTotalElement().getValue().intValue());
|
||||||
assertEquals("https://example.com/base/MedicationOrder?patient=347&searchId=ff15fd40-ff71-4b48-b366-09c706bed9d0&page=2", parsed.getLinkNext().getValue());
|
assertEquals("https://example.com/base/MedicationOrder?patient=347&searchId=ff15fd40-ff71-4b48-b366-09c706bed9d0&page=2", parsed.getLink("next").getUrl());
|
||||||
assertEquals("https://example.com/base/MedicationOrder?patient=347&_include=MedicationOrder.medication", parsed.getLinkSelf().getValue());
|
assertEquals("https://example.com/base/MedicationOrder?patient=347&_include=MedicationOrder.medication", parsed.getLink("self").getUrl());
|
||||||
|
|
||||||
assertEquals(2, parsed.getEntries().size());
|
assertEquals(2, parsed.getEntry().size());
|
||||||
|
|
||||||
MedicationOrder p = (MedicationOrder) parsed.getEntries().get(0).getResource();
|
MedicationOrder p = (MedicationOrder) parsed.getEntry().get(0).getResource();
|
||||||
assertEquals("Patient/347", p.getPatient().getReference().getValue());
|
assertEquals("Patient/347", p.getPatient().getReference().getValue());
|
||||||
assertEquals("2014-08-16T05:31:17Z", ResourceMetadataKeyEnum.UPDATED.get(p).getValueAsString());
|
assertEquals("2014-08-16T05:31:17Z", ResourceMetadataKeyEnum.UPDATED.get(p).getValueAsString());
|
||||||
assertEquals("http://example.com/base/MedicationOrder/3123/_history/1", p.getId().getValue());
|
assertEquals("http://example.com/base/MedicationOrder/3123/_history/1", p.getId().getValue());
|
||||||
|
|
||||||
Medication m = (Medication) parsed.getEntries().get(1).getResource();
|
Medication m = (Medication) parsed.getEntry().get(1).getResource();
|
||||||
assertEquals("http://example.com/base/Medication/example", m.getId().getValue());
|
assertEquals("http://example.com/base/Medication/example", m.getId().getValue());
|
||||||
assertSame(((ResourceReferenceDt) p.getMedication()).getResource(), m);
|
assertSame(((ResourceReferenceDt) p.getMedication()).getResource(), m);
|
||||||
|
|
||||||
String reencoded = ourCtx.newJsonParser().setPrettyPrint(true).encodeBundleToString(parsed);
|
String reencoded = ourCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(parsed);
|
||||||
ourLog.info(reencoded);
|
ourLog.info(reencoded);
|
||||||
|
|
||||||
JsonConfig cfg = new JsonConfig();
|
JsonConfig cfg = new JsonConfig();
|
||||||
|
@ -1130,7 +1077,7 @@ public class JsonParserDstu2Test {
|
||||||
assertEquals("1", parsed.getResourceMetadata().get(ResourceMetadataKeyEnum.VERSION));
|
assertEquals("1", parsed.getResourceMetadata().get(ResourceMetadataKeyEnum.VERSION));
|
||||||
assertEquals("1", parsed.getId().getVersionIdPart());
|
assertEquals("1", parsed.getId().getVersionIdPart());
|
||||||
assertEquals(new InstantDt("2014-08-18T01:43:30Z"), parsed.getResourceMetadata().get(ResourceMetadataKeyEnum.UPDATED));
|
assertEquals(new InstantDt("2014-08-18T01:43:30Z"), parsed.getResourceMetadata().get(ResourceMetadataKeyEnum.UPDATED));
|
||||||
assertEquals("searchset", parsed.getType());
|
assertEquals("searchset", parsed.getTypeElement().getValue());
|
||||||
assertEquals(3, parsed.getTotal().intValue());
|
assertEquals(3, parsed.getTotal().intValue());
|
||||||
assertEquals("https://example.com/base/MedicationOrder?patient=347&searchId=ff15fd40-ff71-4b48-b366-09c706bed9d0&page=2", parsed.getLink().get(0).getUrlElement().getValueAsString());
|
assertEquals("https://example.com/base/MedicationOrder?patient=347&searchId=ff15fd40-ff71-4b48-b366-09c706bed9d0&page=2", parsed.getLink().get(0).getUrlElement().getValueAsString());
|
||||||
assertEquals("https://example.com/base/MedicationOrder?patient=347&_include=MedicationOrder.medication", parsed.getLink().get(1).getUrlElement().getValueAsString());
|
assertEquals("https://example.com/base/MedicationOrder?patient=347&_include=MedicationOrder.medication", parsed.getLink().get(1).getUrlElement().getValueAsString());
|
||||||
|
@ -1169,25 +1116,25 @@ public class JsonParserDstu2Test {
|
||||||
public void testParseAndEncodeBundleOldStyle() throws Exception {
|
public void testParseAndEncodeBundleOldStyle() throws Exception {
|
||||||
String content = IOUtils.toString(JsonParserDstu2Test.class.getResourceAsStream("/bundle-example.json"));
|
String content = IOUtils.toString(JsonParserDstu2Test.class.getResourceAsStream("/bundle-example.json"));
|
||||||
|
|
||||||
Bundle parsed = ourCtx.newJsonParser().parseBundle(content);
|
Bundle parsed = ourCtx.newJsonParser().parseResource(Bundle.class, content);
|
||||||
|
|
||||||
assertEquals(new InstantDt("2014-08-18T01:43:30Z"), parsed.getResourceMetadata().get(ResourceMetadataKeyEnum.UPDATED));
|
assertEquals(new InstantDt("2014-08-18T01:43:30Z"), parsed.getResourceMetadata().get(ResourceMetadataKeyEnum.UPDATED));
|
||||||
assertEquals("searchset", parsed.getType().getValue());
|
assertEquals("searchset", parsed.getTypeElement().getValue());
|
||||||
assertEquals(3, parsed.getTotalResults().getValue().intValue());
|
assertEquals(3, parsed.getTotalElement().getValue().intValue());
|
||||||
|
|
||||||
assertEquals(2, parsed.getEntries().size());
|
assertEquals(2, parsed.getEntry().size());
|
||||||
|
|
||||||
MedicationOrder p = (MedicationOrder) parsed.getEntries().get(0).getResource();
|
MedicationOrder p = (MedicationOrder) parsed.getEntry().get(0).getResource();
|
||||||
assertEquals("Patient/347", p.getPatient().getReference().getValue());
|
assertEquals("Patient/347", p.getPatient().getReference().getValue());
|
||||||
assertEquals("2014-08-16T05:31:17Z", ResourceMetadataKeyEnum.UPDATED.get(p).getValueAsString());
|
assertEquals("2014-08-16T05:31:17Z", ResourceMetadataKeyEnum.UPDATED.get(p).getValueAsString());
|
||||||
assertEquals("http://example.com/base/MedicationOrder/3123/_history/1", p.getId().getValue());
|
assertEquals("http://example.com/base/MedicationOrder/3123/_history/1", p.getId().getValue());
|
||||||
|
|
||||||
Medication m = (Medication) parsed.getEntries().get(1).getResource();
|
Medication m = (Medication) parsed.getEntry().get(1).getResource();
|
||||||
assertEquals("http://example.com/base/Medication/example", m.getId().getValue());
|
assertEquals("http://example.com/base/Medication/example", m.getId().getValue());
|
||||||
assertEquals("Medication/example", ((ResourceReferenceDt) p.getMedication()).getReference().getValue());
|
assertEquals("Medication/example", ((ResourceReferenceDt) p.getMedication()).getReference().getValue());
|
||||||
assertSame(((ResourceReferenceDt) p.getMedication()).getResource(), m);
|
assertSame(((ResourceReferenceDt) p.getMedication()).getResource(), m);
|
||||||
|
|
||||||
String reencoded = ourCtx.newJsonParser().setPrettyPrint(true).encodeBundleToString(parsed);
|
String reencoded = ourCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(parsed);
|
||||||
ourLog.info(reencoded);
|
ourLog.info(reencoded);
|
||||||
|
|
||||||
JsonConfig cfg = new JsonConfig();
|
JsonConfig cfg = new JsonConfig();
|
||||||
|
@ -1211,31 +1158,13 @@ public class JsonParserDstu2Test {
|
||||||
public void testParseAndEncodeBundleResourceWithComments() throws Exception {
|
public void testParseAndEncodeBundleResourceWithComments() throws Exception {
|
||||||
String content = IOUtils.toString(JsonParserDstu2Test.class.getResourceAsStream("/bundle-transaction2.json"));
|
String content = IOUtils.toString(JsonParserDstu2Test.class.getResourceAsStream("/bundle-transaction2.json"));
|
||||||
|
|
||||||
ourCtx.newJsonParser().parseBundle(content);
|
ourCtx.newJsonParser().parseResource(Bundle.class, content);
|
||||||
|
|
||||||
ca.uhn.fhir.model.dstu2.resource.Bundle parsed = ourCtx.newJsonParser().parseResource(ca.uhn.fhir.model.dstu2.resource.Bundle.class, content);
|
ca.uhn.fhir.model.dstu2.resource.Bundle parsed = ourCtx.newJsonParser().parseResource(ca.uhn.fhir.model.dstu2.resource.Bundle.class, content);
|
||||||
|
|
||||||
// TODO: preserve comments
|
// TODO: preserve comments
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testParseAndEncodeBundleWithDeletedEntry() {
|
|
||||||
|
|
||||||
Patient res = new Patient();
|
|
||||||
res.setId(new IdDt("Patient", "111", "222"));
|
|
||||||
ResourceMetadataKeyEnum.DELETED_AT.put(res, new InstantDt("2011-01-01T12:12:22Z"));
|
|
||||||
|
|
||||||
Bundle bundle = new Bundle();
|
|
||||||
bundle.addResource(res, ourCtx, "http://foo/base");
|
|
||||||
|
|
||||||
String actual = ourCtx.newJsonParser().encodeBundleToString(bundle);
|
|
||||||
ourLog.info(actual);
|
|
||||||
|
|
||||||
String expected = "{\"resourceType\":\"Bundle\",\"entry\":[{\"deleted\":{\"type\":\"Patient\",\"resourceId\":\"111\",\"versionId\":\"222\",\"instant\":\"2011-01-01T12:12:22Z\"}}]}";
|
|
||||||
assertEquals(expected, actual);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testParseAndEncodeBundleWithUuidBase() {
|
public void testParseAndEncodeBundleWithUuidBase() {
|
||||||
//@formatter:off
|
//@formatter:off
|
||||||
|
@ -1531,38 +1460,32 @@ public class JsonParserDstu2Test {
|
||||||
" \"lastUpdated\" : \"2001-02-22T11:22:33-05:00\"\n" +
|
" \"lastUpdated\" : \"2001-02-22T11:22:33-05:00\"\n" +
|
||||||
" },\n" +
|
" },\n" +
|
||||||
" \"birthDate\" : \"2012-01-02\"\n" +
|
" \"birthDate\" : \"2012-01-02\"\n" +
|
||||||
" },\n" +
|
|
||||||
" \"search\" : {\n" +
|
|
||||||
" \"mode\" : \"match\",\n" +
|
|
||||||
" \"score\" : 0.123\n" +
|
|
||||||
" },\n" +
|
|
||||||
" \"request\" : {\n" +
|
|
||||||
" \"method\" : \"POST\",\n" +
|
|
||||||
" \"url\" : \"http://foo/Patient?identifier=value\"\n" +
|
|
||||||
" }\n" +
|
" }\n" +
|
||||||
" }]\n" +
|
" }]\n" +
|
||||||
"}";
|
"}";
|
||||||
//@formatter:on
|
//@formatter:on
|
||||||
|
|
||||||
Bundle b = ourCtx.newJsonParser().parseBundle(bundle);
|
Bundle b = ourCtx.newJsonParser().parseResource(Bundle.class, bundle);
|
||||||
assertEquals(1, b.getEntries().size());
|
assertEquals(1, b.getEntry().size());
|
||||||
|
|
||||||
Patient pt = (Patient) b.getEntries().get(0).getResource();
|
Patient pt = (Patient) b.getEntry().get(0).getResource();
|
||||||
assertEquals("http://foo/fhirBase2/Patient/1/_history/2", pt.getId().getValue());
|
assertEquals("http://foo/fhirBase2/Patient/1/_history/2", pt.getId().getValue());
|
||||||
assertEquals("2012-01-02", pt.getBirthDateElement().getValueAsString());
|
assertEquals("2012-01-02", pt.getBirthDateElement().getValueAsString());
|
||||||
assertEquals("0.123", ResourceMetadataKeyEnum.ENTRY_SCORE.get(pt).getValueAsString());
|
// assertEquals("match", ResourceMetadataKeyEnum.ENTRY_SEARCH_MODE.get(pt).getCode());
|
||||||
assertEquals("match", ResourceMetadataKeyEnum.ENTRY_SEARCH_MODE.get(pt).getCode());
|
// assertEquals("POST", ResourceMetadataKeyEnum.ENTRY_TRANSACTION_METHOD.get(pt).getCode());
|
||||||
assertEquals("POST", ResourceMetadataKeyEnum.ENTRY_TRANSACTION_METHOD.get(pt).getCode());
|
// assertEquals("http://foo/Patient?identifier=value", ResourceMetadataKeyEnum.LINK_SEARCH.get(pt));
|
||||||
assertEquals("http://foo/Patient?identifier=value", ResourceMetadataKeyEnum.LINK_SEARCH.get(pt));
|
// assertEquals("2001-02-22T11:22:33-05:00", ResourceMetadataKeyEnum.UPDATED.get(pt).getValueAsString());
|
||||||
assertEquals("2001-02-22T11:22:33-05:00", ResourceMetadataKeyEnum.UPDATED.get(pt).getValueAsString());
|
|
||||||
|
|
||||||
Bundle toBundle = new Bundle();
|
Bundle toBundle = new Bundle();
|
||||||
toBundle.getLinkBase().setValue("http://foo/fhirBase1");
|
toBundle.getTotalElement().setValue(1);
|
||||||
toBundle.getTotalResults().setValue(1);
|
// toBundle.getLinkOrCreate("base").setUrl("http://foo/fhirBase1");
|
||||||
toBundle.getLinkSelf().setValue("http://localhost:52788/Binary?_pretty=true");
|
toBundle.getLinkOrCreate("self").setUrl("http://localhost:52788/Binary?_pretty=true");
|
||||||
|
|
||||||
toBundle.addResource(pt, ourCtx, "http://foo/fhirBase1");
|
toBundle
|
||||||
String reEncoded = ourCtx.newJsonParser().setPrettyPrint(true).encodeBundleToString(toBundle);
|
.addEntry()
|
||||||
|
.setFullUrl("http://foo/fhirBase2/Patient/1/_history/2")
|
||||||
|
.setResource(pt);
|
||||||
|
String reEncoded = ourCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(toBundle);
|
||||||
|
|
||||||
JsonConfig cfg = new JsonConfig();
|
JsonConfig cfg = new JsonConfig();
|
||||||
|
|
||||||
|
@ -1692,9 +1615,9 @@ public class JsonParserDstu2Test {
|
||||||
|
|
||||||
String text = "{\"resourceType\":\"Bundle\",\"id\":null,\"base\":\"http://localhost:57931/fhir/contextDev\",\"total\":1,\"link\":[{\"relation\":\"self\",\"url\":\"http://localhost:57931/fhir/contextDev/Patient?identifier=urn%3AMultiFhirVersionTest%7CtestSubmitPatient01&_format=json\"}],\"entry\":[{\"resource\":{\"resourceType\":\"Patient\",\"id\":\"1\",\"meta\":{\"versionId\":\"1\",\"lastUpdated\":\"2014-12-20T18:41:29.706-05:00\"},\"identifier\":[{\"system\":\"urn:MultiFhirVersionTest\",\"value\":\"testSubmitPatient01\"}]}}]}";
|
String text = "{\"resourceType\":\"Bundle\",\"id\":null,\"base\":\"http://localhost:57931/fhir/contextDev\",\"total\":1,\"link\":[{\"relation\":\"self\",\"url\":\"http://localhost:57931/fhir/contextDev/Patient?identifier=urn%3AMultiFhirVersionTest%7CtestSubmitPatient01&_format=json\"}],\"entry\":[{\"resource\":{\"resourceType\":\"Patient\",\"id\":\"1\",\"meta\":{\"versionId\":\"1\",\"lastUpdated\":\"2014-12-20T18:41:29.706-05:00\"},\"identifier\":[{\"system\":\"urn:MultiFhirVersionTest\",\"value\":\"testSubmitPatient01\"}]}}]}";
|
||||||
FhirContext ctx = FhirContext.forDstu2();
|
FhirContext ctx = FhirContext.forDstu2();
|
||||||
Bundle b = ctx.newJsonParser().parseBundle(text);
|
Bundle b = ctx.newJsonParser().parseResource(Bundle.class, text);
|
||||||
|
|
||||||
IResource patient = b.getEntries().get(0).getResource();
|
IResource patient = b.getEntry().get(0).getResource();
|
||||||
assertEquals(Patient.class, patient.getClass());
|
assertEquals(Patient.class, patient.getClass());
|
||||||
|
|
||||||
assertNull(ResourceMetadataKeyEnum.TAG_LIST.get(patient));
|
assertNull(ResourceMetadataKeyEnum.TAG_LIST.get(patient));
|
||||||
|
@ -1999,29 +1922,29 @@ public class JsonParserDstu2Test {
|
||||||
patient.setPetName(new StringDt("myName"));
|
patient.setPetName(new StringDt("myName"));
|
||||||
|
|
||||||
final Bundle bundle = new Bundle();
|
final Bundle bundle = new Bundle();
|
||||||
final BundleEntry entry = new BundleEntry();
|
final Entry entry = new Entry();
|
||||||
entry.setResource(patient);
|
entry.setResource(patient);
|
||||||
bundle.addEntry(entry);
|
bundle.addEntry(entry);
|
||||||
|
|
||||||
final IParser jsonParser = ourCtx.newJsonParser();
|
final IParser jsonParser = ourCtx.newJsonParser();
|
||||||
jsonParser.setServerBaseUrl("http://www.example.com");
|
jsonParser.setServerBaseUrl("http://www.example.com");
|
||||||
|
|
||||||
final String parsedBundle = jsonParser.encodeBundleToString(bundle);
|
final String parsedBundle = jsonParser.encodeResourceToString(bundle);
|
||||||
System.out.println(parsedBundle);
|
System.out.println(parsedBundle);
|
||||||
assertEquals(expected, parsedBundle);
|
assertEquals(expected, parsedBundle);
|
||||||
|
|
||||||
// Parse with string
|
// Parse with string
|
||||||
Bundle newBundle = jsonParser.parseBundle(parsedBundle);
|
Bundle newBundle = jsonParser.parseResource(Bundle.class, parsedBundle);
|
||||||
assertNotNull(newBundle);
|
assertNotNull(newBundle);
|
||||||
assertEquals(1, newBundle.getEntries().size());
|
assertEquals(1, newBundle.getEntry().size());
|
||||||
Patient newPatient = (Patient) newBundle.getEntries().get(0).getResource();
|
Patient newPatient = (Patient) newBundle.getEntry().get(0).getResource();
|
||||||
assertEquals("myName", ((StringDt) newPatient.getUndeclaredExtensionsByUrl("http://www.example.com/petname").get(0).getValue()).getValue());
|
assertEquals("myName", ((StringDt) newPatient.getUndeclaredExtensionsByUrl("http://www.example.com/petname").get(0).getValue()).getValue());
|
||||||
|
|
||||||
// Parse with stream
|
// Parse with stream
|
||||||
newBundle = jsonParser.parseBundle(new StringReader(parsedBundle));
|
newBundle = jsonParser.parseResource(Bundle.class, new StringReader(parsedBundle));
|
||||||
assertNotNull(newBundle);
|
assertNotNull(newBundle);
|
||||||
assertEquals(1, newBundle.getEntries().size());
|
assertEquals(1, newBundle.getEntry().size());
|
||||||
newPatient = (Patient) newBundle.getEntries().get(0).getResource();
|
newPatient = (Patient) newBundle.getEntry().get(0).getResource();
|
||||||
assertEquals("myName", ((StringDt) newPatient.getUndeclaredExtensionsByUrl("http://www.example.com/petname").get(0).getValue()).getValue());
|
assertEquals("myName", ((StringDt) newPatient.getUndeclaredExtensionsByUrl("http://www.example.com/petname").get(0).getValue()).getValue());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,7 +41,6 @@ import com.google.common.collect.Sets;
|
||||||
|
|
||||||
import ca.uhn.fhir.context.FhirContext;
|
import ca.uhn.fhir.context.FhirContext;
|
||||||
import ca.uhn.fhir.model.api.*;
|
import ca.uhn.fhir.model.api.*;
|
||||||
import ca.uhn.fhir.model.api.Bundle;
|
|
||||||
import ca.uhn.fhir.model.api.annotation.Child;
|
import ca.uhn.fhir.model.api.annotation.Child;
|
||||||
import ca.uhn.fhir.model.api.annotation.ResourceDef;
|
import ca.uhn.fhir.model.api.annotation.ResourceDef;
|
||||||
import ca.uhn.fhir.model.base.composite.BaseCodingDt;
|
import ca.uhn.fhir.model.base.composite.BaseCodingDt;
|
||||||
|
@ -140,7 +139,6 @@ public class XmlParserDstu2Test {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* See #414
|
* See #414
|
||||||
*/
|
*/
|
||||||
|
@ -192,7 +190,7 @@ public class XmlParserDstu2Test {
|
||||||
assertEquals("#3", performer.getId().getValue());
|
assertEquals("#3", performer.getId().getValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected=DataFormatException.class)
|
@Test(expected = DataFormatException.class)
|
||||||
public void testContainedResourceWithNoId() throws IOException {
|
public void testContainedResourceWithNoId() throws IOException {
|
||||||
String string = IOUtils.toString(getClass().getResourceAsStream("/bundle_with_contained_with_no_id.xml"), StandardCharsets.UTF_8);
|
String string = IOUtils.toString(getClass().getResourceAsStream("/bundle_with_contained_with_no_id.xml"), StandardCharsets.UTF_8);
|
||||||
|
|
||||||
|
@ -201,7 +199,6 @@ public class XmlParserDstu2Test {
|
||||||
parser.parseResource(ca.uhn.fhir.model.dstu2.resource.Bundle.class, string);
|
parser.parseResource(ca.uhn.fhir.model.dstu2.resource.Bundle.class, string);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test()
|
@Test()
|
||||||
public void testContainedResourceWithNoIdLenient() throws IOException {
|
public void testContainedResourceWithNoIdLenient() throws IOException {
|
||||||
String string = IOUtils.toString(getClass().getResourceAsStream("/bundle_with_contained_with_no_id.xml"), StandardCharsets.UTF_8);
|
String string = IOUtils.toString(getClass().getResourceAsStream("/bundle_with_contained_with_no_id.xml"), StandardCharsets.UTF_8);
|
||||||
|
@ -211,7 +208,7 @@ public class XmlParserDstu2Test {
|
||||||
parser.parseResource(ca.uhn.fhir.model.dstu2.resource.Bundle.class, string);
|
parser.parseResource(ca.uhn.fhir.model.dstu2.resource.Bundle.class, string);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected=DataFormatException.class)
|
@Test(expected = DataFormatException.class)
|
||||||
public void testParseWithInvalidLocalRef() throws IOException {
|
public void testParseWithInvalidLocalRef() throws IOException {
|
||||||
String string = IOUtils.toString(getClass().getResourceAsStream("/bundle_with_invalid_contained_ref.xml"), StandardCharsets.UTF_8);
|
String string = IOUtils.toString(getClass().getResourceAsStream("/bundle_with_invalid_contained_ref.xml"), StandardCharsets.UTF_8);
|
||||||
|
|
||||||
|
@ -229,7 +226,6 @@ public class XmlParserDstu2Test {
|
||||||
parser.parseResource(ca.uhn.fhir.model.dstu2.resource.Bundle.class, string);
|
parser.parseResource(ca.uhn.fhir.model.dstu2.resource.Bundle.class, string);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBundleWithBinary() {
|
public void testBundleWithBinary() {
|
||||||
//@formatter:off
|
//@formatter:off
|
||||||
|
@ -254,10 +250,10 @@ public class XmlParserDstu2Test {
|
||||||
"</Bundle>";
|
"</Bundle>";
|
||||||
//@formatter:on
|
//@formatter:on
|
||||||
|
|
||||||
Bundle b = ourCtx.newXmlParser().parseBundle(bundle);
|
Bundle b = ourCtx.newXmlParser().parseResource(Bundle.class, bundle);
|
||||||
assertEquals(1, b.getEntries().size());
|
assertEquals(1, b.getEntry().size());
|
||||||
|
|
||||||
Binary bin = (Binary) b.getEntries().get(0).getResource();
|
Binary bin = (Binary) b.getEntry().get(0).getResource();
|
||||||
assertArrayEquals(new byte[] { 1, 2, 3, 4 }, bin.getContent());
|
assertArrayEquals(new byte[] { 1, 2, 3, 4 }, bin.getContent());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -299,7 +295,6 @@ public class XmlParserDstu2Test {
|
||||||
assertEquals(MarkdownDt.class, par.getParameter().get(1).getValue().getClass());
|
assertEquals(MarkdownDt.class, par.getParameter().get(1).getValue().getClass());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testContainedResourceInExtensionUndeclared() {
|
public void testContainedResourceInExtensionUndeclared() {
|
||||||
Patient p = new Patient();
|
Patient p = new Patient();
|
||||||
|
@ -359,13 +354,14 @@ public class XmlParserDstu2Test {
|
||||||
Organization org = new Organization();
|
Organization org = new Organization();
|
||||||
org.addIdentifier().setSystem("urn:system").setValue("someval");
|
org.addIdentifier().setSystem("urn:system").setValue("someval");
|
||||||
|
|
||||||
Bundle bundle = Bundle.withSingleResource(org);
|
Bundle bundle = new Bundle();
|
||||||
String str = ourCtx.newXmlParser().encodeBundleToString(bundle);
|
bundle.addEntry().setResource(org);
|
||||||
|
String str = ourCtx.newXmlParser().encodeResourceToString(bundle);
|
||||||
ourLog.info(str);
|
ourLog.info(str);
|
||||||
|
|
||||||
Bundle parsed = ourCtx.newXmlParser().parseBundle(str);
|
Bundle parsed = ourCtx.newXmlParser().parseResource(Bundle.class, str);
|
||||||
assertThat(parsed.getEntries().get(0).getResource().getId().getValue(), emptyOrNullString());
|
assertThat(parsed.getEntry().get(0).getResource().getId().getValue(), emptyOrNullString());
|
||||||
assertTrue(parsed.getEntries().get(0).getResource().getId().isEmpty());
|
assertTrue(parsed.getEntry().get(0).getResource().getId().isEmpty());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -560,7 +556,6 @@ public class XmlParserDstu2Test {
|
||||||
ourCtx = null;
|
ourCtx = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testEncodeAndParseContainedNonCustomTypes() {
|
public void testEncodeAndParseContainedNonCustomTypes() {
|
||||||
ourCtx = FhirContext.forDstu2();
|
ourCtx = FhirContext.forDstu2();
|
||||||
|
@ -1120,9 +1115,9 @@ public class XmlParserDstu2Test {
|
||||||
p.addName().addFamily("PATIENT");
|
p.addName().addFamily("PATIENT");
|
||||||
|
|
||||||
Bundle b = new Bundle();
|
Bundle b = new Bundle();
|
||||||
b.addEntry().setResource(p);
|
b.addEntry().setFullUrl(p.getId().getValue()).setResource(p);
|
||||||
|
|
||||||
String encoded = ourCtx.newXmlParser().setPrettyPrint(true).encodeBundleToString(b);
|
String encoded = ourCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(b);
|
||||||
ourLog.info(encoded);
|
ourLog.info(encoded);
|
||||||
assertThat(encoded, stringContainsInOrder("<Bundle", "<entry>", "<fullUrl value=\"" + p.getId().getValue() + "\"/>", "<Patient"));
|
assertThat(encoded, stringContainsInOrder("<Bundle", "<entry>", "<fullUrl value=\"" + p.getId().getValue() + "\"/>", "<Patient"));
|
||||||
assertThat(encoded, not(containsString("<id value=\"" + p.getId().getIdPart() + "\"/>")));
|
assertThat(encoded, not(containsString("<id value=\"" + p.getId().getIdPart() + "\"/>")));
|
||||||
|
@ -1135,10 +1130,10 @@ public class XmlParserDstu2Test {
|
||||||
p.addName().addFamily("PATIENT");
|
p.addName().addFamily("PATIENT");
|
||||||
|
|
||||||
Bundle b = new Bundle();
|
Bundle b = new Bundle();
|
||||||
b.getLinkBase().setValue("urn:uuid:");
|
b.getLinkOrCreate("base").setUrl("urn:uuid:");
|
||||||
b.addEntry().setResource(p);
|
b.addEntry().setResource(p);
|
||||||
|
|
||||||
String encoded = ourCtx.newXmlParser().setPrettyPrint(true).encodeBundleToString(b);
|
String encoded = ourCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(b);
|
||||||
ourLog.info(encoded);
|
ourLog.info(encoded);
|
||||||
// Base element has been removed!
|
// Base element has been removed!
|
||||||
assertThat(encoded, not(stringContainsInOrder("<Bundle", "<entry>", "<base value=\"", "<Patient", "<id value=")));
|
assertThat(encoded, not(stringContainsInOrder("<Bundle", "<entry>", "<base value=\"", "<Patient", "<id value=")));
|
||||||
|
@ -1912,30 +1907,30 @@ public class XmlParserDstu2Test {
|
||||||
public void testParseAndEncodeBundle() throws Exception {
|
public void testParseAndEncodeBundle() throws Exception {
|
||||||
String content = IOUtils.toString(XmlParserDstu2Test.class.getResourceAsStream("/bundle-example.xml"), StandardCharsets.UTF_8);
|
String content = IOUtils.toString(XmlParserDstu2Test.class.getResourceAsStream("/bundle-example.xml"), StandardCharsets.UTF_8);
|
||||||
|
|
||||||
Bundle parsed = ourCtx.newXmlParser().parseBundle(content);
|
Bundle parsed = ourCtx.newXmlParser().parseResource(Bundle.class, content);
|
||||||
assertEquals("Bundle/example/_history/1", parsed.getId().getValue());
|
assertEquals("Bundle/example/_history/1", parsed.getId().getValue());
|
||||||
assertEquals("1", parsed.getResourceMetadata().get(ResourceMetadataKeyEnum.VERSION));
|
assertEquals("1", parsed.getResourceMetadata().get(ResourceMetadataKeyEnum.VERSION));
|
||||||
assertEquals("1", parsed.getId().getVersionIdPart());
|
assertEquals("1", parsed.getId().getVersionIdPart());
|
||||||
assertEquals(new InstantDt("2014-08-18T01:43:30Z"), parsed.getResourceMetadata().get(ResourceMetadataKeyEnum.UPDATED));
|
assertEquals(new InstantDt("2014-08-18T01:43:30Z"), parsed.getResourceMetadata().get(ResourceMetadataKeyEnum.UPDATED));
|
||||||
assertEquals("searchset", parsed.getType().getValue());
|
assertEquals("searchset", parsed.getTypeElement().getValue());
|
||||||
assertEquals(3, parsed.getTotalResults().getValue().intValue());
|
assertEquals(3, parsed.getTotalElement().getValue().intValue());
|
||||||
assertEquals("https://example.com/base/MedicationOrder?patient=347&searchId=ff15fd40-ff71-4b48-b366-09c706bed9d0&page=2", parsed.getLinkNext().getValue());
|
assertEquals("https://example.com/base/MedicationOrder?patient=347&searchId=ff15fd40-ff71-4b48-b366-09c706bed9d0&page=2", parsed.getLink("next").getUrl());
|
||||||
assertEquals("https://example.com/base/MedicationOrder?patient=347&_include=MedicationOrder.medication", parsed.getLinkSelf().getValue());
|
assertEquals("https://example.com/base/MedicationOrder?patient=347&_include=MedicationOrder.medication", parsed.getLink("self").getUrl());
|
||||||
|
|
||||||
assertEquals(2, parsed.getEntries().size());
|
assertEquals(2, parsed.getEntry().size());
|
||||||
assertEquals("http://foo?search", parsed.getEntries().get(0).getLinkSearch().getValue());
|
// assertEquals("http://foo?search", parsed.getEntry().get(0).getLink("search").getUrl());
|
||||||
|
// assertEquals("http://example.com/base/MedicationOrder/3123/_history/1", parsed.getEntry().get(0).getLink("alternate").getUrl());
|
||||||
|
|
||||||
assertEquals("http://example.com/base/MedicationOrder/3123/_history/1", parsed.getEntries().get(0).getLinkAlternate().getValue());
|
MedicationOrder p = (MedicationOrder) parsed.getEntry().get(0).getResource();
|
||||||
MedicationOrder p = (MedicationOrder) parsed.getEntries().get(0).getResource();
|
|
||||||
assertEquals("Patient/347", p.getPatient().getReference().getValue());
|
assertEquals("Patient/347", p.getPatient().getReference().getValue());
|
||||||
assertEquals("2014-08-16T05:31:17Z", ResourceMetadataKeyEnum.UPDATED.get(p).getValueAsString());
|
assertEquals("2014-08-16T05:31:17Z", ResourceMetadataKeyEnum.UPDATED.get(p).getValueAsString());
|
||||||
assertEquals("http://example.com/base/MedicationOrder/3123/_history/1", p.getId().getValue());
|
assertEquals("http://example.com/base/MedicationOrder/3123/_history/1", p.getId().getValue());
|
||||||
|
|
||||||
Medication m = (Medication) parsed.getEntries().get(1).getResource();
|
Medication m = (Medication) parsed.getEntry().get(1).getResource();
|
||||||
assertEquals("http://example.com/base/Medication/example", m.getId().getValue());
|
assertEquals("http://example.com/base/Medication/example", m.getId().getValue());
|
||||||
assertSame(((ResourceReferenceDt) p.getMedication()).getResource(), m);
|
assertSame(((ResourceReferenceDt) p.getMedication()).getResource(), m);
|
||||||
|
|
||||||
String reencoded = ourCtx.newXmlParser().setPrettyPrint(true).encodeBundleToString(parsed);
|
String reencoded = ourCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(parsed);
|
||||||
ourLog.info(reencoded);
|
ourLog.info(reencoded);
|
||||||
|
|
||||||
Diff d = new Diff(new StringReader(content), new StringReader(reencoded));
|
Diff d = new Diff(new StringReader(content), new StringReader(reencoded));
|
||||||
|
@ -1952,7 +1947,7 @@ public class XmlParserDstu2Test {
|
||||||
assertEquals("Bundle/example/_history/1", parsed.getId().getValue());
|
assertEquals("Bundle/example/_history/1", parsed.getId().getValue());
|
||||||
assertEquals("1", parsed.getResourceMetadata().get(ResourceMetadataKeyEnum.VERSION));
|
assertEquals("1", parsed.getResourceMetadata().get(ResourceMetadataKeyEnum.VERSION));
|
||||||
assertEquals(new InstantDt("2014-08-18T01:43:30Z"), parsed.getResourceMetadata().get(ResourceMetadataKeyEnum.UPDATED));
|
assertEquals(new InstantDt("2014-08-18T01:43:30Z"), parsed.getResourceMetadata().get(ResourceMetadataKeyEnum.UPDATED));
|
||||||
assertEquals("searchset", parsed.getType());
|
assertEquals("searchset", parsed.getTypeElement().getValueAsString());
|
||||||
assertEquals(3, parsed.getTotal().intValue());
|
assertEquals(3, parsed.getTotal().intValue());
|
||||||
assertEquals("https://example.com/base/MedicationOrder?patient=347&searchId=ff15fd40-ff71-4b48-b366-09c706bed9d0&page=2", parsed.getLink().get(0).getUrlElement().getValueAsString());
|
assertEquals("https://example.com/base/MedicationOrder?patient=347&searchId=ff15fd40-ff71-4b48-b366-09c706bed9d0&page=2", parsed.getLink().get(0).getUrlElement().getValueAsString());
|
||||||
assertEquals("https://example.com/base/MedicationOrder?patient=347&_include=MedicationOrder.medication", parsed.getLink().get(1).getUrlElement().getValueAsString());
|
assertEquals("https://example.com/base/MedicationOrder?patient=347&_include=MedicationOrder.medication", parsed.getLink().get(1).getUrlElement().getValueAsString());
|
||||||
|
@ -2404,46 +2399,8 @@ public class XmlParserDstu2Test {
|
||||||
"</Bundle>";
|
"</Bundle>";
|
||||||
//@formatter:on
|
//@formatter:on
|
||||||
|
|
||||||
Bundle b = ourCtx.newXmlParser().parseBundle(bundle);
|
Bundle b = ourCtx.newXmlParser().parseResource(Bundle.class, bundle);
|
||||||
assertEquals(1, b.getEntries().size());
|
assertEquals(1, b.getEntry().size());
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testParseBundleOldWithPlaceholderIds() {
|
|
||||||
//@formatter:off
|
|
||||||
String input = "<Bundle xmlns=\"http://hl7.org/fhir\">\n" +
|
|
||||||
" <id value=\"ringholm1430996763590912\"/>\n" +
|
|
||||||
" <entry>\n" +
|
|
||||||
" <base value=\"urn:oid:\"/>\n" +
|
|
||||||
" <resource>\n" +
|
|
||||||
" <Provenance>\n" +
|
|
||||||
" <id value=\"0.1.2.3\"/>\n" +
|
|
||||||
" </Provenance>\n" +
|
|
||||||
" </resource>\n" +
|
|
||||||
" </entry>\n" +
|
|
||||||
"</Bundle>\n";
|
|
||||||
//@formatter:on
|
|
||||||
|
|
||||||
Bundle parsed = ourCtx.newXmlParser().parseBundle(input);
|
|
||||||
assertEquals("urn:oid:0.1.2.3", parsed.getEntries().get(0).getResource().getId().getValue());
|
|
||||||
|
|
||||||
//@formatter:off
|
|
||||||
input = "<Bundle xmlns=\"http://hl7.org/fhir\">\n" +
|
|
||||||
" <id value=\"ringholm1430996763590912\"/>\n" +
|
|
||||||
" <entry>\n" +
|
|
||||||
" <base value=\"urn:oid\"/>\n" + // no trailing :, invalid but we'll be nice
|
|
||||||
" <resource>\n" +
|
|
||||||
" <Provenance>\n" +
|
|
||||||
" <id value=\"0.1.2.3\"/>\n" +
|
|
||||||
" </Provenance>\n" +
|
|
||||||
" </resource>\n" +
|
|
||||||
" </entry>\n" +
|
|
||||||
"</Bundle>\n";
|
|
||||||
//@formatter:on
|
|
||||||
|
|
||||||
parsed = ourCtx.newXmlParser().parseBundle(input);
|
|
||||||
assertEquals("urn:oid:0.1.2.3", parsed.getEntries().get(0).getResource().getId().getValue());
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2452,8 +2409,6 @@ public class XmlParserDstu2Test {
|
||||||
// TODO: implement this test, make sure we handle ID and meta correctly in Binary
|
// TODO: implement this test, make sure we handle ID and meta correctly in Binary
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* See #191
|
* See #191
|
||||||
*/
|
*/
|
||||||
|
@ -2559,7 +2514,7 @@ public class XmlParserDstu2Test {
|
||||||
/**
|
/**
|
||||||
* See #366
|
* See #366
|
||||||
*/
|
*/
|
||||||
@Test(expected=DataFormatException.class)
|
@Test(expected = DataFormatException.class)
|
||||||
public void testParseInvalidBoolean() {
|
public void testParseInvalidBoolean() {
|
||||||
//@formatter:off
|
//@formatter:off
|
||||||
String resource = "<Patient xmlns=\"http://hl7.org/fhir\">\n" +
|
String resource = "<Patient xmlns=\"http://hl7.org/fhir\">\n" +
|
||||||
|
@ -2567,7 +2522,6 @@ public class XmlParserDstu2Test {
|
||||||
"</Patient>";
|
"</Patient>";
|
||||||
//@formatter:on
|
//@formatter:on
|
||||||
|
|
||||||
|
|
||||||
IParser parser = ourCtx.newXmlParser();
|
IParser parser = ourCtx.newXmlParser();
|
||||||
parser.setParserErrorHandler(new StrictErrorHandler());
|
parser.setParserErrorHandler(new StrictErrorHandler());
|
||||||
parser.parseResource(resource);
|
parser.parseResource(resource);
|
||||||
|
@ -2621,6 +2575,10 @@ public class XmlParserDstu2Test {
|
||||||
String bundle = "<Bundle xmlns=\"http://hl7.org/fhir\">\n" +
|
String bundle = "<Bundle xmlns=\"http://hl7.org/fhir\">\n" +
|
||||||
" <total value=\"1\"/>\n" +
|
" <total value=\"1\"/>\n" +
|
||||||
" <link>\n" +
|
" <link>\n" +
|
||||||
|
" <relation value=\"base\"/>\n" +
|
||||||
|
" <url value=\"http://foo/fhirBase1\"/>\n" +
|
||||||
|
" </link>\n" +
|
||||||
|
" <link>\n" +
|
||||||
" <relation value=\"self\"/>\n" +
|
" <relation value=\"self\"/>\n" +
|
||||||
" <url value=\"http://localhost:52788/Binary?_pretty=true\"/>\n" +
|
" <url value=\"http://localhost:52788/Binary?_pretty=true\"/>\n" +
|
||||||
" </link>\n" +
|
" </link>\n" +
|
||||||
|
@ -2636,37 +2594,33 @@ public class XmlParserDstu2Test {
|
||||||
" <birthDate value=\"2012-01-02\"/>\n" +
|
" <birthDate value=\"2012-01-02\"/>\n" +
|
||||||
" </Patient>\n" +
|
" </Patient>\n" +
|
||||||
" </resource>\n" +
|
" </resource>\n" +
|
||||||
" <search>\n" +
|
|
||||||
" <mode value=\"match\"/>\n" +
|
|
||||||
" <score value=\"0.123\"/>\n" +
|
|
||||||
" </search>\n" +
|
|
||||||
" <request>\n" +
|
|
||||||
" <method value=\"POST\"/>\n" +
|
|
||||||
" <url value=\"http://foo/Patient?identifier=value\"/>\n" +
|
|
||||||
" </request>\n" +
|
|
||||||
" </entry>\n" +
|
" </entry>\n" +
|
||||||
"</Bundle>";
|
"</Bundle>";
|
||||||
//@formatter:on
|
//@formatter:on
|
||||||
|
|
||||||
Bundle b = ourCtx.newXmlParser().parseBundle(bundle);
|
Bundle b = ourCtx.newXmlParser().parseResource(Bundle.class, bundle);
|
||||||
assertEquals(1, b.getEntries().size());
|
assertEquals(1, b.getEntry().size());
|
||||||
|
|
||||||
Patient pt = (Patient) b.getEntries().get(0).getResource();
|
Patient pt = (Patient) b.getEntry().get(0).getResource();
|
||||||
assertEquals("http://foo/fhirBase2/Patient/1/_history/2", pt.getId().getValue());
|
assertEquals("http://foo/fhirBase2/Patient/1/_history/2", pt.getId().getValue());
|
||||||
assertEquals("2012-01-02", pt.getBirthDateElement().getValueAsString());
|
assertEquals("2012-01-02", pt.getBirthDateElement().getValueAsString());
|
||||||
assertEquals("0.123", ResourceMetadataKeyEnum.ENTRY_SCORE.get(pt).getValueAsString());
|
// assertEquals("0.123", ResourceMetadataKeyEnum.ENTRY_SCORE.get(pt).getValueAsString());
|
||||||
assertEquals("match", ResourceMetadataKeyEnum.ENTRY_SEARCH_MODE.get(pt).getCode());
|
// assertEquals("match", ResourceMetadataKeyEnum.ENTRY_SEARCH_MODE.get(pt).getCode());
|
||||||
assertEquals("POST", ResourceMetadataKeyEnum.ENTRY_TRANSACTION_METHOD.get(pt).getCode());
|
// assertEquals("POST", ResourceMetadataKeyEnum.ENTRY_TRANSACTION_METHOD.get(pt).getCode());
|
||||||
assertEquals("http://foo/Patient?identifier=value", ResourceMetadataKeyEnum.LINK_SEARCH.get(pt));
|
// assertEquals("http://foo/Patient?identifier=value", ResourceMetadataKeyEnum.LINK_SEARCH.get(pt));
|
||||||
assertEquals("2001-02-22T11:22:33-05:00", ResourceMetadataKeyEnum.UPDATED.get(pt).getValueAsString());
|
// assertEquals("2001-02-22T11:22:33-05:00", ResourceMetadataKeyEnum.UPDATED.get(pt).getValueAsString());
|
||||||
|
|
||||||
Bundle toBundle = new Bundle();
|
Bundle toBundle = new Bundle();
|
||||||
toBundle.getLinkBase().setValue("http://foo/fhirBase1");
|
toBundle.getLinkOrCreate("base").setUrl("http://foo/fhirBase1");
|
||||||
toBundle.getTotalResults().setValue(1);
|
toBundle.getTotalElement().setValue(1);
|
||||||
toBundle.getLinkSelf().setValue("http://localhost:52788/Binary?_pretty=true");
|
toBundle.getLinkOrCreate("self").setUrl("http://localhost:52788/Binary?_pretty=true");
|
||||||
|
|
||||||
toBundle.addResource(pt, ourCtx, "http://foo/fhirBase1");
|
toBundle
|
||||||
String reEncoded = ourCtx.newXmlParser().setPrettyPrint(true).encodeBundleToString(toBundle);
|
.addEntry()
|
||||||
|
.setResource(pt)
|
||||||
|
.setFullUrl("http://foo/fhirBase2/Patient/1/_history/2");
|
||||||
|
|
||||||
|
String reEncoded = ourCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(toBundle);
|
||||||
|
|
||||||
ourLog.info(reEncoded);
|
ourLog.info(reEncoded);
|
||||||
|
|
||||||
|
@ -2811,7 +2765,7 @@ public class XmlParserDstu2Test {
|
||||||
newPatient = xmlParser.parseResource(MyPatientWithCustomUrlExtension.class, new StringReader(parsedPatient));
|
newPatient = xmlParser.parseResource(MyPatientWithCustomUrlExtension.class, new StringReader(parsedPatient));
|
||||||
assertEquals("myName", newPatient.getPetName().getValue());
|
assertEquals("myName", newPatient.getPetName().getValue());
|
||||||
|
|
||||||
//Check no NPE if base server not configure
|
// Check no NPE if base server not configure
|
||||||
newPatient = ourCtx.newXmlParser().parseResource(MyPatientWithCustomUrlExtension.class, new StringReader(parsedPatient));
|
newPatient = ourCtx.newXmlParser().parseResource(MyPatientWithCustomUrlExtension.class, new StringReader(parsedPatient));
|
||||||
assertNull("myName", newPatient.getPetName().getValue());
|
assertNull("myName", newPatient.getPetName().getValue());
|
||||||
assertEquals("myName", ((StringDt) newPatient.getUndeclaredExtensionsByUrl("http://www.example.com/petname").get(0).getValue()).getValue());
|
assertEquals("myName", ((StringDt) newPatient.getUndeclaredExtensionsByUrl("http://www.example.com/petname").get(0).getValue()).getValue());
|
||||||
|
@ -2825,29 +2779,29 @@ public class XmlParserDstu2Test {
|
||||||
patient.setPetName(new StringDt("myName"));
|
patient.setPetName(new StringDt("myName"));
|
||||||
|
|
||||||
final Bundle bundle = new Bundle();
|
final Bundle bundle = new Bundle();
|
||||||
final BundleEntry entry = new BundleEntry();
|
final Entry entry = new Entry();
|
||||||
entry.setResource(patient);
|
entry.setResource(patient);
|
||||||
bundle.addEntry(entry);
|
bundle.addEntry(entry);
|
||||||
|
|
||||||
final IParser xmlParser = ourCtx.newXmlParser();
|
final IParser xmlParser = ourCtx.newXmlParser();
|
||||||
xmlParser.setServerBaseUrl("http://www.example.com");
|
xmlParser.setServerBaseUrl("http://www.example.com");
|
||||||
|
|
||||||
final String parsedBundle = xmlParser.encodeBundleToString(bundle);
|
final String parsedBundle = xmlParser.encodeResourceToString(bundle);
|
||||||
System.out.println(parsedBundle);
|
System.out.println(parsedBundle);
|
||||||
assertEquals(expected, parsedBundle);
|
assertEquals(expected, parsedBundle);
|
||||||
|
|
||||||
// Parse with string
|
// Parse with string
|
||||||
Bundle newBundle = xmlParser.parseBundle(parsedBundle);
|
Bundle newBundle = xmlParser.parseResource(Bundle.class, parsedBundle);
|
||||||
assertNotNull(newBundle);
|
assertNotNull(newBundle);
|
||||||
assertEquals(1, newBundle.getEntries().size());
|
assertEquals(1, newBundle.getEntry().size());
|
||||||
Patient newPatient = (Patient) newBundle.getEntries().get(0).getResource();
|
Patient newPatient = (Patient) newBundle.getEntry().get(0).getResource();
|
||||||
assertEquals("myName", ((StringDt) newPatient.getUndeclaredExtensionsByUrl("http://www.example.com/petname").get(0).getValue()).getValue());
|
assertEquals("myName", ((StringDt) newPatient.getUndeclaredExtensionsByUrl("http://www.example.com/petname").get(0).getValue()).getValue());
|
||||||
|
|
||||||
// Parse with stream
|
// Parse with stream
|
||||||
newBundle = xmlParser.parseBundle(new StringReader(parsedBundle));
|
newBundle = xmlParser.parseResource(Bundle.class, new StringReader(parsedBundle));
|
||||||
assertNotNull(newBundle);
|
assertNotNull(newBundle);
|
||||||
assertEquals(1, newBundle.getEntries().size());
|
assertEquals(1, newBundle.getEntry().size());
|
||||||
newPatient = (Patient) newBundle.getEntries().get(0).getResource();
|
newPatient = (Patient) newBundle.getEntry().get(0).getResource();
|
||||||
assertEquals("myName", ((StringDt) newPatient.getUndeclaredExtensionsByUrl("http://www.example.com/petname").get(0).getValue()).getValue());
|
assertEquals("myName", ((StringDt) newPatient.getUndeclaredExtensionsByUrl("http://www.example.com/petname").get(0).getValue()).getValue());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,7 +25,7 @@ import org.mockito.ArgumentCaptor;
|
||||||
import org.mockito.internal.stubbing.defaultanswers.ReturnsDeepStubs;
|
import org.mockito.internal.stubbing.defaultanswers.ReturnsDeepStubs;
|
||||||
|
|
||||||
import ca.uhn.fhir.context.FhirContext;
|
import ca.uhn.fhir.context.FhirContext;
|
||||||
import ca.uhn.fhir.model.api.Bundle;
|
import ca.uhn.fhir.model.dstu2.resource.Bundle;
|
||||||
import ca.uhn.fhir.model.dstu2.resource.Patient;
|
import ca.uhn.fhir.model.dstu2.resource.Patient;
|
||||||
import ca.uhn.fhir.model.valueset.BundleTypeEnum;
|
import ca.uhn.fhir.model.valueset.BundleTypeEnum;
|
||||||
import ca.uhn.fhir.rest.api.Constants;
|
import ca.uhn.fhir.rest.api.Constants;
|
||||||
|
@ -62,7 +62,7 @@ public class BundleTypeDstu2Test {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testTransaction() throws Exception {
|
public void testTransaction() throws Exception {
|
||||||
String retVal = ourCtx.newXmlParser().encodeBundleToString(new Bundle());
|
String retVal = ourCtx.newXmlParser().encodeResourceToString(new Bundle());
|
||||||
|
|
||||||
ArgumentCaptor<HttpUriRequest> capt = ArgumentCaptor.forClass(HttpUriRequest.class);
|
ArgumentCaptor<HttpUriRequest> capt = ArgumentCaptor.forClass(HttpUriRequest.class);
|
||||||
when(ourHttpClient.execute(capt.capture())).thenReturn(ourHttpResponse);
|
when(ourHttpClient.execute(capt.capture())).thenReturn(ourHttpResponse);
|
||||||
|
@ -94,9 +94,9 @@ public class BundleTypeDstu2Test {
|
||||||
IGenericClient client = ctx.newRestfulGenericClient("http://54.165.58.158:8081/FHIRServer/fhir");
|
IGenericClient client = ctx.newRestfulGenericClient("http://54.165.58.158:8081/FHIRServer/fhir");
|
||||||
client.registerInterceptor(new BearerTokenAuthInterceptor("AN3uCTC5B"));
|
client.registerInterceptor(new BearerTokenAuthInterceptor("AN3uCTC5B"));
|
||||||
client.registerInterceptor(new LoggingInterceptor(true));
|
client.registerInterceptor(new LoggingInterceptor(true));
|
||||||
Bundle result = client.search().forResource(Patient.class).where(Patient.NAME.matches().value("Alice")).execute();
|
Bundle result = client.search().forResource(Patient.class).where(Patient.NAME.matches().value("Alice")).returnBundle(Bundle.class).execute();
|
||||||
|
|
||||||
System.out.println(result.getEntries().size());
|
System.out.println(result.getEntry().size());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -36,7 +36,6 @@ import org.mockito.stubbing.Answer;
|
||||||
import ca.uhn.fhir.context.ConfigurationException;
|
import ca.uhn.fhir.context.ConfigurationException;
|
||||||
import ca.uhn.fhir.context.FhirContext;
|
import ca.uhn.fhir.context.FhirContext;
|
||||||
import ca.uhn.fhir.model.api.*;
|
import ca.uhn.fhir.model.api.*;
|
||||||
import ca.uhn.fhir.model.api.Bundle;
|
|
||||||
import ca.uhn.fhir.model.dstu2.composite.IdentifierDt;
|
import ca.uhn.fhir.model.dstu2.composite.IdentifierDt;
|
||||||
import ca.uhn.fhir.model.dstu2.composite.MetaDt;
|
import ca.uhn.fhir.model.dstu2.composite.MetaDt;
|
||||||
import ca.uhn.fhir.model.dstu2.resource.*;
|
import ca.uhn.fhir.model.dstu2.resource.*;
|
||||||
|
@ -261,7 +260,7 @@ public class GenericClientDstu2Test {
|
||||||
int idx = 0;
|
int idx = 0;
|
||||||
|
|
||||||
//@formatter:off
|
//@formatter:off
|
||||||
Conformance resp = (Conformance)client.conformance();
|
Conformance resp = (Conformance)client.fetchConformance().ofType(Conformance.class).execute();
|
||||||
|
|
||||||
//@formatter:on
|
//@formatter:on
|
||||||
assertEquals("http://example.com/fhir/metadata", capt.getAllValues().get(idx).getURI().toASCIIString());
|
assertEquals("http://example.com/fhir/metadata", capt.getAllValues().get(idx).getURI().toASCIIString());
|
||||||
|
@ -381,7 +380,7 @@ public class GenericClientDstu2Test {
|
||||||
Patient p = new Patient();
|
Patient p = new Patient();
|
||||||
p.addName().addFamily("FOOFAMILY");
|
p.addName().addFamily("FOOFAMILY");
|
||||||
|
|
||||||
client.create(p);
|
client.create().resource(p).execute();
|
||||||
|
|
||||||
assertEquals(1, capt.getAllValues().get(idx).getHeaders(Constants.HEADER_CONTENT_TYPE).length);
|
assertEquals(1, capt.getAllValues().get(idx).getHeaders(Constants.HEADER_CONTENT_TYPE).length);
|
||||||
assertEquals(EncodingEnum.XML.getResourceContentType() + Constants.HEADER_SUFFIX_CT_UTF_8, capt.getAllValues().get(idx).getFirstHeader(Constants.HEADER_CONTENT_TYPE).getValue());
|
assertEquals(EncodingEnum.XML.getResourceContentType() + Constants.HEADER_SUFFIX_CT_UTF_8, capt.getAllValues().get(idx).getFirstHeader(Constants.HEADER_CONTENT_TYPE).getValue());
|
||||||
|
@ -519,68 +518,39 @@ public class GenericClientDstu2Test {
|
||||||
try {
|
try {
|
||||||
client.delete().resource(pat).execute();
|
client.delete().resource(pat).execute();
|
||||||
fail();
|
fail();
|
||||||
} catch (IllegalArgumentException e){
|
} catch (IllegalArgumentException e) {
|
||||||
assertEquals("theResource.getId() must contain a resource type and logical ID at a minimum (e.g. Patient/1234), found: 123", e.getMessage());
|
assertEquals("theResource.getId() must contain a resource type and logical ID at a minimum (e.g. Patient/1234), found: 123", e.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
client.delete().resourceById(new IdDt("123")).execute();
|
client.delete().resourceById(new IdDt("123")).execute();
|
||||||
fail();
|
fail();
|
||||||
} catch (IllegalArgumentException e){
|
} catch (IllegalArgumentException e) {
|
||||||
assertEquals("theId must contain a resource type and logical ID at a minimum (e.g. Patient/1234)found: 123", e.getMessage());
|
assertEquals("theId must contain a resource type and logical ID at a minimum (e.g. Patient/1234)found: 123", e.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
client.delete().resourceById("", "123").execute();
|
client.delete().resourceById("", "123").execute();
|
||||||
fail();
|
fail();
|
||||||
} catch (IllegalArgumentException e){
|
} catch (IllegalArgumentException e) {
|
||||||
assertEquals("theResourceType can not be blank/null", e.getMessage());
|
assertEquals("theResourceType can not be blank/null", e.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
client.delete().resourceById("Patient", "").execute();
|
client.delete().resourceById("Patient", "").execute();
|
||||||
fail();
|
fail();
|
||||||
} catch (IllegalArgumentException e){
|
} catch (IllegalArgumentException e) {
|
||||||
assertEquals("theLogicalId can not be blank/null", e.getMessage());
|
assertEquals("theLogicalId can not be blank/null", e.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
client.delete().resourceConditionalByType("InvalidType");
|
client.delete().resourceConditionalByType("InvalidType");
|
||||||
fail();
|
fail();
|
||||||
} catch (DataFormatException e){
|
} catch (DataFormatException e) {
|
||||||
assertEquals("Unknown resource name \"InvalidType\" (this name is not known in FHIR version \"DSTU2\")", e.getMessage());
|
assertEquals("Unknown resource name \"InvalidType\" (this name is not known in FHIR version \"DSTU2\")", e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
|
||||||
@Test
|
|
||||||
public void testDeleteNonFluent() throws Exception {
|
|
||||||
ArgumentCaptor<HttpUriRequest> capt = ArgumentCaptor.forClass(HttpUriRequest.class);
|
|
||||||
when(myHttpClient.execute(capt.capture())).thenReturn(myHttpResponse);
|
|
||||||
when(myHttpResponse.getStatusLine()).thenReturn(new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), Constants.STATUS_HTTP_204_NO_CONTENT, ""));
|
|
||||||
when(myHttpResponse.getEntity().getContent()).then(new Answer<ReaderInputStream>() {
|
|
||||||
@Override
|
|
||||||
public ReaderInputStream answer(InvocationOnMock theInvocation) throws Throwable {
|
|
||||||
return new ReaderInputStream(new StringReader(""), Charset.forName("UTF-8"));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
IGenericClient client = ourCtx.newRestfulGenericClient("http://example.com/fhir");
|
|
||||||
|
|
||||||
int idx = 0;
|
|
||||||
|
|
||||||
client.delete(Patient.class, new IdDt("Patient/123"));
|
|
||||||
assertEquals("DELETE", capt.getAllValues().get(idx).getMethod());
|
|
||||||
assertEquals("http://example.com/fhir/Patient/123", capt.getAllValues().get(idx).getURI().toString());
|
|
||||||
idx++;
|
|
||||||
|
|
||||||
client.delete(Patient.class, "123");
|
|
||||||
assertEquals("DELETE", capt.getAllValues().get(idx).getMethod());
|
|
||||||
assertEquals("http://example.com/fhir/Patient/123", capt.getAllValues().get(idx).getURI().toString());
|
|
||||||
idx++;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* See #322
|
* See #322
|
||||||
*/
|
*/
|
||||||
|
@ -731,7 +701,8 @@ public class GenericClientDstu2Test {
|
||||||
.since(new InstantDt("2001-01-02T11:22:33Z"))
|
.since(new InstantDt("2001-01-02T11:22:33Z"))
|
||||||
.execute();
|
.execute();
|
||||||
//@formatter:on
|
//@formatter:on
|
||||||
assertThat(capt.getAllValues().get(idx).getURI().toString(), either(equalTo("http://example.com/fhir/Patient/123/_history?_since=2001-01-02T11:22:33Z&_count=123")).or(equalTo("http://example.com/fhir/Patient/123/_history?_count=123&_since=2001-01-02T11:22:33Z")));
|
assertThat(capt.getAllValues().get(idx).getURI().toString(), either(equalTo("http://example.com/fhir/Patient/123/_history?_since=2001-01-02T11:22:33Z&_count=123"))
|
||||||
|
.or(equalTo("http://example.com/fhir/Patient/123/_history?_count=123&_since=2001-01-02T11:22:33Z")));
|
||||||
assertEquals(1, response.getEntry().size());
|
assertEquals(1, response.getEntry().size());
|
||||||
idx++;
|
idx++;
|
||||||
|
|
||||||
|
@ -794,7 +765,8 @@ public class GenericClientDstu2Test {
|
||||||
assertEquals("http://example.com/fhir/Patient/123/$meta-add", capt.getAllValues().get(idx).getURI().toASCIIString());
|
assertEquals("http://example.com/fhir/Patient/123/$meta-add", capt.getAllValues().get(idx).getURI().toASCIIString());
|
||||||
assertEquals("urn:profile:out", resp.getProfile().get(0).getValue());
|
assertEquals("urn:profile:out", resp.getProfile().get(0).getValue());
|
||||||
assertEquals("POST", capt.getAllValues().get(idx).getRequestLine().getMethod());
|
assertEquals("POST", capt.getAllValues().get(idx).getRequestLine().getMethod());
|
||||||
assertEquals("<Parameters xmlns=\"http://hl7.org/fhir\"><parameter><name value=\"meta\"/><valueMeta><profile value=\"urn:profile:in\"/></valueMeta></parameter></Parameters>", extractBody(capt, idx));
|
assertEquals("<Parameters xmlns=\"http://hl7.org/fhir\"><parameter><name value=\"meta\"/><valueMeta><profile value=\"urn:profile:in\"/></valueMeta></parameter></Parameters>",
|
||||||
|
extractBody(capt, idx));
|
||||||
idx++;
|
idx++;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1148,7 +1120,9 @@ public class GenericClientDstu2Test {
|
||||||
assertEquals(1, capt.getAllValues().get(idx).getHeaders(Constants.HEADER_CONTENT_TYPE).length);
|
assertEquals(1, capt.getAllValues().get(idx).getHeaders(Constants.HEADER_CONTENT_TYPE).length);
|
||||||
assertEquals(EncodingEnum.XML.getResourceContentType() + Constants.HEADER_SUFFIX_CT_UTF_8, capt.getAllValues().get(idx).getFirstHeader(Constants.HEADER_CONTENT_TYPE).getValue());
|
assertEquals(EncodingEnum.XML.getResourceContentType() + Constants.HEADER_SUFFIX_CT_UTF_8, capt.getAllValues().get(idx).getFirstHeader(Constants.HEADER_CONTENT_TYPE).getValue());
|
||||||
assertEquals("POST", capt.getAllValues().get(idx).getRequestLine().getMethod());
|
assertEquals("POST", capt.getAllValues().get(idx).getRequestLine().getMethod());
|
||||||
assertEquals("<Parameters xmlns=\"http://hl7.org/fhir\"><parameter><name value=\"name1\"/><valueString value=\"value1\"/></parameter><parameter><name value=\"name2\"/><valueString value=\"value1\"/></parameter></Parameters>", (extractBody(capt, idx)));
|
assertEquals(
|
||||||
|
"<Parameters xmlns=\"http://hl7.org/fhir\"><parameter><name value=\"name1\"/><valueString value=\"value1\"/></parameter><parameter><name value=\"name2\"/><valueString value=\"value1\"/></parameter></Parameters>",
|
||||||
|
(extractBody(capt, idx)));
|
||||||
idx++;
|
idx++;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -1169,7 +1143,8 @@ public class GenericClientDstu2Test {
|
||||||
assertEquals(1, capt.getAllValues().get(idx).getHeaders(Constants.HEADER_CONTENT_TYPE).length);
|
assertEquals(1, capt.getAllValues().get(idx).getHeaders(Constants.HEADER_CONTENT_TYPE).length);
|
||||||
assertEquals(EncodingEnum.XML.getResourceContentType() + Constants.HEADER_SUFFIX_CT_UTF_8, capt.getAllValues().get(idx).getFirstHeader(Constants.HEADER_CONTENT_TYPE).getValue());
|
assertEquals(EncodingEnum.XML.getResourceContentType() + Constants.HEADER_SUFFIX_CT_UTF_8, capt.getAllValues().get(idx).getFirstHeader(Constants.HEADER_CONTENT_TYPE).getValue());
|
||||||
assertEquals("POST", capt.getAllValues().get(idx).getRequestLine().getMethod());
|
assertEquals("POST", capt.getAllValues().get(idx).getRequestLine().getMethod());
|
||||||
assertEquals("<Parameters xmlns=\"http://hl7.org/fhir\"><parameter><name value=\"name1\"/><valueIdentifier><system value=\"system1\"/><value value=\"value1\"/></valueIdentifier></parameter><parameter><name value=\"name2\"/><valueString value=\"value1\"/></parameter></Parameters>",
|
assertEquals(
|
||||||
|
"<Parameters xmlns=\"http://hl7.org/fhir\"><parameter><name value=\"name1\"/><valueIdentifier><system value=\"system1\"/><value value=\"value1\"/></valueIdentifier></parameter><parameter><name value=\"name2\"/><valueString value=\"value1\"/></parameter></Parameters>",
|
||||||
(extractBody(capt, idx)));
|
(extractBody(capt, idx)));
|
||||||
idx++;
|
idx++;
|
||||||
|
|
||||||
|
@ -1709,7 +1684,8 @@ public class GenericClientDstu2Test {
|
||||||
.execute();
|
.execute();
|
||||||
//@formatter:on
|
//@formatter:on
|
||||||
|
|
||||||
assertThat(capt.getValue().getURI().toString(), either(equalTo("http://example.com/fhir/Patient/123?_elements=name%2Cidentifier")).or(equalTo("http://example.com/fhir/Patient/123?_elements=identifier%2Cname")));
|
assertThat(capt.getValue().getURI().toString(),
|
||||||
|
either(equalTo("http://example.com/fhir/Patient/123?_elements=name%2Cidentifier")).or(equalTo("http://example.com/fhir/Patient/123?_elements=identifier%2Cname")));
|
||||||
assertEquals(Patient.class, response.getClass());
|
assertEquals(Patient.class, response.getClass());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1848,21 +1824,20 @@ public class GenericClientDstu2Test {
|
||||||
|
|
||||||
IGenericClient client = ourCtx.newRestfulGenericClient("http://example.com/fhir");
|
IGenericClient client = ourCtx.newRestfulGenericClient("http://example.com/fhir");
|
||||||
|
|
||||||
//@formatter:off
|
|
||||||
Bundle response = client.search()
|
Bundle response = client.search()
|
||||||
.forResource("Patient")
|
.forResource("Patient")
|
||||||
.where(Patient.NAME.matches().value("james"))
|
.where(Patient.NAME.matches().value("james"))
|
||||||
.elementsSubset("name", "identifier")
|
.elementsSubset("name", "identifier")
|
||||||
.usingStyle(SearchStyleEnum.POST)
|
.usingStyle(SearchStyleEnum.POST)
|
||||||
|
.returnBundle(Bundle.class)
|
||||||
.execute();
|
.execute();
|
||||||
//@formatter:on
|
|
||||||
|
|
||||||
assertEquals("http://example.com/fhir/Patient/_search?_elements=identifier%2Cname", capt.getValue().getURI().toString());
|
assertEquals("http://example.com/fhir/Patient/_search?_elements=identifier%2Cname", capt.getValue().getURI().toString());
|
||||||
|
|
||||||
// assertThat(capt.getValue().getURI().toString(),
|
// assertThat(capt.getValue().getURI().toString(),
|
||||||
// either(equalTo("http://example.com/fhir/Patient?name=james&_elements=name%2Cidentifier")).or(equalTo("http://example.com/fhir/Patient?name=james&_elements=identifier%2Cname")));
|
// either(equalTo("http://example.com/fhir/Patient?name=james&_elements=name%2Cidentifier")).or(equalTo("http://example.com/fhir/Patient?name=james&_elements=identifier%2Cname")));
|
||||||
|
|
||||||
assertEquals(Patient.class, response.getEntries().get(0).getResource().getClass());
|
assertEquals(Patient.class, response.getEntry().get(0).getResource().getClass());
|
||||||
|
|
||||||
ourLog.info(Arrays.asList(capt.getValue().getAllHeaders()).toString());
|
ourLog.info(Arrays.asList(capt.getValue().getAllHeaders()).toString());
|
||||||
ourLog.info(capt.getValue().toString());
|
ourLog.info(capt.getValue().toString());
|
||||||
|
@ -1888,15 +1863,14 @@ public class GenericClientDstu2Test {
|
||||||
|
|
||||||
IGenericClient client = ourCtx.newRestfulGenericClient("http://example.com/fhir");
|
IGenericClient client = ourCtx.newRestfulGenericClient("http://example.com/fhir");
|
||||||
|
|
||||||
//@formatter:off
|
|
||||||
Bundle response = client.search()
|
Bundle response = client.search()
|
||||||
.forResource("Patient")
|
.forResource("Patient")
|
||||||
.where(Patient.NAME.matches().value("james"))
|
.where(Patient.NAME.matches().value("james"))
|
||||||
.elementsSubset("name", "identifier")
|
.elementsSubset("name", "identifier")
|
||||||
.usingStyle(SearchStyleEnum.POST)
|
.usingStyle(SearchStyleEnum.POST)
|
||||||
.encodedJson()
|
.encodedJson()
|
||||||
|
.returnBundle(Bundle.class)
|
||||||
.execute();
|
.execute();
|
||||||
//@formatter:on
|
|
||||||
|
|
||||||
assertThat(capt.getValue().getURI().toString(), containsString("http://example.com/fhir/Patient/_search?"));
|
assertThat(capt.getValue().getURI().toString(), containsString("http://example.com/fhir/Patient/_search?"));
|
||||||
assertThat(capt.getValue().getURI().toString(), containsString("_elements=identifier%2Cname"));
|
assertThat(capt.getValue().getURI().toString(), containsString("_elements=identifier%2Cname"));
|
||||||
|
@ -1905,7 +1879,7 @@ public class GenericClientDstu2Test {
|
||||||
// assertThat(capt.getValue().getURI().toString(),
|
// assertThat(capt.getValue().getURI().toString(),
|
||||||
// either(equalTo("http://example.com/fhir/Patient?name=james&_elements=name%2Cidentifier")).or(equalTo("http://example.com/fhir/Patient?name=james&_elements=identifier%2Cname")));
|
// either(equalTo("http://example.com/fhir/Patient?name=james&_elements=name%2Cidentifier")).or(equalTo("http://example.com/fhir/Patient?name=james&_elements=identifier%2Cname")));
|
||||||
|
|
||||||
assertEquals(Patient.class, response.getEntries().get(0).getResource().getClass());
|
assertEquals(Patient.class, response.getEntry().get(0).getResource().getClass());
|
||||||
|
|
||||||
ourLog.info(Arrays.asList(capt.getValue().getAllHeaders()).toString());
|
ourLog.info(Arrays.asList(capt.getValue().getAllHeaders()).toString());
|
||||||
ourLog.info(capt.getValue().toString());
|
ourLog.info(capt.getValue().toString());
|
||||||
|
@ -1930,15 +1904,14 @@ public class GenericClientDstu2Test {
|
||||||
|
|
||||||
IGenericClient client = ourCtx.newRestfulGenericClient("http://example.com/fhir");
|
IGenericClient client = ourCtx.newRestfulGenericClient("http://example.com/fhir");
|
||||||
|
|
||||||
//@formatter:off
|
|
||||||
Bundle response = client.search()
|
Bundle response = client.search()
|
||||||
.forResource("Patient")
|
.forResource("Patient")
|
||||||
.where(Patient.NAME.matches().value("james"))
|
.where(Patient.NAME.matches().value("james"))
|
||||||
|
.returnBundle(Bundle.class)
|
||||||
.execute();
|
.execute();
|
||||||
//@formatter:on
|
|
||||||
|
|
||||||
assertEquals("http://example.com/fhir/Patient?name=james", capt.getValue().getURI().toString());
|
assertEquals("http://example.com/fhir/Patient?name=james", capt.getValue().getURI().toString());
|
||||||
assertEquals(Patient.class, response.getEntries().get(0).getResource().getClass());
|
assertEquals(Patient.class, response.getEntry().get(0).getResource().getClass());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2065,16 +2038,16 @@ public class GenericClientDstu2Test {
|
||||||
|
|
||||||
IGenericClient client = ourCtx.newRestfulGenericClient("http://example.com/fhir");
|
IGenericClient client = ourCtx.newRestfulGenericClient("http://example.com/fhir");
|
||||||
|
|
||||||
//@formatter:off
|
|
||||||
Bundle response = client.search()
|
Bundle response = client.search()
|
||||||
.forResource("Patient")
|
.forResource("Patient")
|
||||||
.where(Patient.NAME.matches().value("james"))
|
.where(Patient.NAME.matches().value("james"))
|
||||||
.elementsSubset("name", "identifier")
|
.elementsSubset("name", "identifier")
|
||||||
|
.returnBundle(Bundle.class)
|
||||||
.execute();
|
.execute();
|
||||||
//@formatter:on
|
|
||||||
|
|
||||||
assertThat(capt.getValue().getURI().toString(), either(equalTo("http://example.com/fhir/Patient?name=james&_elements=name%2Cidentifier")).or(equalTo("http://example.com/fhir/Patient?name=james&_elements=identifier%2Cname")));
|
assertThat(capt.getValue().getURI().toString(),
|
||||||
assertEquals(Patient.class, response.getEntries().get(0).getResource().getClass());
|
either(equalTo("http://example.com/fhir/Patient?name=james&_elements=name%2Cidentifier")).or(equalTo("http://example.com/fhir/Patient?name=james&_elements=identifier%2Cname")));
|
||||||
|
assertEquals(Patient.class, response.getEntry().get(0).getResource().getClass());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2090,16 +2063,15 @@ public class GenericClientDstu2Test {
|
||||||
|
|
||||||
IGenericClient client = ourCtx.newRestfulGenericClient("http://example.com/fhir");
|
IGenericClient client = ourCtx.newRestfulGenericClient("http://example.com/fhir");
|
||||||
|
|
||||||
//@formatter:off
|
|
||||||
Bundle response = client.search()
|
Bundle response = client.search()
|
||||||
.forResource("Patient")
|
.forResource("Patient")
|
||||||
.where(Patient.NAME.matches().value("james"))
|
.where(Patient.NAME.matches().value("james"))
|
||||||
.lastUpdated(new DateRangeParam("2011-01-01", "2012-01-01"))
|
.lastUpdated(new DateRangeParam("2011-01-01", "2012-01-01"))
|
||||||
|
.returnBundle(Bundle.class)
|
||||||
.execute();
|
.execute();
|
||||||
//@formatter:on
|
|
||||||
|
|
||||||
assertEquals("http://example.com/fhir/Patient?name=james&_lastUpdated=ge2011-01-01&_lastUpdated=le2012-01-01", capt.getValue().getURI().toString());
|
assertEquals("http://example.com/fhir/Patient?name=james&_lastUpdated=ge2011-01-01&_lastUpdated=le2012-01-01", capt.getValue().getURI().toString());
|
||||||
assertEquals(Patient.class, response.getEntries().get(0).getResource().getClass());
|
assertEquals(Patient.class, response.getEntry().get(0).getResource().getClass());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2116,11 +2088,16 @@ public class GenericClientDstu2Test {
|
||||||
IGenericClient client = ourCtx.newRestfulGenericClient("http://example.com/fhir");
|
IGenericClient client = ourCtx.newRestfulGenericClient("http://example.com/fhir");
|
||||||
|
|
||||||
HashMap<String, List<IQueryParameterType>> params = new HashMap<String, List<IQueryParameterType>>();
|
HashMap<String, List<IQueryParameterType>> params = new HashMap<String, List<IQueryParameterType>>();
|
||||||
params.put("foo", Arrays.asList((IQueryParameterType)new DateParam("2001")));
|
params.put("foo", Arrays.asList((IQueryParameterType) new DateParam("2001")));
|
||||||
Bundle response = client.search(Patient.class, params);
|
Bundle response = client
|
||||||
|
.search()
|
||||||
|
.forResource(Patient.class)
|
||||||
|
.where(params)
|
||||||
|
.returnBundle(Bundle.class)
|
||||||
|
.execute();
|
||||||
|
|
||||||
assertEquals("http://example.com/fhir/Patient?foo=2001", capt.getValue().getURI().toString());
|
assertEquals("http://example.com/fhir/Patient?foo=2001", capt.getValue().getURI().toString());
|
||||||
assertEquals(Patient.class, response.getEntries().get(0).getResource().getClass());
|
assertEquals(Patient.class, response.getEntry().get(0).getResource().getClass());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2136,18 +2113,17 @@ public class GenericClientDstu2Test {
|
||||||
|
|
||||||
IGenericClient client = ourCtx.newRestfulGenericClient("http://example.com/fhir");
|
IGenericClient client = ourCtx.newRestfulGenericClient("http://example.com/fhir");
|
||||||
|
|
||||||
//@formatter:off
|
|
||||||
Bundle response = client.search()
|
Bundle response = client.search()
|
||||||
.forResource("Patient")
|
.forResource("Patient")
|
||||||
.withProfile("http://foo1")
|
.withProfile("http://foo1")
|
||||||
.withProfile("http://foo2")
|
.withProfile("http://foo2")
|
||||||
.withSecurity("system1", "code1")
|
.withSecurity("system1", "code1")
|
||||||
.withSecurity("system2", "code2")
|
.withSecurity("system2", "code2")
|
||||||
|
.returnBundle(Bundle.class)
|
||||||
.execute();
|
.execute();
|
||||||
//@formatter:on
|
|
||||||
|
|
||||||
assertEquals("http://example.com/fhir/Patient?_security=system1%7Ccode1&_security=system2%7Ccode2&_profile=http%3A%2F%2Ffoo1&_profile=http%3A%2F%2Ffoo2", capt.getValue().getURI().toString());
|
assertEquals("http://example.com/fhir/Patient?_security=system1%7Ccode1&_security=system2%7Ccode2&_profile=http%3A%2F%2Ffoo1&_profile=http%3A%2F%2Ffoo2", capt.getValue().getURI().toString());
|
||||||
assertEquals(Patient.class, response.getEntries().get(0).getResource().getClass());
|
assertEquals(Patient.class, response.getEntry().get(0).getResource().getClass());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2165,13 +2141,12 @@ public class GenericClientDstu2Test {
|
||||||
|
|
||||||
IGenericClient client = ourCtx.newRestfulGenericClient("http://example.com/fhir");
|
IGenericClient client = ourCtx.newRestfulGenericClient("http://example.com/fhir");
|
||||||
|
|
||||||
//@formatter:off
|
|
||||||
Bundle response = client.search()
|
Bundle response = client.search()
|
||||||
.forResource(Patient.class)
|
.forResource(Patient.class)
|
||||||
.encodedJson()
|
.encodedJson()
|
||||||
.revInclude(new Include("Provenance:target"))
|
.revInclude(new Include("Provenance:target"))
|
||||||
|
.returnBundle(Bundle.class)
|
||||||
.execute();
|
.execute();
|
||||||
//@formatter:on
|
|
||||||
|
|
||||||
assertEquals("http://example.com/fhir/Patient?_revinclude=Provenance%3Atarget&_format=json", capt.getValue().getURI().toString());
|
assertEquals("http://example.com/fhir/Patient?_revinclude=Provenance%3Atarget&_format=json", capt.getValue().getURI().toString());
|
||||||
|
|
||||||
|
@ -2189,16 +2164,15 @@ public class GenericClientDstu2Test {
|
||||||
|
|
||||||
IGenericClient client = ourCtx.newRestfulGenericClient("http://example.com/fhir");
|
IGenericClient client = ourCtx.newRestfulGenericClient("http://example.com/fhir");
|
||||||
|
|
||||||
//@formatter:off
|
|
||||||
Bundle response = client.search()
|
Bundle response = client.search()
|
||||||
.forResource("Patient")
|
.forResource("Patient")
|
||||||
.where(Patient.NAME.matches().value("james"))
|
.where(Patient.NAME.matches().value("james"))
|
||||||
.summaryMode(SummaryEnum.FALSE)
|
.summaryMode(SummaryEnum.FALSE)
|
||||||
|
.returnBundle(Bundle.class)
|
||||||
.execute();
|
.execute();
|
||||||
//@formatter:on
|
|
||||||
|
|
||||||
assertEquals("http://example.com/fhir/Patient?name=james&_summary=false", capt.getValue().getURI().toString());
|
assertEquals("http://example.com/fhir/Patient?name=james&_summary=false", capt.getValue().getURI().toString());
|
||||||
assertEquals(Patient.class, response.getEntries().get(0).getResource().getClass());
|
assertEquals(Patient.class, response.getEntry().get(0).getResource().getClass());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2540,7 +2514,9 @@ public class GenericClientDstu2Test {
|
||||||
assertEquals("http://example.com/fhir/Patient/$validate", capt.getAllValues().get(idx).getURI().toASCIIString());
|
assertEquals("http://example.com/fhir/Patient/$validate", capt.getAllValues().get(idx).getURI().toASCIIString());
|
||||||
assertEquals("POST", capt.getAllValues().get(idx).getRequestLine().getMethod());
|
assertEquals("POST", capt.getAllValues().get(idx).getRequestLine().getMethod());
|
||||||
assertEquals("application/xml+fhir", capt.getAllValues().get(idx).getFirstHeader("content-type").getValue().replaceAll(";.*", ""));
|
assertEquals("application/xml+fhir", capt.getAllValues().get(idx).getFirstHeader("content-type").getValue().replaceAll(";.*", ""));
|
||||||
assertEquals("<Parameters xmlns=\"http://hl7.org/fhir\"><parameter><name value=\"resource\"/><resource><Patient xmlns=\"http://hl7.org/fhir\"><name><given value=\"GIVEN\"/></name></Patient></resource></parameter></Parameters>", extractBody(capt, idx));
|
assertEquals(
|
||||||
|
"<Parameters xmlns=\"http://hl7.org/fhir\"><parameter><name value=\"resource\"/><resource><Patient xmlns=\"http://hl7.org/fhir\"><name><given value=\"GIVEN\"/></name></Patient></resource></parameter></Parameters>",
|
||||||
|
extractBody(capt, idx));
|
||||||
assertNotNull(response.getOperationOutcome());
|
assertNotNull(response.getOperationOutcome());
|
||||||
assertEquals("FOOBAR", toOo(response.getOperationOutcome()).getIssueFirstRep().getDiagnosticsElement().getValue());
|
assertEquals("FOOBAR", toOo(response.getOperationOutcome()).getIssueFirstRep().getDiagnosticsElement().getValue());
|
||||||
idx++;
|
idx++;
|
||||||
|
@ -2549,7 +2525,9 @@ public class GenericClientDstu2Test {
|
||||||
assertEquals("http://example.com/fhir/Patient/$validate", capt.getAllValues().get(idx).getURI().toASCIIString());
|
assertEquals("http://example.com/fhir/Patient/$validate", capt.getAllValues().get(idx).getURI().toASCIIString());
|
||||||
assertEquals("POST", capt.getAllValues().get(idx).getRequestLine().getMethod());
|
assertEquals("POST", capt.getAllValues().get(idx).getRequestLine().getMethod());
|
||||||
assertEquals("application/xml+fhir", capt.getAllValues().get(idx).getFirstHeader("content-type").getValue().replaceAll(";.*", ""));
|
assertEquals("application/xml+fhir", capt.getAllValues().get(idx).getFirstHeader("content-type").getValue().replaceAll(";.*", ""));
|
||||||
assertEquals("<Parameters xmlns=\"http://hl7.org/fhir\"><parameter><name value=\"resource\"/><resource><Patient xmlns=\"http://hl7.org/fhir\"><name><given value=\"GIVEN\"/></name></Patient></resource></parameter></Parameters>", extractBody(capt, idx));
|
assertEquals(
|
||||||
|
"<Parameters xmlns=\"http://hl7.org/fhir\"><parameter><name value=\"resource\"/><resource><Patient xmlns=\"http://hl7.org/fhir\"><name><given value=\"GIVEN\"/></name></Patient></resource></parameter></Parameters>",
|
||||||
|
extractBody(capt, idx));
|
||||||
assertNotNull(response.getOperationOutcome());
|
assertNotNull(response.getOperationOutcome());
|
||||||
assertEquals("FOOBAR", toOo(response.getOperationOutcome()).getIssueFirstRep().getDiagnosticsElement().getValue());
|
assertEquals("FOOBAR", toOo(response.getOperationOutcome()).getIssueFirstRep().getDiagnosticsElement().getValue());
|
||||||
idx++;
|
idx++;
|
||||||
|
@ -2605,7 +2583,9 @@ public class GenericClientDstu2Test {
|
||||||
|
|
||||||
assertEquals("http://example.com/fhir/Patient/$validate", capt.getAllValues().get(idx).getURI().toASCIIString());
|
assertEquals("http://example.com/fhir/Patient/$validate", capt.getAllValues().get(idx).getURI().toASCIIString());
|
||||||
assertEquals("POST", capt.getAllValues().get(idx).getRequestLine().getMethod());
|
assertEquals("POST", capt.getAllValues().get(idx).getRequestLine().getMethod());
|
||||||
assertEquals("<Parameters xmlns=\"http://hl7.org/fhir\"><parameter><name value=\"resource\"/><resource><Patient xmlns=\"http://hl7.org/fhir\"><name><given value=\"GIVEN\"/></name></Patient></resource></parameter></Parameters>", extractBody(capt, idx));
|
assertEquals(
|
||||||
|
"<Parameters xmlns=\"http://hl7.org/fhir\"><parameter><name value=\"resource\"/><resource><Patient xmlns=\"http://hl7.org/fhir\"><name><given value=\"GIVEN\"/></name></Patient></resource></parameter></Parameters>",
|
||||||
|
extractBody(capt, idx));
|
||||||
assertNotNull(response.getOperationOutcome());
|
assertNotNull(response.getOperationOutcome());
|
||||||
assertEquals("FOOBAR", toOo(response.getOperationOutcome()).getIssueFirstRep().getDiagnosticsElement().getValue());
|
assertEquals("FOOBAR", toOo(response.getOperationOutcome()).getIssueFirstRep().getDiagnosticsElement().getValue());
|
||||||
idx++;
|
idx++;
|
||||||
|
@ -2648,27 +2628,27 @@ public class GenericClientDstu2Test {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void registerInterceptor(IClientInterceptor theInterceptor) {
|
public void registerInterceptor(IClientInterceptor theInterceptor) {
|
||||||
//nothing
|
// nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setEncoding(EncodingEnum theEncoding) {
|
public void setEncoding(EncodingEnum theEncoding) {
|
||||||
//nothing
|
// nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setPrettyPrint(Boolean thePrettyPrint) {
|
public void setPrettyPrint(Boolean thePrettyPrint) {
|
||||||
//nothing
|
// nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setSummary(SummaryEnum theSummary) {
|
public void setSummary(SummaryEnum theSummary) {
|
||||||
//nothing
|
// nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void unregisterInterceptor(IClientInterceptor theInterceptor) {
|
public void unregisterInterceptor(IClientInterceptor theInterceptor) {
|
||||||
//nothing
|
// nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -16,7 +16,6 @@ import ca.uhn.fhir.model.primitive.InstantDt;
|
||||||
public class DateParamTest {
|
public class DateParamTest {
|
||||||
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(DateParamTest.class);
|
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(DateParamTest.class);
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
|
||||||
@Test
|
@Test
|
||||||
public void testConstructors() {
|
public void testConstructors() {
|
||||||
new DateParam();
|
new DateParam();
|
||||||
|
@ -98,4 +97,14 @@ public class DateParamTest {
|
||||||
assertEquals("2016-06-09T16:38:00.000-04:00", dt.getValueAsString());
|
assertEquals("2016-06-09T16:38:00.000-04:00", dt.getValueAsString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testParseLegacyPrefixes() {
|
||||||
|
assertEquals(ParamPrefixEnum.APPROXIMATE, new DateParam("ap2012").getPrefix());
|
||||||
|
assertEquals(ParamPrefixEnum.GREATERTHAN, new DateParam("gt2012").getPrefix());
|
||||||
|
assertEquals(ParamPrefixEnum.GREATERTHAN_OR_EQUALS, new DateParam("ge2012").getPrefix());
|
||||||
|
assertEquals(ParamPrefixEnum.LESSTHAN, new DateParam("lt2012").getPrefix());
|
||||||
|
assertEquals(ParamPrefixEnum.LESSTHAN_OR_EQUALS, new DateParam("le2012").getPrefix());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,9 +25,9 @@ import org.eclipse.jetty.servlet.ServletHolder;
|
||||||
import org.junit.*;
|
import org.junit.*;
|
||||||
|
|
||||||
import ca.uhn.fhir.context.FhirContext;
|
import ca.uhn.fhir.context.FhirContext;
|
||||||
import ca.uhn.fhir.model.api.Bundle;
|
|
||||||
import ca.uhn.fhir.model.api.IResource;
|
import ca.uhn.fhir.model.api.IResource;
|
||||||
import ca.uhn.fhir.model.dstu2.resource.Binary;
|
import ca.uhn.fhir.model.dstu2.resource.Binary;
|
||||||
|
import ca.uhn.fhir.model.dstu2.resource.Bundle;
|
||||||
import ca.uhn.fhir.model.primitive.IdDt;
|
import ca.uhn.fhir.model.primitive.IdDt;
|
||||||
import ca.uhn.fhir.rest.annotation.*;
|
import ca.uhn.fhir.rest.annotation.*;
|
||||||
import ca.uhn.fhir.rest.api.Constants;
|
import ca.uhn.fhir.rest.api.Constants;
|
||||||
|
@ -183,8 +183,8 @@ public class BinaryDstu2Test {
|
||||||
|
|
||||||
ourLog.info(responseContent);
|
ourLog.info(responseContent);
|
||||||
|
|
||||||
Bundle bundle = ourCtx.newJsonParser().parseBundle(responseContent);
|
Bundle bundle = ourCtx.newJsonParser().parseResource(Bundle.class, responseContent);
|
||||||
Binary bin = (Binary) bundle.getEntries().get(0).getResource();
|
Binary bin = (Binary) bundle.getEntry().get(0).getResource();
|
||||||
|
|
||||||
assertEquals("text/plain", bin.getContentType());
|
assertEquals("text/plain", bin.getContentType());
|
||||||
assertArrayEquals(new byte[] { 1, 2, 3, 4 }, bin.getContent());
|
assertArrayEquals(new byte[] { 1, 2, 3, 4 }, bin.getContent());
|
||||||
|
@ -201,8 +201,8 @@ public class BinaryDstu2Test {
|
||||||
|
|
||||||
ourLog.info(responseContent);
|
ourLog.info(responseContent);
|
||||||
|
|
||||||
Bundle bundle = ourCtx.newXmlParser().parseBundle(responseContent);
|
Bundle bundle = ourCtx.newXmlParser().parseResource(Bundle.class, responseContent);
|
||||||
Binary bin = (Binary) bundle.getEntries().get(0).getResource();
|
Binary bin = (Binary) bundle.getEntry().get(0).getResource();
|
||||||
|
|
||||||
assertEquals("text/plain", bin.getContentType());
|
assertEquals("text/plain", bin.getContentType());
|
||||||
assertArrayEquals(new byte[] { 1, 2, 3, 4 }, bin.getContent());
|
assertArrayEquals(new byte[] { 1, 2, 3, 4 }, bin.getContent());
|
||||||
|
|
|
@ -15,13 +15,11 @@ import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
|
||||||
import org.eclipse.jetty.server.Server;
|
import org.eclipse.jetty.server.Server;
|
||||||
import org.eclipse.jetty.servlet.ServletHandler;
|
import org.eclipse.jetty.servlet.ServletHandler;
|
||||||
import org.eclipse.jetty.servlet.ServletHolder;
|
import org.eclipse.jetty.servlet.ServletHolder;
|
||||||
import org.junit.AfterClass;
|
import org.junit.*;
|
||||||
import org.junit.BeforeClass;
|
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
import ca.uhn.fhir.context.FhirContext;
|
import ca.uhn.fhir.context.FhirContext;
|
||||||
import ca.uhn.fhir.model.api.Bundle;
|
|
||||||
import ca.uhn.fhir.model.api.IResource;
|
import ca.uhn.fhir.model.api.IResource;
|
||||||
|
import ca.uhn.fhir.model.dstu2.resource.Bundle;
|
||||||
import ca.uhn.fhir.model.dstu2.resource.Patient;
|
import ca.uhn.fhir.model.dstu2.resource.Patient;
|
||||||
import ca.uhn.fhir.model.valueset.BundleTypeEnum;
|
import ca.uhn.fhir.model.valueset.BundleTypeEnum;
|
||||||
import ca.uhn.fhir.narrative.DefaultThymeleafNarrativeGenerator;
|
import ca.uhn.fhir.narrative.DefaultThymeleafNarrativeGenerator;
|
||||||
|
@ -51,9 +49,9 @@ public class BundleTypeInResponseTest {
|
||||||
|
|
||||||
ourLog.info(responseContent);
|
ourLog.info(responseContent);
|
||||||
|
|
||||||
Bundle bundle = ourCtx.newXmlParser().parseBundle(responseContent);
|
Bundle bundle = ourCtx.newXmlParser().parseResource(Bundle.class, responseContent);
|
||||||
assertEquals(1, bundle.getEntries().size());
|
assertEquals(1, bundle.getEntry().size());
|
||||||
assertEquals(BundleTypeEnum.SEARCHSET, bundle.getType().getValueAsEnum());
|
assertEquals(BundleTypeEnum.SEARCHSET, bundle.getTypeElement().getValueAsEnum());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -22,7 +22,6 @@ import org.junit.Test;
|
||||||
|
|
||||||
import ca.uhn.fhir.context.FhirContext;
|
import ca.uhn.fhir.context.FhirContext;
|
||||||
import ca.uhn.fhir.context.api.BundleInclusionRule;
|
import ca.uhn.fhir.context.api.BundleInclusionRule;
|
||||||
import ca.uhn.fhir.model.api.Bundle;
|
|
||||||
import ca.uhn.fhir.model.api.IResource;
|
import ca.uhn.fhir.model.api.IResource;
|
||||||
import ca.uhn.fhir.model.api.Include;
|
import ca.uhn.fhir.model.api.Include;
|
||||||
import ca.uhn.fhir.model.api.annotation.*;
|
import ca.uhn.fhir.model.api.annotation.*;
|
||||||
|
@ -61,20 +60,21 @@ public class IncludeDstu2Test {
|
||||||
IOUtils.closeQuietly(status.getEntity().getContent());
|
IOUtils.closeQuietly(status.getEntity().getContent());
|
||||||
|
|
||||||
assertEquals(200, status.getStatusLine().getStatusCode());
|
assertEquals(200, status.getStatusLine().getStatusCode());
|
||||||
Bundle bundle = ourCtx.newXmlParser().parseBundle(responseContent);
|
Bundle bundle = ourCtx.newXmlParser().parseResource(Bundle.class, responseContent);
|
||||||
|
|
||||||
ourLog.info(responseContent);
|
ourLog.info(responseContent);
|
||||||
|
|
||||||
assertEquals(3, bundle.size());
|
assertEquals(3, bundle.getEntry().size());
|
||||||
assertEquals(new IdDt("Patient/p1"), bundle.toListOfResources().get(0).getId().toUnqualifiedVersionless());
|
|
||||||
assertEquals(new IdDt("Patient/p2"), bundle.toListOfResources().get(1).getId().toUnqualifiedVersionless());
|
|
||||||
assertEquals(new IdDt("Organization/o1"), bundle.toListOfResources().get(2).getId().toUnqualifiedVersionless());
|
|
||||||
assertEquals(BundleEntrySearchModeEnum.INCLUDE, bundle.getEntries().get(2).getSearchMode().getValueAsEnum());
|
|
||||||
|
|
||||||
Patient p1 = (Patient) bundle.toListOfResources().get(0);
|
assertEquals(new IdDt("Patient/p1"), BundleUtil.toListOfResources(ourCtx, bundle).get(0).getIdElement().toUnqualifiedVersionless());
|
||||||
|
assertEquals(new IdDt("Patient/p2"), BundleUtil.toListOfResources(ourCtx, bundle).get(1).getIdElement().toUnqualifiedVersionless());
|
||||||
|
assertEquals(new IdDt("Organization/o1"), BundleUtil.toListOfResources(ourCtx, bundle).get(2).getIdElement().toUnqualifiedVersionless());
|
||||||
|
assertEquals(BundleEntrySearchModeEnum.INCLUDE, bundle.getEntry().get(2).getSearch().getModeElement().getValueAsEnum());
|
||||||
|
|
||||||
|
Patient p1 = (Patient) BundleUtil.toListOfResources(ourCtx, bundle).get(0);
|
||||||
assertEquals(0, p1.getContained().getContainedResources().size());
|
assertEquals(0, p1.getContained().getContainedResources().size());
|
||||||
|
|
||||||
Patient p2 = (Patient) bundle.toListOfResources().get(1);
|
Patient p2 = (Patient) BundleUtil.toListOfResources(ourCtx, bundle).get(1);
|
||||||
assertEquals(0, p2.getContained().getContainedResources().size());
|
assertEquals(0, p2.getContained().getContainedResources().size());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -87,22 +87,22 @@ public class IncludeDstu2Test {
|
||||||
IOUtils.closeQuietly(status.getEntity().getContent());
|
IOUtils.closeQuietly(status.getEntity().getContent());
|
||||||
|
|
||||||
assertEquals(200, status.getStatusLine().getStatusCode());
|
assertEquals(200, status.getStatusLine().getStatusCode());
|
||||||
Bundle bundle = ourCtx.newXmlParser().parseBundle(responseContent);
|
Bundle bundle = ourCtx.newXmlParser().parseResource(Bundle.class, responseContent);
|
||||||
|
|
||||||
ourLog.info(responseContent);
|
ourLog.info(responseContent);
|
||||||
|
|
||||||
assertEquals(4, bundle.size());
|
assertEquals(4, bundle.getEntry().size());
|
||||||
assertEquals(new IdDt("Patient/p1"), bundle.toListOfResources().get(0).getId().toUnqualifiedVersionless());
|
assertEquals(new IdDt("Patient/p1"), BundleUtil.toListOfResources(ourCtx, bundle).get(0).getIdElement().toUnqualifiedVersionless());
|
||||||
assertEquals(new IdDt("Patient/p2"), bundle.toListOfResources().get(1).getId().toUnqualifiedVersionless());
|
assertEquals(new IdDt("Patient/p2"), BundleUtil.toListOfResources(ourCtx, bundle).get(1).getIdElement().toUnqualifiedVersionless());
|
||||||
assertEquals(new IdDt("Organization/o1"), bundle.toListOfResources().get(2).getId().toUnqualifiedVersionless());
|
assertEquals(new IdDt("Organization/o1"), BundleUtil.toListOfResources(ourCtx, bundle).get(2).getIdElement().toUnqualifiedVersionless());
|
||||||
assertEquals(new IdDt("Organization/o2"), bundle.toListOfResources().get(3).getId().toUnqualifiedVersionless());
|
assertEquals(new IdDt("Organization/o2"), BundleUtil.toListOfResources(ourCtx, bundle).get(3).getIdElement().toUnqualifiedVersionless());
|
||||||
assertEquals(BundleEntrySearchModeEnum.INCLUDE, bundle.getEntries().get(2).getSearchMode().getValueAsEnum());
|
assertEquals(BundleEntrySearchModeEnum.INCLUDE, bundle.getEntry().get(2).getSearch().getModeElement().getValueAsEnum());
|
||||||
assertEquals(BundleEntrySearchModeEnum.INCLUDE, bundle.getEntries().get(3).getSearchMode().getValueAsEnum());
|
assertEquals(BundleEntrySearchModeEnum.INCLUDE, bundle.getEntry().get(3).getSearch().getModeElement().getValueAsEnum());
|
||||||
|
|
||||||
Patient p1 = (Patient) bundle.toListOfResources().get(0);
|
Patient p1 = (Patient) BundleUtil.toListOfResources(ourCtx, bundle).get(0);
|
||||||
assertEquals(0, p1.getContained().getContainedResources().size());
|
assertEquals(0, p1.getContained().getContainedResources().size());
|
||||||
|
|
||||||
Patient p2 = (Patient) bundle.toListOfResources().get(1);
|
Patient p2 = (Patient) BundleUtil.toListOfResources(ourCtx, bundle).get(1);
|
||||||
assertEquals(0, p2.getContained().getContainedResources().size());
|
assertEquals(0, p2.getContained().getContainedResources().size());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -115,20 +115,20 @@ public class IncludeDstu2Test {
|
||||||
IOUtils.closeQuietly(status.getEntity().getContent());
|
IOUtils.closeQuietly(status.getEntity().getContent());
|
||||||
|
|
||||||
assertEquals(200, status.getStatusLine().getStatusCode());
|
assertEquals(200, status.getStatusLine().getStatusCode());
|
||||||
Bundle bundle = ourCtx.newXmlParser().parseBundle(responseContent);
|
Bundle bundle = ourCtx.newXmlParser().parseResource(Bundle.class, responseContent);
|
||||||
|
|
||||||
ourLog.info(responseContent);
|
ourLog.info(responseContent);
|
||||||
|
|
||||||
assertEquals(3, bundle.size());
|
assertEquals(3, bundle.getEntry().size());
|
||||||
assertEquals(new IdDt("Patient/p1"), bundle.toListOfResources().get(0).getId().toUnqualifiedVersionless());
|
assertEquals(new IdDt("Patient/p1"), BundleUtil.toListOfResources(ourCtx, bundle).get(0).getIdElement().toUnqualifiedVersionless());
|
||||||
assertEquals(new IdDt("Patient/p2"), bundle.toListOfResources().get(1).getId().toUnqualifiedVersionless());
|
assertEquals(new IdDt("Patient/p2"), BundleUtil.toListOfResources(ourCtx, bundle).get(1).getIdElement().toUnqualifiedVersionless());
|
||||||
assertEquals(new IdDt("Organization/o1"), bundle.toListOfResources().get(2).getId().toUnqualifiedVersionless());
|
assertEquals(new IdDt("Organization/o1"), BundleUtil.toListOfResources(ourCtx, bundle).get(2).getIdElement().toUnqualifiedVersionless());
|
||||||
assertEquals(BundleEntrySearchModeEnum.INCLUDE, bundle.getEntries().get(2).getSearchMode().getValueAsEnum());
|
assertEquals(BundleEntrySearchModeEnum.INCLUDE, bundle.getEntry().get(2).getSearch().getModeElement().getValueAsEnum());
|
||||||
|
|
||||||
Patient p1 = (Patient) bundle.toListOfResources().get(0);
|
Patient p1 = (Patient) BundleUtil.toListOfResources(ourCtx, bundle).get(0);
|
||||||
assertEquals(0, p1.getContained().getContainedResources().size());
|
assertEquals(0, p1.getContained().getContainedResources().size());
|
||||||
|
|
||||||
Patient p2 = (Patient) bundle.toListOfResources().get(1);
|
Patient p2 = (Patient) BundleUtil.toListOfResources(ourCtx, bundle).get(1);
|
||||||
assertEquals(0, p2.getContained().getContainedResources().size());
|
assertEquals(0, p2.getContained().getContainedResources().size());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -141,20 +141,20 @@ public class IncludeDstu2Test {
|
||||||
IOUtils.closeQuietly(status.getEntity().getContent());
|
IOUtils.closeQuietly(status.getEntity().getContent());
|
||||||
|
|
||||||
assertEquals(200, status.getStatusLine().getStatusCode());
|
assertEquals(200, status.getStatusLine().getStatusCode());
|
||||||
Bundle bundle = ourCtx.newJsonParser().parseBundle(responseContent);
|
Bundle bundle = ourCtx.newJsonParser().parseResource(Bundle.class, responseContent);
|
||||||
|
|
||||||
ourLog.info(responseContent);
|
ourLog.info(responseContent);
|
||||||
|
|
||||||
assertEquals(3, bundle.size());
|
assertEquals(3, bundle.getEntry().size());
|
||||||
assertEquals(new IdDt("Patient/p1"), bundle.toListOfResources().get(0).getId().toUnqualifiedVersionless());
|
assertEquals(new IdDt("Patient/p1"), BundleUtil.toListOfResources(ourCtx, bundle).get(0).getIdElement().toUnqualifiedVersionless());
|
||||||
assertEquals(new IdDt("Patient/p2"), bundle.toListOfResources().get(1).getId().toUnqualifiedVersionless());
|
assertEquals(new IdDt("Patient/p2"), BundleUtil.toListOfResources(ourCtx, bundle).get(1).getIdElement().toUnqualifiedVersionless());
|
||||||
assertEquals(new IdDt("Organization/o1"), bundle.toListOfResources().get(2).getId().toUnqualifiedVersionless());
|
assertEquals(new IdDt("Organization/o1"), BundleUtil.toListOfResources(ourCtx, bundle).get(2).getIdElement().toUnqualifiedVersionless());
|
||||||
assertEquals(BundleEntrySearchModeEnum.INCLUDE, bundle.getEntries().get(2).getSearchMode().getValueAsEnum());
|
assertEquals(BundleEntrySearchModeEnum.INCLUDE, bundle.getEntry().get(2).getSearch().getModeElement().getValueAsEnum());
|
||||||
|
|
||||||
Patient p1 = (Patient) bundle.toListOfResources().get(0);
|
Patient p1 = (Patient) BundleUtil.toListOfResources(ourCtx, bundle).get(0);
|
||||||
assertEquals(0, p1.getContained().getContainedResources().size());
|
assertEquals(0, p1.getContained().getContainedResources().size());
|
||||||
|
|
||||||
Patient p2 = (Patient) bundle.toListOfResources().get(1);
|
Patient p2 = (Patient) BundleUtil.toListOfResources(ourCtx, bundle).get(1);
|
||||||
assertEquals(0, p2.getContained().getContainedResources().size());
|
assertEquals(0, p2.getContained().getContainedResources().size());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -169,8 +169,8 @@ public class IncludeDstu2Test {
|
||||||
ourLog.info(responseContent);
|
ourLog.info(responseContent);
|
||||||
|
|
||||||
assertEquals(200, status.getStatusLine().getStatusCode());
|
assertEquals(200, status.getStatusLine().getStatusCode());
|
||||||
Bundle bundle = ourCtx.newXmlParser().parseBundle(responseContent);
|
Bundle bundle = ourCtx.newXmlParser().parseResource(Bundle.class, responseContent);
|
||||||
assertEquals(4, bundle.size());
|
assertEquals(4, bundle.getEntry().size());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -181,10 +181,10 @@ public class IncludeDstu2Test {
|
||||||
IOUtils.closeQuietly(status.getEntity().getContent());
|
IOUtils.closeQuietly(status.getEntity().getContent());
|
||||||
|
|
||||||
assertEquals(200, status.getStatusLine().getStatusCode());
|
assertEquals(200, status.getStatusLine().getStatusCode());
|
||||||
Bundle bundle = ourCtx.newXmlParser().parseBundle(responseContent);
|
Bundle bundle = ourCtx.newXmlParser().parseResource(Bundle.class, responseContent);
|
||||||
assertEquals(1, bundle.size());
|
assertEquals(1, bundle.getEntry().size());
|
||||||
|
|
||||||
Patient p = bundle.getResources(Patient.class).get(0);
|
Patient p = BundleUtil.toListOfResourcesOfType(ourCtx, bundle, Patient.class).get(0);
|
||||||
assertEquals(0, p.getName().size());
|
assertEquals(0, p.getName().size());
|
||||||
assertEquals("Hello", p.getId().getIdPart());
|
assertEquals("Hello", p.getId().getIdPart());
|
||||||
}
|
}
|
||||||
|
@ -200,10 +200,10 @@ public class IncludeDstu2Test {
|
||||||
|
|
||||||
ourLog.info(responseContent);
|
ourLog.info(responseContent);
|
||||||
|
|
||||||
Bundle bundle = ourCtx.newJsonParser().parseBundle(responseContent);
|
Bundle bundle = ourCtx.newJsonParser().parseResource(Bundle.class, responseContent);
|
||||||
assertEquals(1, bundle.size());
|
assertEquals(1, bundle.getEntry().size());
|
||||||
|
|
||||||
Patient p = bundle.getResources(Patient.class).get(0);
|
Patient p = BundleUtil.toListOfResourcesOfType(ourCtx, bundle, Patient.class).get(0);
|
||||||
assertEquals(1, p.getName().size());
|
assertEquals(1, p.getName().size());
|
||||||
assertEquals("Hello", p.getId().getIdPart());
|
assertEquals("Hello", p.getId().getIdPart());
|
||||||
assertEquals("foo", p.getName().get(0).getFamilyFirstRep().getValue());
|
assertEquals("foo", p.getName().get(0).getFamilyFirstRep().getValue());
|
||||||
|
@ -220,10 +220,10 @@ public class IncludeDstu2Test {
|
||||||
|
|
||||||
ourLog.info(responseContent);
|
ourLog.info(responseContent);
|
||||||
|
|
||||||
Bundle bundle = ourCtx.newXmlParser().parseBundle(responseContent);
|
Bundle bundle = ourCtx.newXmlParser().parseResource(Bundle.class, responseContent);
|
||||||
assertEquals(1, bundle.size());
|
assertEquals(1, bundle.getEntry().size());
|
||||||
|
|
||||||
Patient p = bundle.getResources(Patient.class).get(0);
|
Patient p = BundleUtil.toListOfResourcesOfType(ourCtx, bundle, Patient.class).get(0);
|
||||||
assertEquals(1, p.getName().size());
|
assertEquals(1, p.getName().size());
|
||||||
assertEquals("Hello", p.getId().getIdPart());
|
assertEquals("Hello", p.getId().getIdPart());
|
||||||
assertEquals("foo", p.getName().get(0).getFamilyFirstRep().getValue());
|
assertEquals("foo", p.getName().get(0).getFamilyFirstRep().getValue());
|
||||||
|
@ -239,10 +239,10 @@ public class IncludeDstu2Test {
|
||||||
ourLog.info(responseContent);
|
ourLog.info(responseContent);
|
||||||
|
|
||||||
assertEquals(200, status.getStatusLine().getStatusCode());
|
assertEquals(200, status.getStatusLine().getStatusCode());
|
||||||
Bundle bundle = ourCtx.newXmlParser().parseBundle(responseContent);
|
Bundle bundle = ourCtx.newXmlParser().parseResource(Bundle.class, responseContent);
|
||||||
assertEquals(1, bundle.size());
|
assertEquals(1, bundle.getEntry().size());
|
||||||
|
|
||||||
Patient p = bundle.getResources(Patient.class).get(0);
|
Patient p = BundleUtil.toListOfResourcesOfType(ourCtx, bundle, Patient.class).get(0);
|
||||||
assertEquals(2, p.getName().size());
|
assertEquals(2, p.getName().size());
|
||||||
assertEquals("Hello", p.getId().getIdPart());
|
assertEquals("Hello", p.getId().getIdPart());
|
||||||
|
|
||||||
|
|
|
@ -12,13 +12,7 @@ import org.junit.Test;
|
||||||
|
|
||||||
import ca.uhn.fhir.context.FhirContext;
|
import ca.uhn.fhir.context.FhirContext;
|
||||||
import ca.uhn.fhir.model.dstu2.resource.Patient;
|
import ca.uhn.fhir.model.dstu2.resource.Patient;
|
||||||
import ca.uhn.fhir.model.primitive.StringDt;
|
import ca.uhn.fhir.rest.annotation.*;
|
||||||
import ca.uhn.fhir.rest.annotation.ConditionalUrlParam;
|
|
||||||
import ca.uhn.fhir.rest.annotation.Operation;
|
|
||||||
import ca.uhn.fhir.rest.annotation.OperationParam;
|
|
||||||
import ca.uhn.fhir.rest.annotation.ResourceParam;
|
|
||||||
import ca.uhn.fhir.rest.annotation.Update;
|
|
||||||
import ca.uhn.fhir.rest.annotation.Validate;
|
|
||||||
import ca.uhn.fhir.rest.api.MethodOutcome;
|
import ca.uhn.fhir.rest.api.MethodOutcome;
|
||||||
import ca.uhn.fhir.rest.param.TokenParam;
|
import ca.uhn.fhir.rest.param.TokenParam;
|
||||||
import ca.uhn.fhir.util.TestUtil;
|
import ca.uhn.fhir.util.TestUtil;
|
||||||
|
@ -32,22 +26,6 @@ public class ServerInvalidDefinitionDstu2Test {
|
||||||
TestUtil.clearAllStaticFieldsForUnitTest();
|
TestUtil.clearAllStaticFieldsForUnitTest();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testOperationReturningOldBundleProvider() {
|
|
||||||
RestfulServer srv = new RestfulServer(ourCtx);
|
|
||||||
srv.setFhirContext(ourCtx);
|
|
||||||
srv.setResourceProviders(new OperationReturningOldBundleProvider());
|
|
||||||
|
|
||||||
try {
|
|
||||||
srv.init();
|
|
||||||
fail();
|
|
||||||
} catch (ServletException e) {
|
|
||||||
assertThat(e.getCause().toString(), StringContains.containsString("ConfigurationException"));
|
|
||||||
assertThat(e.getCause().toString(), StringContains.containsString("Can not return a DSTU1 bundle"));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testWrongConditionalUrlType() {
|
public void testWrongConditionalUrlType() {
|
||||||
RestfulServer srv = new RestfulServer(ourCtx);
|
RestfulServer srv = new RestfulServer(ourCtx);
|
||||||
|
@ -59,7 +37,8 @@ public class ServerInvalidDefinitionDstu2Test {
|
||||||
fail();
|
fail();
|
||||||
} catch (ServletException e) {
|
} catch (ServletException e) {
|
||||||
assertThat(e.getCause().toString(), StringContains.containsString("ConfigurationException"));
|
assertThat(e.getCause().toString(), StringContains.containsString("ConfigurationException"));
|
||||||
assertThat(e.getCause().toString(), StringContains.containsString("Parameters annotated with @ConditionalUrlParam must be of type String, found incorrect parameteter in method \"public ca.uhn.fhir.rest.api.MethodOutcome ca.uhn.fhir.rest.server.ServerInvalidDefinitionDstu2Test$UpdateWithWrongConditionalUrlType.update(ca.uhn.fhir.rest.param.TokenParam,ca.uhn.fhir.model.dstu2.resource.Patient)"));
|
assertThat(e.getCause().toString(), StringContains.containsString(
|
||||||
|
"Parameters annotated with @ConditionalUrlParam must be of type String, found incorrect parameteter in method \"public ca.uhn.fhir.rest.api.MethodOutcome ca.uhn.fhir.rest.server.ServerInvalidDefinitionDstu2Test$UpdateWithWrongConditionalUrlType.update(ca.uhn.fhir.rest.param.TokenParam,ca.uhn.fhir.model.dstu2.resource.Patient)"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -74,7 +53,8 @@ public class ServerInvalidDefinitionDstu2Test {
|
||||||
fail();
|
fail();
|
||||||
} catch (ServletException e) {
|
} catch (ServletException e) {
|
||||||
assertThat(e.getCause().toString(), StringContains.containsString("ConfigurationException"));
|
assertThat(e.getCause().toString(), StringContains.containsString("ConfigurationException"));
|
||||||
assertThat(e.getCause().toString(), StringContains.containsString("Method 'update' is annotated with @ResourceParam but has a type that is not an implemtation of org.hl7.fhir.instance.model.api.IBaseResource or String or byte[]"));
|
assertThat(e.getCause().toString(), StringContains
|
||||||
|
.containsString("Method 'update' is annotated with @ResourceParam but has a type that is not an implemtation of org.hl7.fhir.instance.model.api.IBaseResource or String or byte[]"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -108,20 +88,6 @@ public class ServerInvalidDefinitionDstu2Test {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class OperationReturningOldBundleProvider implements IResourceProvider {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Class<? extends IBaseResource> getResourceType() {
|
|
||||||
return Patient.class;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Operation(name = "$OP_TYPE_RET_OLD_BUNDLE")
|
|
||||||
public ca.uhn.fhir.model.api.Bundle opTypeRetOldBundle(@OperationParam(name = "PARAM1") StringDt theParam1, @OperationParam(name = "PARAM2") Patient theParam2) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class UpdateWithWrongConditionalUrlType implements IResourceProvider {
|
public static class UpdateWithWrongConditionalUrlType implements IResourceProvider {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -12,9 +12,7 @@ import static org.junit.Assert.fail;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.Date;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import org.apache.commons.io.IOUtils;
|
import org.apache.commons.io.IOUtils;
|
||||||
import org.hamcrest.core.StringContains;
|
import org.hamcrest.core.StringContains;
|
||||||
|
@ -22,27 +20,12 @@ import org.junit.AfterClass;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import ca.uhn.fhir.context.FhirContext;
|
import ca.uhn.fhir.context.FhirContext;
|
||||||
import ca.uhn.fhir.model.api.Bundle;
|
import ca.uhn.fhir.model.api.*;
|
||||||
import ca.uhn.fhir.model.api.ExtensionDt;
|
import ca.uhn.fhir.model.dstu2.composite.*;
|
||||||
import ca.uhn.fhir.model.api.ResourceMetadataKeyEnum;
|
import ca.uhn.fhir.model.dstu2.resource.*;
|
||||||
import ca.uhn.fhir.model.api.TemporalPrecisionEnum;
|
import ca.uhn.fhir.model.dstu2.valueset.*;
|
||||||
import ca.uhn.fhir.model.dstu2.composite.CodeableConceptDt;
|
import ca.uhn.fhir.model.primitive.*;
|
||||||
import ca.uhn.fhir.model.dstu2.composite.ResourceReferenceDt;
|
import ca.uhn.fhir.parser.*;
|
||||||
import ca.uhn.fhir.model.dstu2.composite.TimingDt;
|
|
||||||
import ca.uhn.fhir.model.dstu2.resource.Condition;
|
|
||||||
import ca.uhn.fhir.model.dstu2.resource.MedicationOrder;
|
|
||||||
import ca.uhn.fhir.model.dstu2.resource.OperationOutcome;
|
|
||||||
import ca.uhn.fhir.model.dstu2.resource.Patient;
|
|
||||||
import ca.uhn.fhir.model.dstu2.valueset.ConditionVerificationStatusEnum;
|
|
||||||
import ca.uhn.fhir.model.dstu2.valueset.ContactPointSystemEnum;
|
|
||||||
import ca.uhn.fhir.model.dstu2.valueset.NarrativeStatusEnum;
|
|
||||||
import ca.uhn.fhir.model.dstu2.valueset.UnitsOfTimeEnum;
|
|
||||||
import ca.uhn.fhir.model.primitive.DateDt;
|
|
||||||
import ca.uhn.fhir.model.primitive.InstantDt;
|
|
||||||
import ca.uhn.fhir.model.primitive.StringDt;
|
|
||||||
import ca.uhn.fhir.parser.DataFormatException;
|
|
||||||
import ca.uhn.fhir.parser.IParser;
|
|
||||||
import ca.uhn.fhir.parser.StrictErrorHandler;
|
|
||||||
import ca.uhn.fhir.parser.XmlParserDstu2Test.TestPatientFor327;
|
import ca.uhn.fhir.parser.XmlParserDstu2Test.TestPatientFor327;
|
||||||
import ca.uhn.fhir.util.TestUtil;
|
import ca.uhn.fhir.util.TestUtil;
|
||||||
import ca.uhn.fhir.validation.schematron.SchematronBaseValidator;
|
import ca.uhn.fhir.validation.schematron.SchematronBaseValidator;
|
||||||
|
@ -102,13 +85,13 @@ public class ResourceValidatorDstu2Test {
|
||||||
@Test
|
@Test
|
||||||
public void testSchemaBundleValidator() throws IOException {
|
public void testSchemaBundleValidator() throws IOException {
|
||||||
String res = IOUtils.toString(getClass().getClassLoader().getResourceAsStream("bundle-example.json"));
|
String res = IOUtils.toString(getClass().getClassLoader().getResourceAsStream("bundle-example.json"));
|
||||||
Bundle b = ourCtx.newJsonParser().parseBundle(res);
|
Bundle b = ourCtx.newJsonParser().parseResource(Bundle.class, res);
|
||||||
|
|
||||||
FhirValidator val = createFhirValidator();
|
FhirValidator val = createFhirValidator();
|
||||||
|
|
||||||
val.validate(b);
|
val.validate(b);
|
||||||
|
|
||||||
MedicationOrder p = (MedicationOrder) b.getEntries().get(0).getResource();
|
MedicationOrder p = (MedicationOrder) b.getEntry().get(0).getResource();
|
||||||
TimingDt timing = new TimingDt();
|
TimingDt timing = new TimingDt();
|
||||||
timing.getRepeat().setDuration(123);
|
timing.getRepeat().setDuration(123);
|
||||||
timing.getRepeat().setDurationUnits((UnitsOfTimeEnum) null);
|
timing.getRepeat().setDurationUnits((UnitsOfTimeEnum) null);
|
||||||
|
@ -127,20 +110,26 @@ public class ResourceValidatorDstu2Test {
|
||||||
@Test
|
@Test
|
||||||
public void testSchemaBundleValidatorFails() throws IOException {
|
public void testSchemaBundleValidatorFails() throws IOException {
|
||||||
String res = IOUtils.toString(getClass().getClassLoader().getResourceAsStream("bundle-example.json"), StandardCharsets.UTF_8);
|
String res = IOUtils.toString(getClass().getClassLoader().getResourceAsStream("bundle-example.json"), StandardCharsets.UTF_8);
|
||||||
Bundle b = ourCtx.newJsonParser().parseBundle(res);
|
Bundle b = ourCtx.newJsonParser().parseResource(Bundle.class, res);
|
||||||
|
|
||||||
|
|
||||||
FhirValidator val = createFhirValidator();
|
FhirValidator val = createFhirValidator();
|
||||||
|
|
||||||
ValidationResult validationResult = val.validateWithResult(b);
|
ValidationResult validationResult = val.validateWithResult(b);
|
||||||
assertTrue(validationResult.isSuccessful());
|
assertTrue(validationResult.isSuccessful());
|
||||||
|
|
||||||
MedicationOrder p = (MedicationOrder) b.getEntries().get(0).getResource();
|
MedicationOrder p = (MedicationOrder) b.getEntry().get(0).getResource();
|
||||||
TimingDt timing = new TimingDt();
|
TimingDt timing = new TimingDt();
|
||||||
timing.getRepeat().setDuration(123);
|
timing.getRepeat().setDuration(123);
|
||||||
timing.getRepeat().setDurationUnits((UnitsOfTimeEnum) null);
|
timing.getRepeat().setDurationUnits((UnitsOfTimeEnum) null);
|
||||||
p.getDosageInstructionFirstRep().setTiming(timing);
|
p.getDosageInstructionFirstRep().setTiming(timing);
|
||||||
|
|
||||||
|
ourLog.info(ourCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(b));
|
||||||
|
|
||||||
validationResult = val.validateWithResult(b);
|
validationResult = val.validateWithResult(b);
|
||||||
|
|
||||||
|
ourLog.info(ourCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(validationResult.toOperationOutcome()));
|
||||||
|
|
||||||
assertFalse(validationResult.isSuccessful());
|
assertFalse(validationResult.isSuccessful());
|
||||||
|
|
||||||
String encoded = logOperationOutcome(validationResult);
|
String encoded = logOperationOutcome(validationResult);
|
||||||
|
@ -150,9 +139,9 @@ public class ResourceValidatorDstu2Test {
|
||||||
@Test
|
@Test
|
||||||
public void testSchemaBundleValidatorIsSuccessful() throws IOException {
|
public void testSchemaBundleValidatorIsSuccessful() throws IOException {
|
||||||
String res = IOUtils.toString(getClass().getClassLoader().getResourceAsStream("bundle-example.json"), StandardCharsets.UTF_8);
|
String res = IOUtils.toString(getClass().getClassLoader().getResourceAsStream("bundle-example.json"), StandardCharsets.UTF_8);
|
||||||
Bundle b = ourCtx.newJsonParser().parseBundle(res);
|
Bundle b = ourCtx.newJsonParser().parseResource(Bundle.class, res);
|
||||||
|
|
||||||
ourLog.info(ourCtx.newXmlParser().setPrettyPrint(true).encodeBundleToString(b));
|
ourLog.info(ourCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(b));
|
||||||
|
|
||||||
FhirValidator val = createFhirValidator();
|
FhirValidator val = createFhirValidator();
|
||||||
|
|
||||||
|
|
|
@ -114,8 +114,13 @@ public class GenericClientDstu3Test {
|
||||||
.returnBundle(Bundle.class)
|
.returnBundle(Bundle.class)
|
||||||
.execute();
|
.execute();
|
||||||
|
|
||||||
assertEquals("http://example.com/fhir/EpisodeOfCare?patient=123&_revinclude=Encounter%3Aepisodeofcare&_revinclude%3Arecurse=Observation%3Aencounter",
|
String expected = "http://example.com/fhir/EpisodeOfCare?patient=123&_revinclude=Encounter%3Aepisodeofcare&_revinclude%3Arecurse=Observation%3Aencounter";
|
||||||
capt.getAllValues().get(idx).getURI().toString());
|
String actual = capt.getAllValues().get(idx).getURI().toString();
|
||||||
|
|
||||||
|
ourLog.info("EXP: {}", expected);
|
||||||
|
ourLog.info("ACT: {}", actual);
|
||||||
|
|
||||||
|
assertEquals(expected, actual);
|
||||||
idx++;
|
idx++;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1526,17 +1531,6 @@ public class GenericClientDstu3Test {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testSearchForUnknownType() throws Exception {
|
|
||||||
IGenericClient client = ourCtx.newRestfulGenericClient("http://example.com/fhir");
|
|
||||||
try {
|
|
||||||
client.search(new UriDt("?aaaa"));
|
|
||||||
fail();
|
|
||||||
} catch (IllegalArgumentException e) {
|
|
||||||
assertEquals("Unable to determine the resource type from the given URI: ?aaaa", e.getMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSearchWithMultipleTokens() throws Exception {
|
public void testSearchWithMultipleTokens() throws Exception {
|
||||||
ArgumentCaptor<HttpUriRequest> capt = prepareClientForSearchResponse();
|
ArgumentCaptor<HttpUriRequest> capt = prepareClientForSearchResponse();
|
||||||
|
|
|
@ -67,9 +67,13 @@ public class DateRangeParamTest {
|
||||||
public void testDay() throws Exception {
|
public void testDay() throws Exception {
|
||||||
assertEquals(parse("2011-01-01 00:00:00.0000"), create(">=2011-01-01", "<2011-01-02").getLowerBoundAsInstant());
|
assertEquals(parse("2011-01-01 00:00:00.0000"), create(">=2011-01-01", "<2011-01-02").getLowerBoundAsInstant());
|
||||||
assertEquals(parseM1("2011-01-02 00:00:00.0000"), create(">=2011-01-01", "<2011-01-02").getUpperBoundAsInstant());
|
assertEquals(parseM1("2011-01-02 00:00:00.0000"), create(">=2011-01-01", "<2011-01-02").getUpperBoundAsInstant());
|
||||||
|
|
||||||
assertEquals(parse("2011-01-02 00:00:00.0000"), create(">2011-01-01", "<=2011-01-02").getLowerBoundAsInstant());
|
assertEquals(parse("2011-01-02 00:00:00.0000"), create(">2011-01-01", "<=2011-01-02").getLowerBoundAsInstant());
|
||||||
assertEquals(parseM1("2011-01-03 00:00:00.0000"), create(">2011-01-01", "<=2011-01-02").getUpperBoundAsInstant());
|
assertEquals(parseM1("2011-01-03 00:00:00.0000"), create(">2011-01-01", "<=2011-01-02").getUpperBoundAsInstant());
|
||||||
|
|
||||||
|
assertEquals(parse("2011-01-01 00:00:00.0000"), create("ge2011-01-01", "lt2011-01-02").getLowerBoundAsInstant());
|
||||||
|
assertEquals(parseM1("2011-01-02 00:00:00.0000"), create("ge2011-01-01", "lt2011-01-02").getUpperBoundAsInstant());
|
||||||
|
assertEquals(parse("2011-01-02 00:00:00.0000"), create("gt2011-01-01", "le2011-01-02").getLowerBoundAsInstant());
|
||||||
|
assertEquals(parseM1("2011-01-03 00:00:00.0000"), create("gt2011-01-01", "le2011-01-02").getUpperBoundAsInstant());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -77,20 +81,20 @@ public class DateRangeParamTest {
|
||||||
assertEquals(parse("2011-01-01 00:00:00.0000"), create("2011-01-01").getLowerBoundAsInstant());
|
assertEquals(parse("2011-01-01 00:00:00.0000"), create("2011-01-01").getLowerBoundAsInstant());
|
||||||
assertEquals(parseM1("2011-01-02 00:00:00.0000"), create("2011-01-01").getUpperBoundAsInstant());
|
assertEquals(parseM1("2011-01-02 00:00:00.0000"), create("2011-01-01").getUpperBoundAsInstant());
|
||||||
|
|
||||||
assertEquals(parse("2011-01-01 00:00:00.0000"), create(">=2011-01-01").getLowerBoundAsInstant());
|
assertEquals(parse("2011-01-01 00:00:00.0000"), create("ge2011-01-01").getLowerBoundAsInstant());
|
||||||
assertEquals(null, create(">=2011-01-01").getUpperBoundAsInstant());
|
assertEquals(null, create("ge2011-01-01").getUpperBoundAsInstant());
|
||||||
|
|
||||||
assertEquals(null, create("<=2011-01-01").getLowerBoundAsInstant());
|
assertEquals(null, create("le2011-01-01").getLowerBoundAsInstant());
|
||||||
assertEquals(parseM1("2011-01-02 00:00:00.0000"), create("<=2011-01-01").getUpperBoundAsInstant());
|
assertEquals(parseM1("2011-01-02 00:00:00.0000"), create("le2011-01-01").getUpperBoundAsInstant());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testMonth() throws Exception {
|
public void testMonth() throws Exception {
|
||||||
assertEquals(parse("2011-01-01 00:00:00.0000"), create(">=2011-01", "<2011-02").getLowerBoundAsInstant());
|
assertEquals(parse("2011-01-01 00:00:00.0000"), create("ge2011-01", "lt2011-02").getLowerBoundAsInstant());
|
||||||
assertEquals(parseM1("2011-02-01 00:00:00.0000"), create(">=2011-01", "<2011-02").getUpperBoundAsInstant());
|
assertEquals(parseM1("2011-02-01 00:00:00.0000"), create("ge2011-01", "lt2011-02").getUpperBoundAsInstant());
|
||||||
|
|
||||||
assertEquals(parse("2011-02-01 00:00:00.0000"), create(">2011-01", "<=2011-02").getLowerBoundAsInstant());
|
assertEquals(parse("2011-02-01 00:00:00.0000"), create("gt2011-01", "le2011-02").getLowerBoundAsInstant());
|
||||||
assertEquals(parseM1("2011-03-01 00:00:00.0000"), create(">2011-01", "<=2011-02").getUpperBoundAsInstant());
|
assertEquals(parseM1("2011-03-01 00:00:00.0000"), create("gt2011-01", "le2011-02").getUpperBoundAsInstant());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -159,20 +163,20 @@ public class DateRangeParamTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSecond() throws Exception {
|
public void testSecond() throws Exception {
|
||||||
assertEquals(parse("2011-01-01 00:00:00.0000"), create(">=2011-01-01T00:00:00", "<2011-01-01T01:00:00").getLowerBoundAsInstant());
|
assertEquals(parse("2011-01-01 00:00:00.0000"), create("ge2011-01-01T00:00:00", "lt2011-01-01T01:00:00").getLowerBoundAsInstant());
|
||||||
assertEquals(parseM1("2011-01-01 02:00:00.0000"), create(">=2011-01-01T00:00:00", "<2011-01-01T02:00:00").getUpperBoundAsInstant());
|
assertEquals(parseM1("2011-01-01 02:00:00.0000"), create("ge2011-01-01T00:00:00", "lt2011-01-01T02:00:00").getUpperBoundAsInstant());
|
||||||
|
|
||||||
assertEquals(parse("2011-01-01 00:00:01.0000"), create(">2011-01-01T00:00:00", "<=2011-01-01T02:00:00").getLowerBoundAsInstant());
|
assertEquals(parse("2011-01-01 00:00:01.0000"), create("gt2011-01-01T00:00:00", "le2011-01-01T02:00:00").getLowerBoundAsInstant());
|
||||||
assertEquals(parseM1("2011-01-01 02:00:01.0000"), create(">2011-01-01T00:00:00", "<=2011-01-01T02:00:00").getUpperBoundAsInstant());
|
assertEquals(parseM1("2011-01-01 02:00:01.0000"), create("gt2011-01-01T00:00:00", "le2011-01-01T02:00:00").getUpperBoundAsInstant());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testYear() throws Exception {
|
public void testYear() throws Exception {
|
||||||
assertEquals(parse("2011-01-01 00:00:00.0000"), create(">=2011", "<2012").getLowerBoundAsInstant());
|
assertEquals(parse("2011-01-01 00:00:00.0000"), create("ge2011", "lt2012").getLowerBoundAsInstant());
|
||||||
assertEquals(parseM1("2012-01-01 00:00:00.0000"), create(">=2011", "<2012").getUpperBoundAsInstant());
|
assertEquals(parseM1("2012-01-01 00:00:00.0000"), create("ge2011", "lt2012").getUpperBoundAsInstant());
|
||||||
|
|
||||||
assertEquals(parse("2012-01-01 00:00:00.0000"), create(">2011", "<=2012").getLowerBoundAsInstant());
|
assertEquals(parse("2012-01-01 00:00:00.0000"), create("gt2011", "le2012").getLowerBoundAsInstant());
|
||||||
assertEquals(parseM1("2014-01-01 00:00:00.0000"), create(">2011", "<=2013").getUpperBoundAsInstant());
|
assertEquals(parseM1("2014-01-01 00:00:00.0000"), create("gt2011", "le2013").getUpperBoundAsInstant());
|
||||||
}
|
}
|
||||||
|
|
||||||
@AfterClass
|
@AfterClass
|
||||||
|
|
|
@ -1286,72 +1286,6 @@ public class JsonParserHl7OrgDstu2Test {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testTagList() {
|
|
||||||
|
|
||||||
//@formatter:off
|
|
||||||
String tagListStr = "{\n" +
|
|
||||||
" \"resourceType\" : \"TagList\", " +
|
|
||||||
" \"category\" : [" +
|
|
||||||
" { " +
|
|
||||||
" \"term\" : \"term0\", " +
|
|
||||||
" \"label\" : \"label0\", " +
|
|
||||||
" \"scheme\" : \"scheme0\" " +
|
|
||||||
" }," +
|
|
||||||
" { " +
|
|
||||||
" \"term\" : \"term1\", " +
|
|
||||||
" \"label\" : \"label1\", " +
|
|
||||||
" \"scheme\" : null " +
|
|
||||||
" }," +
|
|
||||||
" { " +
|
|
||||||
" \"term\" : \"term2\", " +
|
|
||||||
" \"label\" : \"label2\" " +
|
|
||||||
" }" +
|
|
||||||
" ] " +
|
|
||||||
"}";
|
|
||||||
//@formatter:on
|
|
||||||
|
|
||||||
TagList tagList = ourCtx.newJsonParser().parseTagList(tagListStr);
|
|
||||||
assertEquals(3, tagList.size());
|
|
||||||
assertEquals("term0", tagList.get(0).getTerm());
|
|
||||||
assertEquals("label0", tagList.get(0).getLabel());
|
|
||||||
assertEquals("scheme0", tagList.get(0).getScheme());
|
|
||||||
assertEquals("term1", tagList.get(1).getTerm());
|
|
||||||
assertEquals("label1", tagList.get(1).getLabel());
|
|
||||||
assertEquals(null, tagList.get(1).getScheme());
|
|
||||||
assertEquals("term2", tagList.get(2).getTerm());
|
|
||||||
assertEquals("label2", tagList.get(2).getLabel());
|
|
||||||
assertEquals(null, tagList.get(2).getScheme());
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Encode
|
|
||||||
*/
|
|
||||||
|
|
||||||
//@formatter:off
|
|
||||||
String expected = "{" +
|
|
||||||
"\"resourceType\":\"TagList\"," +
|
|
||||||
"\"category\":[" +
|
|
||||||
"{" +
|
|
||||||
"\"term\":\"term0\"," +
|
|
||||||
"\"label\":\"label0\"," +
|
|
||||||
"\"scheme\":\"scheme0\"" +
|
|
||||||
"}," +
|
|
||||||
"{" +
|
|
||||||
"\"term\":\"term1\"," +
|
|
||||||
"\"label\":\"label1\"" +
|
|
||||||
"}," +
|
|
||||||
"{" +
|
|
||||||
"\"term\":\"term2\"," +
|
|
||||||
"\"label\":\"label2\"" +
|
|
||||||
"}" +
|
|
||||||
"]" +
|
|
||||||
"}";
|
|
||||||
//@formatter:on
|
|
||||||
|
|
||||||
String encoded = ourCtx.newJsonParser().encodeTagListToString(tagList);
|
|
||||||
assertEquals(expected, encoded);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@ResourceDef(name = "Patient")
|
@ResourceDef(name = "Patient")
|
||||||
public static class MyPatientWithOneDeclaredAddressExtension extends Patient {
|
public static class MyPatientWithOneDeclaredAddressExtension extends Patient {
|
||||||
|
|
|
@ -29,7 +29,6 @@ import org.mockito.invocation.InvocationOnMock;
|
||||||
import org.mockito.stubbing.Answer;
|
import org.mockito.stubbing.Answer;
|
||||||
|
|
||||||
import ca.uhn.fhir.context.FhirContext;
|
import ca.uhn.fhir.context.FhirContext;
|
||||||
import ca.uhn.fhir.model.api.Bundle;
|
|
||||||
import ca.uhn.fhir.model.api.Include;
|
import ca.uhn.fhir.model.api.Include;
|
||||||
import ca.uhn.fhir.parser.IParser;
|
import ca.uhn.fhir.parser.IParser;
|
||||||
import ca.uhn.fhir.rest.api.Constants;
|
import ca.uhn.fhir.rest.api.Constants;
|
||||||
|
@ -56,8 +55,6 @@ public class GenericClientDstu2Hl7OrgTest {
|
||||||
myHttpResponse = mock(HttpResponse.class, new ReturnsDeepStubs());
|
myHttpResponse = mock(HttpResponse.class, new ReturnsDeepStubs());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testReadUpdatedHeaderDoesntOverwriteResourceValue() throws Exception {
|
public void testReadUpdatedHeaderDoesntOverwriteResourceValue() throws Exception {
|
||||||
|
|
||||||
|
@ -106,7 +103,6 @@ public class GenericClientDstu2Hl7OrgTest {
|
||||||
assertEquals("2015-06-22T15:48:57.554-04:00", response.getMeta().getLastUpdatedElement().getValueAsString());
|
assertEquals("2015-06-22T15:48:57.554-04:00", response.getMeta().getLastUpdatedElement().getValueAsString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
@Test
|
@Test
|
||||||
public void testSearchWithReverseInclude() throws Exception {
|
public void testSearchWithReverseInclude() throws Exception {
|
||||||
|
@ -136,7 +132,6 @@ public class GenericClientDstu2Hl7OrgTest {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private String getPatientFeedWithOneResult() {
|
private String getPatientFeedWithOneResult() {
|
||||||
//@formatter:off
|
//@formatter:off
|
||||||
String msg = "<Bundle xmlns=\"http://hl7.org/fhir\">\n" +
|
String msg = "<Bundle xmlns=\"http://hl7.org/fhir\">\n" +
|
||||||
|
@ -238,23 +233,6 @@ public class GenericClientDstu2Hl7OrgTest {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
|
||||||
@Test
|
|
||||||
public void testSearchRequiresBundleType() {
|
|
||||||
IGenericClient client = ourCtx.newRestfulGenericClient("http://example.com/fhir");
|
|
||||||
|
|
||||||
try {
|
|
||||||
//@formatter:off
|
|
||||||
Bundle response = client.search()
|
|
||||||
.forResource("Patient")
|
|
||||||
.where(new StringClientParam("name").matches().value("james"))
|
|
||||||
.execute();
|
|
||||||
//@formatter:on
|
|
||||||
fail();
|
|
||||||
} catch (IllegalArgumentException e) {
|
|
||||||
// good
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testOperationWithListOfParameterResponse() throws Exception {
|
public void testOperationWithListOfParameterResponse() throws Exception {
|
||||||
|
@ -839,7 +817,8 @@ public class GenericClientDstu2Hl7OrgTest {
|
||||||
assertEquals("http://example.com/fhir/Patient?name=foo&address=AAA%5C%7CBBB", capt.getAllValues().get(idx).getURI().toString());
|
assertEquals("http://example.com/fhir/Patient?name=foo&address=AAA%5C%7CBBB", capt.getAllValues().get(idx).getURI().toString());
|
||||||
idx++;
|
idx++;
|
||||||
|
|
||||||
client.update().resource(ourCtx.newXmlParser().encodeResourceToString(p)).conditional().where(new StringClientParam("name").matches().value("foo")).and(new StringClientParam("address").matches().value("AAA|BBB")).execute();
|
client.update().resource(ourCtx.newXmlParser().encodeResourceToString(p)).conditional().where(new StringClientParam("name").matches().value("foo"))
|
||||||
|
.and(new StringClientParam("address").matches().value("AAA|BBB")).execute();
|
||||||
assertEquals(1, capt.getAllValues().get(idx).getHeaders(Constants.HEADER_CONTENT_TYPE).length);
|
assertEquals(1, capt.getAllValues().get(idx).getHeaders(Constants.HEADER_CONTENT_TYPE).length);
|
||||||
assertEquals(EncodingEnum.XML.getResourceContentType() + Constants.HEADER_SUFFIX_CT_UTF_8, capt.getAllValues().get(idx).getFirstHeader(Constants.HEADER_CONTENT_TYPE).getValue());
|
assertEquals(EncodingEnum.XML.getResourceContentType() + Constants.HEADER_SUFFIX_CT_UTF_8, capt.getAllValues().get(idx).getFirstHeader(Constants.HEADER_CONTENT_TYPE).getValue());
|
||||||
assertThat(extractBody(capt, idx), containsString("<family value=\"FOOFAMILY\"/>"));
|
assertThat(extractBody(capt, idx), containsString("<family value=\"FOOFAMILY\"/>"));
|
||||||
|
|
|
@ -1,56 +0,0 @@
|
||||||
package ca.uhn.fhir.rest.server;
|
|
||||||
|
|
||||||
import static org.junit.Assert.assertThat;
|
|
||||||
import static org.junit.Assert.fail;
|
|
||||||
|
|
||||||
import javax.servlet.ServletException;
|
|
||||||
|
|
||||||
import org.hamcrest.core.StringContains;
|
|
||||||
import org.hl7.fhir.instance.model.Patient;
|
|
||||||
import org.hl7.fhir.instance.model.StringType;
|
|
||||||
import org.hl7.fhir.instance.model.api.IBaseResource;
|
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
import ca.uhn.fhir.context.FhirContext;
|
|
||||||
import ca.uhn.fhir.rest.annotation.Operation;
|
|
||||||
import ca.uhn.fhir.rest.annotation.OperationParam;
|
|
||||||
|
|
||||||
public class ServerInvalidDefinitionHl7OrgDstu2Test {
|
|
||||||
|
|
||||||
private static FhirContext ourCtx = FhirContext.forDstu2Hl7Org();
|
|
||||||
|
|
||||||
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory
|
|
||||||
.getLogger(ServerInvalidDefinitionHl7OrgDstu2Test.class);
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testOperationReturningOldBundleProvider() {
|
|
||||||
RestfulServer srv = new RestfulServer(ourCtx);
|
|
||||||
srv.setFhirContext(ourCtx);
|
|
||||||
srv.setResourceProviders(new OperationReturningOldBundleProvider());
|
|
||||||
|
|
||||||
try {
|
|
||||||
srv.init();
|
|
||||||
fail();
|
|
||||||
} catch (ServletException e) {
|
|
||||||
ourLog.info(e.getCause().toString());
|
|
||||||
assertThat(e.getCause().toString(), StringContains.containsString("ConfigurationException"));
|
|
||||||
assertThat(e.getCause().toString(), StringContains.containsString("Can not return a DSTU1 bundle"));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class OperationReturningOldBundleProvider implements IResourceProvider {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Class<? extends IBaseResource> getResourceType() {
|
|
||||||
return Patient.class;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Operation(name = "$OP_TYPE_RET_OLD_BUNDLE")
|
|
||||||
public ca.uhn.fhir.model.api.Bundle opTypeRetOldBundle(@OperationParam(name = "PARAM1") StringType theParam1,
|
|
||||||
@OperationParam(name = "PARAM2") Patient theParam2) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -264,11 +264,6 @@ public class R4BundleFactory implements IVersionSpecificBundleFactory {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public ca.uhn.fhir.model.api.Bundle getDstu1Bundle() {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IBaseResource getResourceBundle() {
|
public IBaseResource getResourceBundle() {
|
||||||
return myBundle;
|
return myBundle;
|
||||||
|
|
|
@ -2,7 +2,13 @@ package ca.uhn.fhir.rest.client;
|
||||||
|
|
||||||
import static org.hamcrest.Matchers.containsString;
|
import static org.hamcrest.Matchers.containsString;
|
||||||
import static org.hamcrest.Matchers.startsWith;
|
import static org.hamcrest.Matchers.startsWith;
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.assertArrayEquals;
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertFalse;
|
||||||
|
import static org.junit.Assert.assertNotNull;
|
||||||
|
import static org.junit.Assert.assertNull;
|
||||||
|
import static org.junit.Assert.assertThat;
|
||||||
|
import static org.junit.Assert.fail;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
|
@ -33,8 +39,10 @@ import com.phloc.commons.io.streams.StringInputStream;
|
||||||
|
|
||||||
import ca.uhn.fhir.context.FhirContext;
|
import ca.uhn.fhir.context.FhirContext;
|
||||||
import ca.uhn.fhir.context.FhirVersionEnum;
|
import ca.uhn.fhir.context.FhirVersionEnum;
|
||||||
|
import ca.uhn.fhir.model.api.IQueryParameterType;
|
||||||
import ca.uhn.fhir.model.api.TemporalPrecisionEnum;
|
import ca.uhn.fhir.model.api.TemporalPrecisionEnum;
|
||||||
import ca.uhn.fhir.model.primitive.*;
|
import ca.uhn.fhir.model.primitive.DateTimeDt;
|
||||||
|
import ca.uhn.fhir.model.primitive.StringDt;
|
||||||
import ca.uhn.fhir.parser.CustomTypeR4Test;
|
import ca.uhn.fhir.parser.CustomTypeR4Test;
|
||||||
import ca.uhn.fhir.parser.CustomTypeR4Test.MyCustomPatient;
|
import ca.uhn.fhir.parser.CustomTypeR4Test.MyCustomPatient;
|
||||||
import ca.uhn.fhir.parser.IParser;
|
import ca.uhn.fhir.parser.IParser;
|
||||||
|
@ -47,6 +55,7 @@ import ca.uhn.fhir.rest.client.exceptions.NonFhirResponseException;
|
||||||
import ca.uhn.fhir.rest.client.impl.BaseClient;
|
import ca.uhn.fhir.rest.client.impl.BaseClient;
|
||||||
import ca.uhn.fhir.rest.client.interceptor.CookieInterceptor;
|
import ca.uhn.fhir.rest.client.interceptor.CookieInterceptor;
|
||||||
import ca.uhn.fhir.rest.client.interceptor.UserInfoInterceptor;
|
import ca.uhn.fhir.rest.client.interceptor.UserInfoInterceptor;
|
||||||
|
import ca.uhn.fhir.rest.param.DateParam;
|
||||||
import ca.uhn.fhir.rest.param.ParamPrefixEnum;
|
import ca.uhn.fhir.rest.param.ParamPrefixEnum;
|
||||||
import ca.uhn.fhir.rest.server.exceptions.NotImplementedOperationException;
|
import ca.uhn.fhir.rest.server.exceptions.NotImplementedOperationException;
|
||||||
import ca.uhn.fhir.rest.server.exceptions.UnclassifiedServerFailureException;
|
import ca.uhn.fhir.rest.server.exceptions.UnclassifiedServerFailureException;
|
||||||
|
@ -99,272 +108,6 @@ public class GenericClientR4Test {
|
||||||
return capt;
|
return capt;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testRevIncludeRecursive() throws ClientProtocolException, IOException {
|
|
||||||
ArgumentCaptor<HttpUriRequest> capt = prepareClientForSearchResponse();
|
|
||||||
|
|
||||||
IGenericClient client = ourCtx.newRestfulGenericClient("http://example.com/fhir");
|
|
||||||
int idx = 0;
|
|
||||||
|
|
||||||
client.search()
|
|
||||||
.forResource(EpisodeOfCare.class)
|
|
||||||
.where(EpisodeOfCare.PATIENT.hasId("123"))
|
|
||||||
.revInclude(Encounter.INCLUDE_EPISODEOFCARE)
|
|
||||||
.revInclude(Observation.INCLUDE_ENCOUNTER.asRecursive())
|
|
||||||
.returnBundle(Bundle.class)
|
|
||||||
.execute();
|
|
||||||
|
|
||||||
assertEquals("http://example.com/fhir/EpisodeOfCare?patient=123&_revinclude=Encounter%3Aepisodeofcare&_revinclude%3Arecurse=Observation%3Aencounter",
|
|
||||||
capt.getAllValues().get(idx).getURI().toString());
|
|
||||||
idx++;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testPatchJsonByIdString() throws Exception {
|
|
||||||
OperationOutcome conf = new OperationOutcome();
|
|
||||||
conf.getText().setDivAsString("OK!");
|
|
||||||
final String respString = ourCtx.newJsonParser().encodeResourceToString(conf);
|
|
||||||
|
|
||||||
ArgumentCaptor<HttpUriRequest> capt = ArgumentCaptor.forClass(HttpUriRequest.class);
|
|
||||||
when(myHttpClient.execute(capt.capture())).thenReturn(myHttpResponse);
|
|
||||||
when(myHttpResponse.getStatusLine()).thenReturn(new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), 200, "OK"));
|
|
||||||
when(myHttpResponse.getEntity().getContentType()).thenReturn(new BasicHeader("content-type", Constants.CT_FHIR_JSON + "; charset=UTF-8"));
|
|
||||||
when(myHttpResponse.getEntity().getContent()).then(new Answer<InputStream>() {
|
|
||||||
@Override
|
|
||||||
public InputStream answer(InvocationOnMock theInvocation) throws Throwable {
|
|
||||||
return new ReaderInputStream(new StringReader(respString), Charset.forName("UTF-8"));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
IGenericClient client = ourCtx.newRestfulGenericClient("http://example.com/fhir");
|
|
||||||
int idx = 0;
|
|
||||||
|
|
||||||
String patch = "[ { \"op\":\"replace\", \"path\":\"/active\", \"value\":false } ]";
|
|
||||||
|
|
||||||
MethodOutcome outcome = client
|
|
||||||
.patch()
|
|
||||||
.withBody(patch)
|
|
||||||
.withId("Patient/123")
|
|
||||||
.execute();
|
|
||||||
|
|
||||||
assertEquals("http://example.com/fhir/Patient/123", UrlUtil.unescape(capt.getAllValues().get(idx).getURI().toString()));
|
|
||||||
assertEquals("PATCH", capt.getAllValues().get(0).getRequestLine().getMethod());
|
|
||||||
assertEquals(patch, extractBodyAsString(capt));
|
|
||||||
assertEquals(Constants.CT_JSON_PATCH, capt.getAllValues().get(idx).getFirstHeader("Content-Type").getValue().replaceAll(";.*", ""));
|
|
||||||
idx++;
|
|
||||||
|
|
||||||
OperationOutcome oo = (OperationOutcome) outcome.getOperationOutcome();
|
|
||||||
assertThat(oo.getText().getDivAsString(), containsString("OK!"));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testPatchJsonByIdType() throws Exception {
|
|
||||||
OperationOutcome conf = new OperationOutcome();
|
|
||||||
conf.getText().setDivAsString("OK!");
|
|
||||||
final String respString = ourCtx.newJsonParser().encodeResourceToString(conf);
|
|
||||||
|
|
||||||
ArgumentCaptor<HttpUriRequest> capt = ArgumentCaptor.forClass(HttpUriRequest.class);
|
|
||||||
when(myHttpClient.execute(capt.capture())).thenReturn(myHttpResponse);
|
|
||||||
when(myHttpResponse.getStatusLine()).thenReturn(new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), 200, "OK"));
|
|
||||||
when(myHttpResponse.getEntity().getContentType()).thenReturn(new BasicHeader("content-type", Constants.CT_FHIR_JSON + "; charset=UTF-8"));
|
|
||||||
when(myHttpResponse.getEntity().getContent()).then(new Answer<InputStream>() {
|
|
||||||
@Override
|
|
||||||
public InputStream answer(InvocationOnMock theInvocation) throws Throwable {
|
|
||||||
return new ReaderInputStream(new StringReader(respString), Charset.forName("UTF-8"));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
IGenericClient client = ourCtx.newRestfulGenericClient("http://example.com/fhir");
|
|
||||||
int idx = 0;
|
|
||||||
|
|
||||||
String patch = "[ { \"op\":\"replace\", \"path\":\"/active\", \"value\":false } ]";
|
|
||||||
|
|
||||||
MethodOutcome outcome = client
|
|
||||||
.patch()
|
|
||||||
.withBody(patch)
|
|
||||||
.withId(new IdType("http://localhost/fhir/Patient/123/_history/234"))
|
|
||||||
.execute();
|
|
||||||
|
|
||||||
assertEquals("http://example.com/fhir/Patient/123", UrlUtil.unescape(capt.getAllValues().get(idx).getURI().toString()));
|
|
||||||
assertEquals("PATCH", capt.getAllValues().get(0).getRequestLine().getMethod());
|
|
||||||
assertEquals(patch, extractBodyAsString(capt));
|
|
||||||
assertEquals(Constants.CT_JSON_PATCH, capt.getAllValues().get(idx).getFirstHeader("Content-Type").getValue().replaceAll(";.*", ""));
|
|
||||||
idx++;
|
|
||||||
|
|
||||||
OperationOutcome oo = (OperationOutcome) outcome.getOperationOutcome();
|
|
||||||
assertThat(oo.getText().getDivAsString(), containsString("OK!"));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testPatchJsonByConditionalString() throws Exception {
|
|
||||||
OperationOutcome conf = new OperationOutcome();
|
|
||||||
conf.getText().setDivAsString("OK!");
|
|
||||||
final String respString = ourCtx.newJsonParser().encodeResourceToString(conf);
|
|
||||||
|
|
||||||
ArgumentCaptor<HttpUriRequest> capt = ArgumentCaptor.forClass(HttpUriRequest.class);
|
|
||||||
when(myHttpClient.execute(capt.capture())).thenReturn(myHttpResponse);
|
|
||||||
when(myHttpResponse.getStatusLine()).thenReturn(new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), 200, "OK"));
|
|
||||||
when(myHttpResponse.getEntity().getContentType()).thenReturn(new BasicHeader("content-type", Constants.CT_FHIR_JSON + "; charset=UTF-8"));
|
|
||||||
when(myHttpResponse.getEntity().getContent()).then(new Answer<InputStream>() {
|
|
||||||
@Override
|
|
||||||
public InputStream answer(InvocationOnMock theInvocation) throws Throwable {
|
|
||||||
return new ReaderInputStream(new StringReader(respString), Charset.forName("UTF-8"));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
IGenericClient client = ourCtx.newRestfulGenericClient("http://example.com/fhir");
|
|
||||||
int idx = 0;
|
|
||||||
|
|
||||||
String patch = "[ { \"op\":\"replace\", \"path\":\"/active\", \"value\":false } ]";
|
|
||||||
|
|
||||||
MethodOutcome outcome = client
|
|
||||||
.patch()
|
|
||||||
.withBody(patch)
|
|
||||||
.conditionalByUrl("Patient?foo=bar")
|
|
||||||
.execute();
|
|
||||||
|
|
||||||
assertEquals("http://example.com/fhir/Patient?foo=bar", UrlUtil.unescape(capt.getAllValues().get(idx).getURI().toString()));
|
|
||||||
assertEquals("PATCH", capt.getAllValues().get(0).getRequestLine().getMethod());
|
|
||||||
assertEquals(patch, extractBodyAsString(capt));
|
|
||||||
assertEquals(Constants.CT_JSON_PATCH, capt.getAllValues().get(idx).getFirstHeader("Content-Type").getValue().replaceAll(";.*", ""));
|
|
||||||
idx++;
|
|
||||||
|
|
||||||
OperationOutcome oo = (OperationOutcome) outcome.getOperationOutcome();
|
|
||||||
assertThat(oo.getText().getDivAsString(), containsString("OK!"));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testPatchJsonByConditionalParam() throws Exception {
|
|
||||||
OperationOutcome conf = new OperationOutcome();
|
|
||||||
conf.getText().setDivAsString("OK!");
|
|
||||||
final String respString = ourCtx.newJsonParser().encodeResourceToString(conf);
|
|
||||||
|
|
||||||
ArgumentCaptor<HttpUriRequest> capt = ArgumentCaptor.forClass(HttpUriRequest.class);
|
|
||||||
when(myHttpClient.execute(capt.capture())).thenReturn(myHttpResponse);
|
|
||||||
when(myHttpResponse.getStatusLine()).thenReturn(new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), 200, "OK"));
|
|
||||||
when(myHttpResponse.getEntity().getContentType()).thenReturn(new BasicHeader("content-type", Constants.CT_FHIR_JSON + "; charset=UTF-8"));
|
|
||||||
when(myHttpResponse.getEntity().getContent()).then(new Answer<InputStream>() {
|
|
||||||
@Override
|
|
||||||
public InputStream answer(InvocationOnMock theInvocation) throws Throwable {
|
|
||||||
return new ReaderInputStream(new StringReader(respString), Charset.forName("UTF-8"));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
IGenericClient client = ourCtx.newRestfulGenericClient("http://example.com/fhir");
|
|
||||||
int idx = 0;
|
|
||||||
|
|
||||||
String patch = "[ { \"op\":\"replace\", \"path\":\"/active\", \"value\":false } ]";
|
|
||||||
|
|
||||||
MethodOutcome outcome = client
|
|
||||||
.patch()
|
|
||||||
.withBody(patch)
|
|
||||||
.conditional("Patient").where(Patient.NAME.matches().value("TEST"))
|
|
||||||
.and(Patient.FAMILY.matches().value("TEST2"))
|
|
||||||
.execute();
|
|
||||||
|
|
||||||
assertEquals("http://example.com/fhir/Patient?name=TEST&family=TEST2", UrlUtil.unescape(capt.getAllValues().get(idx).getURI().toString()));
|
|
||||||
assertEquals("PATCH", capt.getAllValues().get(0).getRequestLine().getMethod());
|
|
||||||
assertEquals(patch, extractBodyAsString(capt));
|
|
||||||
assertEquals(Constants.CT_JSON_PATCH, capt.getAllValues().get(idx).getFirstHeader("Content-Type").getValue().replaceAll(";.*", ""));
|
|
||||||
idx++;
|
|
||||||
|
|
||||||
OperationOutcome oo = (OperationOutcome) outcome.getOperationOutcome();
|
|
||||||
assertThat(oo.getText().getDivAsString(), containsString("OK!"));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testPatchJsonByConditionalParamResourceType() throws Exception {
|
|
||||||
OperationOutcome conf = new OperationOutcome();
|
|
||||||
conf.getText().setDivAsString("OK!");
|
|
||||||
final String respString = ourCtx.newJsonParser().encodeResourceToString(conf);
|
|
||||||
|
|
||||||
ArgumentCaptor<HttpUriRequest> capt = ArgumentCaptor.forClass(HttpUriRequest.class);
|
|
||||||
when(myHttpClient.execute(capt.capture())).thenReturn(myHttpResponse);
|
|
||||||
when(myHttpResponse.getStatusLine()).thenReturn(new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), 200, "OK"));
|
|
||||||
when(myHttpResponse.getEntity().getContentType()).thenReturn(new BasicHeader("content-type", Constants.CT_FHIR_JSON + "; charset=UTF-8"));
|
|
||||||
when(myHttpResponse.getEntity().getContent()).then(new Answer<InputStream>() {
|
|
||||||
@Override
|
|
||||||
public InputStream answer(InvocationOnMock theInvocation) throws Throwable {
|
|
||||||
return new ReaderInputStream(new StringReader(respString), Charset.forName("UTF-8"));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
IGenericClient client = ourCtx.newRestfulGenericClient("http://example.com/fhir");
|
|
||||||
int idx = 0;
|
|
||||||
|
|
||||||
String patch = "[ { \"op\":\"replace\", \"path\":\"/active\", \"value\":false } ]";
|
|
||||||
|
|
||||||
MethodOutcome outcome = client
|
|
||||||
.patch()
|
|
||||||
.withBody(patch)
|
|
||||||
.conditional(Patient.class).where(Patient.NAME.matches().value("TEST"))
|
|
||||||
.and(Patient.FAMILY.matches().value("TEST2"))
|
|
||||||
.execute();
|
|
||||||
|
|
||||||
assertEquals("http://example.com/fhir/Patient?name=TEST&family=TEST2", UrlUtil.unescape(capt.getAllValues().get(idx).getURI().toString()));
|
|
||||||
assertEquals("PATCH", capt.getAllValues().get(0).getRequestLine().getMethod());
|
|
||||||
assertEquals(patch, extractBodyAsString(capt));
|
|
||||||
assertEquals(Constants.CT_JSON_PATCH, capt.getAllValues().get(idx).getFirstHeader("Content-Type").getValue().replaceAll(";.*", ""));
|
|
||||||
idx++;
|
|
||||||
|
|
||||||
OperationOutcome oo = (OperationOutcome) outcome.getOperationOutcome();
|
|
||||||
assertThat(oo.getText().getDivAsString(), containsString("OK!"));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testPatchXmlByIdString() throws Exception {
|
|
||||||
OperationOutcome conf = new OperationOutcome();
|
|
||||||
conf.getText().setDivAsString("OK!");
|
|
||||||
final String respString = ourCtx.newJsonParser().encodeResourceToString(conf);
|
|
||||||
|
|
||||||
ArgumentCaptor<HttpUriRequest> capt = ArgumentCaptor.forClass(HttpUriRequest.class);
|
|
||||||
when(myHttpClient.execute(capt.capture())).thenReturn(myHttpResponse);
|
|
||||||
when(myHttpResponse.getStatusLine()).thenReturn(new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), 200, "OK"));
|
|
||||||
when(myHttpResponse.getEntity().getContentType()).thenReturn(new BasicHeader("content-type", Constants.CT_FHIR_JSON + "; charset=UTF-8"));
|
|
||||||
when(myHttpResponse.getEntity().getContent()).then(new Answer<InputStream>() {
|
|
||||||
@Override
|
|
||||||
public InputStream answer(InvocationOnMock theInvocation) throws Throwable {
|
|
||||||
return new ReaderInputStream(new StringReader(respString), Charset.forName("UTF-8"));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
IGenericClient client = ourCtx.newRestfulGenericClient("http://example.com/fhir");
|
|
||||||
int idx = 0;
|
|
||||||
|
|
||||||
String patch = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><diff xmlns:fhir=\"http://hl7.org/fhir\"><replace sel=\"fhir:Patient/fhir:active/@value\">false</replace></diff>";
|
|
||||||
|
|
||||||
MethodOutcome outcome = client
|
|
||||||
.patch()
|
|
||||||
.withBody(patch)
|
|
||||||
.withId("Patient/123")
|
|
||||||
.execute();
|
|
||||||
|
|
||||||
assertEquals("http://example.com/fhir/Patient/123", UrlUtil.unescape(capt.getAllValues().get(idx).getURI().toString()));
|
|
||||||
assertEquals("PATCH", capt.getAllValues().get(0).getRequestLine().getMethod());
|
|
||||||
assertEquals(patch, extractBodyAsString(capt));
|
|
||||||
assertEquals(Constants.CT_XML_PATCH, capt.getAllValues().get(idx).getFirstHeader("Content-Type").getValue().replaceAll(";.*", ""));
|
|
||||||
idx++;
|
|
||||||
|
|
||||||
OperationOutcome oo = (OperationOutcome) outcome.getOperationOutcome();
|
|
||||||
assertThat(oo.getText().getDivAsString(), containsString("OK!"));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testPatchInvalid() throws Exception {
|
|
||||||
IGenericClient client = ourCtx.newRestfulGenericClient("http://example.com/fhir");
|
|
||||||
|
|
||||||
try {
|
|
||||||
client
|
|
||||||
.patch()
|
|
||||||
.withBody("AA")
|
|
||||||
.withId("Patient/123")
|
|
||||||
.execute();
|
|
||||||
} catch (IllegalArgumentException e) {
|
|
||||||
assertEquals("Unable to determine encoding of patch", e.getMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testAcceptHeaderWithEncodingSpecified() throws Exception {
|
public void testAcceptHeaderWithEncodingSpecified() throws Exception {
|
||||||
final String msg = "{\"resourceType\":\"Bundle\",\"id\":null,\"base\":\"http://localhost:57931/fhir/contextDev\",\"total\":1,\"link\":[{\"relation\":\"self\",\"url\":\"http://localhost:57931/fhir/contextDev/Patient?identifier=urn%3AMultiFhirVersionTest%7CtestSubmitPatient01&_format=json\"}],\"entry\":[{\"resource\":{\"resourceType\":\"Patient\",\"id\":\"1\",\"meta\":{\"versionId\":\"1\",\"lastUpdated\":\"2014-12-20T18:41:29.706-05:00\"},\"identifier\":[{\"system\":\"urn:MultiFhirVersionTest\",\"value\":\"testSubmitPatient01\"}]}}]}";
|
final String msg = "{\"resourceType\":\"Bundle\",\"id\":null,\"base\":\"http://localhost:57931/fhir/contextDev\",\"total\":1,\"link\":[{\"relation\":\"self\",\"url\":\"http://localhost:57931/fhir/contextDev/Patient?identifier=urn%3AMultiFhirVersionTest%7CtestSubmitPatient01&_format=json\"}],\"entry\":[{\"resource\":{\"resourceType\":\"Patient\",\"id\":\"1\",\"meta\":{\"versionId\":\"1\",\"lastUpdated\":\"2014-12-20T18:41:29.706-05:00\"},\"identifier\":[{\"system\":\"urn:MultiFhirVersionTest\",\"value\":\"testSubmitPatient01\"}]}}]}";
|
||||||
|
@ -923,18 +666,6 @@ public class GenericClientR4Test {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
|
||||||
@Test
|
|
||||||
public void testInvalidConformanceCall() {
|
|
||||||
IGenericClient client = ourCtx.newRestfulGenericClient("http://example.com/fhir");
|
|
||||||
try {
|
|
||||||
client.conformance();
|
|
||||||
fail();
|
|
||||||
} catch (IllegalArgumentException e) {
|
|
||||||
assertEquals("Must call fetchConformance() instead of conformance() for RI/STU3+ structures", e.getMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* See #150
|
* See #150
|
||||||
*/
|
*/
|
||||||
|
@ -980,6 +711,251 @@ public class GenericClientR4Test {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testPatchInvalid() throws Exception {
|
||||||
|
IGenericClient client = ourCtx.newRestfulGenericClient("http://example.com/fhir");
|
||||||
|
|
||||||
|
try {
|
||||||
|
client
|
||||||
|
.patch()
|
||||||
|
.withBody("AA")
|
||||||
|
.withId("Patient/123")
|
||||||
|
.execute();
|
||||||
|
} catch (IllegalArgumentException e) {
|
||||||
|
assertEquals("Unable to determine encoding of patch", e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testPatchJsonByConditionalParam() throws Exception {
|
||||||
|
OperationOutcome conf = new OperationOutcome();
|
||||||
|
conf.getText().setDivAsString("OK!");
|
||||||
|
final String respString = ourCtx.newJsonParser().encodeResourceToString(conf);
|
||||||
|
|
||||||
|
ArgumentCaptor<HttpUriRequest> capt = ArgumentCaptor.forClass(HttpUriRequest.class);
|
||||||
|
when(myHttpClient.execute(capt.capture())).thenReturn(myHttpResponse);
|
||||||
|
when(myHttpResponse.getStatusLine()).thenReturn(new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), 200, "OK"));
|
||||||
|
when(myHttpResponse.getEntity().getContentType()).thenReturn(new BasicHeader("content-type", Constants.CT_FHIR_JSON + "; charset=UTF-8"));
|
||||||
|
when(myHttpResponse.getEntity().getContent()).then(new Answer<InputStream>() {
|
||||||
|
@Override
|
||||||
|
public InputStream answer(InvocationOnMock theInvocation) throws Throwable {
|
||||||
|
return new ReaderInputStream(new StringReader(respString), Charset.forName("UTF-8"));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
IGenericClient client = ourCtx.newRestfulGenericClient("http://example.com/fhir");
|
||||||
|
int idx = 0;
|
||||||
|
|
||||||
|
String patch = "[ { \"op\":\"replace\", \"path\":\"/active\", \"value\":false } ]";
|
||||||
|
|
||||||
|
MethodOutcome outcome = client
|
||||||
|
.patch()
|
||||||
|
.withBody(patch)
|
||||||
|
.conditional("Patient").where(Patient.NAME.matches().value("TEST"))
|
||||||
|
.and(Patient.FAMILY.matches().value("TEST2"))
|
||||||
|
.execute();
|
||||||
|
|
||||||
|
assertEquals("http://example.com/fhir/Patient?name=TEST&family=TEST2", UrlUtil.unescape(capt.getAllValues().get(idx).getURI().toString()));
|
||||||
|
assertEquals("PATCH", capt.getAllValues().get(0).getRequestLine().getMethod());
|
||||||
|
assertEquals(patch, extractBodyAsString(capt));
|
||||||
|
assertEquals(Constants.CT_JSON_PATCH, capt.getAllValues().get(idx).getFirstHeader("Content-Type").getValue().replaceAll(";.*", ""));
|
||||||
|
idx++;
|
||||||
|
|
||||||
|
OperationOutcome oo = (OperationOutcome) outcome.getOperationOutcome();
|
||||||
|
assertThat(oo.getText().getDivAsString(), containsString("OK!"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testPatchJsonByConditionalParamResourceType() throws Exception {
|
||||||
|
OperationOutcome conf = new OperationOutcome();
|
||||||
|
conf.getText().setDivAsString("OK!");
|
||||||
|
final String respString = ourCtx.newJsonParser().encodeResourceToString(conf);
|
||||||
|
|
||||||
|
ArgumentCaptor<HttpUriRequest> capt = ArgumentCaptor.forClass(HttpUriRequest.class);
|
||||||
|
when(myHttpClient.execute(capt.capture())).thenReturn(myHttpResponse);
|
||||||
|
when(myHttpResponse.getStatusLine()).thenReturn(new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), 200, "OK"));
|
||||||
|
when(myHttpResponse.getEntity().getContentType()).thenReturn(new BasicHeader("content-type", Constants.CT_FHIR_JSON + "; charset=UTF-8"));
|
||||||
|
when(myHttpResponse.getEntity().getContent()).then(new Answer<InputStream>() {
|
||||||
|
@Override
|
||||||
|
public InputStream answer(InvocationOnMock theInvocation) throws Throwable {
|
||||||
|
return new ReaderInputStream(new StringReader(respString), Charset.forName("UTF-8"));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
IGenericClient client = ourCtx.newRestfulGenericClient("http://example.com/fhir");
|
||||||
|
int idx = 0;
|
||||||
|
|
||||||
|
String patch = "[ { \"op\":\"replace\", \"path\":\"/active\", \"value\":false } ]";
|
||||||
|
|
||||||
|
MethodOutcome outcome = client
|
||||||
|
.patch()
|
||||||
|
.withBody(patch)
|
||||||
|
.conditional(Patient.class).where(Patient.NAME.matches().value("TEST"))
|
||||||
|
.and(Patient.FAMILY.matches().value("TEST2"))
|
||||||
|
.execute();
|
||||||
|
|
||||||
|
assertEquals("http://example.com/fhir/Patient?name=TEST&family=TEST2", UrlUtil.unescape(capt.getAllValues().get(idx).getURI().toString()));
|
||||||
|
assertEquals("PATCH", capt.getAllValues().get(0).getRequestLine().getMethod());
|
||||||
|
assertEquals(patch, extractBodyAsString(capt));
|
||||||
|
assertEquals(Constants.CT_JSON_PATCH, capt.getAllValues().get(idx).getFirstHeader("Content-Type").getValue().replaceAll(";.*", ""));
|
||||||
|
idx++;
|
||||||
|
|
||||||
|
OperationOutcome oo = (OperationOutcome) outcome.getOperationOutcome();
|
||||||
|
assertThat(oo.getText().getDivAsString(), containsString("OK!"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testPatchJsonByConditionalString() throws Exception {
|
||||||
|
OperationOutcome conf = new OperationOutcome();
|
||||||
|
conf.getText().setDivAsString("OK!");
|
||||||
|
final String respString = ourCtx.newJsonParser().encodeResourceToString(conf);
|
||||||
|
|
||||||
|
ArgumentCaptor<HttpUriRequest> capt = ArgumentCaptor.forClass(HttpUriRequest.class);
|
||||||
|
when(myHttpClient.execute(capt.capture())).thenReturn(myHttpResponse);
|
||||||
|
when(myHttpResponse.getStatusLine()).thenReturn(new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), 200, "OK"));
|
||||||
|
when(myHttpResponse.getEntity().getContentType()).thenReturn(new BasicHeader("content-type", Constants.CT_FHIR_JSON + "; charset=UTF-8"));
|
||||||
|
when(myHttpResponse.getEntity().getContent()).then(new Answer<InputStream>() {
|
||||||
|
@Override
|
||||||
|
public InputStream answer(InvocationOnMock theInvocation) throws Throwable {
|
||||||
|
return new ReaderInputStream(new StringReader(respString), Charset.forName("UTF-8"));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
IGenericClient client = ourCtx.newRestfulGenericClient("http://example.com/fhir");
|
||||||
|
int idx = 0;
|
||||||
|
|
||||||
|
String patch = "[ { \"op\":\"replace\", \"path\":\"/active\", \"value\":false } ]";
|
||||||
|
|
||||||
|
MethodOutcome outcome = client
|
||||||
|
.patch()
|
||||||
|
.withBody(patch)
|
||||||
|
.conditionalByUrl("Patient?foo=bar")
|
||||||
|
.execute();
|
||||||
|
|
||||||
|
assertEquals("http://example.com/fhir/Patient?foo=bar", UrlUtil.unescape(capt.getAllValues().get(idx).getURI().toString()));
|
||||||
|
assertEquals("PATCH", capt.getAllValues().get(0).getRequestLine().getMethod());
|
||||||
|
assertEquals(patch, extractBodyAsString(capt));
|
||||||
|
assertEquals(Constants.CT_JSON_PATCH, capt.getAllValues().get(idx).getFirstHeader("Content-Type").getValue().replaceAll(";.*", ""));
|
||||||
|
idx++;
|
||||||
|
|
||||||
|
OperationOutcome oo = (OperationOutcome) outcome.getOperationOutcome();
|
||||||
|
assertThat(oo.getText().getDivAsString(), containsString("OK!"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testPatchJsonByIdString() throws Exception {
|
||||||
|
OperationOutcome conf = new OperationOutcome();
|
||||||
|
conf.getText().setDivAsString("OK!");
|
||||||
|
final String respString = ourCtx.newJsonParser().encodeResourceToString(conf);
|
||||||
|
|
||||||
|
ArgumentCaptor<HttpUriRequest> capt = ArgumentCaptor.forClass(HttpUriRequest.class);
|
||||||
|
when(myHttpClient.execute(capt.capture())).thenReturn(myHttpResponse);
|
||||||
|
when(myHttpResponse.getStatusLine()).thenReturn(new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), 200, "OK"));
|
||||||
|
when(myHttpResponse.getEntity().getContentType()).thenReturn(new BasicHeader("content-type", Constants.CT_FHIR_JSON + "; charset=UTF-8"));
|
||||||
|
when(myHttpResponse.getEntity().getContent()).then(new Answer<InputStream>() {
|
||||||
|
@Override
|
||||||
|
public InputStream answer(InvocationOnMock theInvocation) throws Throwable {
|
||||||
|
return new ReaderInputStream(new StringReader(respString), Charset.forName("UTF-8"));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
IGenericClient client = ourCtx.newRestfulGenericClient("http://example.com/fhir");
|
||||||
|
int idx = 0;
|
||||||
|
|
||||||
|
String patch = "[ { \"op\":\"replace\", \"path\":\"/active\", \"value\":false } ]";
|
||||||
|
|
||||||
|
MethodOutcome outcome = client
|
||||||
|
.patch()
|
||||||
|
.withBody(patch)
|
||||||
|
.withId("Patient/123")
|
||||||
|
.execute();
|
||||||
|
|
||||||
|
assertEquals("http://example.com/fhir/Patient/123", UrlUtil.unescape(capt.getAllValues().get(idx).getURI().toString()));
|
||||||
|
assertEquals("PATCH", capt.getAllValues().get(0).getRequestLine().getMethod());
|
||||||
|
assertEquals(patch, extractBodyAsString(capt));
|
||||||
|
assertEquals(Constants.CT_JSON_PATCH, capt.getAllValues().get(idx).getFirstHeader("Content-Type").getValue().replaceAll(";.*", ""));
|
||||||
|
idx++;
|
||||||
|
|
||||||
|
OperationOutcome oo = (OperationOutcome) outcome.getOperationOutcome();
|
||||||
|
assertThat(oo.getText().getDivAsString(), containsString("OK!"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testPatchJsonByIdType() throws Exception {
|
||||||
|
OperationOutcome conf = new OperationOutcome();
|
||||||
|
conf.getText().setDivAsString("OK!");
|
||||||
|
final String respString = ourCtx.newJsonParser().encodeResourceToString(conf);
|
||||||
|
|
||||||
|
ArgumentCaptor<HttpUriRequest> capt = ArgumentCaptor.forClass(HttpUriRequest.class);
|
||||||
|
when(myHttpClient.execute(capt.capture())).thenReturn(myHttpResponse);
|
||||||
|
when(myHttpResponse.getStatusLine()).thenReturn(new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), 200, "OK"));
|
||||||
|
when(myHttpResponse.getEntity().getContentType()).thenReturn(new BasicHeader("content-type", Constants.CT_FHIR_JSON + "; charset=UTF-8"));
|
||||||
|
when(myHttpResponse.getEntity().getContent()).then(new Answer<InputStream>() {
|
||||||
|
@Override
|
||||||
|
public InputStream answer(InvocationOnMock theInvocation) throws Throwable {
|
||||||
|
return new ReaderInputStream(new StringReader(respString), Charset.forName("UTF-8"));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
IGenericClient client = ourCtx.newRestfulGenericClient("http://example.com/fhir");
|
||||||
|
int idx = 0;
|
||||||
|
|
||||||
|
String patch = "[ { \"op\":\"replace\", \"path\":\"/active\", \"value\":false } ]";
|
||||||
|
|
||||||
|
MethodOutcome outcome = client
|
||||||
|
.patch()
|
||||||
|
.withBody(patch)
|
||||||
|
.withId(new IdType("http://localhost/fhir/Patient/123/_history/234"))
|
||||||
|
.execute();
|
||||||
|
|
||||||
|
assertEquals("http://example.com/fhir/Patient/123", UrlUtil.unescape(capt.getAllValues().get(idx).getURI().toString()));
|
||||||
|
assertEquals("PATCH", capt.getAllValues().get(0).getRequestLine().getMethod());
|
||||||
|
assertEquals(patch, extractBodyAsString(capt));
|
||||||
|
assertEquals(Constants.CT_JSON_PATCH, capt.getAllValues().get(idx).getFirstHeader("Content-Type").getValue().replaceAll(";.*", ""));
|
||||||
|
idx++;
|
||||||
|
|
||||||
|
OperationOutcome oo = (OperationOutcome) outcome.getOperationOutcome();
|
||||||
|
assertThat(oo.getText().getDivAsString(), containsString("OK!"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testPatchXmlByIdString() throws Exception {
|
||||||
|
OperationOutcome conf = new OperationOutcome();
|
||||||
|
conf.getText().setDivAsString("OK!");
|
||||||
|
final String respString = ourCtx.newJsonParser().encodeResourceToString(conf);
|
||||||
|
|
||||||
|
ArgumentCaptor<HttpUriRequest> capt = ArgumentCaptor.forClass(HttpUriRequest.class);
|
||||||
|
when(myHttpClient.execute(capt.capture())).thenReturn(myHttpResponse);
|
||||||
|
when(myHttpResponse.getStatusLine()).thenReturn(new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), 200, "OK"));
|
||||||
|
when(myHttpResponse.getEntity().getContentType()).thenReturn(new BasicHeader("content-type", Constants.CT_FHIR_JSON + "; charset=UTF-8"));
|
||||||
|
when(myHttpResponse.getEntity().getContent()).then(new Answer<InputStream>() {
|
||||||
|
@Override
|
||||||
|
public InputStream answer(InvocationOnMock theInvocation) throws Throwable {
|
||||||
|
return new ReaderInputStream(new StringReader(respString), Charset.forName("UTF-8"));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
IGenericClient client = ourCtx.newRestfulGenericClient("http://example.com/fhir");
|
||||||
|
int idx = 0;
|
||||||
|
|
||||||
|
String patch = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><diff xmlns:fhir=\"http://hl7.org/fhir\"><replace sel=\"fhir:Patient/fhir:active/@value\">false</replace></diff>";
|
||||||
|
|
||||||
|
MethodOutcome outcome = client
|
||||||
|
.patch()
|
||||||
|
.withBody(patch)
|
||||||
|
.withId("Patient/123")
|
||||||
|
.execute();
|
||||||
|
|
||||||
|
assertEquals("http://example.com/fhir/Patient/123", UrlUtil.unescape(capt.getAllValues().get(idx).getURI().toString()));
|
||||||
|
assertEquals("PATCH", capt.getAllValues().get(0).getRequestLine().getMethod());
|
||||||
|
assertEquals(patch, extractBodyAsString(capt));
|
||||||
|
assertEquals(Constants.CT_XML_PATCH, capt.getAllValues().get(idx).getFirstHeader("Content-Type").getValue().replaceAll(";.*", ""));
|
||||||
|
idx++;
|
||||||
|
|
||||||
|
OperationOutcome oo = (OperationOutcome) outcome.getOperationOutcome();
|
||||||
|
assertThat(oo.getText().getDivAsString(), containsString("OK!"));
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPutDoesntForceAllIdsJson() throws Exception {
|
public void testPutDoesntForceAllIdsJson() throws Exception {
|
||||||
IParser p = ourCtx.newJsonParser();
|
IParser p = ourCtx.newJsonParser();
|
||||||
|
@ -1152,33 +1128,24 @@ public class GenericClientR4Test {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSearchWithNullParameters() throws Exception {
|
public void testRevIncludeRecursive() throws ClientProtocolException, IOException {
|
||||||
final String msg = "{\"resourceType\":\"Bundle\",\"id\":null,\"base\":\"http://localhost:57931/fhir/contextDev\",\"total\":1,\"link\":[{\"relation\":\"self\",\"url\":\"http://localhost:57931/fhir/contextDev/Patient?identifier=urn%3AMultiFhirVersionTest%7CtestSubmitPatient01&_format=json\"}],\"entry\":[{\"resource\":{\"resourceType\":\"Patient\",\"id\":\"1\",\"meta\":{\"versionId\":\"1\",\"lastUpdated\":\"2014-12-20T18:41:29.706-05:00\"},\"identifier\":[{\"system\":\"urn:MultiFhirVersionTest\",\"value\":\"testSubmitPatient01\"}]}}]}";
|
ArgumentCaptor<HttpUriRequest> capt = prepareClientForSearchResponse();
|
||||||
|
|
||||||
ArgumentCaptor<HttpUriRequest> capt = ArgumentCaptor.forClass(HttpUriRequest.class);
|
|
||||||
when(myHttpClient.execute(capt.capture())).thenReturn(myHttpResponse);
|
|
||||||
when(myHttpResponse.getStatusLine()).thenReturn(new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), 200, "OK"));
|
|
||||||
when(myHttpResponse.getEntity().getContentType()).thenReturn(new BasicHeader("content-type", Constants.CT_FHIR_JSON + "; charset=UTF-8"));
|
|
||||||
when(myHttpResponse.getEntity().getContent()).then(new Answer<InputStream>() {
|
|
||||||
@Override
|
|
||||||
public InputStream answer(InvocationOnMock theInvocation) throws Throwable {
|
|
||||||
return new ReaderInputStream(new StringReader(msg), Charset.forName("UTF-8"));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
IGenericClient client = ourCtx.newRestfulGenericClient("http://example.com/fhir");
|
IGenericClient client = ourCtx.newRestfulGenericClient("http://example.com/fhir");
|
||||||
int idx = 0;
|
int idx = 0;
|
||||||
|
|
||||||
DateTimeDt now = DateTimeDt.withCurrentTime();
|
|
||||||
String dateString = now.getValueAsString().substring(0, 10);
|
|
||||||
|
|
||||||
client.search()
|
client.search()
|
||||||
.forResource("Patient")
|
.forResource(EpisodeOfCare.class)
|
||||||
.where(Patient.NAME.matches().value((String) null))
|
.where(EpisodeOfCare.PATIENT.hasId("123"))
|
||||||
|
.revInclude(Encounter.INCLUDE_EPISODEOFCARE)
|
||||||
|
.revInclude(Observation.INCLUDE_ENCOUNTER.asRecursive())
|
||||||
.returnBundle(Bundle.class)
|
.returnBundle(Bundle.class)
|
||||||
.execute();
|
.execute();
|
||||||
assertEquals("http://example.com/fhir/Patient", capt.getAllValues().get(idx).getURI().toString());
|
|
||||||
|
assertEquals("http://example.com/fhir/EpisodeOfCare?patient=123&_revinclude=Encounter%3Aepisodeofcare&_revinclude%3Arecurse=Observation%3Aencounter",
|
||||||
|
capt.getAllValues().get(idx).getURI().toString());
|
||||||
idx++;
|
idx++;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -1530,14 +1497,29 @@ public class GenericClientR4Test {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSearchForUnknownType() throws Exception {
|
public void testSearchWithMap() throws Exception {
|
||||||
|
String msg = "{\"resourceType\":\"Bundle\",\"id\":null,\"base\":\"http://localhost:57931/fhir/contextDev\",\"total\":1,\"link\":[{\"relation\":\"self\",\"url\":\"http://localhost:57931/fhir/contextDev/Patient?identifier=urn%3AMultiFhirVersionTest%7CtestSubmitPatient01&_format=json\"}],\"entry\":[{\"resource\":{\"resourceType\":\"Patient\",\"id\":\"1\",\"meta\":{\"versionId\":\"1\",\"lastUpdated\":\"2014-12-20T18:41:29.706-05:00\"},\"identifier\":[{\"system\":\"urn:MultiFhirVersionTest\",\"value\":\"testSubmitPatient01\"}]}}]}";
|
||||||
|
|
||||||
|
ArgumentCaptor<HttpUriRequest> capt = ArgumentCaptor.forClass(HttpUriRequest.class);
|
||||||
|
when(myHttpClient.execute(capt.capture())).thenReturn(myHttpResponse);
|
||||||
|
when(myHttpResponse.getStatusLine()).thenReturn(new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), 200, "OK"));
|
||||||
|
when(myHttpResponse.getEntity().getContentType()).thenReturn(new BasicHeader("content-type", Constants.CT_FHIR_JSON + "; charset=UTF-8"));
|
||||||
|
when(myHttpResponse.getEntity().getContent()).thenReturn(new ReaderInputStream(new StringReader(msg), Charset.forName("UTF-8")));
|
||||||
|
|
||||||
IGenericClient client = ourCtx.newRestfulGenericClient("http://example.com/fhir");
|
IGenericClient client = ourCtx.newRestfulGenericClient("http://example.com/fhir");
|
||||||
try {
|
|
||||||
client.search(new UriDt("?aaaa"));
|
HashMap<String, List<IQueryParameterType>> params = new HashMap<String, List<IQueryParameterType>>();
|
||||||
fail();
|
params.put("foo", Arrays.asList((IQueryParameterType) new DateParam("2001")));
|
||||||
} catch (IllegalArgumentException e) {
|
Bundle response = client
|
||||||
assertEquals("Unable to determine the resource type from the given URI: ?aaaa", e.getMessage());
|
.search()
|
||||||
}
|
.forResource(Patient.class)
|
||||||
|
.where(params)
|
||||||
|
.returnBundle(Bundle.class)
|
||||||
|
.execute();
|
||||||
|
|
||||||
|
assertEquals("http://example.com/fhir/Patient?foo=2001", capt.getValue().getURI().toString());
|
||||||
|
assertEquals(Patient.class, response.getEntry().get(0).getResource().getClass());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -1561,6 +1543,36 @@ public class GenericClientR4Test {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testSearchWithNullParameters() throws Exception {
|
||||||
|
final String msg = "{\"resourceType\":\"Bundle\",\"id\":null,\"base\":\"http://localhost:57931/fhir/contextDev\",\"total\":1,\"link\":[{\"relation\":\"self\",\"url\":\"http://localhost:57931/fhir/contextDev/Patient?identifier=urn%3AMultiFhirVersionTest%7CtestSubmitPatient01&_format=json\"}],\"entry\":[{\"resource\":{\"resourceType\":\"Patient\",\"id\":\"1\",\"meta\":{\"versionId\":\"1\",\"lastUpdated\":\"2014-12-20T18:41:29.706-05:00\"},\"identifier\":[{\"system\":\"urn:MultiFhirVersionTest\",\"value\":\"testSubmitPatient01\"}]}}]}";
|
||||||
|
|
||||||
|
ArgumentCaptor<HttpUriRequest> capt = ArgumentCaptor.forClass(HttpUriRequest.class);
|
||||||
|
when(myHttpClient.execute(capt.capture())).thenReturn(myHttpResponse);
|
||||||
|
when(myHttpResponse.getStatusLine()).thenReturn(new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), 200, "OK"));
|
||||||
|
when(myHttpResponse.getEntity().getContentType()).thenReturn(new BasicHeader("content-type", Constants.CT_FHIR_JSON + "; charset=UTF-8"));
|
||||||
|
when(myHttpResponse.getEntity().getContent()).then(new Answer<InputStream>() {
|
||||||
|
@Override
|
||||||
|
public InputStream answer(InvocationOnMock theInvocation) throws Throwable {
|
||||||
|
return new ReaderInputStream(new StringReader(msg), Charset.forName("UTF-8"));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
IGenericClient client = ourCtx.newRestfulGenericClient("http://example.com/fhir");
|
||||||
|
int idx = 0;
|
||||||
|
|
||||||
|
DateTimeDt now = DateTimeDt.withCurrentTime();
|
||||||
|
String dateString = now.getValueAsString().substring(0, 10);
|
||||||
|
|
||||||
|
client.search()
|
||||||
|
.forResource("Patient")
|
||||||
|
.where(Patient.NAME.matches().value((String) null))
|
||||||
|
.returnBundle(Bundle.class)
|
||||||
|
.execute();
|
||||||
|
assertEquals("http://example.com/fhir/Patient", capt.getAllValues().get(idx).getURI().toString());
|
||||||
|
idx++;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* See #371
|
* See #371
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -0,0 +1,654 @@
|
||||||
|
package ca.uhn.fhir.rest.server;
|
||||||
|
|
||||||
|
import static ca.uhn.fhir.util.UrlUtil.escape;
|
||||||
|
import static org.hamcrest.Matchers.containsInAnyOrder;
|
||||||
|
import static org.hamcrest.Matchers.containsString;
|
||||||
|
import static org.hamcrest.Matchers.empty;
|
||||||
|
import static org.hamcrest.Matchers.startsWith;
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertFalse;
|
||||||
|
import static org.junit.Assert.assertThat;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
import org.apache.commons.io.IOUtils;
|
||||||
|
import org.apache.http.*;
|
||||||
|
import org.apache.http.client.entity.UrlEncodedFormEntity;
|
||||||
|
import org.apache.http.client.methods.*;
|
||||||
|
import org.apache.http.entity.ByteArrayEntity;
|
||||||
|
import org.apache.http.impl.client.CloseableHttpClient;
|
||||||
|
import org.apache.http.impl.client.HttpClientBuilder;
|
||||||
|
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
|
||||||
|
import org.apache.http.message.BasicNameValuePair;
|
||||||
|
import org.eclipse.jetty.server.Server;
|
||||||
|
import org.eclipse.jetty.servlet.ServletHandler;
|
||||||
|
import org.eclipse.jetty.servlet.ServletHolder;
|
||||||
|
import org.hl7.fhir.r4.model.*;
|
||||||
|
import org.junit.*;
|
||||||
|
|
||||||
|
import ca.uhn.fhir.context.FhirContext;
|
||||||
|
import ca.uhn.fhir.model.api.Include;
|
||||||
|
import ca.uhn.fhir.narrative.DefaultThymeleafNarrativeGenerator;
|
||||||
|
import ca.uhn.fhir.rest.annotation.*;
|
||||||
|
import ca.uhn.fhir.rest.api.MethodOutcome;
|
||||||
|
import ca.uhn.fhir.rest.client.api.IGenericClient;
|
||||||
|
import ca.uhn.fhir.rest.param.*;
|
||||||
|
import ca.uhn.fhir.util.*;
|
||||||
|
|
||||||
|
public class SearchSearchServerDstu1Test {
|
||||||
|
|
||||||
|
private static CloseableHttpClient ourClient;
|
||||||
|
private static FhirContext ourCtx = FhirContext.forR4();
|
||||||
|
private static IServerAddressStrategy ourDefaultAddressStrategy;
|
||||||
|
private static StringAndListParam ourLastAndList;
|
||||||
|
|
||||||
|
private static Set<Include> ourLastIncludes;
|
||||||
|
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(SearchSearchServerDstu1Test.class);
|
||||||
|
private static int ourPort;
|
||||||
|
private static Server ourServer;
|
||||||
|
private static RestfulServer ourServlet;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void before() {
|
||||||
|
ourServlet.setServerAddressStrategy(ourDefaultAddressStrategy);
|
||||||
|
ourLastIncludes = null;
|
||||||
|
ourLastAndList = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testEncodeConvertsReferencesToRelative() throws Exception {
|
||||||
|
HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient?_query=searchWithRef");
|
||||||
|
HttpResponse status = ourClient.execute(httpGet);
|
||||||
|
String responseContent = IOUtils.toString(status.getEntity().getContent());
|
||||||
|
IOUtils.closeQuietly(status.getEntity().getContent());
|
||||||
|
ourLog.info(responseContent);
|
||||||
|
|
||||||
|
assertEquals(200, status.getStatusLine().getStatusCode());
|
||||||
|
Patient patient = (Patient) ourCtx.newXmlParser().parseResource(Bundle.class, responseContent).getEntry().get(0).getResource();
|
||||||
|
String ref = patient.getManagingOrganization().getReference();
|
||||||
|
assertEquals("Organization/555", ref);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Try loading the page as a POST just to make sure we get the right error
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testGetPagesWithPost() throws Exception {
|
||||||
|
|
||||||
|
HttpPost httpPost = new HttpPost("http://localhost:" + ourPort);
|
||||||
|
List<? extends NameValuePair> parameters = Collections.singletonList(new BasicNameValuePair("_getpages", "AAA"));
|
||||||
|
httpPost.setEntity(new UrlEncodedFormEntity(parameters));
|
||||||
|
|
||||||
|
CloseableHttpResponse status = ourClient.execute(httpPost);
|
||||||
|
String responseContent = IOUtils.toString(status.getEntity().getContent());
|
||||||
|
IOUtils.closeQuietly(status.getEntity().getContent());
|
||||||
|
ourLog.info(responseContent);
|
||||||
|
assertEquals(400, status.getStatusLine().getStatusCode());
|
||||||
|
// assertThat(responseContent, containsString("Requests for _getpages must use HTTP GET"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testOmitEmptyOptionalParam() throws Exception {
|
||||||
|
HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient?_id=");
|
||||||
|
HttpResponse status = ourClient.execute(httpGet);
|
||||||
|
String responseContent = IOUtils.toString(status.getEntity().getContent());
|
||||||
|
IOUtils.closeQuietly(status.getEntity().getContent());
|
||||||
|
assertEquals(200, status.getStatusLine().getStatusCode());
|
||||||
|
Bundle bundle = ourCtx.newXmlParser().parseResource(Bundle.class, responseContent);
|
||||||
|
assertEquals(1, bundle.getEntry().size());
|
||||||
|
|
||||||
|
Patient p = BundleUtil.toListOfResourcesOfType(ourCtx, bundle, Patient.class).get(0);
|
||||||
|
assertEquals(null, p.getNameFirstRep().getFamily());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testParseEscapedValues() throws Exception {
|
||||||
|
|
||||||
|
StringBuilder b = new StringBuilder();
|
||||||
|
b.append("http://localhost:");
|
||||||
|
b.append(ourPort);
|
||||||
|
b.append("/Patient?");
|
||||||
|
b.append(escape("findPatientWithAndList")).append('=').append(escape("NE\\,NE,NE\\,NE")).append('&');
|
||||||
|
b.append(escape("findPatientWithAndList")).append('=').append(escape("NE\\\\NE")).append('&');
|
||||||
|
b.append(escape("findPatientWithAndList:exact")).append('=').append(escape("E\\$E")).append('&');
|
||||||
|
b.append(escape("findPatientWithAndList:exact")).append('=').append(escape("E\\|E")).append('&');
|
||||||
|
|
||||||
|
HttpGet httpGet = new HttpGet(b.toString());
|
||||||
|
|
||||||
|
HttpResponse status = ourClient.execute(httpGet);
|
||||||
|
String responseContent = IOUtils.toString(status.getEntity().getContent());
|
||||||
|
IOUtils.closeQuietly(status.getEntity().getContent());
|
||||||
|
ourLog.info(responseContent);
|
||||||
|
|
||||||
|
assertEquals(200, status.getStatusLine().getStatusCode());
|
||||||
|
|
||||||
|
assertEquals(4, ourLastAndList.getValuesAsQueryTokens().size());
|
||||||
|
assertEquals(2, ourLastAndList.getValuesAsQueryTokens().get(0).getValuesAsQueryTokens().size());
|
||||||
|
assertFalse(ourLastAndList.getValuesAsQueryTokens().get(0).getValuesAsQueryTokens().get(0).isExact());
|
||||||
|
assertEquals("NE,NE", ourLastAndList.getValuesAsQueryTokens().get(0).getValuesAsQueryTokens().get(0).getValue());
|
||||||
|
assertEquals("NE,NE", ourLastAndList.getValuesAsQueryTokens().get(0).getValuesAsQueryTokens().get(1).getValue());
|
||||||
|
assertEquals("NE\\NE", ourLastAndList.getValuesAsQueryTokens().get(1).getValuesAsQueryTokens().get(0).getValue());
|
||||||
|
assertTrue(ourLastAndList.getValuesAsQueryTokens().get(2).getValuesAsQueryTokens().get(0).isExact());
|
||||||
|
assertEquals("E$E", ourLastAndList.getValuesAsQueryTokens().get(2).getValuesAsQueryTokens().get(0).getValue());
|
||||||
|
assertEquals("E|E", ourLastAndList.getValuesAsQueryTokens().get(3).getValuesAsQueryTokens().get(0).getValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testReturnLinks() throws Exception {
|
||||||
|
HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient?_query=findWithLinks");
|
||||||
|
|
||||||
|
CloseableHttpResponse status = ourClient.execute(httpGet);
|
||||||
|
String responseContent = IOUtils.toString(status.getEntity().getContent());
|
||||||
|
IOUtils.closeQuietly(status.getEntity().getContent());
|
||||||
|
assertEquals(200, status.getStatusLine().getStatusCode());
|
||||||
|
Bundle bundle = ourCtx.newXmlParser().parseResource(Bundle.class, responseContent);
|
||||||
|
assertEquals(10, bundle.getEntry().size());
|
||||||
|
|
||||||
|
Patient p = BundleUtil.toListOfResourcesOfType(ourCtx, bundle, Patient.class).get(0);
|
||||||
|
assertEquals("AAANamed", p.getIdentifierFirstRep().getValue());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* #149
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testReturnLinksWithAddressStrategy() throws Exception {
|
||||||
|
ourServlet.setServerAddressStrategy(new HardcodedServerAddressStrategy("https://blah.com/base"));
|
||||||
|
|
||||||
|
HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient?_query=findWithLinks");
|
||||||
|
|
||||||
|
CloseableHttpResponse status = ourClient.execute(httpGet);
|
||||||
|
String responseContent = IOUtils.toString(status.getEntity().getContent());
|
||||||
|
IOUtils.closeQuietly(status.getEntity().getContent());
|
||||||
|
assertEquals(200, status.getStatusLine().getStatusCode());
|
||||||
|
Bundle bundle = ourCtx.newXmlParser().parseResource(Bundle.class, responseContent);
|
||||||
|
|
||||||
|
ourLog.info(responseContent);
|
||||||
|
|
||||||
|
assertEquals(10, bundle.getEntry().size());
|
||||||
|
assertEquals("https://blah.com/base/Patient?_query=findWithLinks", bundle.getLink("self").getUrl());
|
||||||
|
|
||||||
|
Patient p = BundleUtil.toListOfResourcesOfType(ourCtx, bundle, Patient.class).get(0);
|
||||||
|
assertEquals("AAANamed", p.getIdentifierFirstRep().getValue());
|
||||||
|
|
||||||
|
String linkNext = bundle.getLink("next").getUrl();
|
||||||
|
ourLog.info(linkNext);
|
||||||
|
assertThat(linkNext, startsWith("https://blah.com/base?_getpages="));
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Load the second page
|
||||||
|
*/
|
||||||
|
String urlPart = linkNext.substring(linkNext.indexOf('?'));
|
||||||
|
String link = "http://localhost:" + ourPort + urlPart;
|
||||||
|
httpGet = new HttpGet(link);
|
||||||
|
|
||||||
|
status = ourClient.execute(httpGet);
|
||||||
|
responseContent = IOUtils.toString(status.getEntity().getContent());
|
||||||
|
IOUtils.closeQuietly(status.getEntity().getContent());
|
||||||
|
assertEquals(200, status.getStatusLine().getStatusCode());
|
||||||
|
bundle = ourCtx.newXmlParser().parseResource(Bundle.class, responseContent);
|
||||||
|
|
||||||
|
ourLog.info(responseContent);
|
||||||
|
|
||||||
|
assertEquals(10, bundle.getEntry().size());
|
||||||
|
assertEquals(linkNext, bundle.getLink("self").getUrl());
|
||||||
|
|
||||||
|
p = BundleUtil.toListOfResourcesOfType(ourCtx, bundle, Patient.class).get(0);
|
||||||
|
assertEquals("AAANamed", p.getIdentifierFirstRep().getValue());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testSearchById() throws Exception {
|
||||||
|
HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient?_id=aaa");
|
||||||
|
HttpResponse status = ourClient.execute(httpGet);
|
||||||
|
String responseContent = IOUtils.toString(status.getEntity().getContent());
|
||||||
|
IOUtils.closeQuietly(status.getEntity().getContent());
|
||||||
|
assertEquals(200, status.getStatusLine().getStatusCode());
|
||||||
|
Bundle bundle = ourCtx.newXmlParser().parseResource(Bundle.class, responseContent);
|
||||||
|
assertEquals(1, bundle.getEntry().size());
|
||||||
|
|
||||||
|
Patient p = BundleUtil.toListOfResourcesOfType(ourCtx, bundle, Patient.class).get(0);
|
||||||
|
assertEquals("idaaa", p.getNameFirstRep().getFamily());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testSearchByIdUsingClient() throws Exception {
|
||||||
|
IGenericClient client = ourCtx.newRestfulGenericClient("http://localhost:" + ourPort);
|
||||||
|
|
||||||
|
Bundle bundle = client
|
||||||
|
.search()
|
||||||
|
.forResource("Patient")
|
||||||
|
.where(BaseResource.RES_ID.exactly().code("aaa"))
|
||||||
|
.returnBundle(Bundle.class)
|
||||||
|
.execute();
|
||||||
|
assertEquals(1, bundle.getEntry().size());
|
||||||
|
|
||||||
|
Patient p = BundleUtil.toListOfResourcesOfType(ourCtx, bundle, Patient.class).get(0);
|
||||||
|
assertEquals("idaaa", p.getNameFirstRep().getFamily());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testSearchByPost() throws Exception {
|
||||||
|
HttpPost filePost = new HttpPost("http://localhost:" + ourPort + "/Patient/_search");
|
||||||
|
|
||||||
|
// add parameters to the post method
|
||||||
|
List<NameValuePair> parameters = new ArrayList<NameValuePair>();
|
||||||
|
parameters.add(new BasicNameValuePair("_id", "aaa"));
|
||||||
|
|
||||||
|
UrlEncodedFormEntity sendentity = new UrlEncodedFormEntity(parameters, "UTF-8");
|
||||||
|
filePost.setEntity(sendentity);
|
||||||
|
|
||||||
|
HttpResponse status = ourClient.execute(filePost);
|
||||||
|
String responseContent = IOUtils.toString(status.getEntity().getContent());
|
||||||
|
IOUtils.closeQuietly(status.getEntity().getContent());
|
||||||
|
assertEquals(200, status.getStatusLine().getStatusCode());
|
||||||
|
Bundle bundle = ourCtx.newXmlParser().parseResource(Bundle.class, responseContent);
|
||||||
|
assertEquals(1, bundle.getEntry().size());
|
||||||
|
|
||||||
|
Patient p = BundleUtil.toListOfResourcesOfType(ourCtx, bundle, Patient.class).get(0);
|
||||||
|
assertEquals("idaaa", p.getNameFirstRep().getFamily());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* See #164
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testSearchByPostWithInvalidPostUrl() throws Exception {
|
||||||
|
HttpPost filePost = new HttpPost("http://localhost:" + ourPort + "/Patient?name=Central"); // should end with
|
||||||
|
// _search
|
||||||
|
|
||||||
|
// add parameters to the post method
|
||||||
|
List<NameValuePair> parameters = new ArrayList<NameValuePair>();
|
||||||
|
parameters.add(new BasicNameValuePair("_id", "aaa"));
|
||||||
|
|
||||||
|
UrlEncodedFormEntity sendentity = new UrlEncodedFormEntity(parameters, "UTF-8");
|
||||||
|
filePost.setEntity(sendentity);
|
||||||
|
|
||||||
|
HttpResponse status = ourClient.execute(filePost);
|
||||||
|
String responseContent = IOUtils.toString(status.getEntity().getContent());
|
||||||
|
IOUtils.closeQuietly(status.getEntity().getContent());
|
||||||
|
ourLog.info(responseContent);
|
||||||
|
assertEquals(400, status.getStatusLine().getStatusCode());
|
||||||
|
assertThat(responseContent, containsString(
|
||||||
|
"<diagnostics value=\"Incorrect Content-Type header value of "application/x-www-form-urlencoded; charset=UTF-8" was provided in the request. A FHIR Content-Type is required for "CREATE" operation\"/>"));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* See #164
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testSearchByPostWithMissingContentType() throws Exception {
|
||||||
|
HttpPost filePost = new HttpPost("http://localhost:" + ourPort + "/Patient?name=Central"); // should end with
|
||||||
|
// _search
|
||||||
|
|
||||||
|
HttpEntity sendentity = new ByteArrayEntity(new byte[] { 1, 2, 3, 4 });
|
||||||
|
filePost.setEntity(sendentity);
|
||||||
|
|
||||||
|
HttpResponse status = ourClient.execute(filePost);
|
||||||
|
String responseContent = IOUtils.toString(status.getEntity().getContent());
|
||||||
|
IOUtils.closeQuietly(status.getEntity().getContent());
|
||||||
|
ourLog.info(responseContent);
|
||||||
|
assertEquals(400, status.getStatusLine().getStatusCode());
|
||||||
|
assertThat(responseContent, containsString("<diagnostics value=\"No Content-Type header was provided in the request. This is required for "CREATE" operation\"/>"));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* See #164
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testSearchByPostWithParamsInBodyAndUrl() throws Exception {
|
||||||
|
HttpPost filePost = new HttpPost("http://localhost:" + ourPort + "/Patient/_search?name=Central");
|
||||||
|
|
||||||
|
// add parameters to the post method
|
||||||
|
List<NameValuePair> parameters = new ArrayList<NameValuePair>();
|
||||||
|
parameters.add(new BasicNameValuePair("_id", "aaa"));
|
||||||
|
|
||||||
|
UrlEncodedFormEntity sendentity = new UrlEncodedFormEntity(parameters, "UTF-8");
|
||||||
|
filePost.setEntity(sendentity);
|
||||||
|
|
||||||
|
HttpResponse status = ourClient.execute(filePost);
|
||||||
|
String responseContent = IOUtils.toString(status.getEntity().getContent());
|
||||||
|
IOUtils.closeQuietly(status.getEntity().getContent());
|
||||||
|
ourLog.info(responseContent);
|
||||||
|
assertEquals(200, status.getStatusLine().getStatusCode());
|
||||||
|
|
||||||
|
Bundle bundle = ourCtx.newXmlParser().parseResource(Bundle.class, responseContent);
|
||||||
|
assertEquals(1, bundle.getEntry().size());
|
||||||
|
|
||||||
|
Patient p = BundleUtil.toListOfResourcesOfType(ourCtx, bundle, Patient.class).get(0);
|
||||||
|
assertEquals("idaaa", p.getName().get(0).getFamily());
|
||||||
|
assertEquals("nameCentral", p.getName().get(1).getGiven().get(0).getValue());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testSearchCompartment() throws Exception {
|
||||||
|
HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient/123/fooCompartment");
|
||||||
|
HttpResponse status = ourClient.execute(httpGet);
|
||||||
|
String responseContent = IOUtils.toString(status.getEntity().getContent());
|
||||||
|
ourLog.info(responseContent);
|
||||||
|
IOUtils.closeQuietly(status.getEntity().getContent());
|
||||||
|
assertEquals(200, status.getStatusLine().getStatusCode());
|
||||||
|
Bundle bundle = ourCtx.newXmlParser().parseResource(Bundle.class, responseContent);
|
||||||
|
assertEquals(1, bundle.getEntry().size());
|
||||||
|
|
||||||
|
Patient p = BundleUtil.toListOfResourcesOfType(ourCtx, bundle, Patient.class).get(0);
|
||||||
|
assertEquals("fooCompartment", p.getIdentifierFirstRep().getValue());
|
||||||
|
assertThat(bundle.getEntry().get(0).getResource().getIdElement().getValue(), containsString("Patient/123"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testSearchGetWithUnderscoreSearch() throws Exception {
|
||||||
|
HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Observation/_search?subject%3APatient=100&name=3141-9%2C8302-2%2C8287-5%2C39156-5");
|
||||||
|
|
||||||
|
HttpResponse status = ourClient.execute(httpGet);
|
||||||
|
String responseContent = IOUtils.toString(status.getEntity().getContent());
|
||||||
|
IOUtils.closeQuietly(status.getEntity().getContent());
|
||||||
|
|
||||||
|
assertEquals(200, status.getStatusLine().getStatusCode());
|
||||||
|
Bundle bundle = ourCtx.newXmlParser().parseResource(Bundle.class, responseContent);
|
||||||
|
assertEquals(1, bundle.getEntry().size());
|
||||||
|
|
||||||
|
Observation p = BundleUtil.toListOfResourcesOfType(ourCtx, bundle, Observation.class).get(0);
|
||||||
|
assertEquals("Patient/100", p.getSubject().getReference().toString());
|
||||||
|
assertEquals(4, p.getCode().getCoding().size());
|
||||||
|
assertEquals("3141-9", p.getCode().getCoding().get(0).getCode());
|
||||||
|
assertEquals("8302-2", p.getCode().getCoding().get(1).getCode());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testSearchIncludesParametersIncludes() throws Exception {
|
||||||
|
HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient?_query=searchIncludes&_include=foo&_include:recurse=bar");
|
||||||
|
|
||||||
|
CloseableHttpResponse status = ourClient.execute(httpGet);
|
||||||
|
IOUtils.toString(status.getEntity().getContent());
|
||||||
|
IOUtils.closeQuietly(status.getEntity().getContent());
|
||||||
|
assertEquals(200, status.getStatusLine().getStatusCode());
|
||||||
|
|
||||||
|
assertEquals(2, ourLastIncludes.size());
|
||||||
|
assertThat(ourLastIncludes, containsInAnyOrder(new Include("foo", false), new Include("bar", true)));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testSearchIncludesParametersIncludesList() throws Exception {
|
||||||
|
HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient?_query=searchIncludesList&_include=foo&_include:recurse=bar");
|
||||||
|
|
||||||
|
CloseableHttpResponse status = ourClient.execute(httpGet);
|
||||||
|
IOUtils.toString(status.getEntity().getContent());
|
||||||
|
IOUtils.closeQuietly(status.getEntity().getContent());
|
||||||
|
assertEquals(200, status.getStatusLine().getStatusCode());
|
||||||
|
|
||||||
|
assertEquals(2, ourLastIncludes.size());
|
||||||
|
assertThat(ourLastIncludes, containsInAnyOrder(new Include("foo", false), new Include("bar", true)));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testSearchIncludesParametersNone() throws Exception {
|
||||||
|
HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient?_query=searchIncludes");
|
||||||
|
|
||||||
|
CloseableHttpResponse status = ourClient.execute(httpGet);
|
||||||
|
IOUtils.toString(status.getEntity().getContent());
|
||||||
|
IOUtils.closeQuietly(status.getEntity().getContent());
|
||||||
|
assertEquals(200, status.getStatusLine().getStatusCode());
|
||||||
|
|
||||||
|
assertThat(ourLastIncludes, empty());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testSearchWithOrList() throws Exception {
|
||||||
|
HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient?findPatientWithOrList=aaa,bbb");
|
||||||
|
HttpResponse status = ourClient.execute(httpGet);
|
||||||
|
String responseContent = IOUtils.toString(status.getEntity().getContent());
|
||||||
|
IOUtils.closeQuietly(status.getEntity().getContent());
|
||||||
|
assertEquals(200, status.getStatusLine().getStatusCode());
|
||||||
|
Bundle bundle = ourCtx.newXmlParser().parseResource(Bundle.class, responseContent);
|
||||||
|
assertEquals(1, bundle.getEntry().size());
|
||||||
|
|
||||||
|
Patient p = BundleUtil.toListOfResourcesOfType(ourCtx, bundle, Patient.class).get(0);
|
||||||
|
assertEquals("aaa", p.getIdentifier().get(0).getValue());
|
||||||
|
assertEquals("bbb", p.getIdentifier().get(1).getValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testSearchWithTokenParameter() throws Exception {
|
||||||
|
String token = UrlUtil.escape("http://www.dmix.gov/vista/2957|301");
|
||||||
|
HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient?tokenParam=" + token);
|
||||||
|
HttpResponse status = ourClient.execute(httpGet);
|
||||||
|
String responseContent = IOUtils.toString(status.getEntity().getContent());
|
||||||
|
IOUtils.closeQuietly(status.getEntity().getContent());
|
||||||
|
assertEquals(200, status.getStatusLine().getStatusCode());
|
||||||
|
Bundle bundle = ourCtx.newXmlParser().parseResource(Bundle.class, responseContent);
|
||||||
|
assertEquals(1, bundle.getEntry().size());
|
||||||
|
|
||||||
|
Patient p = BundleUtil.toListOfResourcesOfType(ourCtx, bundle, Patient.class).get(0);
|
||||||
|
assertEquals("http://www.dmix.gov/vista/2957", p.getNameFirstRep().getFamily());
|
||||||
|
assertEquals("301", p.getNameFirstRep().getGivenAsSingleString());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testSpecificallyNamedQueryGetsPrecedence() throws Exception {
|
||||||
|
HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient?AAA=123");
|
||||||
|
|
||||||
|
HttpResponse status = ourClient.execute(httpGet);
|
||||||
|
String responseContent = IOUtils.toString(status.getEntity().getContent());
|
||||||
|
IOUtils.closeQuietly(status.getEntity().getContent());
|
||||||
|
assertEquals(200, status.getStatusLine().getStatusCode());
|
||||||
|
Bundle bundle = ourCtx.newXmlParser().parseResource(Bundle.class, responseContent);
|
||||||
|
assertEquals(1, bundle.getEntry().size());
|
||||||
|
|
||||||
|
Patient p = BundleUtil.toListOfResourcesOfType(ourCtx, bundle, Patient.class).get(0);
|
||||||
|
assertEquals("AAA", p.getIdentifierFirstRep().getValue());
|
||||||
|
|
||||||
|
// Now the named query
|
||||||
|
|
||||||
|
httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient?_query=findPatientByAAA&AAA=123");
|
||||||
|
|
||||||
|
status = ourClient.execute(httpGet);
|
||||||
|
responseContent = IOUtils.toString(status.getEntity().getContent());
|
||||||
|
IOUtils.closeQuietly(status.getEntity().getContent());
|
||||||
|
assertEquals(200, status.getStatusLine().getStatusCode());
|
||||||
|
bundle = ourCtx.newXmlParser().parseResource(Bundle.class, responseContent);
|
||||||
|
assertEquals(1, bundle.getEntry().size());
|
||||||
|
|
||||||
|
p = BundleUtil.toListOfResourcesOfType(ourCtx, bundle, Patient.class).get(0);
|
||||||
|
assertEquals("AAANamed", p.getIdentifierFirstRep().getValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
@AfterClass
|
||||||
|
public static void afterClassClearContext() throws Exception {
|
||||||
|
ourServer.stop();
|
||||||
|
TestUtil.clearAllStaticFieldsForUnitTest();
|
||||||
|
}
|
||||||
|
|
||||||
|
@BeforeClass
|
||||||
|
public static void beforeClass() throws Exception {
|
||||||
|
ourPort = PortUtil.findFreePort();
|
||||||
|
ourServer = new Server(ourPort);
|
||||||
|
|
||||||
|
DummyPatientResourceProvider patientProvider = new DummyPatientResourceProvider();
|
||||||
|
|
||||||
|
ServletHandler proxyHandler = new ServletHandler();
|
||||||
|
ourServlet = new RestfulServer(ourCtx);
|
||||||
|
ourServlet.getFhirContext().setNarrativeGenerator(new DefaultThymeleafNarrativeGenerator());
|
||||||
|
ourServlet.setPagingProvider(new FifoMemoryPagingProvider(10).setDefaultPageSize(10));
|
||||||
|
|
||||||
|
ourServlet.setResourceProviders(patientProvider, new DummyObservationResourceProvider());
|
||||||
|
ServletHolder servletHolder = new ServletHolder(ourServlet);
|
||||||
|
proxyHandler.addServletWithMapping(servletHolder, "/*");
|
||||||
|
ourServer.setHandler(proxyHandler);
|
||||||
|
ourServer.start();
|
||||||
|
|
||||||
|
PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager(5000, TimeUnit.MILLISECONDS);
|
||||||
|
HttpClientBuilder builder = HttpClientBuilder.create();
|
||||||
|
builder.setConnectionManager(connectionManager);
|
||||||
|
ourClient = builder.build();
|
||||||
|
|
||||||
|
ourDefaultAddressStrategy = ourServlet.getServerAddressStrategy();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class DummyObservationResourceProvider implements IResourceProvider {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Class<Observation> getResourceType() {
|
||||||
|
return Observation.class;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Search
|
||||||
|
public Observation search(@RequiredParam(name = "subject") ReferenceParam theSubject, @RequiredParam(name = "name") TokenOrListParam theName) {
|
||||||
|
Observation o = new Observation();
|
||||||
|
o.setId("1");
|
||||||
|
|
||||||
|
o.getSubject().setReference(theSubject.getResourceType() + "/" + theSubject.getIdPart());
|
||||||
|
for (TokenParam next : theName.getValuesAsQueryTokens()) {
|
||||||
|
o.getCode().addCoding().setSystem(next.getSystem()).setCode(next.getValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
return o;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class DummyPatientResourceProvider implements IResourceProvider {
|
||||||
|
|
||||||
|
@Search(compartmentName = "fooCompartment")
|
||||||
|
public List<Patient> compartment(@IdParam IdType theId) {
|
||||||
|
ArrayList<Patient> retVal = new ArrayList<Patient>();
|
||||||
|
|
||||||
|
Patient patient = new Patient();
|
||||||
|
patient.setId(theId);
|
||||||
|
patient.addIdentifier().setSystem("system").setValue("fooCompartment");
|
||||||
|
retVal.add(patient);
|
||||||
|
return retVal;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Only needed for #164
|
||||||
|
*/
|
||||||
|
@Create
|
||||||
|
public MethodOutcome create(@ResourceParam Patient thePatient) {
|
||||||
|
throw new IllegalArgumentException();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Search
|
||||||
|
public List<Patient> findPatient(@RequiredParam(name = "_id") StringParam theParam, @OptionalParam(name = "name") StringParam theName) {
|
||||||
|
ArrayList<Patient> retVal = new ArrayList<Patient>();
|
||||||
|
|
||||||
|
Patient patient = new Patient();
|
||||||
|
patient.setId("1");
|
||||||
|
patient.addIdentifier().setSystem("system").setValue("identifier123");
|
||||||
|
if (theParam != null) {
|
||||||
|
patient.addName().setFamily("id" + theParam.getValue());
|
||||||
|
if (theName != null) {
|
||||||
|
patient.addName().addGiven("name" + theName.getValue());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
retVal.add(patient);
|
||||||
|
return retVal;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Search
|
||||||
|
public List<Patient> findPatientByAAA01(@RequiredParam(name = "AAA") StringParam theParam) {
|
||||||
|
ArrayList<Patient> retVal = new ArrayList<Patient>();
|
||||||
|
|
||||||
|
Patient patient = new Patient();
|
||||||
|
patient.setId("1");
|
||||||
|
patient.addIdentifier().setSystem("system").setValue("AAA");
|
||||||
|
retVal.add(patient);
|
||||||
|
return retVal;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Search(queryName = "findPatientByAAA")
|
||||||
|
public List<Patient> findPatientByAAA02Named(@OptionalParam(name = "AAA") StringParam theParam) {
|
||||||
|
ArrayList<Patient> retVal = new ArrayList<Patient>();
|
||||||
|
|
||||||
|
Patient patient = new Patient();
|
||||||
|
patient.setId("1");
|
||||||
|
patient.addIdentifier().setSystem("system").setValue( "AAANamed");
|
||||||
|
retVal.add(patient);
|
||||||
|
return retVal;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Search()
|
||||||
|
public List<Patient> findPatientWithAndList(@RequiredParam(name = "findPatientWithAndList") StringAndListParam theParam) {
|
||||||
|
ourLastAndList = theParam;
|
||||||
|
ArrayList<Patient> retVal = new ArrayList<Patient>();
|
||||||
|
return retVal;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Search()
|
||||||
|
public List<Patient> findPatientWithOrList(@RequiredParam(name = "findPatientWithOrList") StringOrListParam theParam) {
|
||||||
|
ArrayList<Patient> retVal = new ArrayList<Patient>();
|
||||||
|
|
||||||
|
Patient patient = new Patient();
|
||||||
|
patient.setId("1");
|
||||||
|
for (StringParam next : theParam.getValuesAsQueryTokens()) {
|
||||||
|
patient.addIdentifier().setSystem("system").setValue( next.getValue());
|
||||||
|
}
|
||||||
|
retVal.add(patient);
|
||||||
|
return retVal;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Search()
|
||||||
|
public List<Patient> findPatientWithToken(@RequiredParam(name = "tokenParam") TokenParam theParam) {
|
||||||
|
ArrayList<Patient> retVal = new ArrayList<Patient>();
|
||||||
|
|
||||||
|
Patient patient = new Patient();
|
||||||
|
patient.setId("1");
|
||||||
|
patient.addName().setFamily(theParam.getSystem()).addGiven(theParam.getValue());
|
||||||
|
retVal.add(patient);
|
||||||
|
return retVal;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Search(queryName = "findWithLinks")
|
||||||
|
public List<Patient> findWithLinks() {
|
||||||
|
ArrayList<Patient> retVal = new ArrayList<Patient>();
|
||||||
|
|
||||||
|
for (int i = 1; i <= 20; i++) {
|
||||||
|
Patient patient = new Patient();
|
||||||
|
patient.setId("" + i);
|
||||||
|
patient.addIdentifier().setSystem("system").setValue( "AAANamed");
|
||||||
|
retVal.add(patient);
|
||||||
|
}
|
||||||
|
|
||||||
|
return retVal;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Class<Patient> getResourceType() {
|
||||||
|
return Patient.class;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Search(queryName = "searchIncludes")
|
||||||
|
public List<Patient> searchIncludes(@IncludeParam Set<Include> theIncludes) {
|
||||||
|
ourLastIncludes = theIncludes;
|
||||||
|
|
||||||
|
ArrayList<Patient> retVal = new ArrayList<Patient>();
|
||||||
|
return retVal;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Search(queryName = "searchIncludesList")
|
||||||
|
public List<Patient> searchIncludesList(@IncludeParam List<Include> theIncludes) {
|
||||||
|
if (theIncludes != null) {
|
||||||
|
ourLastIncludes = new HashSet<Include>(theIncludes);
|
||||||
|
}
|
||||||
|
|
||||||
|
ArrayList<Patient> retVal = new ArrayList<Patient>();
|
||||||
|
return retVal;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Search(queryName = "searchWithRef")
|
||||||
|
public Patient searchWithRef() {
|
||||||
|
Patient patient = new Patient();
|
||||||
|
patient.setId("Patient/1/_history/1");
|
||||||
|
patient.getManagingOrganization().setReference("http://localhost:" + ourPort + "/Organization/555/_history/666");
|
||||||
|
return patient;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,30 @@
|
||||||
|
<configuration>
|
||||||
|
|
||||||
|
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
|
||||||
|
<encoder>
|
||||||
|
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} [%file:%line] - %msg%n
|
||||||
|
</pattern>
|
||||||
|
</encoder>
|
||||||
|
</appender>
|
||||||
|
|
||||||
|
<logger name="org.eclipse" additivity="false" level="info">
|
||||||
|
<appender-ref ref="STDOUT" />
|
||||||
|
</logger>
|
||||||
|
<logger name="org.apache" additivity="false" level="info">
|
||||||
|
<appender-ref ref="STDOUT" />
|
||||||
|
</logger>
|
||||||
|
<logger name="org.thymeleaf" additivity="false" level="warn">
|
||||||
|
<appender-ref ref="STDOUT" />
|
||||||
|
</logger>
|
||||||
|
|
||||||
|
<!--
|
||||||
|
<logger name="ca.uhn.fhir.rest.client" additivity="false" level="trace">
|
||||||
|
<appender-ref ref="STDOUT" />
|
||||||
|
</logger>
|
||||||
|
-->
|
||||||
|
|
||||||
|
<root level="info">
|
||||||
|
<appender-ref ref="STDOUT" />
|
||||||
|
</root>
|
||||||
|
|
||||||
|
</configuration>
|
|
@ -5,7 +5,6 @@ import java.util.List;
|
||||||
import org.hl7.fhir.instance.model.api.IBaseResource;
|
import org.hl7.fhir.instance.model.api.IBaseResource;
|
||||||
import org.hl7.fhir.utilities.validation.ValidationMessage;
|
import org.hl7.fhir.utilities.validation.ValidationMessage;
|
||||||
|
|
||||||
import ca.uhn.fhir.model.api.Bundle;
|
|
||||||
import ca.uhn.fhir.validation.*;
|
import ca.uhn.fhir.validation.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -39,11 +38,6 @@ abstract class BaseValidatorBridge implements IValidatorModule {
|
||||||
|
|
||||||
protected abstract List<ValidationMessage> validate(IValidationContext<?> theCtx);
|
protected abstract List<ValidationMessage> validate(IValidationContext<?> theCtx);
|
||||||
|
|
||||||
@Override
|
|
||||||
public void validateBundle(IValidationContext<Bundle> theCtx) {
|
|
||||||
doValidate(theCtx);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void validateResource(IValidationContext<IBaseResource> theCtx) {
|
public void validateResource(IValidationContext<IBaseResource> theCtx) {
|
||||||
doValidate(theCtx);
|
doValidate(theCtx);
|
||||||
|
|
|
@ -5,11 +5,7 @@ import java.util.List;
|
||||||
import org.hl7.fhir.instance.model.api.IBaseResource;
|
import org.hl7.fhir.instance.model.api.IBaseResource;
|
||||||
import org.hl7.fhir.utilities.validation.ValidationMessage;
|
import org.hl7.fhir.utilities.validation.ValidationMessage;
|
||||||
|
|
||||||
import ca.uhn.fhir.model.api.Bundle;
|
import ca.uhn.fhir.validation.*;
|
||||||
import ca.uhn.fhir.validation.IValidationContext;
|
|
||||||
import ca.uhn.fhir.validation.IValidatorModule;
|
|
||||||
import ca.uhn.fhir.validation.ResultSeverityEnum;
|
|
||||||
import ca.uhn.fhir.validation.SingleValidationMessage;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Base class for a bridge between the RI validation tools and HAPI
|
* Base class for a bridge between the RI validation tools and HAPI
|
||||||
|
@ -42,11 +38,6 @@ abstract class BaseValidatorBridge implements IValidatorModule {
|
||||||
|
|
||||||
protected abstract List<ValidationMessage> validate(IValidationContext<?> theCtx);
|
protected abstract List<ValidationMessage> validate(IValidationContext<?> theCtx);
|
||||||
|
|
||||||
@Override
|
|
||||||
public void validateBundle(IValidationContext<Bundle> theCtx) {
|
|
||||||
doValidate(theCtx);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void validateResource(IValidationContext<IBaseResource> theCtx) {
|
public void validateResource(IValidationContext<IBaseResource> theCtx) {
|
||||||
doValidate(theCtx);
|
doValidate(theCtx);
|
||||||
|
|
|
@ -265,11 +265,6 @@ public class Dstu2BundleFactory implements IVersionSpecificBundleFactory {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public ca.uhn.fhir.model.api.Bundle getDstu1Bundle() {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IResource getResourceBundle() {
|
public IResource getResourceBundle() {
|
||||||
return myBundle;
|
return myBundle;
|
||||||
|
|
|
@ -1,23 +1,8 @@
|
||||||
package ca.uhn.fhir.tinder;
|
package ca.uhn.fhir.tinder;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.*;
|
||||||
import java.io.FileInputStream;
|
|
||||||
import java.io.FileNotFoundException;
|
|
||||||
import java.io.FileOutputStream;
|
|
||||||
import java.io.FileReader;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.io.InputStreamReader;
|
|
||||||
import java.io.OutputStreamWriter;
|
|
||||||
import java.nio.charset.Charset;
|
import java.nio.charset.Charset;
|
||||||
import java.util.Collection;
|
import java.util.*;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Set;
|
|
||||||
import java.util.TreeMap;
|
|
||||||
|
|
||||||
import org.apache.commons.io.IOUtils;
|
import org.apache.commons.io.IOUtils;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
@ -28,23 +13,17 @@ import org.apache.velocity.app.VelocityEngine;
|
||||||
import org.apache.velocity.tools.generic.EscapeTool;
|
import org.apache.velocity.tools.generic.EscapeTool;
|
||||||
|
|
||||||
import ca.uhn.fhir.context.FhirContext;
|
import ca.uhn.fhir.context.FhirContext;
|
||||||
import ca.uhn.fhir.model.api.Bundle;
|
|
||||||
import ca.uhn.fhir.model.api.BundleEntry;
|
|
||||||
import ca.uhn.fhir.model.dstu.resource.ValueSet;
|
import ca.uhn.fhir.model.dstu.resource.ValueSet;
|
||||||
import ca.uhn.fhir.model.dstu.resource.ValueSet.ComposeInclude;
|
import ca.uhn.fhir.model.dstu.resource.ValueSet.ComposeInclude;
|
||||||
import ca.uhn.fhir.model.dstu.resource.ValueSet.Define;
|
import ca.uhn.fhir.model.dstu.resource.ValueSet.Define;
|
||||||
import ca.uhn.fhir.model.dstu.resource.ValueSet.DefineConcept;
|
import ca.uhn.fhir.model.dstu.resource.ValueSet.DefineConcept;
|
||||||
import ca.uhn.fhir.model.dstu2.resource.Bundle.Entry;
|
import ca.uhn.fhir.model.dstu2.resource.Bundle.Entry;
|
||||||
import ca.uhn.fhir.model.dstu2.resource.ValueSet.CodeSystem;
|
import ca.uhn.fhir.model.dstu2.resource.ValueSet.*;
|
||||||
import ca.uhn.fhir.model.dstu2.resource.ValueSet.CodeSystemConcept;
|
|
||||||
import ca.uhn.fhir.model.dstu2.resource.ValueSet.ComposeIncludeConcept;
|
|
||||||
import ca.uhn.fhir.model.primitive.CodeDt;
|
import ca.uhn.fhir.model.primitive.CodeDt;
|
||||||
import ca.uhn.fhir.parser.IParser;
|
import ca.uhn.fhir.parser.IParser;
|
||||||
import ca.uhn.fhir.parser.LenientErrorHandler;
|
import ca.uhn.fhir.parser.LenientErrorHandler;
|
||||||
import ca.uhn.fhir.tinder.TinderStructuresMojo.ValueSetFileDefinition;
|
import ca.uhn.fhir.tinder.TinderStructuresMojo.ValueSetFileDefinition;
|
||||||
import ca.uhn.fhir.tinder.model.BaseRootType;
|
|
||||||
import ca.uhn.fhir.tinder.model.ValueSetTm;
|
import ca.uhn.fhir.tinder.model.ValueSetTm;
|
||||||
import ca.uhn.fhir.tinder.parser.ResourceGeneratorUsingSpreadsheet;
|
|
||||||
import ca.uhn.fhir.tinder.parser.TargetType;
|
import ca.uhn.fhir.tinder.parser.TargetType;
|
||||||
|
|
||||||
public class ValueSetGenerator {
|
public class ValueSetGenerator {
|
||||||
|
@ -126,18 +105,14 @@ public class ValueSetGenerator {
|
||||||
throw new FileNotFoundException(name);
|
throw new FileNotFoundException(name);
|
||||||
}
|
}
|
||||||
String vs = IOUtils.toString(is, Charset.defaultCharset());
|
String vs = IOUtils.toString(is, Charset.defaultCharset());
|
||||||
if ("dstu".equals(myVersion)) {
|
if ("dstu2".equals(myVersion)) {
|
||||||
Bundle bundle = newXmlParser.parseBundle(vs);
|
|
||||||
for (BundleEntry next : bundle.getEntries()) {
|
|
||||||
ValueSet nextVs = (ValueSet) next.getResource();
|
|
||||||
parseValueSet(nextVs);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
ca.uhn.fhir.model.dstu2.resource.Bundle bundle = newXmlParser.parseResource(ca.uhn.fhir.model.dstu2.resource.Bundle.class, vs);
|
ca.uhn.fhir.model.dstu2.resource.Bundle bundle = newXmlParser.parseResource(ca.uhn.fhir.model.dstu2.resource.Bundle.class, vs);
|
||||||
for (Entry nextEntry : bundle.getEntry()) {
|
for (Entry nextEntry : bundle.getEntry()) {
|
||||||
ca.uhn.fhir.model.dstu2.resource.ValueSet nextVs = (ca.uhn.fhir.model.dstu2.resource.ValueSet) nextEntry.getResource();
|
ca.uhn.fhir.model.dstu2.resource.ValueSet nextVs = (ca.uhn.fhir.model.dstu2.resource.ValueSet) nextEntry.getResource();
|
||||||
parseValueSet(nextVs);
|
parseValueSet(nextVs);
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
throw new IllegalStateException("Fhir version not supported");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (myResourceValueSetFiles != null) {
|
if (myResourceValueSetFiles != null) {
|
||||||
|
|
|
@ -18,6 +18,10 @@
|
||||||
being used in Bundle.entry.request.url as a part of the conditional URL
|
being used in Bundle.entry.request.url as a part of the conditional URL
|
||||||
within transactions.
|
within transactions.
|
||||||
</action>
|
</action>
|
||||||
|
<action type="fix">
|
||||||
|
Schematron validator now applies invariants to resources within a Bundle, not
|
||||||
|
just to the outer Bundle resource itself
|
||||||
|
</action>
|
||||||
</release
|
</release
|
||||||
<release version="2.6" date="TBD">
|
<release version="2.6" date="TBD">
|
||||||
<action type="add">
|
<action type="add">
|
||||||
|
|
Loading…
Reference in New Issue