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;
|
||||
|
||||
import org.hl7.fhir.instance.model.api.IBaseBundle;
|
||||
import org.hl7.fhir.instance.model.api.IBaseResource;
|
||||
|
||||
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>
|
||||
* 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
|
||||
|
|
|
@ -1,5 +1,9 @@
|
|||
package ca.uhn.fhir.rest.gclient;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import ca.uhn.fhir.model.api.IQueryParameterType;
|
||||
|
||||
/*
|
||||
* #%L
|
||||
* HAPI FHIR - Core Library
|
||||
|
@ -24,6 +28,8 @@ public interface IBaseQuery<T extends IBaseQuery<?>> {
|
|||
|
||||
T where(ICriterion<?> theCriterion);
|
||||
|
||||
T where(Map<String, List<IQueryParameterType>> 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
|
||||
|
|
|
@ -24,5 +24,5 @@ import org.hl7.fhir.instance.model.api.IBaseMetaType;
|
|||
|
||||
public interface IMetaAddOrDeleteSourced {
|
||||
|
||||
<T extends IBaseMetaType> IClientExecutable<IClientExecutable<?, ?>, T> meta(T theMeta);
|
||||
<T extends IBaseMetaType> IClientExecutable<IClientExecutable<?, T>, T> meta(T theMeta);
|
||||
}
|
||||
|
|
|
@ -10,7 +10,7 @@ package ca.uhn.fhir.rest.gclient;
|
|||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
|
@ -25,16 +25,16 @@ import org.hl7.fhir.instance.model.api.IIdType;
|
|||
|
||||
public interface IMetaGetUnsourced<T extends IBaseMetaType> {
|
||||
|
||||
IClientExecutable<IClientExecutable<?,?>, T> fromServer();
|
||||
|
||||
IClientExecutable<IClientExecutable<?,?>, T> fromType(String theResourceName);
|
||||
IClientExecutable<IClientExecutable<?, T>, T> fromServer();
|
||||
|
||||
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.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
|
||||
|
@ -39,9 +39,9 @@ public interface IQuery extends IBaseQuery<IQuery> {
|
|||
* <li><b>No Recurse:</b> <code>.include(Patient.INCLUDE_ORGANIZATION.asNonRecursive())</code>
|
||||
* </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
|
||||
|
@ -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
|
||||
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
|
||||
|
@ -58,7 +58,7 @@ public interface IQuery extends IBaseQuery<IQuery> {
|
|||
*
|
||||
* @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
|
||||
|
@ -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 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
|
||||
|
@ -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 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
|
||||
* the <code>_profile</code> URL parameter.
|
||||
* @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.
|
||||
* 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.
|
||||
*/
|
||||
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
|
||||
|
@ -100,44 +100,44 @@ public interface IQuery extends IBaseQuery<IQuery> {
|
|||
* @see SearchStyleEnum
|
||||
* @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
|
||||
*
|
||||
* @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
|
||||
*
|
||||
* @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>
|
||||
* 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}
|
||||
*/
|
||||
// This is here as an overridden method to allow mocking clients with Mockito to work
|
||||
@Override
|
||||
IQuery where(ICriterion<?> theCriterion);
|
||||
IQuery<Y> where(ICriterion<?> theCriterion);
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
// This is here as an overridden method to allow mocking clients with Mockito to work
|
||||
@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%
|
||||
*/
|
||||
|
||||
public interface ISort {
|
||||
public interface ISort<T> {
|
||||
|
||||
/**
|
||||
* Sort ascending
|
||||
*/
|
||||
IQuery ascending(IParam theParam);
|
||||
IQuery<T> ascending(IParam theParam);
|
||||
|
||||
/**
|
||||
* Sort ascending
|
||||
*
|
||||
* @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
|
||||
|
@ -40,7 +40,7 @@ public interface ISort {
|
|||
* technically implies "ascending" but it makes more sense to use
|
||||
* {@link #ascending(IParam)}
|
||||
*/
|
||||
IQuery defaultOrder(IParam theParam);
|
||||
IQuery<T> defaultOrder(IParam theParam);
|
||||
|
||||
/**
|
||||
* 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 such as <code>new StringClientParam("foo")</code>
|
||||
*/
|
||||
IQuery descending(IParam theParam);
|
||||
IQuery<T> descending(IParam theParam);
|
||||
|
||||
/**
|
||||
* Sort ascending
|
||||
*
|
||||
* @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;
|
||||
|
||||
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
|
||||
|
@ -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
|
||||
* (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;
|
||||
|
||||
import static org.apache.commons.lang3.StringUtils.isBlank;
|
||||
|
||||
public abstract class BaseParamWithPrefix<T extends BaseParam> extends BaseParam {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(BaseParamWithPrefix.class);
|
||||
|
||||
private ParamPrefixEnum myPrefix;
|
||||
|
||||
|
@ -32,8 +35,40 @@ public abstract class BaseParamWithPrefix<T extends BaseParam> extends BaseParam
|
|||
}
|
||||
|
||||
String prefix = theString.substring(0, offset);
|
||||
myPrefix = ParamPrefixEnum.forValue(prefix);
|
||||
|
||||
if (!isBlank(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);
|
||||
}
|
||||
|
||||
|
|
|
@ -143,8 +143,9 @@ public class BundleUtil {
|
|||
/**
|
||||
* 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) {
|
||||
List<IBaseResource> retVal = new ArrayList<IBaseResource>();
|
||||
@SuppressWarnings("unchecked")
|
||||
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);
|
||||
BaseRuntimeChildDefinition entryChild = def.getChildByName("entry");
|
||||
|
@ -157,7 +158,7 @@ public class BundleUtil {
|
|||
if (theTypeToInclude != null && !theTypeToInclude.isAssignableFrom(next.getClass())) {
|
||||
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> {
|
||||
|
||||
protected final FhirContext myFhirContext;
|
||||
private List<SingleValidationMessage> myMessages = new ArrayList<SingleValidationMessage>();
|
||||
|
||||
private List<SingleValidationMessage> myMessages;
|
||||
BaseValidationContext(FhirContext theFhirContext) {
|
||||
this(theFhirContext, new ArrayList<SingleValidationMessage>());
|
||||
}
|
||||
|
||||
BaseValidationContext(FhirContext theFhirContext, List<SingleValidationMessage> theMessages) {
|
||||
myFhirContext = theFhirContext;
|
||||
myMessages = theMessages;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -46,6 +51,11 @@ abstract class BaseValidationContext<T> implements IValidationContext<T> {
|
|||
return myFhirContext;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SingleValidationMessage> getMessages() {
|
||||
return myMessages;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ValidationResult toResult() {
|
||||
return new ValidationResult(myFhirContext, myMessages);
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package ca.uhn.fhir.validation;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/*
|
||||
* #%L
|
||||
* HAPI FHIR - Core Library
|
||||
|
@ -35,6 +37,8 @@ public interface IValidationContext<T> {
|
|||
|
||||
void addValidationMessage(SingleValidationMessage theMessage);
|
||||
|
||||
List<SingleValidationMessage> getMessages();
|
||||
|
||||
ValidationResult toResult();
|
||||
|
||||
}
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
package ca.uhn.fhir.validation;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/*
|
||||
* #%L
|
||||
* HAPI FHIR - Core Library
|
||||
|
@ -37,7 +40,11 @@ public class ValidationContext<T> extends BaseValidationContext<T> implements IV
|
|||
private final EncodingEnum myResourceAsStringEncoding;
|
||||
|
||||
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;
|
||||
myEncoder = theEncoder;
|
||||
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 org.apache.commons.io.IOUtils;
|
||||
import org.hl7.fhir.instance.model.api.IBaseBundle;
|
||||
import org.hl7.fhir.instance.model.api.IBaseResource;
|
||||
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.rest.api.EncodingEnum;
|
||||
import ca.uhn.fhir.rest.server.exceptions.InternalErrorException;
|
||||
import ca.uhn.fhir.util.BundleUtil;
|
||||
import ca.uhn.fhir.validation.*;
|
||||
|
||||
/**
|
||||
|
@ -57,6 +59,14 @@ public class SchematronBaseValidator implements IValidatorModule {
|
|||
@Override
|
||||
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);
|
||||
String resourceAsString;
|
||||
if (theCtx.getResourceAsStringEncoding() == EncodingEnum.XML) {
|
||||
|
|
|
@ -25,6 +25,7 @@ import static org.apache.commons.lang3.StringUtils.isNotBlank;
|
|||
import java.io.IOException;
|
||||
import java.io.Reader;
|
||||
import java.util.*;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
@ -75,13 +76,11 @@ public class GenericClient extends BaseClient implements IGenericClient {
|
|||
return new CreateInternal();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public IDelete delete() {
|
||||
return new DeleteInternal();
|
||||
}
|
||||
|
||||
|
||||
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) {
|
||||
String resName = toResourceName(theType);
|
||||
|
@ -165,15 +164,11 @@ public class GenericClient extends BaseClient implements IGenericClient {
|
|||
return theResource.getIdElement().getIdPart();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public IHistory history() {
|
||||
return new HistoryInternal();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// @Override
|
||||
// public <T extends IBaseResource> T read(final Class<T> theType, IdDt theId) {
|
||||
// return doReadOrVRead(theType, theId, false, null, null);
|
||||
|
@ -204,6 +199,11 @@ public class GenericClient extends BaseClient implements IGenericClient {
|
|||
return new OperationInternal();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IPatch patch() {
|
||||
return new PatchInternal();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IRead read() {
|
||||
return new ReadInternal();
|
||||
|
@ -234,12 +234,12 @@ public class GenericClient extends BaseClient implements IGenericClient {
|
|||
return read(def.getImplementingClass(), id);
|
||||
}
|
||||
|
||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||
@Override
|
||||
public IUntypedQuery search() {
|
||||
return new SearchInternal();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 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();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public IPatch patch() {
|
||||
return new PatchInternal();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IUpdate update() {
|
||||
return new UpdateInternal();
|
||||
|
@ -366,18 +360,13 @@ public class GenericClient extends BaseClient implements IGenericClient {
|
|||
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;
|
||||
|
||||
private List<Class<? extends IBaseResource>> myPreferResponseTypes;
|
||||
|
||||
protected Boolean myPrettyPrint;
|
||||
|
||||
private boolean myQueryLogRequestAndResponse;
|
||||
|
||||
private HashSet<String> mySubsetElements;
|
||||
|
||||
protected SummaryEnum mySummaryMode;
|
||||
|
||||
@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 PreferReturnEnum myPrefer;
|
||||
private IBaseResource myResource;
|
||||
private String myResourceBody;
|
||||
private String mySearchUrl;
|
||||
|
||||
@Override
|
||||
public ICreateWithQueryTyped and(ICriterion<?> theCriterion) {
|
||||
myCriterionList.add((ICriterionInternal) theCriterion);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ICreateWithQuery conditional() {
|
||||
myCriterionList = new CriterionList();
|
||||
myConditional = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
@ -534,8 +559,8 @@ public class GenericClient extends BaseClient implements IGenericClient {
|
|||
BaseHttpClientInvocation invocation;
|
||||
if (mySearchUrl != null) {
|
||||
invocation = MethodUtil.createCreateInvocation(myResource, myResourceBody, myId, myContext, mySearchUrl);
|
||||
} else if (myCriterionList != null) {
|
||||
invocation = MethodUtil.createCreateInvocation(myResource, myResourceBody, myId, myContext, myCriterionList.toParamList());
|
||||
} else if (myConditional) {
|
||||
invocation = MethodUtil.createCreateInvocation(myResource, myResourceBody, myId, myContext, getParamMap());
|
||||
} else {
|
||||
invocation = MethodUtil.createCreateInvocation(myResource, myResourceBody, myId, myContext);
|
||||
}
|
||||
|
@ -569,12 +594,6 @@ public class GenericClient extends BaseClient implements IGenericClient {
|
|||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ICreateWithQueryTyped where(ICriterion<?> theCriterion) {
|
||||
myCriterionList.add((ICriterionInternal) theCriterion);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CreateInternal withId(IdDt theId) {
|
||||
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;
|
||||
|
||||
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 boolean myConditional;
|
||||
private IIdType myId;
|
||||
private String myResourceType;
|
||||
private String mySearchUrl;
|
||||
|
||||
@Override
|
||||
public IDeleteWithQueryTyped and(ICriterion<?> theCriterion) {
|
||||
myCriterionList.add((ICriterionInternal) theCriterion);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBaseOperationOutcome execute() {
|
||||
HttpDeleteClientInvocation invocation;
|
||||
if (myId != null) {
|
||||
invocation = DeleteMethodBinding.createDeleteInvocation(getFhirContext(), myId);
|
||||
} else if (myCriterionList != null) {
|
||||
Map<String, List<String>> params = myCriterionList.toParamList();
|
||||
invocation = DeleteMethodBinding.createDeleteInvocation(getFhirContext(), myResourceType, params);
|
||||
} else if (myConditional) {
|
||||
invocation = DeleteMethodBinding.createDeleteInvocation(getFhirContext(), myResourceType, getParamMap());
|
||||
} else {
|
||||
invocation = DeleteMethodBinding.createDeleteInvocation(getFhirContext(), mySearchUrl);
|
||||
}
|
||||
|
@ -679,7 +669,7 @@ public class GenericClient extends BaseClient implements IGenericClient {
|
|||
@Override
|
||||
public IDeleteWithQuery resourceConditionalByType(Class<? extends IBaseResource> theResourceType) {
|
||||
Validate.notNull(theResourceType, "theResourceType can not be null");
|
||||
myCriterionList = new CriterionList();
|
||||
myConditional = true;
|
||||
myResourceType = myContext.getResourceDefinition(theResourceType).getName();
|
||||
return this;
|
||||
}
|
||||
|
@ -691,7 +681,7 @@ public class GenericClient extends BaseClient implements IGenericClient {
|
|||
throw new IllegalArgumentException("Unknown resource type: " + theResourceType);
|
||||
}
|
||||
myResourceType = theResourceType;
|
||||
myCriterionList = new CriterionList();
|
||||
myConditional = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
@ -701,11 +691,6 @@ public class GenericClient extends BaseClient implements IGenericClient {
|
|||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IDeleteWithQueryTyped where(ICriterion<?> theCriterion) {
|
||||
myCriterionList.add((ICriterionInternal) theCriterion);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||
|
@ -755,7 +740,6 @@ public class GenericClient extends BaseClient implements IGenericClient {
|
|||
|
||||
}
|
||||
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public IGetPageUntyped byUrl(String thePageUrl) {
|
||||
if (isBlank(thePageUrl)) {
|
||||
|
@ -864,7 +847,6 @@ public class GenericClient extends BaseClient implements IGenericClient {
|
|||
return this;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public <T extends IBaseBundle> IGetPageTyped<T> next(T 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));
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public <T extends IBaseBundle> IGetPageTyped<T> previous(T theBundle) {
|
||||
return nextOrPrevious(PREVIOUS, theBundle);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
|
@ -993,7 +973,7 @@ public class GenericClient extends BaseClient implements IGenericClient {
|
|||
|
||||
@SuppressWarnings("unchecked")
|
||||
@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");
|
||||
myMeta = theMeta;
|
||||
myMetaType = myMeta.getClass();
|
||||
|
@ -1062,56 +1042,15 @@ public class GenericClient extends BaseClient implements IGenericClient {
|
|||
implements IOperation, IOperationUnnamed, IOperationUntyped, IOperationUntypedWithInput, IOperationUntypedWithInputAndPartialOutput, IOperationProcessMsg, IOperationProcessMsgMode {
|
||||
|
||||
private IIdType myId;
|
||||
private Boolean myIsAsync;
|
||||
private IBaseBundle myMsgBundle;
|
||||
private String myOperationName;
|
||||
private IBaseParameters myParameters;
|
||||
private RuntimeResourceDefinition myParametersDef;
|
||||
private String myResponseUrl;
|
||||
private Class myReturnResourceType;
|
||||
private Class<? extends IBaseResource> myType;
|
||||
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")
|
||||
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) {
|
||||
IPrimitiveType<?> stringType = ParametersUtil.createString(myContext, theValue.getValueAsQueryToken(myContext));
|
||||
addParam(theName, stringType);
|
||||
|
@ -1169,6 +1102,15 @@ public class GenericClient extends BaseClient implements IGenericClient {
|
|||
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")
|
||||
@Override
|
||||
public Object execute() {
|
||||
|
@ -1259,6 +1201,52 @@ public class GenericClient extends BaseClient implements IGenericClient {
|
|||
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
|
||||
public IOperationUntypedWithInput useHttpGet() {
|
||||
myUseHttpGet = true;
|
||||
|
@ -1319,14 +1307,6 @@ public class GenericClient extends BaseClient implements IGenericClient {
|
|||
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> {
|
||||
|
@ -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" })
|
||||
private class ReadInternal extends BaseClientExecutable implements IRead, IReadTyped, IReadExecutable {
|
||||
private IIdType myId;
|
||||
|
@ -1533,10 +1626,9 @@ public class GenericClient extends BaseClient implements IGenericClient {
|
|||
}
|
||||
|
||||
@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 CriterionList myCriterion = new CriterionList();
|
||||
private List<Include> myInclude = new ArrayList<Include>();
|
||||
private DateRangeParam myLastUpdated;
|
||||
private Integer myParamLimit;
|
||||
|
@ -1558,12 +1650,6 @@ public class GenericClient extends BaseClient implements IGenericClient {
|
|||
mySearchUrl = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IQuery and(ICriterion<?> theCriterion) {
|
||||
myCriterion.add((ICriterionInternal) theCriterion);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IQuery byUrl(String theSearchUrl) {
|
||||
Validate.notBlank(theSearchUrl, "theSearchUrl must not be blank/null");
|
||||
|
@ -1603,15 +1689,9 @@ public class GenericClient extends BaseClient implements IGenericClient {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Object execute() {
|
||||
public OUTPUT execute() {
|
||||
|
||||
Map<String, List<String>> params = new LinkedHashMap<String, List<String>>();
|
||||
// Map<String, List<String>> initial = createExtraParams();
|
||||
// if (initial != null) {
|
||||
// params.putAll(initial);
|
||||
// }
|
||||
|
||||
myCriterion.populateParamList(params);
|
||||
Map<String, List<String>> params = getParamMap();
|
||||
|
||||
for (TokenParam next : myTags) {
|
||||
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);
|
||||
}
|
||||
|
||||
return invoke(params, binding, invocation);
|
||||
return (OUTPUT) invoke(params, binding, invocation);
|
||||
|
||||
}
|
||||
|
||||
|
@ -1711,7 +1791,7 @@ public class GenericClient extends BaseClient implements IGenericClient {
|
|||
}
|
||||
|
||||
@Override
|
||||
public IQuery forResource(Class<? extends IBaseResource> theResourceType) {
|
||||
public IQuery forResource(Class theResourceType) {
|
||||
setType(theResourceType);
|
||||
return this;
|
||||
}
|
||||
|
@ -1741,7 +1821,7 @@ public class GenericClient extends BaseClient implements IGenericClient {
|
|||
}
|
||||
|
||||
@Override
|
||||
public IQueryTyped returnBundle(Class theClass) {
|
||||
public IQuery returnBundle(Class theClass) {
|
||||
if (theClass == null) {
|
||||
throw new NullPointerException("theClass must not be null");
|
||||
}
|
||||
|
@ -1780,8 +1860,9 @@ public class GenericClient extends BaseClient implements IGenericClient {
|
|||
}
|
||||
|
||||
@Override
|
||||
public IQuery where(ICriterion<?> theCriterion) {
|
||||
myCriterion.add((ICriterionInternal) theCriterion);
|
||||
public IQuery withAnyProfile(Collection theProfileUris) {
|
||||
Validate.notEmpty(theProfileUris, "theProfileUris must not be null or empty");
|
||||
myProfiles.add(theProfileUris);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
@ -1799,13 +1880,6 @@ public class GenericClient extends BaseClient implements IGenericClient {
|
|||
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
|
||||
public IQuery withSecurity(String theSystem, String theCode) {
|
||||
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 SortOrderEnum myDirection;
|
||||
private SearchInternal myFor;
|
||||
private String myParamName;
|
||||
private String myParamValue;
|
||||
private SortOrderEnum myDirection;
|
||||
|
||||
public SortInternal(SearchInternal 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 IBaseBundle myBaseBundle;
|
||||
|
@ -1932,7 +2006,7 @@ public class GenericClient extends BaseClient implements IGenericClient {
|
|||
ResourceResponseHandler binding = new ResourceResponseHandler(myBaseBundle.getClass(), getPreferResponseTypes());
|
||||
BaseHttpClientInvocation invocation = TransactionMethodBinding.createTransactionInvocation(myBaseBundle, myContext);
|
||||
return (T) invoke(params, binding, invocation);
|
||||
// } else if (myRawBundle != null) {
|
||||
// } else if (myRawBundle != null) {
|
||||
} else {
|
||||
StringResponseHandler binding = new StringResponseHandler();
|
||||
/*
|
||||
|
@ -1953,7 +2027,6 @@ public class GenericClient extends BaseClient implements IGenericClient {
|
|||
|
||||
private final class TransactionInternal implements ITransaction {
|
||||
|
||||
|
||||
@Override
|
||||
public ITransactionTyped<String> withBundle(String theBundle) {
|
||||
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 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 boolean myConditional;
|
||||
private IIdType myId;
|
||||
private PreferReturnEnum myPrefer;
|
||||
private IBaseResource myResource;
|
||||
private String myResourceBody;
|
||||
private String mySearchUrl;
|
||||
|
||||
@Override
|
||||
public IUpdateWithQueryTyped and(ICriterion<?> theCriterion) {
|
||||
myCriterionList.add((ICriterionInternal) theCriterion);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IUpdateWithQuery conditional() {
|
||||
myCriterionList = new CriterionList();
|
||||
myConditional = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
@ -2140,8 +2083,8 @@ public class GenericClient extends BaseClient implements IGenericClient {
|
|||
BaseHttpClientInvocation invocation;
|
||||
if (mySearchUrl != null) {
|
||||
invocation = MethodUtil.createUpdateInvocation(myContext, myResource, myResourceBody, mySearchUrl);
|
||||
} else if (myCriterionList != null) {
|
||||
invocation = MethodUtil.createUpdateInvocation(myContext, myResource, myResourceBody, myCriterionList.toParamList());
|
||||
} else if (myConditional) {
|
||||
invocation = MethodUtil.createUpdateInvocation(myContext, myResource, myResourceBody, getParamMap());
|
||||
} else {
|
||||
if (myId == null) {
|
||||
myId = myResource.getIdElement();
|
||||
|
@ -2182,12 +2125,6 @@ public class GenericClient extends BaseClient implements IGenericClient {
|
|||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IUpdateWithQueryTyped where(ICriterion<?> theCriterion) {
|
||||
myCriterionList.add((ICriterionInternal) theCriterion);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IUpdateExecutable withId(IIdType theId) {
|
||||
if (theId == null) {
|
||||
|
|
|
@ -13,7 +13,8 @@ import ca.uhn.fhir.context.RuntimeResourceDefinition;
|
|||
import ca.uhn.fhir.context.RuntimeSearchParam;
|
||||
import ca.uhn.fhir.jpa.entity.ResourceTable;
|
||||
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.dstu2.resource.OperationOutcome;
|
||||
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.server.exceptions.*;
|
||||
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.validation.*;
|
||||
|
||||
|
@ -36,7 +36,7 @@ import ca.uhn.fhir.validation.*;
|
|||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
|
@ -55,7 +55,7 @@ public class FhirResourceDaoDstu2<T extends IResource> extends BaseHapiFhirResou
|
|||
@Autowired()
|
||||
@Qualifier("myInstanceValidatorDstu2")
|
||||
private IValidatorModule myInstanceValidator;
|
||||
|
||||
|
||||
@Override
|
||||
protected List<Object> getIncludeValues(FhirTerser theTerser, Include theInclude, IBaseResource theResource, RuntimeResourceDefinition theResourceDef) {
|
||||
List<Object> values;
|
||||
|
@ -100,7 +100,7 @@ public class FhirResourceDaoDstu2<T extends IResource> extends BaseHapiFhirResou
|
|||
List<DeleteConflict> deleteConflicts = new ArrayList<DeleteConflict>();
|
||||
validateOkToDelete(deleteConflicts, entity);
|
||||
validateDeleteConflictsEmptyOrThrowException(deleteConflicts);
|
||||
|
||||
|
||||
OperationOutcome oo = new OperationOutcome();
|
||||
oo.addIssue().setSeverity(IssueSeverityEnum.INFORMATION).setDiagnostics("Ok to delete");
|
||||
return new MethodOutcome(new IdDt(theId.getValue()), oo);
|
||||
|
@ -155,12 +155,6 @@ public class FhirResourceDaoDstu2<T extends IResource> extends BaseHapiFhirResou
|
|||
|
||||
}
|
||||
|
||||
@CoverageIgnore
|
||||
@Override
|
||||
public void validateBundle(IValidationContext<Bundle> theContext) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -10,7 +10,7 @@ package ca.uhn.fhir.jpa.dao.dstu3;
|
|||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
|
@ -33,19 +33,18 @@ import org.hl7.fhir.instance.model.api.*;
|
|||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
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.IFhirResourceDao;
|
||||
import ca.uhn.fhir.jpa.entity.ResourceTable;
|
||||
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.base.composite.BaseResourceReferenceDt;
|
||||
import ca.uhn.fhir.rest.api.*;
|
||||
import ca.uhn.fhir.rest.api.server.RequestDetails;
|
||||
import ca.uhn.fhir.rest.server.exceptions.*;
|
||||
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.validation.*;
|
||||
|
||||
|
@ -57,9 +56,6 @@ public class FhirResourceDaoDstu3<T extends IAnyResource> extends BaseHapiFhirRe
|
|||
@Qualifier("myInstanceValidatorDstu3")
|
||||
private IValidatorModule myInstanceValidator;
|
||||
|
||||
@Autowired
|
||||
private FhirContext fhirContext;
|
||||
|
||||
@Override
|
||||
protected IBaseOperationOutcome createOperationOutcome(String theSeverity, String theMessage, String theCode) {
|
||||
OperationOutcome oo = new OperationOutcome();
|
||||
|
@ -127,7 +123,7 @@ public class FhirResourceDaoDstu3<T extends IAnyResource> extends BaseHapiFhirRe
|
|||
IFhirResourceDao<? extends IBaseResource> dao = getDao(type);
|
||||
resourceToValidateById = dao.read(theId, theRequestDetails);
|
||||
}
|
||||
|
||||
|
||||
ValidationResult result;
|
||||
if (theResource == null) {
|
||||
if (resourceToValidateById != null) {
|
||||
|
@ -160,12 +156,6 @@ public class FhirResourceDaoDstu3<T extends IAnyResource> extends BaseHapiFhirRe
|
|||
myMode = theMode;
|
||||
}
|
||||
|
||||
@CoverageIgnore
|
||||
@Override
|
||||
public void validateBundle(IValidationContext<Bundle> theContext) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void validateResource(IValidationContext<IBaseResource> theCtx) {
|
||||
boolean hasId = theCtx.getResource().getIdElement().hasIdPart();
|
||||
|
|
|
@ -24,28 +24,27 @@ import static org.apache.commons.lang3.StringUtils.isNotBlank;
|
|||
|
||||
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.OperationOutcome;
|
||||
import org.hl7.fhir.r4.model.OperationOutcome.IssueSeverity;
|
||||
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.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.IFhirResourceDao;
|
||||
import ca.uhn.fhir.jpa.entity.ResourceTable;
|
||||
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.base.composite.BaseResourceReferenceDt;
|
||||
import ca.uhn.fhir.rest.api.*;
|
||||
import ca.uhn.fhir.rest.api.server.RequestDetails;
|
||||
import ca.uhn.fhir.rest.server.exceptions.*;
|
||||
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.validation.*;
|
||||
|
||||
|
@ -57,9 +56,6 @@ public class FhirResourceDaoR4<T extends IAnyResource> extends BaseHapiFhirResou
|
|||
@Qualifier("myInstanceValidatorDstu3")
|
||||
private IValidatorModule myInstanceValidator;
|
||||
|
||||
@Autowired
|
||||
private FhirContext fhirContext;
|
||||
|
||||
@Override
|
||||
protected IBaseOperationOutcome createOperationOutcome(String theSeverity, String theMessage, String theCode) {
|
||||
OperationOutcome oo = new OperationOutcome();
|
||||
|
@ -160,12 +156,6 @@ public class FhirResourceDaoR4<T extends IAnyResource> extends BaseHapiFhirResou
|
|||
myMode = theMode;
|
||||
}
|
||||
|
||||
@CoverageIgnore
|
||||
@Override
|
||||
public void validateBundle(IValidationContext<Bundle> theContext) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void validateResource(IValidationContext<IBaseResource> theCtx) {
|
||||
boolean hasId = theCtx.getResource().getIdElement().hasIdPart();
|
||||
|
|
|
@ -10,7 +10,7 @@ package ca.uhn.fhir.jpa.provider;
|
|||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
|
@ -30,7 +30,6 @@ import org.springframework.beans.factory.annotation.Required;
|
|||
|
||||
import ca.uhn.fhir.jpa.dao.DaoMethodOutcome;
|
||||
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.api.PatchTypeEnum;
|
||||
import ca.uhn.fhir.rest.api.server.IBundleProvider;
|
||||
|
@ -65,7 +64,7 @@ public abstract class BaseJpaResourceProvider<T extends IBaseResource> extends B
|
|||
@At DateRangeParam theAt,
|
||||
RequestDetails theRequestDetails) {
|
||||
//@formatter:on
|
||||
|
||||
|
||||
startRequest(theRequest);
|
||||
try {
|
||||
DateRangeParam sinceOrAt = processSinceOrAt(theSince, theAt);
|
||||
|
@ -77,9 +76,9 @@ public abstract class BaseJpaResourceProvider<T extends IBaseResource> extends B
|
|||
|
||||
@History
|
||||
public IBundleProvider getHistoryForResourceType(
|
||||
HttpServletRequest theRequest,
|
||||
@Since Date theSince,
|
||||
@At DateRangeParam theAt,
|
||||
HttpServletRequest theRequest,
|
||||
@Since Date theSince,
|
||||
@At DateRangeParam theAt,
|
||||
RequestDetails theRequestDetails) {
|
||||
startRequest(theRequest);
|
||||
try {
|
||||
|
@ -95,26 +94,6 @@ public abstract class BaseJpaResourceProvider<T extends IBaseResource> extends B
|
|||
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)
|
||||
public T read(HttpServletRequest theRequest, @IdParam IIdType theId, RequestDetails theRequestDetails) {
|
||||
startRequest(theRequest);
|
||||
|
|
|
@ -10,7 +10,7 @@ package ca.uhn.fhir.jpa.provider;
|
|||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
|
@ -27,7 +27,6 @@ import javax.servlet.http.HttpServletRequest;
|
|||
import org.springframework.beans.factory.annotation.Required;
|
||||
|
||||
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.api.server.IBundleProvider;
|
||||
import ca.uhn.fhir.rest.api.server.RequestDetails;
|
||||
|
@ -36,23 +35,13 @@ import ca.uhn.fhir.rest.param.DateRangeParam;
|
|||
public class BaseJpaSystemProvider<T, MT> extends BaseJpaProvider {
|
||||
|
||||
public static final String MARK_ALL_RESOURCES_FOR_REINDEXING = "$mark-all-resources-for-reindexing";
|
||||
|
||||
|
||||
private IFhirSystemDao<T, MT> myDao;
|
||||
|
||||
public BaseJpaSystemProvider() {
|
||||
// nothing
|
||||
}
|
||||
|
||||
@GetTags
|
||||
public TagList getAllTagsOnServer(HttpServletRequest theRequest, RequestDetails theRequestDetails) {
|
||||
startRequest(theRequest);
|
||||
try {
|
||||
return myDao.getAllTags(theRequestDetails);
|
||||
} finally {
|
||||
endRequest(theRequest);
|
||||
}
|
||||
}
|
||||
|
||||
protected IFhirSystemDao<T, MT> getDao() {
|
||||
return myDao;
|
||||
}
|
||||
|
|
|
@ -1,7 +1,23 @@
|
|||
package ca.uhn.fhir.jpa.provider;
|
||||
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.hamcrest.Matchers.contains;
|
||||
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.net.*;
|
||||
|
@ -34,7 +50,6 @@ import ca.uhn.fhir.model.valueset.BundleTypeEnum;
|
|||
import ca.uhn.fhir.parser.IParser;
|
||||
import ca.uhn.fhir.rest.api.*;
|
||||
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.server.exceptions.*;
|
||||
import ca.uhn.fhir.util.*;
|
||||
|
@ -457,6 +472,7 @@ public class ResourceProviderDstu2Test extends BaseResourceProviderDstu2Test {
|
|||
.forResource(Organization.class)
|
||||
.where(Organization.NAME.matches().value("rpdstu2_testCountParam_01"))
|
||||
.count(10)
|
||||
.returnBundle(Bundle.class)
|
||||
.execute();
|
||||
assertEquals(100, found.getTotalElement().getValue().intValue());
|
||||
assertEquals(10, found.getEntry().size());
|
||||
|
@ -466,6 +482,7 @@ public class ResourceProviderDstu2Test extends BaseResourceProviderDstu2Test {
|
|||
.forResource(Organization.class)
|
||||
.where(Organization.NAME.matches().value("rpdstu2_testCountParam_01"))
|
||||
.count(999)
|
||||
.returnBundle(Bundle.class)
|
||||
.execute();
|
||||
assertEquals(100, found.getTotalElement().getValue().intValue());
|
||||
assertEquals(50, found.getEntry().size());
|
||||
|
@ -704,6 +721,7 @@ public class ResourceProviderDstu2Test extends BaseResourceProviderDstu2Test {
|
|||
.where(Encounter.IDENTIFIER.exactly().systemAndCode("urn:foo", "testDeepChainingE1"))
|
||||
.include(Encounter.INCLUDE_LOCATION.asRecursive())
|
||||
.include(Location.INCLUDE_PARTOF.asRecursive())
|
||||
.returnBundle(Bundle.class)
|
||||
.execute();
|
||||
|
||||
assertEquals(3, res.getEntry().size());
|
||||
|
@ -1581,15 +1599,6 @@ public class ResourceProviderDstu2Test extends BaseResourceProviderDstu2Test {
|
|||
pat = new Patient();
|
||||
pat.addIdentifier().setSystem("urn:system").setValue("testReadAllInstancesOfType_02");
|
||||
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
|
||||
.search()
|
||||
|
@ -1598,10 +1607,15 @@ public class ResourceProviderDstu2Test extends BaseResourceProviderDstu2Test {
|
|||
.encodedXml()
|
||||
.execute();
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
@ -1648,7 +1662,13 @@ public class ResourceProviderDstu2Test extends BaseResourceProviderDstu2Test {
|
|||
assertEquals(1, actual.getContained().getContainedResources().size());
|
||||
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());
|
||||
|
||||
}
|
||||
|
@ -1714,7 +1734,13 @@ public class ResourceProviderDstu2Test extends BaseResourceProviderDstu2Test {
|
|||
p1.addIdentifier().setValue("testSearchByIdentifierWithoutSystem01");
|
||||
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();
|
||||
assertEquals(1, actual.getEntry().size());
|
||||
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();
|
||||
}
|
||||
|
||||
//@formatter:off
|
||||
Bundle found = ourClient
|
||||
.search()
|
||||
.forResource(Patient.class)
|
||||
.where(BaseResource.RES_ID.matches().values(id1.getIdPart(), id2.getIdPart()))
|
||||
.and(BaseResource.RES_ID.matches().value(id1.getIdPart()))
|
||||
.returnBundle(Bundle.class)
|
||||
.execute();
|
||||
//@formatter:on
|
||||
|
||||
assertThat(toIdListUnqualifiedVersionless(found), containsInAnyOrder(id1));
|
||||
}
|
||||
|
@ -1761,21 +1786,24 @@ public class ResourceProviderDstu2Test extends BaseResourceProviderDstu2Test {
|
|||
p1.setManagingOrganization(new ResourceReferenceDt(o1id.toUnqualifiedVersionless()));
|
||||
IdDt p1Id = (IdDt) ourClient.create().resource(p1).execute().getId();
|
||||
|
||||
//@formatter:off
|
||||
Bundle actual = ourClient.search()
|
||||
.forResource(Patient.class)
|
||||
.where(Patient.ORGANIZATION.hasId(o1id.getIdPart()))
|
||||
.encodedJson().prettyPrint().execute();
|
||||
//@formatter:on
|
||||
.encodedJson()
|
||||
.prettyPrint()
|
||||
.returnBundle(Bundle.class)
|
||||
.execute();
|
||||
assertEquals(1, actual.getEntry().size());
|
||||
assertEquals(p1Id.getIdPart(), actual.getEntry().get(0).getResource().getId().getIdPart());
|
||||
|
||||
//@formatter:off
|
||||
actual = ourClient.search()
|
||||
actual = ourClient
|
||||
.search()
|
||||
.forResource(Patient.class)
|
||||
.where(Patient.ORGANIZATION.hasId(o1id.getValue()))
|
||||
.encodedJson().prettyPrint().execute();
|
||||
//@formatter:on
|
||||
.encodedJson()
|
||||
.prettyPrint()
|
||||
.returnBundle(Bundle.class)
|
||||
.execute();
|
||||
assertEquals(1, actual.getEntry().size());
|
||||
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()));
|
||||
IdDt p2Id = (IdDt) ourClient.create().resource(p2).execute().getId();
|
||||
|
||||
//@formatter:off
|
||||
Bundle actual = ourClient.search()
|
||||
.forResource(Patient.class)
|
||||
.where(Patient.ORGANIZATION.hasAnyOfIds(Arrays.asList(o1id.getIdPart(), o2id.getIdPart())))
|
||||
.encodedJson().prettyPrint().execute();
|
||||
//@formatter:on
|
||||
.encodedJson()
|
||||
.prettyPrint()
|
||||
.returnBundle(Bundle.class)
|
||||
.execute();
|
||||
|
||||
Set<String> expectedIds = new HashSet<String>();
|
||||
expectedIds.add(p1Id.getIdPart());
|
||||
expectedIds.add(p2Id.getIdPart());
|
||||
Set<String> actualIds = new HashSet<String>();
|
||||
for (BundleEntry ele : actual.getEntry()) {
|
||||
for (Entry ele : actual.getEntry()) {
|
||||
actualIds.add(ele.getResource().getId().getIdPart());
|
||||
}
|
||||
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.getMeta().addProfile("http://profile1").addProfile("http://profile3");
|
||||
IdDt o2id = (IdDt) ourClient.create().resource(o2).execute().getId().toUnqualifiedVersionless();
|
||||
//@formatter:off
|
||||
|
||||
Bundle actual = ourClient.search()
|
||||
.forResource(Organization.class)
|
||||
.withProfile("http://profile1")
|
||||
.withProfile("http://profileX")
|
||||
.encodedJson().prettyPrint().execute();
|
||||
//@formatter:on
|
||||
.encodedJson()
|
||||
.prettyPrint()
|
||||
.returnBundle(Bundle.class)
|
||||
.execute();
|
||||
|
||||
assertEquals("nothing matches profile x", Collections.emptyList(), actual.getEntry());
|
||||
//@formatter:off
|
||||
|
||||
actual = ourClient.search()
|
||||
.forResource(Organization.class)
|
||||
.withProfile("http://profile1")
|
||||
.withProfile("http://profile2")
|
||||
.encodedJson().prettyPrint().execute();
|
||||
//@formatter:on
|
||||
.returnBundle(Bundle.class)
|
||||
.encodedJson()
|
||||
.prettyPrint()
|
||||
.execute();
|
||||
|
||||
Set<String> expectedIds = new HashSet<String>();
|
||||
expectedIds.add(o1id.getIdPart());
|
||||
Set<String> actualIds = new HashSet<String>();
|
||||
for (BundleEntry ele : actual.getEntry()) {
|
||||
for (Entry ele : actual.getEntry()) {
|
||||
actualIds.add(ele.getResource().getId().getIdPart());
|
||||
}
|
||||
assertEquals("Expects to retrieve the 1 orgination matching on Org1's profiles", expectedIds, actualIds);
|
||||
//@formatter:off
|
||||
|
||||
actual = ourClient.search()
|
||||
.forResource(Organization.class)
|
||||
.withProfile("http://profile1")
|
||||
.withAnyProfile(Arrays.asList("http://profile3", "http://profile2"))
|
||||
.encodedJson().prettyPrint().execute();
|
||||
//@formatter:on
|
||||
.encodedJson()
|
||||
.prettyPrint()
|
||||
.returnBundle(Bundle.class)
|
||||
.execute();
|
||||
|
||||
expectedIds = new HashSet<String>();
|
||||
expectedIds.add(o1id.getIdPart());
|
||||
expectedIds.add(o2id.getIdPart());
|
||||
actualIds = new HashSet<String>();
|
||||
for (BundleEntry ele : actual.getEntry()) {
|
||||
for (Entry ele : actual.getEntry()) {
|
||||
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);
|
||||
|
@ -1905,60 +1944,58 @@ public class ResourceProviderDstu2Test extends BaseResourceProviderDstu2Test {
|
|||
|
||||
ourLog.info("Before: {}", beforeAny.getValue());
|
||||
{
|
||||
//@formatter:off
|
||||
Bundle found = ourClient.search()
|
||||
Bundle found = ourClient
|
||||
.search()
|
||||
.forResource(Patient.class)
|
||||
.where(Patient.NAME.matches().value("testSearchLastUpdatedParamRp"))
|
||||
.lastUpdated(new DateRangeParam(beforeAny, null))
|
||||
.returnBundle(Bundle.class)
|
||||
.execute();
|
||||
//@formatter:on
|
||||
List<IdDt> patients = toIdListUnqualifiedVersionless(found);
|
||||
assertThat(patients, hasItems(id1a, id1b, id2));
|
||||
}
|
||||
|
||||
{
|
||||
//@formatter:off
|
||||
Bundle found = ourClient.search()
|
||||
.forResource(Patient.class)
|
||||
.where(Patient.NAME.matches().value("testSearchLastUpdatedParamRp"))
|
||||
.returnBundle(Bundle.class)
|
||||
.execute();
|
||||
//@formatter:on
|
||||
List<IdDt> patients = toIdListUnqualifiedVersionless(found);
|
||||
assertThat(patients, hasItems(id1a, id1b, id2));
|
||||
}
|
||||
|
||||
{
|
||||
//@formatter:off
|
||||
Bundle found = ourClient.search()
|
||||
.forResource(Patient.class)
|
||||
.where(Patient.NAME.matches().value("testSearchLastUpdatedParamRp"))
|
||||
.lastUpdated(new DateRangeParam(beforeR2, null))
|
||||
.returnBundle(Bundle.class)
|
||||
.execute();
|
||||
//@formatter:on
|
||||
List<IdDt> patients = toIdListUnqualifiedVersionless(found);
|
||||
assertThat(patients, hasItems(id2));
|
||||
assertThat(patients, not(hasItems(id1a, id1b)));
|
||||
}
|
||||
{
|
||||
//@formatter:off
|
||||
Bundle found = ourClient.search()
|
||||
.forResource(Patient.class)
|
||||
.where(Patient.NAME.matches().value("testSearchLastUpdatedParamRp"))
|
||||
.lastUpdated(new DateRangeParam(beforeAny, beforeR2))
|
||||
.returnBundle(Bundle.class)
|
||||
.execute();
|
||||
//@formatter:on
|
||||
|
||||
List<IdDt> patients = toIdListUnqualifiedVersionless(found);
|
||||
assertThat(patients.toString(), patients, not(hasItems(id2)));
|
||||
assertThat(patients.toString(), patients, (hasItems(id1a, id1b)));
|
||||
}
|
||||
{
|
||||
//@formatter:off
|
||||
Bundle found = ourClient.search()
|
||||
.forResource(Patient.class)
|
||||
.where(Patient.NAME.matches().value("testSearchLastUpdatedParamRp"))
|
||||
.lastUpdated(new DateRangeParam(null, beforeR2))
|
||||
.returnBundle(Bundle.class)
|
||||
.execute();
|
||||
//@formatter:on
|
||||
|
||||
List<IdDt> patients = toIdListUnqualifiedVersionless(found);
|
||||
assertThat(patients, (hasItems(id1a, id1b)));
|
||||
assertThat(patients, not(hasItems(id2)));
|
||||
|
@ -1985,14 +2022,12 @@ public class ResourceProviderDstu2Test extends BaseResourceProviderDstu2Test {
|
|||
Date before = new Date();
|
||||
Thread.sleep(100);
|
||||
|
||||
//@formatter:off
|
||||
ca.uhn.fhir.model.dstu2.resource.Bundle found = ourClient
|
||||
.search()
|
||||
.forResource(Patient.class)
|
||||
.prettyPrint()
|
||||
.returnBundle(ca.uhn.fhir.model.dstu2.resource.Bundle.class)
|
||||
.execute();
|
||||
//@formatter:on
|
||||
|
||||
Thread.sleep(100);
|
||||
Date after = new Date();
|
||||
|
@ -2018,23 +2053,22 @@ public class ResourceProviderDstu2Test extends BaseResourceProviderDstu2Test {
|
|||
pat.getManagingOrganization().setReference(orgId.toUnqualifiedVersionless());
|
||||
ourClient.create().resource(pat).prettyPrint().encodedXml().execute().getId();
|
||||
|
||||
//@formatter:off
|
||||
Bundle found = ourClient
|
||||
.search()
|
||||
.forResource(Patient.class)
|
||||
.where(Patient.IDENTIFIER.exactly().systemAndIdentifier("urn:system:rpdstu2","testSearchWithInclude02"))
|
||||
.include(Patient.INCLUDE_ORGANIZATION)
|
||||
.prettyPrint()
|
||||
.returnBundle(Bundle.class)
|
||||
.execute();
|
||||
//@formatter:on
|
||||
|
||||
assertEquals(2, found.getEntry().size());
|
||||
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));
|
||||
assertThat(found.getEntry().get(0).getResource().getText().getDiv().getValueAsString(), containsString("<table class=\"hapiPropertyTable"));
|
||||
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));
|
||||
}
|
||||
|
||||
|
@ -2043,14 +2077,12 @@ public class ResourceProviderDstu2Test extends BaseResourceProviderDstu2Test {
|
|||
Observation o = new Observation();
|
||||
o.getCode().setText("testSearchWithInvalidSort");
|
||||
myObservationDao.create(o, mySrd);
|
||||
//@formatter:off
|
||||
ourClient
|
||||
.search()
|
||||
.forResource(Observation.class)
|
||||
.sort().ascending(Observation.CODE_VALUE_QUANTITY) // composite sort not supported yet
|
||||
.prettyPrint()
|
||||
.execute();
|
||||
//@formatter:on
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -2086,15 +2118,14 @@ public class ResourceProviderDstu2Test extends BaseResourceProviderDstu2Test {
|
|||
IdDt orgMissing = (IdDt) ourClient.create().resource(org).prettyPrint().encodedXml().execute().getId().toUnqualifiedVersionless();
|
||||
|
||||
{
|
||||
//@formatter:off
|
||||
Bundle found = ourClient
|
||||
.search()
|
||||
.forResource(Organization.class)
|
||||
.where(Organization.NAME.isMissing(false))
|
||||
.count(100)
|
||||
.prettyPrint()
|
||||
.returnBundle(Bundle.class)
|
||||
.execute();
|
||||
//@formatter:on
|
||||
|
||||
List<IdDt> list = toIdListUnqualifiedVersionless(found);
|
||||
ourLog.info(methodName + ": " + list.toString());
|
||||
|
@ -2104,15 +2135,14 @@ public class ResourceProviderDstu2Test extends BaseResourceProviderDstu2Test {
|
|||
assertThat(list, not(containsInRelativeOrder(orgMissing)));
|
||||
}
|
||||
|
||||
//@formatter:off
|
||||
Bundle found = ourClient
|
||||
.search()
|
||||
.forResource(Organization.class)
|
||||
.where(Organization.NAME.isMissing(true))
|
||||
.count(100)
|
||||
.prettyPrint()
|
||||
.execute();
|
||||
//@formatter:on
|
||||
Bundle found = ourClient
|
||||
.search()
|
||||
.forResource(Organization.class)
|
||||
.where(Organization.NAME.isMissing(true))
|
||||
.count(100)
|
||||
.prettyPrint()
|
||||
.returnBundle(Bundle.class)
|
||||
.execute();
|
||||
|
||||
List<IdDt> list = toIdListUnqualifiedVersionless(found);
|
||||
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");
|
||||
ourClient.create().resource(p).execute();
|
||||
|
||||
//@formatter:off
|
||||
Bundle resp = ourClient
|
||||
.search()
|
||||
.forResource(Patient.class)
|
||||
|
@ -2244,14 +2273,13 @@ public class ResourceProviderDstu2Test extends BaseResourceProviderDstu2Test {
|
|||
.sort().ascending(Patient.FAMILY)
|
||||
.sort().ascending(Patient.GIVEN)
|
||||
.count(100)
|
||||
.returnBundle(Bundle.class)
|
||||
.execute();
|
||||
//@formatter:on
|
||||
|
||||
List<String> names = toNameList(resp);
|
||||
|
||||
ourLog.info(StringUtils.join(names, '\n'));
|
||||
|
||||
//@formatter:off
|
||||
assertThat(names, contains( // this matches in order only
|
||||
"Daniel Adams",
|
||||
"Aaron Alexis",
|
||||
|
@ -2269,7 +2297,6 @@ public class ResourceProviderDstu2Test extends BaseResourceProviderDstu2Test {
|
|||
"Brian Gracia",
|
||||
"Sarah Graham",
|
||||
"Stephan Graham"));
|
||||
//@formatter:om
|
||||
|
||||
}
|
||||
|
||||
|
@ -2474,7 +2501,15 @@ public class ResourceProviderDstu2Test extends BaseResourceProviderDstu2Test {
|
|||
|
||||
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(p1Id.getIdPart(), actual.getEntry().get(0).getResource().getId().getIdPart());
|
||||
|
||||
|
|
|
@ -1,12 +1,13 @@
|
|||
package ca.uhn.fhir.rest.server;
|
||||
|
||||
import static org.mockito.Matchers.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
import static org.mockito.Matchers.any;
|
||||
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.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
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.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 org.junit.*;
|
||||
import org.mockito.InOrder;
|
||||
|
||||
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.primitive.IdDt;
|
||||
import ca.uhn.fhir.model.primitive.UriDt;
|
||||
import ca.uhn.fhir.rest.annotation.IdParam;
|
||||
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.annotation.*;
|
||||
import ca.uhn.fhir.rest.api.RestOperationTypeEnum;
|
||||
import ca.uhn.fhir.rest.method.RequestDetails;
|
||||
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
|
||||
public IBaseResource getResourceBundle() {
|
||||
return myBundle;
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -258,11 +258,6 @@ public class Dstu2BundleFactory implements IVersionSpecificBundleFactory {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ca.uhn.fhir.model.api.Bundle getDstu1Bundle() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IResource getResourceBundle() {
|
||||
return myBundle;
|
||||
|
|
|
@ -36,7 +36,6 @@ import com.google.common.collect.Sets;
|
|||
import ca.uhn.fhir.context.ConfigurationException;
|
||||
import ca.uhn.fhir.context.FhirContext;
|
||||
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.dstu2.composite.*;
|
||||
import ca.uhn.fhir.model.dstu2.resource.*;
|
||||
|
@ -74,7 +73,7 @@ public class JsonParserDstu2Test {
|
|||
ourCtx = FhirContext.forDstu2();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testOverrideResourceIdWithBundleEntryFullUrlDisabled_ConfiguredOnParser() {
|
||||
try {
|
||||
|
@ -94,30 +93,30 @@ public class JsonParserDstu2Test {
|
|||
ourCtx = FhirContext.forDstu2();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* See #544
|
||||
*/
|
||||
@Test
|
||||
public void testBundleStitchReferencesByUuid() throws Exception {
|
||||
ca.uhn.fhir.model.dstu2.resource.Bundle bundle = new ca.uhn.fhir.model.dstu2.resource.Bundle();
|
||||
|
||||
|
||||
DocumentManifest dm = new DocumentManifest();
|
||||
dm.getSubject().setReference("urn:uuid:96e85cca-9797-45d6-834a-c4eb27f331d3");
|
||||
bundle.addEntry().setResource(dm);
|
||||
|
||||
|
||||
Patient patient = new Patient();
|
||||
patient.addName().addFamily("FAMILY");
|
||||
bundle.addEntry().setResource(patient).setFullUrl("urn:uuid:96e85cca-9797-45d6-834a-c4eb27f331d3");
|
||||
|
||||
|
||||
String encoded = ourCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(bundle);
|
||||
ourLog.info(encoded);
|
||||
|
||||
|
||||
bundle = ourCtx.newJsonParser().parseResource(ca.uhn.fhir.model.dstu2.resource.Bundle.class, encoded);
|
||||
dm = (DocumentManifest) bundle.getEntry().get(0).getResource();
|
||||
|
||||
|
||||
assertEquals("urn:uuid:96e85cca-9797-45d6-834a-c4eb27f331d3", dm.getSubject().getReference().getValue());
|
||||
|
||||
|
||||
Patient subject = (Patient) dm.getSubject().getResource();
|
||||
assertNotNull(subject);
|
||||
assertEquals("FAMILY", subject.getNameFirstRep().getFamilyAsSingleString());
|
||||
|
@ -145,21 +144,6 @@ public class JsonParserDstu2Test {
|
|||
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
|
||||
*/
|
||||
|
@ -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
|
||||
public void testEncodeDoesntIncludeUuidId() {
|
||||
|
@ -1055,28 +1002,28 @@ public class JsonParserDstu2Test {
|
|||
public void testParseAndEncodeBundle() throws Exception {
|
||||
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("1", parsed.getResourceMetadata().get(ResourceMetadataKeyEnum.VERSION));
|
||||
assertEquals("1", parsed.getId().getVersionIdPart());
|
||||
assertEquals(new InstantDt("2014-08-18T01:43:30Z"), parsed.getResourceMetadata().get(ResourceMetadataKeyEnum.UPDATED));
|
||||
assertEquals("searchset", parsed.getType().getValue());
|
||||
assertEquals(3, parsed.getTotalResults().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&_include=MedicationOrder.medication", parsed.getLinkSelf().getValue());
|
||||
assertEquals("searchset", parsed.getTypeElement().getValueAsString());
|
||||
assertEquals(3, parsed.getTotalElement().getValue().intValue());
|
||||
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.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("2014-08-16T05:31:17Z", ResourceMetadataKeyEnum.UPDATED.get(p).getValueAsString());
|
||||
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());
|
||||
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);
|
||||
|
||||
JsonConfig cfg = new JsonConfig();
|
||||
|
@ -1130,7 +1077,7 @@ public class JsonParserDstu2Test {
|
|||
assertEquals("1", parsed.getResourceMetadata().get(ResourceMetadataKeyEnum.VERSION));
|
||||
assertEquals("1", parsed.getId().getVersionIdPart());
|
||||
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("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());
|
||||
|
@ -1169,25 +1116,25 @@ public class JsonParserDstu2Test {
|
|||
public void testParseAndEncodeBundleOldStyle() throws Exception {
|
||||
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("searchset", parsed.getType().getValue());
|
||||
assertEquals(3, parsed.getTotalResults().getValue().intValue());
|
||||
assertEquals("searchset", parsed.getTypeElement().getValue());
|
||||
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("2014-08-16T05:31:17Z", ResourceMetadataKeyEnum.UPDATED.get(p).getValueAsString());
|
||||
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("Medication/example", ((ResourceReferenceDt) p.getMedication()).getReference().getValue());
|
||||
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);
|
||||
|
||||
JsonConfig cfg = new JsonConfig();
|
||||
|
@ -1211,31 +1158,13 @@ public class JsonParserDstu2Test {
|
|||
public void testParseAndEncodeBundleResourceWithComments() throws Exception {
|
||||
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);
|
||||
|
||||
// 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
|
||||
public void testParseAndEncodeBundleWithUuidBase() {
|
||||
//@formatter:off
|
||||
|
@ -1531,38 +1460,32 @@ public class JsonParserDstu2Test {
|
|||
" \"lastUpdated\" : \"2001-02-22T11:22:33-05:00\"\n" +
|
||||
" },\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" +
|
||||
"}";
|
||||
//@formatter:on
|
||||
|
||||
Bundle b = ourCtx.newJsonParser().parseBundle(bundle);
|
||||
assertEquals(1, b.getEntries().size());
|
||||
Bundle b = ourCtx.newJsonParser().parseResource(Bundle.class, bundle);
|
||||
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("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("POST", ResourceMetadataKeyEnum.ENTRY_TRANSACTION_METHOD.get(pt).getCode());
|
||||
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("match", ResourceMetadataKeyEnum.ENTRY_SEARCH_MODE.get(pt).getCode());
|
||||
// assertEquals("POST", ResourceMetadataKeyEnum.ENTRY_TRANSACTION_METHOD.get(pt).getCode());
|
||||
// assertEquals("http://foo/Patient?identifier=value", ResourceMetadataKeyEnum.LINK_SEARCH.get(pt));
|
||||
// assertEquals("2001-02-22T11:22:33-05:00", ResourceMetadataKeyEnum.UPDATED.get(pt).getValueAsString());
|
||||
|
||||
Bundle toBundle = new Bundle();
|
||||
toBundle.getLinkBase().setValue("http://foo/fhirBase1");
|
||||
toBundle.getTotalResults().setValue(1);
|
||||
toBundle.getLinkSelf().setValue("http://localhost:52788/Binary?_pretty=true");
|
||||
toBundle.getTotalElement().setValue(1);
|
||||
// toBundle.getLinkOrCreate("base").setUrl("http://foo/fhirBase1");
|
||||
toBundle.getLinkOrCreate("self").setUrl("http://localhost:52788/Binary?_pretty=true");
|
||||
|
||||
toBundle.addResource(pt, ourCtx, "http://foo/fhirBase1");
|
||||
String reEncoded = ourCtx.newJsonParser().setPrettyPrint(true).encodeBundleToString(toBundle);
|
||||
toBundle
|
||||
.addEntry()
|
||||
.setFullUrl("http://foo/fhirBase2/Patient/1/_history/2")
|
||||
.setResource(pt);
|
||||
String reEncoded = ourCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(toBundle);
|
||||
|
||||
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\"}]}}]}";
|
||||
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());
|
||||
|
||||
assertNull(ResourceMetadataKeyEnum.TAG_LIST.get(patient));
|
||||
|
@ -1999,29 +1922,29 @@ public class JsonParserDstu2Test {
|
|||
patient.setPetName(new StringDt("myName"));
|
||||
|
||||
final Bundle bundle = new Bundle();
|
||||
final BundleEntry entry = new BundleEntry();
|
||||
final Entry entry = new Entry();
|
||||
entry.setResource(patient);
|
||||
bundle.addEntry(entry);
|
||||
|
||||
final IParser jsonParser = ourCtx.newJsonParser();
|
||||
jsonParser.setServerBaseUrl("http://www.example.com");
|
||||
|
||||
final String parsedBundle = jsonParser.encodeBundleToString(bundle);
|
||||
final String parsedBundle = jsonParser.encodeResourceToString(bundle);
|
||||
System.out.println(parsedBundle);
|
||||
assertEquals(expected, parsedBundle);
|
||||
|
||||
// Parse with string
|
||||
Bundle newBundle = jsonParser.parseBundle(parsedBundle);
|
||||
Bundle newBundle = jsonParser.parseResource(Bundle.class, parsedBundle);
|
||||
assertNotNull(newBundle);
|
||||
assertEquals(1, newBundle.getEntries().size());
|
||||
Patient newPatient = (Patient) newBundle.getEntries().get(0).getResource();
|
||||
assertEquals(1, newBundle.getEntry().size());
|
||||
Patient newPatient = (Patient) newBundle.getEntry().get(0).getResource();
|
||||
assertEquals("myName", ((StringDt) newPatient.getUndeclaredExtensionsByUrl("http://www.example.com/petname").get(0).getValue()).getValue());
|
||||
|
||||
// Parse with stream
|
||||
newBundle = jsonParser.parseBundle(new StringReader(parsedBundle));
|
||||
newBundle = jsonParser.parseResource(Bundle.class, new StringReader(parsedBundle));
|
||||
assertNotNull(newBundle);
|
||||
assertEquals(1, newBundle.getEntries().size());
|
||||
newPatient = (Patient) newBundle.getEntries().get(0).getResource();
|
||||
assertEquals(1, newBundle.getEntry().size());
|
||||
newPatient = (Patient) newBundle.getEntry().get(0).getResource();
|
||||
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.model.api.*;
|
||||
import ca.uhn.fhir.model.api.Bundle;
|
||||
import ca.uhn.fhir.model.api.annotation.Child;
|
||||
import ca.uhn.fhir.model.api.annotation.ResourceDef;
|
||||
import ca.uhn.fhir.model.base.composite.BaseCodingDt;
|
||||
|
@ -67,7 +66,7 @@ public class XmlParserDstu2Test {
|
|||
ourCtx = FhirContext.forDstu2();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testOverrideResourceIdWithBundleEntryFullUrlDisabled_ConfiguredOnFhirContext() {
|
||||
try {
|
||||
|
@ -88,7 +87,7 @@ public class XmlParserDstu2Test {
|
|||
ourCtx = null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testOverrideResourceIdWithBundleEntryFullUrlDisabled_ConfiguredOnParser() {
|
||||
try {
|
||||
|
@ -108,7 +107,7 @@ public class XmlParserDstu2Test {
|
|||
ourCtx = null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* See #414
|
||||
*/
|
||||
|
@ -137,10 +136,9 @@ public class XmlParserDstu2Test {
|
|||
} catch (DataFormatException e) {
|
||||
assertEquals("Resource is missing required element 'url' in parent element 'extension'", e.getCause().getMessage());
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* See #414
|
||||
*/
|
||||
|
@ -169,9 +167,9 @@ public class XmlParserDstu2Test {
|
|||
} catch (DataFormatException e) {
|
||||
assertEquals("Resource is missing required element 'url' in parent element 'modifierExtension'", e.getCause().getMessage());
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* If a contained resource refers to a contained resource that comes after it, it should still be successfully
|
||||
* woven together.
|
||||
|
@ -179,11 +177,11 @@ public class XmlParserDstu2Test {
|
|||
@Test
|
||||
public void testParseWovenContainedResources() throws IOException {
|
||||
String string = IOUtils.toString(getClass().getResourceAsStream("/bundle_with_woven_obs.xml"), StandardCharsets.UTF_8);
|
||||
|
||||
|
||||
IParser parser = ourCtx.newXmlParser();
|
||||
parser.setParserErrorHandler(new StrictErrorHandler());
|
||||
ca.uhn.fhir.model.dstu2.resource.Bundle bundle = parser.parseResource(ca.uhn.fhir.model.dstu2.resource.Bundle.class, string);
|
||||
|
||||
|
||||
DiagnosticReport resource = (DiagnosticReport) bundle.getEntry().get(0).getResource();
|
||||
Observation obs = (Observation) resource.getResult().get(1).getResource();
|
||||
assertEquals("#2", obs.getId().getValue());
|
||||
|
@ -191,30 +189,29 @@ public class XmlParserDstu2Test {
|
|||
Practitioner performer = (Practitioner) performerFirstRep.getResource();
|
||||
assertEquals("#3", performer.getId().getValue());
|
||||
}
|
||||
|
||||
@Test(expected=DataFormatException.class)
|
||||
|
||||
@Test(expected = DataFormatException.class)
|
||||
public void testContainedResourceWithNoId() throws IOException {
|
||||
String string = IOUtils.toString(getClass().getResourceAsStream("/bundle_with_contained_with_no_id.xml"), StandardCharsets.UTF_8);
|
||||
|
||||
|
||||
IParser parser = ourCtx.newXmlParser();
|
||||
parser.setParserErrorHandler(new StrictErrorHandler());
|
||||
parser.parseResource(ca.uhn.fhir.model.dstu2.resource.Bundle.class, string);
|
||||
}
|
||||
|
||||
|
||||
@Test()
|
||||
public void testContainedResourceWithNoIdLenient() throws IOException {
|
||||
String string = IOUtils.toString(getClass().getResourceAsStream("/bundle_with_contained_with_no_id.xml"), StandardCharsets.UTF_8);
|
||||
|
||||
|
||||
IParser parser = ourCtx.newXmlParser();
|
||||
parser.setParserErrorHandler(new LenientErrorHandler());
|
||||
parser.parseResource(ca.uhn.fhir.model.dstu2.resource.Bundle.class, string);
|
||||
}
|
||||
|
||||
@Test(expected=DataFormatException.class)
|
||||
@Test(expected = DataFormatException.class)
|
||||
public void testParseWithInvalidLocalRef() throws IOException {
|
||||
String string = IOUtils.toString(getClass().getResourceAsStream("/bundle_with_invalid_contained_ref.xml"), StandardCharsets.UTF_8);
|
||||
|
||||
|
||||
IParser parser = ourCtx.newXmlParser();
|
||||
parser.setParserErrorHandler(new StrictErrorHandler());
|
||||
parser.parseResource(ca.uhn.fhir.model.dstu2.resource.Bundle.class, string);
|
||||
|
@ -223,13 +220,12 @@ public class XmlParserDstu2Test {
|
|||
@Test()
|
||||
public void testParseWithInvalidLocalRefLenient() throws IOException {
|
||||
String string = IOUtils.toString(getClass().getResourceAsStream("/bundle_with_invalid_contained_ref.xml"), StandardCharsets.UTF_8);
|
||||
|
||||
|
||||
IParser parser = ourCtx.newXmlParser();
|
||||
parser.setParserErrorHandler(new LenientErrorHandler());
|
||||
parser.parseResource(ca.uhn.fhir.model.dstu2.resource.Bundle.class, string);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testBundleWithBinary() {
|
||||
//@formatter:off
|
||||
|
@ -254,14 +250,14 @@ public class XmlParserDstu2Test {
|
|||
"</Bundle>";
|
||||
//@formatter:on
|
||||
|
||||
Bundle b = ourCtx.newXmlParser().parseBundle(bundle);
|
||||
assertEquals(1, b.getEntries().size());
|
||||
Bundle b = ourCtx.newXmlParser().parseResource(Bundle.class, bundle);
|
||||
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());
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testChoiceTypeWithProfiledType() {
|
||||
//@formatter:off
|
||||
|
@ -281,7 +277,7 @@ public class XmlParserDstu2Test {
|
|||
String encoded = ourCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(parsed);
|
||||
assertThat(encoded, containsString("<valueMarkdown value=\"THIS IS MARKDOWN\"/>"));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testChoiceTypeWithProfiledType2() {
|
||||
Parameters par = new Parameters();
|
||||
|
@ -299,7 +295,6 @@ public class XmlParserDstu2Test {
|
|||
assertEquals(MarkdownDt.class, par.getParameter().get(1).getValue().getClass());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testContainedResourceInExtensionUndeclared() {
|
||||
Patient p = new Patient();
|
||||
|
@ -359,13 +354,14 @@ public class XmlParserDstu2Test {
|
|||
Organization org = new Organization();
|
||||
org.addIdentifier().setSystem("urn:system").setValue("someval");
|
||||
|
||||
Bundle bundle = Bundle.withSingleResource(org);
|
||||
String str = ourCtx.newXmlParser().encodeBundleToString(bundle);
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.addEntry().setResource(org);
|
||||
String str = ourCtx.newXmlParser().encodeResourceToString(bundle);
|
||||
ourLog.info(str);
|
||||
|
||||
Bundle parsed = ourCtx.newXmlParser().parseBundle(str);
|
||||
assertThat(parsed.getEntries().get(0).getResource().getId().getValue(), emptyOrNullString());
|
||||
assertTrue(parsed.getEntries().get(0).getResource().getId().isEmpty());
|
||||
Bundle parsed = ourCtx.newXmlParser().parseResource(Bundle.class, str);
|
||||
assertThat(parsed.getEntry().get(0).getResource().getId().getValue(), emptyOrNullString());
|
||||
assertTrue(parsed.getEntry().get(0).getResource().getId().isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -479,20 +475,20 @@ public class XmlParserDstu2Test {
|
|||
ourCtx = FhirContext.forDstu2();
|
||||
ourCtx.setDefaultTypeForProfile(CustomObservationDstu2.PROFILE, CustomObservationDstu2.class);
|
||||
ourCtx.setDefaultTypeForProfile(CustomDiagnosticReportDstu2.PROFILE, CustomDiagnosticReportDstu2.class);
|
||||
|
||||
|
||||
CustomObservationDstu2 obs = new CustomObservationDstu2();
|
||||
obs.setStatus(ObservationStatusEnum.FINAL);
|
||||
|
||||
|
||||
CustomDiagnosticReportDstu2 dr = new CustomDiagnosticReportDstu2();
|
||||
dr.setStatus(DiagnosticReportStatusEnum.FINAL);
|
||||
dr.addResult().setResource(obs);
|
||||
|
||||
|
||||
IParser parser = ourCtx.newXmlParser();
|
||||
parser.setPrettyPrint(true);
|
||||
|
||||
|
||||
String output = parser.encodeResourceToString(dr);
|
||||
ourLog.info(output);
|
||||
|
||||
|
||||
//@formatter:off
|
||||
assertThat(output,stringContainsInOrder(
|
||||
"<DiagnosticReport xmlns=\"http://hl7.org/fhir\">",
|
||||
|
@ -514,11 +510,11 @@ public class XmlParserDstu2Test {
|
|||
"</result>",
|
||||
"</DiagnosticReport>"));
|
||||
//@formatter:on
|
||||
|
||||
|
||||
/*
|
||||
* Now PARSE!
|
||||
*/
|
||||
|
||||
|
||||
dr = (CustomDiagnosticReportDstu2) parser.parseResource(output);
|
||||
assertEquals(DiagnosticReportStatusEnum.FINAL, dr.getStatusElement().getValueAsEnum());
|
||||
|
||||
|
@ -549,35 +545,34 @@ public class XmlParserDstu2Test {
|
|||
"<status value=\"final\"/>" +
|
||||
"</DiagnosticReport>";
|
||||
//@formatter:on
|
||||
|
||||
|
||||
IParser parser = ourCtx.newXmlParser();
|
||||
CustomDiagnosticReportDstu2 dr = (CustomDiagnosticReportDstu2) parser.parseResource(input);
|
||||
assertEquals(DiagnosticReportStatusEnum.FINAL, dr.getStatusElement().getValueAsEnum());
|
||||
|
||||
List<IdDt> profiles = ResourceMetadataKeyEnum.PROFILES.get(dr);
|
||||
assertEquals(3, profiles.size());
|
||||
|
||||
|
||||
ourCtx = null;
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testEncodeAndParseContainedNonCustomTypes() {
|
||||
ourCtx = FhirContext.forDstu2();
|
||||
|
||||
|
||||
Observation obs = new Observation();
|
||||
obs.setStatus(ObservationStatusEnum.FINAL);
|
||||
|
||||
|
||||
DiagnosticReport dr = new DiagnosticReport();
|
||||
dr.setStatus(DiagnosticReportStatusEnum.FINAL);
|
||||
dr.addResult().setResource(obs);
|
||||
|
||||
|
||||
IParser parser = ourCtx.newXmlParser();
|
||||
parser.setPrettyPrint(true);
|
||||
|
||||
|
||||
String output = parser.encodeResourceToString(dr);
|
||||
ourLog.info(output);
|
||||
|
||||
|
||||
//@formatter:off
|
||||
assertThat(output,stringContainsInOrder(
|
||||
"<DiagnosticReport xmlns=\"http://hl7.org/fhir\">",
|
||||
|
@ -593,11 +588,11 @@ public class XmlParserDstu2Test {
|
|||
"</result>",
|
||||
"</DiagnosticReport>"));
|
||||
//@formatter:on
|
||||
|
||||
|
||||
/*
|
||||
* Now PARSE!
|
||||
*/
|
||||
|
||||
|
||||
dr = (DiagnosticReport) parser.parseResource(output);
|
||||
assertEquals(DiagnosticReportStatusEnum.FINAL, dr.getStatusElement().getValueAsEnum());
|
||||
|
||||
|
@ -621,10 +616,10 @@ public class XmlParserDstu2Test {
|
|||
condition.setOurAbatement(new DateTimeDt(new Date()));
|
||||
|
||||
String conditionXml = parser.encodeResourceToString(condition);
|
||||
|
||||
|
||||
ourLog.info(conditionXml);
|
||||
assertThat(conditionXml, containsString("abatementDateTime"));
|
||||
|
||||
|
||||
CustomCondition parsedCondition = (CustomCondition) parser.parseResource(conditionXml);
|
||||
assertNotNull(parsedCondition.getOurAbatement());
|
||||
}
|
||||
|
@ -1120,9 +1115,9 @@ public class XmlParserDstu2Test {
|
|||
p.addName().addFamily("PATIENT");
|
||||
|
||||
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);
|
||||
assertThat(encoded, stringContainsInOrder("<Bundle", "<entry>", "<fullUrl value=\"" + p.getId().getValue() + "\"/>", "<Patient"));
|
||||
assertThat(encoded, not(containsString("<id value=\"" + p.getId().getIdPart() + "\"/>")));
|
||||
|
@ -1135,10 +1130,10 @@ public class XmlParserDstu2Test {
|
|||
p.addName().addFamily("PATIENT");
|
||||
|
||||
Bundle b = new Bundle();
|
||||
b.getLinkBase().setValue("urn:uuid:");
|
||||
b.getLinkOrCreate("base").setUrl("urn:uuid:");
|
||||
b.addEntry().setResource(p);
|
||||
|
||||
String encoded = ourCtx.newXmlParser().setPrettyPrint(true).encodeBundleToString(b);
|
||||
String encoded = ourCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(b);
|
||||
ourLog.info(encoded);
|
||||
// Base element has been removed!
|
||||
assertThat(encoded, not(stringContainsInOrder("<Bundle", "<entry>", "<base value=\"", "<Patient", "<id value=")));
|
||||
|
@ -1318,7 +1313,7 @@ public class XmlParserDstu2Test {
|
|||
"<pre>line1\nline2\nline3 <b>BOLD</b></pre>"
|
||||
));
|
||||
//@formatter:on
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1326,13 +1321,13 @@ public class XmlParserDstu2Test {
|
|||
*/
|
||||
@Test
|
||||
public void testEncodeDivWithPrePrettyPrint() {
|
||||
|
||||
|
||||
Patient p = new Patient();
|
||||
p.getText().setDiv("<div>\n\n<p>A P TAG</p><p><pre>line1\nline2\nline3 <b>BOLD</b></pre></p></div>");
|
||||
|
||||
|
||||
String output = ourCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(p);
|
||||
ourLog.info(output);
|
||||
|
||||
|
||||
//@formatter:off
|
||||
assertThat(output, stringContainsInOrder(
|
||||
" <text>",
|
||||
|
@ -1340,7 +1335,7 @@ public class XmlParserDstu2Test {
|
|||
" <pre>line1\nline2\nline3 <b>BOLD</b></pre>"
|
||||
));
|
||||
//@formatter:on
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -1352,7 +1347,7 @@ public class XmlParserDstu2Test {
|
|||
String actual = ourCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(p);
|
||||
assertThat(actual, not(containsString("78ef6f64c2f2")));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testEncodeEmptyBinary() {
|
||||
String output = ourCtx.newXmlParser().encodeResourceToString(new Binary());
|
||||
|
@ -1367,10 +1362,10 @@ public class XmlParserDstu2Test {
|
|||
TagList tagList = new TagList();
|
||||
tagList.addTag(null, null, null);
|
||||
tagList.addTag(null, null, "Label");
|
||||
|
||||
|
||||
Patient p = new Patient();
|
||||
ResourceMetadataKeyEnum.TAG_LIST.put(p, tagList);
|
||||
|
||||
|
||||
String encoded = ourCtx.newXmlParser().encodeResourceToString(p);
|
||||
assertThat(encoded, not(containsString("tag")));
|
||||
}
|
||||
|
@ -1383,10 +1378,10 @@ public class XmlParserDstu2Test {
|
|||
TagList tagList = new TagList();
|
||||
tagList.addTag("scheme", "code", null);
|
||||
tagList.addTag(null, null, "Label");
|
||||
|
||||
|
||||
Patient p = new Patient();
|
||||
ResourceMetadataKeyEnum.TAG_LIST.put(p, tagList);
|
||||
|
||||
|
||||
String encoded = ourCtx.newXmlParser().encodeResourceToString(p);
|
||||
assertThat(encoded, containsString("tag"));
|
||||
assertThat(encoded, containsString("scheme"));
|
||||
|
@ -1400,11 +1395,11 @@ public class XmlParserDstu2Test {
|
|||
obs.getMeta().addProfile("http://profile");
|
||||
ExtensionDt ext = obs.addUndeclaredExtension(false, "http://exturl");
|
||||
ext.setUrl("http://exturl").setValue(new StringDt("ext_url_value"));
|
||||
|
||||
|
||||
obs.getCode().setText("CODE");
|
||||
|
||||
|
||||
IParser parser = ourCtx.newXmlParser();
|
||||
|
||||
|
||||
String output = parser.setPrettyPrint(true).encodeResourceToString(obs);
|
||||
ourLog.info(output);
|
||||
|
||||
|
@ -1912,30 +1907,30 @@ public class XmlParserDstu2Test {
|
|||
public void testParseAndEncodeBundle() throws Exception {
|
||||
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("1", parsed.getResourceMetadata().get(ResourceMetadataKeyEnum.VERSION));
|
||||
assertEquals("1", parsed.getId().getVersionIdPart());
|
||||
assertEquals(new InstantDt("2014-08-18T01:43:30Z"), parsed.getResourceMetadata().get(ResourceMetadataKeyEnum.UPDATED));
|
||||
assertEquals("searchset", parsed.getType().getValue());
|
||||
assertEquals(3, parsed.getTotalResults().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&_include=MedicationOrder.medication", parsed.getLinkSelf().getValue());
|
||||
assertEquals("searchset", parsed.getTypeElement().getValue());
|
||||
assertEquals(3, parsed.getTotalElement().getValue().intValue());
|
||||
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.getLink("self").getUrl());
|
||||
|
||||
assertEquals(2, parsed.getEntries().size());
|
||||
assertEquals("http://foo?search", parsed.getEntries().get(0).getLinkSearch().getValue());
|
||||
assertEquals(2, parsed.getEntry().size());
|
||||
// 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.getEntries().get(0).getResource();
|
||||
MedicationOrder p = (MedicationOrder) parsed.getEntry().get(0).getResource();
|
||||
assertEquals("Patient/347", p.getPatient().getReference().getValue());
|
||||
assertEquals("2014-08-16T05:31:17Z", ResourceMetadataKeyEnum.UPDATED.get(p).getValueAsString());
|
||||
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());
|
||||
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);
|
||||
|
||||
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("1", parsed.getResourceMetadata().get(ResourceMetadataKeyEnum.VERSION));
|
||||
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("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());
|
||||
|
@ -2404,46 +2399,8 @@ public class XmlParserDstu2Test {
|
|||
"</Bundle>";
|
||||
//@formatter:on
|
||||
|
||||
Bundle b = ourCtx.newXmlParser().parseBundle(bundle);
|
||||
assertEquals(1, b.getEntries().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());
|
||||
Bundle b = ourCtx.newXmlParser().parseResource(Bundle.class, bundle);
|
||||
assertEquals(1, b.getEntry().size());
|
||||
|
||||
}
|
||||
|
||||
|
@ -2452,8 +2409,6 @@ public class XmlParserDstu2Test {
|
|||
// TODO: implement this test, make sure we handle ID and meta correctly in Binary
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* See #191
|
||||
*/
|
||||
|
@ -2559,15 +2514,14 @@ public class XmlParserDstu2Test {
|
|||
/**
|
||||
* See #366
|
||||
*/
|
||||
@Test(expected=DataFormatException.class)
|
||||
@Test(expected = DataFormatException.class)
|
||||
public void testParseInvalidBoolean() {
|
||||
//@formatter:off
|
||||
String resource = "<Patient xmlns=\"http://hl7.org/fhir\">\n" +
|
||||
" <active value=\"1\"/>\n" +
|
||||
"</Patient>";
|
||||
//@formatter:on
|
||||
|
||||
|
||||
|
||||
IParser parser = ourCtx.newXmlParser();
|
||||
parser.setParserErrorHandler(new StrictErrorHandler());
|
||||
parser.parseResource(resource);
|
||||
|
@ -2621,6 +2575,10 @@ public class XmlParserDstu2Test {
|
|||
String bundle = "<Bundle xmlns=\"http://hl7.org/fhir\">\n" +
|
||||
" <total value=\"1\"/>\n" +
|
||||
" <link>\n" +
|
||||
" <relation value=\"base\"/>\n" +
|
||||
" <url value=\"http://foo/fhirBase1\"/>\n" +
|
||||
" </link>\n" +
|
||||
" <link>\n" +
|
||||
" <relation value=\"self\"/>\n" +
|
||||
" <url value=\"http://localhost:52788/Binary?_pretty=true\"/>\n" +
|
||||
" </link>\n" +
|
||||
|
@ -2636,37 +2594,33 @@ public class XmlParserDstu2Test {
|
|||
" <birthDate value=\"2012-01-02\"/>\n" +
|
||||
" </Patient>\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" +
|
||||
"</Bundle>";
|
||||
//@formatter:on
|
||||
|
||||
Bundle b = ourCtx.newXmlParser().parseBundle(bundle);
|
||||
assertEquals(1, b.getEntries().size());
|
||||
Bundle b = ourCtx.newXmlParser().parseResource(Bundle.class, bundle);
|
||||
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("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("POST", ResourceMetadataKeyEnum.ENTRY_TRANSACTION_METHOD.get(pt).getCode());
|
||||
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("0.123", ResourceMetadataKeyEnum.ENTRY_SCORE.get(pt).getValueAsString());
|
||||
// assertEquals("match", ResourceMetadataKeyEnum.ENTRY_SEARCH_MODE.get(pt).getCode());
|
||||
// assertEquals("POST", ResourceMetadataKeyEnum.ENTRY_TRANSACTION_METHOD.get(pt).getCode());
|
||||
// assertEquals("http://foo/Patient?identifier=value", ResourceMetadataKeyEnum.LINK_SEARCH.get(pt));
|
||||
// assertEquals("2001-02-22T11:22:33-05:00", ResourceMetadataKeyEnum.UPDATED.get(pt).getValueAsString());
|
||||
|
||||
Bundle toBundle = new Bundle();
|
||||
toBundle.getLinkBase().setValue("http://foo/fhirBase1");
|
||||
toBundle.getTotalResults().setValue(1);
|
||||
toBundle.getLinkSelf().setValue("http://localhost:52788/Binary?_pretty=true");
|
||||
toBundle.getLinkOrCreate("base").setUrl("http://foo/fhirBase1");
|
||||
toBundle.getTotalElement().setValue(1);
|
||||
toBundle.getLinkOrCreate("self").setUrl("http://localhost:52788/Binary?_pretty=true");
|
||||
|
||||
toBundle.addResource(pt, ourCtx, "http://foo/fhirBase1");
|
||||
String reEncoded = ourCtx.newXmlParser().setPrettyPrint(true).encodeBundleToString(toBundle);
|
||||
toBundle
|
||||
.addEntry()
|
||||
.setResource(pt)
|
||||
.setFullUrl("http://foo/fhirBase2/Patient/1/_history/2");
|
||||
|
||||
String reEncoded = ourCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(toBundle);
|
||||
|
||||
ourLog.info(reEncoded);
|
||||
|
||||
|
@ -2769,7 +2723,7 @@ public class XmlParserDstu2Test {
|
|||
assertEquals("Patient", reincarnatedPatient.getId().getResourceType());
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Test for the url generated based on the server config
|
||||
*/
|
||||
@Test
|
||||
|
@ -2811,7 +2765,7 @@ public class XmlParserDstu2Test {
|
|||
newPatient = xmlParser.parseResource(MyPatientWithCustomUrlExtension.class, new StringReader(parsedPatient));
|
||||
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));
|
||||
assertNull("myName", newPatient.getPetName().getValue());
|
||||
assertEquals("myName", ((StringDt) newPatient.getUndeclaredExtensionsByUrl("http://www.example.com/petname").get(0).getValue()).getValue());
|
||||
|
@ -2825,33 +2779,33 @@ public class XmlParserDstu2Test {
|
|||
patient.setPetName(new StringDt("myName"));
|
||||
|
||||
final Bundle bundle = new Bundle();
|
||||
final BundleEntry entry = new BundleEntry();
|
||||
final Entry entry = new Entry();
|
||||
entry.setResource(patient);
|
||||
bundle.addEntry(entry);
|
||||
|
||||
final IParser xmlParser = ourCtx.newXmlParser();
|
||||
xmlParser.setServerBaseUrl("http://www.example.com");
|
||||
|
||||
final String parsedBundle = xmlParser.encodeBundleToString(bundle);
|
||||
final String parsedBundle = xmlParser.encodeResourceToString(bundle);
|
||||
System.out.println(parsedBundle);
|
||||
assertEquals(expected, parsedBundle);
|
||||
|
||||
// Parse with string
|
||||
Bundle newBundle = xmlParser.parseBundle(parsedBundle);
|
||||
Bundle newBundle = xmlParser.parseResource(Bundle.class, parsedBundle);
|
||||
assertNotNull(newBundle);
|
||||
assertEquals(1, newBundle.getEntries().size());
|
||||
Patient newPatient = (Patient) newBundle.getEntries().get(0).getResource();
|
||||
assertEquals(1, newBundle.getEntry().size());
|
||||
Patient newPatient = (Patient) newBundle.getEntry().get(0).getResource();
|
||||
assertEquals("myName", ((StringDt) newPatient.getUndeclaredExtensionsByUrl("http://www.example.com/petname").get(0).getValue()).getValue());
|
||||
|
||||
// Parse with stream
|
||||
newBundle = xmlParser.parseBundle(new StringReader(parsedBundle));
|
||||
newBundle = xmlParser.parseResource(Bundle.class, new StringReader(parsedBundle));
|
||||
assertNotNull(newBundle);
|
||||
assertEquals(1, newBundle.getEntries().size());
|
||||
newPatient = (Patient) newBundle.getEntries().get(0).getResource();
|
||||
assertEquals(1, newBundle.getEntry().size());
|
||||
newPatient = (Patient) newBundle.getEntry().get(0).getResource();
|
||||
assertEquals("myName", ((StringDt) newPatient.getUndeclaredExtensionsByUrl("http://www.example.com/petname").get(0).getValue()).getValue());
|
||||
|
||||
}
|
||||
|
||||
|
||||
@AfterClass
|
||||
public static void afterClassClearContext() {
|
||||
TestUtil.clearAllStaticFieldsForUnitTest();
|
||||
|
@ -2885,7 +2839,7 @@ public class XmlParserDstu2Test {
|
|||
this.myAbatement = theAbatement;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ResourceDef(name = "Patient")
|
||||
public static class TestPatientFor327 extends Patient {
|
||||
|
||||
|
|
|
@ -25,7 +25,7 @@ import org.mockito.ArgumentCaptor;
|
|||
import org.mockito.internal.stubbing.defaultanswers.ReturnsDeepStubs;
|
||||
|
||||
import ca.uhn.fhir.context.FhirContext;
|
||||
import ca.uhn.fhir.model.api.Bundle;
|
||||
import ca.uhn.fhir.model.dstu2.resource.Bundle;
|
||||
import ca.uhn.fhir.model.dstu2.resource.Patient;
|
||||
import ca.uhn.fhir.model.valueset.BundleTypeEnum;
|
||||
import ca.uhn.fhir.rest.api.Constants;
|
||||
|
@ -62,7 +62,7 @@ public class BundleTypeDstu2Test {
|
|||
|
||||
@Test
|
||||
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);
|
||||
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");
|
||||
client.registerInterceptor(new BearerTokenAuthInterceptor("AN3uCTC5B"));
|
||||
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.FhirContext;
|
||||
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.MetaDt;
|
||||
import ca.uhn.fhir.model.dstu2.resource.*;
|
||||
|
@ -74,12 +73,12 @@ public class GenericClientDstu2Test {
|
|||
ourCtx.getRestfulClientFactory().setConnectTimeout(10000);
|
||||
ourCtx.getRestfulClientFactory().setPoolMaxPerRoute(100);
|
||||
ourCtx.getRestfulClientFactory().setPoolMaxTotal(100);
|
||||
|
||||
|
||||
ourCtx.getRestfulClientFactory().setHttpClient(myHttpClient);
|
||||
ourCtx.getRestfulClientFactory().setServerValidationMode(ServerValidationModeEnum.NEVER);
|
||||
myHttpResponse = mock(HttpResponse.class, new ReturnsDeepStubs());
|
||||
myResponseCount = 0;
|
||||
|
||||
|
||||
System.setProperty(BaseClient.HAPI_CLIENT_KEEPRESPONSES, "true");
|
||||
}
|
||||
|
||||
|
@ -108,7 +107,7 @@ public class GenericClientDstu2Test {
|
|||
//@formatter:on
|
||||
return msg;
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testAcceptHeaderFetchConformance() throws Exception {
|
||||
IParser p = ourCtx.newXmlParser();
|
||||
|
@ -261,7 +260,7 @@ public class GenericClientDstu2Test {
|
|||
int idx = 0;
|
||||
|
||||
//@formatter:off
|
||||
Conformance resp = (Conformance)client.conformance();
|
||||
Conformance resp = (Conformance)client.fetchConformance().ofType(Conformance.class).execute();
|
||||
|
||||
//@formatter:on
|
||||
assertEquals("http://example.com/fhir/metadata", capt.getAllValues().get(idx).getURI().toASCIIString());
|
||||
|
@ -381,7 +380,7 @@ public class GenericClientDstu2Test {
|
|||
Patient p = new Patient();
|
||||
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(EncodingEnum.XML.getResourceContentType() + Constants.HEADER_SUFFIX_CT_UTF_8, capt.getAllValues().get(idx).getFirstHeader(Constants.HEADER_CONTENT_TYPE).getValue());
|
||||
|
@ -468,7 +467,7 @@ public class GenericClientDstu2Test {
|
|||
|
||||
Patient pat = new Patient();
|
||||
pat.setId("Patient/123");
|
||||
|
||||
|
||||
client.delete().resource(pat).execute();
|
||||
assertEquals("DELETE", capt.getAllValues().get(idx).getMethod());
|
||||
assertEquals("http://example.com/fhir/Patient/123", capt.getAllValues().get(idx).getURI().toString());
|
||||
|
@ -513,74 +512,45 @@ public class GenericClientDstu2Test {
|
|||
public void testDeleteInvalidRequest() throws Exception {
|
||||
Patient pat = new Patient();
|
||||
pat.setId("123");
|
||||
|
||||
|
||||
IGenericClient client = ourCtx.newRestfulGenericClient("http://example.com/fhir");
|
||||
|
||||
try {
|
||||
client.delete().resource(pat).execute();
|
||||
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());
|
||||
}
|
||||
|
||||
|
||||
try {
|
||||
client.delete().resourceById(new IdDt("123")).execute();
|
||||
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());
|
||||
}
|
||||
|
||||
try {
|
||||
client.delete().resourceById("", "123").execute();
|
||||
fail();
|
||||
} catch (IllegalArgumentException e){
|
||||
} catch (IllegalArgumentException e) {
|
||||
assertEquals("theResourceType can not be blank/null", e.getMessage());
|
||||
}
|
||||
|
||||
try {
|
||||
client.delete().resourceById("Patient", "").execute();
|
||||
fail();
|
||||
} catch (IllegalArgumentException e){
|
||||
} catch (IllegalArgumentException e) {
|
||||
assertEquals("theLogicalId can not be blank/null", e.getMessage());
|
||||
}
|
||||
|
||||
try {
|
||||
client.delete().resourceConditionalByType("InvalidType");
|
||||
fail();
|
||||
} catch (DataFormatException e){
|
||||
} catch (DataFormatException e) {
|
||||
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
|
||||
*/
|
||||
|
@ -731,7 +701,8 @@ public class GenericClientDstu2Test {
|
|||
.since(new InstantDt("2001-01-02T11:22:33Z"))
|
||||
.execute();
|
||||
//@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());
|
||||
idx++;
|
||||
|
||||
|
@ -794,7 +765,8 @@ public class GenericClientDstu2Test {
|
|||
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("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++;
|
||||
|
||||
}
|
||||
|
@ -1148,7 +1120,9 @@ public class GenericClientDstu2Test {
|
|||
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("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++;
|
||||
|
||||
/*
|
||||
|
@ -1169,7 +1143,8 @@ public class GenericClientDstu2Test {
|
|||
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("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)));
|
||||
idx++;
|
||||
|
||||
|
@ -1709,7 +1684,8 @@ public class GenericClientDstu2Test {
|
|||
.execute();
|
||||
//@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());
|
||||
|
||||
}
|
||||
|
@ -1848,21 +1824,20 @@ public class GenericClientDstu2Test {
|
|||
|
||||
IGenericClient client = ourCtx.newRestfulGenericClient("http://example.com/fhir");
|
||||
|
||||
//@formatter:off
|
||||
Bundle response = client.search()
|
||||
.forResource("Patient")
|
||||
.where(Patient.NAME.matches().value("james"))
|
||||
.elementsSubset("name", "identifier")
|
||||
.usingStyle(SearchStyleEnum.POST)
|
||||
.execute();
|
||||
//@formatter:on
|
||||
.forResource("Patient")
|
||||
.where(Patient.NAME.matches().value("james"))
|
||||
.elementsSubset("name", "identifier")
|
||||
.usingStyle(SearchStyleEnum.POST)
|
||||
.returnBundle(Bundle.class)
|
||||
.execute();
|
||||
|
||||
assertEquals("http://example.com/fhir/Patient/_search?_elements=identifier%2Cname", 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")));
|
||||
// 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")));
|
||||
|
||||
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(capt.getValue().toString());
|
||||
|
@ -1888,24 +1863,23 @@ public class GenericClientDstu2Test {
|
|||
|
||||
IGenericClient client = ourCtx.newRestfulGenericClient("http://example.com/fhir");
|
||||
|
||||
//@formatter:off
|
||||
Bundle response = client.search()
|
||||
.forResource("Patient")
|
||||
.where(Patient.NAME.matches().value("james"))
|
||||
.elementsSubset("name", "identifier")
|
||||
.usingStyle(SearchStyleEnum.POST)
|
||||
.encodedJson()
|
||||
.execute();
|
||||
//@formatter:on
|
||||
.forResource("Patient")
|
||||
.where(Patient.NAME.matches().value("james"))
|
||||
.elementsSubset("name", "identifier")
|
||||
.usingStyle(SearchStyleEnum.POST)
|
||||
.encodedJson()
|
||||
.returnBundle(Bundle.class)
|
||||
.execute();
|
||||
|
||||
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(), not(containsString("_format=json")));
|
||||
|
||||
// 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(),
|
||||
// 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(capt.getValue().toString());
|
||||
|
@ -1930,15 +1904,14 @@ public class GenericClientDstu2Test {
|
|||
|
||||
IGenericClient client = ourCtx.newRestfulGenericClient("http://example.com/fhir");
|
||||
|
||||
//@formatter:off
|
||||
Bundle response = client.search()
|
||||
.forResource("Patient")
|
||||
.where(Patient.NAME.matches().value("james"))
|
||||
.execute();
|
||||
//@formatter:on
|
||||
Bundle response = client.search()
|
||||
.forResource("Patient")
|
||||
.where(Patient.NAME.matches().value("james"))
|
||||
.returnBundle(Bundle.class)
|
||||
.execute();
|
||||
|
||||
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");
|
||||
|
||||
//@formatter:off
|
||||
Bundle response = client.search()
|
||||
.forResource("Patient")
|
||||
.where(Patient.NAME.matches().value("james"))
|
||||
.elementsSubset("name", "identifier")
|
||||
.execute();
|
||||
//@formatter:on
|
||||
Bundle response = client.search()
|
||||
.forResource("Patient")
|
||||
.where(Patient.NAME.matches().value("james"))
|
||||
.elementsSubset("name", "identifier")
|
||||
.returnBundle(Bundle.class)
|
||||
.execute();
|
||||
|
||||
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")));
|
||||
assertEquals(Patient.class, response.getEntries().get(0).getResource().getClass());
|
||||
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")));
|
||||
assertEquals(Patient.class, response.getEntry().get(0).getResource().getClass());
|
||||
|
||||
}
|
||||
|
||||
|
@ -2090,16 +2063,15 @@ public class GenericClientDstu2Test {
|
|||
|
||||
IGenericClient client = ourCtx.newRestfulGenericClient("http://example.com/fhir");
|
||||
|
||||
//@formatter:off
|
||||
Bundle response = client.search()
|
||||
.forResource("Patient")
|
||||
.where(Patient.NAME.matches().value("james"))
|
||||
.lastUpdated(new DateRangeParam("2011-01-01", "2012-01-01"))
|
||||
.execute();
|
||||
//@formatter:on
|
||||
Bundle response = client.search()
|
||||
.forResource("Patient")
|
||||
.where(Patient.NAME.matches().value("james"))
|
||||
.lastUpdated(new DateRangeParam("2011-01-01", "2012-01-01"))
|
||||
.returnBundle(Bundle.class)
|
||||
.execute();
|
||||
|
||||
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");
|
||||
|
||||
HashMap<String, List<IQueryParameterType>> params = new HashMap<String, List<IQueryParameterType>>();
|
||||
params.put("foo", Arrays.asList((IQueryParameterType)new DateParam("2001")));
|
||||
Bundle response = client.search(Patient.class, params);
|
||||
params.put("foo", Arrays.asList((IQueryParameterType) new DateParam("2001")));
|
||||
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(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");
|
||||
|
||||
//@formatter:off
|
||||
Bundle response = client.search()
|
||||
.forResource("Patient")
|
||||
.withProfile("http://foo1")
|
||||
.withProfile("http://foo2")
|
||||
.withSecurity("system1", "code1")
|
||||
.withSecurity("system2", "code2")
|
||||
.execute();
|
||||
//@formatter:on
|
||||
Bundle response = client.search()
|
||||
.forResource("Patient")
|
||||
.withProfile("http://foo1")
|
||||
.withProfile("http://foo2")
|
||||
.withSecurity("system1", "code1")
|
||||
.withSecurity("system2", "code2")
|
||||
.returnBundle(Bundle.class)
|
||||
.execute();
|
||||
|
||||
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");
|
||||
|
||||
//@formatter:off
|
||||
Bundle response = client.search()
|
||||
.forResource(Patient.class)
|
||||
.encodedJson()
|
||||
.revInclude(new Include("Provenance:target"))
|
||||
.returnBundle(Bundle.class)
|
||||
.execute();
|
||||
//@formatter:on
|
||||
|
||||
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");
|
||||
|
||||
//@formatter:off
|
||||
Bundle response = client.search()
|
||||
.forResource("Patient")
|
||||
.where(Patient.NAME.matches().value("james"))
|
||||
.summaryMode(SummaryEnum.FALSE)
|
||||
.execute();
|
||||
//@formatter:on
|
||||
Bundle response = client.search()
|
||||
.forResource("Patient")
|
||||
.where(Patient.NAME.matches().value("james"))
|
||||
.summaryMode(SummaryEnum.FALSE)
|
||||
.returnBundle(Bundle.class)
|
||||
.execute();
|
||||
|
||||
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("POST", capt.getAllValues().get(idx).getRequestLine().getMethod());
|
||||
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());
|
||||
assertEquals("FOOBAR", toOo(response.getOperationOutcome()).getIssueFirstRep().getDiagnosticsElement().getValue());
|
||||
idx++;
|
||||
|
@ -2549,7 +2525,9 @@ public class GenericClientDstu2Test {
|
|||
assertEquals("http://example.com/fhir/Patient/$validate", capt.getAllValues().get(idx).getURI().toASCIIString());
|
||||
assertEquals("POST", capt.getAllValues().get(idx).getRequestLine().getMethod());
|
||||
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());
|
||||
assertEquals("FOOBAR", toOo(response.getOperationOutcome()).getIssueFirstRep().getDiagnosticsElement().getValue());
|
||||
idx++;
|
||||
|
@ -2605,7 +2583,9 @@ public class GenericClientDstu2Test {
|
|||
|
||||
assertEquals("http://example.com/fhir/Patient/$validate", capt.getAllValues().get(idx).getURI().toASCIIString());
|
||||
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());
|
||||
assertEquals("FOOBAR", toOo(response.getOperationOutcome()).getIssueFirstRep().getDiagnosticsElement().getValue());
|
||||
idx++;
|
||||
|
@ -2648,27 +2628,27 @@ public class GenericClientDstu2Test {
|
|||
|
||||
@Override
|
||||
public void registerInterceptor(IClientInterceptor theInterceptor) {
|
||||
//nothing
|
||||
// nothing
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setEncoding(EncodingEnum theEncoding) {
|
||||
//nothing
|
||||
// nothing
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPrettyPrint(Boolean thePrettyPrint) {
|
||||
//nothing
|
||||
// nothing
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSummary(SummaryEnum theSummary) {
|
||||
//nothing
|
||||
// nothing
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unregisterInterceptor(IClientInterceptor theInterceptor) {
|
||||
//nothing
|
||||
// nothing
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -16,7 +16,6 @@ import ca.uhn.fhir.model.primitive.InstantDt;
|
|||
public class DateParamTest {
|
||||
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(DateParamTest.class);
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Test
|
||||
public void testConstructors() {
|
||||
new DateParam();
|
||||
|
@ -97,5 +96,15 @@ public class DateParamTest {
|
|||
ourLog.info("POST: " + dt.getValue());
|
||||
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 ca.uhn.fhir.context.FhirContext;
|
||||
import ca.uhn.fhir.model.api.Bundle;
|
||||
import ca.uhn.fhir.model.api.IResource;
|
||||
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.rest.annotation.*;
|
||||
import ca.uhn.fhir.rest.api.Constants;
|
||||
|
@ -183,8 +183,8 @@ public class BinaryDstu2Test {
|
|||
|
||||
ourLog.info(responseContent);
|
||||
|
||||
Bundle bundle = ourCtx.newJsonParser().parseBundle(responseContent);
|
||||
Binary bin = (Binary) bundle.getEntries().get(0).getResource();
|
||||
Bundle bundle = ourCtx.newJsonParser().parseResource(Bundle.class, responseContent);
|
||||
Binary bin = (Binary) bundle.getEntry().get(0).getResource();
|
||||
|
||||
assertEquals("text/plain", bin.getContentType());
|
||||
assertArrayEquals(new byte[] { 1, 2, 3, 4 }, bin.getContent());
|
||||
|
@ -201,8 +201,8 @@ public class BinaryDstu2Test {
|
|||
|
||||
ourLog.info(responseContent);
|
||||
|
||||
Bundle bundle = ourCtx.newXmlParser().parseBundle(responseContent);
|
||||
Binary bin = (Binary) bundle.getEntries().get(0).getResource();
|
||||
Bundle bundle = ourCtx.newXmlParser().parseResource(Bundle.class, responseContent);
|
||||
Binary bin = (Binary) bundle.getEntry().get(0).getResource();
|
||||
|
||||
assertEquals("text/plain", bin.getContentType());
|
||||
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.servlet.ServletHandler;
|
||||
import org.eclipse.jetty.servlet.ServletHolder;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.junit.*;
|
||||
|
||||
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.dstu2.resource.Bundle;
|
||||
import ca.uhn.fhir.model.dstu2.resource.Patient;
|
||||
import ca.uhn.fhir.model.valueset.BundleTypeEnum;
|
||||
import ca.uhn.fhir.narrative.DefaultThymeleafNarrativeGenerator;
|
||||
|
@ -51,9 +49,9 @@ public class BundleTypeInResponseTest {
|
|||
|
||||
ourLog.info(responseContent);
|
||||
|
||||
Bundle bundle = ourCtx.newXmlParser().parseBundle(responseContent);
|
||||
assertEquals(1, bundle.getEntries().size());
|
||||
assertEquals(BundleTypeEnum.SEARCHSET, bundle.getType().getValueAsEnum());
|
||||
Bundle bundle = ourCtx.newXmlParser().parseResource(Bundle.class, responseContent);
|
||||
assertEquals(1, bundle.getEntry().size());
|
||||
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.api.BundleInclusionRule;
|
||||
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.annotation.*;
|
||||
|
@ -61,20 +60,21 @@ public class IncludeDstu2Test {
|
|||
IOUtils.closeQuietly(status.getEntity().getContent());
|
||||
|
||||
assertEquals(200, status.getStatusLine().getStatusCode());
|
||||
Bundle bundle = ourCtx.newXmlParser().parseBundle(responseContent);
|
||||
Bundle bundle = ourCtx.newXmlParser().parseResource(Bundle.class, responseContent);
|
||||
|
||||
ourLog.info(responseContent);
|
||||
|
||||
assertEquals(3, bundle.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());
|
||||
assertEquals(3, bundle.getEntry().size());
|
||||
|
||||
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) bundle.toListOfResources().get(0);
|
||||
Patient p1 = (Patient) BundleUtil.toListOfResources(ourCtx, bundle).get(0);
|
||||
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());
|
||||
|
||||
}
|
||||
|
@ -87,22 +87,22 @@ public class IncludeDstu2Test {
|
|||
IOUtils.closeQuietly(status.getEntity().getContent());
|
||||
|
||||
assertEquals(200, status.getStatusLine().getStatusCode());
|
||||
Bundle bundle = ourCtx.newXmlParser().parseBundle(responseContent);
|
||||
Bundle bundle = ourCtx.newXmlParser().parseResource(Bundle.class, responseContent);
|
||||
|
||||
ourLog.info(responseContent);
|
||||
|
||||
assertEquals(4, bundle.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(new IdDt("Organization/o2"), bundle.toListOfResources().get(3).getId().toUnqualifiedVersionless());
|
||||
assertEquals(BundleEntrySearchModeEnum.INCLUDE, bundle.getEntries().get(2).getSearchMode().getValueAsEnum());
|
||||
assertEquals(BundleEntrySearchModeEnum.INCLUDE, bundle.getEntries().get(3).getSearchMode().getValueAsEnum());
|
||||
assertEquals(4, bundle.getEntry().size());
|
||||
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(new IdDt("Organization/o2"), BundleUtil.toListOfResources(ourCtx, bundle).get(3).getIdElement().toUnqualifiedVersionless());
|
||||
assertEquals(BundleEntrySearchModeEnum.INCLUDE, bundle.getEntry().get(2).getSearch().getModeElement().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());
|
||||
|
||||
Patient p2 = (Patient) bundle.toListOfResources().get(1);
|
||||
Patient p2 = (Patient) BundleUtil.toListOfResources(ourCtx, bundle).get(1);
|
||||
assertEquals(0, p2.getContained().getContainedResources().size());
|
||||
|
||||
}
|
||||
|
@ -115,20 +115,20 @@ public class IncludeDstu2Test {
|
|||
IOUtils.closeQuietly(status.getEntity().getContent());
|
||||
|
||||
assertEquals(200, status.getStatusLine().getStatusCode());
|
||||
Bundle bundle = ourCtx.newXmlParser().parseBundle(responseContent);
|
||||
Bundle bundle = ourCtx.newXmlParser().parseResource(Bundle.class, responseContent);
|
||||
|
||||
ourLog.info(responseContent);
|
||||
|
||||
assertEquals(3, bundle.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());
|
||||
assertEquals(3, bundle.getEntry().size());
|
||||
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) bundle.toListOfResources().get(0);
|
||||
Patient p1 = (Patient) BundleUtil.toListOfResources(ourCtx, bundle).get(0);
|
||||
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());
|
||||
|
||||
}
|
||||
|
@ -141,20 +141,20 @@ public class IncludeDstu2Test {
|
|||
IOUtils.closeQuietly(status.getEntity().getContent());
|
||||
|
||||
assertEquals(200, status.getStatusLine().getStatusCode());
|
||||
Bundle bundle = ourCtx.newJsonParser().parseBundle(responseContent);
|
||||
Bundle bundle = ourCtx.newJsonParser().parseResource(Bundle.class, responseContent);
|
||||
|
||||
ourLog.info(responseContent);
|
||||
|
||||
assertEquals(3, bundle.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());
|
||||
assertEquals(3, bundle.getEntry().size());
|
||||
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) bundle.toListOfResources().get(0);
|
||||
Patient p1 = (Patient) BundleUtil.toListOfResources(ourCtx, bundle).get(0);
|
||||
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());
|
||||
|
||||
}
|
||||
|
@ -169,8 +169,8 @@ public class IncludeDstu2Test {
|
|||
ourLog.info(responseContent);
|
||||
|
||||
assertEquals(200, status.getStatusLine().getStatusCode());
|
||||
Bundle bundle = ourCtx.newXmlParser().parseBundle(responseContent);
|
||||
assertEquals(4, bundle.size());
|
||||
Bundle bundle = ourCtx.newXmlParser().parseResource(Bundle.class, responseContent);
|
||||
assertEquals(4, bundle.getEntry().size());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -181,10 +181,10 @@ public class IncludeDstu2Test {
|
|||
IOUtils.closeQuietly(status.getEntity().getContent());
|
||||
|
||||
assertEquals(200, status.getStatusLine().getStatusCode());
|
||||
Bundle bundle = ourCtx.newXmlParser().parseBundle(responseContent);
|
||||
assertEquals(1, bundle.size());
|
||||
Bundle bundle = ourCtx.newXmlParser().parseResource(Bundle.class, responseContent);
|
||||
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("Hello", p.getId().getIdPart());
|
||||
}
|
||||
|
@ -200,10 +200,10 @@ public class IncludeDstu2Test {
|
|||
|
||||
ourLog.info(responseContent);
|
||||
|
||||
Bundle bundle = ourCtx.newJsonParser().parseBundle(responseContent);
|
||||
assertEquals(1, bundle.size());
|
||||
Bundle bundle = ourCtx.newJsonParser().parseResource(Bundle.class, responseContent);
|
||||
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("Hello", p.getId().getIdPart());
|
||||
assertEquals("foo", p.getName().get(0).getFamilyFirstRep().getValue());
|
||||
|
@ -220,10 +220,10 @@ public class IncludeDstu2Test {
|
|||
|
||||
ourLog.info(responseContent);
|
||||
|
||||
Bundle bundle = ourCtx.newXmlParser().parseBundle(responseContent);
|
||||
assertEquals(1, bundle.size());
|
||||
Bundle bundle = ourCtx.newXmlParser().parseResource(Bundle.class, responseContent);
|
||||
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("Hello", p.getId().getIdPart());
|
||||
assertEquals("foo", p.getName().get(0).getFamilyFirstRep().getValue());
|
||||
|
@ -239,10 +239,10 @@ public class IncludeDstu2Test {
|
|||
ourLog.info(responseContent);
|
||||
|
||||
assertEquals(200, status.getStatusLine().getStatusCode());
|
||||
Bundle bundle = ourCtx.newXmlParser().parseBundle(responseContent);
|
||||
assertEquals(1, bundle.size());
|
||||
Bundle bundle = ourCtx.newXmlParser().parseResource(Bundle.class, responseContent);
|
||||
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("Hello", p.getId().getIdPart());
|
||||
|
||||
|
|
|
@ -12,13 +12,7 @@ import org.junit.Test;
|
|||
|
||||
import ca.uhn.fhir.context.FhirContext;
|
||||
import ca.uhn.fhir.model.dstu2.resource.Patient;
|
||||
import ca.uhn.fhir.model.primitive.StringDt;
|
||||
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.annotation.*;
|
||||
import ca.uhn.fhir.rest.api.MethodOutcome;
|
||||
import ca.uhn.fhir.rest.param.TokenParam;
|
||||
import ca.uhn.fhir.util.TestUtil;
|
||||
|
@ -32,22 +26,6 @@ public class ServerInvalidDefinitionDstu2Test {
|
|||
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
|
||||
public void testWrongConditionalUrlType() {
|
||||
RestfulServer srv = new RestfulServer(ourCtx);
|
||||
|
@ -59,7 +37,8 @@ public class ServerInvalidDefinitionDstu2Test {
|
|||
fail();
|
||||
} catch (ServletException e) {
|
||||
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();
|
||||
} catch (ServletException e) {
|
||||
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 {
|
||||
|
||||
@Override
|
||||
|
|
|
@ -12,9 +12,7 @@ import static org.junit.Assert.fail;
|
|||
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.*;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.hamcrest.core.StringContains;
|
||||
|
@ -22,27 +20,12 @@ import org.junit.AfterClass;
|
|||
import org.junit.Test;
|
||||
|
||||
import ca.uhn.fhir.context.FhirContext;
|
||||
import ca.uhn.fhir.model.api.Bundle;
|
||||
import ca.uhn.fhir.model.api.ExtensionDt;
|
||||
import ca.uhn.fhir.model.api.ResourceMetadataKeyEnum;
|
||||
import ca.uhn.fhir.model.api.TemporalPrecisionEnum;
|
||||
import ca.uhn.fhir.model.dstu2.composite.CodeableConceptDt;
|
||||
import ca.uhn.fhir.model.dstu2.composite.ResourceReferenceDt;
|
||||
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.model.api.*;
|
||||
import ca.uhn.fhir.model.dstu2.composite.*;
|
||||
import ca.uhn.fhir.model.dstu2.resource.*;
|
||||
import ca.uhn.fhir.model.dstu2.valueset.*;
|
||||
import ca.uhn.fhir.model.primitive.*;
|
||||
import ca.uhn.fhir.parser.*;
|
||||
import ca.uhn.fhir.parser.XmlParserDstu2Test.TestPatientFor327;
|
||||
import ca.uhn.fhir.util.TestUtil;
|
||||
import ca.uhn.fhir.validation.schematron.SchematronBaseValidator;
|
||||
|
@ -102,13 +85,13 @@ public class ResourceValidatorDstu2Test {
|
|||
@Test
|
||||
public void testSchemaBundleValidator() throws IOException {
|
||||
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();
|
||||
|
||||
val.validate(b);
|
||||
|
||||
MedicationOrder p = (MedicationOrder) b.getEntries().get(0).getResource();
|
||||
MedicationOrder p = (MedicationOrder) b.getEntry().get(0).getResource();
|
||||
TimingDt timing = new TimingDt();
|
||||
timing.getRepeat().setDuration(123);
|
||||
timing.getRepeat().setDurationUnits((UnitsOfTimeEnum) null);
|
||||
|
@ -127,20 +110,26 @@ public class ResourceValidatorDstu2Test {
|
|||
@Test
|
||||
public void testSchemaBundleValidatorFails() throws IOException {
|
||||
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();
|
||||
|
||||
ValidationResult validationResult = val.validateWithResult(b);
|
||||
assertTrue(validationResult.isSuccessful());
|
||||
|
||||
MedicationOrder p = (MedicationOrder) b.getEntries().get(0).getResource();
|
||||
MedicationOrder p = (MedicationOrder) b.getEntry().get(0).getResource();
|
||||
TimingDt timing = new TimingDt();
|
||||
timing.getRepeat().setDuration(123);
|
||||
timing.getRepeat().setDurationUnits((UnitsOfTimeEnum) null);
|
||||
p.getDosageInstructionFirstRep().setTiming(timing);
|
||||
|
||||
ourLog.info(ourCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(b));
|
||||
|
||||
validationResult = val.validateWithResult(b);
|
||||
|
||||
ourLog.info(ourCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(validationResult.toOperationOutcome()));
|
||||
|
||||
assertFalse(validationResult.isSuccessful());
|
||||
|
||||
String encoded = logOperationOutcome(validationResult);
|
||||
|
@ -150,9 +139,9 @@ public class ResourceValidatorDstu2Test {
|
|||
@Test
|
||||
public void testSchemaBundleValidatorIsSuccessful() throws IOException {
|
||||
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();
|
||||
|
||||
|
|
|
@ -114,8 +114,13 @@ public class GenericClientDstu3Test {
|
|||
.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());
|
||||
String expected = "http://example.com/fhir/EpisodeOfCare?patient=123&_revinclude=Encounter%3Aepisodeofcare&_revinclude%3Arecurse=Observation%3Aencounter";
|
||||
String actual = capt.getAllValues().get(idx).getURI().toString();
|
||||
|
||||
ourLog.info("EXP: {}", expected);
|
||||
ourLog.info("ACT: {}", actual);
|
||||
|
||||
assertEquals(expected, actual);
|
||||
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
|
||||
public void testSearchWithMultipleTokens() throws Exception {
|
||||
ArgumentCaptor<HttpUriRequest> capt = prepareClientForSearchResponse();
|
||||
|
|
|
@ -67,9 +67,13 @@ public class DateRangeParamTest {
|
|||
public void testDay() throws Exception {
|
||||
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(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(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
|
||||
|
@ -77,20 +81,20 @@ public class DateRangeParamTest {
|
|||
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(parse("2011-01-01 00:00:00.0000"), create(">=2011-01-01").getLowerBoundAsInstant());
|
||||
assertEquals(null, create(">=2011-01-01").getUpperBoundAsInstant());
|
||||
assertEquals(parse("2011-01-01 00:00:00.0000"), create("ge2011-01-01").getLowerBoundAsInstant());
|
||||
assertEquals(null, create("ge2011-01-01").getUpperBoundAsInstant());
|
||||
|
||||
assertEquals(null, create("<=2011-01-01").getLowerBoundAsInstant());
|
||||
assertEquals(parseM1("2011-01-02 00:00:00.0000"), create("<=2011-01-01").getUpperBoundAsInstant());
|
||||
assertEquals(null, create("le2011-01-01").getLowerBoundAsInstant());
|
||||
assertEquals(parseM1("2011-01-02 00:00:00.0000"), create("le2011-01-01").getUpperBoundAsInstant());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMonth() throws Exception {
|
||||
assertEquals(parse("2011-01-01 00:00:00.0000"), create(">=2011-01", "<2011-02").getLowerBoundAsInstant());
|
||||
assertEquals(parseM1("2011-02-01 00:00:00.0000"), create(">=2011-01", "<2011-02").getUpperBoundAsInstant());
|
||||
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("ge2011-01", "lt2011-02").getUpperBoundAsInstant());
|
||||
|
||||
assertEquals(parse("2011-02-01 00:00:00.0000"), create(">2011-01", "<=2011-02").getLowerBoundAsInstant());
|
||||
assertEquals(parseM1("2011-03-01 00:00:00.0000"), create(">2011-01", "<=2011-02").getUpperBoundAsInstant());
|
||||
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("gt2011-01", "le2011-02").getUpperBoundAsInstant());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -159,20 +163,20 @@ public class DateRangeParamTest {
|
|||
|
||||
@Test
|
||||
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(parseM1("2011-01-01 02:00:00.0000"), create(">=2011-01-01T00:00:00", "<2011-01-01T02:00:00").getUpperBoundAsInstant());
|
||||
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("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(parseM1("2011-01-01 02:00:01.0000"), create(">2011-01-01T00:00:00", "<=2011-01-01T02:00:00").getUpperBoundAsInstant());
|
||||
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("gt2011-01-01T00:00:00", "le2011-01-01T02:00:00").getUpperBoundAsInstant());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testYear() throws Exception {
|
||||
assertEquals(parse("2011-01-01 00:00:00.0000"), create(">=2011", "<2012").getLowerBoundAsInstant());
|
||||
assertEquals(parseM1("2012-01-01 00:00:00.0000"), create(">=2011", "<2012").getUpperBoundAsInstant());
|
||||
assertEquals(parse("2011-01-01 00:00:00.0000"), create("ge2011", "lt2012").getLowerBoundAsInstant());
|
||||
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(parseM1("2014-01-01 00:00:00.0000"), create(">2011", "<=2013").getUpperBoundAsInstant());
|
||||
assertEquals(parse("2012-01-01 00:00:00.0000"), create("gt2011", "le2012").getLowerBoundAsInstant());
|
||||
assertEquals(parseM1("2014-01-01 00:00:00.0000"), create("gt2011", "le2013").getUpperBoundAsInstant());
|
||||
}
|
||||
|
||||
@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")
|
||||
public static class MyPatientWithOneDeclaredAddressExtension extends Patient {
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -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
|
||||
public IBaseResource getResourceBundle() {
|
||||
return myBundle;
|
||||
|
|
|
@ -2,7 +2,13 @@ package ca.uhn.fhir.rest.client;
|
|||
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
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.when;
|
||||
|
||||
|
@ -33,8 +39,10 @@ import com.phloc.commons.io.streams.StringInputStream;
|
|||
|
||||
import ca.uhn.fhir.context.FhirContext;
|
||||
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.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.MyCustomPatient;
|
||||
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.interceptor.CookieInterceptor;
|
||||
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.server.exceptions.NotImplementedOperationException;
|
||||
import ca.uhn.fhir.rest.server.exceptions.UnclassifiedServerFailureException;
|
||||
|
@ -99,272 +108,6 @@ public class GenericClientR4Test {
|
|||
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
|
||||
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\"}]}}]}";
|
||||
|
@ -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
|
||||
*/
|
||||
|
@ -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
|
||||
public void testPutDoesntForceAllIdsJson() throws Exception {
|
||||
IParser p = ourCtx.newJsonParser();
|
||||
|
@ -1152,33 +1128,24 @@ 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"));
|
||||
}
|
||||
});
|
||||
public void testRevIncludeRecursive() throws ClientProtocolException, IOException {
|
||||
ArgumentCaptor<HttpUriRequest> capt = prepareClientForSearchResponse();
|
||||
|
||||
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))
|
||||
.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/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++;
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -1530,14 +1497,29 @@ public class GenericClientR4Test {
|
|||
}
|
||||
|
||||
@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");
|
||||
try {
|
||||
client.search(new UriDt("?aaaa"));
|
||||
fail();
|
||||
} catch (IllegalArgumentException e) {
|
||||
assertEquals("Unable to determine the resource type from the given URI: ?aaaa", e.getMessage());
|
||||
}
|
||||
|
||||
HashMap<String, List<IQueryParameterType>> params = new HashMap<String, List<IQueryParameterType>>();
|
||||
params.put("foo", Arrays.asList((IQueryParameterType) new DateParam("2001")));
|
||||
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(Patient.class, response.getEntry().get(0).getResource().getClass());
|
||||
|
||||
}
|
||||
|
||||
@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
|
||||
*/
|
||||
|
|
|
@ -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.utilities.validation.ValidationMessage;
|
||||
|
||||
import ca.uhn.fhir.model.api.Bundle;
|
||||
import ca.uhn.fhir.validation.*;
|
||||
|
||||
/**
|
||||
|
@ -39,11 +38,6 @@ abstract class BaseValidatorBridge implements IValidatorModule {
|
|||
|
||||
protected abstract List<ValidationMessage> validate(IValidationContext<?> theCtx);
|
||||
|
||||
@Override
|
||||
public void validateBundle(IValidationContext<Bundle> theCtx) {
|
||||
doValidate(theCtx);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void validateResource(IValidationContext<IBaseResource> theCtx) {
|
||||
doValidate(theCtx);
|
||||
|
|
|
@ -5,11 +5,7 @@ import java.util.List;
|
|||
import org.hl7.fhir.instance.model.api.IBaseResource;
|
||||
import org.hl7.fhir.utilities.validation.ValidationMessage;
|
||||
|
||||
import ca.uhn.fhir.model.api.Bundle;
|
||||
import ca.uhn.fhir.validation.IValidationContext;
|
||||
import ca.uhn.fhir.validation.IValidatorModule;
|
||||
import ca.uhn.fhir.validation.ResultSeverityEnum;
|
||||
import ca.uhn.fhir.validation.SingleValidationMessage;
|
||||
import ca.uhn.fhir.validation.*;
|
||||
|
||||
/**
|
||||
* 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);
|
||||
|
||||
@Override
|
||||
public void validateBundle(IValidationContext<Bundle> theCtx) {
|
||||
doValidate(theCtx);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void validateResource(IValidationContext<IBaseResource> theCtx) {
|
||||
doValidate(theCtx);
|
||||
|
|
|
@ -265,11 +265,6 @@ public class Dstu2BundleFactory implements IVersionSpecificBundleFactory {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ca.uhn.fhir.model.api.Bundle getDstu1Bundle() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IResource getResourceBundle() {
|
||||
return myBundle;
|
||||
|
|
|
@ -1,23 +1,8 @@
|
|||
package ca.uhn.fhir.tinder;
|
||||
|
||||
import java.io.File;
|
||||
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.io.*;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.Collection;
|
||||
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 java.util.*;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
@ -28,23 +13,17 @@ import org.apache.velocity.app.VelocityEngine;
|
|||
import org.apache.velocity.tools.generic.EscapeTool;
|
||||
|
||||
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.ComposeInclude;
|
||||
import ca.uhn.fhir.model.dstu.resource.ValueSet.Define;
|
||||
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.ValueSet.CodeSystem;
|
||||
import ca.uhn.fhir.model.dstu2.resource.ValueSet.CodeSystemConcept;
|
||||
import ca.uhn.fhir.model.dstu2.resource.ValueSet.ComposeIncludeConcept;
|
||||
import ca.uhn.fhir.model.dstu2.resource.ValueSet.*;
|
||||
import ca.uhn.fhir.model.primitive.CodeDt;
|
||||
import ca.uhn.fhir.parser.IParser;
|
||||
import ca.uhn.fhir.parser.LenientErrorHandler;
|
||||
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.parser.ResourceGeneratorUsingSpreadsheet;
|
||||
import ca.uhn.fhir.tinder.parser.TargetType;
|
||||
|
||||
public class ValueSetGenerator {
|
||||
|
@ -126,18 +105,14 @@ public class ValueSetGenerator {
|
|||
throw new FileNotFoundException(name);
|
||||
}
|
||||
String vs = IOUtils.toString(is, Charset.defaultCharset());
|
||||
if ("dstu".equals(myVersion)) {
|
||||
Bundle bundle = newXmlParser.parseBundle(vs);
|
||||
for (BundleEntry next : bundle.getEntries()) {
|
||||
ValueSet nextVs = (ValueSet) next.getResource();
|
||||
parseValueSet(nextVs);
|
||||
}
|
||||
} else {
|
||||
if ("dstu2".equals(myVersion)) {
|
||||
ca.uhn.fhir.model.dstu2.resource.Bundle bundle = newXmlParser.parseResource(ca.uhn.fhir.model.dstu2.resource.Bundle.class, vs);
|
||||
for (Entry nextEntry : bundle.getEntry()) {
|
||||
ca.uhn.fhir.model.dstu2.resource.ValueSet nextVs = (ca.uhn.fhir.model.dstu2.resource.ValueSet) nextEntry.getResource();
|
||||
parseValueSet(nextVs);
|
||||
}
|
||||
} else {
|
||||
throw new IllegalStateException("Fhir version not supported");
|
||||
}
|
||||
|
||||
if (myResourceValueSetFiles != null) {
|
||||
|
|
|
@ -18,6 +18,10 @@
|
|||
being used in Bundle.entry.request.url as a part of the conditional URL
|
||||
within transactions.
|
||||
</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 version="2.6" date="TBD">
|
||||
<action type="add">
|
||||
|
|
Loading…
Reference in New Issue