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

This commit is contained in:
James Agnew 2016-02-26 18:20:32 -05:00
commit 7fdbee6f21
109 changed files with 3324 additions and 1800 deletions

View File

@ -243,6 +243,7 @@ public class FhirContext {
* for extending the core library.
*/
public RuntimeResourceDefinition getResourceDefinition(IBaseResource theResource) {
Validate.notNull(theResource, "theResource must not be null");
return getResourceDefinition(theResource.getClass());
}

View File

@ -539,9 +539,11 @@ class ModelScanner {
*/
List<Class<? extends IBaseResource>> refTypesList = new ArrayList<Class<? extends IBaseResource>>();
for (Class<? extends IElement> nextType : childAnnotation.type()) {
if (IBaseResource.class.isAssignableFrom(nextType) == false) {
throw new ConfigurationException("Field '" + next.getName() + "' in class '" + next.getDeclaringClass().getCanonicalName() + "' is of type " + BaseResourceReferenceDt.class
+ " but contains a non-resource type: " + nextType.getCanonicalName());
if (IBaseReference.class.isAssignableFrom(nextType)) {
refTypesList.add(myVersion.isRi() ? IAnyResource.class : IResource.class);
continue;
} else if (IBaseResource.class.isAssignableFrom(nextType) == false) {
throw new ConfigurationException("Field '" + next.getName() + "' in class '" + next.getDeclaringClass().getCanonicalName() + "' is of type " + BaseResourceReferenceDt.class + " but contains a non-resource type: " + nextType.getCanonicalName());
}
refTypesList.add((Class<? extends IBaseResource>) nextType);
addScanAlso(nextType);

View File

@ -49,7 +49,7 @@ import ca.uhn.fhir.util.UrlUtil;
* limit of 36 characters.
* </p>
* <p>
* regex: [a-z0-9\-\.]{1,36}
* regex: [a-z-Z0-9\-\.]{1,36}
* </p>
*/
@DatatypeDef(name = "id", profileOf=StringDt.class)

View File

@ -303,8 +303,7 @@ public abstract class BaseMethodBinding<T> implements IClientResponseHandler<T>
* The method params as generated by the specific method binding
*/
protected void populateActionRequestDetailsForInterceptor(RequestDetails theRequestDetails, ActionRequestDetails theDetails, Object[] theMethodParams) {
// TODO Auto-generated method stub
// nothing by default
}
protected BaseServerResponseException processNon2xxResponseAndReturnExceptionToThrow(int theStatusCode, String theResponseMimeType, Reader theResponseReader) {

View File

@ -35,6 +35,7 @@ import ca.uhn.fhir.rest.server.IRestfulServer;
import ca.uhn.fhir.rest.server.SimpleBundleProvider;
import ca.uhn.fhir.rest.server.exceptions.BaseServerResponseException;
import ca.uhn.fhir.rest.server.exceptions.InternalErrorException;
import ca.uhn.fhir.rest.server.exceptions.MethodNotAllowedException;
public class ConformanceMethodBinding extends BaseResourceReturningMethodBinding {
@ -83,8 +84,16 @@ public class ConformanceMethodBinding extends BaseResourceReturningMethodBinding
return true;
}
if (theRequest.getRequestType() == RequestTypeEnum.GET && "metadata".equals(theRequest.getOperation())) {
return true;
if (theRequest.getResourceName() != null) {
return false;
}
if ("metadata".equals(theRequest.getOperation())) {
if (theRequest.getRequestType() == RequestTypeEnum.GET) {
return true;
} else {
throw new MethodNotAllowedException("/metadata request must use HTTP GET", RequestTypeEnum.GET);
}
}
return false;

View File

@ -22,6 +22,7 @@ package ca.uhn.fhir.rest.method;
import static org.apache.commons.lang3.StringUtils.isBlank;
import static org.apache.commons.lang3.StringUtils.isNotBlank;
import java.io.IOException;
import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
@ -50,11 +51,13 @@ import ca.uhn.fhir.rest.annotation.OperationParam;
import ca.uhn.fhir.rest.api.RequestTypeEnum;
import ca.uhn.fhir.rest.api.RestOperationTypeEnum;
import ca.uhn.fhir.rest.client.BaseHttpClientInvocation;
import ca.uhn.fhir.rest.param.ResourceParameter;
import ca.uhn.fhir.rest.server.IBundleProvider;
import ca.uhn.fhir.rest.server.IRestfulServer;
import ca.uhn.fhir.rest.server.exceptions.BaseServerResponseException;
import ca.uhn.fhir.rest.server.exceptions.InternalErrorException;
import ca.uhn.fhir.rest.server.exceptions.MethodNotAllowedException;
import ca.uhn.fhir.rest.server.interceptor.IServerInterceptor.ActionRequestDetails;
import ca.uhn.fhir.util.FhirTerser;
public class OperationMethodBinding extends BaseResourceReturningMethodBinding {
@ -62,6 +65,7 @@ public class OperationMethodBinding extends BaseResourceReturningMethodBinding {
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(OperationMethodBinding.class);
private boolean myCanOperateAtInstanceLevel;
private boolean myCanOperateAtServerLevel;
private boolean myCanOperateAtTypeLevel;
private String myDescription;
private final boolean myIdempotent;
private final Integer myIdParamIndex;
@ -69,7 +73,6 @@ public class OperationMethodBinding extends BaseResourceReturningMethodBinding {
private final RestOperationTypeEnum myOtherOperatiopnType;
private List<ReturnType> myReturnParams;
private final ReturnTypeEnum myReturnType;
private boolean myCanOperateAtTypeLevel;
protected OperationMethodBinding(Class<?> theReturnResourceType, Class<? extends IBaseResource> theReturnTypeFromRp, Method theMethod, FhirContext theContext, Object theProvider, boolean theIdempotent, String theOperationName, Class<? extends IBaseResource> theOperationType,
OperationParam[] theReturnParams) {
@ -86,7 +89,7 @@ public class OperationMethodBinding extends BaseResourceReturningMethodBinding {
} else {
myCanOperateAtTypeLevel = true;
}
Description description = theMethod.getAnnotation(Description.class);
if (description != null) {
myDescription = description.formalDefinition();
@ -179,16 +182,16 @@ public class OperationMethodBinding extends BaseResourceReturningMethodBinding {
return myName;
}
@Override
public RestOperationTypeEnum getRestOperationType() {
return myOtherOperatiopnType;
}
@Override
protected BundleTypeEnum getResponseBundleType() {
return BundleTypeEnum.COLLECTION;
}
@Override
public RestOperationTypeEnum getRestOperationType() {
return myOtherOperatiopnType;
}
public List<ReturnType> getReturnParams() {
return Collections.unmodifiableList(myReturnParams);
}
@ -211,7 +214,13 @@ public class OperationMethodBinding extends BaseResourceReturningMethodBinding {
if (!myName.equals(theRequest.getOperation())) {
return false;
}
RequestTypeEnum requestType = theRequest.getRequestType();
if (requestType != RequestTypeEnum.GET && requestType != RequestTypeEnum.POST) {
// Operations can only be invoked with GET and POST
return false;
}
boolean requestHasId = theRequest.getId() != null;
if (requestHasId) {
if (isCanOperateAtInstanceLevel() == false) {
@ -246,9 +255,9 @@ public class OperationMethodBinding extends BaseResourceReturningMethodBinding {
}
@Override
public Object invokeServer(IRestfulServer theServer, RequestDetails theRequest, Object[] theMethodParams) throws BaseServerResponseException {
public Object invokeServer(IRestfulServer<?> theServer, RequestDetails theRequest, Object[] theMethodParams) throws BaseServerResponseException {
if (theRequest.getRequestType() == RequestTypeEnum.POST) {
// always ok
// all good
} else if (theRequest.getRequestType() == RequestTypeEnum.GET) {
if (!myIdempotent) {
String message = getContext().getLocalizer().getMessage(OperationMethodBinding.class, "methodNotSupported", theRequest.getRequestType(), RequestTypeEnum.POST.name());
@ -273,6 +282,15 @@ public class OperationMethodBinding extends BaseResourceReturningMethodBinding {
return retVal;
}
@Override
public Object invokeServer(IRestfulServer<?> theServer, RequestDetails theRequest) throws BaseServerResponseException, IOException {
if (theRequest.getRequestType() == RequestTypeEnum.POST) {
IBaseResource requestContents = ResourceParameter.loadResourceFromRequest(theRequest, this, null);
theRequest.getUserData().put(OperationParameter.REQUEST_CONTENTS_USERDATA_KEY, requestContents);
}
return super.invokeServer(theServer, theRequest);
}
public boolean isCanOperateAtInstanceLevel() {
return this.myCanOperateAtInstanceLevel;
}
@ -285,6 +303,12 @@ public class OperationMethodBinding extends BaseResourceReturningMethodBinding {
return myIdempotent;
}
@Override
protected void populateActionRequestDetailsForInterceptor(RequestDetails theRequestDetails, ActionRequestDetails theDetails, Object[] theMethodParams) {
super.populateActionRequestDetailsForInterceptor(theRequestDetails, theDetails, theMethodParams);
theDetails.setResource((IBaseResource) theRequestDetails.getUserData().get(OperationParameter.REQUEST_CONTENTS_USERDATA_KEY));
}
public void setDescription(String theDescription) {
myDescription = theDescription;
}

View File

@ -50,7 +50,6 @@ import ca.uhn.fhir.rest.api.RequestTypeEnum;
import ca.uhn.fhir.rest.api.ValidationModeEnum;
import ca.uhn.fhir.rest.param.CollectionBinder;
import ca.uhn.fhir.rest.param.DateRangeParam;
import ca.uhn.fhir.rest.param.ResourceParameter;
import ca.uhn.fhir.rest.server.exceptions.InternalErrorException;
import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException;
import ca.uhn.fhir.rest.server.exceptions.MethodNotAllowedException;
@ -59,6 +58,8 @@ import ca.uhn.fhir.util.ParametersUtil;
public class OperationParameter implements IParameter {
static final String REQUEST_CONTENTS_USERDATA_KEY = OperationParam.class.getName() + "_PARSED_RESOURCE";
private IConverter myConverter;
@SuppressWarnings("rawtypes")
private Class<? extends Collection> myInnerCollectionType;
@ -210,14 +211,7 @@ public class OperationParameter implements IParameter {
FhirContext ctx = theRequest.getServer().getFhirContext();
if (theRequest.getRequestType() == RequestTypeEnum.GET) {
return null;
}
// Class<? extends IBaseResource> wantedResourceType = theMethodBinding.getContext().getResourceDefinition("Parameters").getImplementingClass();
Class<IBaseResource> wantedResourceType = null;
IBaseResource requestContents = ResourceParameter.loadResourceFromRequest(theRequest, theMethodBinding, wantedResourceType);
IBaseResource requestContents = (IBaseResource) theRequest.getUserData().get(REQUEST_CONTENTS_USERDATA_KEY);
RuntimeResourceDefinition def = ctx.getResourceDefinition(requestContents);
if (def.getName().equals("Parameters")) {

View File

@ -37,24 +37,27 @@ import ca.uhn.fhir.rest.api.RequestTypeEnum;
import ca.uhn.fhir.rest.api.RestOperationTypeEnum;
import ca.uhn.fhir.rest.server.IRestfulResponse;
import ca.uhn.fhir.rest.server.IRestfulServerDefaults;
import ca.uhn.fhir.rest.server.interceptor.IServerInterceptor;
public abstract class RequestDetails {
private byte[] myRequestContents;
private String myCompartmentName;
private String myCompleteUrl;
private String myFhirServerBase;
private IIdType myId;
private String myOperation;
private Map<String, String[]> myParameters;
private byte[] myRequestContents;
private String myRequestPath;
private RequestTypeEnum myRequestType;
private String myResourceName;
private boolean myRespondGzip;
private IRestfulResponse myResponse;
private RestOperationTypeEnum myRestOperationType;
private String mySecondaryOperation;
private Map<String, List<String>> myUnqualifiedToQualifiedNames;
private IRestfulResponse myResponse;
private Map<Object, Object> myUserData;
protected abstract byte[] getByteStreamRequestContents();
public String getCompartmentName() {
return myCompartmentName;
@ -73,10 +76,28 @@ public abstract class RequestDetails {
return myFhirServerBase;
}
public abstract String getHeader(String name);
public abstract List<String> getHeaders(String name);
public IIdType getId() {
return myId;
}
/**
* Retrieves the body of the request as binary data. Either this method or {@link #getReader} may be called to read
* the body, not both.
*
* @return a {@link InputStream} object containing the body of the request
*
* @exception IllegalStateException
* if the {@link #getReader} method has already been called for this request
*
* @exception IOException
* if an input or output exception occurred
*/
public abstract InputStream getInputStream() throws IOException;
public String getOperation() {
return myOperation;
}
@ -85,6 +106,26 @@ public abstract class RequestDetails {
return myParameters;
}
/**
* Retrieves the body of the request as character data using a <code>BufferedReader</code>. The reader translates the
* character data according to the character encoding used on the body. Either this method or {@link #getInputStream}
* may be called to read the body, not both.
*
* @return a <code>Reader</code> containing the body of the request
*
* @exception UnsupportedEncodingException
* if the character set encoding used is not supported and the text cannot be decoded
*
* @exception IllegalStateException
* if {@link #getInputStream} method has been called on this request
*
* @exception IOException
* if an input or output exception occurred
*
* @see javax.servlet.http.HttpServletRequest#getInputStream
*/
public abstract Reader getReader() throws IOException;
/**
* The part of the request URL that comes after the server base.
* <p>
@ -103,6 +144,10 @@ public abstract class RequestDetails {
return myResourceName;
}
public IRestfulResponse getResponse() {
return myResponse;
}
public RestOperationTypeEnum getRestOperationType() {
return myRestOperationType;
}
@ -113,14 +158,45 @@ public abstract class RequestDetails {
public abstract IRestfulServerDefaults getServer();
/**
* Returns the server base URL (with no trailing '/') for a given request
*/
public abstract String getServerBaseForRequest();
public Map<String, List<String>> getUnqualifiedToQualifiedNames() {
return myUnqualifiedToQualifiedNames;
}
/**
* Returns a map which can be used to hold any user specific data to pass it from one
* part of the request handling chain to another. Data in this map can use any key, although
* user code should try to use keys which are specific enough to avoid conflicts.
* <p>
* A new map is created for each individual request that is handled by the server,
* so this map can be used (for example) to pass authorization details from an interceptor
* to the resource providers, or from an interceptor's {@link IServerInterceptor#incomingRequestPreHandled(RestOperationTypeEnum, ca.uhn.fhir.rest.server.interceptor.IServerInterceptor.ActionRequestDetails)}
* method to the {@link IServerInterceptor#outgoingResponse(RequestDetails, org.hl7.fhir.instance.model.api.IBaseResource, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)}
* method.
* </p>
*/
public Map<Object, Object> getUserData() {
if (myUserData == null) {
myUserData = new HashMap<Object, Object>();
}
return myUserData;
}
public boolean isRespondGzip() {
return myRespondGzip;
}
public final byte[] loadRequestContents() {
if (myRequestContents == null) {
myRequestContents = getByteStreamRequestContents();
}
return myRequestContents;
}
public void setCompartmentName(String theCompartmentName) {
myCompartmentName = theCompartmentName;
}
@ -186,6 +262,10 @@ public abstract class RequestDetails {
myRespondGzip = theRespondGzip;
}
public void setResponse(IRestfulResponse theResponse) {
this.myResponse = theResponse;
}
public void setRestOperationType(RestOperationTypeEnum theRestOperationType) {
myRestOperationType = theRestOperationType;
}
@ -194,64 +274,4 @@ public abstract class RequestDetails {
mySecondaryOperation = theSecondaryOperation;
}
public IRestfulResponse getResponse() {
return myResponse;
}
public void setResponse(IRestfulResponse theResponse) {
this.myResponse = theResponse;
}
public abstract String getHeader(String name);
public final byte[] loadRequestContents() {
if (myRequestContents == null) {
myRequestContents = getByteStreamRequestContents();
}
return myRequestContents;
}
protected abstract byte[] getByteStreamRequestContents();
public abstract List<String> getHeaders(String name);
/**
* Retrieves the body of the request as character data using a <code>BufferedReader</code>. The reader translates the
* character data according to the character encoding used on the body. Either this method or {@link #getInputStream}
* may be called to read the body, not both.
*
* @return a <code>Reader</code> containing the body of the request
*
* @exception UnsupportedEncodingException
* if the character set encoding used is not supported and the text cannot be decoded
*
* @exception IllegalStateException
* if {@link #getInputStream} method has been called on this request
*
* @exception IOException
* if an input or output exception occurred
*
* @see javax.servlet.http.HttpServletRequest#getInputStream
*/
public abstract Reader getReader() throws IOException;
/**
* Retrieves the body of the request as binary data. Either this method or {@link #getReader} may be called to read
* the body, not both.
*
* @return a {@link InputStream} object containing the body of the request
*
* @exception IllegalStateException
* if the {@link #getReader} method has already been called for this request
*
* @exception IOException
* if an input or output exception occurred
*/
public abstract InputStream getInputStream() throws IOException;
/**
* Returns the server base URL (with no trailing '/') for a given request
*/
public abstract String getServerBaseForRequest();
}

View File

@ -34,6 +34,8 @@ import ca.uhn.fhir.rest.client.BaseHttpClientInvocation;
import ca.uhn.fhir.rest.param.ResourceParameter;
import ca.uhn.fhir.rest.server.Constants;
import ca.uhn.fhir.rest.server.EncodingEnum;
import ca.uhn.fhir.rest.server.IRestfulServer;
import ca.uhn.fhir.rest.server.exceptions.BaseServerResponseException;
import ca.uhn.fhir.util.ParametersUtil;
public class ValidateMethodBindingDstu2 extends OperationMethodBinding {

View File

@ -223,7 +223,7 @@ public class RestfulServer extends HttpServlet implements IRestfulServer<Servlet
ResourceBinding resourceBinding = null;
BaseMethodBinding<?> resourceMethod = null;
String resourceName = requestDetails.getResourceName();
if (Constants.URL_TOKEN_METADATA.equals(resourceName) || requestType == RequestTypeEnum.OPTIONS) {
if (myServerConformanceMethod.incomingServerRequestMatchesMethod(requestDetails)) {
resourceMethod = myServerConformanceMethod;
} else if (resourceName == null) {
resourceBinding = myServerBinding;
@ -620,10 +620,12 @@ public class RestfulServer extends HttpServlet implements IRestfulServer<Servlet
}
/*
* Actualy invoke the server method. This call is to a HAPI method binding, which is an object that wraps a specific implementing (user-supplied) method, but handles its input and provides
* its output back to the client.
* Actualy invoke the server method. This call is to a HAPI method binding, which
* is an object that wraps a specific implementing (user-supplied) method, but
* handles its input and provides its output back to the client.
*
* This is basically the end of processing for a successful request, since the method binding replies to the client and closes the response.
* This is basically the end of processing for a successful request, since the
* method binding replies to the client and closes the response.
*/
resourceMethod.invokeServer(this, requestDetails);
@ -1389,7 +1391,7 @@ public class RestfulServer extends HttpServlet implements IRestfulServer<Servlet
}
private static boolean partIsOperation(String nextString) {
return nextString.length() > 0 && (nextString.charAt(0) == '_' || nextString.charAt(0) == '$');
return nextString.length() > 0 && (nextString.charAt(0) == '_' || nextString.charAt(0) == '$' || nextString.equals(Constants.URL_TOKEN_METADATA));
}
}

View File

@ -21,6 +21,7 @@ package ca.uhn.fhir.rest.server.interceptor;
*/
import java.io.IOException;
import java.util.Map;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
@ -114,7 +115,16 @@ public interface IServerInterceptor {
boolean incomingRequestPostProcessed(RequestDetails theRequestDetails, HttpServletRequest theRequest, HttpServletResponse theResponse) throws AuthenticationException;
/**
* Invoked before an incoming request is processed
* Invoked before an incoming request is processed. Note that this method is called
* after the server has begin preparing the response to the incoming client request.
* As such, it is not able to supply a response to the incoming request in the way that
* {@link #incomingRequestPreHandled(RestOperationTypeEnum, ActionRequestDetails)} and
* {@link #incomingRequestPostProcessed(RequestDetails, HttpServletRequest, HttpServletResponse)}
* are.
* <p>
* This method may however throw a subclass of {@link BaseServerResponseException}, and processing
* will be aborted with an appropriate error returned to the client.
* </p>
*
* @param theServletRequest
* The incoming servlet request as provided by the servlet container
@ -151,15 +161,9 @@ public interface IServerInterceptor {
* response back to the client
*
* @param theRequestDetails
* A bean containing details about the request that is about to be processed, including
* @param theResponseObject
* The actual object which is being streamed to the client as a response
* @param theServletRequest
* The incoming request
* @param theServletResponse
* The response. Note that interceptors may choose to provide a response (i.e. by calling
* {@link HttpServletResponse#getWriter()}) but in that case it is important to return <code>false</code>
* to indicate that the server itself should not also provide a response.
* A bean containing details about the request that is about to be processed, including details such as the
* resource type and logical ID (if any) and other FHIR-specific aspects of the request which have been
* pulled out of the {@link HttpServletRequest servlet request}.
* @return Return <code>true</code> if processing should continue normally. This is generally the right thing to do.
* If your interceptor is providing a response rather than letting HAPI handle the response normally, you
* must return <code>false</code>. In this case, no further processing will occur and no further interceptors
@ -168,7 +172,7 @@ public interface IServerInterceptor {
* This exception may be thrown to indicate that the interceptor has detected an unauthorized access
* attempt. If thrown, processing will stop and an HTTP 401 will be returned to the client.
*/
boolean outgoingResponse(RequestDetails theRequestDetails, Bundle theResponseObject, HttpServletRequest theServletRequest, HttpServletResponse theServletResponse) throws AuthenticationException;
boolean outgoingResponse(RequestDetails theRequestDetails);
/**
* This method is called after the server implementation method has been called, but before any attempt to stream the
@ -194,6 +198,30 @@ public interface IServerInterceptor {
*/
boolean outgoingResponse(RequestDetails theRequest, Bundle bundle);
/**
* This method is called after the server implementation method has been called, but before any attempt to stream the
* response back to the client
*
* @param theRequestDetails
* A bean containing details about the request that is about to be processed, including
* @param theResponseObject
* The actual object which is being streamed to the client as a response
* @param theServletRequest
* The incoming request
* @param theServletResponse
* The response. Note that interceptors may choose to provide a response (i.e. by calling
* {@link HttpServletResponse#getWriter()}) but in that case it is important to return <code>false</code>
* to indicate that the server itself should not also provide a response.
* @return Return <code>true</code> if processing should continue normally. This is generally the right thing to do.
* If your interceptor is providing a response rather than letting HAPI handle the response normally, you
* must return <code>false</code>. In this case, no further processing will occur and no further interceptors
* will be called.
* @throws AuthenticationException
* This exception may be thrown to indicate that the interceptor has detected an unauthorized access
* attempt. If thrown, processing will stop and an HTTP 401 will be returned to the client.
*/
boolean outgoingResponse(RequestDetails theRequestDetails, Bundle theResponseObject, HttpServletRequest theServletRequest, HttpServletResponse theServletResponse) throws AuthenticationException;
/**
* This method is called after the server implementation method has been called, but before any attempt to stream the
* response back to the client
@ -218,50 +246,6 @@ public interface IServerInterceptor {
*/
boolean outgoingResponse(RequestDetails theRequestDetails, HttpServletRequest theServletRequest, HttpServletResponse theServletResponse) throws AuthenticationException;
/**
* This method is called after the server implementation method has been called, but before any attempt to stream the
* response back to the client
*
* @param theRequestDetails
* A bean containing details about the request that is about to be processed, including details such as the
* resource type and logical ID (if any) and other FHIR-specific aspects of the request which have been
* pulled out of the {@link HttpServletRequest servlet request}.
* @return Return <code>true</code> if processing should continue normally. This is generally the right thing to do.
* If your interceptor is providing a response rather than letting HAPI handle the response normally, you
* must return <code>false</code>. In this case, no further processing will occur and no further interceptors
* will be called.
* @throws AuthenticationException
* This exception may be thrown to indicate that the interceptor has detected an unauthorized access
* attempt. If thrown, processing will stop and an HTTP 401 will be returned to the client.
*/
boolean outgoingResponse(RequestDetails theRequestDetails);
/**
* This method is called after the server implementation method has been called, but before any attempt to stream the
* response back to the client
*
* @param theRequestDetails
* A bean containing details about the request that is about to be processed, including details such as the
* resource type and logical ID (if any) and other FHIR-specific aspects of the request which have been
* pulled out of the {@link HttpServletRequest servlet request}.
* @param theResponseObject
* The actual object which is being streamed to the client as a response
* @param theServletRequest
* The incoming request
* @param theServletResponse
* The response. Note that interceptors may choose to provide a response (i.e. by calling
* {@link HttpServletResponse#getWriter()}) but in that case it is important to return <code>false</code>
* to indicate that the server itself should not also provide a response.
* @return Return <code>true</code> if processing should continue normally. This is generally the right thing to do.
* If your interceptor is providing a response rather than letting HAPI handle the response normally, you
* must return <code>false</code>. In this case, no further processing will occur and no further interceptors
* will be called.
* @throws AuthenticationException
* This exception may be thrown to indicate that the interceptor has detected an unauthorized access
* attempt. If thrown, processing will stop and an HTTP 401 will be returned to the client.
*/
boolean outgoingResponse(RequestDetails theRequestDetails, IBaseResource theResponseObject, HttpServletRequest theServletRequest, HttpServletResponse theServletResponse) throws AuthenticationException;
/**
* This method is called after the server implementation method has been called, but before any attempt to stream the
* response back to the client
@ -306,7 +290,7 @@ public interface IServerInterceptor {
* This exception may be thrown to indicate that the interceptor has detected an unauthorized access
* attempt. If thrown, processing will stop and an HTTP 401 will be returned to the client.
*/
boolean outgoingResponse(RequestDetails theRequestDetails, TagList theResponseObject, HttpServletRequest theServletRequest, HttpServletResponse theServletResponse) throws AuthenticationException;
boolean outgoingResponse(RequestDetails theRequestDetails, IBaseResource theResponseObject, HttpServletRequest theServletRequest, HttpServletResponse theServletResponse) throws AuthenticationException;
/**
* This method is called after the server implementation method has been called, but before any attempt to stream the
@ -328,6 +312,32 @@ public interface IServerInterceptor {
*/
boolean outgoingResponse(RequestDetails theRequestDetails, TagList theResponseObject);
/**
* This method is called after the server implementation method has been called, but before any attempt to stream the
* response back to the client
*
* @param theRequestDetails
* A bean containing details about the request that is about to be processed, including details such as the
* resource type and logical ID (if any) and other FHIR-specific aspects of the request which have been
* pulled out of the {@link HttpServletRequest servlet request}.
* @param theResponseObject
* The actual object which is being streamed to the client as a response
* @param theServletRequest
* The incoming request
* @param theServletResponse
* The response. Note that interceptors may choose to provide a response (i.e. by calling
* {@link HttpServletResponse#getWriter()}) but in that case it is important to return <code>false</code>
* to indicate that the server itself should not also provide a response.
* @return Return <code>true</code> if processing should continue normally. This is generally the right thing to do.
* If your interceptor is providing a response rather than letting HAPI handle the response normally, you
* must return <code>false</code>. In this case, no further processing will occur and no further interceptors
* will be called.
* @throws AuthenticationException
* This exception may be thrown to indicate that the interceptor has detected an unauthorized access
* attempt. If thrown, processing will stop and an HTTP 401 will be returned to the client.
*/
boolean outgoingResponse(RequestDetails theRequestDetails, TagList theResponseObject, HttpServletRequest theServletRequest, HttpServletResponse theServletResponse) throws AuthenticationException;
/**
* This method is called upon any exception being thrown within the server's request processing code. This includes
* any exceptions thrown within resource provider methods (e.g. {@link Search} and {@link Read} methods) as well as
@ -353,33 +363,35 @@ public interface IServerInterceptor {
BaseServerResponseException preProcessOutgoingException(RequestDetails theRequestDetails, Throwable theException, HttpServletRequest theServletRequest) throws ServletException;
public static class ActionRequestDetails {
private final FhirContext myContext;
private final IIdType myId;
private boolean myLocked = false;
private RequestDetails myRequestDetails;
private IBaseResource myResource;
private final String myResourceType;
private final FhirContext myContext;
public ActionRequestDetails(IIdType theId, String theResourceType, FhirContext theContext) {
public ActionRequestDetails(IIdType theId, String theResourceType, FhirContext theContext, RequestDetails theRequestDetails) {
myId = theId;
myResourceType = theResourceType;
myContext = theContext;
myRequestDetails = theRequestDetails;
}
public ActionRequestDetails(IIdType theId, String theResourceType, IBaseResource theResource, FhirContext theContext, RequestDetails theRequestDetails) {
this(theId, theResourceType, theContext, theRequestDetails);
myResource = theResource;
}
public ActionRequestDetails(RequestDetails theRequestDetails) {
myId = theRequestDetails.getId();
myResourceType = theRequestDetails.getResourceName();
myContext = theRequestDetails.getServer().getFhirContext();
myRequestDetails = theRequestDetails;
}
public FhirContext getContext() {
return myContext;
}
public ActionRequestDetails(IIdType theId, String theResourceType, IBaseResource theResource, FhirContext theContext) {
this(theId, theResourceType, theContext);
myResource = theResource;
}
/**
* Returns the ID of the incoming request (typically this is from the request URL)
*/
@ -409,25 +421,19 @@ public interface IServerInterceptor {
}
/**
* Prevent any further changes to this object
* Returns the same map which was
*/
public void lock() {
myLocked = true;
public Map<Object, Object> getUserData() {
return myRequestDetails.getUserData();
}
/**
* This method should not be called by client code
*/
public void setResource(IBaseResource theObject) {
validateNotLocked();
myResource = theObject;
}
private void validateNotLocked() {
if (myLocked) {
throw new IllegalStateException("Values on this object may not be changed");
}
}
}
}

View File

@ -0,0 +1,21 @@
package ca.uhn.fhir.util;
import static org.apache.commons.lang3.StringUtils.isBlank;
import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException;
public class ValidateUtil {
public static void isNotNullOrThrowInvalidRequest(boolean theSuccess, String theMessage) {
if (theSuccess == false) {
throw new InvalidRequestException(theMessage);
}
}
public static void isNotBlankOrThrowInvalidRequest(String theString, String theMessage) {
if (isBlank(theString)) {
throw new InvalidRequestException(theMessage);
}
}
}

View File

@ -68,4 +68,6 @@ ca.uhn.fhir.jpa.dao.BaseHapiFhirResourceDao.successfulCreate=Successfully create
ca.uhn.fhir.jpa.dao.BaseHapiFhirResourceDao.successfulUpdate=Successfully updated resource "{0}" in {1}ms
ca.uhn.fhir.jpa.dao.SearchBuilder.invalidQuantityPrefix=Unable to handle quantity prefix "{0}" for value: {1}
ca.uhn.fhir.jpa.dao.SearchBuilder.invalidNumberPrefix=Unable to handle number prefix "{0}" for value: {1}
ca.uhn.fhir.jpa.dao.SearchBuilder.invalidNumberPrefix=Unable to handle number prefix "{0}" for value: {1}
ca.uhn.fhir.jpa.term.TerminologySvcImpl.cannotCreateDuplicateCodeSystemUri=Can not create multiple code systems with URI "{0}", already have one with resource ID: {1}

View File

@ -0,0 +1,50 @@
package ca.uhn.fhir.util;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
import org.junit.Test;
import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException;
public class ValidateUtilTest {
@Test
public void testValidate() {
ValidateUtil.isNotNullOrThrowInvalidRequest(true, "");
try {
ValidateUtil.isNotNullOrThrowInvalidRequest(false, "The message");
fail();
} catch (InvalidRequestException e) {
assertEquals("The message", e.getMessage());
}
}
@Test
public void testIsNotBlank() {
ValidateUtil.isNotBlankOrThrowInvalidRequest("aa", "");
try {
ValidateUtil.isNotBlankOrThrowInvalidRequest("", "The message");
fail();
} catch (InvalidRequestException e) {
assertEquals("The message", e.getMessage());
}
try {
ValidateUtil.isNotBlankOrThrowInvalidRequest(null, "The message");
fail();
} catch (InvalidRequestException e) {
assertEquals("The message", e.getMessage());
}
try {
ValidateUtil.isNotBlankOrThrowInvalidRequest(" ", "The message");
fail();
} catch (InvalidRequestException e) {
assertEquals("The message", e.getMessage());
}
}
}

View File

@ -22,6 +22,7 @@ package ca.uhn.fhir.jpa.config;
import javax.annotation.Resource;
import org.springframework.beans.factory.annotation.Autowire;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
@ -37,6 +38,8 @@ import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
import org.springframework.scheduling.config.ScheduledTaskRegistrar;
import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.jpa.term.ITerminologySvc;
import ca.uhn.fhir.jpa.term.TerminologySvcImpl;
@Configuration
@EnableScheduling
@ -95,6 +98,11 @@ public class BaseConfig implements SchedulingConfigurer {
return ourFhirContextDstu3;
}
@Bean(autowire=Autowire.BY_TYPE)
public ITerminologySvc terminologyService() {
return new TerminologySvcImpl();
}
@Bean
public TaskScheduler taskScheduler() {
ThreadPoolTaskScheduler retVal = new ThreadPoolTaskScheduler();

View File

@ -124,6 +124,7 @@ import ca.uhn.fhir.parser.IParser;
import ca.uhn.fhir.rest.api.RestOperationTypeEnum;
import ca.uhn.fhir.rest.method.MethodUtil;
import ca.uhn.fhir.rest.method.QualifiedParamList;
import ca.uhn.fhir.rest.method.RequestDetails;
import ca.uhn.fhir.rest.method.RestSearchParameterTypeEnum;
import ca.uhn.fhir.rest.param.DateRangeParam;
import ca.uhn.fhir.rest.param.StringAndListParam;
@ -929,9 +930,11 @@ public abstract class BaseHapiFhirDao<T extends IBaseResource> implements IDao {
* first time.
*
* @param theEntity
* The resource
* @param theResource
* The resource being persisted
* The entity being updated (Do not modify the entity! Undefined behaviour will occur!)
* @param theTag
* The tag
* @return Returns <code>true</code> if the tag should be removed
* @see <a href="http://hl7.org/fhir/2015Sep/resource.html#1.11.3.7">Updates to Tags, Profiles, and Security Labels</a> for a description of the logic that the default behaviour folows.
*/
protected void postPersist(ResourceTable theEntity, T theResource) {
// nothing
@ -1259,15 +1262,19 @@ public abstract class BaseHapiFhirDao<T extends IBaseResource> implements IDao {
}
}
protected ResourceTable updateEntity(final IResource theResource, ResourceTable entity, boolean theUpdateHistory, Date theDeletedTimestampOrNull, Date theUpdateTime, RequestDetails theRequestDetails) {
return updateEntity(theResource, entity, theUpdateHistory, theDeletedTimestampOrNull, true, true, theUpdateTime, theRequestDetails);
}
@SuppressWarnings("unchecked")
protected ResourceTable updateEntity(final IBaseResource theResource, ResourceTable theEntity, boolean theUpdateHistory, Date theDeletedTimestampOrNull, boolean thePerformIndexing, boolean theUpdateVersion, Date theUpdateTime) {
protected ResourceTable updateEntity(final IBaseResource theResource, ResourceTable theEntity, boolean theUpdateHistory, Date theDeletedTimestampOrNull, boolean thePerformIndexing, boolean theUpdateVersion, Date theUpdateTime, RequestDetails theRequestDetails) {
/*
* This should be the very first thing..
*/
if (theResource != null) {
if (thePerformIndexing) {
validateResourceForStorage((T) theResource, theEntity);
validateResourceForStorage((T) theResource, theEntity, theRequestDetails);
}
String resourceType = myContext.getResourceDefinition(theResource).getName();
if (isNotBlank(theEntity.getResourceType()) && !theEntity.getResourceType().equals(resourceType)) {
@ -1584,8 +1591,9 @@ public abstract class BaseHapiFhirDao<T extends IBaseResource> implements IDao {
* The resource that is about to be persisted
* @param theEntityToSave
* TODO
* @param theRequestDetails TODO
*/
protected void validateResourceForStorage(T theResource, ResourceTable theEntityToSave) {
protected void validateResourceForStorage(T theResource, ResourceTable theEntityToSave, RequestDetails theRequestDetails) {
Object tag = null;
if (theResource instanceof IResource) {
IResource res = (IResource) theResource;

View File

@ -75,6 +75,7 @@ import ca.uhn.fhir.model.api.TagList;
import ca.uhn.fhir.model.primitive.IdDt;
import ca.uhn.fhir.model.primitive.InstantDt;
import ca.uhn.fhir.rest.api.RestOperationTypeEnum;
import ca.uhn.fhir.rest.method.RequestDetails;
import ca.uhn.fhir.rest.method.RestSearchParameterTypeEnum;
import ca.uhn.fhir.rest.param.DateRangeParam;
import ca.uhn.fhir.rest.server.IBundleProvider;
@ -142,17 +143,17 @@ public abstract class BaseHapiFhirResourceDao<T extends IBaseResource> extends B
}
@Override
public DaoMethodOutcome create(final T theResource) {
return create(theResource, null, true);
public DaoMethodOutcome create(final T theResource, RequestDetails theRequestDetails) {
return create(theResource, null, true, theRequestDetails);
}
@Override
public DaoMethodOutcome create(final T theResource, String theIfNoneExist) {
return create(theResource, theIfNoneExist, true);
public DaoMethodOutcome create(final T theResource, String theIfNoneExist, RequestDetails theRequestDetails) {
return create(theResource, theIfNoneExist, true, theRequestDetails);
}
@Override
public DaoMethodOutcome create(T theResource, String theIfNoneExist, boolean thePerformIndexing) {
public DaoMethodOutcome create(T theResource, String theIfNoneExist, boolean thePerformIndexing, RequestDetails theRequestDetails) {
if (isNotBlank(theResource.getIdElement().getIdPart())) {
if (getContext().getVersion().getVersion().equals(FhirVersionEnum.DSTU1)) {
if (theResource.getIdElement().isIdPartValidLong()) {
@ -165,7 +166,7 @@ public abstract class BaseHapiFhirResourceDao<T extends IBaseResource> extends B
}
}
return doCreate(theResource, theIfNoneExist, thePerformIndexing, new Date());
return doCreate(theResource, theIfNoneExist, thePerformIndexing, new Date(), theRequestDetails);
}
public IBaseOperationOutcome createErrorOperationOutcome(String theMessage, String theCode) {
@ -179,11 +180,11 @@ public abstract class BaseHapiFhirResourceDao<T extends IBaseResource> extends B
protected abstract IBaseOperationOutcome createOperationOutcome(String theSeverity, String theMessage, String theCode);
@Override
public DaoMethodOutcome delete(IIdType theId) {
public DaoMethodOutcome delete(IIdType theId, RequestDetails theRequestDetails) {
List<DeleteConflict> deleteConflicts = new ArrayList<DeleteConflict>();
StopWatch w = new StopWatch();
ResourceTable savedEntity = delete(theId, deleteConflicts);
ResourceTable savedEntity = delete(theId, deleteConflicts, theRequestDetails);
validateDeleteConflictsEmptyOrThrowException(deleteConflicts);
@ -192,7 +193,7 @@ public abstract class BaseHapiFhirResourceDao<T extends IBaseResource> extends B
}
@Override
public ResourceTable delete(IIdType theId, List<DeleteConflict> deleteConflicts) {
public ResourceTable delete(IIdType theId, List<DeleteConflict> deleteConflicts, RequestDetails theRequestDetails) {
if (theId == null || !theId.hasIdPart()) {
throw new InvalidRequestException("Can not perform delete, no ID provided");
}
@ -204,11 +205,11 @@ public abstract class BaseHapiFhirResourceDao<T extends IBaseResource> extends B
validateOkToDelete(deleteConflicts, entity);
// Notify interceptors
ActionRequestDetails requestDetails = new ActionRequestDetails(theId, theId.getResourceType(), getContext());
ActionRequestDetails requestDetails = new ActionRequestDetails(theId, theId.getResourceType(), getContext(), theRequestDetails);
notifyInterceptors(RestOperationTypeEnum.DELETE, requestDetails);
Date updateTime = new Date();
ResourceTable savedEntity = updateEntity(null, entity, true, updateTime, updateTime);
ResourceTable savedEntity = updateEntity(null, entity, true, updateTime, updateTime, theRequestDetails);
// Notify JPA interceptors
for (IServerInterceptor next : getConfig().getInterceptors()) {
@ -220,11 +221,11 @@ public abstract class BaseHapiFhirResourceDao<T extends IBaseResource> extends B
}
@Override
public DaoMethodOutcome deleteByUrl(String theUrl) {
public DaoMethodOutcome deleteByUrl(String theUrl, RequestDetails theRequestDetails) {
StopWatch w = new StopWatch();
List<DeleteConflict> deleteConflicts = new ArrayList<DeleteConflict>();
List<ResourceTable> deletedResources = deleteByUrl(theUrl, deleteConflicts);
List<ResourceTable> deletedResources = deleteByUrl(theUrl, deleteConflicts, theRequestDetails);
validateDeleteConflictsEmptyOrThrowException(deleteConflicts);
@ -237,7 +238,7 @@ public abstract class BaseHapiFhirResourceDao<T extends IBaseResource> extends B
}
@Override
public List<ResourceTable> deleteByUrl(String theUrl, List<DeleteConflict> deleteConflicts) {
public List<ResourceTable> deleteByUrl(String theUrl, List<DeleteConflict> deleteConflicts, RequestDetails theRequestDetails) {
Set<Long> resource = processMatchUrl(theUrl, myResourceType);
if (resource.size() > 1) {
if (myDaoConfig.isAllowMultipleDelete() == false) {
@ -254,12 +255,12 @@ public abstract class BaseHapiFhirResourceDao<T extends IBaseResource> extends B
// Notify interceptors
IdDt idToDelete = entity.getIdDt();
ActionRequestDetails requestDetails = new ActionRequestDetails(idToDelete, idToDelete.getResourceType(), getContext());
ActionRequestDetails requestDetails = new ActionRequestDetails(idToDelete, idToDelete.getResourceType(), getContext(), theRequestDetails);
notifyInterceptors(RestOperationTypeEnum.DELETE, requestDetails);
// Perform delete
Date updateTime = new Date();
updateEntity(null, entity, true, updateTime, updateTime);
updateEntity(null, entity, true, updateTime, updateTime, theRequestDetails);
// Notify JPA interceptors
for (IServerInterceptor next : getConfig().getInterceptors()) {
@ -273,7 +274,7 @@ public abstract class BaseHapiFhirResourceDao<T extends IBaseResource> extends B
return retVal;
}
private DaoMethodOutcome doCreate(T theResource, String theIfNoneExist, boolean thePerformIndexing, Date theUpdateTime) {
private DaoMethodOutcome doCreate(T theResource, String theIfNoneExist, boolean thePerformIndexing, Date theUpdateTime, RequestDetails theRequestDetails) {
StopWatch w = new StopWatch();
preProcessResourceForStorage(theResource);
@ -311,11 +312,11 @@ public abstract class BaseHapiFhirResourceDao<T extends IBaseResource> extends B
}
// Notify interceptors
ActionRequestDetails requestDetails = new ActionRequestDetails(theResource.getIdElement(), toResourceName(theResource), theResource, getContext());
ActionRequestDetails requestDetails = new ActionRequestDetails(theResource.getIdElement(), toResourceName(theResource), theResource, getContext(), theRequestDetails);
notifyInterceptors(RestOperationTypeEnum.CREATE, requestDetails);
// Perform actual DB update
updateEntity(theResource, entity, false, null, thePerformIndexing, true, theUpdateTime);
updateEntity(theResource, entity, false, null, thePerformIndexing, true, theUpdateTime, theRequestDetails);
// Notify JPA interceptors
for (IServerInterceptor next : getConfig().getInterceptors()) {
@ -334,9 +335,9 @@ public abstract class BaseHapiFhirResourceDao<T extends IBaseResource> extends B
}
@Override
public TagList getAllResourceTags() {
public TagList getAllResourceTags(RequestDetails theRequestDetails) {
// Notify interceptors
ActionRequestDetails requestDetails = new ActionRequestDetails(null, null, getContext());
ActionRequestDetails requestDetails = new ActionRequestDetails(null, null, getContext(), theRequestDetails);
notifyInterceptors(RestOperationTypeEnum.GET_TAGS, requestDetails);
StopWatch w = new StopWatch();
@ -357,9 +358,9 @@ public abstract class BaseHapiFhirResourceDao<T extends IBaseResource> extends B
}
@Override
public TagList getTags(IIdType theResourceId) {
public TagList getTags(IIdType theResourceId, RequestDetails theRequestDetails) {
// Notify interceptors
ActionRequestDetails requestDetails = new ActionRequestDetails(theResourceId, null, getContext());
ActionRequestDetails requestDetails = new ActionRequestDetails(theResourceId, null, getContext(), theRequestDetails);
notifyInterceptors(RestOperationTypeEnum.GET_TAGS, requestDetails);
StopWatch w = new StopWatch();
@ -369,9 +370,9 @@ public abstract class BaseHapiFhirResourceDao<T extends IBaseResource> extends B
}
@Override
public IBundleProvider history(Date theSince) {
public IBundleProvider history(Date theSince, RequestDetails theRequestDetails) {
// Notify interceptors
ActionRequestDetails requestDetails = new ActionRequestDetails(null, null, getContext());
ActionRequestDetails requestDetails = new ActionRequestDetails(null, null, getContext(), theRequestDetails);
notifyInterceptors(RestOperationTypeEnum.HISTORY_SYSTEM, requestDetails);
StopWatch w = new StopWatch();
@ -381,9 +382,9 @@ public abstract class BaseHapiFhirResourceDao<T extends IBaseResource> extends B
}
@Override
public IBundleProvider history(final IIdType theId, final Date theSince) {
public IBundleProvider history(final IIdType theId, final Date theSince, RequestDetails theRequestDetails) {
// Notify interceptors
ActionRequestDetails requestDetails = new ActionRequestDetails(theId, getResourceName(), getContext());
ActionRequestDetails requestDetails = new ActionRequestDetails(theId, getResourceName(), getContext(), theRequestDetails);
notifyInterceptors(RestOperationTypeEnum.HISTORY_INSTANCE, requestDetails);
final InstantDt end = createHistoryToTimestamp();
@ -496,9 +497,9 @@ public abstract class BaseHapiFhirResourceDao<T extends IBaseResource> extends B
}
@Override
public IBundleProvider history(Long theId, Date theSince) {
public IBundleProvider history(Long theId, Date theSince, RequestDetails theRequestDetails) {
// Notify interceptors
ActionRequestDetails requestDetails = new ActionRequestDetails(null, getResourceName(), getContext());
ActionRequestDetails requestDetails = new ActionRequestDetails(null, getResourceName(), getContext(), theRequestDetails);
notifyInterceptors(RestOperationTypeEnum.HISTORY_TYPE, requestDetails);
StopWatch w = new StopWatch();
@ -508,9 +509,9 @@ public abstract class BaseHapiFhirResourceDao<T extends IBaseResource> extends B
}
@Override
public <MT extends IBaseMetaType> MT metaAddOperation(IIdType theResourceId, MT theMetaAdd) {
public <MT extends IBaseMetaType> MT metaAddOperation(IIdType theResourceId, MT theMetaAdd, RequestDetails theRequestDetails) {
// Notify interceptors
ActionRequestDetails requestDetails = new ActionRequestDetails(theResourceId, getResourceName(), getContext());
ActionRequestDetails requestDetails = new ActionRequestDetails(theResourceId, getResourceName(), getContext(), theRequestDetails);
notifyInterceptors(RestOperationTypeEnum.META_ADD, requestDetails);
StopWatch w = new StopWatch();
@ -548,7 +549,7 @@ public abstract class BaseHapiFhirResourceDao<T extends IBaseResource> extends B
ourLog.info("Processed metaAddOperation on {} in {}ms", new Object[] { theResourceId, w.getMillisAndRestart() });
@SuppressWarnings("unchecked")
MT retVal = (MT) metaGetOperation(theMetaAdd.getClass(), theResourceId);
MT retVal = (MT) metaGetOperation(theMetaAdd.getClass(), theResourceId, theRequestDetails);
return retVal;
}
@ -635,9 +636,9 @@ public abstract class BaseHapiFhirResourceDao<T extends IBaseResource> extends B
// }
@Override
public <MT extends IBaseMetaType> MT metaDeleteOperation(IIdType theResourceId, MT theMetaDel) {
public <MT extends IBaseMetaType> MT metaDeleteOperation(IIdType theResourceId, MT theMetaDel, RequestDetails theRequestDetails) {
// Notify interceptors
ActionRequestDetails requestDetails = new ActionRequestDetails(theResourceId, getResourceName(), getContext());
ActionRequestDetails requestDetails = new ActionRequestDetails(theResourceId, getResourceName(), getContext(), theRequestDetails);
notifyInterceptors(RestOperationTypeEnum.META_DELETE, requestDetails);
StopWatch w = new StopWatch();
@ -671,14 +672,14 @@ public abstract class BaseHapiFhirResourceDao<T extends IBaseResource> extends B
ourLog.info("Processed metaDeleteOperation on {} in {}ms", new Object[] { theResourceId.getValue(), w.getMillisAndRestart() });
@SuppressWarnings("unchecked")
MT retVal = (MT) metaGetOperation(theMetaDel.getClass(), theResourceId);
MT retVal = (MT) metaGetOperation(theMetaDel.getClass(), theResourceId, theRequestDetails);
return retVal;
}
@Override
public <MT extends IBaseMetaType> MT metaGetOperation(Class<MT> theType) {
public <MT extends IBaseMetaType> MT metaGetOperation(Class<MT> theType, RequestDetails theRequestDetails) {
// Notify interceptors
ActionRequestDetails requestDetails = new ActionRequestDetails(null, getResourceName(), getContext());
ActionRequestDetails requestDetails = new ActionRequestDetails(null, getResourceName(), getContext(), theRequestDetails);
notifyInterceptors(RestOperationTypeEnum.META, requestDetails);
String sql = "SELECT d FROM TagDefinition d WHERE d.myId IN (SELECT DISTINCT t.myTagId FROM ResourceTag t WHERE t.myResourceType = :res_type)";
@ -715,9 +716,9 @@ public abstract class BaseHapiFhirResourceDao<T extends IBaseResource> extends B
}
@Override
public <MT extends IBaseMetaType> MT metaGetOperation(Class<MT> theType, IIdType theId) {
public <MT extends IBaseMetaType> MT metaGetOperation(Class<MT> theType, IIdType theId, RequestDetails theRequestDetails) {
// Notify interceptors
ActionRequestDetails requestDetails = new ActionRequestDetails(theId, getResourceName(), getContext());
ActionRequestDetails requestDetails = new ActionRequestDetails(theId, getResourceName(), getContext(), theRequestDetails);
notifyInterceptors(RestOperationTypeEnum.META, requestDetails);
Set<TagDefinition> tagDefs = new HashSet<TagDefinition>();
@ -775,11 +776,11 @@ public abstract class BaseHapiFhirResourceDao<T extends IBaseResource> extends B
}
@Override
public T read(IIdType theId) {
public T read(IIdType theId, RequestDetails theRequestDetails) {
validateResourceTypeAndThrowIllegalArgumentException(theId);
// Notify interceptors
ActionRequestDetails requestDetails = new ActionRequestDetails(theId, getResourceName(), getContext());
ActionRequestDetails requestDetails = new ActionRequestDetails(theId, getResourceName(), getContext(), theRequestDetails);
RestOperationTypeEnum operationType = theId.hasVersionIdPart() ? RestOperationTypeEnum.VREAD : RestOperationTypeEnum.READ;
notifyInterceptors(operationType, requestDetails);
@ -864,14 +865,14 @@ public abstract class BaseHapiFhirResourceDao<T extends IBaseResource> extends B
}
@Override
public void reindex(T theResource, ResourceTable theEntity) {
updateEntity(theResource, theEntity, false, null, true, false, theEntity.getUpdatedDate());
public void reindex(T theResource, ResourceTable theEntity, RequestDetails theRequestDetails) {
updateEntity(theResource, theEntity, false, null, true, false, theEntity.getUpdatedDate(), theRequestDetails);
}
@Override
public void removeTag(IIdType theId, TagTypeEnum theTagType, String theScheme, String theTerm) {
public void removeTag(IIdType theId, TagTypeEnum theTagType, String theScheme, String theTerm, RequestDetails theRequestDetails) {
// Notify interceptors
ActionRequestDetails requestDetails = new ActionRequestDetails(theId, getResourceName(), getContext());
ActionRequestDetails requestDetails = new ActionRequestDetails(theId, getResourceName(), getContext(), theRequestDetails);
notifyInterceptors(RestOperationTypeEnum.DELETE_TAGS, requestDetails);
StopWatch w = new StopWatch();
@ -912,7 +913,7 @@ public abstract class BaseHapiFhirResourceDao<T extends IBaseResource> extends B
@Override
public IBundleProvider search(final SearchParameterMap theParams) {
// Notify interceptors
ActionRequestDetails requestDetails = new ActionRequestDetails(null, getResourceName(), getContext());
ActionRequestDetails requestDetails = new ActionRequestDetails(null, getResourceName(), getContext(), theParams.getRequestDetails());
notifyInterceptors(RestOperationTypeEnum.SEARCH_TYPE, requestDetails);
SearchBuilder builder = new SearchBuilder(getContext(), myEntityManager, myPlatformTransactionManager, mySearchDao, mySearchResultDao, this, myResourceIndexedSearchParamUriDao);
@ -1005,17 +1006,17 @@ public abstract class BaseHapiFhirResourceDao<T extends IBaseResource> extends B
}
@Override
public DaoMethodOutcome update(T theResource) {
return update(theResource, null);
public DaoMethodOutcome update(T theResource, RequestDetails theRequestDetails) {
return update(theResource, null, theRequestDetails);
}
@Override
public DaoMethodOutcome update(T theResource, String theMatchUrl) {
return update(theResource, theMatchUrl, true);
public DaoMethodOutcome update(T theResource, String theMatchUrl, RequestDetails theRequestDetails) {
return update(theResource, theMatchUrl, true, theRequestDetails);
}
@Override
public DaoMethodOutcome update(T theResource, String theMatchUrl, boolean thePerformIndexing) {
public DaoMethodOutcome update(T theResource, String theMatchUrl, boolean thePerformIndexing, RequestDetails theRequestDetails) {
StopWatch w = new StopWatch();
preProcessResourceForStorage(theResource);
@ -1033,7 +1034,7 @@ public abstract class BaseHapiFhirResourceDao<T extends IBaseResource> extends B
entity = myEntityManager.find(ResourceTable.class, pid);
resourceId = entity.getIdDt();
} else {
return create(theResource, null, thePerformIndexing);
return create(theResource, null, thePerformIndexing, theRequestDetails);
}
} else {
resourceId = theResource.getIdElement();
@ -1046,7 +1047,7 @@ public abstract class BaseHapiFhirResourceDao<T extends IBaseResource> extends B
if (resourceId.isIdPartValidLong()) {
throw new InvalidRequestException(getContext().getLocalizer().getMessage(BaseHapiFhirResourceDao.class, "failedToCreateWithClientAssignedNumericId", theResource.getIdElement().getIdPart()));
}
return doCreate(theResource, null, thePerformIndexing, new Date());
return doCreate(theResource, null, thePerformIndexing, new Date(), theRequestDetails);
}
}
@ -1059,11 +1060,11 @@ public abstract class BaseHapiFhirResourceDao<T extends IBaseResource> extends B
}
// Notify interceptors
ActionRequestDetails requestDetails = new ActionRequestDetails(resourceId, getResourceName(), theResource, getContext());
ActionRequestDetails requestDetails = new ActionRequestDetails(resourceId, getResourceName(), theResource, getContext(), theRequestDetails);
notifyInterceptors(RestOperationTypeEnum.UPDATE, requestDetails);
// Perform update
ResourceTable savedEntity = updateEntity(theResource, entity, true, null, thePerformIndexing, true, new Date());
ResourceTable savedEntity = updateEntity(theResource, entity, true, null, thePerformIndexing, true, new Date(), theRequestDetails);
// Notify JPA interceptors
for (IServerInterceptor next : getConfig().getInterceptors()) {

View File

@ -49,6 +49,7 @@ import ca.uhn.fhir.model.api.TagList;
import ca.uhn.fhir.model.primitive.IdDt;
import ca.uhn.fhir.model.primitive.InstantDt;
import ca.uhn.fhir.rest.api.RestOperationTypeEnum;
import ca.uhn.fhir.rest.method.RequestDetails;
import ca.uhn.fhir.rest.server.IBundleProvider;
import ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException;
import ca.uhn.fhir.rest.server.interceptor.IServerInterceptor.ActionRequestDetails;
@ -62,15 +63,15 @@ public abstract class BaseHapiFhirSystemDao<T, MT> extends BaseHapiFhirDao<IBase
@Transactional(propagation = Propagation.REQUIRED)
@Override
public void deleteAllTagsOnServer() {
public void deleteAllTagsOnServer(RequestDetails theRequestDetails) {
// Notify interceptors
ActionRequestDetails requestDetails = new ActionRequestDetails(null, null, getContext());
ActionRequestDetails requestDetails = new ActionRequestDetails(null, null, getContext(), theRequestDetails);
notifyInterceptors(RestOperationTypeEnum.DELETE_TAGS, requestDetails);
myEntityManager.createQuery("DELETE from ResourceTag t").executeUpdate();
}
private int doPerformReindexingPass(final Integer theCount) {
private int doPerformReindexingPass(final Integer theCount, final RequestDetails theRequestDetails) {
TransactionTemplate txTemplate = new TransactionTemplate(myTxManager);
txTemplate.setPropagationBehavior(TransactionTemplate.PROPAGATION_REQUIRED);
return txTemplate.execute(new TransactionCallback<Integer>() {
@ -102,7 +103,7 @@ public abstract class BaseHapiFhirSystemDao<T, MT> extends BaseHapiFhirDao<IBase
@SuppressWarnings("rawtypes")
final IFhirResourceDao dao = getDao(resource.getClass());
dao.reindex(resource, resourceTable);
dao.reindex(resource, resourceTable, theRequestDetails);
} catch (Exception e) {
ourLog.error("Failed to index resource {}: {}", new Object[] { resourceTable.getIdDt(), e.toString(), e });
throw new ReindexFailureException(resourceTable.getId());
@ -120,9 +121,9 @@ public abstract class BaseHapiFhirSystemDao<T, MT> extends BaseHapiFhirDao<IBase
}
@Override
public TagList getAllTags() {
public TagList getAllTags(RequestDetails theRequestDetails) {
// Notify interceptors
ActionRequestDetails requestDetails = new ActionRequestDetails(null, null, getContext());
ActionRequestDetails requestDetails = new ActionRequestDetails(null, null, getContext(), theRequestDetails);
notifyInterceptors(RestOperationTypeEnum.GET_TAGS, requestDetails);
StopWatch w = new StopWatch();
@ -155,9 +156,9 @@ public abstract class BaseHapiFhirSystemDao<T, MT> extends BaseHapiFhirDao<IBase
}
@Override
public IBundleProvider history(Date theSince) {
public IBundleProvider history(Date theSince, RequestDetails theRequestDetails) {
// Notify interceptors
ActionRequestDetails requestDetails = new ActionRequestDetails(null, null, getContext());
ActionRequestDetails requestDetails = new ActionRequestDetails(null, null, getContext(), theRequestDetails);
notifyInterceptors(RestOperationTypeEnum.HISTORY_SYSTEM, requestDetails);
StopWatch w = new StopWatch();
@ -194,9 +195,9 @@ public abstract class BaseHapiFhirSystemDao<T, MT> extends BaseHapiFhirDao<IBase
@Override
@Transactional(propagation = Propagation.NOT_SUPPORTED)
public int performReindexingPass(final Integer theCount) {
public int performReindexingPass(final Integer theCount, RequestDetails theRequestDetails) {
try {
return doPerformReindexingPass(theCount);
return doPerformReindexingPass(theCount, theRequestDetails);
} catch (ReindexFailureException e) {
ourLog.warn("Reindexing failed for resource {}", e.getResourceId());
markResourceAsIndexingFailed(e.getResourceId());

View File

@ -35,6 +35,7 @@ import ca.uhn.fhir.model.base.composite.BaseResourceReferenceDt;
import ca.uhn.fhir.model.dstu.resource.OperationOutcome;
import ca.uhn.fhir.rest.api.MethodOutcome;
import ca.uhn.fhir.rest.api.ValidationModeEnum;
import ca.uhn.fhir.rest.method.RequestDetails;
import ca.uhn.fhir.rest.server.EncodingEnum;
import ca.uhn.fhir.util.FhirTerser;
@ -55,7 +56,7 @@ public class FhirResourceDaoDstu1<T extends IResource> extends BaseHapiFhirResou
}
@Override
public MethodOutcome validate(T theResource, IIdType theId, String theRawResource, EncodingEnum theEncoding, ValidationModeEnum theMode, String theProfile) {
public MethodOutcome validate(T theResource, IIdType theId, String theRawResource, EncodingEnum theEncoding, ValidationModeEnum theMode, String theProfile, RequestDetails theRequestDetails) {
throw new UnsupportedOperationException();
}

View File

@ -52,6 +52,7 @@ import ca.uhn.fhir.model.primitive.IdDt;
import ca.uhn.fhir.rest.api.MethodOutcome;
import ca.uhn.fhir.rest.api.RestOperationTypeEnum;
import ca.uhn.fhir.rest.api.ValidationModeEnum;
import ca.uhn.fhir.rest.method.RequestDetails;
import ca.uhn.fhir.rest.server.EncodingEnum;
import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException;
import ca.uhn.fhir.rest.server.exceptions.PreconditionFailedException;
@ -98,8 +99,8 @@ public class FhirResourceDaoDstu2<T extends IResource> extends BaseHapiFhirResou
}
@Override
public MethodOutcome validate(T theResource, IIdType theId, String theRawResource, EncodingEnum theEncoding, ValidationModeEnum theMode, String theProfile) {
ActionRequestDetails requestDetails = new ActionRequestDetails(theId, null, theResource, getContext());
public MethodOutcome validate(T theResource, IIdType theId, String theRawResource, EncodingEnum theEncoding, ValidationModeEnum theMode, String theProfile, RequestDetails theRequestDetails) {
ActionRequestDetails requestDetails = new ActionRequestDetails(theId, null, theResource, getContext(), theRequestDetails);
notifyInterceptors(RestOperationTypeEnum.VALIDATE, requestDetails);
if (theMode == ValidationModeEnum.DELETE) {

View File

@ -32,6 +32,7 @@ import ca.uhn.fhir.model.api.IResource;
import ca.uhn.fhir.model.dstu2.resource.Patient;
import ca.uhn.fhir.rest.api.RestOperationTypeEnum;
import ca.uhn.fhir.rest.api.SortSpec;
import ca.uhn.fhir.rest.method.RequestDetails;
import ca.uhn.fhir.rest.param.DateRangeParam;
import ca.uhn.fhir.rest.param.StringAndListParam;
import ca.uhn.fhir.rest.param.StringParam;
@ -66,18 +67,18 @@ public class FhirResourceDaoPatientDstu2 extends FhirResourceDaoDstu2<Patient>im
}
@Override
public IBundleProvider patientInstanceEverything(HttpServletRequest theServletRequest, IIdType theId, IPrimitiveType<Integer> theCount, DateRangeParam theLastUpdated, SortSpec theSort, StringAndListParam theContent, StringAndListParam theNarrative) {
public IBundleProvider patientInstanceEverything(HttpServletRequest theServletRequest, IIdType theId, IPrimitiveType<Integer> theCount, DateRangeParam theLastUpdated, SortSpec theSort, StringAndListParam theContent, StringAndListParam theNarrative, RequestDetails theRequestDetails) {
// Notify interceptors
ActionRequestDetails requestDetails = new ActionRequestDetails(null, getResourceName(), getContext());
ActionRequestDetails requestDetails = new ActionRequestDetails(null, getResourceName(), getContext(), theRequestDetails);
notifyInterceptors(RestOperationTypeEnum.EXTENDED_OPERATION_INSTANCE, requestDetails);
return doEverythingOperation(theId, theCount, theLastUpdated, theSort, theContent, theNarrative);
}
@Override
public IBundleProvider patientTypeEverything(HttpServletRequest theServletRequest, IPrimitiveType<Integer> theCount, DateRangeParam theLastUpdated, SortSpec theSort, StringAndListParam theContent, StringAndListParam theNarrative) {
public IBundleProvider patientTypeEverything(HttpServletRequest theServletRequest, IPrimitiveType<Integer> theCount, DateRangeParam theLastUpdated, SortSpec theSort, StringAndListParam theContent, StringAndListParam theNarrative, RequestDetails theRequestDetails) {
// Notify interceptors
ActionRequestDetails requestDetails = new ActionRequestDetails(null, getResourceName(), getContext());
ActionRequestDetails requestDetails = new ActionRequestDetails(null, getResourceName(), getContext(), theRequestDetails);
notifyInterceptors(RestOperationTypeEnum.EXTENDED_OPERATION_TYPE, requestDetails);
return doEverythingOperation(null, theCount, theLastUpdated, theSort, theContent, theNarrative);

View File

@ -35,6 +35,7 @@ import ca.uhn.fhir.model.dstu2.resource.OperationOutcome;
import ca.uhn.fhir.model.dstu2.resource.Questionnaire;
import ca.uhn.fhir.model.dstu2.resource.QuestionnaireResponse;
import ca.uhn.fhir.model.dstu2.resource.ValueSet;
import ca.uhn.fhir.rest.method.RequestDetails;
import ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException;
import ca.uhn.fhir.rest.server.exceptions.UnprocessableEntityException;
import ca.uhn.fhir.validation.FhirValidator;
@ -63,8 +64,8 @@ public class FhirResourceDaoQuestionnaireResponseDstu2 extends FhirResourceDaoDs
}
@Override
protected void validateResourceForStorage(QuestionnaireResponse theResource, ResourceTable theEntityToSave) {
super.validateResourceForStorage(theResource, theEntityToSave);
protected void validateResourceForStorage(QuestionnaireResponse theResource, ResourceTable theEntityToSave, RequestDetails theRequestDetails) {
super.validateResourceForStorage(theResource, theEntityToSave, theRequestDetails);
if (!myValidateResponses) {
return;
}
@ -79,7 +80,7 @@ public class FhirResourceDaoQuestionnaireResponseDstu2 extends FhirResourceDaoDs
val.setValidateAgainstStandardSchematron(false);
FhirQuestionnaireResponseValidator module = new FhirQuestionnaireResponseValidator();
module.setResourceLoader(new JpaResourceLoader());
module.setResourceLoader(new JpaResourceLoader(theRequestDetails));
val.registerValidatorModule(module);
ValidationResult result = val.validateWithResult(myRefImplCtx.newJsonParser().parseResource(getContext().newJsonParser().encodeResourceToString(qa)));
@ -91,6 +92,12 @@ public class FhirResourceDaoQuestionnaireResponseDstu2 extends FhirResourceDaoDs
public class JpaResourceLoader implements IResourceLoader {
private RequestDetails myRequestDetails;
public JpaResourceLoader(RequestDetails theRequestDetails) {
myRequestDetails = theRequestDetails;
}
@Override
public <T extends IBaseResource> T load(Class<T> theType, IIdType theId) throws ResourceNotFoundException {
@ -100,7 +107,7 @@ public class FhirResourceDaoQuestionnaireResponseDstu2 extends FhirResourceDaoDs
*/
if ("ValueSet".equals(theType.getSimpleName())) {
IFhirResourceDao<ValueSet> dao = getDao(ValueSet.class);
ValueSet in = dao.read(theId);
ValueSet in = dao.read(theId, myRequestDetails);
String encoded = getContext().newJsonParser().encodeResourceToString(in);
// TODO: this is temporary until structures-dstu2 catches up to structures-hl7org.dstu2
@ -109,7 +116,7 @@ public class FhirResourceDaoQuestionnaireResponseDstu2 extends FhirResourceDaoDs
return myRefImplCtx.newJsonParser().parseResource(theType, encoded);
} else if ("Questionnaire".equals(theType.getSimpleName())) {
IFhirResourceDao<Questionnaire> dao = getDao(Questionnaire.class);
Questionnaire vs = dao.read(theId);
Questionnaire vs = dao.read(theId, myRequestDetails);
return myRefImplCtx.newJsonParser().parseResource(theType, getContext().newJsonParser().encodeResourceToString(vs));
} else {
// Should not happen, validator will only ask for these two

View File

@ -27,6 +27,8 @@ import org.springframework.scheduling.annotation.Scheduled;
import ca.uhn.fhir.model.dstu2.composite.MetaDt;
import ca.uhn.fhir.model.dstu2.resource.Bundle;
import ca.uhn.fhir.model.dstu2.resource.SearchParameter;
import ca.uhn.fhir.rest.method.RequestDetails;
import ca.uhn.fhir.rest.server.servlet.ServletRequestDetails;
public class FhirResourceDaoSearchParameterDstu2 extends FhirResourceDaoDstu2<SearchParameter>implements IFhirResourceDaoSearchParameter<SearchParameter> {
@ -46,9 +48,10 @@ public class FhirResourceDaoSearchParameterDstu2 extends FhirResourceDaoDstu2<Se
return;
}
int count = mySystemDao.performReindexingPass(100);
RequestDetails requestDetails = new ServletRequestDetails();
int count = mySystemDao.performReindexingPass(100, requestDetails);
for (int i = 0; i < 50 && count > 0; i++) {
count = mySystemDao.performReindexingPass(100);
count = mySystemDao.performReindexingPass(100, requestDetails);
try {
Thread.sleep(DateUtils.MILLIS_PER_SECOND);
} catch (InterruptedException e) {

View File

@ -60,11 +60,13 @@ import ca.uhn.fhir.model.primitive.InstantDt;
import ca.uhn.fhir.parser.DataFormatException;
import ca.uhn.fhir.rest.api.SortOrderEnum;
import ca.uhn.fhir.rest.api.SortSpec;
import ca.uhn.fhir.rest.method.RequestDetails;
import ca.uhn.fhir.rest.param.DateParam;
import ca.uhn.fhir.rest.param.DateRangeParam;
import ca.uhn.fhir.rest.server.Constants;
import ca.uhn.fhir.rest.server.IBundleProvider;
import ca.uhn.fhir.rest.server.exceptions.UnprocessableEntityException;
import ca.uhn.fhir.rest.server.servlet.ServletRequestDetails;
public class FhirResourceDaoSubscriptionDstu2 extends FhirResourceDaoDstu2<Subscription>implements IFhirResourceDaoSubscription<Subscription> {
@ -250,7 +252,7 @@ public class FhirResourceDaoSubscriptionDstu2 extends FhirResourceDaoDstu2<Subsc
txTemplate.execute(new TransactionCallback<Void>() {
@Override
public Void doInTransaction(TransactionStatus theStatus) {
delete(subscriptionId);
delete(subscriptionId, new ServletRequestDetails());
return null;
}
});
@ -259,8 +261,8 @@ public class FhirResourceDaoSubscriptionDstu2 extends FhirResourceDaoDstu2<Subsc
@Override
protected ResourceTable updateEntity(IBaseResource theResource, ResourceTable theEntity, boolean theUpdateHistory, Date theDeletedTimestampOrNull, boolean thePerformIndexing, boolean theUpdateVersion,
Date theUpdateTime) {
ResourceTable retVal = super.updateEntity(theResource, theEntity, theUpdateHistory, theDeletedTimestampOrNull, thePerformIndexing, theUpdateVersion, theUpdateTime);
Date theUpdateTime, RequestDetails theRequestDetails) {
ResourceTable retVal = super.updateEntity(theResource, theEntity, theUpdateHistory, theDeletedTimestampOrNull, thePerformIndexing, theUpdateVersion, theUpdateTime, theRequestDetails);
Subscription resource = (Subscription) theResource;
Long resourceId = theEntity.getId();
@ -309,8 +311,8 @@ public class FhirResourceDaoSubscriptionDstu2 extends FhirResourceDaoDstu2<Subsc
}
@Override
protected void validateResourceForStorage(Subscription theResource, ResourceTable theEntityToSave) {
super.validateResourceForStorage(theResource, theEntityToSave);
protected void validateResourceForStorage(Subscription theResource, ResourceTable theEntityToSave, RequestDetails theRequestDetails) {
super.validateResourceForStorage(theResource, theEntityToSave, theRequestDetails);
RuntimeResourceDefinition resDef = validateCriteriaAndReturnResourceDefinition(theResource);

View File

@ -49,6 +49,7 @@ import ca.uhn.fhir.model.dstu2.resource.ValueSet.ComposeIncludeConcept;
import ca.uhn.fhir.model.dstu2.resource.ValueSet.ExpansionContains;
import ca.uhn.fhir.model.primitive.DateTimeDt;
import ca.uhn.fhir.model.primitive.IdDt;
import ca.uhn.fhir.rest.method.RequestDetails;
import ca.uhn.fhir.rest.param.TokenParam;
import ca.uhn.fhir.rest.param.UriParam;
import ca.uhn.fhir.rest.server.IBundleProvider;
@ -288,7 +289,7 @@ public class FhirResourceDaoValueSetDstu2 extends FhirResourceDaoDstu2<ValueSet>
}
@Override
public ca.uhn.fhir.jpa.dao.IFhirResourceDaoValueSet.LookupCodeResult lookupCode(IPrimitiveType<String> theCode, IPrimitiveType<String> theSystem, CodingDt theCoding) {
public ca.uhn.fhir.jpa.dao.IFhirResourceDaoValueSet.LookupCodeResult lookupCode(IPrimitiveType<String> theCode, IPrimitiveType<String> theSystem, CodingDt theCoding, RequestDetails theRequestDetails) {
boolean haveCoding = theCoding != null && isNotBlank(theCoding.getSystem()) && isNotBlank(theCoding.getCode());
boolean haveCode = theCode != null && theCode.isEmpty() == false;
boolean haveSystem = theSystem != null && theSystem.isEmpty() == false;

View File

@ -54,7 +54,7 @@ public class FhirSystemDaoDstu1 extends BaseHapiFhirSystemDao<List<IResource>, M
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(FhirSystemDaoDstu1.class);
@Override
public MetaDt metaGetOperation() {
public MetaDt metaGetOperation(RequestDetails theRequestDetails) {
throw new NotImplementedOperationException("meta not supported in DSTU1");
}
@ -64,7 +64,7 @@ public class FhirSystemDaoDstu1 extends BaseHapiFhirSystemDao<List<IResource>, M
ourLog.info("Beginning transaction with {} resources", theResources.size());
// Notify interceptors
ActionRequestDetails requestDetails = new ActionRequestDetails(null, null, getContext());
ActionRequestDetails requestDetails = new ActionRequestDetails(null, null, getContext(), theRequestDetails);
notifyInterceptors(RestOperationTypeEnum.TRANSACTION, requestDetails);
long start = System.currentTimeMillis();
@ -270,7 +270,7 @@ public class FhirSystemDaoDstu1 extends BaseHapiFhirSystemDao<List<IResource>, M
ResourceMetadataKeyEnum.DELETED_AT.put(resource, new InstantDt(deletedTimestampOrNull));
}
updateEntity(resource, table, table.getId() != null, deletedTimestampOrNull, updateTime);
updateEntity(resource, table, table.getId() != null, deletedTimestampOrNull, updateTime, theRequestDetails);
}
long delay = System.currentTimeMillis() - start;

View File

@ -198,9 +198,9 @@ public class FhirSystemDaoDstu2 extends BaseHapiFhirSystemDao<Bundle, MetaDt> {
}
@Override
public MetaDt metaGetOperation() {
public MetaDt metaGetOperation(RequestDetails theRequestDetails) {
// Notify interceptors
ActionRequestDetails requestDetails = new ActionRequestDetails(null, null, getContext());
ActionRequestDetails requestDetails = new ActionRequestDetails(null, null, getContext(), theRequestDetails);
notifyInterceptors(RestOperationTypeEnum.META, requestDetails);
String sql = "SELECT d FROM TagDefinition d WHERE d.myId IN (SELECT DISTINCT t.myTagId FROM ResourceTag t)";
@ -259,7 +259,7 @@ public class FhirSystemDaoDstu2 extends BaseHapiFhirSystemDao<Bundle, MetaDt> {
@Transactional(propagation = Propagation.REQUIRED)
@Override
public Bundle transaction(RequestDetails theRequestDetails, Bundle theRequest) {
ActionRequestDetails requestDetails = new ActionRequestDetails(null, "Bundle", theRequest, getContext());
ActionRequestDetails requestDetails = new ActionRequestDetails(null, "Bundle", theRequest, getContext(), theRequestDetails);
notifyInterceptors(RestOperationTypeEnum.TRANSACTION, requestDetails);
String actionName = "Transaction";
@ -379,7 +379,7 @@ public class FhirSystemDaoDstu2 extends BaseHapiFhirSystemDao<Bundle, MetaDt> {
IFhirResourceDao resourceDao = getDaoOrThrowException(res.getClass());
res.setId((String) null);
DaoMethodOutcome outcome;
outcome = resourceDao.create(res, nextReqEntry.getRequest().getIfNoneExist(), false);
outcome = resourceDao.create(res, nextReqEntry.getRequest().getIfNoneExist(), false, theRequestDetails);
handleTransactionCreateOrUpdateOutcome(idSubstitutions, idToPersistedOutcome, nextResourceId, outcome, nextRespEntry, resourceType, res);
break;
}
@ -390,12 +390,12 @@ public class FhirSystemDaoDstu2 extends BaseHapiFhirSystemDao<Bundle, MetaDt> {
ca.uhn.fhir.jpa.dao.IFhirResourceDao<? extends IBaseResource> dao = toDao(parts, verb.getCode(), url);
int status = Constants.STATUS_HTTP_204_NO_CONTENT;
if (parts.getResourceId() != null) {
ResourceTable deleted = dao.delete(new IdDt(parts.getResourceType(), parts.getResourceId()), deleteConflicts);
ResourceTable deleted = dao.delete(new IdDt(parts.getResourceType(), parts.getResourceId()), deleteConflicts, theRequestDetails);
if (deleted != null) {
deletedResources.add(deleted.getIdDt().toUnqualifiedVersionless());
}
} else {
List<ResourceTable> allDeleted = dao.deleteByUrl(parts.getResourceType() + '?' + parts.getParams(), deleteConflicts);
List<ResourceTable> allDeleted = dao.deleteByUrl(parts.getResourceType() + '?' + parts.getParams(), deleteConflicts, theRequestDetails);
for (ResourceTable deleted : allDeleted) {
deletedResources.add(deleted.getIdDt().toUnqualifiedVersionless());
}
@ -419,10 +419,10 @@ public class FhirSystemDaoDstu2 extends BaseHapiFhirSystemDao<Bundle, MetaDt> {
UrlParts parts = UrlUtil.parseUrl(url);
if (isNotBlank(parts.getResourceId())) {
res.setId(new IdDt(parts.getResourceType(), parts.getResourceId()));
outcome = resourceDao.update(res, null, false);
outcome = resourceDao.update(res, null, false, theRequestDetails);
} else {
res.setId((String) null);
outcome = resourceDao.update(res, parts.getResourceType() + '?' + parts.getParams(), false);
outcome = resourceDao.update(res, parts.getResourceType() + '?' + parts.getParams(), false, theRequestDetails);
}
handleTransactionCreateOrUpdateOutcome(idSubstitutions, idToPersistedOutcome, nextResourceId, outcome, nextRespEntry, resourceType, res);
@ -471,7 +471,7 @@ public class FhirSystemDaoDstu2 extends BaseHapiFhirSystemDao<Bundle, MetaDt> {
InstantDt deletedInstantOrNull = ResourceMetadataKeyEnum.DELETED_AT.get(nextResource);
Date deletedTimestampOrNull = deletedInstantOrNull != null ? deletedInstantOrNull.getValue() : null;
updateEntity(nextResource, nextOutcome.getEntity(), false, deletedTimestampOrNull, true, false, updateTime);
updateEntity(nextResource, nextOutcome.getEntity(), false, deletedTimestampOrNull, true, false, updateTime, theRequestDetails);
}
myEntityManager.flush();
@ -571,9 +571,14 @@ public class FhirSystemDaoDstu2 extends BaseHapiFhirSystemDao<Bundle, MetaDt> {
}
}
ourLog.info("Flushing context after {}", theActionName);
myEntityManager.flush();
long delay = System.currentTimeMillis() - start;
ourLog.info(theActionName + " completed in {}ms", new Object[] { delay });
int numEntries = theRequest.getEntry().size();
long delayPer = delay / numEntries;
ourLog.info("{} completed in {}ms ({} entries at {}ms per entry)", new Object[] { theActionName , delay, numEntries, delayPer });
response.setType(BundleTypeEnum.TRANSACTION_RESPONSE);
return response;

View File

@ -39,6 +39,7 @@ import ca.uhn.fhir.model.api.IQueryParameterType;
import ca.uhn.fhir.model.api.TagList;
import ca.uhn.fhir.rest.api.MethodOutcome;
import ca.uhn.fhir.rest.api.ValidationModeEnum;
import ca.uhn.fhir.rest.method.RequestDetails;
import ca.uhn.fhir.rest.param.DateRangeParam;
import ca.uhn.fhir.rest.server.EncodingEnum;
import ca.uhn.fhir.rest.server.IBundleProvider;
@ -48,82 +49,92 @@ public interface IFhirResourceDao<T extends IBaseResource> extends IDao {
void addTag(IIdType theId, TagTypeEnum theTagType, String theScheme, String theTerm, String theLabel);
DaoMethodOutcome create(T theResource);
DaoMethodOutcome create(T theResource, RequestDetails theRequestDetails);
DaoMethodOutcome create(T theResource, String theIfNoneExist);
DaoMethodOutcome create(T theResource, String theIfNoneExist, RequestDetails theRequestDetails);
/**
* @param thePerformIndexing
* Use with caution! If you set this to false, you need to manually perform indexing or your resources
* won't be indexed and searches won't work.
* @param theRequestDetails TODO
*/
DaoMethodOutcome create(T theResource, String theIfNoneExist, boolean thePerformIndexing);
DaoMethodOutcome create(T theResource, String theIfNoneExist, boolean thePerformIndexing, RequestDetails theRequestDetails);
/**
* This method throws an exception if there are delete conflicts
* @param theRequestDetails TODO
*/
DaoMethodOutcome delete(IIdType theResource);
DaoMethodOutcome delete(IIdType theResource, RequestDetails theRequestDetails);
/**
* This method does not throw an exception if there are delete conflicts, but populates them
* in the provided list
* @param theRequestDetails TODO
*/
ResourceTable delete(IIdType theResource, List<DeleteConflict> theDeleteConflictsListToPopulate);
ResourceTable delete(IIdType theResource, List<DeleteConflict> theDeleteConflictsListToPopulate, RequestDetails theRequestDetails);
/**
* This method throws an exception if there are delete conflicts
* @param theRequestDetails TODO
*/
DaoMethodOutcome deleteByUrl(String theString);
DaoMethodOutcome deleteByUrl(String theString, RequestDetails theRequestDetails);
/**
* This method does not throw an exception if there are delete conflicts, but populates them
* in the provided list
* @param theRequestDetails TODO
* @return
*/
List<ResourceTable> deleteByUrl(String theUrl, List<DeleteConflict> theDeleteConflictsListToPopulate);
List<ResourceTable> deleteByUrl(String theUrl, List<DeleteConflict> theDeleteConflictsListToPopulate, RequestDetails theRequestDetails);
TagList getAllResourceTags();
TagList getAllResourceTags(RequestDetails theRequestDetails);
Class<T> getResourceType();
TagList getTags(IIdType theResourceId);
TagList getTags(IIdType theResourceId, RequestDetails theRequestDetails);
IBundleProvider history(Date theSince);
IBundleProvider history(Date theSince, RequestDetails theRequestDetails);
IBundleProvider history(IIdType theId, Date theSince);
IBundleProvider history(IIdType theId, Date theSince, RequestDetails theRequestDetails);
IBundleProvider history(Long theId, Date theSince);
IBundleProvider history(Long theId, Date theSince, RequestDetails theRequestDetails);
/**
* Not supported in DSTU1!
* @param theRequestDetails TODO
*/
<MT extends IBaseMetaType> MT metaAddOperation(IIdType theId1, MT theMetaAdd);
<MT extends IBaseMetaType> MT metaAddOperation(IIdType theId1, MT theMetaAdd, RequestDetails theRequestDetails);
/**
* Not supported in DSTU1!
* @param theRequestDetails TODO
*/
<MT extends IBaseMetaType> MT metaDeleteOperation(IIdType theId1, MT theMetaDel);
<MT extends IBaseMetaType> MT metaDeleteOperation(IIdType theId1, MT theMetaDel, RequestDetails theRequestDetails);
/**
* Not supported in DSTU1!
* @param theRequestDetails TODO
*/
<MT extends IBaseMetaType> MT metaGetOperation(Class<MT> theType);
<MT extends IBaseMetaType> MT metaGetOperation(Class<MT> theType, RequestDetails theRequestDetails);
/**
* Not supported in DSTU1!
* @param theRequestDetails TODO
*/
<MT extends IBaseMetaType> MT metaGetOperation(Class<MT> theType, IIdType theId);
<MT extends IBaseMetaType> MT metaGetOperation(Class<MT> theType, IIdType theId, RequestDetails theRequestDetails);
Set<Long> processMatchUrl(String theMatchUrl);
/**
*
* @param theId
* @param theRequestDetails TODO
* @return
* @throws ResourceNotFoundException
* If the ID is not known to the server
*/
T read(IIdType theId);
T read(IIdType theId, RequestDetails theRequestDetails);
BaseHasResource readEntity(IIdType theId);
@ -137,10 +148,11 @@ public interface IFhirResourceDao<T extends IBaseResource> extends IDao {
/**
* Updates index tables associated with the given resource. Does not create a new
* version or update the resource's update time.
* @param theRequestDetails TODO
*/
void reindex(T theResource, ResourceTable theEntity);
void reindex(T theResource, ResourceTable theEntity, RequestDetails theRequestDetails);
void removeTag(IIdType theId, TagTypeEnum theTagType, String theScheme, String theTerm);
void removeTag(IIdType theId, TagTypeEnum theTagType, String theScheme, String theTerm, RequestDetails theRequestDetails);
IBundleProvider search(Map<String, IQueryParameterType> theParams);
@ -154,21 +166,23 @@ public interface IFhirResourceDao<T extends IBaseResource> extends IDao {
Set<Long> searchForIdsWithAndOr(SearchParameterMap theParams, Collection<Long> theInitialPids, DateRangeParam theLastUpdated);
DaoMethodOutcome update(T theResource);
DaoMethodOutcome update(T theResource, RequestDetails theRequestDetails);
DaoMethodOutcome update(T theResource, String theMatchUrl);
DaoMethodOutcome update(T theResource, String theMatchUrl, RequestDetails theRequestDetails);
/**
* @param thePerformIndexing
* Use with caution! If you set this to false, you need to manually perform indexing or your resources
* won't be indexed and searches won't work.
* @param theRequestDetails TODO
*/
DaoMethodOutcome update(T theResource, String theMatchUrl, boolean thePerformIndexing);
DaoMethodOutcome update(T theResource, String theMatchUrl, boolean thePerformIndexing, RequestDetails theRequestDetails);
/**
* Not supported in DSTU1!
* @param theRequestDetails TODO
*/
MethodOutcome validate(T theResource, IIdType theId, String theRawResource, EncodingEnum theEncoding, ValidationModeEnum theMode, String theProfile);
MethodOutcome validate(T theResource, IIdType theId, String theRawResource, EncodingEnum theEncoding, ValidationModeEnum theMode, String theProfile, RequestDetails theRequestDetails);
// /**
// * Invoke the everything operation

View File

@ -27,14 +27,15 @@ import org.hl7.fhir.instance.model.api.IIdType;
import org.hl7.fhir.instance.model.api.IPrimitiveType;
import ca.uhn.fhir.rest.api.SortSpec;
import ca.uhn.fhir.rest.method.RequestDetails;
import ca.uhn.fhir.rest.param.DateRangeParam;
import ca.uhn.fhir.rest.param.StringAndListParam;
import ca.uhn.fhir.rest.server.IBundleProvider;
public interface IFhirResourceDaoPatient<T extends IBaseResource> extends IFhirResourceDao<T> {
IBundleProvider patientInstanceEverything(HttpServletRequest theServletRequest, IIdType theId, IPrimitiveType<Integer> theCount, DateRangeParam theLastUpdate, SortSpec theSort, StringAndListParam theContent, StringAndListParam theNarrative);
IBundleProvider patientInstanceEverything(HttpServletRequest theServletRequest, IIdType theId, IPrimitiveType<Integer> theCount, DateRangeParam theLastUpdate, SortSpec theSort, StringAndListParam theContent, StringAndListParam theNarrative, RequestDetails theRequestDetails);
IBundleProvider patientTypeEverything(HttpServletRequest theServletRequest, IPrimitiveType<Integer> theCount, DateRangeParam theLastUpdated, SortSpec theSortSpec, StringAndListParam theContent, StringAndListParam theNarrative);
IBundleProvider patientTypeEverything(HttpServletRequest theServletRequest, IPrimitiveType<Integer> theCount, DateRangeParam theLastUpdated, SortSpec theSortSpec, StringAndListParam theContent, StringAndListParam theNarrative, RequestDetails theRequestDetails);
}

View File

@ -24,6 +24,8 @@ import org.hl7.fhir.instance.model.api.IBaseResource;
import org.hl7.fhir.instance.model.api.IIdType;
import org.hl7.fhir.instance.model.api.IPrimitiveType;
import ca.uhn.fhir.rest.method.RequestDetails;
public interface IFhirResourceDaoValueSet<T extends IBaseResource, CD, CC> extends IFhirResourceDao<T> {
T expand(IIdType theId, String theFilter);
@ -32,7 +34,7 @@ public interface IFhirResourceDaoValueSet<T extends IBaseResource, CD, CC> exten
T expandByIdentifier(String theUri, String theFilter);
LookupCodeResult lookupCode(IPrimitiveType<String> theCode, IPrimitiveType<String> theSystem, CD theCoding);
LookupCodeResult lookupCode(IPrimitiveType<String> theCode, IPrimitiveType<String> theSystem, CD theCoding, RequestDetails theRequestDetails);
ValidateCodeResult validateCode(IPrimitiveType<String> theValueSetIdentifier, IIdType theId, IPrimitiveType<String> theCode, IPrimitiveType<String> theSystem, IPrimitiveType<String> theDisplay, CD theCoding, CC theCodeableConcept);

View File

@ -35,14 +35,15 @@ public interface IFhirSystemDao<T, MT> extends IDao {
/**
* Use with caution! This deletes everything!!
* @param theRequestDetails TODO
*/
void deleteAllTagsOnServer();
void deleteAllTagsOnServer(RequestDetails theRequestDetails);
TagList getAllTags();
TagList getAllTags(RequestDetails theRequestDetails);
Map<String, Long> getResourceCounts();
IBundleProvider history(Date theDate);
IBundleProvider history(Date theDate, RequestDetails theRequestDetails);
/**
* Marks all indexes as needing fresh indexing
@ -53,10 +54,11 @@ public interface IFhirSystemDao<T, MT> extends IDao {
/**
* Not supported for DSTU1
* @param theRequestDetails TODO
*/
MT metaGetOperation();
MT metaGetOperation(RequestDetails theRequestDetails);
int performReindexingPass(Integer theCount);
int performReindexingPass(Integer theCount, RequestDetails theRequestDetails);
T transaction(RequestDetails theRequestDetails, T theResources);

View File

@ -34,6 +34,7 @@ import ca.uhn.fhir.model.api.IQueryParameterOr;
import ca.uhn.fhir.model.api.IQueryParameterType;
import ca.uhn.fhir.model.api.Include;
import ca.uhn.fhir.rest.api.SortSpec;
import ca.uhn.fhir.rest.method.RequestDetails;
import ca.uhn.fhir.rest.param.DateRangeParam;
import ca.uhn.fhir.rest.server.Constants;
@ -45,6 +46,7 @@ public class SearchParameterMap extends LinkedHashMap<String, List<List<? extend
private EverythingModeEnum myEverythingMode = null;
private Set<Include> myIncludes;
private DateRangeParam myLastUpdated;
private RequestDetails myRequestDetails;
private Set<Include> myRevIncludes;
private SortSpec mySort;
@ -101,6 +103,10 @@ public class SearchParameterMap extends LinkedHashMap<String, List<List<? extend
return myCount;
}
public EverythingModeEnum getEverythingMode() {
return myEverythingMode;
}
public Set<Include> getIncludes() {
if (myIncludes == null) {
myIncludes = new HashSet<Include>();
@ -112,6 +118,10 @@ public class SearchParameterMap extends LinkedHashMap<String, List<List<? extend
return myLastUpdated;
}
public RequestDetails getRequestDetails() {
return myRequestDetails;
}
public Set<Include> getRevIncludes() {
if (myRevIncludes == null) {
myRevIncludes = new HashSet<Include>();
@ -123,10 +133,6 @@ public class SearchParameterMap extends LinkedHashMap<String, List<List<? extend
return mySort;
}
public EverythingModeEnum getEverythingMode() {
return myEverythingMode;
}
public void setCount(Integer theCount) {
myCount = theCount;
}
@ -143,6 +149,10 @@ public class SearchParameterMap extends LinkedHashMap<String, List<List<? extend
myLastUpdated = theLastUpdated;
}
public void setRequestDetails(RequestDetails theRequestDetails) {
myRequestDetails = theRequestDetails;
}
public void setRevIncludes(Set<Include> theRevIncludes) {
myRevIncludes = theRevIncludes;
}
@ -164,36 +174,36 @@ public class SearchParameterMap extends LinkedHashMap<String, List<List<? extend
}
public enum EverythingModeEnum {
//@formatter:off
PATIENT_TYPE(true, false, false),
PATIENT_INSTANCE(true, false, true),
ENCOUNTER_INSTANCE(false, true, true),
ENCOUNTER_TYPE(false, true, false),
ENCOUNTER_INSTANCE(false, true, true);
PATIENT_INSTANCE(true, false, true),
//@formatter:off
PATIENT_TYPE(true, false, false);
//@formatter:on
private final boolean myPatient;
public boolean isPatient() {
return myPatient;
}
public boolean isEncounter() {
return myEncounter;
}
public boolean isInstance() {
return myInstance;
}
private final boolean myEncounter;
private final boolean myInstance;
private final boolean myPatient;
private EverythingModeEnum(boolean thePatient, boolean theEncounter, boolean theInstance) {
assert thePatient ^ theEncounter;
myPatient = thePatient;
myEncounter = theEncounter;
myInstance = theInstance;
}
public boolean isEncounter() {
return myEncounter;
}
public boolean isInstance() {
return myInstance;
}
public boolean isPatient() {
return myPatient;
}
}
}

View File

@ -0,0 +1,34 @@
package ca.uhn.fhir.jpa.dao.data;
/*
* #%L
* HAPI FHIR JPA Server
* %%
* Copyright (C) 2014 - 2016 University Health Network
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* #L%
*/
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import ca.uhn.fhir.jpa.entity.TermCodeSystem;
public interface ITermCodeSystemDao extends JpaRepository<TermCodeSystem, Long> {
@Query("SELECT cs FROM TermCodeSystem cs WHERE cs.myCodeSystemUri = :code_system_uri")
TermCodeSystem findByCodeSystemUri(@Param("code_system_uri") String theCodeSystemUri);
}

View File

@ -0,0 +1,34 @@
package ca.uhn.fhir.jpa.dao.data;
/*
* #%L
* HAPI FHIR JPA Server
* %%
* Copyright (C) 2014 - 2016 University Health Network
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* #L%
*/
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import ca.uhn.fhir.jpa.entity.TermCodeSystemVersion;
public interface ITermCodeSystemVersionDao extends JpaRepository<TermCodeSystemVersion, Long> {
@Query("SELECT cs FROM TermCodeSystemVersion cs WHERE cs.myResource.myId = :resource_id AND cs.myResourceVersionId = :version_id")
TermCodeSystemVersion findByCodeSystemResourceAndVersion(@Param("resource_id") Long theCodeSystemResourcePid, @Param("version_id") Long theCodeSystemVersionPid);
}

View File

@ -0,0 +1,35 @@
package ca.uhn.fhir.jpa.dao.data;
/*
* #%L
* HAPI FHIR JPA Server
* %%
* Copyright (C) 2014 - 2016 University Health Network
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* #L%
*/
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import ca.uhn.fhir.jpa.entity.TermCodeSystemVersion;
import ca.uhn.fhir.jpa.entity.TermConcept;
public interface ITermConceptDao extends JpaRepository<TermConcept, Long> {
@Query("SELECT c FROM TermConcept c WHERE c.myCodeSystem = :code_system AND c.myCode = :code")
TermConcept findByCodeSystemAndCode(@Param("code_system") TermCodeSystemVersion theCodeSystem, @Param("code") String theCode);
}

View File

@ -0,0 +1,29 @@
package ca.uhn.fhir.jpa.dao.data;
/*
* #%L
* HAPI FHIR JPA Server
* %%
* Copyright (C) 2014 - 2016 University Health Network
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* #L%
*/
import org.springframework.data.jpa.repository.JpaRepository;
import ca.uhn.fhir.jpa.entity.TermConceptParentChildLink;
public interface ITermConceptParentChildLinkDao extends JpaRepository<TermConceptParentChildLink, Long> {
// nothing
}

View File

@ -50,6 +50,7 @@ import ca.uhn.fhir.model.base.composite.BaseResourceReferenceDt;
import ca.uhn.fhir.rest.api.MethodOutcome;
import ca.uhn.fhir.rest.api.RestOperationTypeEnum;
import ca.uhn.fhir.rest.api.ValidationModeEnum;
import ca.uhn.fhir.rest.method.RequestDetails;
import ca.uhn.fhir.rest.server.EncodingEnum;
import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException;
import ca.uhn.fhir.rest.server.exceptions.PreconditionFailedException;
@ -102,8 +103,8 @@ public class FhirResourceDaoDstu3<T extends IAnyResource> extends BaseHapiFhirRe
}
@Override
public MethodOutcome validate(T theResource, IIdType theId, String theRawResource, EncodingEnum theEncoding, ValidationModeEnum theMode, String theProfile) {
ActionRequestDetails requestDetails = new ActionRequestDetails(theId, null, theResource, getContext());
public MethodOutcome validate(T theResource, IIdType theId, String theRawResource, EncodingEnum theEncoding, ValidationModeEnum theMode, String theProfile, RequestDetails theRequestDetails) {
ActionRequestDetails requestDetails = new ActionRequestDetails(theId, null, theResource, getContext(), theRequestDetails);
notifyInterceptors(RestOperationTypeEnum.VALIDATE, requestDetails);
if (theMode == ValidationModeEnum.DELETE) {

View File

@ -35,6 +35,7 @@ import ca.uhn.fhir.jpa.dao.SearchParameterMap.EverythingModeEnum;
import ca.uhn.fhir.model.api.IResource;
import ca.uhn.fhir.rest.api.RestOperationTypeEnum;
import ca.uhn.fhir.rest.api.SortSpec;
import ca.uhn.fhir.rest.method.RequestDetails;
import ca.uhn.fhir.rest.param.DateRangeParam;
import ca.uhn.fhir.rest.param.StringAndListParam;
import ca.uhn.fhir.rest.param.StringParam;
@ -69,18 +70,18 @@ public class FhirResourceDaoPatientDstu3 extends FhirResourceDaoDstu3<Patient>im
}
@Override
public IBundleProvider patientInstanceEverything(HttpServletRequest theServletRequest, IIdType theId, IPrimitiveType<Integer> theCount, DateRangeParam theLastUpdated, SortSpec theSort, StringAndListParam theContent, StringAndListParam theNarrative) {
public IBundleProvider patientInstanceEverything(HttpServletRequest theServletRequest, IIdType theId, IPrimitiveType<Integer> theCount, DateRangeParam theLastUpdated, SortSpec theSort, StringAndListParam theContent, StringAndListParam theNarrative, RequestDetails theRequestDetails) {
// Notify interceptors
ActionRequestDetails requestDetails = new ActionRequestDetails(null, getResourceName(), getContext());
ActionRequestDetails requestDetails = new ActionRequestDetails(null, getResourceName(), getContext(), theRequestDetails);
notifyInterceptors(RestOperationTypeEnum.EXTENDED_OPERATION_INSTANCE, requestDetails);
return doEverythingOperation(theId, theCount, theLastUpdated, theSort, theContent, theNarrative);
}
@Override
public IBundleProvider patientTypeEverything(HttpServletRequest theServletRequest, IPrimitiveType<Integer> theCount, DateRangeParam theLastUpdated, SortSpec theSort, StringAndListParam theContent, StringAndListParam theNarrative) {
public IBundleProvider patientTypeEverything(HttpServletRequest theServletRequest, IPrimitiveType<Integer> theCount, DateRangeParam theLastUpdated, SortSpec theSort, StringAndListParam theContent, StringAndListParam theNarrative, RequestDetails theRequestDetails) {
// Notify interceptors
ActionRequestDetails requestDetails = new ActionRequestDetails(null, getResourceName(), getContext());
ActionRequestDetails requestDetails = new ActionRequestDetails(null, getResourceName(), getContext(), theRequestDetails);
notifyInterceptors(RestOperationTypeEnum.EXTENDED_OPERATION_TYPE, requestDetails);
return doEverythingOperation(null, theCount, theLastUpdated, theSort, theContent, theNarrative);

View File

@ -34,6 +34,7 @@ import org.springframework.beans.factory.annotation.Qualifier;
import ca.uhn.fhir.jpa.dao.IFhirResourceDao;
import ca.uhn.fhir.jpa.entity.ResourceTable;
import ca.uhn.fhir.rest.method.RequestDetails;
import ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException;
import ca.uhn.fhir.rest.server.exceptions.UnprocessableEntityException;
import ca.uhn.fhir.validation.FhirValidator;
@ -64,8 +65,8 @@ public class FhirResourceDaoQuestionnaireResponseDstu3 extends FhirResourceDaoDs
}
@Override
protected void validateResourceForStorage(QuestionnaireResponse theResource, ResourceTable theEntityToSave) {
super.validateResourceForStorage(theResource, theEntityToSave);
protected void validateResourceForStorage(QuestionnaireResponse theResource, ResourceTable theEntityToSave, RequestDetails theRequestDetails) {
super.validateResourceForStorage(theResource, theEntityToSave, theRequestDetails);
if (!myValidateResponses) {
return;
}
@ -89,6 +90,13 @@ public class FhirResourceDaoQuestionnaireResponseDstu3 extends FhirResourceDaoDs
public class JpaResourceLoader implements IResourceLoader {
private RequestDetails myRequestDetails;
public JpaResourceLoader(RequestDetails theRequestDetails) {
super();
myRequestDetails = theRequestDetails;
}
@Override
public <T extends IBaseResource> T load(Class<T> theType, IIdType theId) throws ResourceNotFoundException {
@ -98,11 +106,11 @@ public class FhirResourceDaoQuestionnaireResponseDstu3 extends FhirResourceDaoDs
*/
if ("ValueSet".equals(theType.getSimpleName())) {
IFhirResourceDao<ValueSet> dao = getDao(ValueSet.class);
ValueSet in = dao.read(theId);
ValueSet in = dao.read(theId, myRequestDetails);
return (T) in;
} else if ("Questionnaire".equals(theType.getSimpleName())) {
IFhirResourceDao<Questionnaire> dao = getDao(Questionnaire.class);
Questionnaire vs = dao.read(theId);
Questionnaire vs = dao.read(theId, myRequestDetails);
return (T) vs;
} else {
// Should not happen, validator will only ask for these two

View File

@ -29,6 +29,8 @@ import org.springframework.scheduling.annotation.Scheduled;
import ca.uhn.fhir.jpa.dao.IFhirResourceDaoSearchParameter;
import ca.uhn.fhir.jpa.dao.IFhirSystemDao;
import ca.uhn.fhir.rest.method.RequestDetails;
import ca.uhn.fhir.rest.server.servlet.ServletRequestDetails;
public class FhirResourceDaoSearchParameterDstu3 extends FhirResourceDaoDstu3<SearchParameter>implements IFhirResourceDaoSearchParameter<SearchParameter> {
@ -48,9 +50,10 @@ public class FhirResourceDaoSearchParameterDstu3 extends FhirResourceDaoDstu3<Se
return;
}
int count = mySystemDao.performReindexingPass(100);
RequestDetails requestDetails = new ServletRequestDetails();
int count = mySystemDao.performReindexingPass(100, requestDetails);
for (int i = 0; i < 50 && count > 0; i++) {
count = mySystemDao.performReindexingPass(100);
count = mySystemDao.performReindexingPass(100, requestDetails);
try {
Thread.sleep(DateUtils.MILLIS_PER_SECOND);
} catch (InterruptedException e) {

View File

@ -64,11 +64,13 @@ import ca.uhn.fhir.model.primitive.InstantDt;
import ca.uhn.fhir.parser.DataFormatException;
import ca.uhn.fhir.rest.api.SortOrderEnum;
import ca.uhn.fhir.rest.api.SortSpec;
import ca.uhn.fhir.rest.method.RequestDetails;
import ca.uhn.fhir.rest.param.DateParam;
import ca.uhn.fhir.rest.param.DateRangeParam;
import ca.uhn.fhir.rest.server.Constants;
import ca.uhn.fhir.rest.server.IBundleProvider;
import ca.uhn.fhir.rest.server.exceptions.UnprocessableEntityException;
import ca.uhn.fhir.rest.server.servlet.ServletRequestDetails;
public class FhirResourceDaoSubscriptionDstu3 extends FhirResourceDaoDstu3<Subscription>implements IFhirResourceDaoSubscription<Subscription> {
@ -255,7 +257,7 @@ public class FhirResourceDaoSubscriptionDstu3 extends FhirResourceDaoDstu3<Subsc
txTemplate.execute(new TransactionCallback<Void>() {
@Override
public Void doInTransaction(TransactionStatus theStatus) {
delete(subscriptionId);
delete(subscriptionId, new ServletRequestDetails());
return null;
}
});
@ -264,8 +266,8 @@ public class FhirResourceDaoSubscriptionDstu3 extends FhirResourceDaoDstu3<Subsc
@Override
protected ResourceTable updateEntity(IBaseResource theResource, ResourceTable theEntity, boolean theUpdateHistory, Date theDeletedTimestampOrNull, boolean thePerformIndexing, boolean theUpdateVersion,
Date theUpdateTime) {
ResourceTable retVal = super.updateEntity(theResource, theEntity, theUpdateHistory, theDeletedTimestampOrNull, thePerformIndexing, theUpdateVersion, theUpdateTime);
Date theUpdateTime, RequestDetails theRequestDetails) {
ResourceTable retVal = super.updateEntity(theResource, theEntity, theUpdateHistory, theDeletedTimestampOrNull, thePerformIndexing, theUpdateVersion, theUpdateTime, theRequestDetails);
Subscription resource = (Subscription) theResource;
Long resourceId = theEntity.getId();
@ -314,8 +316,8 @@ public class FhirResourceDaoSubscriptionDstu3 extends FhirResourceDaoDstu3<Subsc
}
@Override
protected void validateResourceForStorage(Subscription theResource, ResourceTable theEntityToSave) {
super.validateResourceForStorage(theResource, theEntityToSave);
protected void validateResourceForStorage(Subscription theResource, ResourceTable theEntityToSave, RequestDetails theRequestDetails) {
super.validateResourceForStorage(theResource, theEntityToSave, theRequestDetails);
RuntimeResourceDefinition resDef = validateCriteriaAndReturnResourceDefinition(theResource);

View File

@ -54,6 +54,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import ca.uhn.fhir.jpa.dao.IFhirResourceDaoValueSet;
import ca.uhn.fhir.jpa.dao.IFhirResourceDaoValueSet.LookupCodeResult;
import ca.uhn.fhir.jpa.dao.IFhirResourceDaoValueSet.ValidateCodeResult;
import ca.uhn.fhir.rest.method.RequestDetails;
import ca.uhn.fhir.rest.param.TokenParam;
import ca.uhn.fhir.rest.param.UriParam;
import ca.uhn.fhir.rest.server.IBundleProvider;
@ -288,7 +289,7 @@ public class FhirResourceDaoValueSetDstu3 extends FhirResourceDaoDstu3<ValueSet>
}
@Override
public ca.uhn.fhir.jpa.dao.IFhirResourceDaoValueSet.LookupCodeResult lookupCode(IPrimitiveType<String> theCode, IPrimitiveType<String> theSystem, Coding theCoding) {
public ca.uhn.fhir.jpa.dao.IFhirResourceDaoValueSet.LookupCodeResult lookupCode(IPrimitiveType<String> theCode, IPrimitiveType<String> theSystem, Coding theCoding, RequestDetails theRequestDetails) {
boolean haveCoding = theCoding != null && isNotBlank(theCoding.getSystem()) && isNotBlank(theCoding.getCode());
boolean haveCode = theCode != null && theCode.isEmpty() == false;
boolean haveSystem = theSystem != null && theSystem.isEmpty() == false;
@ -349,7 +350,7 @@ public class FhirResourceDaoValueSetDstu3 extends FhirResourceDaoDstu3<ValueSet>
List<IIdType> valueSetIds = findValueSetIdsContainingSystemAndCode(code, system);
for (IIdType nextId : valueSetIds) {
ValueSet expansion = read(nextId);
ValueSet expansion = read(nextId, theRequestDetails);
for (ConceptDefinitionComponent next : expansion.getCodeSystem().getConcept()) {
if (code.equals(next.getCode())) {
ca.uhn.fhir.jpa.dao.IFhirResourceDaoValueSet.LookupCodeResult retVal = new LookupCodeResult();

View File

@ -202,9 +202,9 @@ public class FhirSystemDaoDstu3 extends BaseHapiFhirSystemDao<Bundle, Meta> {
}
@Override
public Meta metaGetOperation() {
public Meta metaGetOperation(RequestDetails theRequestDetails) {
// Notify interceptors
ActionRequestDetails requestDetails = new ActionRequestDetails(null, null, getContext());
ActionRequestDetails requestDetails = new ActionRequestDetails(null, null, getContext(), theRequestDetails);
notifyInterceptors(RestOperationTypeEnum.META, requestDetails);
String sql = "SELECT d FROM TagDefinition d WHERE d.myId IN (SELECT DISTINCT t.myTagId FROM ResourceTag t)";
@ -263,7 +263,7 @@ public class FhirSystemDaoDstu3 extends BaseHapiFhirSystemDao<Bundle, Meta> {
@Transactional(propagation = Propagation.REQUIRED)
@Override
public Bundle transaction(RequestDetails theRequestDetails, Bundle theRequest) {
ActionRequestDetails requestDetails = new ActionRequestDetails(null, "Bundle", theRequest, getContext());
ActionRequestDetails requestDetails = new ActionRequestDetails(null, "Bundle", theRequest, getContext(), theRequestDetails);
notifyInterceptors(RestOperationTypeEnum.TRANSACTION, requestDetails);
String actionName = "Transaction";
@ -389,7 +389,7 @@ public class FhirSystemDaoDstu3 extends BaseHapiFhirSystemDao<Bundle, Meta> {
IFhirResourceDao resourceDao = getDaoOrThrowException(res.getClass());
res.setId((String) null);
DaoMethodOutcome outcome;
outcome = resourceDao.create(res, nextReqEntry.getRequest().getIfNoneExist(), false);
outcome = resourceDao.create(res, nextReqEntry.getRequest().getIfNoneExist(), false, theRequestDetails);
handleTransactionCreateOrUpdateOutcome(idSubstitutions, idToPersistedOutcome, nextResourceId, outcome, nextRespEntry, resourceType, res);
break;
}
@ -400,12 +400,12 @@ public class FhirSystemDaoDstu3 extends BaseHapiFhirSystemDao<Bundle, Meta> {
ca.uhn.fhir.jpa.dao.IFhirResourceDao<? extends IBaseResource> dao = toDao(parts, verb.toCode(), url);
int status = Constants.STATUS_HTTP_204_NO_CONTENT;
if (parts.getResourceId() != null) {
ResourceTable deleted = dao.delete(new IdType(parts.getResourceType(), parts.getResourceId()), deleteConflicts);
ResourceTable deleted = dao.delete(new IdType(parts.getResourceType(), parts.getResourceId()), deleteConflicts, theRequestDetails);
if (deleted != null) {
deletedResources.add(deleted.getIdDt().toUnqualifiedVersionless());
}
} else {
List<ResourceTable> allDeleted = dao.deleteByUrl(parts.getResourceType() + '?' + parts.getParams(), deleteConflicts);
List<ResourceTable> allDeleted = dao.deleteByUrl(parts.getResourceType() + '?' + parts.getParams(), deleteConflicts, theRequestDetails);
for (ResourceTable deleted : allDeleted) {
deletedResources.add(deleted.getIdDt().toUnqualifiedVersionless());
}
@ -429,10 +429,10 @@ public class FhirSystemDaoDstu3 extends BaseHapiFhirSystemDao<Bundle, Meta> {
UrlParts parts = UrlUtil.parseUrl(url);
if (isNotBlank(parts.getResourceId())) {
res.setId(new IdType(parts.getResourceType(), parts.getResourceId()));
outcome = resourceDao.update(res, null, false);
outcome = resourceDao.update(res, null, false, theRequestDetails);
} else {
res.setId((String) null);
outcome = resourceDao.update(res, parts.getResourceType() + '?' + parts.getParams(), false);
outcome = resourceDao.update(res, parts.getResourceType() + '?' + parts.getParams(), false, theRequestDetails);
}
handleTransactionCreateOrUpdateOutcome(idSubstitutions, idToPersistedOutcome, nextResourceId, outcome, nextRespEntry, resourceType, res);
@ -481,7 +481,7 @@ public class FhirSystemDaoDstu3 extends BaseHapiFhirSystemDao<Bundle, Meta> {
IPrimitiveType<Date> deletedInstantOrNull = ResourceMetadataKeyEnum.DELETED_AT.get((IAnyResource) nextResource);
Date deletedTimestampOrNull = deletedInstantOrNull != null ? deletedInstantOrNull.getValue() : null;
updateEntity(nextResource, nextOutcome.getEntity(), false, deletedTimestampOrNull, true, false, updateTime);
updateEntity(nextResource, nextOutcome.getEntity(), false, deletedTimestampOrNull, true, false, updateTime, theRequestDetails);
}
myEntityManager.flush();

View File

@ -25,6 +25,7 @@ import java.io.Serializable;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToOne;
@ -34,24 +35,39 @@ import javax.persistence.UniqueConstraint;
//@formatter:off
@Table(name="TRM_CODESYSTEM", uniqueConstraints= {
@UniqueConstraint(name="IDX_CS_RESOURCEPID", columnNames= {"RES_ID"})
@UniqueConstraint(name="IDX_CS_CODESYSTEM", columnNames= {"CODE_SYSTEM_URI"})
})
@Entity()
//@formatter:on
public class TermCodeSystem implements Serializable {
private static final long serialVersionUID = 1L;
@Id()
@SequenceGenerator(name="SEQ_CODESYSTEM_PID", sequenceName="SEQ_CODESYSTEM_PID")
@GeneratedValue()
@Column(name="PID")
private Long myPid;
@OneToOne()
@JoinColumn(name="RES_ID", referencedColumnName="RES_ID", nullable=false, updatable=false)
private ResourceTable myResource;
@Column(name="RES_VERSION_ID", nullable=false, updatable=false)
private Long myResourceVersionId;
@Column(name="CODE_SYSTEM_URI", nullable=false)
private String myCodeSystemUri;
@Id()
@SequenceGenerator(name = "SEQ_CODESYSTEM_PID", sequenceName = "SEQ_CODESYSTEM_PID")
@GeneratedValue(strategy=GenerationType.AUTO, generator="SEQ_CODESYSTEM_PID")
@Column(name = "PID")
private Long myPid;
@OneToOne()
@JoinColumn(name = "RES_ID", referencedColumnName = "RES_ID", nullable = false, updatable = false)
private ResourceTable myResource;
public String getCodeSystemUri() {
return myCodeSystemUri;
}
public ResourceTable getResource() {
return myResource;
}
public void setCodeSystemUri(String theCodeSystemUri) {
myCodeSystemUri = theCodeSystemUri;
}
public void setResource(ResourceTable theResource) {
myResource = theResource;
}
}

View File

@ -0,0 +1,88 @@
package ca.uhn.fhir.jpa.entity;
/*
* #%L
* HAPI FHIR JPA Server
* %%
* Copyright (C) 2014 - 2016 University Health Network
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* #L%
*/
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;
//@formatter:off
@Table(name="TRM_CODESYSTEM_VER", uniqueConstraints= {
@UniqueConstraint(name="IDX_CSV_RESOURCEPID_AND_VER", columnNames= {"RES_ID", "RES_VERSION_ID"})
})
@Entity()
//@formatter:on
public class TermCodeSystemVersion implements Serializable {
private static final long serialVersionUID = 1L;
@OneToMany(fetch = FetchType.LAZY, mappedBy = "myCodeSystem")
private Collection<TermConcept> myConcepts;
@Id()
@SequenceGenerator(name = "SEQ_CODESYSTEMVER_PID", sequenceName = "SEQ_CODESYSTEMVER_PID")
@GeneratedValue(strategy=GenerationType.AUTO, generator="SEQ_CODESYSTEMVER_PID")
@Column(name = "PID")
private Long myPid;
@OneToOne()
@JoinColumn(name = "RES_ID", referencedColumnName = "RES_ID", nullable = false, updatable = false)
private ResourceTable myResource;
@Column(name = "RES_VERSION_ID", nullable = false, updatable = false)
private Long myResourceVersionId;
public Collection<TermConcept> getConcepts() {
if (myConcepts == null) {
myConcepts = new ArrayList<TermConcept>();
}
return myConcepts;
}
public ResourceTable getResource() {
return myResource;
}
public Long getResourceVersionId() {
return myResourceVersionId;
}
public void setResource(ResourceTable theResource) {
myResource = theResource;
}
public void setResourceVersionId(Long theResourceVersionId) {
myResourceVersionId = theResourceVersionId;
}
}

View File

@ -21,36 +21,138 @@ package ca.uhn.fhir.jpa.entity;
*/
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.ForeignKey;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;
import org.apache.commons.lang3.Validate;
import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;
@Entity
@Table(name="TRM_CONCEPT")
@Table(name="TRM_CONCEPT", uniqueConstraints= {
@UniqueConstraint(name="IDX_CONCEPT_CS_CODE", columnNames= {"CODESYSTEM_PID", "CODE"})
})
public class TermConcept implements Serializable {
private static final long serialVersionUID = 1L;
@Id()
@SequenceGenerator(name="SEQ_CONCEPT_PID", sequenceName="SEQ_CONCEPT_PID")
@GeneratedValue()
@Column(name="PID")
private Long myPid;
@OneToMany(fetch=FetchType.LAZY, mappedBy="myParent")
private Collection<TermConceptParentChildLink> myChildren;
@ManyToOne()
@JoinColumn(name="CODESYSTEM_PID", referencedColumnName="PID", foreignKey=@ForeignKey(name="FK_CONCEPT_PID_CS_PID"))
private TermCodeSystem myCodeSystem;
@Column(name="CODE", length=100, nullable=false)
private String myCode;
@ManyToOne()
@JoinColumn(name="CODESYSTEM_PID", referencedColumnName="PID", foreignKey=@ForeignKey(name="FK_CONCEPT_PID_CS_PID"))
private TermCodeSystemVersion myCodeSystem;
@Column(name="DISPLAY", length=200, nullable=true)
private String myDisplay;
@OneToMany(cascade=CascadeType.ALL, fetch=FetchType.LAZY, mappedBy="myChild")
private Collection<TermConceptParentChildLink> myParents;
@Id()
@SequenceGenerator(name="SEQ_CONCEPT_PID", sequenceName="SEQ_CONCEPT_PID")
@GeneratedValue(strategy=GenerationType.AUTO, generator="SEQ_CONCEPT_PID")
@Column(name="PID")
private Long myPid;
public TermConcept() {
super();
}
public TermConcept(TermCodeSystemVersion theCs, String theCode) {
setCodeSystem(theCs);
setCode(theCode);
}
public TermConcept addChild(TermConcept theChild) {
Validate.notNull(theChild.getCodeSystem(), "theChild.getCodeSystem() must not return null");
TermConceptParentChildLink link = new TermConceptParentChildLink();
link.setParent(this);
link.setCodeSystem(theChild.getCodeSystem());
link.setChild(theChild);
getChildren().add(link);
return this;
}
@Override
public boolean equals(Object theObj) {
if (!(theObj instanceof TermConcept)) {
return false;
}
if (theObj == this) {
return true;
}
TermConcept obj = (TermConcept)theObj;
if (obj.myPid == null) {
return false;
}
EqualsBuilder b = new EqualsBuilder();
b.append(myPid, obj.myPid);
return b.isEquals();
}
public Collection<TermConceptParentChildLink> getChildren() {
if (myChildren == null) {
myChildren = new ArrayList<TermConceptParentChildLink>();
}
return myChildren;
}
public String getCode() {
return myCode;
}
public TermCodeSystemVersion getCodeSystem() {
return myCodeSystem;
}
public String getDisplay() {
return myDisplay;
}
public Collection<TermConceptParentChildLink> getParents() {
if (myParents == null) {
myParents = new ArrayList<TermConceptParentChildLink>();
}
return myParents;
}
@Override
public int hashCode() {
HashCodeBuilder b = new HashCodeBuilder();
b.append(myPid);
return b.toHashCode();
}
public void setCode(String theCode) {
myCode = theCode;
}
public void setCodeSystem(TermCodeSystemVersion theCodeSystem) {
myCodeSystem = theCodeSystem;
}
public void setDisplay(String theDisplay) {
myDisplay = theDisplay;
}
}

View File

@ -24,7 +24,9 @@ import java.io.Serializable;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.ForeignKey;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
@ -32,26 +34,50 @@ import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
@Entity
@Table(name="TRM_CONCEPT")
@Table(name="TRM_CONCEPT_PC_LINK")
public class TermConceptParentChildLink implements Serializable {
private static final long serialVersionUID = 1L;
@ManyToOne()
@JoinColumn(name="CHILD_PID", nullable=false, referencedColumnName="PID", foreignKey=@ForeignKey(name="FK_TERM_CONCEPTPC_CHILD"))
private TermConcept myChild;
@ManyToOne()
@JoinColumn(name="CODESYSTEM_PID", nullable=false, foreignKey=@ForeignKey(name="FK_TERM_CONCEPTPC_CS"))
private TermCodeSystemVersion myCodeSystem;
@ManyToOne()
@JoinColumn(name="PARENT_PID", nullable=false, referencedColumnName="PID", foreignKey=@ForeignKey(name="FK_TERM_CONCEPTPC_PARENT"))
private TermConcept myParent;
@Id()
@SequenceGenerator(name="SEQ_CONCEPT_PC_PID", sequenceName="SEQ_CONCEPT_PC_PID")
@GeneratedValue()
@GeneratedValue(strategy=GenerationType.AUTO, generator="SEQ_CONCEPT_PC_PID")
@Column(name="PID")
private Long myPid;
@ManyToOne
@JoinColumn(name="PARENT_PID", nullable=false)
private TermConcept myParent;
@ManyToOne
@JoinColumn(name="CHILD_PID", nullable=false)
private TermConcept myChild;
public TermConcept getChild() {
return myChild;
}
@ManyToOne
@JoinColumn(name="CODESYSTEM_PID", nullable=false)
private TermCodeSystem myCodeSystem;
public TermCodeSystemVersion getCodeSystem() {
return myCodeSystem;
}
public TermConcept getParent() {
return myParent;
}
public void setChild(TermConcept theChild) {
myChild = theChild;
}
public void setCodeSystem(TermCodeSystemVersion theCodeSystem) {
myCodeSystem = theCodeSystem;
}
public void setParent(TermConcept theParent) {
myParent = theParent;
}
}

View File

@ -35,6 +35,7 @@ import ca.uhn.fhir.rest.annotation.History;
import ca.uhn.fhir.rest.annotation.IdParam;
import ca.uhn.fhir.rest.annotation.Read;
import ca.uhn.fhir.rest.annotation.Since;
import ca.uhn.fhir.rest.method.RequestDetails;
import ca.uhn.fhir.rest.server.IBundleProvider;
import ca.uhn.fhir.rest.server.IResourceProvider;
import ca.uhn.fhir.util.CoverageIgnore;
@ -57,20 +58,20 @@ public abstract class BaseJpaResourceProvider<T extends IBaseResource> extends B
}
@History
public IBundleProvider getHistoryForResourceInstance(HttpServletRequest theRequest, @IdParam IIdType theId, @Since Date theDate) {
public IBundleProvider getHistoryForResourceInstance(HttpServletRequest theRequest, @IdParam IIdType theId, @Since Date theDate, RequestDetails theRequestDetails) {
startRequest(theRequest);
try {
return myDao.history(theId, theDate);
return myDao.history(theId, theDate, theRequestDetails);
} finally {
endRequest(theRequest);
}
}
@History
public IBundleProvider getHistoryForResourceType(HttpServletRequest theRequest, @Since Date theDate) {
public IBundleProvider getHistoryForResourceType(HttpServletRequest theRequest, @Since Date theDate, RequestDetails theRequestDetails) {
startRequest(theRequest);
try {
return myDao.history(theDate);
return myDao.history(theDate, theRequestDetails);
} finally {
endRequest(theRequest);
}
@ -82,30 +83,30 @@ public abstract class BaseJpaResourceProvider<T extends IBaseResource> extends B
}
@GetTags
public TagList getTagsForResourceInstance(HttpServletRequest theRequest, @IdParam IIdType theResourceId) {
public TagList getTagsForResourceInstance(HttpServletRequest theRequest, @IdParam IIdType theResourceId, RequestDetails theRequestDetails) {
startRequest(theRequest);
try {
return myDao.getTags(theResourceId);
return myDao.getTags(theResourceId, theRequestDetails);
} finally {
endRequest(theRequest);
}
}
@GetTags
public TagList getTagsForResourceType(HttpServletRequest theRequest) {
public TagList getTagsForResourceType(HttpServletRequest theRequest, RequestDetails theRequestDetails) {
startRequest(theRequest);
try {
return myDao.getAllResourceTags();
return myDao.getAllResourceTags(theRequestDetails);
} finally {
endRequest(theRequest);
}
}
@Read(version = true)
public T read(HttpServletRequest theRequest, @IdParam IIdType theId) {
public T read(HttpServletRequest theRequest, @IdParam IIdType theId, RequestDetails theRequestDetails) {
startRequest(theRequest);
try {
return myDao.read(theId);
return myDao.read(theId, theRequestDetails);
} finally {
endRequest(theRequest);
}

View File

@ -33,6 +33,7 @@ import ca.uhn.fhir.rest.annotation.Operation;
import ca.uhn.fhir.rest.annotation.OperationParam;
import ca.uhn.fhir.rest.annotation.Sort;
import ca.uhn.fhir.rest.api.SortSpec;
import ca.uhn.fhir.rest.method.RequestDetails;
import ca.uhn.fhir.rest.param.DateRangeParam;
import ca.uhn.fhir.rest.param.StringAndListParam;
import ca.uhn.fhir.rest.param.StringOrListParam;
@ -43,6 +44,7 @@ public class BaseJpaResourceProviderPatientDstu2 extends JpaResourceProviderDstu
/**
* Patient/123/$everything
* @param theRequestDetails
*/
//@formatter:off
@Operation(name = "everything", idempotent = true)
@ -70,13 +72,15 @@ public class BaseJpaResourceProviderPatientDstu2 extends JpaResourceProviderDstu
List<StringDt> theNarrative,
@Sort
SortSpec theSortSpec
SortSpec theSortSpec,
RequestDetails theRequestDetails
) {
//@formatter:on
startRequest(theServletRequest);
try {
return ((IFhirResourceDaoPatient<Patient>) getDao()).patientInstanceEverything(theServletRequest, theId, theCount, theLastUpdated, theSortSpec, toStringAndList(theContent), toStringAndList(theNarrative));
return ((IFhirResourceDaoPatient<Patient>) getDao()).patientInstanceEverything(theServletRequest, theId, theCount, theLastUpdated, theSortSpec, toStringAndList(theContent), toStringAndList(theNarrative), theRequestDetails);
} finally {
endRequest(theServletRequest);
}
@ -84,6 +88,7 @@ public class BaseJpaResourceProviderPatientDstu2 extends JpaResourceProviderDstu
/**
* /Patient/$everything
* @param theRequestDetails
*/
//@formatter:off
@Operation(name = "everything", idempotent = true)
@ -108,13 +113,15 @@ public class BaseJpaResourceProviderPatientDstu2 extends JpaResourceProviderDstu
List<StringDt> theNarrative,
@Sort
SortSpec theSortSpec
SortSpec theSortSpec,
RequestDetails theRequestDetails
) {
//@formatter:on
startRequest(theServletRequest);
try {
return ((IFhirResourceDaoPatient<Patient>) getDao()).patientTypeEverything(theServletRequest, theCount, theLastUpdated, theSortSpec, toStringAndList(theContent), toStringAndList(theNarrative));
return ((IFhirResourceDaoPatient<Patient>) getDao()).patientTypeEverything(theServletRequest, theCount, theLastUpdated, theSortSpec, toStringAndList(theContent), toStringAndList(theNarrative), theRequestDetails);
} finally {
endRequest(theServletRequest);
}

View File

@ -39,6 +39,7 @@ import ca.uhn.fhir.model.primitive.UriDt;
import ca.uhn.fhir.rest.annotation.IdParam;
import ca.uhn.fhir.rest.annotation.Operation;
import ca.uhn.fhir.rest.annotation.OperationParam;
import ca.uhn.fhir.rest.method.RequestDetails;
import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException;
import ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException;
@ -113,14 +114,15 @@ public class BaseJpaResourceProviderValueSetDstu2 extends JpaResourceProviderDst
HttpServletRequest theServletRequest,
@OperationParam(name="code", min=0, max=1) CodeDt theCode,
@OperationParam(name="system", min=0, max=1) UriDt theSystem,
@OperationParam(name="coding", min=0, max=1) CodingDt theCoding
@OperationParam(name="coding", min=0, max=1) CodingDt theCoding,
RequestDetails theRequestDetails
) {
//@formatter:on
startRequest(theServletRequest);
try {
IFhirResourceDaoValueSet<ValueSet, CodingDt, CodeableConceptDt> dao = (IFhirResourceDaoValueSet<ValueSet, CodingDt, CodeableConceptDt>) getDao();
LookupCodeResult result = dao.lookupCode(theCode, theSystem, theCoding);
LookupCodeResult result = dao.lookupCode(theCode, theSystem, theCoding, theRequestDetails);
if (result.isFound()==false) {
throw new ResourceNotFoundException("Unable to find code[" + result.getSearchedForCode() + "] in system[" + result.getSearchedForSystem() + "]");
}

View File

@ -31,6 +31,7 @@ import ca.uhn.fhir.model.api.TagList;
import ca.uhn.fhir.rest.annotation.GetTags;
import ca.uhn.fhir.rest.annotation.History;
import ca.uhn.fhir.rest.annotation.Since;
import ca.uhn.fhir.rest.method.RequestDetails;
import ca.uhn.fhir.rest.server.IBundleProvider;
public class BaseJpaSystemProvider<T, MT> extends BaseJpaProvider {
@ -47,10 +48,10 @@ public class BaseJpaSystemProvider<T, MT> extends BaseJpaProvider {
}
@History
public IBundleProvider historyServer(HttpServletRequest theRequest, @Since Date theDate) {
public IBundleProvider historyServer(HttpServletRequest theRequest, @Since Date theDate, RequestDetails theRequestDetails) {
startRequest(theRequest);
try {
return myDao.history(theDate);
return myDao.history(theDate, theRequestDetails);
} finally {
endRequest(theRequest);
}
@ -61,10 +62,10 @@ public class BaseJpaSystemProvider<T, MT> extends BaseJpaProvider {
}
@GetTags
public TagList getAllTagsOnServer(HttpServletRequest theRequest) {
public TagList getAllTagsOnServer(HttpServletRequest theRequest, RequestDetails theRequestDetails) {
startRequest(theRequest);
try {
return myDao.getAllTags();
return myDao.getAllTags(theRequestDetails);
} finally {
endRequest(theRequest);
}

View File

@ -34,6 +34,7 @@ import ca.uhn.fhir.rest.annotation.ResourceParam;
import ca.uhn.fhir.rest.annotation.Update;
import ca.uhn.fhir.rest.annotation.Validate;
import ca.uhn.fhir.rest.api.MethodOutcome;
import ca.uhn.fhir.rest.method.RequestDetails;
import ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException;
public class JpaResourceProviderDstu1<T extends IResource> extends BaseJpaResourceProvider<T> {
@ -49,35 +50,35 @@ public class JpaResourceProviderDstu1<T extends IResource> extends BaseJpaResour
}
@Create
public MethodOutcome create(HttpServletRequest theRequest, @ResourceParam T theResource) {
public MethodOutcome create(HttpServletRequest theRequest, @ResourceParam T theResource, RequestDetails theRequestDetails) {
startRequest(theRequest);
try {
return getDao().create(theResource);
return getDao().create(theResource, theRequestDetails);
} finally {
endRequest(theRequest);
}
}
@Delete
public MethodOutcome delete(HttpServletRequest theRequest, @IdParam IdDt theResource) {
public MethodOutcome delete(HttpServletRequest theRequest, @IdParam IdDt theResource, RequestDetails theRequestDetails) {
startRequest(theRequest);
try {
return getDao().delete(theResource);
return getDao().delete(theResource, theRequestDetails);
} finally {
endRequest(theRequest);
}
}
@Update
public MethodOutcome update(HttpServletRequest theRequest, @ResourceParam T theResource, @IdParam IdDt theId) {
public MethodOutcome update(HttpServletRequest theRequest, @ResourceParam T theResource, @IdParam IdDt theId, RequestDetails theRequestDetails) {
startRequest(theRequest);
try {
theResource.setId(theId);
return getDao().update(theResource);
return getDao().update(theResource, theRequestDetails);
} catch (ResourceNotFoundException e) {
ourLog.info("Can't update resource with ID[" + theId.getValue() + "] because it doesn't exist, going to create it instead");
theResource.setId(theId);
return getDao().create(theResource);
return getDao().create(theResource, theRequestDetails);
} finally {
endRequest(theRequest);
}

View File

@ -38,8 +38,10 @@ import ca.uhn.fhir.rest.annotation.Update;
import ca.uhn.fhir.rest.annotation.Validate;
import ca.uhn.fhir.rest.api.MethodOutcome;
import ca.uhn.fhir.rest.api.ValidationModeEnum;
import ca.uhn.fhir.rest.method.RequestDetails;
import ca.uhn.fhir.rest.server.EncodingEnum;
import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException;
import ca.uhn.fhir.rest.server.servlet.ServletRequestDetails;
public class JpaResourceProviderDstu2<T extends IResource> extends BaseJpaResourceProvider<T> {
@ -56,13 +58,13 @@ public class JpaResourceProviderDstu2<T extends IResource> extends BaseJpaResour
}
@Create
public MethodOutcome create(HttpServletRequest theRequest, @ResourceParam T theResource, @ConditionalUrlParam String theConditional) {
public MethodOutcome create(HttpServletRequest theRequest, @ResourceParam T theResource, @ConditionalUrlParam String theConditional, RequestDetails theRequestDetails) {
startRequest(theRequest);
try {
if (theConditional != null) {
return getDao().create(theResource, theConditional);
return getDao().create(theResource, theConditional, theRequestDetails);
} else {
return getDao().create(theResource);
return getDao().create(theResource, theRequestDetails);
}
} finally {
endRequest(theRequest);
@ -70,13 +72,13 @@ public class JpaResourceProviderDstu2<T extends IResource> extends BaseJpaResour
}
@Delete()
public MethodOutcome delete(HttpServletRequest theRequest, @IdParam IdDt theResource, @ConditionalUrlParam(supportsMultiple=true) String theConditional) {
public MethodOutcome delete(HttpServletRequest theRequest, @IdParam IdDt theResource, @ConditionalUrlParam(supportsMultiple=true) String theConditional, RequestDetails theRequestDetails) {
startRequest(theRequest);
try {
if (theConditional != null) {
return getDao().deleteByUrl(theConditional);
return getDao().deleteByUrl(theConditional, theRequestDetails);
} else {
return getDao().delete(theResource);
return getDao().delete(theResource, theRequestDetails);
}
} finally {
endRequest(theRequest);
@ -88,9 +90,9 @@ public class JpaResourceProviderDstu2<T extends IResource> extends BaseJpaResour
@OperationParam(name="return", type=MetaDt.class)
})
//@formatter:on
public Parameters meta() {
public Parameters meta(RequestDetails theRequestDetails) {
Parameters parameters = new Parameters();
MetaDt metaGetOperation = getDao().metaGetOperation(MetaDt.class);
MetaDt metaGetOperation = getDao().metaGetOperation(MetaDt.class, theRequestDetails);
parameters.addParameter().setName("return").setValue(metaGetOperation);
return parameters;
}
@ -100,9 +102,9 @@ public class JpaResourceProviderDstu2<T extends IResource> extends BaseJpaResour
@OperationParam(name="return", type=MetaDt.class)
})
//@formatter:on
public Parameters meta(@IdParam IdDt theId) {
public Parameters meta(@IdParam IdDt theId, RequestDetails theRequestDetails) {
Parameters parameters = new Parameters();
MetaDt metaGetOperation = getDao().metaGetOperation(MetaDt.class, theId);
MetaDt metaGetOperation = getDao().metaGetOperation(MetaDt.class, theId, theRequestDetails);
parameters.addParameter().setName("return").setValue(metaGetOperation);
return parameters;
}
@ -112,12 +114,12 @@ public class JpaResourceProviderDstu2<T extends IResource> extends BaseJpaResour
@OperationParam(name="return", type=MetaDt.class)
})
//@formatter:on
public Parameters metaAdd(@IdParam IdDt theId, @OperationParam(name = "meta") MetaDt theMeta) {
public Parameters metaAdd(@IdParam IdDt theId, @OperationParam(name = "meta") MetaDt theMeta, RequestDetails theRequestDetails) {
if (theMeta == null) {
throw new InvalidRequestException("Input contains no parameter with name 'meta'");
}
Parameters parameters = new Parameters();
MetaDt metaAddOperation = getDao().metaAddOperation(theId, theMeta);
MetaDt metaAddOperation = getDao().metaAddOperation(theId, theMeta, theRequestDetails);
parameters.addParameter().setName("return").setValue(metaAddOperation);
return parameters;
}
@ -127,24 +129,24 @@ public class JpaResourceProviderDstu2<T extends IResource> extends BaseJpaResour
@OperationParam(name="return", type=MetaDt.class)
})
//@formatter:on
public Parameters metaDelete(@IdParam IdDt theId, @OperationParam(name = "meta") MetaDt theMeta) {
public Parameters metaDelete(@IdParam IdDt theId, @OperationParam(name = "meta") MetaDt theMeta, RequestDetails theRequestDetails) {
if (theMeta == null) {
throw new InvalidRequestException("Input contains no parameter with name 'meta'");
}
Parameters parameters = new Parameters();
parameters.addParameter().setName("return").setValue(getDao().metaDeleteOperation(theId, theMeta));
parameters.addParameter().setName("return").setValue(getDao().metaDeleteOperation(theId, theMeta, theRequestDetails));
return parameters;
}
@Update
public MethodOutcome update(HttpServletRequest theRequest, @ResourceParam T theResource, @IdParam IdDt theId, @ConditionalUrlParam String theConditional) {
public MethodOutcome update(HttpServletRequest theRequest, @ResourceParam T theResource, @IdParam IdDt theId, @ConditionalUrlParam String theConditional, RequestDetails theRequestDetails) {
startRequest(theRequest);
try {
if (theConditional != null) {
return getDao().update(theResource, theConditional);
return getDao().update(theResource, theConditional, theRequestDetails);
} else {
theResource.setId(theId);
return getDao().update(theResource);
return getDao().update(theResource, theRequestDetails);
}
} finally {
endRequest(theRequest);
@ -153,14 +155,14 @@ public class JpaResourceProviderDstu2<T extends IResource> extends BaseJpaResour
@Validate
public MethodOutcome validate(@ResourceParam T theResource, @ResourceParam String theRawResource, @ResourceParam EncodingEnum theEncoding, @Validate.Mode ValidationModeEnum theMode,
@Validate.Profile String theProfile) {
return validate(theResource, null, theRawResource, theEncoding, theMode, theProfile);
@Validate.Profile String theProfile, RequestDetails theRequestDetails) {
return validate(theResource, null, theRawResource, theEncoding, theMode, theProfile, theRequestDetails);
}
@Validate
public MethodOutcome validate(@ResourceParam T theResource, @IdParam IdDt theId, @ResourceParam String theRawResource, @ResourceParam EncodingEnum theEncoding, @Validate.Mode ValidationModeEnum theMode,
@Validate.Profile String theProfile) {
return getDao().validate(theResource, theId, theRawResource, theEncoding, theMode, theProfile);
@Validate.Profile String theProfile, RequestDetails theRequestDetails) {
return getDao().validate(theResource, theId, theRawResource, theEncoding, theMode, theProfile, theRequestDetails);
}
}

View File

@ -187,9 +187,9 @@ public class JpaSystemProviderDstu2 extends BaseJpaSystemProvider<Bundle, MetaDt
@OperationParam(name="return", type=MetaDt.class)
})
//@formatter:on
public Parameters meta() {
public Parameters meta(RequestDetails theRequestDetails) {
Parameters parameters = new Parameters();
parameters.addParameter().setName("return").setValue(getDao().metaGetOperation());
parameters.addParameter().setName("return").setValue(getDao().metaGetOperation(theRequestDetails));
return parameters;
}

View File

@ -36,6 +36,7 @@ import ca.uhn.fhir.rest.annotation.Operation;
import ca.uhn.fhir.rest.annotation.OperationParam;
import ca.uhn.fhir.rest.annotation.Sort;
import ca.uhn.fhir.rest.api.SortSpec;
import ca.uhn.fhir.rest.method.RequestDetails;
import ca.uhn.fhir.rest.param.DateRangeParam;
import ca.uhn.fhir.rest.param.StringAndListParam;
import ca.uhn.fhir.rest.param.StringOrListParam;
@ -46,6 +47,7 @@ public class BaseJpaResourceProviderPatientDstu3 extends JpaResourceProviderDstu
/**
* Patient/123/$everything
* @param theRequestDetails
*/
//@formatter:off
@Operation(name = "everything", idempotent = true)
@ -73,13 +75,15 @@ public class BaseJpaResourceProviderPatientDstu3 extends JpaResourceProviderDstu
List<StringType> theNarrative,
@Sort
SortSpec theSortSpec
SortSpec theSortSpec,
RequestDetails theRequestDetails
) {
//@formatter:on
startRequest(theServletRequest);
try {
return ((IFhirResourceDaoPatient<Patient>) getDao()).patientInstanceEverything(theServletRequest, theId, theCount, theLastUpdated, theSortSpec, toStringAndList(theContent), toStringAndList(theNarrative));
return ((IFhirResourceDaoPatient<Patient>) getDao()).patientInstanceEverything(theServletRequest, theId, theCount, theLastUpdated, theSortSpec, toStringAndList(theContent), toStringAndList(theNarrative), theRequestDetails);
} finally {
endRequest(theServletRequest);
}
@ -87,6 +91,7 @@ public class BaseJpaResourceProviderPatientDstu3 extends JpaResourceProviderDstu
/**
* /Patient/$everything
* @param theRequestDetails
*/
//@formatter:off
@Operation(name = "everything", idempotent = true)
@ -111,13 +116,15 @@ public class BaseJpaResourceProviderPatientDstu3 extends JpaResourceProviderDstu
List<StringType> theNarrative,
@Sort
SortSpec theSortSpec
SortSpec theSortSpec,
RequestDetails theRequestDetails
) {
//@formatter:on
startRequest(theServletRequest);
try {
return ((IFhirResourceDaoPatient<Patient>) getDao()).patientTypeEverything(theServletRequest, theCount, theLastUpdated, theSortSpec, toStringAndList(theContent), toStringAndList(theNarrative));
return ((IFhirResourceDaoPatient<Patient>) getDao()).patientTypeEverything(theServletRequest, theCount, theLastUpdated, theSortSpec, toStringAndList(theContent), toStringAndList(theNarrative), theRequestDetails);
} finally {
endRequest(theServletRequest);
}

View File

@ -40,6 +40,7 @@ import ca.uhn.fhir.jpa.dao.IFhirResourceDaoValueSet.ValidateCodeResult;
import ca.uhn.fhir.rest.annotation.IdParam;
import ca.uhn.fhir.rest.annotation.Operation;
import ca.uhn.fhir.rest.annotation.OperationParam;
import ca.uhn.fhir.rest.method.RequestDetails;
import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException;
import ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException;
@ -114,14 +115,15 @@ public class BaseJpaResourceProviderValueSetDstu3 extends JpaResourceProviderDst
HttpServletRequest theServletRequest,
@OperationParam(name="code", min=0, max=1) CodeType theCode,
@OperationParam(name="system", min=0, max=1) UriType theSystem,
@OperationParam(name="coding", min=0, max=1) Coding theCoding
@OperationParam(name="coding", min=0, max=1) Coding theCoding,
RequestDetails theRequestDetails
) {
//@formatter:on
startRequest(theServletRequest);
try {
IFhirResourceDaoValueSet<ValueSet, Coding, CodeableConcept> dao = (IFhirResourceDaoValueSet<ValueSet, Coding, CodeableConcept>) getDao();
LookupCodeResult result = dao.lookupCode(theCode, theSystem, theCoding);
LookupCodeResult result = dao.lookupCode(theCode, theSystem, theCoding, theRequestDetails);
if (result.isFound()==false) {
throw new ResourceNotFoundException("Unable to find code[" + result.getSearchedForCode() + "] in system[" + result.getSearchedForSystem() + "]");
}

View File

@ -40,6 +40,7 @@ import ca.uhn.fhir.rest.annotation.Update;
import ca.uhn.fhir.rest.annotation.Validate;
import ca.uhn.fhir.rest.api.MethodOutcome;
import ca.uhn.fhir.rest.api.ValidationModeEnum;
import ca.uhn.fhir.rest.method.RequestDetails;
import ca.uhn.fhir.rest.server.EncodingEnum;
import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException;
@ -58,13 +59,13 @@ public class JpaResourceProviderDstu3<T extends IAnyResource> extends BaseJpaRes
}
@Create
public MethodOutcome create(HttpServletRequest theRequest, @ResourceParam T theResource, @ConditionalUrlParam String theConditional) {
public MethodOutcome create(HttpServletRequest theRequest, @ResourceParam T theResource, @ConditionalUrlParam String theConditional, RequestDetails theRequestDetails) {
startRequest(theRequest);
try {
if (theConditional != null) {
return getDao().create(theResource, theConditional);
return getDao().create(theResource, theConditional, theRequestDetails);
} else {
return getDao().create(theResource);
return getDao().create(theResource, theRequestDetails);
}
} finally {
endRequest(theRequest);
@ -72,13 +73,13 @@ public class JpaResourceProviderDstu3<T extends IAnyResource> extends BaseJpaRes
}
@Delete()
public MethodOutcome delete(HttpServletRequest theRequest, @IdParam IdType theResource, @ConditionalUrlParam(supportsMultiple=true) String theConditional) {
public MethodOutcome delete(HttpServletRequest theRequest, @IdParam IdType theResource, @ConditionalUrlParam(supportsMultiple=true) String theConditional, RequestDetails theRequestDetails) {
startRequest(theRequest);
try {
if (theConditional != null) {
return getDao().deleteByUrl(theConditional);
return getDao().deleteByUrl(theConditional, theRequestDetails);
} else {
return getDao().delete(theResource);
return getDao().delete(theResource, theRequestDetails);
}
} finally {
endRequest(theRequest);
@ -90,9 +91,9 @@ public class JpaResourceProviderDstu3<T extends IAnyResource> extends BaseJpaRes
@OperationParam(name="return", type=Meta.class)
})
//@formatter:on
public Parameters meta() {
public Parameters meta(RequestDetails theRequestDetails) {
Parameters parameters = new Parameters();
Meta metaGetOperation = getDao().metaGetOperation(Meta.class);
Meta metaGetOperation = getDao().metaGetOperation(Meta.class, theRequestDetails);
parameters.addParameter().setName("return").setValue(metaGetOperation);
return parameters;
}
@ -102,9 +103,9 @@ public class JpaResourceProviderDstu3<T extends IAnyResource> extends BaseJpaRes
@OperationParam(name="return", type=Meta.class)
})
//@formatter:on
public Parameters meta(@IdParam IdType theId) {
public Parameters meta(@IdParam IdType theId, RequestDetails theRequestDetails) {
Parameters parameters = new Parameters();
Meta metaGetOperation = getDao().metaGetOperation(Meta.class, theId);
Meta metaGetOperation = getDao().metaGetOperation(Meta.class, theId, theRequestDetails);
parameters.addParameter().setName("return").setValue(metaGetOperation);
return parameters;
}
@ -114,12 +115,12 @@ public class JpaResourceProviderDstu3<T extends IAnyResource> extends BaseJpaRes
@OperationParam(name="return", type=Meta.class)
})
//@formatter:on
public Parameters metaAdd(@IdParam IdType theId, @OperationParam(name = "meta") Meta theMeta) {
public Parameters metaAdd(@IdParam IdType theId, @OperationParam(name = "meta") Meta theMeta, RequestDetails theRequestDetails) {
if (theMeta == null) {
throw new InvalidRequestException("Input contains no parameter with name 'meta'");
}
Parameters parameters = new Parameters();
Meta metaAddOperation = getDao().metaAddOperation(theId, theMeta);
Meta metaAddOperation = getDao().metaAddOperation(theId, theMeta, theRequestDetails);
parameters.addParameter().setName("return").setValue(metaAddOperation);
return parameters;
}
@ -129,24 +130,24 @@ public class JpaResourceProviderDstu3<T extends IAnyResource> extends BaseJpaRes
@OperationParam(name="return", type=Meta.class)
})
//@formatter:on
public Parameters metaDelete(@IdParam IdType theId, @OperationParam(name = "meta") Meta theMeta) {
public Parameters metaDelete(@IdParam IdType theId, @OperationParam(name = "meta") Meta theMeta, RequestDetails theRequestDetails) {
if (theMeta == null) {
throw new InvalidRequestException("Input contains no parameter with name 'meta'");
}
Parameters parameters = new Parameters();
parameters.addParameter().setName("return").setValue(getDao().metaDeleteOperation(theId, theMeta));
parameters.addParameter().setName("return").setValue(getDao().metaDeleteOperation(theId, theMeta, theRequestDetails));
return parameters;
}
@Update
public MethodOutcome update(HttpServletRequest theRequest, @ResourceParam T theResource, @IdParam IdType theId, @ConditionalUrlParam String theConditional) {
public MethodOutcome update(HttpServletRequest theRequest, @ResourceParam T theResource, @IdParam IdType theId, @ConditionalUrlParam String theConditional, RequestDetails theRequestDetails) {
startRequest(theRequest);
try {
if (theConditional != null) {
return getDao().update(theResource, theConditional);
return getDao().update(theResource, theConditional, theRequestDetails);
} else {
theResource.setId(theId);
return getDao().update(theResource);
return getDao().update(theResource, theRequestDetails);
}
} finally {
endRequest(theRequest);
@ -155,14 +156,14 @@ public class JpaResourceProviderDstu3<T extends IAnyResource> extends BaseJpaRes
@Validate
public MethodOutcome validate(@ResourceParam T theResource, @ResourceParam String theRawResource, @ResourceParam EncodingEnum theEncoding, @Validate.Mode ValidationModeEnum theMode,
@Validate.Profile String theProfile) {
return validate(theResource, null, theRawResource, theEncoding, theMode, theProfile);
@Validate.Profile String theProfile, RequestDetails theRequestDetails) {
return validate(theResource, null, theRawResource, theEncoding, theMode, theProfile, theRequestDetails);
}
@Validate
public MethodOutcome validate(@ResourceParam T theResource, @IdParam IdType theId, @ResourceParam String theRawResource, @ResourceParam EncodingEnum theEncoding, @Validate.Mode ValidationModeEnum theMode,
@Validate.Profile String theProfile) {
return getDao().validate(theResource, theId, theRawResource, theEncoding, theMode, theProfile);
@Validate.Profile String theProfile, RequestDetails theRequestDetails) {
return getDao().validate(theResource, theId, theRawResource, theEncoding, theMode, theProfile, theRequestDetails);
}
}

View File

@ -189,9 +189,9 @@ public class JpaSystemProviderDstu3 extends BaseJpaSystemProvider<Bundle, Meta>
@OperationParam(name="return", type=Meta.class)
})
//@formatter:on
public Parameters meta() {
public Parameters meta(RequestDetails theRequestDetails) {
Parameters parameters = new Parameters();
parameters.addParameter().setName("return").setValue(getDao().metaGetOperation());
parameters.addParameter().setName("return").setValue(getDao().metaGetOperation(theRequestDetails));
return parameters;
}

View File

@ -49,6 +49,7 @@ import ca.uhn.fhir.rest.server.Constants;
import ca.uhn.fhir.rest.server.EncodingEnum;
import ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException;
import ca.uhn.fhir.rest.server.exceptions.UnprocessableEntityException;
import ca.uhn.fhir.rest.server.servlet.ServletRequestDetails;
public class SubscriptionWebsocketHandlerDstu2 extends TextWebSocketHandler implements ISubscriptionWebsocketHandler, Runnable {
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(SubscriptionWebsocketHandlerDstu2.class);
@ -145,7 +146,7 @@ public class SubscriptionWebsocketHandlerDstu2 extends TextWebSocketHandler impl
public void closing() {
ourLog.info("Deleting subscription {}", mySubscriptionId);
try {
mySubscriptionDao.delete(mySubscriptionId);
mySubscriptionDao.delete(mySubscriptionId, new ServletRequestDetails());
} catch (Exception e) {
handleFailure(e);
}
@ -232,7 +233,7 @@ public class SubscriptionWebsocketHandlerDstu2 extends TextWebSocketHandler impl
}
try {
Subscription subscription = mySubscriptionDao.read(id);
Subscription subscription = mySubscriptionDao.read(id, new ServletRequestDetails());
mySubscriptionPid = mySubscriptionDao.getSubscriptionTablePidForSubscriptionResource(id);
mySubscriptionId = subscription.getIdElement();
myState = new BoundStaticSubscipriptionState(theSession);
@ -269,7 +270,7 @@ public class SubscriptionWebsocketHandlerDstu2 extends TextWebSocketHandler impl
}
}
IIdType id = mySubscriptionDao.create(subscription).getId();
IIdType id = mySubscriptionDao.create(subscription, new ServletRequestDetails()).getId();
mySubscriptionPid = mySubscriptionDao.getSubscriptionTablePidForSubscriptionResource(id);
mySubscriptionId = subscription.getIdElement();

View File

@ -49,6 +49,7 @@ import ca.uhn.fhir.rest.server.Constants;
import ca.uhn.fhir.rest.server.EncodingEnum;
import ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException;
import ca.uhn.fhir.rest.server.exceptions.UnprocessableEntityException;
import ca.uhn.fhir.rest.server.servlet.ServletRequestDetails;
public class SubscriptionWebsocketHandlerDstu3 extends TextWebSocketHandler implements ISubscriptionWebsocketHandler, Runnable {
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(SubscriptionWebsocketHandlerDstu3.class);
@ -145,7 +146,7 @@ public class SubscriptionWebsocketHandlerDstu3 extends TextWebSocketHandler impl
public void closing() {
ourLog.info("Deleting subscription {}", mySubscriptionId);
try {
mySubscriptionDao.delete(mySubscriptionId);
mySubscriptionDao.delete(mySubscriptionId, new ServletRequestDetails());
} catch (Exception e) {
handleFailure(e);
}
@ -232,7 +233,7 @@ public class SubscriptionWebsocketHandlerDstu3 extends TextWebSocketHandler impl
}
try {
Subscription subscription = mySubscriptionDao.read(id);
Subscription subscription = mySubscriptionDao.read(id, new ServletRequestDetails());
mySubscriptionPid = mySubscriptionDao.getSubscriptionTablePidForSubscriptionResource(id);
mySubscriptionId = subscription.getIdElement();
myState = new BoundStaticSubscipriptionState(theSession);
@ -269,7 +270,7 @@ public class SubscriptionWebsocketHandlerDstu3 extends TextWebSocketHandler impl
}
}
IIdType id = mySubscriptionDao.create(subscription).getId();
IIdType id = mySubscriptionDao.create(subscription, new ServletRequestDetails()).getId();
mySubscriptionPid = mySubscriptionDao.getSubscriptionTablePidForSubscriptionResource(id);
mySubscriptionId = subscription.getIdElement();

View File

@ -1,5 +1,14 @@
package ca.uhn.fhir.jpa.term;
import java.util.Set;
import ca.uhn.fhir.jpa.entity.TermCodeSystemVersion;
import ca.uhn.fhir.jpa.entity.TermConcept;
public interface ITerminologySvc {
void storeNewCodeSystemVersion(String theSystemUri, TermCodeSystemVersion theCodeSytem);
Set<TermConcept> findCodesBelow(Long theCodeSystemResourcePid, Long theCodeSystemResourceVersion, String theCode);
}

View File

@ -1,6 +1,136 @@
package ca.uhn.fhir.jpa.term;
import java.util.HashSet;
import java.util.IdentityHashMap;
import java.util.Set;
import javax.transaction.Transactional;
import javax.transaction.Transactional.TxType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.ValidationUtils;
import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.jpa.dao.data.ITermCodeSystemDao;
import ca.uhn.fhir.jpa.dao.data.ITermCodeSystemVersionDao;
import ca.uhn.fhir.jpa.dao.data.ITermConceptDao;
import ca.uhn.fhir.jpa.dao.data.ITermConceptParentChildLinkDao;
import ca.uhn.fhir.jpa.entity.TermCodeSystem;
import ca.uhn.fhir.jpa.entity.TermCodeSystemVersion;
import ca.uhn.fhir.jpa.entity.TermConcept;
import ca.uhn.fhir.jpa.entity.TermConceptParentChildLink;
import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException;
import ca.uhn.fhir.util.ObjectUtil;
import ca.uhn.fhir.util.ValidateUtil;
public class TerminologySvcImpl implements ITerminologySvc {
private static final Object PLACEHOLDER_OBJECT = new Object();
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(TerminologySvcImpl.class);
@Autowired
private ITermCodeSystemVersionDao myCodeSystemVersionDao;
@Autowired
private ITermConceptParentChildLinkDao myConceptParentChildLinkDao;
@Autowired
private ITermConceptDao myConceptDao;
@Autowired
private ITermCodeSystemDao myCodeSystemDao;
@Autowired
private FhirContext myContext;
@Override
@Transactional(value=TxType.REQUIRED)
public void storeNewCodeSystemVersion(String theSystemUri, TermCodeSystemVersion theCodeSystem) {
ourLog.info("Storing code system");
ValidateUtil.isNotNullOrThrowInvalidRequest(theCodeSystem.getResource() != null, "No resource supplied");
ValidateUtil.isNotBlankOrThrowInvalidRequest(theSystemUri, "No system URI supplied");
TermCodeSystem codeSystem = myCodeSystemDao.findByCodeSystemUri(theSystemUri);
if (codeSystem == null) {
TermCodeSystem newCodeSystem = new TermCodeSystem();
newCodeSystem.setResource(theCodeSystem.getResource());
newCodeSystem.setCodeSystemUri(theSystemUri);
myCodeSystemDao.save(newCodeSystem);
} else {
if (!ObjectUtil.equals(codeSystem.getResource().getId(), theCodeSystem.getResource().getId())) {
throw new InvalidRequestException(myContext.getLocalizer().getMessage(TerminologySvcImpl.class, "cannotCreateDuplicateCodeSystemUri", theSystemUri, codeSystem.getResource().getIdDt().getValue()));
}
}
// Validate the code system
IdentityHashMap<TermConcept, Object> conceptsStack = new IdentityHashMap<TermConcept, Object>();
for (TermConcept next : theCodeSystem.getConcepts()) {
validateConceptForStorage(next, theCodeSystem, conceptsStack);
}
myCodeSystemVersionDao.save(theCodeSystem);
conceptsStack = new IdentityHashMap<TermConcept, Object>();
for (TermConcept next : theCodeSystem.getConcepts()) {
persistChildren(next, theCodeSystem, conceptsStack);
}
}
private void persistChildren(TermConcept theConcept, TermCodeSystemVersion theCodeSystem, IdentityHashMap<TermConcept, Object> theConceptsStack) {
if (theConceptsStack.put(theConcept, PLACEHOLDER_OBJECT) != null) {
return;
}
for (TermConceptParentChildLink next : theConcept.getChildren()) {
persistChildren(next.getChild(), theCodeSystem, theConceptsStack);
}
myConceptDao.save(theConcept);
for (TermConceptParentChildLink next : theConcept.getChildren()) {
myConceptParentChildLinkDao.save(next);
}
}
private void validateConceptForStorage(TermConcept theConcept, TermCodeSystemVersion theCodeSystem, IdentityHashMap<TermConcept, Object> theConceptsStack) {
ValidateUtil.isNotNullOrThrowInvalidRequest(theConcept.getCodeSystem() == theCodeSystem, "Codesystem contains a code which does not reference the codesystem");
ValidateUtil.isNotBlankOrThrowInvalidRequest(theConcept.getCode(), "Codesystem contains a code which does not reference the codesystem");
if (theConceptsStack.put(theConcept, PLACEHOLDER_OBJECT) != null) {
throw new InvalidRequestException("CodeSystem contains circular reference around code " + theConcept.getCode());
}
for (TermConceptParentChildLink next : theConcept.getChildren()) {
validateConceptForStorage(next.getChild(), theCodeSystem, theConceptsStack);
}
theConceptsStack.remove(theConcept);
}
@Transactional(value=TxType.REQUIRED)
@Override
public Set<TermConcept> findCodesBelow(Long theCodeSystemResourcePid, Long theCodeSystemVersionPid, String theCode) {
TermCodeSystemVersion codeSystem = myCodeSystemVersionDao.findByCodeSystemResourceAndVersion(theCodeSystemResourcePid, theCodeSystemVersionPid);
TermConcept concept = myConceptDao.findByCodeSystemAndCode(codeSystem, theCode);
Set<TermConcept> retVal = new HashSet<TermConcept>();
retVal.add(concept);
fetchChildren(concept, retVal);
return retVal;
}
private void fetchChildren(TermConcept theConcept, Set<TermConcept> theSetToPopulate) {
for (TermConceptParentChildLink nextChildLink : theConcept.getChildren()) {
TermConcept nextChild = nextChildLink.getChild();
if (theSetToPopulate.add(nextChild)) {
fetchChildren(nextChild, theSetToPopulate);
}
}
}

View File

@ -37,6 +37,7 @@ import ca.uhn.fhir.rest.api.RestOperationTypeEnum;
import ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException;
import ca.uhn.fhir.rest.server.exceptions.UnprocessableEntityException;
import ca.uhn.fhir.rest.server.interceptor.InterceptorAdapter;
import ca.uhn.fhir.rest.server.servlet.ServletRequestDetails;
import ca.uhn.fhir.util.CoverageIgnore;
/**
@ -100,7 +101,7 @@ public class SubscriptionsRequireManualActivationInterceptorDstu2 extends Interc
if (requestId != null && requestId.hasIdPart()) {
Subscription existing;
try {
existing = myDao.read(requestId);
existing = myDao.read(requestId, new ServletRequestDetails());
SubscriptionStatusEnum existingStatus = existing.getStatusElement().getValueAsEnum();
if (existingStatus != newStatus) {
verifyActiveStatus(subscription, newStatus, existingStatus);

View File

@ -38,6 +38,7 @@ import ca.uhn.fhir.rest.api.RestOperationTypeEnum;
import ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException;
import ca.uhn.fhir.rest.server.exceptions.UnprocessableEntityException;
import ca.uhn.fhir.rest.server.interceptor.InterceptorAdapter;
import ca.uhn.fhir.rest.server.servlet.ServletRequestDetails;
import ca.uhn.fhir.util.CoverageIgnore;
/**
@ -101,7 +102,7 @@ public class SubscriptionsRequireManualActivationInterceptorDstu3 extends Interc
if (requestId != null && requestId.hasIdPart()) {
Subscription existing;
try {
existing = myDao.read(requestId);
existing = myDao.read(requestId, new ServletRequestDetails());
SubscriptionStatus existingStatus = existing.getStatusElement().getValue();
if (existingStatus != newStatus) {
verifyActiveStatus(subscription, newStatus, existingStatus);

View File

@ -1,24 +1,19 @@
package ca.uhn.fhir.jpa.dao;
import static org.hamcrest.Matchers.containsInAnyOrder;
import static org.hamcrest.Matchers.containsString;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.fail;
import java.util.List;
import org.hamcrest.core.StringContains;
import org.hl7.fhir.instance.model.api.IIdType;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.jpa.config.TestDstu1Config;
import ca.uhn.fhir.jpa.config.TestDstu2Config;
import ca.uhn.fhir.model.dstu.composite.ResourceReferenceDt;
import ca.uhn.fhir.model.dstu.resource.Device;
import ca.uhn.fhir.model.dstu.resource.DiagnosticReport;
@ -28,11 +23,10 @@ import ca.uhn.fhir.model.dstu.resource.Observation;
import ca.uhn.fhir.model.dstu.resource.Organization;
import ca.uhn.fhir.model.dstu.resource.Patient;
import ca.uhn.fhir.model.primitive.IdDt;
import ca.uhn.fhir.model.primitive.StringDt;
import ca.uhn.fhir.rest.server.Constants;
import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException;
import ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException;
import ca.uhn.fhir.rest.server.exceptions.UnprocessableEntityException;
import ca.uhn.fhir.rest.server.servlet.ServletRequestDetails;
@SuppressWarnings("unused")
public class FhirResourceDaoDstu1Test extends BaseJpaTest {
@ -55,7 +49,7 @@ public class FhirResourceDaoDstu1Test extends BaseJpaTest {
Patient p = new Patient();
p.addIdentifier().setSystem("urn:system").setValue(methodName);
p.setId("Patient/" + methodName);
IIdType id = ourPatientDao.create(p).getId();
IIdType id = ourPatientDao.create(p, new ServletRequestDetails()).getId();
ourLog.info("Created patient, got it: {}", id);
p = new Patient();
@ -63,7 +57,7 @@ public class FhirResourceDaoDstu1Test extends BaseJpaTest {
p.addName().addFamily("Hello");
p.setId("Patient/" + methodName);
try {
ourPatientDao.create(p);
ourPatientDao.create(p, new ServletRequestDetails());
fail();
} catch (UnprocessableEntityException e) {
assertThat(e.getMessage(), containsString("Can not create entity with ID[" + methodName + "], a resource with this ID already exists"));
@ -77,7 +71,7 @@ public class FhirResourceDaoDstu1Test extends BaseJpaTest {
p.addName().addFamily("Hello");
p.setId("Patient/123");
try {
ourPatientDao.create(p);
ourPatientDao.create(p, new ServletRequestDetails());
fail();
} catch (InvalidRequestException e) {
assertThat(e.getMessage(), containsString("clients may only assign IDs which contain at least one non-numeric"));
@ -90,7 +84,7 @@ public class FhirResourceDaoDstu1Test extends BaseJpaTest {
patient.addName().addFamily("testSearchResourceLinkWithChainWithMultipleTypes01");
patient.setManagingOrganization(new ResourceReferenceDt("Patient/99999999"));
try {
ourPatientDao.create(patient);
ourPatientDao.create(patient, new ServletRequestDetails());
fail();
} catch (InvalidRequestException e) {
assertThat(e.getMessage(), StringContains.containsString("99999 not found"));
@ -104,17 +98,17 @@ public class FhirResourceDaoDstu1Test extends BaseJpaTest {
p1.addIdentifier().setSystem("urn:system").setValue("testUpdateRejectsIdWhichPointsToForcedId01");
p1.addName().addFamily("Tester").addGiven("testUpdateRejectsIdWhichPointsToForcedId01");
p1.setId("ABABA");
IIdType p1id = ourPatientDao.create(p1).getId();
IIdType p1id = ourPatientDao.create(p1, new ServletRequestDetails()).getId();
assertEquals("ABABA", p1id.getIdPart());
Patient p2 = new Patient();
p2.addIdentifier().setSystem("urn:system").setValue("testUpdateRejectsIdWhichPointsToForcedId02");
p2.addName().addFamily("Tester").addGiven("testUpdateRejectsIdWhichPointsToForcedId02");
IIdType p2id = ourPatientDao.create(p2).getId();
IIdType p2id = ourPatientDao.create(p2, new ServletRequestDetails()).getId();
long p1longId = p2id.getIdPartAsLong() - 1;
try {
ourPatientDao.read(new IdDt("Patient/" + p1longId));
ourPatientDao.read(new IdDt("Patient/" + p1longId), new ServletRequestDetails());
fail();
} catch (ResourceNotFoundException e) {
// good
@ -122,7 +116,7 @@ public class FhirResourceDaoDstu1Test extends BaseJpaTest {
try {
p1.setId(new IdDt("Patient/" + p1longId));
ourPatientDao.update(p1);
ourPatientDao.update(p1, new ServletRequestDetails());
fail();
} catch (InvalidRequestException e) {
assertThat(e.getMessage(), containsString("clients may only assign IDs which contain at least one non-numeric"));

View File

@ -47,6 +47,7 @@ import ca.uhn.fhir.rest.method.RequestDetails;
import ca.uhn.fhir.rest.param.TokenParam;
import ca.uhn.fhir.rest.server.IBundleProvider;
import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException;
import ca.uhn.fhir.rest.server.servlet.ServletRequestDetails;
public class FhirSystemDaoDstu1Test extends BaseJpaTest {
@ -63,14 +64,14 @@ public class FhirSystemDaoDstu1Test extends BaseJpaTest {
public void testGetResourceCounts() {
Observation obs = new Observation();
obs.getName().addCoding().setSystem("urn:system").setCode("testGetResourceCountsO01");
ourObservationDao.create(obs);
ourObservationDao.create(obs, new ServletRequestDetails());
Map<String, Long> oldCounts = ourSystemDao.getResourceCounts();
Patient patient = new Patient();
patient.addIdentifier().setSystem("urn:system").setValue("testGetResourceCountsP01");
patient.addName().addFamily("Tester").addGiven("Joe");
ourPatientDao.create(patient);
ourPatientDao.create(patient, new ServletRequestDetails());
Map<String, Long> newCounts = ourSystemDao.getResourceCounts();
@ -92,21 +93,21 @@ public class FhirSystemDaoDstu1Test extends BaseJpaTest {
Patient patient = new Patient();
patient.addIdentifier().setSystem("urn:system").setValue("testHistory");
patient.addName().addFamily("Tester").addGiven("Joe");
IIdType pid = ourPatientDao.create(patient).getId().toVersionless();
IIdType pid = ourPatientDao.create(patient, new ServletRequestDetails()).getId().toVersionless();
Thread.sleep(10);
patient.setId(pid);
IIdType newpid = ourPatientDao.update(patient).getId();
IIdType newpid = ourPatientDao.update(patient, new ServletRequestDetails()).getId();
Thread.sleep(10);
patient.setId(pid);
IIdType newpid2 = ourPatientDao.update(patient).getId();
IIdType newpid2 = ourPatientDao.update(patient, new ServletRequestDetails()).getId();
Thread.sleep(10);
patient.setId(pid);
IIdType newpid3 = ourPatientDao.update(patient).getId();
IIdType newpid3 = ourPatientDao.update(patient, new ServletRequestDetails()).getId();
IBundleProvider values = ourSystemDao.history(start);
IBundleProvider values = ourSystemDao.history(start, new ServletRequestDetails());
assertEquals(4, values.size());
List<IBaseResource> res = values.getResources(0, 4);
@ -117,18 +118,18 @@ public class FhirSystemDaoDstu1Test extends BaseJpaTest {
Location loc = new Location();
loc.getAddress().addLine("AAA");
IIdType lid = ourLocationDao.create(loc).getId();
IIdType lid = ourLocationDao.create(loc, new ServletRequestDetails()).getId();
Location loc2 = new Location();
loc2.getAddress().addLine("AAA");
ourLocationDao.create(loc2).getId();
ourLocationDao.create(loc2, new ServletRequestDetails()).getId();
Thread.sleep(2000);
values = ourLocationDao.history(start);
values = ourLocationDao.history(start, new ServletRequestDetails());
assertEquals(2, values.size());
values = ourLocationDao.history(lid.getIdPartAsLong(), start);
values = ourLocationDao.history(lid.getIdPartAsLong(), start, new ServletRequestDetails());
assertEquals(1, values.size());
}
@ -219,44 +220,44 @@ public class FhirSystemDaoDstu1Test extends BaseJpaTest {
@Test
public void testTagOperationss() throws Exception {
TagList preSystemTl = ourSystemDao.getAllTags();
TagList preSystemTl = ourSystemDao.getAllTags(new ServletRequestDetails());
TagList tl1 = new TagList();
tl1.addTag("testGetAllTagsScheme1", "testGetAllTagsTerm1", "testGetAllTagsLabel1");
Patient p1 = new Patient();
p1.addIdentifier().setSystem("foo").setValue("testGetAllTags01");
ResourceMetadataKeyEnum.TAG_LIST.put(p1, tl1);
ourPatientDao.create(p1);
ourPatientDao.create(p1, new ServletRequestDetails());
TagList tl2 = new TagList();
tl2.addTag("testGetAllTagsScheme2", "testGetAllTagsTerm2", "testGetAllTagsLabel2");
Observation o1 = new Observation();
o1.getName().setText("testGetAllTags02");
ResourceMetadataKeyEnum.TAG_LIST.put(o1, tl2);
IIdType o1id = ourObservationDao.create(o1).getId();
IIdType o1id = ourObservationDao.create(o1, new ServletRequestDetails()).getId();
assertTrue(o1id.getVersionIdPart() != null);
TagList postSystemTl = ourSystemDao.getAllTags();
TagList postSystemTl = ourSystemDao.getAllTags(new ServletRequestDetails());
assertEquals(preSystemTl.size() + 2, postSystemTl.size());
assertEquals("testGetAllTagsLabel1", postSystemTl.getTag("testGetAllTagsScheme1", "testGetAllTagsTerm1").getLabel());
TagList tags = ourPatientDao.getAllResourceTags();
TagList tags = ourPatientDao.getAllResourceTags(new ServletRequestDetails());
assertEquals("testGetAllTagsLabel1", tags.getTag("testGetAllTagsScheme1", "testGetAllTagsTerm1").getLabel());
assertNull(tags.getTag("testGetAllTagsScheme2", "testGetAllTagsTerm2"));
TagList tags2 = ourObservationDao.getTags(o1id);
TagList tags2 = ourObservationDao.getTags(o1id, new ServletRequestDetails());
assertNull(tags2.getTag("testGetAllTagsScheme1", "testGetAllTagsTerm1"));
assertEquals("testGetAllTagsLabel2", tags2.getTag("testGetAllTagsScheme2", "testGetAllTagsTerm2").getLabel());
o1.setId(o1id);
IIdType o1id2 = ourObservationDao.update(o1).getId();
IIdType o1id2 = ourObservationDao.update(o1, new ServletRequestDetails()).getId();
assertTrue(o1id2.getVersionIdPart() != null);
tags2 = ourObservationDao.getTags(o1id);
tags2 = ourObservationDao.getTags(o1id, new ServletRequestDetails());
assertNull(tags2.getTag("testGetAllTagsScheme1", "testGetAllTagsTerm1"));
assertEquals("testGetAllTagsLabel2", tags2.getTag("testGetAllTagsScheme2", "testGetAllTagsTerm2").getLabel());
tags2 = ourObservationDao.getTags(o1id2);
tags2 = ourObservationDao.getTags(o1id2, new ServletRequestDetails());
assertNull(tags2.getTag("testGetAllTagsScheme1", "testGetAllTagsTerm1"));
assertNotNull(tags2.getTag("testGetAllTagsScheme2", "testGetAllTagsTerm2"));
@ -264,12 +265,12 @@ public class FhirSystemDaoDstu1Test extends BaseJpaTest {
* Remove a tag from a version
*/
ourObservationDao.removeTag(o1id2, TagTypeEnum.TAG, "testGetAllTagsScheme2", "testGetAllTagsTerm2");
tags2 = ourObservationDao.getTags(o1id2);
ourObservationDao.removeTag(o1id2, TagTypeEnum.TAG, "testGetAllTagsScheme2", "testGetAllTagsTerm2", new ServletRequestDetails());
tags2 = ourObservationDao.getTags(o1id2, new ServletRequestDetails());
assertNull(tags2.getTag("testGetAllTagsScheme1", "testGetAllTagsTerm1"));
assertNull(tags2.getTag("testGetAllTagsScheme2", "testGetAllTagsTerm2"));
tags2 = ourObservationDao.getTags(o1id);
tags2 = ourObservationDao.getTags(o1id, new ServletRequestDetails());
assertNull(tags2.getTag("testGetAllTagsScheme1", "testGetAllTagsTerm1"));
assertNotNull(tags2.getTag("testGetAllTagsScheme2", "testGetAllTagsTerm2"));
@ -277,13 +278,13 @@ public class FhirSystemDaoDstu1Test extends BaseJpaTest {
* Add a tag
*/
ourObservationDao.addTag(o1id2, TagTypeEnum.TAG, "testGetAllTagsScheme3", "testGetAllTagsTerm3", "testGetAllTagsLabel3");
tags2 = ourObservationDao.getTags(o1id2);
tags2 = ourObservationDao.getTags(o1id2, new ServletRequestDetails());
assertNull(tags2.getTag("testGetAllTagsScheme1", "testGetAllTagsTerm1"));
assertNull(tags2.getTag("testGetAllTagsScheme2", "testGetAllTagsTerm2"));
assertNotNull(tags2.getTag("testGetAllTagsScheme3", "testGetAllTagsTerm3"));
assertEquals("testGetAllTagsLabel3", tags2.getTag("testGetAllTagsScheme3", "testGetAllTagsTerm3").getLabel());
tags2 = ourObservationDao.getTags(o1id);
tags2 = ourObservationDao.getTags(o1id, new ServletRequestDetails());
assertNull(tags2.getTag("testGetAllTagsScheme1", "testGetAllTagsTerm1"));
assertNotNull(tags2.getTag("testGetAllTagsScheme2", "testGetAllTagsTerm2"));

View File

@ -18,6 +18,7 @@ import ca.uhn.fhir.jpa.interceptor.JpaServerInterceptorAdapter;
import ca.uhn.fhir.model.dstu2.resource.Patient;
import ca.uhn.fhir.model.primitive.IdDt;
import ca.uhn.fhir.rest.server.interceptor.IServerInterceptor.ActionRequestDetails;
import ca.uhn.fhir.rest.server.servlet.ServletRequestDetails;
public class FhirResourceDaoDstu2InterceptorTest extends BaseJpaDstu2Test {
@ -48,7 +49,7 @@ public class FhirResourceDaoDstu2InterceptorTest extends BaseJpaDstu2Test {
public void testJpaCreate() {
Patient p = new Patient();
p.addName().addFamily("PATIENT");
Long id = myPatientDao.create(p).getId().getIdPartAsLong();
Long id = myPatientDao.create(p, new ServletRequestDetails()).getId().getIdPartAsLong();
ArgumentCaptor<ActionRequestDetails> detailsCapt;
ArgumentCaptor<ResourceTable> tableCapt;
@ -68,7 +69,7 @@ public class FhirResourceDaoDstu2InterceptorTest extends BaseJpaDstu2Test {
*/
p = new Patient();
p.addName().addFamily("PATIENT1");
Long id2 = myPatientDao.create(p, "Patient?family=PATIENT").getId().getIdPartAsLong();
Long id2 = myPatientDao.create(p, "Patient?family=PATIENT", new ServletRequestDetails()).getId().getIdPartAsLong();
assertEquals(id, id2);
detailsCapt = ArgumentCaptor.forClass(ActionRequestDetails.class);
@ -82,9 +83,9 @@ public class FhirResourceDaoDstu2InterceptorTest extends BaseJpaDstu2Test {
public void testJpaDelete() {
Patient p = new Patient();
p.addName().addFamily("PATIENT");
Long id = myPatientDao.create(p).getId().getIdPartAsLong();
Long id = myPatientDao.create(p, new ServletRequestDetails()).getId().getIdPartAsLong();
myPatientDao.delete(new IdDt("Patient", id));
myPatientDao.delete(new IdDt("Patient", id), new ServletRequestDetails());
ArgumentCaptor<ActionRequestDetails> detailsCapt;
ArgumentCaptor<ResourceTable> tableCapt;
@ -102,12 +103,12 @@ public class FhirResourceDaoDstu2InterceptorTest extends BaseJpaDstu2Test {
public void testJpaUpdate() {
Patient p = new Patient();
p.addName().addFamily("PATIENT");
Long id = myPatientDao.create(p).getId().getIdPartAsLong();
Long id = myPatientDao.create(p, new ServletRequestDetails()).getId().getIdPartAsLong();
p = new Patient();
p.setId(new IdDt(id));
p.addName().addFamily("PATIENT1");
Long id2 = myPatientDao.update(p).getId().getIdPartAsLong();
Long id2 = myPatientDao.update(p, new ServletRequestDetails()).getId().getIdPartAsLong();
assertEquals(id, id2);
ArgumentCaptor<ActionRequestDetails> detailsCapt;
@ -126,7 +127,7 @@ public class FhirResourceDaoDstu2InterceptorTest extends BaseJpaDstu2Test {
p = new Patient();
p.setId(new IdDt(id));
p.addName().addFamily("PATIENT2");
id2 = myPatientDao.update(p, "Patient?family=PATIENT1").getId().getIdPartAsLong();
id2 = myPatientDao.update(p, "Patient?family=PATIENT1", new ServletRequestDetails()).getId().getIdPartAsLong();
assertEquals(id, id2);
detailsCapt = ArgumentCaptor.forClass(ActionRequestDetails.class);
@ -141,7 +142,7 @@ public class FhirResourceDaoDstu2InterceptorTest extends BaseJpaDstu2Test {
p = new Patient();
p.addName().addFamily("PATIENT3");
id2 = myPatientDao.update(p, "Patient?family=ZZZ").getId().getIdPartAsLong();
id2 = myPatientDao.update(p, "Patient?family=ZZZ", new ServletRequestDetails()).getId().getIdPartAsLong();
assertNotEquals(id, id2);
detailsCapt = ArgumentCaptor.forClass(ActionRequestDetails.class);

View File

@ -28,6 +28,7 @@ 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.server.Constants;
import ca.uhn.fhir.rest.server.servlet.ServletRequestDetails;
public class FhirResourceDaoDstu2SearchFtTest extends BaseJpaDstu2Test {
@ -37,7 +38,7 @@ public class FhirResourceDaoDstu2SearchFtTest extends BaseJpaDstu2Test {
public void testSuggestIgnoresBase64Content() {
Patient patient = new Patient();
patient.addName().addFamily("testSuggest");
IIdType ptId = myPatientDao.create(patient).getId().toUnqualifiedVersionless();
IIdType ptId = myPatientDao.create(patient, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
Media med = new Media();
med.getSubject().setReference(ptId);
@ -45,7 +46,7 @@ public class FhirResourceDaoDstu2SearchFtTest extends BaseJpaDstu2Test {
med.getContent().setContentType("LCws");
med.getContent().setData(new Base64BinaryDt(new byte[] {44,44,44,44,44,44,44,44}));
med.getContent().setTitle("bbbb syst");
myMediaDao.create(med);
myMediaDao.create(med, new ServletRequestDetails());
ourLog.info(myFhirCtx.newJsonParser().encodeResourceToString(med));
List<Suggestion> output = mySearchDao.suggestKeywords("Patient/" + ptId.getIdPart() + "/$everything", "_content", "press");
@ -77,35 +78,35 @@ public class FhirResourceDaoDstu2SearchFtTest extends BaseJpaDstu2Test {
public void testSuggest() {
Patient patient = new Patient();
patient.addName().addFamily("testSuggest");
IIdType ptId = myPatientDao.create(patient).getId().toUnqualifiedVersionless();
IIdType ptId = myPatientDao.create(patient, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
Observation obs = new Observation();
obs.getSubject().setReference(ptId);
obs.getCode().setText("ZXCVBNM ASDFGHJKL QWERTYUIOPASDFGHJKL");
myObservationDao.create(obs);
myObservationDao.create(obs, new ServletRequestDetails());
obs = new Observation();
obs.getSubject().setReference(ptId);
obs.getCode().setText("MNBVCXZ");
myObservationDao.create(obs);
myObservationDao.create(obs, new ServletRequestDetails());
obs = new Observation();
obs.getSubject().setReference(ptId);
obs.getCode().setText("ZXC HELLO");
obs.addComponent().getCode().setText("HHHHHHHHHH");
myObservationDao.create(obs);
myObservationDao.create(obs, new ServletRequestDetails());
/*
* These shouldn't match since they're for another patient
*/
patient = new Patient();
patient.addName().addFamily("testSuggest2");
IIdType ptId2 = myPatientDao.create(patient).getId().toUnqualifiedVersionless();
IIdType ptId2 = myPatientDao.create(patient, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
Observation obs2 = new Observation();
obs2.getSubject().setReference(ptId2);
obs2.getCode().setText("ZXCVBNMZZ");
myObservationDao.create(obs2);
myObservationDao.create(obs2, new ServletRequestDetails());
List<Suggestion> output = mySearchDao.suggestKeywords("Patient/" + ptId.getIdPart() + "/$everything", "_content", "ZXCVBNM");
ourLog.info("Found: " + output);
@ -150,7 +151,7 @@ public class FhirResourceDaoDstu2SearchFtTest extends BaseJpaDstu2Test {
patient = new Patient();
patient.getText().setDiv("<div>DIVAAA</div>");
patient.addName().addGiven("NAMEAAA");
IIdType pId1 = myPatientDao.create(patient).getId().toUnqualifiedVersionless();
IIdType pId1 = myPatientDao.create(patient, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
map = new SearchParameterMap();
map.add(Constants.PARAM_CONTENT, new StringParam("NAMEAAA"));
@ -168,7 +169,7 @@ public class FhirResourceDaoDstu2SearchFtTest extends BaseJpaDstu2Test {
patient.setId(pId1);
patient.getText().setDiv("<div>DIVBBB</div>");
patient.addName().addGiven("NAMEBBB");
myPatientDao.update(patient);
myPatientDao.update(patient, new ServletRequestDetails());
map = new SearchParameterMap();
map.add(Constants.PARAM_CONTENT, new StringParam("NAMEAAA"));
@ -192,19 +193,19 @@ public class FhirResourceDaoDstu2SearchFtTest extends BaseJpaDstu2Test {
public void testEverythingInstanceWithContentFilter() {
Patient pt1 = new Patient();
pt1.addName().addFamily("Everything").addGiven("Arthur");
IIdType ptId1 = myPatientDao.create(pt1).getId().toUnqualifiedVersionless();
IIdType ptId1 = myPatientDao.create(pt1, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
Patient pt2 = new Patient();
pt2.addName().addFamily("Everything").addGiven("Arthur");
IIdType ptId2 = myPatientDao.create(pt2).getId().toUnqualifiedVersionless();
IIdType ptId2 = myPatientDao.create(pt2, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
Device dev1 = new Device();
dev1.setManufacturer("Some Manufacturer");
IIdType devId1 = myDeviceDao.create(dev1).getId().toUnqualifiedVersionless();
IIdType devId1 = myDeviceDao.create(dev1, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
Device dev2 = new Device();
dev2.setManufacturer("Some Manufacturer 2");
myDeviceDao.create(dev2).getId().toUnqualifiedVersionless();
myDeviceDao.create(dev2, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
Observation obs1 = new Observation();
obs1.getText().setDiv("<div>OBSTEXT1</div>");
@ -212,19 +213,19 @@ public class FhirResourceDaoDstu2SearchFtTest extends BaseJpaDstu2Test {
obs1.getCode().addCoding().setCode("CODE1");
obs1.setValue(new StringDt("obsvalue1"));
obs1.getDevice().setReference(devId1);
IIdType obsId1 = myObservationDao.create(obs1).getId().toUnqualifiedVersionless();
IIdType obsId1 = myObservationDao.create(obs1, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
Observation obs2 = new Observation();
obs2.getSubject().setReference(ptId1);
obs2.getCode().addCoding().setCode("CODE2");
obs2.setValue(new StringDt("obsvalue2"));
IIdType obsId2 = myObservationDao.create(obs2).getId().toUnqualifiedVersionless();
IIdType obsId2 = myObservationDao.create(obs2, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
Observation obs3 = new Observation();
obs3.getSubject().setReference(ptId2);
obs3.getCode().addCoding().setCode("CODE3");
obs3.setValue(new StringDt("obsvalue3"));
IIdType obsId3 = myObservationDao.create(obs3).getId().toUnqualifiedVersionless();
IIdType obsId3 = myObservationDao.create(obs3, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
HttpServletRequest request;
List<IIdType> actual;
@ -235,16 +236,16 @@ public class FhirResourceDaoDstu2SearchFtTest extends BaseJpaDstu2Test {
param = new StringAndListParam();
param.addAnd(new StringOrListParam().addOr(new StringParam("obsvalue1")));
actual = toUnqualifiedVersionlessIds(myPatientDao.patientInstanceEverything(request, ptId1, null, null, null, param, null));
actual = toUnqualifiedVersionlessIds(myPatientDao.patientInstanceEverything(request, ptId1, null, null, null, param, null, new ServletRequestDetails()));
assertThat(actual, containsInAnyOrder(ptId1, obsId1, devId1));
param = new StringAndListParam();
param.addAnd(new StringOrListParam().addOr(new StringParam("obstext1")));
actual = toUnqualifiedVersionlessIds(myPatientDao.patientInstanceEverything(request, ptId1, null, null, null, null, param));
actual = toUnqualifiedVersionlessIds(myPatientDao.patientInstanceEverything(request, ptId1, null, null, null, null, param, new ServletRequestDetails()));
assertThat(actual, containsInAnyOrder(ptId1, obsId1, devId1));
request = mock(HttpServletRequest.class);
actual = toUnqualifiedVersionlessIds(myPatientDao.patientInstanceEverything(request, ptId1, null, null, null, null, null));
actual = toUnqualifiedVersionlessIds(myPatientDao.patientInstanceEverything(request, ptId1, null, null, null, null, null, new ServletRequestDetails()));
assertThat(actual, containsInAnyOrder(ptId1, obsId1, obsId2, devId1));
/*
@ -255,12 +256,12 @@ public class FhirResourceDaoDstu2SearchFtTest extends BaseJpaDstu2Test {
obs4.getSubject().setReference(ptId1);
obs4.getCode().addCoding().setCode("CODE1");
obs4.setValue(new StringDt("obsvalue1"));
IIdType obsId4 = myObservationDao.create(obs4).getId().toUnqualifiedVersionless();
IIdType obsId4 = myObservationDao.create(obs4, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
assertNotEquals(obsId1.getIdPart(), obsId4.getIdPart(), devId1);
param = new StringAndListParam();
param.addAnd(new StringOrListParam().addOr(new StringParam("obsvalue1")));
actual = toUnqualifiedVersionlessIds(myPatientDao.patientInstanceEverything(request, ptId1, null, null, null, param, null));
actual = toUnqualifiedVersionlessIds(myPatientDao.patientInstanceEverything(request, ptId1, null, null, null, param, null, new ServletRequestDetails()));
assertThat(actual, containsInAnyOrder(ptId1, obsId1, obsId4, devId1));
/*
@ -272,11 +273,11 @@ public class FhirResourceDaoDstu2SearchFtTest extends BaseJpaDstu2Test {
obs1.getSubject().setReference(ptId1);
obs1.getCode().addCoding().setCode("CODE2");
obs1.setValue(new StringDt("obsvalue2"));
myObservationDao.update(obs1);
myObservationDao.update(obs1, new ServletRequestDetails());
param = new StringAndListParam();
param.addAnd(new StringOrListParam().addOr(new StringParam("obsvalue1")));
actual = toUnqualifiedVersionlessIds(myPatientDao.patientInstanceEverything(request, ptId1, null, null, null, param, null));
actual = toUnqualifiedVersionlessIds(myPatientDao.patientInstanceEverything(request, ptId1, null, null, null, param, null, new ServletRequestDetails()));
assertThat(actual, containsInAnyOrder(ptId1, obsId4));
}
@ -285,38 +286,38 @@ public class FhirResourceDaoDstu2SearchFtTest extends BaseJpaDstu2Test {
public void testEverythingTypeWithContentFilter() {
Patient pt1 = new Patient();
pt1.addName().addFamily("Everything").addGiven("Arthur");
IIdType ptId1 = myPatientDao.create(pt1).getId().toUnqualifiedVersionless();
IIdType ptId1 = myPatientDao.create(pt1, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
Patient pt2 = new Patient();
pt2.addName().addFamily("Everything").addGiven("Arthur");
IIdType ptId2 = myPatientDao.create(pt2).getId().toUnqualifiedVersionless();
IIdType ptId2 = myPatientDao.create(pt2, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
Device dev1 = new Device();
dev1.setManufacturer("Some Manufacturer");
IIdType devId1 = myDeviceDao.create(dev1).getId().toUnqualifiedVersionless();
IIdType devId1 = myDeviceDao.create(dev1, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
Device dev2 = new Device();
dev2.setManufacturer("Some Manufacturer 2");
IIdType devId2 = myDeviceDao.create(dev2).getId().toUnqualifiedVersionless();
IIdType devId2 = myDeviceDao.create(dev2, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
Observation obs1 = new Observation();
obs1.getSubject().setReference(ptId1);
obs1.getCode().addCoding().setCode("CODE1");
obs1.setValue(new StringDt("obsvalue1"));
obs1.getDevice().setReference(devId1);
IIdType obsId1 = myObservationDao.create(obs1).getId().toUnqualifiedVersionless();
IIdType obsId1 = myObservationDao.create(obs1, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
Observation obs2 = new Observation();
obs2.getSubject().setReference(ptId1);
obs2.getCode().addCoding().setCode("CODE2");
obs2.setValue(new StringDt("obsvalue2"));
IIdType obsId2 = myObservationDao.create(obs2).getId().toUnqualifiedVersionless();
IIdType obsId2 = myObservationDao.create(obs2, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
Observation obs3 = new Observation();
obs3.getSubject().setReference(ptId2);
obs3.getCode().addCoding().setCode("CODE3");
obs3.setValue(new StringDt("obsvalue3"));
IIdType obsId3 = myObservationDao.create(obs3).getId().toUnqualifiedVersionless();
IIdType obsId3 = myObservationDao.create(obs3, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
HttpServletRequest request;
List<IIdType> actual;
@ -327,11 +328,11 @@ public class FhirResourceDaoDstu2SearchFtTest extends BaseJpaDstu2Test {
param = new StringAndListParam();
param.addAnd(new StringOrListParam().addOr(new StringParam("obsvalue1")));
actual = toUnqualifiedVersionlessIds(myPatientDao.patientTypeEverything(request, null, null, null, param, null));
actual = toUnqualifiedVersionlessIds(myPatientDao.patientTypeEverything(request, null, null, null, param, null, new ServletRequestDetails()));
assertThat(actual, containsInAnyOrder(ptId1, obsId1, devId1));
request = mock(HttpServletRequest.class);
actual = toUnqualifiedVersionlessIds(myPatientDao.patientTypeEverything(request, null, null, null, null, null));
actual = toUnqualifiedVersionlessIds(myPatientDao.patientTypeEverything(request, null, null, null, null, null, new ServletRequestDetails()));
assertThat(actual, containsInAnyOrder(ptId1, obsId1, obsId2, devId1, ptId2, obsId3));
/*
@ -342,12 +343,12 @@ public class FhirResourceDaoDstu2SearchFtTest extends BaseJpaDstu2Test {
obs4.getSubject().setReference(ptId1);
obs4.getCode().addCoding().setCode("CODE1");
obs4.setValue(new StringDt("obsvalue1"));
IIdType obsId4 = myObservationDao.create(obs4).getId().toUnqualifiedVersionless();
IIdType obsId4 = myObservationDao.create(obs4, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
assertNotEquals(obsId1.getIdPart(), obsId4.getIdPart(), devId1);
param = new StringAndListParam();
param.addAnd(new StringOrListParam().addOr(new StringParam("obsvalue1")));
actual = toUnqualifiedVersionlessIds(myPatientDao.patientTypeEverything(request, null, null, null, param, null));
actual = toUnqualifiedVersionlessIds(myPatientDao.patientTypeEverything(request, null, null, null, param, null, new ServletRequestDetails()));
assertThat(actual, containsInAnyOrder(ptId1, obsId1, obsId4, devId1));
/*
@ -359,11 +360,11 @@ public class FhirResourceDaoDstu2SearchFtTest extends BaseJpaDstu2Test {
obs1.getSubject().setReference(ptId1);
obs1.getCode().addCoding().setCode("CODE2");
obs1.setValue(new StringDt("obsvalue2"));
myObservationDao.update(obs1);
myObservationDao.update(obs1, new ServletRequestDetails());
param = new StringAndListParam();
param.addAnd(new StringOrListParam().addOr(new StringParam("obsvalue1")));
actual = toUnqualifiedVersionlessIds(myPatientDao.patientTypeEverything(request, null, null, null, param, null));
actual = toUnqualifiedVersionlessIds(myPatientDao.patientTypeEverything(request, null, null, null, param, null, new ServletRequestDetails()));
assertThat(actual, containsInAnyOrder(ptId1, obsId4));
}
@ -381,7 +382,7 @@ public class FhirResourceDaoDstu2SearchFtTest extends BaseJpaDstu2Test {
patient = new Patient();
patient.getText().setDiv("<div>DIVAAA</div>");
patient.addName().addGiven("NAMEAAA");
IIdType pId1 = myPatientDao.create(patient).getId().toUnqualifiedVersionless();
IIdType pId1 = myPatientDao.create(patient, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
map = new SearchParameterMap();
map.add(Constants.PARAM_CONTENT, new StringParam("NAMEAAA"));
@ -399,7 +400,7 @@ public class FhirResourceDaoDstu2SearchFtTest extends BaseJpaDstu2Test {
patient.setId(pId1);
patient.getText().setDiv("<div>DIVBBB</div>");
patient.addName().addGiven("NAMEBBB");
myPatientDao.update(patient, null, false);
myPatientDao.update(patient, null, false, new ServletRequestDetails());
map = new SearchParameterMap();
map.add(Constants.PARAM_CONTENT, new StringParam("NAMEAAA"));
@ -408,7 +409,7 @@ public class FhirResourceDaoDstu2SearchFtTest extends BaseJpaDstu2Test {
map.add(Constants.PARAM_CONTENT, new StringParam("NAMEBBB"));
assertThat(toUnqualifiedVersionlessIds(myPatientDao.search(map)), not(contains(pId1)));
myPatientDao.update(patient, null, true);
myPatientDao.update(patient, null, true, new ServletRequestDetails());
map = new SearchParameterMap();
map.add(Constants.PARAM_CONTENT, new StringParam("NAMEAAA"));
@ -436,18 +437,18 @@ public class FhirResourceDaoDstu2SearchFtTest extends BaseJpaDstu2Test {
Patient patient = new Patient();
patient.addName().addGiven(methodName);
patient.addAddress().addLine("My fulltext address");
pId1 = myPatientDao.create(patient).getId().toUnqualifiedVersionless();
pId1 = myPatientDao.create(patient, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
}
Observation obs = new Observation();
obs.getSubject().setReference(pId1);
obs.setValue(new StringDt("This is the FULLtext of the observation"));
IIdType oId1 = myObservationDao.create(obs).getId().toUnqualifiedVersionless();
IIdType oId1 = myObservationDao.create(obs, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
obs = new Observation();
obs.getSubject().setReference(pId1);
obs.setValue(new StringDt("Another fullText"));
IIdType oId2 = myObservationDao.create(obs).getId().toUnqualifiedVersionless();
IIdType oId2 = myObservationDao.create(obs, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
List<IIdType> patients;
SearchParameterMap params;

View File

@ -96,6 +96,7 @@ import ca.uhn.fhir.rest.server.Constants;
import ca.uhn.fhir.rest.server.IBundleProvider;
import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException;
import ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException;
import ca.uhn.fhir.rest.server.servlet.ServletRequestDetails;
@SuppressWarnings("unchecked")
public class FhirResourceDaoDstu2SearchNoFtTest extends BaseJpaDstu2Test {
@ -107,7 +108,7 @@ public class FhirResourceDaoDstu2SearchNoFtTest extends BaseJpaDstu2Test {
subs.setStatus(SubscriptionStatusEnum.ACTIVE);
subs.getChannel().setType(SubscriptionChannelTypeEnum.WEBSOCKET);
subs.setCriteria("Observation?");
IIdType id = mySubscriptionDao.create(subs).getId().toUnqualifiedVersionless();
IIdType id = mySubscriptionDao.create(subs, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
SearchParameterMap map = new SearchParameterMap();
map.add(Subscription.SP_TYPE, new TokenParam(null, SubscriptionChannelTypeEnum.WEBSOCKET.getCode()));
@ -121,33 +122,33 @@ public class FhirResourceDaoDstu2SearchNoFtTest extends BaseJpaDstu2Test {
Organization org = new Organization();
org.setName(methodName);
IIdType orgId = myOrganizationDao.create(org).getId().toUnqualifiedVersionless();
IIdType orgId = myOrganizationDao.create(org, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
Medication med = new Medication();
med.getCode().setText(methodName);
IIdType medId = myMedicationDao.create(med).getId().toUnqualifiedVersionless();
IIdType medId = myMedicationDao.create(med, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
Patient pat = new Patient();
pat.addAddress().addLine(methodName);
pat.getManagingOrganization().setReference(orgId);
IIdType patId = myPatientDao.create(pat).getId().toUnqualifiedVersionless();
IIdType patId = myPatientDao.create(pat, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
Patient pat2 = new Patient();
pat2.addAddress().addLine(methodName);
pat2.getManagingOrganization().setReference(orgId);
IIdType patId2 = myPatientDao.create(pat2).getId().toUnqualifiedVersionless();
IIdType patId2 = myPatientDao.create(pat2, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
MedicationOrder mo = new MedicationOrder();
mo.getPatient().setReference(patId);
mo.setMedication(new ResourceReferenceDt(medId));
IIdType moId = myMedicationOrderDao.create(mo).getId().toUnqualifiedVersionless();
IIdType moId = myMedicationOrderDao.create(mo, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
HttpServletRequest request = mock(HttpServletRequest.class);
IBundleProvider resp = myPatientDao.patientTypeEverything(request, null, null, null, null, null);
IBundleProvider resp = myPatientDao.patientTypeEverything(request, null, null, null, null, null, new ServletRequestDetails());
assertThat(toUnqualifiedVersionlessIds(resp), containsInAnyOrder(orgId, medId, patId, moId, patId2));
request = mock(HttpServletRequest.class);
resp = myPatientDao.patientInstanceEverything(request, patId, null, null, null, null, null);
resp = myPatientDao.patientInstanceEverything(request, patId, null, null, null, null, null, new ServletRequestDetails());
assertThat(toUnqualifiedVersionlessIds(resp), containsInAnyOrder(orgId, medId, patId, moId));
}
@ -161,7 +162,7 @@ public class FhirResourceDaoDstu2SearchNoFtTest extends BaseJpaDstu2Test {
order.addItem().addEvent().setDateTime(new DateTimeDt("2011-12-12T11:12:12Z"));
order.addItem().addEvent().setDateTime(new DateTimeDt("2011-12-12T11:12:12Z"));
IIdType id = myDiagnosticOrderDao.create(order).getId().toUnqualifiedVersionless();
IIdType id = myDiagnosticOrderDao.create(order, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
List<IIdType> actual = toUnqualifiedVersionlessIds(myDiagnosticOrderDao.search(DiagnosticOrder.SP_ITEM_DATE, new DateParam("2011-12-12T11:12:12Z")));
assertThat(actual, contains(id));
@ -182,7 +183,7 @@ public class FhirResourceDaoDstu2SearchNoFtTest extends BaseJpaDstu2Test {
res.addVaccinationProtocol().setDoseSequence(2);
res.addVaccinationProtocol().setDoseSequence(2);
IIdType id = myImmunizationDao.create(res).getId().toUnqualifiedVersionless();
IIdType id = myImmunizationDao.create(res, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
List<IIdType> actual = toUnqualifiedVersionlessIds(myImmunizationDao.search(Immunization.SP_DOSE_SEQUENCE, new NumberParam("1")));
assertThat(actual, contains(id));
@ -201,7 +202,7 @@ public class FhirResourceDaoDstu2SearchNoFtTest extends BaseJpaDstu2Test {
res.addInstance().getQuantity().setSystem("http://foo2").setCode("UNIT2").setValue(1232);
res.addInstance().getQuantity().setSystem("http://foo2").setCode("UNIT2").setValue(1232);
IIdType id = mySubstanceDao.create(res).getId().toUnqualifiedVersionless();
IIdType id = mySubstanceDao.create(res, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
Class<ResourceIndexedSearchParamQuantity> type = ResourceIndexedSearchParamQuantity.class;
List<?> results = myEntityManager.createQuery("SELECT i FROM " + type.getSimpleName() + " i", type).getResultList();
@ -217,11 +218,11 @@ public class FhirResourceDaoDstu2SearchNoFtTest extends BaseJpaDstu2Test {
Practitioner pract = new Practitioner();
pract.setId("Practitioner/somepract");
pract.getName().addFamily("SOME PRACT");
myPractitionerDao.update(pract);
myPractitionerDao.update(pract, new ServletRequestDetails());
Practitioner pract2 = new Practitioner();
pract2.setId("Practitioner/somepract2");
pract2.getName().addFamily("SOME PRACT2");
myPractitionerDao.update(pract2);
myPractitionerDao.update(pract2, new ServletRequestDetails());
DiagnosticOrder res = new DiagnosticOrder();
res.addEvent().setActor(new ResourceReferenceDt("Practitioner/somepract"));
@ -229,7 +230,7 @@ public class FhirResourceDaoDstu2SearchNoFtTest extends BaseJpaDstu2Test {
res.addEvent().setActor(new ResourceReferenceDt("Practitioner/somepract2"));
res.addEvent().setActor(new ResourceReferenceDt("Practitioner/somepract2"));
IIdType id = myDiagnosticOrderDao.create(res).getId().toUnqualifiedVersionless();
IIdType id = myDiagnosticOrderDao.create(res, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
Class<ResourceLink> type = ResourceLink.class;
List<?> results = myEntityManager.createQuery("SELECT i FROM " + type.getSimpleName() + " i", type).getResultList();
@ -250,7 +251,7 @@ public class FhirResourceDaoDstu2SearchNoFtTest extends BaseJpaDstu2Test {
p.addAddress().addLine("456 Fake Street");
p.addAddress().addLine("456 Fake Street");
IIdType id = myPatientDao.create(p).getId().toUnqualifiedVersionless();
IIdType id = myPatientDao.create(p, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
Class<ResourceIndexedSearchParamString> type = ResourceIndexedSearchParamString.class;
List<ResourceIndexedSearchParamString> results = myEntityManager.createQuery("SELECT i FROM " + type.getSimpleName() + " i", type).getResultList();
@ -269,7 +270,7 @@ public class FhirResourceDaoDstu2SearchNoFtTest extends BaseJpaDstu2Test {
res.addIdentifier().setSystem("http://foo2").setValue("1234");
res.addIdentifier().setSystem("http://foo2").setValue("1234");
IIdType id = myPatientDao.create(res).getId().toUnqualifiedVersionless();
IIdType id = myPatientDao.create(res, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
Class<ResourceIndexedSearchParamToken> type = ResourceIndexedSearchParamToken.class;
List<?> results = myEntityManager.createQuery("SELECT i FROM " + type.getSimpleName() + " i", type).getResultList();
@ -288,7 +289,7 @@ public class FhirResourceDaoDstu2SearchNoFtTest extends BaseJpaDstu2Test {
res.addElement().addTarget().addDependsOn().setElement("http://bar");
res.addElement().addTarget().addDependsOn().setElement("http://bar");
IIdType id = myConceptMapDao.create(res).getId().toUnqualifiedVersionless();
IIdType id = myConceptMapDao.create(res, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
Class<ResourceIndexedSearchParamUri> type = ResourceIndexedSearchParamUri.class;
List<?> results = myEntityManager.createQuery("SELECT i FROM " + type.getSimpleName() + " i", type).getResultList();
@ -305,13 +306,13 @@ public class FhirResourceDaoDstu2SearchNoFtTest extends BaseJpaDstu2Test {
Patient patient = new Patient();
patient.addIdentifier().setSystem("urn:system").setValue("001");
patient.addName().addFamily("Tester").addGiven("Joe");
myPatientDao.create(patient);
myPatientDao.create(patient, new ServletRequestDetails());
}
{
Patient patient = new Patient();
patient.addIdentifier().setSystem("urn:system").setValue("002");
patient.addName().addFamily("Tester").addGiven("John");
myPatientDao.create(patient);
myPatientDao.create(patient, new ServletRequestDetails());
}
Map<String, IQueryParameterType> params = new HashMap<String, IQueryParameterType>();
@ -325,13 +326,13 @@ public class FhirResourceDaoDstu2SearchNoFtTest extends BaseJpaDstu2Test {
{
Patient patient = new Patient();
patient.addIdentifier().setSystem("urn:system").setValue("001");
id1 = myPatientDao.create(patient).getId();
id1 = myPatientDao.create(patient, new ServletRequestDetails()).getId();
}
IIdType id2;
{
Organization patient = new Organization();
patient.addIdentifier().setSystem("urn:system").setValue("001");
id2 = myOrganizationDao.create(patient).getId();
id2 = myOrganizationDao.create(patient, new ServletRequestDetails()).getId();
}
Map<String, IQueryParameterType> params = new HashMap<String, IQueryParameterType>();
@ -352,13 +353,13 @@ public class FhirResourceDaoDstu2SearchNoFtTest extends BaseJpaDstu2Test {
{
Patient patient = new Patient();
patient.addIdentifier().setSystem("urn:system").setValue("001");
id1 = myPatientDao.create(patient).getId().toUnqualifiedVersionless();
id1 = myPatientDao.create(patient, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
}
IIdType id2;
{
Patient patient = new Patient();
patient.addIdentifier().setSystem("urn:system").setValue("001");
id2 = myPatientDao.create(patient).getId().toUnqualifiedVersionless();
id2 = myPatientDao.create(patient, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
}
SearchParameterMap params;
@ -400,14 +401,14 @@ public class FhirResourceDaoDstu2SearchNoFtTest extends BaseJpaDstu2Test {
{
Patient patient = new Patient();
patient.addIdentifier().setSystem("urn:system").setValue("001");
id1 = myPatientDao.create(patient).getId().toUnqualifiedVersionless();
id1 = myPatientDao.create(patient, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
}
long betweenTime = System.currentTimeMillis();
IIdType id2;
{
Patient patient = new Patient();
patient.addIdentifier().setSystem("urn:system").setValue("001");
id2 = myPatientDao.create(patient).getId().toUnqualifiedVersionless();
id2 = myPatientDao.create(patient, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
}
SearchParameterMap params = new SearchParameterMap();
@ -437,13 +438,13 @@ public class FhirResourceDaoDstu2SearchNoFtTest extends BaseJpaDstu2Test {
{
Patient patient = new Patient();
patient.addIdentifier().setSystem("urn:system").setValue("001");
id1 = myPatientDao.create(patient).getId().toUnqualifiedVersionless();
id1 = myPatientDao.create(patient, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
}
IIdType id2;
{
Organization patient = new Organization();
patient.addIdentifier().setSystem("urn:system").setValue("001");
id2 = myOrganizationDao.create(patient).getId().toUnqualifiedVersionless();
id2 = myOrganizationDao.create(patient, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
}
SearchParameterMap params = new SearchParameterMap();
@ -457,12 +458,12 @@ public class FhirResourceDaoDstu2SearchNoFtTest extends BaseJpaDstu2Test {
Observation o1 = new Observation();
o1.getCode().addCoding().setSystem("foo").setCode("testSearchCompositeParamN01");
o1.setValue(new StringDt("testSearchCompositeParamS01"));
IIdType id1 = myObservationDao.create(o1).getId();
IIdType id1 = myObservationDao.create(o1, new ServletRequestDetails()).getId();
Observation o2 = new Observation();
o2.getCode().addCoding().setSystem("foo").setCode("testSearchCompositeParamN01");
o2.setValue(new StringDt("testSearchCompositeParamS02"));
IIdType id2 = myObservationDao.create(o2).getId();
IIdType id2 = myObservationDao.create(o2, new ServletRequestDetails()).getId();
{
TokenParam v0 = new TokenParam("foo", "testSearchCompositeParamN01");
@ -487,12 +488,12 @@ public class FhirResourceDaoDstu2SearchNoFtTest extends BaseJpaDstu2Test {
Observation o1 = new Observation();
o1.getCode().addCoding().setSystem("foo").setCode("testSearchCompositeParamDateN01");
o1.setValue(new PeriodDt().setStart(new DateTimeDt("2001-01-01T11:11:11")));
IIdType id1 = myObservationDao.create(o1).getId().toUnqualifiedVersionless();
IIdType id1 = myObservationDao.create(o1, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
Observation o2 = new Observation();
o2.getCode().addCoding().setSystem("foo").setCode("testSearchCompositeParamDateN01");
o2.setValue(new PeriodDt().setStart(new DateTimeDt("2001-01-01T12:12:12")));
IIdType id2 = myObservationDao.create(o2).getId().toUnqualifiedVersionless();
IIdType id2 = myObservationDao.create(o2, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
{
TokenParam v0 = new TokenParam("foo", "testSearchCompositeParamDateN01");
@ -526,7 +527,7 @@ public class FhirResourceDaoDstu2SearchNoFtTest extends BaseJpaDstu2Test {
patient.setLanguage(new CodeDt("TEST"));
patient.addName().addFamily("TEST");
patient.addIdentifier().setSystem("TEST").setValue("TEST");
myPatientDao.update(patient);
myPatientDao.update(patient, new ServletRequestDetails());
}
Map<String, IQueryParameterType> params = new HashMap<String, IQueryParameterType>();
@ -542,7 +543,7 @@ public class FhirResourceDaoDstu2SearchNoFtTest extends BaseJpaDstu2Test {
params.put(Patient.SP_NAME, new StringParam("TEST"));
assertEquals(1, toList(myPatientDao.search(params)).size());
myPatientDao.delete(new IdDt("Patient/TEST"));
myPatientDao.delete(new IdDt("Patient/TEST"), new ServletRequestDetails());
params = new HashMap<String, IQueryParameterType>();
params.put("_id", new StringDt("TEST"));
@ -577,7 +578,7 @@ public class FhirResourceDaoDstu2SearchNoFtTest extends BaseJpaDstu2Test {
patient.getLanguage().setValue("en_CA");
patient.addIdentifier().setSystem("urn:system").setValue("001");
patient.addName().addFamily("testSearchLanguageParam").addGiven("Joe");
id1 = myPatientDao.create(patient).getId();
id1 = myPatientDao.create(patient, new ServletRequestDetails()).getId();
}
IIdType id2;
{
@ -585,7 +586,7 @@ public class FhirResourceDaoDstu2SearchNoFtTest extends BaseJpaDstu2Test {
patient.getLanguage().setValue("en_US");
patient.addIdentifier().setSystem("urn:system").setValue("002");
patient.addName().addFamily("testSearchLanguageParam").addGiven("John");
id2 = myPatientDao.create(patient).getId();
id2 = myPatientDao.create(patient, new ServletRequestDetails()).getId();
}
{
Map<String, IQueryParameterType> params = new HashMap<String, IQueryParameterType>();
@ -617,7 +618,7 @@ public class FhirResourceDaoDstu2SearchNoFtTest extends BaseJpaDstu2Test {
patient.getLanguage().setValue("en_CA");
patient.addIdentifier().setSystem("urn:system").setValue("001");
patient.addName().addFamily("testSearchLanguageParam").addGiven("Joe");
id1 = myPatientDao.create(patient).getId().toUnqualifiedVersionless();
id1 = myPatientDao.create(patient, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
}
Date betweenTime = new Date();
@ -628,7 +629,7 @@ public class FhirResourceDaoDstu2SearchNoFtTest extends BaseJpaDstu2Test {
patient.getLanguage().setValue("en_US");
patient.addIdentifier().setSystem("urn:system").setValue("002");
patient.addName().addFamily("testSearchLanguageParam").addGiven("John");
id2 = myPatientDao.create(patient).getId().toUnqualifiedVersionless();
id2 = myPatientDao.create(patient, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
}
{
SearchParameterMap params = new SearchParameterMap();
@ -712,14 +713,14 @@ public class FhirResourceDaoDstu2SearchNoFtTest extends BaseJpaDstu2Test {
Patient patient = new Patient();
patient.addIdentifier().setSystem("urn:system").setValue("001");
patient.addName().addFamily(methodName).addGiven("Joe");
id1a = myPatientDao.create(patient).getId().toUnqualifiedVersionless();
id1a = myPatientDao.create(patient, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
}
IIdType id1b;
{
Patient patient = new Patient();
patient.addIdentifier().setSystem("urn:system").setValue("002");
patient.addName().addFamily(methodName + "XXXX").addGiven("Joe");
id1b = myPatientDao.create(patient).getId().toUnqualifiedVersionless();
id1b = myPatientDao.create(patient, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
}
Thread.sleep(1100);
@ -731,7 +732,7 @@ public class FhirResourceDaoDstu2SearchNoFtTest extends BaseJpaDstu2Test {
Patient patient = new Patient();
patient.addIdentifier().setSystem("urn:system").setValue("002");
patient.addName().addFamily(methodName).addGiven("John");
id2 = myPatientDao.create(patient).getId().toUnqualifiedVersionless();
id2 = myPatientDao.create(patient, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
}
{
@ -776,7 +777,7 @@ public class FhirResourceDaoDstu2SearchNoFtTest extends BaseJpaDstu2Test {
{
Patient patient = new Patient();
patient.addIdentifier().setSystem("urn:system").setValue("001");
id0 = myPatientDao.create(patient).getId().toUnqualifiedVersionless();
id0 = myPatientDao.create(patient, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
}
int sleep = 100;
@ -789,18 +790,18 @@ public class FhirResourceDaoDstu2SearchNoFtTest extends BaseJpaDstu2Test {
{
Patient patient = new Patient();
patient.addIdentifier().setSystem("urn:system").setValue("001");
id1a = myPatientDao.create(patient).getId().toUnqualifiedVersionless();
id1a = myPatientDao.create(patient, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
}
IIdType id1b;
{
Patient patient = new Patient();
patient.addIdentifier().setSystem("urn:system").setValue("001");
id1b = myPatientDao.create(patient).getId().toUnqualifiedVersionless();
id1b = myPatientDao.create(patient, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
}
ourLog.info("Res 1: {}", ResourceMetadataKeyEnum.PUBLISHED.get(myPatientDao.read(id0)).getValueAsString());
ourLog.info("Res 2: {}", ResourceMetadataKeyEnum.PUBLISHED.get(myPatientDao.read(id1a)).getValueAsString());
InstantDt id1bpublished = ResourceMetadataKeyEnum.PUBLISHED.get(myPatientDao.read(id1b));
ourLog.info("Res 1: {}", ResourceMetadataKeyEnum.PUBLISHED.get(myPatientDao.read(id0, new ServletRequestDetails())).getValueAsString());
ourLog.info("Res 2: {}", ResourceMetadataKeyEnum.PUBLISHED.get(myPatientDao.read(id1a, new ServletRequestDetails())).getValueAsString());
InstantDt id1bpublished = ResourceMetadataKeyEnum.PUBLISHED.get(myPatientDao.read(id1b, new ServletRequestDetails()));
ourLog.info("Res 3: {}", id1bpublished.getValueAsString());
Thread.sleep(sleep);
@ -841,13 +842,13 @@ public class FhirResourceDaoDstu2SearchNoFtTest extends BaseJpaDstu2Test {
patient.addIdentifier().setSystem("urn:system").setValue("001");
patient.addName().addFamily("testSearchNameParam01Fam").addGiven("testSearchNameParam01Giv");
ResourceMetadataKeyEnum.TITLE.put(patient, "P1TITLE");
id1 = myPatientDao.create(patient).getId();
id1 = myPatientDao.create(patient, new ServletRequestDetails()).getId();
}
{
Patient patient = new Patient();
patient.addIdentifier().setSystem("urn:system").setValue("002");
patient.addName().addFamily("testSearchNameParam02Fam").addGiven("testSearchNameParam02Giv");
myPatientDao.create(patient);
myPatientDao.create(patient, new ServletRequestDetails());
}
Map<String, IQueryParameterType> params = new HashMap<String, IQueryParameterType>();
@ -891,7 +892,7 @@ public class FhirResourceDaoDstu2SearchNoFtTest extends BaseJpaDstu2Test {
Location loc = new Location();
loc.getPosition().setLatitude(43.7);
loc.getPosition().setLatitude(79.4);
myLocationDao.create(loc);
myLocationDao.create(loc, new ServletRequestDetails());
}
}
@ -900,12 +901,12 @@ public class FhirResourceDaoDstu2SearchNoFtTest extends BaseJpaDstu2Test {
Encounter e1 = new Encounter();
e1.addIdentifier().setSystem("foo").setValue("testSearchNumberParam01");
e1.getLength().setSystem(BaseHapiFhirDao.UCUM_NS).setCode("min").setValue(4.0 * 24 * 60);
IIdType id1 = myEncounterDao.create(e1).getId();
IIdType id1 = myEncounterDao.create(e1, new ServletRequestDetails()).getId();
Encounter e2 = new Encounter();
e2.addIdentifier().setSystem("foo").setValue("testSearchNumberParam02");
e2.getLength().setSystem(BaseHapiFhirDao.UCUM_NS).setCode("year").setValue(2.0);
IIdType id2 = myEncounterDao.create(e2).getId();
IIdType id2 = myEncounterDao.create(e2, new ServletRequestDetails()).getId();
{
IBundleProvider found = myEncounterDao.search(Encounter.SP_LENGTH, new NumberParam(">2"));
assertEquals(2, found.size());
@ -933,7 +934,7 @@ public class FhirResourceDaoDstu2SearchNoFtTest extends BaseJpaDstu2Test {
{
Patient patient = new Patient();
patient.addName().addFamily(name);
id = myPatientDao.create(patient).getId().toUnqualifiedVersionless();
id = myPatientDao.create(patient, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
}
Map<String, IQueryParameterType> params = new HashMap<String, IQueryParameterType>();
@ -944,7 +945,7 @@ public class FhirResourceDaoDstu2SearchNoFtTest extends BaseJpaDstu2Test {
Patient patient = new Patient();
patient.addIdentifier().setSystem(name).setValue(name);
patient.setId(id);
myPatientDao.update(patient);
myPatientDao.update(patient, new ServletRequestDetails());
params = new HashMap<String, IQueryParameterType>();
params.put(Patient.SP_FAMILY, new StringDt(name));
@ -961,14 +962,14 @@ public class FhirResourceDaoDstu2SearchNoFtTest extends BaseJpaDstu2Test {
Practitioner patient = new Practitioner();
patient.getName().addFamily(methodName);
patient.addTelecom().setSystem(ContactPointSystemEnum.PHONE).setValue("123");
id1 = myPractitionerDao.create(patient).getId().toUnqualifiedVersionless();
id1 = myPractitionerDao.create(patient, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
}
IIdType id2;
{
Practitioner patient = new Practitioner();
patient.getName().addFamily(methodName);
patient.addTelecom().setSystem(ContactPointSystemEnum.EMAIL).setValue("abc");
id2 = myPractitionerDao.create(patient).getId().toUnqualifiedVersionless();
id2 = myPractitionerDao.create(patient, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
}
Map<String, IQueryParameterType> params;
@ -1007,27 +1008,27 @@ public class FhirResourceDaoDstu2SearchNoFtTest extends BaseJpaDstu2Test {
Patient patient = new Patient();
patient.addIdentifier().setSystem("urn:system").setValue("testSearchResourceLinkWithChainXX");
patient.addIdentifier().setSystem("urn:system").setValue("testSearchResourceLinkWithChain01");
IIdType patientId01 = myPatientDao.create(patient).getId();
IIdType patientId01 = myPatientDao.create(patient, new ServletRequestDetails()).getId();
Patient patient02 = new Patient();
patient02.addIdentifier().setSystem("urn:system").setValue("testSearchResourceLinkWithChainXX");
patient02.addIdentifier().setSystem("urn:system").setValue("testSearchResourceLinkWithChain02");
IIdType patientId02 = myPatientDao.create(patient02).getId();
IIdType patientId02 = myPatientDao.create(patient02, new ServletRequestDetails()).getId();
Observation obs01 = new Observation();
obs01.setEffective(new DateTimeDt(new Date()));
obs01.setSubject(new ResourceReferenceDt(patientId01));
IIdType obsId01 = myObservationDao.create(obs01).getId();
IIdType obsId01 = myObservationDao.create(obs01, new ServletRequestDetails()).getId();
Observation obs02 = new Observation();
obs02.setEffective(new DateTimeDt(new Date()));
obs02.setSubject(new ResourceReferenceDt(patientId02));
IIdType obsId02 = myObservationDao.create(obs02).getId();
IIdType obsId02 = myObservationDao.create(obs02, new ServletRequestDetails()).getId();
// Create another type, that shouldn't be returned
DiagnosticReport dr01 = new DiagnosticReport();
dr01.setSubject(new ResourceReferenceDt(patientId01));
IIdType drId01 = myDiagnosticReportDao.create(dr01).getId();
IIdType drId01 = myDiagnosticReportDao.create(dr01, new ServletRequestDetails()).getId();
ourLog.info("P1[{}] P2[{}] O1[{}] O2[{}] D1[{}]", new Object[] { patientId01, patientId02, obsId01, obsId02, drId01 });
@ -1061,19 +1062,19 @@ public class FhirResourceDaoDstu2SearchNoFtTest extends BaseJpaDstu2Test {
Organization org = new Organization();
org.setName(methodName);
IIdType orgId01 = myOrganizationDao.create(org).getId().toUnqualifiedVersionless();
IIdType orgId01 = myOrganizationDao.create(org, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
Location locParent = new Location();
locParent.setManagingOrganization(new ResourceReferenceDt(orgId01));
IIdType locParentId = myLocationDao.create(locParent).getId().toUnqualifiedVersionless();
IIdType locParentId = myLocationDao.create(locParent, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
Location locChild = new Location();
locChild.setPartOf(new ResourceReferenceDt(locParentId));
IIdType locChildId = myLocationDao.create(locChild).getId().toUnqualifiedVersionless();
IIdType locChildId = myLocationDao.create(locChild, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
Location locGrandchild = new Location();
locGrandchild.setPartOf(new ResourceReferenceDt(locChildId));
IIdType locGrandchildId = myLocationDao.create(locGrandchild).getId().toUnqualifiedVersionless();
IIdType locGrandchildId = myLocationDao.create(locGrandchild, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
IBundleProvider found;
ReferenceParam param;
@ -1106,21 +1107,21 @@ public class FhirResourceDaoDstu2SearchNoFtTest extends BaseJpaDstu2Test {
Patient patient = new Patient();
patient.addName().addFamily("testSearchResourceLinkWithChainWithMultipleTypes01");
patient.addName().addFamily("testSearchResourceLinkWithChainWithMultipleTypesXX");
IIdType patientId01 = myPatientDao.create(patient).getId();
IIdType patientId01 = myPatientDao.create(patient, new ServletRequestDetails()).getId();
Location loc01 = new Location();
loc01.getNameElement().setValue("testSearchResourceLinkWithChainWithMultipleTypes01");
IIdType locId01 = myLocationDao.create(loc01).getId();
IIdType locId01 = myLocationDao.create(loc01, new ServletRequestDetails()).getId();
Observation obs01 = new Observation();
obs01.setEffective(new DateTimeDt(new Date()));
obs01.setSubject(new ResourceReferenceDt(patientId01));
IIdType obsId01 = myObservationDao.create(obs01).getId();
IIdType obsId01 = myObservationDao.create(obs01, new ServletRequestDetails()).getId();
Observation obs02 = new Observation();
obs02.setEffective(new DateTimeDt(new Date()));
obs02.setSubject(new ResourceReferenceDt(locId01));
IIdType obsId02 = myObservationDao.create(obs02).getId();
IIdType obsId02 = myObservationDao.create(obs02, new ServletRequestDetails()).getId();
ourLog.info("P1[{}] L1[{}] Obs1[{}] Obs2[{}]", new Object[] { patientId01, locId01, obsId01, obsId02 });
@ -1147,28 +1148,28 @@ public class FhirResourceDaoDstu2SearchNoFtTest extends BaseJpaDstu2Test {
patient.setId("testSearchResourceLinkWithTextLogicalId01");
patient.addIdentifier().setSystem("urn:system").setValue("testSearchResourceLinkWithTextLogicalIdXX");
patient.addIdentifier().setSystem("urn:system").setValue("testSearchResourceLinkWithTextLogicalId01");
IIdType patientId01 = myPatientDao.update(patient).getId();
IIdType patientId01 = myPatientDao.update(patient, new ServletRequestDetails()).getId();
Patient patient02 = new Patient();
patient02.setId("testSearchResourceLinkWithTextLogicalId02");
patient02.addIdentifier().setSystem("urn:system").setValue("testSearchResourceLinkWithTextLogicalIdXX");
patient02.addIdentifier().setSystem("urn:system").setValue("testSearchResourceLinkWithTextLogicalId02");
IIdType patientId02 = myPatientDao.update(patient02).getId();
IIdType patientId02 = myPatientDao.update(patient02, new ServletRequestDetails()).getId();
Observation obs01 = new Observation();
obs01.setEffective(new DateTimeDt(new Date()));
obs01.setSubject(new ResourceReferenceDt(patientId01));
IIdType obsId01 = myObservationDao.create(obs01).getId();
IIdType obsId01 = myObservationDao.create(obs01, new ServletRequestDetails()).getId();
Observation obs02 = new Observation();
obs02.setEffective(new DateTimeDt(new Date()));
obs02.setSubject(new ResourceReferenceDt(patientId02));
IIdType obsId02 = myObservationDao.create(obs02).getId();
IIdType obsId02 = myObservationDao.create(obs02, new ServletRequestDetails()).getId();
// Create another type, that shouldn't be returned
DiagnosticReport dr01 = new DiagnosticReport();
dr01.setSubject(new ResourceReferenceDt(patientId01));
IIdType drId01 = myDiagnosticReportDao.create(dr01).getId();
IIdType drId01 = myDiagnosticReportDao.create(dr01, new ServletRequestDetails()).getId();
ourLog.info("P1[{}] P2[{}] O1[{}] O2[{}] D1[{}]", new Object[] { patientId01, patientId02, obsId01, obsId02, drId01 });
@ -1199,13 +1200,13 @@ public class FhirResourceDaoDstu2SearchNoFtTest extends BaseJpaDstu2Test {
Patient patient = new Patient();
patient.addIdentifier().setSystem("urn:system").setValue("001");
patient.addName().addFamily("Tester_testSearchStringParam").addGiven("Joe");
myPatientDao.create(patient);
myPatientDao.create(patient, new ServletRequestDetails());
}
{
Patient patient = new Patient();
patient.addIdentifier().setSystem("urn:system").setValue("002");
patient.addName().addFamily("Tester_testSearchStringParam").addGiven("John");
myPatientDao.create(patient);
myPatientDao.create(patient, new ServletRequestDetails());
}
Map<String, IQueryParameterType> params = new HashMap<String, IQueryParameterType>();
@ -1230,12 +1231,12 @@ public class FhirResourceDaoDstu2SearchNoFtTest extends BaseJpaDstu2Test {
Patient patient = new Patient();
patient.addIdentifier().setSystem("urn:system").setValue("001");
patient.addName().addFamily(value);
longId = myPatientDao.create(patient).getId().toUnqualifiedVersionless();
longId = myPatientDao.create(patient, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
}
{
Patient patient = new Patient();
patient.addIdentifier().setSystem("urn:system").setValue("002");
shortId = myPatientDao.create(patient).getId().toUnqualifiedVersionless();
shortId = myPatientDao.create(patient, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
}
Map<String, IQueryParameterType> params = new HashMap<String, IQueryParameterType>();
@ -1254,13 +1255,13 @@ public class FhirResourceDaoDstu2SearchNoFtTest extends BaseJpaDstu2Test {
Patient patient = new Patient();
patient.addIdentifier().setSystem("urn:system").setValue("001");
patient.addName().addGiven("testSearchStringParamWithNonNormalized_h\u00F6ra");
myPatientDao.create(patient);
myPatientDao.create(patient, new ServletRequestDetails());
}
{
Patient patient = new Patient();
patient.addIdentifier().setSystem("urn:system").setValue("002");
patient.addName().addGiven("testSearchStringParamWithNonNormalized_HORA");
myPatientDao.create(patient);
myPatientDao.create(patient, new ServletRequestDetails());
}
Map<String, IQueryParameterType> params = new HashMap<String, IQueryParameterType>();
@ -1282,12 +1283,12 @@ public class FhirResourceDaoDstu2SearchNoFtTest extends BaseJpaDstu2Test {
patient.addIdentifier().setSystem("urn:system").setValue("testSearchTokenParam001");
patient.addName().addFamily("Tester").addGiven("testSearchTokenParam1");
patient.addCommunication().getLanguage().setText("testSearchTokenParamComText").addCoding().setCode("testSearchTokenParamCode").setSystem("testSearchTokenParamSystem").setDisplay("testSearchTokenParamDisplay");
myPatientDao.create(patient);
myPatientDao.create(patient, new ServletRequestDetails());
patient = new Patient();
patient.addIdentifier().setSystem("urn:system").setValue("testSearchTokenParam002");
patient.addName().addFamily("Tester").addGiven("testSearchTokenParam2");
myPatientDao.create(patient);
myPatientDao.create(patient, new ServletRequestDetails());
{
SearchParameterMap map = new SearchParameterMap();
@ -1390,7 +1391,7 @@ public class FhirResourceDaoDstu2SearchNoFtTest extends BaseJpaDstu2Test {
QuantityDt q = new QuantityDt().setSystem("urn:bar:" + methodName).setCode(methodName + "units").setValue(100);
o.setValue(q);
myObservationDao.create(o);
myObservationDao.create(o, new ServletRequestDetails());
param = new QuantityParam(ParamPrefixEnum.GREATERTHAN_OR_EQUALS, new BigDecimal("10"), null, null);
found = myObservationDao.searchForIds("value-quantity", param);
@ -1429,7 +1430,7 @@ public class FhirResourceDaoDstu2SearchNoFtTest extends BaseJpaDstu2Test {
{
Organization org = new Organization();
org.getNameElement().setValue(methodName + "_O1Parent");
parentOrgId = myOrganizationDao.create(org).getId().toUnqualifiedVersionless();
parentOrgId = myOrganizationDao.create(org, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
}
IIdType orgId;
IIdType patientId;
@ -1437,20 +1438,20 @@ public class FhirResourceDaoDstu2SearchNoFtTest extends BaseJpaDstu2Test {
Organization org = new Organization();
org.getNameElement().setValue(methodName + "_O1");
org.setPartOf(new ResourceReferenceDt(parentOrgId));
orgId = myOrganizationDao.create(org).getId().toUnqualifiedVersionless();
orgId = myOrganizationDao.create(org, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
Patient patient = new Patient();
patient.addIdentifier().setSystem("urn:system").setValue("001");
patient.addName().addFamily("Tester_" + methodName + "_P1").addGiven("Joe");
patient.getManagingOrganization().setReference(orgId);
patient.addCareProvider().setReference(orgId);
patientId = myPatientDao.create(patient).getId().toUnqualifiedVersionless();
patientId = myPatientDao.create(patient, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
}
IIdType practId2;
{
Practitioner pract = new Practitioner();
pract.getName().addFamily(methodName + "_PRACT1");
practId2 = myPractitionerDao.create(pract).getId().toUnqualifiedVersionless();
practId2 = myPractitionerDao.create(pract, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
}
IIdType patientId2;
{
@ -1458,7 +1459,7 @@ public class FhirResourceDaoDstu2SearchNoFtTest extends BaseJpaDstu2Test {
patient.addIdentifier().setSystem("urn:system").setValue("002");
patient.addName().addFamily("Tester_" + methodName + "_P2").addGiven("John");
patient.addCareProvider().setReference(practId2);
patientId2 = myPatientDao.create(patient).getId().toUnqualifiedVersionless();
patientId2 = myPatientDao.create(patient, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
}
{
@ -1561,21 +1562,21 @@ public class FhirResourceDaoDstu2SearchNoFtTest extends BaseJpaDstu2Test {
{
Organization org = new Organization();
org.getNameElement().setValue(methodName + "_O1Parent");
parentParentOrgId = myOrganizationDao.create(org).getId().toUnqualifiedVersionless();
parentParentOrgId = myOrganizationDao.create(org, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
}
IIdType parentOrgId;
{
Organization org = new Organization();
org.getNameElement().setValue(methodName + "_O1Parent");
org.setPartOf(new ResourceReferenceDt(parentParentOrgId));
parentOrgId = myOrganizationDao.create(org).getId().toUnqualifiedVersionless();
parentOrgId = myOrganizationDao.create(org, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
}
IIdType orgId;
{
Organization org = new Organization();
org.getNameElement().setValue(methodName + "_O1");
org.setPartOf(new ResourceReferenceDt(parentOrgId));
orgId = myOrganizationDao.create(org).getId().toUnqualifiedVersionless();
orgId = myOrganizationDao.create(org, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
}
IIdType patientId;
{
@ -1583,7 +1584,7 @@ public class FhirResourceDaoDstu2SearchNoFtTest extends BaseJpaDstu2Test {
patient.addIdentifier().setSystem("urn:system").setValue("001");
patient.addName().addFamily("Tester_" + methodName + "_P1").addGiven("Joe");
patient.getManagingOrganization().setReference(orgId);
patientId = myPatientDao.create(patient).getId().toUnqualifiedVersionless();
patientId = myPatientDao.create(patient, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
}
{
@ -1603,21 +1604,21 @@ public class FhirResourceDaoDstu2SearchNoFtTest extends BaseJpaDstu2Test {
{
Organization org = new Organization();
org.getNameElement().setValue(methodName + "_O1Parent");
parentParentOrgId = myOrganizationDao.create(org).getId().toUnqualifiedVersionless();
parentParentOrgId = myOrganizationDao.create(org, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
}
IIdType parentOrgId;
{
Organization org = new Organization();
org.getNameElement().setValue(methodName + "_O1Parent");
org.setPartOf(new ResourceReferenceDt(parentParentOrgId));
parentOrgId = myOrganizationDao.create(org).getId().toUnqualifiedVersionless();
parentOrgId = myOrganizationDao.create(org, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
}
IIdType orgId;
{
Organization org = new Organization();
org.getNameElement().setValue(methodName + "_O1");
org.setPartOf(new ResourceReferenceDt(parentOrgId));
orgId = myOrganizationDao.create(org).getId().toUnqualifiedVersionless();
orgId = myOrganizationDao.create(org, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
}
IIdType patientId;
{
@ -1625,7 +1626,7 @@ public class FhirResourceDaoDstu2SearchNoFtTest extends BaseJpaDstu2Test {
patient.addIdentifier().setSystem("urn:system").setValue("001");
patient.addName().addFamily("Tester_" + methodName + "_P1").addGiven("Joe");
patient.getManagingOrganization().setReference(orgId);
patientId = myPatientDao.create(patient).getId().toUnqualifiedVersionless();
patientId = myPatientDao.create(patient, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
}
{
@ -1645,21 +1646,21 @@ public class FhirResourceDaoDstu2SearchNoFtTest extends BaseJpaDstu2Test {
{
Organization org = new Organization();
org.getNameElement().setValue(methodName + "_O1Parent");
parentParentOrgId = myOrganizationDao.create(org).getId().toUnqualifiedVersionless();
parentParentOrgId = myOrganizationDao.create(org, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
}
IIdType parentOrgId;
{
Organization org = new Organization();
org.getNameElement().setValue(methodName + "_O1Parent");
org.setPartOf(new ResourceReferenceDt(parentParentOrgId));
parentOrgId = myOrganizationDao.create(org).getId().toUnqualifiedVersionless();
parentOrgId = myOrganizationDao.create(org, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
}
IIdType orgId;
{
Organization org = new Organization();
org.getNameElement().setValue(methodName + "_O1");
org.setPartOf(new ResourceReferenceDt(parentOrgId));
orgId = myOrganizationDao.create(org).getId().toUnqualifiedVersionless();
orgId = myOrganizationDao.create(org, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
}
IIdType patientId;
{
@ -1667,7 +1668,7 @@ public class FhirResourceDaoDstu2SearchNoFtTest extends BaseJpaDstu2Test {
patient.addIdentifier().setSystem("urn:system").setValue("001");
patient.addName().addFamily("Tester_" + methodName + "_P1").addGiven("Joe");
patient.getManagingOrganization().setReference(orgId);
patientId = myPatientDao.create(patient).getId().toUnqualifiedVersionless();
patientId = myPatientDao.create(patient, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
}
{
@ -1686,21 +1687,21 @@ public class FhirResourceDaoDstu2SearchNoFtTest extends BaseJpaDstu2Test {
{
Organization org = new Organization();
org.getNameElement().setValue(methodName + "_O1Parent");
parentParentOrgId = myOrganizationDao.create(org).getId().toUnqualifiedVersionless();
parentParentOrgId = myOrganizationDao.create(org, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
}
IIdType parentOrgId;
{
Organization org = new Organization();
org.getNameElement().setValue(methodName + "_O1Parent");
org.setPartOf(new ResourceReferenceDt(parentParentOrgId));
parentOrgId = myOrganizationDao.create(org).getId().toUnqualifiedVersionless();
parentOrgId = myOrganizationDao.create(org, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
}
IIdType orgId;
{
Organization org = new Organization();
org.getNameElement().setValue(methodName + "_O1");
org.setPartOf(new ResourceReferenceDt(parentOrgId));
orgId = myOrganizationDao.create(org).getId().toUnqualifiedVersionless();
orgId = myOrganizationDao.create(org, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
}
IIdType patientId;
{
@ -1708,7 +1709,7 @@ public class FhirResourceDaoDstu2SearchNoFtTest extends BaseJpaDstu2Test {
patient.addIdentifier().setSystem("urn:system").setValue("001");
patient.addName().addFamily("Tester_" + methodName + "_P1").addGiven("Joe");
patient.getManagingOrganization().setReference(orgId);
patientId = myPatientDao.create(patient).getId().toUnqualifiedVersionless();
patientId = myPatientDao.create(patient, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
}
{
@ -1729,20 +1730,20 @@ public class FhirResourceDaoDstu2SearchNoFtTest extends BaseJpaDstu2Test {
Organization org = new Organization();
org.setId("testSearchWithIncludesThatHaveTextIdid1");
org.getNameElement().setValue("testSearchWithIncludesThatHaveTextId_O1");
IIdType orgId = myOrganizationDao.update(org).getId();
IIdType orgId = myOrganizationDao.update(org, new ServletRequestDetails()).getId();
assertThat(orgId.getValue(), endsWith("Organization/testSearchWithIncludesThatHaveTextIdid1/_history/1"));
Patient patient = new Patient();
patient.addIdentifier().setSystem("urn:system").setValue("001");
patient.addName().addFamily("Tester_testSearchWithIncludesThatHaveTextId_P1").addGiven("Joe");
patient.getManagingOrganization().setReference(orgId);
myPatientDao.create(patient);
myPatientDao.create(patient, new ServletRequestDetails());
}
{
Patient patient = new Patient();
patient.addIdentifier().setSystem("urn:system").setValue("002");
patient.addName().addFamily("Tester_testSearchWithIncludesThatHaveTextId_P2").addGiven("John");
myPatientDao.create(patient);
myPatientDao.create(patient, new ServletRequestDetails());
}
SearchParameterMap params = new SearchParameterMap();
@ -1763,13 +1764,13 @@ public class FhirResourceDaoDstu2SearchNoFtTest extends BaseJpaDstu2Test {
@Test
public void testSearchWithMissingDate() {
IIdType orgId = myOrganizationDao.create(new Organization()).getId();
IIdType orgId = myOrganizationDao.create(new Organization(), new ServletRequestDetails()).getId();
IIdType notMissing;
IIdType missing;
{
Patient patient = new Patient();
patient.addIdentifier().setSystem("urn:system").setValue("001");
missing = myPatientDao.create(patient).getId().toUnqualifiedVersionless();
missing = myPatientDao.create(patient, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
}
{
Patient patient = new Patient();
@ -1777,7 +1778,7 @@ public class FhirResourceDaoDstu2SearchNoFtTest extends BaseJpaDstu2Test {
patient.addName().addFamily("Tester_testSearchStringParam").addGiven("John");
patient.setBirthDate(new DateDt("2011-01-01"));
patient.getManagingOrganization().setReference(orgId);
notMissing = myPatientDao.create(patient).getId().toUnqualifiedVersionless();
notMissing = myPatientDao.create(patient, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
}
// Date Param
{
@ -1807,13 +1808,13 @@ public class FhirResourceDaoDstu2SearchNoFtTest extends BaseJpaDstu2Test {
{
Observation obs = new Observation();
obs.addIdentifier().setSystem("urn:system").setValue("001");
missing = myObservationDao.create(obs).getId().toUnqualifiedVersionless();
missing = myObservationDao.create(obs, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
}
{
Observation obs = new Observation();
obs.addIdentifier().setSystem("urn:system").setValue("002");
obs.setValue(new QuantityDt(123));
notMissing = myObservationDao.create(obs).getId().toUnqualifiedVersionless();
notMissing = myObservationDao.create(obs, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
}
// Quantity Param
{
@ -1838,13 +1839,13 @@ public class FhirResourceDaoDstu2SearchNoFtTest extends BaseJpaDstu2Test {
@Test
public void testSearchWithMissingReference() {
IIdType orgId = myOrganizationDao.create(new Organization()).getId().toUnqualifiedVersionless();
IIdType orgId = myOrganizationDao.create(new Organization(), new ServletRequestDetails()).getId().toUnqualifiedVersionless();
IIdType notMissing;
IIdType missing;
{
Patient patient = new Patient();
patient.addIdentifier().setSystem("urn:system").setValue("001");
missing = myPatientDao.create(patient).getId().toUnqualifiedVersionless();
missing = myPatientDao.create(patient, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
}
{
Patient patient = new Patient();
@ -1852,7 +1853,7 @@ public class FhirResourceDaoDstu2SearchNoFtTest extends BaseJpaDstu2Test {
patient.addName().addFamily("Tester_testSearchStringParam").addGiven("John");
patient.setBirthDate(new DateDt("2011-01-01"));
patient.getManagingOrganization().setReference(orgId);
notMissing = myPatientDao.create(patient).getId().toUnqualifiedVersionless();
notMissing = myPatientDao.create(patient, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
}
// Reference Param
{
@ -1878,13 +1879,13 @@ public class FhirResourceDaoDstu2SearchNoFtTest extends BaseJpaDstu2Test {
@Test
public void testSearchWithMissingString() {
IIdType orgId = myOrganizationDao.create(new Organization()).getId();
IIdType orgId = myOrganizationDao.create(new Organization(), new ServletRequestDetails()).getId();
IIdType notMissing;
IIdType missing;
{
Patient patient = new Patient();
patient.addIdentifier().setSystem("urn:system").setValue("001");
missing = myPatientDao.create(patient).getId().toUnqualifiedVersionless();
missing = myPatientDao.create(patient, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
}
{
Patient patient = new Patient();
@ -1892,7 +1893,7 @@ public class FhirResourceDaoDstu2SearchNoFtTest extends BaseJpaDstu2Test {
patient.addName().addFamily("Tester_testSearchStringParam").addGiven("John");
patient.setBirthDate(new DateDt("2011-01-01"));
patient.getManagingOrganization().setReference(orgId);
notMissing = myPatientDao.create(patient).getId().toUnqualifiedVersionless();
notMissing = myPatientDao.create(patient, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
}
// String Param
{
@ -1919,13 +1920,13 @@ public class FhirResourceDaoDstu2SearchNoFtTest extends BaseJpaDstu2Test {
public void testSearchWithNoResults() {
Device dev = new Device();
dev.addIdentifier().setSystem("Foo");
myDeviceDao.create(dev);
myDeviceDao.create(dev, new ServletRequestDetails());
IBundleProvider value = myDeviceDao.search(new SearchParameterMap());
ourLog.info("Initial size: " + value.size());
for (IBaseResource next : value.getResources(0, value.size())) {
ourLog.info("Deleting: {}", next.getIdElement());
myDeviceDao.delete((IIdType) next.getIdElement());
myDeviceDao.delete((IIdType) next.getIdElement(), new ServletRequestDetails());
}
value = myDeviceDao.search(new SearchParameterMap());
@ -1951,7 +1952,7 @@ public class FhirResourceDaoDstu2SearchNoFtTest extends BaseJpaDstu2Test {
List<BaseCodingDt> security = new ArrayList<BaseCodingDt>();
security.add(new CodingDt("urn:taglist", methodName + "1a"));
ResourceMetadataKeyEnum.SECURITY_LABELS.put(org, security);
tag1id = myOrganizationDao.create(org).getId().toUnqualifiedVersionless();
tag1id = myOrganizationDao.create(org, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
}
IIdType tag2id;
{
@ -1960,7 +1961,7 @@ public class FhirResourceDaoDstu2SearchNoFtTest extends BaseJpaDstu2Test {
List<IdDt> security = new ArrayList<IdDt>();
security.add(new IdDt("http://" + methodName));
ResourceMetadataKeyEnum.PROFILES.put(org, security);
tag2id = myOrganizationDao.create(org).getId().toUnqualifiedVersionless();
tag2id = myOrganizationDao.create(org, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
}
{
SearchParameterMap params = new SearchParameterMap();
@ -1988,7 +1989,7 @@ public class FhirResourceDaoDstu2SearchNoFtTest extends BaseJpaDstu2Test {
tagList.addTag("urn:taglist", methodName + "1a");
tagList.addTag("urn:taglist", methodName + "1b");
ResourceMetadataKeyEnum.TAG_LIST.put(org, tagList);
tag1id = myOrganizationDao.create(org).getId().toUnqualifiedVersionless();
tag1id = myOrganizationDao.create(org, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
}
Date betweenDate = new Date();
@ -2001,7 +2002,7 @@ public class FhirResourceDaoDstu2SearchNoFtTest extends BaseJpaDstu2Test {
tagList.addTag("urn:taglist", methodName + "2a");
tagList.addTag("urn:taglist", methodName + "2b");
ResourceMetadataKeyEnum.TAG_LIST.put(org, tagList);
tag2id = myOrganizationDao.create(org).getId().toUnqualifiedVersionless();
tag2id = myOrganizationDao.create(org, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
}
{
@ -2071,13 +2072,13 @@ public class FhirResourceDaoDstu2SearchNoFtTest extends BaseJpaDstu2Test {
{
Observation obs = new Observation();
obs.addIdentifier().setSystem("urn:system").setValue("001");
missing = myObservationDao.create(obs).getId().toUnqualifiedVersionless();
missing = myObservationDao.create(obs, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
}
{
Observation obs = new Observation();
obs.addIdentifier().setSystem("urn:system").setValue("002");
obs.getCode().addCoding().setSystem("urn:system").setCode("002");
notMissing = myObservationDao.create(obs).getId().toUnqualifiedVersionless();
notMissing = myObservationDao.create(obs, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
}
// Token Param
{
@ -2105,7 +2106,7 @@ public class FhirResourceDaoDstu2SearchNoFtTest extends BaseJpaDstu2Test {
Class<ValueSet> type = ValueSet.class;
String resourceName = "/valueset-dstu2.json";
ValueSet vs = loadResourceFromClasspath(type, resourceName);
myValueSetDao.update(vs);
myValueSetDao.update(vs, new ServletRequestDetails());
IBundleProvider result = myValueSetDao.search(ValueSet.SP_URL, new UriParam("http://hl7.org/fhir/ValueSet/basic-resource-type"));
assertThat(toUnqualifiedVersionlessIds(result), contains((IIdType) new IdDt("ValueSet/testSearchWithUriParam")));

View File

@ -38,6 +38,7 @@ import ca.uhn.fhir.model.dstu2.valueset.SubscriptionStatusEnum;
import ca.uhn.fhir.rest.server.IBundleProvider;
import ca.uhn.fhir.rest.server.exceptions.ResourceGoneException;
import ca.uhn.fhir.rest.server.exceptions.UnprocessableEntityException;
import ca.uhn.fhir.rest.server.servlet.ServletRequestDetails;
public class FhirResourceDaoDstu2SubscriptionTest extends BaseJpaDstu2Test {
@ -64,16 +65,16 @@ public class FhirResourceDaoDstu2SubscriptionTest extends BaseJpaDstu2Test {
subs.getChannel().setType(SubscriptionChannelTypeEnum.WEBSOCKET);
subs.setStatus(SubscriptionStatusEnum.REQUESTED);
IIdType id = mySubscriptionDao.create(subs).getId().toUnqualifiedVersionless();
IIdType id = mySubscriptionDao.create(subs, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
mySubscriptionDao.purgeInactiveSubscriptions();
mySubscriptionDao.read(id);
mySubscriptionDao.read(id, new ServletRequestDetails());
Thread.sleep(1500);
myDaoConfig.setSchedulingDisabled(false);
mySubscriptionDao.purgeInactiveSubscriptions();
try {
mySubscriptionDao.read(id);
mySubscriptionDao.read(id, new ServletRequestDetails());
fail();
} catch (ResourceGoneException e) {
// good
@ -95,9 +96,9 @@ public class FhirResourceDaoDstu2SubscriptionTest extends BaseJpaDstu2Test {
subs.getChannel().setType(SubscriptionChannelTypeEnum.WEBSOCKET);
subs.setStatus(SubscriptionStatusEnum.REQUESTED);
IIdType id = mySubscriptionDao.create(subs).getId().toUnqualifiedVersionless();
IIdType id = mySubscriptionDao.create(subs, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
mySubscriptionDao.purgeInactiveSubscriptions();
mySubscriptionDao.read(id);
mySubscriptionDao.read(id, new ServletRequestDetails());
mySubscriptionDao.getUndeliveredResourcesAndPurge(mySubscriptionDao.getSubscriptionTablePidForSubscriptionResource(id));
@ -106,7 +107,7 @@ public class FhirResourceDaoDstu2SubscriptionTest extends BaseJpaDstu2Test {
myDaoConfig.setSchedulingDisabled(false);
mySubscriptionDao.purgeInactiveSubscriptions();
try {
mySubscriptionDao.read(id);
mySubscriptionDao.read(id, new ServletRequestDetails());
fail();
} catch (ResourceGoneException e) {
// good
@ -120,7 +121,7 @@ public class FhirResourceDaoDstu2SubscriptionTest extends BaseJpaDstu2Test {
subs.getChannel().setType(SubscriptionChannelTypeEnum.WEBSOCKET);
subs.setStatus(SubscriptionStatusEnum.REQUESTED);
IIdType id = mySubscriptionDao.create(subs).getId().toUnqualifiedVersionless();
IIdType id = mySubscriptionDao.create(subs, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
TypedQuery<SubscriptionTable> q = myEntityManager.createQuery("SELECT t from SubscriptionTable t WHERE t.mySubscriptionResource.myId = :id", SubscriptionTable.class);
q.setParameter("id", id.getIdPartAsLong());
@ -130,15 +131,15 @@ public class FhirResourceDaoDstu2SubscriptionTest extends BaseJpaDstu2Test {
assertNotNull(table.getNextCheck());
assertEquals(table.getNextCheck(), table.getSubscriptionResource().getPublished().getValue());
assertEquals(SubscriptionStatusEnum.REQUESTED.getCode(), myEntityManager.find(SubscriptionTable.class, table.getId()).getStatus());
assertEquals(SubscriptionStatusEnum.REQUESTED, mySubscriptionDao.read(id).getStatusElement().getValueAsEnum());
assertEquals(SubscriptionStatusEnum.REQUESTED, mySubscriptionDao.read(id, new ServletRequestDetails()).getStatusElement().getValueAsEnum());
subs.setStatus(SubscriptionStatusEnum.ACTIVE);
mySubscriptionDao.update(subs);
mySubscriptionDao.update(subs, new ServletRequestDetails());
assertEquals(SubscriptionStatusEnum.ACTIVE.getCode(), myEntityManager.find(SubscriptionTable.class, table.getId()).getStatus());
assertEquals(SubscriptionStatusEnum.ACTIVE, mySubscriptionDao.read(id).getStatusElement().getValueAsEnum());
assertEquals(SubscriptionStatusEnum.ACTIVE, mySubscriptionDao.read(id, new ServletRequestDetails()).getStatusElement().getValueAsEnum());
mySubscriptionDao.delete(id);
mySubscriptionDao.delete(id, new ServletRequestDetails());
assertNull(myEntityManager.find(SubscriptionTable.class, table.getId()));
@ -151,10 +152,10 @@ public class FhirResourceDaoDstu2SubscriptionTest extends BaseJpaDstu2Test {
subs.getChannel().setType(SubscriptionChannelTypeEnum.WEBSOCKET);
subs.setId(id);
subs.setStatus(SubscriptionStatusEnum.REQUESTED);
mySubscriptionDao.update(subs);
mySubscriptionDao.update(subs, new ServletRequestDetails());
assertEquals(SubscriptionStatusEnum.REQUESTED.getCode(), myEntityManager.createQuery("SELECT t FROM SubscriptionTable t WHERE t.myResId = " + id.getIdPart(), SubscriptionTable.class).getSingleResult().getStatus());
assertEquals(SubscriptionStatusEnum.REQUESTED, mySubscriptionDao.read(id).getStatusElement().getValueAsEnum());
assertEquals(SubscriptionStatusEnum.REQUESTED, mySubscriptionDao.read(id, new ServletRequestDetails()).getStatusElement().getValueAsEnum());
}
@Test
@ -163,7 +164,7 @@ public class FhirResourceDaoDstu2SubscriptionTest extends BaseJpaDstu2Test {
subs.setStatus(SubscriptionStatusEnum.REQUESTED);
subs.setCriteria("Observation");
try {
mySubscriptionDao.create(subs);
mySubscriptionDao.create(subs, new ServletRequestDetails());
fail();
} catch (UnprocessableEntityException e) {
assertThat(e.getMessage(), containsString("Subscription.criteria must be in the form \"{Resource Type}?[params]\""));
@ -173,7 +174,7 @@ public class FhirResourceDaoDstu2SubscriptionTest extends BaseJpaDstu2Test {
subs.setStatus(SubscriptionStatusEnum.REQUESTED);
subs.setCriteria("http://foo.com/Observation?AAA=BBB");
try {
mySubscriptionDao.create(subs);
mySubscriptionDao.create(subs, new ServletRequestDetails());
fail();
} catch (UnprocessableEntityException e) {
assertThat(e.getMessage(), containsString("Subscription.criteria must be in the form \"{Resource Type}?[params]\""));
@ -183,7 +184,7 @@ public class FhirResourceDaoDstu2SubscriptionTest extends BaseJpaDstu2Test {
subs.setStatus(SubscriptionStatusEnum.REQUESTED);
subs.setCriteria("ObservationZZZZ?a=b");
try {
mySubscriptionDao.create(subs);
mySubscriptionDao.create(subs, new ServletRequestDetails());
fail();
} catch (UnprocessableEntityException e) {
assertThat(e.getMessage(), containsString("Subscription.criteria contains invalid/unsupported resource type: ObservationZZZZ"));
@ -193,7 +194,7 @@ public class FhirResourceDaoDstu2SubscriptionTest extends BaseJpaDstu2Test {
subs.setStatus(SubscriptionStatusEnum.REQUESTED);
subs.setCriteria("Observation?identifier=123");
try {
mySubscriptionDao.create(subs);
mySubscriptionDao.create(subs, new ServletRequestDetails());
fail();
} catch (UnprocessableEntityException e) {
assertThat(e.getMessage(), containsString("Subscription.channel.type must be populated on this server"));
@ -203,7 +204,7 @@ public class FhirResourceDaoDstu2SubscriptionTest extends BaseJpaDstu2Test {
subs.setStatus(SubscriptionStatusEnum.REQUESTED);
subs.setCriteria("Observation?identifier=123");
subs.getChannel().setType(SubscriptionChannelTypeEnum.WEBSOCKET);
assertTrue(mySubscriptionDao.create(subs).getId().hasIdPart());
assertTrue(mySubscriptionDao.create(subs, new ServletRequestDetails()).getId().hasIdPart());
}
@ -214,7 +215,7 @@ public class FhirResourceDaoDstu2SubscriptionTest extends BaseJpaDstu2Test {
String methodName = "testDeleteSubscriptionWithFlaggedResources";
Patient p = new Patient();
p.addName().addFamily(methodName);
IIdType pId = myPatientDao.create(p).getId().toUnqualifiedVersionless();
IIdType pId = myPatientDao.create(p, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
Subscription subs;
@ -226,7 +227,7 @@ public class FhirResourceDaoDstu2SubscriptionTest extends BaseJpaDstu2Test {
subs.getChannel().setType(SubscriptionChannelTypeEnum.WEBSOCKET);
subs.setCriteria("Observation?subject=Patient/" + pId.getIdPart());
subs.setStatus(SubscriptionStatusEnum.ACTIVE);
IIdType subsId = mySubscriptionDao.create(subs).getId().toUnqualifiedVersionless();
IIdType subsId = mySubscriptionDao.create(subs, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
Long subsPid = mySubscriptionDao.getSubscriptionTablePidForSubscriptionResource(subsId);
assertNull(mySubscriptionTableDao.findOne(subsPid).getLastClientPoll());
@ -239,12 +240,12 @@ public class FhirResourceDaoDstu2SubscriptionTest extends BaseJpaDstu2Test {
Observation obs = new Observation();
obs.getSubject().setReference(pId);
obs.setStatus(ObservationStatusEnum.FINAL);
myObservationDao.create(obs).getId().toUnqualifiedVersionless();
myObservationDao.create(obs, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
obs = new Observation();
obs.getSubject().setReference(pId);
obs.setStatus(ObservationStatusEnum.FINAL);
myObservationDao.create(obs).getId().toUnqualifiedVersionless();
myObservationDao.create(obs, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
Thread.sleep(100);
@ -258,7 +259,7 @@ public class FhirResourceDaoDstu2SubscriptionTest extends BaseJpaDstu2Test {
* Delete the subscription
*/
mySubscriptionDao.delete(subsId);
mySubscriptionDao.delete(subsId, new ServletRequestDetails());
assertThat(mySubscriptionFlaggedResourceDataDao.count(), not(greaterThan(0L)));
assertThat(mySubscriptionTableDao.count(), not(greaterThan(0L)));
@ -266,14 +267,14 @@ public class FhirResourceDaoDstu2SubscriptionTest extends BaseJpaDstu2Test {
/*
* Delete a second time just to make sure that works
*/
mySubscriptionDao.delete(subsId);
mySubscriptionDao.delete(subsId, new ServletRequestDetails());
/*
* Re-create the subscription
*/
subs.setId(subsId);
mySubscriptionDao.update(subs).getId();
mySubscriptionDao.update(subs, new ServletRequestDetails()).getId();
assertThat(mySubscriptionFlaggedResourceDataDao.count(), not(greaterThan(0L)));
assertThat(mySubscriptionTableDao.count(), (greaterThan(0L)));
@ -285,7 +286,7 @@ public class FhirResourceDaoDstu2SubscriptionTest extends BaseJpaDstu2Test {
obs = new Observation();
obs.getSubject().setReference(pId);
obs.setStatus(ObservationStatusEnum.FINAL);
myObservationDao.create(obs).getId().toUnqualifiedVersionless();
myObservationDao.create(obs, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
Thread.sleep(100);
@ -302,12 +303,12 @@ public class FhirResourceDaoDstu2SubscriptionTest extends BaseJpaDstu2Test {
String methodName = "testSubscriptionResourcesAppear";
Patient p = new Patient();
p.addName().addFamily(methodName);
IIdType pId = myPatientDao.create(p).getId().toUnqualifiedVersionless();
IIdType pId = myPatientDao.create(p, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
Observation obs = new Observation();
obs.getSubject().setReference(pId);
obs.setStatus(ObservationStatusEnum.FINAL);
myObservationDao.create(obs).getId().toUnqualifiedVersionless();
myObservationDao.create(obs, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
Subscription subs;
@ -319,13 +320,13 @@ public class FhirResourceDaoDstu2SubscriptionTest extends BaseJpaDstu2Test {
subs.getChannel().setType(SubscriptionChannelTypeEnum.WEBSOCKET);
subs.setCriteria("Observation?subject=Patient/" + pId.getIdPart());
subs.setStatus(SubscriptionStatusEnum.ACTIVE);
Long subsId1 = mySubscriptionDao.getSubscriptionTablePidForSubscriptionResource(mySubscriptionDao.create(subs).getId());
Long subsId1 = mySubscriptionDao.getSubscriptionTablePidForSubscriptionResource(mySubscriptionDao.create(subs, new ServletRequestDetails()).getId());
subs = new Subscription();
subs.getChannel().setType(SubscriptionChannelTypeEnum.WEBSOCKET);
subs.setCriteria("Observation?subject=Patient/" + pId.getIdPart());
subs.setStatus(SubscriptionStatusEnum.ACTIVE);
Long subsId2 = mySubscriptionDao.getSubscriptionTablePidForSubscriptionResource(mySubscriptionDao.create(subs).getId());
Long subsId2 = mySubscriptionDao.getSubscriptionTablePidForSubscriptionResource(mySubscriptionDao.create(subs, new ServletRequestDetails()).getId());
assertNull(mySubscriptionTableDao.findOne(subsId1).getLastClientPoll());
@ -335,12 +336,12 @@ public class FhirResourceDaoDstu2SubscriptionTest extends BaseJpaDstu2Test {
obs = new Observation();
obs.getSubject().setReference(pId);
obs.setStatus(ObservationStatusEnum.FINAL);
IIdType afterId1 = myObservationDao.create(obs).getId().toUnqualifiedVersionless();
IIdType afterId1 = myObservationDao.create(obs, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
obs = new Observation();
obs.getSubject().setReference(pId);
obs.setStatus(ObservationStatusEnum.FINAL);
IIdType afterId2 = myObservationDao.create(obs).getId().toUnqualifiedVersionless();
IIdType afterId2 = myObservationDao.create(obs, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
Thread.sleep(100);
@ -381,7 +382,7 @@ public class FhirResourceDaoDstu2SubscriptionTest extends BaseJpaDstu2Test {
*/
mySystemDao.markAllResourcesForReindexing();
mySystemDao.performReindexingPass(100);
mySystemDao.performReindexingPass(100, new ServletRequestDetails());
assertEquals(0, mySubscriptionDao.pollForNewUndeliveredResources());
@ -394,7 +395,7 @@ public class FhirResourceDaoDstu2SubscriptionTest extends BaseJpaDstu2Test {
ourLog.info("Updating observation");
Observation nextObs = (Observation) next;
nextObs.addPerformer().setDisplay("Some display");
myObservationDao.update(nextObs);
myObservationDao.update(nextObs, new ServletRequestDetails());
}
assertEquals(6, mySubscriptionDao.pollForNewUndeliveredResources());
@ -410,12 +411,12 @@ public class FhirResourceDaoDstu2SubscriptionTest extends BaseJpaDstu2Test {
String methodName = "testSubscriptionResourcesAppear2";
Patient p = new Patient();
p.addName().addFamily(methodName);
IIdType pId = myPatientDao.create(p).getId().toUnqualifiedVersionless();
IIdType pId = myPatientDao.create(p, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
Observation obs = new Observation();
obs.getSubject().setReference(pId);
obs.setStatus(ObservationStatusEnum.FINAL);
IIdType oId = myObservationDao.create(obs).getId().toUnqualifiedVersionless();
IIdType oId = myObservationDao.create(obs, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
Subscription subs;
@ -427,7 +428,7 @@ public class FhirResourceDaoDstu2SubscriptionTest extends BaseJpaDstu2Test {
subs.getChannel().setType(SubscriptionChannelTypeEnum.WEBSOCKET);
subs.setCriteria("Observation?subject=Patient/" + pId.getIdPart());
subs.setStatus(SubscriptionStatusEnum.ACTIVE);
Long subsId1 = mySubscriptionDao.getSubscriptionTablePidForSubscriptionResource(mySubscriptionDao.create(subs).getId());
Long subsId1 = mySubscriptionDao.getSubscriptionTablePidForSubscriptionResource(mySubscriptionDao.create(subs, new ServletRequestDetails()).getId());
assertNull(mySubscriptionTableDao.findOne(subsId1).getLastClientPoll());
@ -435,7 +436,7 @@ public class FhirResourceDaoDstu2SubscriptionTest extends BaseJpaDstu2Test {
ourLog.info("pId: {} - oId: {}", pId, oId);
myObservationDao.update(myObservationDao.read(oId));
myObservationDao.update(myObservationDao.read(oId, new ServletRequestDetails()), new ServletRequestDetails());
assertEquals(1, mySubscriptionDao.pollForNewUndeliveredResources());
ourLog.info("Between passes");
@ -447,12 +448,12 @@ public class FhirResourceDaoDstu2SubscriptionTest extends BaseJpaDstu2Test {
obs = new Observation();
obs.getSubject().setReference(pId);
obs.setStatus(ObservationStatusEnum.FINAL);
myObservationDao.create(obs).getId().toUnqualifiedVersionless();
myObservationDao.create(obs, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
obs = new Observation();
obs.getSubject().setReference(pId);
obs.setStatus(ObservationStatusEnum.FINAL);
myObservationDao.create(obs).getId().toUnqualifiedVersionless();
myObservationDao.create(obs, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
Thread.sleep(100);
@ -476,7 +477,7 @@ public class FhirResourceDaoDstu2SubscriptionTest extends BaseJpaDstu2Test {
obs = new Observation();
obs.getSubject().setReference(pId);
obs.setStatus(ObservationStatusEnum.FINAL);
myObservationDao.create(obs).getId().toUnqualifiedVersionless();
myObservationDao.create(obs, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
mySubscriptionDao.pollForNewUndeliveredResources();
assertEquals(4, mySubscriptionFlaggedResourceDataDao.count());

View File

@ -44,6 +44,7 @@ import ca.uhn.fhir.rest.server.IBundleProvider;
import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException;
import ca.uhn.fhir.rest.server.exceptions.UnprocessableEntityException;
import ca.uhn.fhir.rest.server.interceptor.IServerInterceptor.ActionRequestDetails;
import ca.uhn.fhir.rest.server.servlet.ServletRequestDetails;
public class FhirResourceDaoDstu2UpdateTest extends BaseJpaDstu2Test {
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(FhirResourceDaoDstu2UpdateTest.class);
@ -54,14 +55,14 @@ public class FhirResourceDaoDstu2UpdateTest extends BaseJpaDstu2Test {
patient.addIdentifier().setSystem("urn:system").setValue("001");
patient.addName().addFamily("Tester").addGiven("Joe");
MethodOutcome outcome = myPatientDao.create(patient);
MethodOutcome outcome = myPatientDao.create(patient, new ServletRequestDetails());
assertNotNull(outcome.getId());
assertFalse(outcome.getId().isEmpty());
assertEquals("1", outcome.getId().getVersionIdPart());
Date now = new Date();
Patient retrieved = myPatientDao.read(outcome.getId());
Patient retrieved = myPatientDao.read(outcome.getId(), new ServletRequestDetails());
InstantDt published = (InstantDt) retrieved.getResourceMetadata().get(ResourceMetadataKeyEnum.PUBLISHED);
InstantDt updated = (InstantDt) retrieved.getResourceMetadata().get(ResourceMetadataKeyEnum.UPDATED);
assertTrue(published.before(now));
@ -71,7 +72,7 @@ public class FhirResourceDaoDstu2UpdateTest extends BaseJpaDstu2Test {
reset(myInterceptor);
retrieved.getIdentifierFirstRep().setValue("002");
MethodOutcome outcome2 = myPatientDao.update(retrieved);
MethodOutcome outcome2 = myPatientDao.update(retrieved, new ServletRequestDetails());
assertEquals(outcome.getId().getIdPart(), outcome2.getId().getIdPart());
assertNotEquals(outcome.getId().getVersionIdPart(), outcome2.getId().getVersionIdPart());
assertEquals("2", outcome2.getId().getVersionIdPart());
@ -86,7 +87,7 @@ public class FhirResourceDaoDstu2UpdateTest extends BaseJpaDstu2Test {
Date now2 = new Date();
Patient retrieved2 = myPatientDao.read(outcome.getId().toVersionless());
Patient retrieved2 = myPatientDao.read(outcome.getId().toVersionless(), new ServletRequestDetails());
assertEquals("2", retrieved2.getId().getVersionIdPart());
assertEquals("002", retrieved2.getIdentifierFirstRep().getValue());
@ -102,7 +103,7 @@ public class FhirResourceDaoDstu2UpdateTest extends BaseJpaDstu2Test {
* Get history
*/
IBundleProvider historyBundle = myPatientDao.history(outcome.getId(), null);
IBundleProvider historyBundle = myPatientDao.history(outcome.getId(), null, new ServletRequestDetails());
assertEquals(2, historyBundle.size());
@ -125,7 +126,7 @@ public class FhirResourceDaoDstu2UpdateTest extends BaseJpaDstu2Test {
Patient p = new Patient();
p.addIdentifier().setSystem("urn:system").setValue(methodName);
IIdType id = myPatientDao.create(p).getId();
IIdType id = myPatientDao.create(p, new ServletRequestDetails()).getId();
ourLog.info("Created patient, got it: {}", id);
p = new Patient();
@ -133,9 +134,9 @@ public class FhirResourceDaoDstu2UpdateTest extends BaseJpaDstu2Test {
p.addName().addFamily("Hello");
p.setId("Patient/" + methodName);
myPatientDao.update(p, "Patient?identifier=urn%3Asystem%7C" + methodName);
myPatientDao.update(p, "Patient?identifier=urn%3Asystem%7C" + methodName, new ServletRequestDetails());
p = myPatientDao.read(id.toVersionless());
p = myPatientDao.read(id.toVersionless(), new ServletRequestDetails());
assertThat(p.getId().toVersionless().toString(), not(containsString("test")));
assertEquals(id.toVersionless(), p.getId().toVersionless());
assertNotEquals(id, p.getId());
@ -151,10 +152,10 @@ public class FhirResourceDaoDstu2UpdateTest extends BaseJpaDstu2Test {
p.addName().addFamily("Hello");
p.setId("Patient/" + methodName);
IIdType id = myPatientDao.update(p).getId();
IIdType id = myPatientDao.update(p, new ServletRequestDetails()).getId();
assertEquals("Patient/" + methodName, id.toUnqualifiedVersionless().getValue());
p = myPatientDao.read(id);
p = myPatientDao.read(id, new ServletRequestDetails());
assertEquals(methodName, p.getIdentifierFirstRep().getValue());
}
@ -165,7 +166,7 @@ public class FhirResourceDaoDstu2UpdateTest extends BaseJpaDstu2Test {
p.setId("0" + methodName);
p.addName().addFamily(methodName);
myPatientDao.update(p);
myPatientDao.update(p, new ServletRequestDetails());
}
/**
@ -190,7 +191,7 @@ public class FhirResourceDaoDstu2UpdateTest extends BaseJpaDstu2Test {
profileList.add(new IdDt("http://foo1"));
ResourceMetadataKeyEnum.PROFILES.put(p1, profileList);
p1id = myPatientDao.create(p1).getId().toUnqualifiedVersionless();
p1id = myPatientDao.create(p1, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
}
{
Patient p1 = new Patient();
@ -207,10 +208,10 @@ public class FhirResourceDaoDstu2UpdateTest extends BaseJpaDstu2Test {
profileList.add(new IdDt("http://foo2"));
ResourceMetadataKeyEnum.PROFILES.put(p1, profileList);
myPatientDao.update(p1);
myPatientDao.update(p1, new ServletRequestDetails());
}
{
Patient p1 = myPatientDao.read(p1id);
Patient p1 = myPatientDao.read(p1id, new ServletRequestDetails());
TagList tagList = ResourceMetadataKeyEnum.TAG_LIST.get(p1);
assertThat(tagList, containsInAnyOrder(new Tag("tag_scheme1", "tag_term1"), new Tag("tag_scheme2", "tag_term2")));
List<BaseCodingDt> secList = ResourceMetadataKeyEnum.SECURITY_LABELS.get(p1);
@ -229,12 +230,12 @@ public class FhirResourceDaoDstu2UpdateTest extends BaseJpaDstu2Test {
Patient p1 = new Patient();
p1.addIdentifier().setSystem("urn:system").setValue("testUpdateMaintainsSearchParamsDstu2AAA");
p1.addName().addFamily("Tester").addGiven("testUpdateMaintainsSearchParamsDstu2AAA");
IIdType p1id = myPatientDao.create(p1).getId();
IIdType p1id = myPatientDao.create(p1, new ServletRequestDetails()).getId();
Patient p2 = new Patient();
p2.addIdentifier().setSystem("urn:system").setValue("testUpdateMaintainsSearchParamsDstu2BBB");
p2.addName().addFamily("Tester").addGiven("testUpdateMaintainsSearchParamsDstu2BBB");
myPatientDao.create(p2).getId();
myPatientDao.create(p2, new ServletRequestDetails()).getId();
Set<Long> ids = myPatientDao.searchForIds(Patient.SP_GIVEN, new StringDt("testUpdateMaintainsSearchParamsDstu2AAA"));
assertEquals(1, ids.size());
@ -242,7 +243,7 @@ public class FhirResourceDaoDstu2UpdateTest extends BaseJpaDstu2Test {
// Update the name
p1.getNameFirstRep().getGivenFirstRep().setValue("testUpdateMaintainsSearchParamsDstu2BBB");
MethodOutcome update2 = myPatientDao.update(p1);
MethodOutcome update2 = myPatientDao.update(p1, new ServletRequestDetails());
IIdType p1id2 = update2.getId();
ids = myPatientDao.searchForIds(Patient.SP_GIVEN, new StringDt("testUpdateMaintainsSearchParamsDstu2AAA"));
@ -252,10 +253,10 @@ public class FhirResourceDaoDstu2UpdateTest extends BaseJpaDstu2Test {
assertEquals(2, ids.size());
// Make sure vreads work
p1 = myPatientDao.read(p1id);
p1 = myPatientDao.read(p1id, new ServletRequestDetails());
assertEquals("testUpdateMaintainsSearchParamsDstu2AAA", p1.getNameFirstRep().getGivenAsSingleString());
p1 = myPatientDao.read(p1id2);
p1 = myPatientDao.read(p1id2, new ServletRequestDetails());
assertEquals("testUpdateMaintainsSearchParamsDstu2BBB", p1.getNameFirstRep().getGivenAsSingleString());
}
@ -265,13 +266,13 @@ public class FhirResourceDaoDstu2UpdateTest extends BaseJpaDstu2Test {
Patient p1 = new Patient();
p1.addIdentifier().setSystem("urn:system").setValue("testUpdateRejectsInvalidTypes");
p1.addName().addFamily("Tester").addGiven("testUpdateRejectsInvalidTypes");
IIdType p1id = myPatientDao.create(p1).getId();
IIdType p1id = myPatientDao.create(p1, new ServletRequestDetails()).getId();
Organization p2 = new Organization();
p2.getNameElement().setValue("testUpdateRejectsInvalidTypes");
try {
p2.setId(new IdDt("Organization/" + p1id.getIdPart()));
myOrganizationDao.update(p2);
myOrganizationDao.update(p2, new ServletRequestDetails());
fail();
} catch (UnprocessableEntityException e) {
// good
@ -279,7 +280,7 @@ public class FhirResourceDaoDstu2UpdateTest extends BaseJpaDstu2Test {
try {
p2.setId(new IdDt("Patient/" + p1id.getIdPart()));
myOrganizationDao.update(p2);
myOrganizationDao.update(p2, new ServletRequestDetails());
fail();
} catch (UnprocessableEntityException e) {
ourLog.error("Good", e);
@ -301,12 +302,12 @@ public class FhirResourceDaoDstu2UpdateTest extends BaseJpaDstu2Test {
tl.add(new IdDt("http://foo/bar"));
ResourceMetadataKeyEnum.PROFILES.put(patient, tl);
id = myPatientDao.create(patient).getId().toUnqualifiedVersionless();
id = myPatientDao.create(patient, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
}
// Do a read
{
Patient patient = myPatientDao.read(id);
Patient patient = myPatientDao.read(id, new ServletRequestDetails());
List<IdDt> tl = ResourceMetadataKeyEnum.PROFILES.get(patient);
assertEquals(1, tl.size());
assertEquals("http://foo/bar", tl.get(0).getValue());
@ -326,12 +327,12 @@ public class FhirResourceDaoDstu2UpdateTest extends BaseJpaDstu2Test {
tl.add(new IdDt("http://foo/bar"));
ResourceMetadataKeyEnum.PROFILES.put(patient, tl);
id = myPatientDao.create(patient).getId().toUnqualifiedVersionless();
id = myPatientDao.create(patient, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
}
// Do a read
{
Patient patient = myPatientDao.read(id);
Patient patient = myPatientDao.read(id, new ServletRequestDetails());
List<IdDt> tl = ResourceMetadataKeyEnum.PROFILES.get(patient);
assertEquals(1, tl.size());
assertEquals("http://foo/bar", tl.get(0).getValue());
@ -347,12 +348,12 @@ public class FhirResourceDaoDstu2UpdateTest extends BaseJpaDstu2Test {
tl.add(new IdDt("http://foo/baz"));
ResourceMetadataKeyEnum.PROFILES.put(patient, tl);
id = myPatientDao.update(patient).getId().toUnqualifiedVersionless();
id = myPatientDao.update(patient, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
}
// Do a read
{
Patient patient = myPatientDao.read(id);
Patient patient = myPatientDao.read(id, new ServletRequestDetails());
List<IdDt> tl = ResourceMetadataKeyEnum.PROFILES.get(patient);
assertEquals(1, tl.size());
assertEquals("http://foo/baz", tl.get(0).getValue());
@ -367,7 +368,7 @@ public class FhirResourceDaoDstu2UpdateTest extends BaseJpaDstu2Test {
p.addName().addFamily("Hello");
p.setId("Patient/9999999999999999");
try {
myPatientDao.update(p);
myPatientDao.update(p, new ServletRequestDetails());
fail();
} catch (InvalidRequestException e) {
assertThat(e.getMessage(), containsString("Can not create resource with ID[9999999999999999], no resource with this ID exists and clients may only"));
@ -381,7 +382,7 @@ public class FhirResourceDaoDstu2UpdateTest extends BaseJpaDstu2Test {
p.addName().addFamily("Hello");
p.setId("Patient/123:456");
try {
myPatientDao.update(p);
myPatientDao.update(p, new ServletRequestDetails());
fail();
} catch (InvalidRequestException e) {
assertEquals("Can not process entity with ID[123:456], this is not a valid FHIR ID", e.getMessage());
@ -395,7 +396,7 @@ public class FhirResourceDaoDstu2UpdateTest extends BaseJpaDstu2Test {
p.addName().addFamily("Hello");
p.setId("Patient/123");
try {
myPatientDao.update(p);
myPatientDao.update(p, new ServletRequestDetails());
fail();
} catch (InvalidRequestException e) {
assertThat(e.getMessage(), containsString("clients may only assign IDs which contain at least one non-numeric"));
@ -408,11 +409,11 @@ public class FhirResourceDaoDstu2UpdateTest extends BaseJpaDstu2Test {
p.addIdentifier().setSystem("urn:system").setValue("testCreateNumericIdFails");
p.addName().addFamily("Hello");
p.setId("Patient/123abc");
IIdType id = myPatientDao.update(p).getId();
IIdType id = myPatientDao.update(p, new ServletRequestDetails()).getId();
assertEquals("123abc", id.getIdPart());
assertEquals("1", id.getVersionIdPart());
p = myPatientDao.read(id.toUnqualifiedVersionless());
p = myPatientDao.read(id.toUnqualifiedVersionless(), new ServletRequestDetails());
assertEquals("Patient/123abc", p.getId().toUnqualifiedVersionless().getValue());
assertEquals("Hello", p.getName().get(0).getFamily().get(0).getValue());

View File

@ -1,7 +1,8 @@
package ca.uhn.fhir.jpa.dao.dstu2;
import static org.hamcrest.Matchers.containsString;
import static org.junit.Assert.*;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.fail;
import java.io.IOException;
import java.util.Arrays;
@ -27,6 +28,7 @@ import ca.uhn.fhir.rest.server.EncodingEnum;
import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException;
import ca.uhn.fhir.rest.server.exceptions.PreconditionFailedException;
import ca.uhn.fhir.rest.server.exceptions.ResourceVersionConflictException;
import ca.uhn.fhir.rest.server.servlet.ServletRequestDetails;
public class FhirResourceDaoDstu2ValidateTest extends BaseJpaDstu2Test {
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(FhirResourceDaoDstu2ValidateTest.class);
@ -57,20 +59,20 @@ public class FhirResourceDaoDstu2ValidateTest extends BaseJpaDstu2Test {
private OperationOutcome doTestValidateResourceContainingProfileDeclaration(String methodName, EncodingEnum enc) throws IOException {
Bundle vss = loadResourceFromClasspath(Bundle.class, "/org/hl7/fhir/instance/model/valueset/valuesets.xml");
myValueSetDao.update((ValueSet) findResourceByIdInBundle(vss, "observation-status"));
myValueSetDao.update((ValueSet) findResourceByIdInBundle(vss, "observation-category"));
myValueSetDao.update((ValueSet) findResourceByIdInBundle(vss, "observation-codes"));
myValueSetDao.update((ValueSet) findResourceByIdInBundle(vss, "observation-methods"));
myValueSetDao.update((ValueSet) findResourceByIdInBundle(vss, "observation-valueabsentreason"));
myValueSetDao.update((ValueSet) findResourceByIdInBundle(vss, "observation-interpretation"));
myValueSetDao.update((ValueSet) findResourceByIdInBundle(vss, "body-site"));
myValueSetDao.update((ValueSet) findResourceByIdInBundle(vss, "referencerange-meaning"));
myValueSetDao.update((ValueSet) findResourceByIdInBundle(vss, "observation-relationshiptypes"));
myValueSetDao.update((ValueSet) findResourceByIdInBundle(vss, "observation-status"), new ServletRequestDetails());
myValueSetDao.update((ValueSet) findResourceByIdInBundle(vss, "observation-category"), new ServletRequestDetails());
myValueSetDao.update((ValueSet) findResourceByIdInBundle(vss, "observation-codes"), new ServletRequestDetails());
myValueSetDao.update((ValueSet) findResourceByIdInBundle(vss, "observation-methods"), new ServletRequestDetails());
myValueSetDao.update((ValueSet) findResourceByIdInBundle(vss, "observation-valueabsentreason"), new ServletRequestDetails());
myValueSetDao.update((ValueSet) findResourceByIdInBundle(vss, "observation-interpretation"), new ServletRequestDetails());
myValueSetDao.update((ValueSet) findResourceByIdInBundle(vss, "body-site"), new ServletRequestDetails());
myValueSetDao.update((ValueSet) findResourceByIdInBundle(vss, "referencerange-meaning"), new ServletRequestDetails());
myValueSetDao.update((ValueSet) findResourceByIdInBundle(vss, "observation-relationshiptypes"), new ServletRequestDetails());
StructureDefinition sd = loadResourceFromClasspath(StructureDefinition.class, "/org/hl7/fhir/instance/model/profile/devicemetricobservation.profile.xml");
sd.setId(new IdDt());
sd.setUrl("http://example.com/foo/bar/" + methodName);
myStructureDefinitionDao.create(sd);
myStructureDefinitionDao.create(sd, new ServletRequestDetails());
Observation input = new Observation();
ResourceMetadataKeyEnum.PROFILES.put(input, Arrays.asList(new IdDt(sd.getUrl())));
@ -87,7 +89,7 @@ public class FhirResourceDaoDstu2ValidateTest extends BaseJpaDstu2Test {
case JSON:
encoded = myFhirCtx.newJsonParser().encodeResourceToString(input);
try {
myObservationDao.validate(input, null, encoded, EncodingEnum.JSON, mode, null);
myObservationDao.validate(input, null, encoded, EncodingEnum.JSON, mode, null, new ServletRequestDetails());
fail();
} catch (PreconditionFailedException e) {
return (OperationOutcome) e.getOperationOutcome();
@ -95,7 +97,7 @@ public class FhirResourceDaoDstu2ValidateTest extends BaseJpaDstu2Test {
case XML:
encoded = myFhirCtx.newXmlParser().encodeResourceToString(input);
try {
myObservationDao.validate(input, null, encoded, EncodingEnum.XML, mode, null);
myObservationDao.validate(input, null, encoded, EncodingEnum.XML, mode, null, new ServletRequestDetails());
fail();
} catch (PreconditionFailedException e) {
return (OperationOutcome) e.getOperationOutcome();
@ -120,7 +122,7 @@ public class FhirResourceDaoDstu2ValidateTest extends BaseJpaDstu2Test {
ValidationModeEnum mode = ValidationModeEnum.CREATE;
String encoded = myFhirCtx.newJsonParser().encodeResourceToString(input);
MethodOutcome outcome = myObservationDao.validate(input, null, encoded, EncodingEnum.JSON, mode, null);
MethodOutcome outcome = myObservationDao.validate(input, null, encoded, EncodingEnum.JSON, mode, null, new ServletRequestDetails());
String ooString = myFhirCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(outcome.getOperationOutcome());
ourLog.info(ooString);
@ -137,14 +139,14 @@ public class FhirResourceDaoDstu2ValidateTest extends BaseJpaDstu2Test {
pat.addName().addFamily(methodName);
try {
myPatientDao.validate(pat, null, null, null, ValidationModeEnum.CREATE, null);
myPatientDao.validate(pat, null, null, null, ValidationModeEnum.CREATE, null, new ServletRequestDetails());
fail();
} catch (InvalidRequestException e) {
assertThat(e.getMessage(), containsString("ID must not be populated"));
}
pat.setId("");
myPatientDao.validate(pat, null, null, null, ValidationModeEnum.CREATE, null);
myPatientDao.validate(pat, null, null, null, ValidationModeEnum.CREATE, null, new ServletRequestDetails());
}
@ -155,12 +157,12 @@ public class FhirResourceDaoDstu2ValidateTest extends BaseJpaDstu2Test {
Patient pat = new Patient();
pat.setId("Patient/123");
pat.addName().addFamily(methodName);
myPatientDao.validate(pat, null, null, null, ValidationModeEnum.UPDATE, null);
myPatientDao.validate(pat, null, null, null, ValidationModeEnum.UPDATE, null, new ServletRequestDetails());
pat.setId("");
try {
myPatientDao.validate(pat, null, null, null, ValidationModeEnum.UPDATE, null);
myPatientDao.validate(pat, null, null, null, ValidationModeEnum.UPDATE, null, new ServletRequestDetails());
fail();
} catch (InvalidRequestException e) {
assertThat(e.getMessage(), containsString("ID must be populated"));
@ -178,12 +180,12 @@ public class FhirResourceDaoDstu2ValidateTest extends BaseJpaDstu2Test {
Patient pat = new Patient();
pat.setId("Patient/123");
pat.addName().addFamily(methodName);
myPatientDao.validate(pat, null, null, null, ValidationModeEnum.UPDATE, null);
myPatientDao.validate(pat, null, null, null, ValidationModeEnum.UPDATE, null, new ServletRequestDetails());
pat.setId("");
try {
myPatientDao.validate(pat, null, null, null, ValidationModeEnum.UPDATE, null);
myPatientDao.validate(pat, null, null, null, ValidationModeEnum.UPDATE, null, new ServletRequestDetails());
fail();
} catch (InvalidRequestException e) {
assertThat(e.getMessage(), containsString("ID must be populated"));
@ -198,16 +200,16 @@ public class FhirResourceDaoDstu2ValidateTest extends BaseJpaDstu2Test {
Organization org = new Organization();
org.setName(methodName);
IIdType orgId = myOrganizationDao.create(org).getId().toUnqualifiedVersionless();
IIdType orgId = myOrganizationDao.create(org, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
Patient pat = new Patient();
pat.addName().addFamily(methodName);
pat.getManagingOrganization().setReference(orgId);
IIdType patId = myPatientDao.create(pat).getId().toUnqualifiedVersionless();
IIdType patId = myPatientDao.create(pat, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
OperationOutcome outcome=null;
try {
myOrganizationDao.validate(null, orgId, null, null, ValidationModeEnum.DELETE, null);
myOrganizationDao.validate(null, orgId, null, null, ValidationModeEnum.DELETE, null, new ServletRequestDetails());
fail();
} catch (ResourceVersionConflictException e) {
outcome= (OperationOutcome) e.getOperationOutcome();
@ -219,9 +221,9 @@ public class FhirResourceDaoDstu2ValidateTest extends BaseJpaDstu2Test {
pat.setId(patId);
pat.getManagingOrganization().setReference("");
myPatientDao.update(pat);
myPatientDao.update(pat, new ServletRequestDetails());
outcome = (OperationOutcome) myOrganizationDao.validate(null, orgId, null, null, ValidationModeEnum.DELETE, null).getOperationOutcome();
outcome = (OperationOutcome) myOrganizationDao.validate(null, orgId, null, null, ValidationModeEnum.DELETE, null, new ServletRequestDetails()).getOperationOutcome();
ooString = myFhirCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(outcome);
ourLog.info(ooString);
assertThat(ooString, containsString("Ok to delete"));

View File

@ -24,6 +24,7 @@ import ca.uhn.fhir.model.primitive.CodeDt;
import ca.uhn.fhir.model.primitive.IdDt;
import ca.uhn.fhir.model.primitive.StringDt;
import ca.uhn.fhir.model.primitive.UriDt;
import ca.uhn.fhir.rest.server.servlet.ServletRequestDetails;
public class FhirResourceDaoValueSetDstu2Test extends BaseJpaDstu2Test {
@ -37,7 +38,7 @@ public class FhirResourceDaoValueSetDstu2Test extends BaseJpaDstu2Test {
public void before02() throws IOException {
ValueSet upload = loadResourceFromClasspath(ValueSet.class, "/extensional-case-2.xml");
upload.setId("");
myExtensionalVsId = myValueSetDao.create(upload).getId().toUnqualifiedVersionless();
myExtensionalVsId = myValueSetDao.create(upload, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
}
@Test

View File

@ -17,6 +17,7 @@ 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.server.Constants;
import ca.uhn.fhir.rest.server.servlet.ServletRequestDetails;
public class FhirSearchDaoDstu2Test extends BaseJpaDstu2Test {
@ -32,7 +33,7 @@ public class FhirSearchDaoDstu2Test extends BaseJpaDstu2Test {
patient.addName().addGiven("testSearchStringParamWithNonNormalized_h\u00F6ra");
patient.addName().addFamily("AAAS");
patient.addName().addFamily("CCC");
id1 = myPatientDao.create(patient).getId().toUnqualifiedVersionless().getIdPartAsLong();
id1 = myPatientDao.create(patient, new ServletRequestDetails()).getId().toUnqualifiedVersionless().getIdPartAsLong();
}
Long id2;
{
@ -41,13 +42,13 @@ public class FhirSearchDaoDstu2Test extends BaseJpaDstu2Test {
patient.addName().addGiven("testSearchStringParamWithNonNormalized_HORA");
patient.addName().addFamily("AAAB");
patient.addName().addFamily("CCC");
id2 = myPatientDao.create(patient).getId().toUnqualifiedVersionless().getIdPartAsLong();
id2 = myPatientDao.create(patient, new ServletRequestDetails()).getId().toUnqualifiedVersionless().getIdPartAsLong();
}
Long id3;
{
Organization org = new Organization();
org.setName("DDD");
id3 = myOrganizationDao.create(org).getId().toUnqualifiedVersionless().getIdPartAsLong();
id3 = myOrganizationDao.create(org, new ServletRequestDetails()).getId().toUnqualifiedVersionless().getIdPartAsLong();
}
SearchParameterMap map = new SearchParameterMap();
@ -109,13 +110,13 @@ public class FhirSearchDaoDstu2Test extends BaseJpaDstu2Test {
{
Patient patient = new Patient();
patient.getText().setDiv("<div>AAAS<p>FOO</p> CCC </div>");
id1 = myPatientDao.create(patient).getId().toUnqualifiedVersionless().getIdPartAsLong();
id1 = myPatientDao.create(patient, new ServletRequestDetails()).getId().toUnqualifiedVersionless().getIdPartAsLong();
}
Long id2;
{
Patient patient = new Patient();
patient.getText().setDiv("<div>AAAB<p>FOO</p> CCC </div>");
id2 = myPatientDao.create(patient).getId().toUnqualifiedVersionless().getIdPartAsLong();
id2 = myPatientDao.create(patient, new ServletRequestDetails()).getId().toUnqualifiedVersionless().getIdPartAsLong();
}
SearchParameterMap map = new SearchParameterMap();

View File

@ -65,6 +65,7 @@ import ca.uhn.fhir.rest.server.exceptions.PreconditionFailedException;
import ca.uhn.fhir.rest.server.exceptions.ResourceGoneException;
import ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException;
import ca.uhn.fhir.rest.server.interceptor.IServerInterceptor.ActionRequestDetails;
import ca.uhn.fhir.rest.server.servlet.ServletRequestDetails;
public class FhirSystemDaoDstu2Test extends BaseJpaDstu2SystemTest {
@ -74,11 +75,11 @@ public class FhirSystemDaoDstu2Test extends BaseJpaDstu2SystemTest {
public void testReindexing() {
Patient p = new Patient();
p.addName().addFamily("family");
final IIdType id = myPatientDao.create(p).getId().toUnqualifiedVersionless();
final IIdType id = myPatientDao.create(p, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
ValueSet vs = new ValueSet();
vs.setUrl("http://foo");
myValueSetDao.create(vs);
myValueSetDao.create(vs, new ServletRequestDetails());
ResourceTable entity = new TransactionTemplate(myTxManager).execute(new TransactionCallback<ResourceTable>() {
@Override
@ -98,7 +99,7 @@ public class FhirSystemDaoDstu2Test extends BaseJpaDstu2SystemTest {
});
assertEquals(null, entity.getIndexStatus());
mySystemDao.performReindexingPass(null);
mySystemDao.performReindexingPass(null, new ServletRequestDetails());
entity = new TransactionTemplate(myTxManager).execute(new TransactionCallback<ResourceTable>() {
@Override
@ -109,7 +110,7 @@ public class FhirSystemDaoDstu2Test extends BaseJpaDstu2SystemTest {
assertEquals(Long.valueOf(1), entity.getIndexStatus());
// Just make sure this doesn't cause a choke
mySystemDao.performReindexingPass(100000);
mySystemDao.performReindexingPass(100000, new ServletRequestDetails());
// Try making the resource unparseable
@ -131,7 +132,7 @@ public class FhirSystemDaoDstu2Test extends BaseJpaDstu2SystemTest {
}
});
mySystemDao.performReindexingPass(null);
mySystemDao.performReindexingPass(null, new ServletRequestDetails());
entity = new TransactionTemplate(myTxManager).execute(new TransactionCallback<ResourceTable>() {
@Override
@ -146,7 +147,7 @@ public class FhirSystemDaoDstu2Test extends BaseJpaDstu2SystemTest {
@Test
public void testSystemMetaOperation() {
MetaDt meta = mySystemDao.metaGetOperation();
MetaDt meta = mySystemDao.metaGetOperation(new ServletRequestDetails());
List<CodingDt> published = meta.getTag();
assertEquals(0, published.size());
@ -168,7 +169,7 @@ public class FhirSystemDaoDstu2Test extends BaseJpaDstu2SystemTest {
profiles.add(new IdDt("http://profile/1"));
ResourceMetadataKeyEnum.PROFILES.put(patient, profiles);
id1 = myPatientDao.create(patient).getId();
id1 = myPatientDao.create(patient, new ServletRequestDetails()).getId();
}
{
Patient patient = new Patient();
@ -186,10 +187,10 @@ public class FhirSystemDaoDstu2Test extends BaseJpaDstu2SystemTest {
profiles.add(new IdDt("http://profile/2"));
ResourceMetadataKeyEnum.PROFILES.put(patient, profiles);
myPatientDao.create(patient);
myPatientDao.create(patient, new ServletRequestDetails());
}
meta = mySystemDao.metaGetOperation();
meta = mySystemDao.metaGetOperation(new ServletRequestDetails());
published = meta.getTag();
assertEquals(2, published.size());
assertEquals(null, published.get(0).getSystem());
@ -211,11 +212,11 @@ public class FhirSystemDaoDstu2Test extends BaseJpaDstu2SystemTest {
assertEquals("http://profile/1", profiles.get(0).getValue());
assertEquals("http://profile/2", profiles.get(1).getValue());
myPatientDao.removeTag(id1, TagTypeEnum.TAG, null, "Dog");
myPatientDao.removeTag(id1, TagTypeEnum.SECURITY_LABEL, "seclabel:sys:1", "seclabel:code:1");
myPatientDao.removeTag(id1, TagTypeEnum.PROFILE, BaseHapiFhirDao.NS_JPA_PROFILE, "http://profile/1");
myPatientDao.removeTag(id1, TagTypeEnum.TAG, null, "Dog", new ServletRequestDetails());
myPatientDao.removeTag(id1, TagTypeEnum.SECURITY_LABEL, "seclabel:sys:1", "seclabel:code:1", new ServletRequestDetails());
myPatientDao.removeTag(id1, TagTypeEnum.PROFILE, BaseHapiFhirDao.NS_JPA_PROFILE, "http://profile/1", new ServletRequestDetails());
meta = mySystemDao.metaGetOperation();
meta = mySystemDao.metaGetOperation(new ServletRequestDetails());
published = meta.getTag();
assertEquals(1, published.size());
assertEquals("http://foo", published.get(0).getSystem());
@ -271,7 +272,7 @@ public class FhirSystemDaoDstu2Test extends BaseJpaDstu2SystemTest {
assertEquals("201 Created", respEntry.getStatus());
IdDt createdId = new IdDt(respEntry.getLocation());
assertEquals("Patient", createdId.getResourceType());
myPatientDao.read(createdId); // shouldn't fail
myPatientDao.read(createdId, new ServletRequestDetails()); // shouldn't fail
// Check GET
respEntry = resp.getEntry().get(2).getResponse();
@ -287,7 +288,7 @@ public class FhirSystemDaoDstu2Test extends BaseJpaDstu2SystemTest {
Patient p = new Patient();
p.addIdentifier().setSystem("urn:system").setValue(methodName);
p.setId("Patient/" + methodName);
IIdType id = myPatientDao.update(p).getId();
IIdType id = myPatientDao.update(p, new ServletRequestDetails()).getId();
ourLog.info("Created patient, got it: {}", id);
p = new Patient();
@ -315,7 +316,7 @@ public class FhirSystemDaoDstu2Test extends BaseJpaDstu2SystemTest {
assertThat(respEntry.getResponse().getLocation(), endsWith("/_history/1"));
assertEquals("1", respEntry.getResponse().getEtag());
o = (Observation) myObservationDao.read(new IdDt(respEntry.getResponse().getLocationElement()));
o = (Observation) myObservationDao.read(new IdDt(respEntry.getResponse().getLocationElement()), new ServletRequestDetails());
assertEquals(id.toVersionless(), o.getSubject().getReference());
assertEquals("1", o.getId().getVersionIdPart());
@ -327,12 +328,12 @@ public class FhirSystemDaoDstu2Test extends BaseJpaDstu2SystemTest {
Patient p = new Patient();
p.addIdentifier().setSystem("urn:system").setValue(methodName);
IIdType id = myPatientDao.create(p).getId();
IIdType id = myPatientDao.create(p, new ServletRequestDetails()).getId();
ourLog.info("Created patient, got it: {}", id);
p = new Patient();
p.addIdentifier().setSystem("urn:system").setValue(methodName);
id = myPatientDao.create(p).getId();
id = myPatientDao.create(p, new ServletRequestDetails()).getId();
ourLog.info("Created patient, got it: {}", id);
Bundle request = new Bundle();
@ -389,7 +390,7 @@ public class FhirSystemDaoDstu2Test extends BaseJpaDstu2SystemTest {
assertThat(respEntry.getResponse().getLocation(), endsWith("/_history/1"));
assertEquals("1", respEntry.getResponse().getEtag());
o = (Observation) myObservationDao.read(new IdDt(respEntry.getResponse().getLocationElement()));
o = (Observation) myObservationDao.read(new IdDt(respEntry.getResponse().getLocationElement()), new ServletRequestDetails());
assertEquals(new IdDt(patientId).toUnqualifiedVersionless(), o.getSubject().getReference());
}
@ -552,13 +553,13 @@ public class FhirSystemDaoDstu2Test extends BaseJpaDstu2SystemTest {
Patient p1 = new Patient();
p1.addIdentifier().setSystem("urn:system").setValue(methodName);
IIdType id1 = myPatientDao.create(p1).getId();
IIdType id1 = myPatientDao.create(p1, new ServletRequestDetails()).getId();
ourLog.info("Created patient, got it: {}", id1);
Patient p2 = new Patient();
p2.addIdentifier().setSystem("urn:system").setValue(methodName);
p2.setId("Patient/" + methodName);
IIdType id2 = myPatientDao.update(p2).getId();
IIdType id2 = myPatientDao.update(p2, new ServletRequestDetails()).getId();
ourLog.info("Created patient, got it: {}", id2);
Bundle request = new Bundle();
@ -566,8 +567,8 @@ public class FhirSystemDaoDstu2Test extends BaseJpaDstu2SystemTest {
request.addEntry().getRequest().setMethod(HTTPVerbEnum.DELETE).setUrl("Patient/" + id1.getIdPart());
request.addEntry().getRequest().setMethod(HTTPVerbEnum.DELETE).setUrl("Patient/" + id2.getIdPart());
myPatientDao.read(id1.toVersionless());
myPatientDao.read(id2.toVersionless());
myPatientDao.read(id1.toVersionless(), new ServletRequestDetails());
myPatientDao.read(id2.toVersionless(), new ServletRequestDetails());
Bundle resp = mySystemDao.transaction(myRequestDetails, request);
@ -576,14 +577,14 @@ public class FhirSystemDaoDstu2Test extends BaseJpaDstu2SystemTest {
assertEquals("204 No Content", resp.getEntry().get(1).getResponse().getStatus());
try {
myPatientDao.read(id1.toVersionless());
myPatientDao.read(id1.toVersionless(), new ServletRequestDetails());
fail();
} catch (ResourceGoneException e) {
// good
}
try {
myPatientDao.read(id2.toVersionless());
myPatientDao.read(id2.toVersionless(), new ServletRequestDetails());
fail();
} catch (ResourceGoneException e) {
// good
@ -600,20 +601,20 @@ public class FhirSystemDaoDstu2Test extends BaseJpaDstu2SystemTest {
Patient p1 = new Patient();
p1.addIdentifier().setSystem("urn:system").setValue(methodName);
IIdType pid = myPatientDao.create(p1).getId().toUnqualifiedVersionless();
IIdType pid = myPatientDao.create(p1, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
ourLog.info("Created patient, got it: {}", pid);
Observation o1 = new Observation();
o1.getSubject().setReference(pid);
IIdType oid1 = myObservationDao.create(o1).getId().toUnqualifiedVersionless();
IIdType oid1 = myObservationDao.create(o1, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
Observation o2 = new Observation();
o2.addIdentifier().setValue(methodName);
o2.getSubject().setReference(pid);
IIdType oid2 = myObservationDao.create(o2).getId().toUnqualifiedVersionless();
IIdType oid2 = myObservationDao.create(o2, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
myPatientDao.read(pid);
myObservationDao.read(oid1);
myPatientDao.read(pid, new ServletRequestDetails());
myObservationDao.read(oid1, new ServletRequestDetails());
// The target is Patient, so try with it first in the bundle
Bundle request = new Bundle();
@ -628,21 +629,21 @@ public class FhirSystemDaoDstu2Test extends BaseJpaDstu2SystemTest {
assertEquals("204 No Content", resp.getEntry().get(2).getResponse().getStatus());
try {
myPatientDao.read(pid);
myPatientDao.read(pid, new ServletRequestDetails());
fail();
} catch (ResourceGoneException e) {
// good
}
try {
myObservationDao.read(oid1);
myObservationDao.read(oid1, new ServletRequestDetails());
fail();
} catch (ResourceGoneException e) {
// good
}
try {
myObservationDao.read(oid2);
myObservationDao.read(oid2, new ServletRequestDetails());
fail();
} catch (ResourceGoneException e) {
// good
@ -659,20 +660,20 @@ public class FhirSystemDaoDstu2Test extends BaseJpaDstu2SystemTest {
Patient p1 = new Patient();
p1.addIdentifier().setSystem("urn:system").setValue(methodName);
IIdType pid = myPatientDao.create(p1).getId().toUnqualifiedVersionless();
IIdType pid = myPatientDao.create(p1, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
ourLog.info("Created patient, got it: {}", pid);
Observation o1 = new Observation();
o1.getSubject().setReference(pid);
IIdType oid1 = myObservationDao.create(o1).getId().toUnqualifiedVersionless();
IIdType oid1 = myObservationDao.create(o1, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
Observation o2 = new Observation();
o2.addIdentifier().setValue(methodName);
o2.getSubject().setReference(pid);
IIdType oid2 = myObservationDao.create(o2).getId().toUnqualifiedVersionless();
IIdType oid2 = myObservationDao.create(o2, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
myPatientDao.read(pid);
myObservationDao.read(oid1);
myPatientDao.read(pid, new ServletRequestDetails());
myObservationDao.read(oid1, new ServletRequestDetails());
// The target is Patient, so try with it last in the bundle
Bundle request = new Bundle();
@ -687,21 +688,21 @@ public class FhirSystemDaoDstu2Test extends BaseJpaDstu2SystemTest {
assertEquals("204 No Content", resp.getEntry().get(2).getResponse().getStatus());
try {
myPatientDao.read(pid);
myPatientDao.read(pid, new ServletRequestDetails());
fail();
} catch (ResourceGoneException e) {
// good
}
try {
myObservationDao.read(oid1);
myObservationDao.read(oid1, new ServletRequestDetails());
fail();
} catch (ResourceGoneException e) {
// good
}
try {
myObservationDao.read(oid2);
myObservationDao.read(oid2, new ServletRequestDetails());
fail();
} catch (ResourceGoneException e) {
// good
@ -715,7 +716,7 @@ public class FhirSystemDaoDstu2Test extends BaseJpaDstu2SystemTest {
Patient p = new Patient();
p.addIdentifier().setSystem("urn:system").setValue(methodName);
IIdType id = myPatientDao.create(p).getId();
IIdType id = myPatientDao.create(p, new ServletRequestDetails()).getId();
ourLog.info("Created patient, got it: {}", id);
Bundle request = new Bundle();
@ -728,20 +729,20 @@ public class FhirSystemDaoDstu2Test extends BaseJpaDstu2SystemTest {
assertEquals(Constants.STATUS_HTTP_204_NO_CONTENT + " No Content", nextEntry.getResponse().getStatus());
try {
myPatientDao.read(id.toVersionless());
myPatientDao.read(id.toVersionless(), new ServletRequestDetails());
fail();
} catch (ResourceGoneException e) {
// ok
}
try {
myPatientDao.read(new IdDt("Patient/" + methodName));
myPatientDao.read(new IdDt("Patient/" + methodName), new ServletRequestDetails());
fail();
} catch (ResourceNotFoundException e) {
// ok
}
IBundleProvider history = myPatientDao.history(id, null);
IBundleProvider history = myPatientDao.history(id, null, new ServletRequestDetails());
assertEquals(2, history.size());
assertNotNull(ResourceMetadataKeyEnum.DELETED_AT.get((IResource) history.getResources(0, 0).get(0)));
@ -758,12 +759,12 @@ public class FhirSystemDaoDstu2Test extends BaseJpaDstu2SystemTest {
Patient p = new Patient();
p.addIdentifier().setSystem("urn:system").setValue(methodName);
IIdType id = myPatientDao.create(p).getId();
IIdType id = myPatientDao.create(p, new ServletRequestDetails()).getId();
ourLog.info("Created patient, got it: {}", id);
p = new Patient();
p.addIdentifier().setSystem("urn:system").setValue(methodName);
id = myPatientDao.create(p).getId();
id = myPatientDao.create(p, new ServletRequestDetails()).getId();
ourLog.info("Created patient, got it: {}", id);
p = new Patient();
@ -807,7 +808,7 @@ public class FhirSystemDaoDstu2Test extends BaseJpaDstu2SystemTest {
Patient p = new Patient();
p.addIdentifier().setSystem("urn:system").setValue(methodName);
p.setId("Patient/" + methodName);
IIdType id = myPatientDao.update(p).getId();
IIdType id = myPatientDao.update(p, new ServletRequestDetails()).getId();
ourLog.info("Created patient, got it: {}", id);
Bundle request = new Bundle();
@ -819,7 +820,7 @@ public class FhirSystemDaoDstu2Test extends BaseJpaDstu2SystemTest {
assertEquals(Constants.STATUS_HTTP_204_NO_CONTENT + " No Content", res.getEntry().get(0).getResponse().getStatus());
try {
myPatientDao.read(id.toVersionless());
myPatientDao.read(id.toVersionless(), new ServletRequestDetails());
fail();
} catch (ResourceGoneException e) {
// ok
@ -858,7 +859,7 @@ public class FhirSystemDaoDstu2Test extends BaseJpaDstu2SystemTest {
assertThat(resp.getEntry().get(1).getResponse().getLocation(), startsWith("Patient/temp6789/_history/"));
assertThat(resp.getEntry().get(2).getResponse().getLocation(), startsWith("Organization/GHH/_history/"));
Patient p = myPatientDao.read(new IdDt("Patient/a555-44-4444/_history/1"));
Patient p = myPatientDao.read(new IdDt("Patient/a555-44-4444/_history/1"), new ServletRequestDetails());
assertEquals("Patient/temp6789", p.getLink().get(0).getOther().getReference().getValue());
}
@ -974,14 +975,14 @@ public class FhirSystemDaoDstu2Test extends BaseJpaDstu2SystemTest {
Patient p = new Patient();
p.addIdentifier().setSystem("urn:system").setValue(methodName);
p.setId("Patient/" + methodName);
IIdType idv1 = myPatientDao.update(p).getId();
IIdType idv1 = myPatientDao.update(p, new ServletRequestDetails()).getId();
ourLog.info("Created patient, got id: {}", idv1);
p = new Patient();
p.addIdentifier().setSystem("urn:system").setValue(methodName);
p.addName().addFamily("Family Name");
p.setId("Patient/" + methodName);
IIdType idv2 = myPatientDao.update(p).getId();
IIdType idv2 = myPatientDao.update(p, new ServletRequestDetails()).getId();
ourLog.info("Updated patient, got id: {}", idv2);
Bundle request = new Bundle();
@ -1044,14 +1045,14 @@ public class FhirSystemDaoDstu2Test extends BaseJpaDstu2SystemTest {
Patient p = new Patient();
p.addIdentifier().setSystem("urn:system").setValue(methodName);
p.setId("Patient/" + methodName);
IIdType idv1 = myPatientDao.update(p).getId();
IIdType idv1 = myPatientDao.update(p, new ServletRequestDetails()).getId();
ourLog.info("Created patient, got id: {}", idv1);
p = new Patient();
p.addIdentifier().setSystem("urn:system").setValue(methodName);
p.addName().addFamily("Family Name");
p.setId("Patient/" + methodName);
IIdType idv2 = myPatientDao.update(p).getId();
IIdType idv2 = myPatientDao.update(p, new ServletRequestDetails()).getId();
ourLog.info("Updated patient, got id: {}", idv2);
Bundle request = new Bundle();
@ -1089,14 +1090,14 @@ public class FhirSystemDaoDstu2Test extends BaseJpaDstu2SystemTest {
Patient p = new Patient();
p.addIdentifier().setSystem("urn:system").setValue(methodName);
p.setId("Patient/" + methodName);
IIdType idv1 = myPatientDao.update(p).getId();
IIdType idv1 = myPatientDao.update(p, new ServletRequestDetails()).getId();
ourLog.info("Created patient, got id: {}", idv1);
p = new Patient();
p.addIdentifier().setSystem("urn:system").setValue(methodName);
p.addName().addFamily("Family Name");
p.setId("Patient/" + methodName);
IIdType idv2 = myPatientDao.update(p).getId();
IIdType idv2 = myPatientDao.update(p, new ServletRequestDetails()).getId();
ourLog.info("Updated patient, got id: {}", idv2);
Bundle request = new Bundle();
@ -1152,7 +1153,7 @@ public class FhirSystemDaoDstu2Test extends BaseJpaDstu2SystemTest {
Patient p = new Patient();
p.addIdentifier().setSystem("urn:system").setValue(methodName);
IIdType id = myPatientDao.create(p).getId();
IIdType id = myPatientDao.create(p, new ServletRequestDetails()).getId();
ourLog.info("Created patient, got it: {}", id);
p = new Patient();
@ -1181,7 +1182,7 @@ public class FhirSystemDaoDstu2Test extends BaseJpaDstu2SystemTest {
assertThat(nextEntry.getResponse().getLocation(), not(emptyString()));
nextEntry = resp.getEntry().get(1);
o = myObservationDao.read(new IdDt(nextEntry.getResponse().getLocation()));
o = myObservationDao.read(new IdDt(nextEntry.getResponse().getLocation()), new ServletRequestDetails());
assertEquals(id.toVersionless(), o.getSubject().getReference());
}
@ -1193,12 +1194,12 @@ public class FhirSystemDaoDstu2Test extends BaseJpaDstu2SystemTest {
Patient p = new Patient();
p.addIdentifier().setSystem("urn:system").setValue(methodName);
IIdType id = myPatientDao.create(p).getId();
IIdType id = myPatientDao.create(p, new ServletRequestDetails()).getId();
ourLog.info("Created patient, got it: {}", id);
p = new Patient();
p.addIdentifier().setSystem("urn:system").setValue(methodName);
id = myPatientDao.create(p).getId();
id = myPatientDao.create(p, new ServletRequestDetails()).getId();
ourLog.info("Created patient, got it: {}", id);
p = new Patient();
@ -1227,7 +1228,7 @@ public class FhirSystemDaoDstu2Test extends BaseJpaDstu2SystemTest {
Patient p = new Patient();
p.addName().addFamily("Hello");
IIdType id = myPatientDao.create(p).getId();
IIdType id = myPatientDao.create(p, new ServletRequestDetails()).getId();
p = new Patient();
p.addIdentifier().setSystem("urn:system").setValue(methodName);
@ -1253,7 +1254,7 @@ public class FhirSystemDaoDstu2Test extends BaseJpaDstu2SystemTest {
assertThat(patientId.getValue(), endsWith("/_history/1"));
nextEntry = resp.getEntry().get(1);
o = myObservationDao.read(new IdDt(nextEntry.getResponse().getLocation()));
o = myObservationDao.read(new IdDt(nextEntry.getResponse().getLocation()), new ServletRequestDetails());
assertEquals(patientId.toVersionless(), o.getSubject().getReference());
}
@ -1266,7 +1267,7 @@ public class FhirSystemDaoDstu2Test extends BaseJpaDstu2SystemTest {
Patient p = new Patient();
p.addIdentifier().setSystem("urn:system").setValue(methodName);
p.setId("Patient/" + methodName);
IIdType id = myPatientDao.update(p).getId();
IIdType id = myPatientDao.update(p, new ServletRequestDetails()).getId();
ourLog.info("Created patient, got it: {}", id);
p = new Patient();
@ -1294,7 +1295,7 @@ public class FhirSystemDaoDstu2Test extends BaseJpaDstu2SystemTest {
nextEntry = resp.getEntry().get(1);
assertEquals(Constants.STATUS_HTTP_201_CREATED + " Created", nextEntry.getResponse().getStatus());
o = myObservationDao.read(new IdDt(resp.getEntry().get(1).getResponse().getLocation()));
o = myObservationDao.read(new IdDt(resp.getEntry().get(1).getResponse().getLocation()), new ServletRequestDetails());
assertEquals(id.toVersionless(), o.getSubject().getReference());
}
@ -1503,8 +1504,8 @@ public class FhirSystemDaoDstu2Test extends BaseJpaDstu2SystemTest {
assertTrue(resp.getEntry().get(1).getResponse().getLocation(), new IdDt(resp.getEntry().get(1).getResponse().getLocation()).getIdPart().matches("^[0-9]+$"));
assertTrue(resp.getEntry().get(2).getResponse().getLocation(), new IdDt(resp.getEntry().get(2).getResponse().getLocation()).getIdPart().matches("^[0-9]+$"));
o1 = myObservationDao.read(new IdDt(resp.getEntry().get(1).getResponse().getLocation()));
o2 = myObservationDao.read(new IdDt(resp.getEntry().get(2).getResponse().getLocation()));
o1 = myObservationDao.read(new IdDt(resp.getEntry().get(1).getResponse().getLocation()), new ServletRequestDetails());
o2 = myObservationDao.read(new IdDt(resp.getEntry().get(2).getResponse().getLocation()), new ServletRequestDetails());
assertThat(o1.getSubject().getReference().getValue(), endsWith("Patient/" + p1.getId().getIdPart()));
assertThat(o2.getSubject().getReference().getValue(), endsWith("Patient/" + p1.getId().getIdPart()));
@ -1546,8 +1547,8 @@ public class FhirSystemDaoDstu2Test extends BaseJpaDstu2SystemTest {
assertTrue(resp.getEntry().get(1).getResponse().getLocation(), new IdDt(resp.getEntry().get(1).getResponse().getLocation()).getIdPart().matches("^[0-9]+$"));
assertTrue(resp.getEntry().get(2).getResponse().getLocation(), new IdDt(resp.getEntry().get(2).getResponse().getLocation()).getIdPart().matches("^[0-9]+$"));
o1 = myObservationDao.read(new IdDt(resp.getEntry().get(1).getResponse().getLocation()));
o2 = myObservationDao.read(new IdDt(resp.getEntry().get(2).getResponse().getLocation()));
o1 = myObservationDao.read(new IdDt(resp.getEntry().get(1).getResponse().getLocation()), new ServletRequestDetails());
o2 = myObservationDao.read(new IdDt(resp.getEntry().get(2).getResponse().getLocation()), new ServletRequestDetails());
assertThat(o1.getSubject().getReference().getValue(), endsWith("Patient/" + p1.getId().getIdPart()));
assertThat(o2.getSubject().getReference().getValue(), endsWith("Patient/" + p1.getId().getIdPart()));

View File

@ -13,6 +13,7 @@ import org.hibernate.search.jpa.FullTextEntityManager;
import org.hibernate.search.jpa.Search;
import org.hl7.fhir.dstu3.hapi.validation.IValidationSupport;
import org.hl7.fhir.dstu3.model.Bundle;
import org.hl7.fhir.dstu3.model.CodeSystem;
import org.hl7.fhir.dstu3.model.CodeableConcept;
import org.hl7.fhir.dstu3.model.Coding;
import org.hl7.fhir.dstu3.model.ConceptMap;
@ -62,6 +63,7 @@ import ca.uhn.fhir.jpa.dao.IFhirResourceDaoSubscription;
import ca.uhn.fhir.jpa.dao.IFhirResourceDaoValueSet;
import ca.uhn.fhir.jpa.dao.IFhirSystemDao;
import ca.uhn.fhir.jpa.dao.ISearchDao;
import ca.uhn.fhir.jpa.dao.data.IResourceTableDao;
import ca.uhn.fhir.jpa.dao.dstu2.FhirResourceDaoDstu2SearchNoFtTest;
import ca.uhn.fhir.jpa.entity.ForcedId;
import ca.uhn.fhir.jpa.entity.ResourceHistoryTable;
@ -79,7 +81,12 @@ import ca.uhn.fhir.jpa.entity.ResourceTag;
import ca.uhn.fhir.jpa.entity.SubscriptionFlaggedResource;
import ca.uhn.fhir.jpa.entity.SubscriptionTable;
import ca.uhn.fhir.jpa.entity.TagDefinition;
import ca.uhn.fhir.jpa.entity.TermCodeSystem;
import ca.uhn.fhir.jpa.entity.TermCodeSystemVersion;
import ca.uhn.fhir.jpa.entity.TermConcept;
import ca.uhn.fhir.jpa.entity.TermConceptParentChildLink;
import ca.uhn.fhir.jpa.provider.dstu3.JpaSystemProviderDstu3;
import ca.uhn.fhir.jpa.term.ITerminologySvc;
import ca.uhn.fhir.parser.IParser;
import ca.uhn.fhir.rest.method.MethodUtil;
import ca.uhn.fhir.rest.server.interceptor.IServerInterceptor;
@ -89,6 +96,10 @@ import ca.uhn.fhir.rest.server.interceptor.IServerInterceptor;
@ContextConfiguration(classes= {TestDstu3Config.class})
//@formatter:on
public abstract class BaseJpaDstu3Test extends BaseJpaTest {
@Autowired
protected IResourceTableDao myResourceTableDao;
@Autowired
protected ITerminologySvc myTermSvc;
@Autowired
@Qualifier("myJpaValidationSupportChainDstu3")
protected IValidationSupport myValidationSupport;
@ -100,6 +111,9 @@ public abstract class BaseJpaDstu3Test extends BaseJpaTest {
@Qualifier("myConceptMapDaoDstu3")
protected IFhirResourceDao<ConceptMap> myConceptMapDao;
@Autowired
@Qualifier("myCodeSystemDaoDstu3")
protected IFhirResourceDao<CodeSystem> myCodeSystemDao;
@Autowired
@Qualifier("myMedicationDaoDstu3")
protected IFhirResourceDao<Medication> myMedicationDao;
@Autowired
@ -242,6 +256,16 @@ public abstract class BaseJpaDstu3Test extends BaseJpaTest {
return null;
}
});
txTemplate.execute(new TransactionCallback<Void>() {
@Override
public Void doInTransaction(TransactionStatus theStatus) {
entityManager.createQuery("DELETE from " + TermConceptParentChildLink.class.getSimpleName() + " d").executeUpdate();
entityManager.createQuery("DELETE from " + TermConcept.class.getSimpleName() + " d").executeUpdate();
entityManager.createQuery("DELETE from " + TermCodeSystemVersion.class.getSimpleName() + " d").executeUpdate();
entityManager.createQuery("DELETE from " + TermCodeSystem.class.getSimpleName() + " d").executeUpdate();
return null;
}
});
txTemplate.execute(new TransactionCallback<Void>() {
@Override
public Void doInTransaction(TransactionStatus theStatus) {

View File

@ -18,6 +18,7 @@ import ca.uhn.fhir.jpa.entity.ResourceTable;
import ca.uhn.fhir.jpa.interceptor.IJpaServerInterceptor;
import ca.uhn.fhir.jpa.interceptor.JpaServerInterceptorAdapter;
import ca.uhn.fhir.rest.server.interceptor.IServerInterceptor.ActionRequestDetails;
import ca.uhn.fhir.rest.server.servlet.ServletRequestDetails;
public class FhirResourceDaoDstu3InterceptorTest extends BaseJpaDstu3Test {
@ -48,7 +49,7 @@ public class FhirResourceDaoDstu3InterceptorTest extends BaseJpaDstu3Test {
public void testJpaCreate() {
Patient p = new Patient();
p.addName().addFamily("PATIENT");
Long id = myPatientDao.create(p).getId().getIdPartAsLong();
Long id = myPatientDao.create(p, new ServletRequestDetails()).getId().getIdPartAsLong();
ArgumentCaptor<ActionRequestDetails> detailsCapt;
ArgumentCaptor<ResourceTable> tableCapt;
@ -68,7 +69,7 @@ public class FhirResourceDaoDstu3InterceptorTest extends BaseJpaDstu3Test {
*/
p = new Patient();
p.addName().addFamily("PATIENT1");
Long id2 = myPatientDao.create(p, "Patient?family=PATIENT").getId().getIdPartAsLong();
Long id2 = myPatientDao.create(p, "Patient?family=PATIENT", new ServletRequestDetails()).getId().getIdPartAsLong();
assertEquals(id, id2);
detailsCapt = ArgumentCaptor.forClass(ActionRequestDetails.class);
@ -82,9 +83,9 @@ public class FhirResourceDaoDstu3InterceptorTest extends BaseJpaDstu3Test {
public void testJpaDelete() {
Patient p = new Patient();
p.addName().addFamily("PATIENT");
Long id = myPatientDao.create(p).getId().getIdPartAsLong();
Long id = myPatientDao.create(p, new ServletRequestDetails()).getId().getIdPartAsLong();
myPatientDao.delete(new IdType("Patient", id));
myPatientDao.delete(new IdType("Patient", id), new ServletRequestDetails());
ArgumentCaptor<ActionRequestDetails> detailsCapt;
ArgumentCaptor<ResourceTable> tableCapt;
@ -102,12 +103,12 @@ public class FhirResourceDaoDstu3InterceptorTest extends BaseJpaDstu3Test {
public void testJpaUpdate() {
Patient p = new Patient();
p.addName().addFamily("PATIENT");
Long id = myPatientDao.create(p).getId().getIdPartAsLong();
Long id = myPatientDao.create(p, new ServletRequestDetails()).getId().getIdPartAsLong();
p = new Patient();
p.setId(new IdType(id));
p.addName().addFamily("PATIENT1");
Long id2 = myPatientDao.update(p).getId().getIdPartAsLong();
Long id2 = myPatientDao.update(p, new ServletRequestDetails()).getId().getIdPartAsLong();
assertEquals(id, id2);
ArgumentCaptor<ActionRequestDetails> detailsCapt;
@ -126,7 +127,7 @@ public class FhirResourceDaoDstu3InterceptorTest extends BaseJpaDstu3Test {
p = new Patient();
p.setId(new IdType(id));
p.addName().addFamily("PATIENT2");
id2 = myPatientDao.update(p, "Patient?family=PATIENT1").getId().getIdPartAsLong();
id2 = myPatientDao.update(p, "Patient?family=PATIENT1", new ServletRequestDetails()).getId().getIdPartAsLong();
assertEquals(id, id2);
detailsCapt = ArgumentCaptor.forClass(ActionRequestDetails.class);
@ -141,7 +142,7 @@ public class FhirResourceDaoDstu3InterceptorTest extends BaseJpaDstu3Test {
p = new Patient();
p.addName().addFamily("PATIENT3");
id2 = myPatientDao.update(p, "Patient?family=ZZZ").getId().getIdPartAsLong();
id2 = myPatientDao.update(p, "Patient?family=ZZZ", new ServletRequestDetails()).getId().getIdPartAsLong();
assertNotEquals(id, id2);
detailsCapt = ArgumentCaptor.forClass(ActionRequestDetails.class);

View File

@ -17,10 +17,10 @@ import org.hl7.fhir.dstu3.model.Base64BinaryType;
import org.hl7.fhir.dstu3.model.Device;
import org.hl7.fhir.dstu3.model.Media;
import org.hl7.fhir.dstu3.model.Observation;
import org.hl7.fhir.dstu3.model.Observation.ObservationStatus;
import org.hl7.fhir.dstu3.model.Patient;
import org.hl7.fhir.dstu3.model.Quantity;
import org.hl7.fhir.dstu3.model.StringType;
import org.hl7.fhir.dstu3.model.Observation.ObservationStatus;
import org.hl7.fhir.instance.model.api.IIdType;
import org.junit.Ignore;
import org.junit.Test;
@ -33,6 +33,7 @@ import ca.uhn.fhir.rest.param.StringParam;
import ca.uhn.fhir.rest.param.TokenParam;
import ca.uhn.fhir.rest.param.TokenParamModifier;
import ca.uhn.fhir.rest.server.Constants;
import ca.uhn.fhir.rest.server.servlet.ServletRequestDetails;
public class FhirResourceDaoDstu3SearchFtTest extends BaseJpaDstu3Test {
@ -46,13 +47,13 @@ public class FhirResourceDaoDstu3SearchFtTest extends BaseJpaDstu3Test {
obs1.setStatus(ObservationStatus.FINAL);
obs1.setValue(new Quantity(123));
obs1.setComments("obs1");
IIdType id1 = myObservationDao.create(obs1).getId().toUnqualifiedVersionless();
IIdType id1 = myObservationDao.create(obs1, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
Observation obs2 = new Observation();
obs2.getCode().setText("Diastolic Blood Pressure");
obs2.setStatus(ObservationStatus.FINAL);
obs2.setValue(new Quantity(81));
IIdType id2 = myObservationDao.create(obs2).getId().toUnqualifiedVersionless();
IIdType id2 = myObservationDao.create(obs2, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
SearchParameterMap map;
@ -78,13 +79,13 @@ public class FhirResourceDaoDstu3SearchFtTest extends BaseJpaDstu3Test {
obs1.getCode().setText("AAAAA");
obs1.setValue(new StringType("Systolic Blood Pressure"));
obs1.setStatus(ObservationStatus.FINAL);
IIdType id1 = myObservationDao.create(obs1).getId().toUnqualifiedVersionless();
IIdType id1 = myObservationDao.create(obs1, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
Observation obs2 = new Observation();
obs1.getCode().setText("AAAAA");
obs1.setValue(new StringType("Diastolic Blood Pressure"));
obs2.setStatus(ObservationStatus.FINAL);
IIdType id2 = myObservationDao.create(obs2).getId().toUnqualifiedVersionless();
IIdType id2 = myObservationDao.create(obs2, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
SearchParameterMap map;
@ -99,7 +100,7 @@ public class FhirResourceDaoDstu3SearchFtTest extends BaseJpaDstu3Test {
public void testSuggestIgnoresBase64Content() {
Patient patient = new Patient();
patient.addName().addFamily("testSuggest");
IIdType ptId = myPatientDao.create(patient).getId().toUnqualifiedVersionless();
IIdType ptId = myPatientDao.create(patient, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
Media med = new Media();
med.getSubject().setReferenceElement(ptId);
@ -107,7 +108,7 @@ public class FhirResourceDaoDstu3SearchFtTest extends BaseJpaDstu3Test {
med.getContent().setContentType("LCws");
med.getContent().setDataElement(new Base64BinaryType(new byte[] {44,44,44,44,44,44,44,44}));
med.getContent().setTitle("bbbb syst");
myMediaDao.create(med);
myMediaDao.create(med, new ServletRequestDetails());
ourLog.info(myFhirCtx.newJsonParser().encodeResourceToString(med));
List<Suggestion> output = mySearchDao.suggestKeywords("Patient/" + ptId.getIdPart() + "/$everything", "_content", "press");
@ -139,35 +140,35 @@ public class FhirResourceDaoDstu3SearchFtTest extends BaseJpaDstu3Test {
public void testSuggest() {
Patient patient = new Patient();
patient.addName().addFamily("testSuggest");
IIdType ptId = myPatientDao.create(patient).getId().toUnqualifiedVersionless();
IIdType ptId = myPatientDao.create(patient, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
Observation obs = new Observation();
obs.getSubject().setReferenceElement(ptId);
obs.getCode().setText("ZXCVBNM ASDFGHJKL QWERTYUIOPASDFGHJKL");
myObservationDao.create(obs);
myObservationDao.create(obs, new ServletRequestDetails());
obs = new Observation();
obs.getSubject().setReferenceElement(ptId);
obs.getCode().setText("MNBVCXZ");
myObservationDao.create(obs);
myObservationDao.create(obs, new ServletRequestDetails());
obs = new Observation();
obs.getSubject().setReferenceElement(ptId);
obs.getCode().setText("ZXC HELLO");
obs.addComponent().getCode().setText("HHHHHHHHHH");
myObservationDao.create(obs);
myObservationDao.create(obs, new ServletRequestDetails());
/*
* These shouldn't match since they're for another patient
*/
patient = new Patient();
patient.addName().addFamily("testSuggest2");
IIdType ptId2 = myPatientDao.create(patient).getId().toUnqualifiedVersionless();
IIdType ptId2 = myPatientDao.create(patient, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
Observation obs2 = new Observation();
obs2.getSubject().setReferenceElement(ptId2);
obs2.getCode().setText("ZXCVBNMZZ");
myObservationDao.create(obs2);
myObservationDao.create(obs2, new ServletRequestDetails());
List<Suggestion> output = mySearchDao.suggestKeywords("Patient/" + ptId.getIdPart() + "/$everything", "_content", "ZXCVBNM");
ourLog.info("Found: " + output);
@ -212,7 +213,7 @@ public class FhirResourceDaoDstu3SearchFtTest extends BaseJpaDstu3Test {
patient = new Patient();
patient.getText().setDivAsString("<div>DIVAAA</div>");
patient.addName().addGiven("NAMEAAA");
IIdType pId1 = myPatientDao.create(patient).getId().toUnqualifiedVersionless();
IIdType pId1 = myPatientDao.create(patient, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
map = new SearchParameterMap();
map.add(Constants.PARAM_CONTENT, new StringParam("NAMEAAA"));
@ -230,7 +231,7 @@ public class FhirResourceDaoDstu3SearchFtTest extends BaseJpaDstu3Test {
patient.setId(pId1);
patient.getText().setDivAsString("<div>DIVBBB</div>");
patient.addName().addGiven("NAMEBBB");
myPatientDao.update(patient);
myPatientDao.update(patient, new ServletRequestDetails());
map = new SearchParameterMap();
map.add(Constants.PARAM_CONTENT, new StringParam("NAMEAAA"));
@ -254,19 +255,19 @@ public class FhirResourceDaoDstu3SearchFtTest extends BaseJpaDstu3Test {
public void testEverythingInstanceWithContentFilter() {
Patient pt1 = new Patient();
pt1.addName().addFamily("Everything").addGiven("Arthur");
IIdType ptId1 = myPatientDao.create(pt1).getId().toUnqualifiedVersionless();
IIdType ptId1 = myPatientDao.create(pt1, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
Patient pt2 = new Patient();
pt2.addName().addFamily("Everything").addGiven("Arthur");
IIdType ptId2 = myPatientDao.create(pt2).getId().toUnqualifiedVersionless();
IIdType ptId2 = myPatientDao.create(pt2, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
Device dev1 = new Device();
dev1.setManufacturer("Some Manufacturer");
IIdType devId1 = myDeviceDao.create(dev1).getId().toUnqualifiedVersionless();
IIdType devId1 = myDeviceDao.create(dev1, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
Device dev2 = new Device();
dev2.setManufacturer("Some Manufacturer 2");
myDeviceDao.create(dev2).getId().toUnqualifiedVersionless();
myDeviceDao.create(dev2, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
Observation obs1 = new Observation();
obs1.getText().setDivAsString("<div>OBSTEXT1</div>");
@ -274,19 +275,19 @@ public class FhirResourceDaoDstu3SearchFtTest extends BaseJpaDstu3Test {
obs1.getCode().addCoding().setCode("CODE1");
obs1.setValue(new StringType("obsvalue1"));
obs1.getDevice().setReferenceElement(devId1);
IIdType obsId1 = myObservationDao.create(obs1).getId().toUnqualifiedVersionless();
IIdType obsId1 = myObservationDao.create(obs1, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
Observation obs2 = new Observation();
obs2.getSubject().setReferenceElement(ptId1);
obs2.getCode().addCoding().setCode("CODE2");
obs2.setValue(new StringType("obsvalue2"));
IIdType obsId2 = myObservationDao.create(obs2).getId().toUnqualifiedVersionless();
IIdType obsId2 = myObservationDao.create(obs2, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
Observation obs3 = new Observation();
obs3.getSubject().setReferenceElement(ptId2);
obs3.getCode().addCoding().setCode("CODE3");
obs3.setValue(new StringType("obsvalue3"));
IIdType obsId3 = myObservationDao.create(obs3).getId().toUnqualifiedVersionless();
IIdType obsId3 = myObservationDao.create(obs3, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
HttpServletRequest request;
List<String> actual;
@ -297,16 +298,16 @@ public class FhirResourceDaoDstu3SearchFtTest extends BaseJpaDstu3Test {
param = new StringAndListParam();
param.addAnd(new StringOrListParam().addOr(new StringParam("obsvalue1")));
actual = toUnqualifiedVersionlessIdValues(myPatientDao.patientInstanceEverything(request, ptId1, null, null, null, param, null));
actual = toUnqualifiedVersionlessIdValues(myPatientDao.patientInstanceEverything(request, ptId1, null, null, null, param, null, new ServletRequestDetails()));
assertThat(actual, containsInAnyOrder(toValues(ptId1, obsId1, devId1)));
param = new StringAndListParam();
param.addAnd(new StringOrListParam().addOr(new StringParam("obstext1")));
actual = toUnqualifiedVersionlessIdValues(myPatientDao.patientInstanceEverything(request, ptId1, null, null, null, null, param));
actual = toUnqualifiedVersionlessIdValues(myPatientDao.patientInstanceEverything(request, ptId1, null, null, null, null, param, new ServletRequestDetails()));
assertThat(actual, containsInAnyOrder(toValues(ptId1, obsId1, devId1)));
request = mock(HttpServletRequest.class);
actual = toUnqualifiedVersionlessIdValues(myPatientDao.patientInstanceEverything(request, ptId1, null, null, null, null, null));
actual = toUnqualifiedVersionlessIdValues(myPatientDao.patientInstanceEverything(request, ptId1, null, null, null, null, null, new ServletRequestDetails()));
assertThat(actual, containsInAnyOrder(toValues(ptId1, obsId1, obsId2, devId1)));
/*
@ -317,12 +318,12 @@ public class FhirResourceDaoDstu3SearchFtTest extends BaseJpaDstu3Test {
obs4.getSubject().setReferenceElement(ptId1);
obs4.getCode().addCoding().setCode("CODE1");
obs4.setValue(new StringType("obsvalue1"));
IIdType obsId4 = myObservationDao.create(obs4).getId().toUnqualifiedVersionless();
IIdType obsId4 = myObservationDao.create(obs4, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
assertNotEquals(obsId1.getIdPart(), obsId4.getIdPart(), devId1);
param = new StringAndListParam();
param.addAnd(new StringOrListParam().addOr(new StringParam("obsvalue1")));
actual = toUnqualifiedVersionlessIdValues(myPatientDao.patientInstanceEverything(request, ptId1, null, null, null, param, null));
actual = toUnqualifiedVersionlessIdValues(myPatientDao.patientInstanceEverything(request, ptId1, null, null, null, param, null, new ServletRequestDetails()));
assertThat(actual, containsInAnyOrder(toValues(ptId1, obsId1, obsId4, devId1)));
/*
@ -334,11 +335,11 @@ public class FhirResourceDaoDstu3SearchFtTest extends BaseJpaDstu3Test {
obs1.getSubject().setReferenceElement(ptId1);
obs1.getCode().addCoding().setCode("CODE2");
obs1.setValue(new StringType("obsvalue2"));
myObservationDao.update(obs1);
myObservationDao.update(obs1, new ServletRequestDetails());
param = new StringAndListParam();
param.addAnd(new StringOrListParam().addOr(new StringParam("obsvalue1")));
actual = toUnqualifiedVersionlessIdValues(myPatientDao.patientInstanceEverything(request, ptId1, null, null, null, param, null));
actual = toUnqualifiedVersionlessIdValues(myPatientDao.patientInstanceEverything(request, ptId1, null, null, null, param, null, new ServletRequestDetails()));
assertThat(actual, containsInAnyOrder(toValues(ptId1, obsId4)));
}
@ -347,38 +348,38 @@ public class FhirResourceDaoDstu3SearchFtTest extends BaseJpaDstu3Test {
public void testEverythingTypeWithContentFilter() {
Patient pt1 = new Patient();
pt1.addName().addFamily("Everything").addGiven("Arthur");
IIdType ptId1 = myPatientDao.create(pt1).getId().toUnqualifiedVersionless();
IIdType ptId1 = myPatientDao.create(pt1, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
Patient pt2 = new Patient();
pt2.addName().addFamily("Everything").addGiven("Arthur");
IIdType ptId2 = myPatientDao.create(pt2).getId().toUnqualifiedVersionless();
IIdType ptId2 = myPatientDao.create(pt2, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
Device dev1 = new Device();
dev1.setManufacturer("Some Manufacturer");
IIdType devId1 = myDeviceDao.create(dev1).getId().toUnqualifiedVersionless();
IIdType devId1 = myDeviceDao.create(dev1, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
Device dev2 = new Device();
dev2.setManufacturer("Some Manufacturer 2");
myDeviceDao.create(dev2).getId().toUnqualifiedVersionless();
IIdType devId2 = myDeviceDao.create(dev2, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
Observation obs1 = new Observation();
obs1.getSubject().setReferenceElement(ptId1);
obs1.getCode().addCoding().setCode("CODE1");
obs1.setValue(new StringType("obsvalue1"));
obs1.getDevice().setReferenceElement(devId1);
IIdType obsId1 = myObservationDao.create(obs1).getId().toUnqualifiedVersionless();
IIdType obsId1 = myObservationDao.create(obs1, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
Observation obs2 = new Observation();
obs2.getSubject().setReferenceElement(ptId1);
obs2.getCode().addCoding().setCode("CODE2");
obs2.setValue(new StringType("obsvalue2"));
IIdType obsId2 = myObservationDao.create(obs2).getId().toUnqualifiedVersionless();
IIdType obsId2 = myObservationDao.create(obs2, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
Observation obs3 = new Observation();
obs3.getSubject().setReferenceElement(ptId2);
obs3.getCode().addCoding().setCode("CODE3");
obs3.setValue(new StringType("obsvalue3"));
IIdType obsId3 = myObservationDao.create(obs3).getId().toUnqualifiedVersionless();
IIdType obsId3 = myObservationDao.create(obs3, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
HttpServletRequest request;
List<String> actual;
@ -389,11 +390,11 @@ public class FhirResourceDaoDstu3SearchFtTest extends BaseJpaDstu3Test {
param = new StringAndListParam();
param.addAnd(new StringOrListParam().addOr(new StringParam("obsvalue1")));
actual = toUnqualifiedVersionlessIdValues(myPatientDao.patientTypeEverything(request, null, null, null, param, null));
actual = toUnqualifiedVersionlessIdValues(myPatientDao.patientTypeEverything(request, null, null, null, param, null, new ServletRequestDetails()));
assertThat(actual, containsInAnyOrder(toValues(ptId1, obsId1, devId1)));
request = mock(HttpServletRequest.class);
actual = toUnqualifiedVersionlessIdValues(myPatientDao.patientTypeEverything(request, null, null, null, null, null));
actual = toUnqualifiedVersionlessIdValues(myPatientDao.patientTypeEverything(request, null, null, null, null, null, new ServletRequestDetails()));
assertThat(actual, containsInAnyOrder(toValues(ptId1, obsId1, obsId2, devId1, ptId2, obsId3)));
/*
@ -404,12 +405,12 @@ public class FhirResourceDaoDstu3SearchFtTest extends BaseJpaDstu3Test {
obs4.getSubject().setReferenceElement(ptId1);
obs4.getCode().addCoding().setCode("CODE1");
obs4.setValue(new StringType("obsvalue1"));
IIdType obsId4 = myObservationDao.create(obs4).getId().toUnqualifiedVersionless();
IIdType obsId4 = myObservationDao.create(obs4, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
assertNotEquals(obsId1.getIdPart(), obsId4.getIdPart(), devId1);
param = new StringAndListParam();
param.addAnd(new StringOrListParam().addOr(new StringParam("obsvalue1")));
actual = toUnqualifiedVersionlessIdValues(myPatientDao.patientTypeEverything(request, null, null, null, param, null));
actual = toUnqualifiedVersionlessIdValues(myPatientDao.patientTypeEverything(request, null, null, null, param, null, new ServletRequestDetails()));
assertThat(actual, containsInAnyOrder(toValues(ptId1, obsId1, obsId4, devId1)));
/*
@ -421,11 +422,11 @@ public class FhirResourceDaoDstu3SearchFtTest extends BaseJpaDstu3Test {
obs1.getSubject().setReferenceElement(ptId1);
obs1.getCode().addCoding().setCode("CODE2");
obs1.setValue(new StringType("obsvalue2"));
myObservationDao.update(obs1);
myObservationDao.update(obs1, new ServletRequestDetails());
param = new StringAndListParam();
param.addAnd(new StringOrListParam().addOr(new StringParam("obsvalue1")));
actual = toUnqualifiedVersionlessIdValues(myPatientDao.patientTypeEverything(request, null, null, null, param, null));
actual = toUnqualifiedVersionlessIdValues(myPatientDao.patientTypeEverything(request, null, null, null, param, null, new ServletRequestDetails()));
assertThat(actual, containsInAnyOrder(toValues(ptId1, obsId4)));
}
@ -443,7 +444,7 @@ public class FhirResourceDaoDstu3SearchFtTest extends BaseJpaDstu3Test {
patient = new Patient();
patient.getText().setDivAsString("<div>DIVAAA</div>");
patient.addName().addGiven("NAMEAAA");
IIdType pId1 = myPatientDao.create(patient).getId().toUnqualifiedVersionless();
IIdType pId1 = myPatientDao.create(patient, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
map = new SearchParameterMap();
map.add(Constants.PARAM_CONTENT, new StringParam("NAMEAAA"));
@ -461,7 +462,7 @@ public class FhirResourceDaoDstu3SearchFtTest extends BaseJpaDstu3Test {
patient.setId(pId1);
patient.getText().setDivAsString("<div>DIVBBB</div>");
patient.addName().addGiven("NAMEBBB");
myPatientDao.update(patient, null, false);
myPatientDao.update(patient, null, false, new ServletRequestDetails());
map = new SearchParameterMap();
map.add(Constants.PARAM_CONTENT, new StringParam("NAMEAAA"));
@ -470,7 +471,7 @@ public class FhirResourceDaoDstu3SearchFtTest extends BaseJpaDstu3Test {
map.add(Constants.PARAM_CONTENT, new StringParam("NAMEBBB"));
assertThat(toUnqualifiedVersionlessIdValues(myPatientDao.search(map)), not(contains(toValues(pId1))));
myPatientDao.update(patient, null, true);
myPatientDao.update(patient, null, true, new ServletRequestDetails());
map = new SearchParameterMap();
map.add(Constants.PARAM_CONTENT, new StringParam("NAMEAAA"));
@ -498,18 +499,18 @@ public class FhirResourceDaoDstu3SearchFtTest extends BaseJpaDstu3Test {
Patient patient = new Patient();
patient.addName().addGiven(methodName);
patient.addAddress().addLine("My fulltext address");
pId1 = myPatientDao.create(patient).getId().toUnqualifiedVersionless();
pId1 = myPatientDao.create(patient, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
}
Observation obs = new Observation();
obs.getSubject().setReferenceElement(pId1);
obs.setValue(new StringType("This is the FULLtext of the observation"));
IIdType oId1 = myObservationDao.create(obs).getId().toUnqualifiedVersionless();
IIdType oId1 = myObservationDao.create(obs, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
obs = new Observation();
obs.getSubject().setReferenceElement(pId1);
obs.setValue(new StringType("Another fullText"));
IIdType oId2 = myObservationDao.create(obs).getId().toUnqualifiedVersionless();
IIdType oId2 = myObservationDao.create(obs, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
List<String> patients;
SearchParameterMap params;

View File

@ -51,7 +51,6 @@ import org.hl7.fhir.dstu3.model.Subscription.SubscriptionStatus;
import org.hl7.fhir.dstu3.model.Substance;
import org.hl7.fhir.dstu3.model.TemporalPrecisionEnum;
import org.hl7.fhir.dstu3.model.ValueSet;
import org.hl7.fhir.instance.model.api.IAnyResource;
import org.hl7.fhir.instance.model.api.IBaseResource;
import org.hl7.fhir.instance.model.api.IIdType;
import org.junit.Ignore;
@ -89,6 +88,7 @@ import ca.uhn.fhir.rest.server.Constants;
import ca.uhn.fhir.rest.server.IBundleProvider;
import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException;
import ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException;
import ca.uhn.fhir.rest.server.servlet.ServletRequestDetails;
@SuppressWarnings("unchecked")
public class FhirResourceDaoDstu3SearchNoFtTest extends BaseJpaDstu3Test {
@ -100,7 +100,7 @@ public class FhirResourceDaoDstu3SearchNoFtTest extends BaseJpaDstu3Test {
subs.setStatus(SubscriptionStatus.ACTIVE);
subs.getChannel().setType(SubscriptionChannelType.WEBSOCKET);
subs.setCriteria("Observation?");
IIdType id = mySubscriptionDao.create(subs).getId().toUnqualifiedVersionless();
IIdType id = mySubscriptionDao.create(subs, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
SearchParameterMap map = new SearchParameterMap();
map.add(Subscription.SP_TYPE, new TokenParam(null, SubscriptionChannelType.WEBSOCKET.toCode()));
@ -114,33 +114,33 @@ public class FhirResourceDaoDstu3SearchNoFtTest extends BaseJpaDstu3Test {
Organization org = new Organization();
org.setName(methodName);
IIdType orgId = myOrganizationDao.create(org).getId().toUnqualifiedVersionless();
IIdType orgId = myOrganizationDao.create(org, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
Medication med = new Medication();
med.getCode().setText(methodName);
IIdType medId = myMedicationDao.create(med).getId().toUnqualifiedVersionless();
IIdType medId = myMedicationDao.create(med, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
Patient pat = new Patient();
pat.addAddress().addLine(methodName);
pat.getManagingOrganization().setReferenceElement(orgId);
IIdType patId = myPatientDao.create(pat).getId().toUnqualifiedVersionless();
IIdType patId = myPatientDao.create(pat, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
Patient pat2 = new Patient();
pat2.addAddress().addLine(methodName);
pat2.getManagingOrganization().setReferenceElement(orgId);
IIdType patId2 = myPatientDao.create(pat2).getId().toUnqualifiedVersionless();
IIdType patId2 = myPatientDao.create(pat2, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
MedicationOrder mo = new MedicationOrder();
mo.getPatient().setReferenceElement(patId);
mo.setMedication(new Reference(medId));
IIdType moId = myMedicationOrderDao.create(mo).getId().toUnqualifiedVersionless();
IIdType moId = myMedicationOrderDao.create(mo, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
HttpServletRequest request = mock(HttpServletRequest.class);
IBundleProvider resp = myPatientDao.patientTypeEverything(request, null, null, null, null, null);
IBundleProvider resp = myPatientDao.patientTypeEverything(request, null, null, null, null, null, new ServletRequestDetails());
assertThat(toUnqualifiedVersionlessIds(resp), containsInAnyOrder(orgId, medId, patId, moId, patId2));
request = mock(HttpServletRequest.class);
resp = myPatientDao.patientInstanceEverything(request, patId, null, null, null, null, null);
resp = myPatientDao.patientInstanceEverything(request, patId, null, null, null, null, null, new ServletRequestDetails());
assertThat(toUnqualifiedVersionlessIds(resp), containsInAnyOrder(orgId, medId, patId, moId));
}
@ -154,7 +154,7 @@ public class FhirResourceDaoDstu3SearchNoFtTest extends BaseJpaDstu3Test {
order.addItem().addEvent().setDateTimeElement(new DateTimeType("2011-12-12T11:12:12Z"));
order.addItem().addEvent().setDateTimeElement(new DateTimeType("2011-12-12T11:12:12Z"));
IIdType id = myDiagnosticOrderDao.create(order).getId().toUnqualifiedVersionless();
IIdType id = myDiagnosticOrderDao.create(order, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
List<IIdType> actual = toUnqualifiedVersionlessIds(myDiagnosticOrderDao.search(DiagnosticOrder.SP_ITEM_DATE, new DateParam("2011-12-12T11:12:12Z")));
assertThat(actual, contains(id));
@ -175,7 +175,7 @@ public class FhirResourceDaoDstu3SearchNoFtTest extends BaseJpaDstu3Test {
res.addVaccinationProtocol().setDoseSequence(2);
res.addVaccinationProtocol().setDoseSequence(2);
IIdType id = myImmunizationDao.create(res).getId().toUnqualifiedVersionless();
IIdType id = myImmunizationDao.create(res, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
List<IIdType> actual = toUnqualifiedVersionlessIds(myImmunizationDao.search(Immunization.SP_DOSE_SEQUENCE, new NumberParam("1")));
assertThat(actual, contains(id));
@ -194,7 +194,7 @@ public class FhirResourceDaoDstu3SearchNoFtTest extends BaseJpaDstu3Test {
res.addInstance().getQuantity().setSystem("http://foo2").setCode("UNIT2").setValue(1232);
res.addInstance().getQuantity().setSystem("http://foo2").setCode("UNIT2").setValue(1232);
IIdType id = mySubstanceDao.create(res).getId().toUnqualifiedVersionless();
IIdType id = mySubstanceDao.create(res, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
Class<ResourceIndexedSearchParamQuantity> type = ResourceIndexedSearchParamQuantity.class;
List<?> results = myEntityManager.createQuery("SELECT i FROM " + type.getSimpleName() + " i", type).getResultList();
@ -210,11 +210,11 @@ public class FhirResourceDaoDstu3SearchNoFtTest extends BaseJpaDstu3Test {
Practitioner pract =new Practitioner();
pract.setId("Practitioner/somepract");
pract.getName().addFamily("SOME PRACT");
myPractitionerDao.update(pract);
myPractitionerDao.update(pract, new ServletRequestDetails());
Practitioner pract2 =new Practitioner();
pract2.setId("Practitioner/somepract2");
pract2.getName().addFamily("SOME PRACT2");
myPractitionerDao.update(pract2);
myPractitionerDao.update(pract2, new ServletRequestDetails());
DiagnosticOrder res = new DiagnosticOrder();
res.addEvent().setActor(new Reference("Practitioner/somepract"));
@ -222,7 +222,7 @@ public class FhirResourceDaoDstu3SearchNoFtTest extends BaseJpaDstu3Test {
res.addEvent().setActor(new Reference("Practitioner/somepract2"));
res.addEvent().setActor(new Reference("Practitioner/somepract2"));
IIdType id = myDiagnosticOrderDao.create(res).getId().toUnqualifiedVersionless();
IIdType id = myDiagnosticOrderDao.create(res, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
Class<ResourceLink> type = ResourceLink.class;
List<?> results = myEntityManager.createQuery("SELECT i FROM " + type.getSimpleName() + " i", type).getResultList();
@ -243,7 +243,7 @@ public class FhirResourceDaoDstu3SearchNoFtTest extends BaseJpaDstu3Test {
p.addAddress().addLine("456 Fake Street");
p.addAddress().addLine("456 Fake Street");
IIdType id = myPatientDao.create(p).getId().toUnqualifiedVersionless();
IIdType id = myPatientDao.create(p, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
Class<ResourceIndexedSearchParamString> type = ResourceIndexedSearchParamString.class;
List<ResourceIndexedSearchParamString> results = myEntityManager.createQuery("SELECT i FROM " + type.getSimpleName() + " i", type).getResultList();
@ -262,7 +262,7 @@ public class FhirResourceDaoDstu3SearchNoFtTest extends BaseJpaDstu3Test {
res.addIdentifier().setSystem("http://foo2").setValue("1234");
res.addIdentifier().setSystem("http://foo2").setValue("1234");
IIdType id = myPatientDao.create(res).getId().toUnqualifiedVersionless();
IIdType id = myPatientDao.create(res, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
Class<ResourceIndexedSearchParamToken> type = ResourceIndexedSearchParamToken.class;
List<?> results = myEntityManager.createQuery("SELECT i FROM " + type.getSimpleName() + " i", type).getResultList();
@ -281,7 +281,7 @@ public class FhirResourceDaoDstu3SearchNoFtTest extends BaseJpaDstu3Test {
res.addElement().addTarget().addDependsOn().setElement("http://bar");
res.addElement().addTarget().addDependsOn().setElement("http://bar");
IIdType id = myConceptMapDao.create(res).getId().toUnqualifiedVersionless();
IIdType id = myConceptMapDao.create(res, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
Class<ResourceIndexedSearchParamUri> type = ResourceIndexedSearchParamUri.class;
List<?> results = myEntityManager.createQuery("SELECT i FROM " + type.getSimpleName() + " i", type).getResultList();
@ -298,13 +298,13 @@ public class FhirResourceDaoDstu3SearchNoFtTest extends BaseJpaDstu3Test {
Patient patient = new Patient();
patient.addIdentifier().setSystem("urn:system").setValue("001");
patient.addName().addFamily("Tester").addGiven("Joe");
myPatientDao.create(patient);
myPatientDao.create(patient, new ServletRequestDetails());
}
{
Patient patient = new Patient();
patient.addIdentifier().setSystem("urn:system").setValue("002");
patient.addName().addFamily("Tester").addGiven("John");
myPatientDao.create(patient);
myPatientDao.create(patient, new ServletRequestDetails());
}
Map<String, IQueryParameterType> params = new HashMap<String, IQueryParameterType>();
@ -318,13 +318,13 @@ public class FhirResourceDaoDstu3SearchNoFtTest extends BaseJpaDstu3Test {
{
Patient patient = new Patient();
patient.addIdentifier().setSystem("urn:system").setValue("001");
id1 = myPatientDao.create(patient).getId();
id1 = myPatientDao.create(patient, new ServletRequestDetails()).getId();
}
IIdType id2;
{
Organization patient = new Organization();
patient.addIdentifier().setSystem("urn:system").setValue("001");
id2 = myOrganizationDao.create(patient).getId();
id2 = myOrganizationDao.create(patient, new ServletRequestDetails()).getId();
}
Map<String, IQueryParameterType> params = new HashMap<String, IQueryParameterType>();
@ -345,13 +345,13 @@ public class FhirResourceDaoDstu3SearchNoFtTest extends BaseJpaDstu3Test {
{
Patient patient = new Patient();
patient.addIdentifier().setSystem("urn:system").setValue("001");
id1 = myPatientDao.create(patient).getId().toUnqualifiedVersionless();
id1 = myPatientDao.create(patient, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
}
IIdType id2;
{
Patient patient = new Patient();
patient.addIdentifier().setSystem("urn:system").setValue("001");
id2 = myPatientDao.create(patient).getId().toUnqualifiedVersionless();
id2 = myPatientDao.create(patient, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
}
SearchParameterMap params;
@ -393,14 +393,14 @@ public class FhirResourceDaoDstu3SearchNoFtTest extends BaseJpaDstu3Test {
{
Patient patient = new Patient();
patient.addIdentifier().setSystem("urn:system").setValue("001");
id1 = myPatientDao.create(patient).getId().toUnqualifiedVersionless();
id1 = myPatientDao.create(patient, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
}
long betweenTime = System.currentTimeMillis();
IIdType id2;
{
Patient patient = new Patient();
patient.addIdentifier().setSystem("urn:system").setValue("001");
id2 = myPatientDao.create(patient).getId().toUnqualifiedVersionless();
id2 = myPatientDao.create(patient, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
}
SearchParameterMap params = new SearchParameterMap();
@ -430,13 +430,13 @@ public class FhirResourceDaoDstu3SearchNoFtTest extends BaseJpaDstu3Test {
{
Patient patient = new Patient();
patient.addIdentifier().setSystem("urn:system").setValue("001");
id1 = myPatientDao.create(patient).getId().toUnqualifiedVersionless();
id1 = myPatientDao.create(patient, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
}
IIdType id2;
{
Organization patient = new Organization();
patient.addIdentifier().setSystem("urn:system").setValue("001");
id2 = myOrganizationDao.create(patient).getId().toUnqualifiedVersionless();
id2 = myOrganizationDao.create(patient, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
}
SearchParameterMap params = new SearchParameterMap();
@ -450,12 +450,12 @@ public class FhirResourceDaoDstu3SearchNoFtTest extends BaseJpaDstu3Test {
Observation o1 = new Observation();
o1.getCode().addCoding().setSystem("foo").setCode("testSearchCompositeParamN01");
o1.setValue(new StringType("testSearchCompositeParamS01"));
IIdType id1 = myObservationDao.create(o1).getId();
IIdType id1 = myObservationDao.create(o1, new ServletRequestDetails()).getId();
Observation o2 = new Observation();
o2.getCode().addCoding().setSystem("foo").setCode("testSearchCompositeParamN01");
o2.setValue(new StringType("testSearchCompositeParamS02"));
IIdType id2 = myObservationDao.create(o2).getId();
IIdType id2 = myObservationDao.create(o2, new ServletRequestDetails()).getId();
{
TokenParam v0 = new TokenParam("foo", "testSearchCompositeParamN01");
@ -480,12 +480,12 @@ public class FhirResourceDaoDstu3SearchNoFtTest extends BaseJpaDstu3Test {
Observation o1 = new Observation();
o1.getCode().addCoding().setSystem("foo").setCode("testSearchCompositeParamDateN01");
o1.setValue(new Period().setStartElement(new DateTimeType("2001-01-01T11:11:11")));
IIdType id1 = myObservationDao.create(o1).getId().toUnqualifiedVersionless();
IIdType id1 = myObservationDao.create(o1, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
Observation o2 = new Observation();
o2.getCode().addCoding().setSystem("foo").setCode("testSearchCompositeParamDateN01");
o2.setValue(new Period().setStartElement(new DateTimeType("2001-01-01T12:12:12")));
IIdType id2 = myObservationDao.create(o2).getId().toUnqualifiedVersionless();
IIdType id2 = myObservationDao.create(o2, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
{
TokenParam v0 = new TokenParam("foo", "testSearchCompositeParamDateN01");
@ -520,7 +520,7 @@ public class FhirResourceDaoDstu3SearchNoFtTest extends BaseJpaDstu3Test {
patient.setLanguageElement(new CodeType("TEST"));
patient.addName().addFamily("TEST");
patient.addIdentifier().setSystem("TEST").setValue("TEST");
myPatientDao.update(patient);
myPatientDao.update(patient, new ServletRequestDetails());
}
Map<String, IQueryParameterType> params = new HashMap<String, IQueryParameterType>();
@ -536,7 +536,7 @@ public class FhirResourceDaoDstu3SearchNoFtTest extends BaseJpaDstu3Test {
params.put(Patient.SP_NAME, new StringParam("TEST"));
assertEquals(1, toList(myPatientDao.search(params)).size());
myPatientDao.delete(new IdType("Patient/TEST"));
myPatientDao.delete(new IdType("Patient/TEST"), new ServletRequestDetails());
params = new HashMap<String, IQueryParameterType>();
params.put("_id", new StringParam("TEST"));
@ -572,7 +572,7 @@ public class FhirResourceDaoDstu3SearchNoFtTest extends BaseJpaDstu3Test {
patient.getLanguageElement().setValue("en_CA");
patient.addIdentifier().setSystem("urn:system").setValue("001");
patient.addName().addFamily("testSearchLanguageParam").addGiven("Joe");
id1 = myPatientDao.create(patient).getId();
id1 = myPatientDao.create(patient, new ServletRequestDetails()).getId();
}
IIdType id2;
{
@ -580,7 +580,7 @@ public class FhirResourceDaoDstu3SearchNoFtTest extends BaseJpaDstu3Test {
patient.getLanguageElement().setValue("en_US");
patient.addIdentifier().setSystem("urn:system").setValue("002");
patient.addName().addFamily("testSearchLanguageParam").addGiven("John");
id2 = myPatientDao.create(patient).getId();
id2 = myPatientDao.create(patient, new ServletRequestDetails()).getId();
}
{
Map<String, IQueryParameterType> params = new HashMap<String, IQueryParameterType>();
@ -612,7 +612,7 @@ public class FhirResourceDaoDstu3SearchNoFtTest extends BaseJpaDstu3Test {
patient.getLanguageElement().setValue("en_CA");
patient.addIdentifier().setSystem("urn:system").setValue("001");
patient.addName().addFamily("testSearchLanguageParam").addGiven("Joe");
id1 = myPatientDao.create(patient).getId().toUnqualifiedVersionless();
id1 = myPatientDao.create(patient, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
}
Date betweenTime = new Date();
@ -623,7 +623,7 @@ public class FhirResourceDaoDstu3SearchNoFtTest extends BaseJpaDstu3Test {
patient.getLanguageElement().setValue("en_US");
patient.addIdentifier().setSystem("urn:system").setValue("002");
patient.addName().addFamily("testSearchLanguageParam").addGiven("John");
id2 = myPatientDao.create(patient).getId().toUnqualifiedVersionless();
id2 = myPatientDao.create(patient, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
}
{
SearchParameterMap params = new SearchParameterMap();
@ -707,14 +707,14 @@ public class FhirResourceDaoDstu3SearchNoFtTest extends BaseJpaDstu3Test {
Patient patient = new Patient();
patient.addIdentifier().setSystem("urn:system").setValue("001");
patient.addName().addFamily(methodName).addGiven("Joe");
id1a = myPatientDao.create(patient).getId().toUnqualifiedVersionless();
id1a = myPatientDao.create(patient, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
}
IIdType id1b;
{
Patient patient = new Patient();
patient.addIdentifier().setSystem("urn:system").setValue("002");
patient.addName().addFamily(methodName + "XXXX").addGiven("Joe");
id1b = myPatientDao.create(patient).getId().toUnqualifiedVersionless();
id1b = myPatientDao.create(patient, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
}
Thread.sleep(1100);
@ -726,7 +726,7 @@ public class FhirResourceDaoDstu3SearchNoFtTest extends BaseJpaDstu3Test {
Patient patient = new Patient();
patient.addIdentifier().setSystem("urn:system").setValue("002");
patient.addName().addFamily(methodName).addGiven("John");
id2 = myPatientDao.create(patient).getId().toUnqualifiedVersionless();
id2 = myPatientDao.create(patient, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
}
{
@ -769,7 +769,7 @@ public class FhirResourceDaoDstu3SearchNoFtTest extends BaseJpaDstu3Test {
{
Patient patient = new Patient();
patient.addIdentifier().setSystem("urn:system").setValue("001");
id0 = myPatientDao.create(patient).getId().toUnqualifiedVersionless();
id0 = myPatientDao.create(patient, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
}
int sleep = 100;
@ -781,18 +781,18 @@ public class FhirResourceDaoDstu3SearchNoFtTest extends BaseJpaDstu3Test {
{
Patient patient = new Patient();
patient.addIdentifier().setSystem("urn:system").setValue("001");
id1a = myPatientDao.create(patient).getId().toUnqualifiedVersionless();
id1a = myPatientDao.create(patient, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
}
IIdType id1b;
{
Patient patient = new Patient();
patient.addIdentifier().setSystem("urn:system").setValue("001");
id1b = myPatientDao.create(patient).getId().toUnqualifiedVersionless();
id1b = myPatientDao.create(patient, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
}
ourLog.info("Res 1: {}", myPatientDao.read(id0).getMeta().getLastUpdatedElement().getValueAsString());
ourLog.info("Res 2: {}", myPatientDao.read(id1a).getMeta().getLastUpdatedElement().getValueAsString());
ourLog.info("Res 3: {}", myPatientDao.read(id1b).getMeta().getLastUpdatedElement().getValueAsString());
ourLog.info("Res 1: {}", myPatientDao.read(id0, new ServletRequestDetails()).getMeta().getLastUpdatedElement().getValueAsString());
ourLog.info("Res 2: {}", myPatientDao.read(id1a, new ServletRequestDetails()).getMeta().getLastUpdatedElement().getValueAsString());
ourLog.info("Res 3: {}", myPatientDao.read(id1b, new ServletRequestDetails()).getMeta().getLastUpdatedElement().getValueAsString());
Thread.sleep(sleep);
@ -820,7 +820,7 @@ public class FhirResourceDaoDstu3SearchNoFtTest extends BaseJpaDstu3Test {
assertThat(toUnqualifiedVersionlessIds(myPatientDao.search(map)), containsInAnyOrder(id1a, id1b));
map = new SearchParameterMap();
map.setLastUpdated(new DateRangeParam(new DateParam(ParamPrefixEnum.GREATERTHAN, startDateTime.getValue()), new DateParam(ParamPrefixEnum.LESSTHAN, myPatientDao.read(id1b).getMeta().getLastUpdatedElement().getValue())));
map.setLastUpdated(new DateRangeParam(new DateParam(QuantityCompararatorEnum.GREATERTHAN, startDateTime.getValue()), new DateParam(QuantityCompararatorEnum.LESSTHAN, myPatientDao.read(id1b, new ServletRequestDetails()).getMeta().getLastUpdatedElement().getValue())));
ourLog.info("Searching: {}", map.getLastUpdated());
assertThat(toUnqualifiedVersionlessIds(myPatientDao.search(map)), containsInAnyOrder(id1a));
}
@ -831,13 +831,13 @@ public class FhirResourceDaoDstu3SearchNoFtTest extends BaseJpaDstu3Test {
Patient patient = new Patient();
patient.addIdentifier().setSystem("urn:system").setValue("001");
patient.addName().addFamily("testSearchNameParam01Fam").addGiven("testSearchNameParam01Giv");
id1 = myPatientDao.create(patient).getId();
id1 = myPatientDao.create(patient, new ServletRequestDetails()).getId();
}
{
Patient patient = new Patient();
patient.addIdentifier().setSystem("urn:system").setValue("002");
patient.addName().addFamily("testSearchNameParam02Fam").addGiven("testSearchNameParam02Giv");
myPatientDao.create(patient);
myPatientDao.create(patient, new ServletRequestDetails());
}
Map<String, IQueryParameterType> params = new HashMap<String, IQueryParameterType>();
@ -880,7 +880,7 @@ public class FhirResourceDaoDstu3SearchNoFtTest extends BaseJpaDstu3Test {
Location loc = new Location();
loc.getPosition().setLatitude(43.7);
loc.getPosition().setLatitude(79.4);
myLocationDao.create(loc);
myLocationDao.create(loc, new ServletRequestDetails());
}
}
@ -890,12 +890,12 @@ public class FhirResourceDaoDstu3SearchNoFtTest extends BaseJpaDstu3Test {
Encounter e1 = new Encounter();
e1.addIdentifier().setSystem("foo").setValue("testSearchNumberParam01");
e1.getLength().setSystem(BaseHapiFhirDao.UCUM_NS).setCode("min").setValue(4.0 * 24 * 60);
IIdType id1 = myEncounterDao.create(e1).getId();
IIdType id1 = myEncounterDao.create(e1, new ServletRequestDetails()).getId();
Encounter e2 = new Encounter();
e2.addIdentifier().setSystem("foo").setValue("testSearchNumberParam02");
e2.getLength().setSystem(BaseHapiFhirDao.UCUM_NS).setCode("year").setValue(2.0);
IIdType id2 = myEncounterDao.create(e2).getId();
IIdType id2 = myEncounterDao.create(e2, new ServletRequestDetails()).getId();
{
IBundleProvider found = myEncounterDao.search(Encounter.SP_LENGTH, new NumberParam(">2"));
assertEquals(2, found.size());
@ -920,7 +920,7 @@ public class FhirResourceDaoDstu3SearchNoFtTest extends BaseJpaDstu3Test {
{
Patient patient = new Patient();
patient.addName().addFamily(name);
id = myPatientDao.create(patient).getId().toUnqualifiedVersionless();
id = myPatientDao.create(patient, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
}
Map<String, IQueryParameterType> params = new HashMap<String, IQueryParameterType>();
@ -931,7 +931,7 @@ public class FhirResourceDaoDstu3SearchNoFtTest extends BaseJpaDstu3Test {
Patient patient = new Patient();
patient.addIdentifier().setSystem(name).setValue(name);
patient.setId(id);
myPatientDao.update(patient);
myPatientDao.update(patient, new ServletRequestDetails());
params = new HashMap<String, IQueryParameterType>();
params.put(Patient.SP_FAMILY, new StringParam(name));
@ -948,14 +948,14 @@ public class FhirResourceDaoDstu3SearchNoFtTest extends BaseJpaDstu3Test {
Practitioner patient = new Practitioner();
patient.getName().addFamily(methodName);
patient.addTelecom().setSystem(ContactPointSystem.PHONE).setValue("123");
id1 = myPractitionerDao.create(patient).getId().toUnqualifiedVersionless();
id1 = myPractitionerDao.create(patient, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
}
IIdType id2;
{
Practitioner patient = new Practitioner();
patient.getName().addFamily(methodName);
patient.addTelecom().setSystem(ContactPointSystem.EMAIL).setValue("abc");
id2 = myPractitionerDao.create(patient).getId().toUnqualifiedVersionless();
id2 = myPractitionerDao.create(patient, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
}
Map<String, IQueryParameterType> params;
@ -994,27 +994,27 @@ public class FhirResourceDaoDstu3SearchNoFtTest extends BaseJpaDstu3Test {
Patient patient = new Patient();
patient.addIdentifier().setSystem("urn:system").setValue("testSearchResourceLinkWithChainXX");
patient.addIdentifier().setSystem("urn:system").setValue("testSearchResourceLinkWithChain01");
IIdType patientId01 = myPatientDao.create(patient).getId();
IIdType patientId01 = myPatientDao.create(patient, new ServletRequestDetails()).getId();
Patient patient02 = new Patient();
patient02.addIdentifier().setSystem("urn:system").setValue("testSearchResourceLinkWithChainXX");
patient02.addIdentifier().setSystem("urn:system").setValue("testSearchResourceLinkWithChain02");
IIdType patientId02 = myPatientDao.create(patient02).getId();
IIdType patientId02 = myPatientDao.create(patient02, new ServletRequestDetails()).getId();
Observation obs01 = new Observation();
obs01.setEffective(new DateTimeType(new Date()));
obs01.setSubject(new Reference(patientId01));
IIdType obsId01 = myObservationDao.create(obs01).getId();
IIdType obsId01 = myObservationDao.create(obs01, new ServletRequestDetails()).getId();
Observation obs02 = new Observation();
obs02.setEffective(new DateTimeType(new Date()));
obs02.setSubject(new Reference(patientId02));
IIdType obsId02 = myObservationDao.create(obs02).getId();
IIdType obsId02 = myObservationDao.create(obs02, new ServletRequestDetails()).getId();
// Create another type, that shouldn't be returned
DiagnosticReport dr01 = new DiagnosticReport();
dr01.setSubject(new Reference(patientId01));
IIdType drId01 = myDiagnosticReportDao.create(dr01).getId();
IIdType drId01 = myDiagnosticReportDao.create(dr01, new ServletRequestDetails()).getId();
ourLog.info("P1[{}] P2[{}] O1[{}] O2[{}] D1[{}]", new Object[] { patientId01, patientId02, obsId01, obsId02, drId01 });
@ -1048,19 +1048,19 @@ public class FhirResourceDaoDstu3SearchNoFtTest extends BaseJpaDstu3Test {
Organization org = new Organization();
org.setName(methodName);
IIdType orgId01 = myOrganizationDao.create(org).getId().toUnqualifiedVersionless();
IIdType orgId01 = myOrganizationDao.create(org, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
Location locParent = new Location();
locParent.setManagingOrganization(new Reference(orgId01));
IIdType locParentId = myLocationDao.create(locParent).getId().toUnqualifiedVersionless();
IIdType locParentId = myLocationDao.create(locParent, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
Location locChild = new Location();
locChild.setPartOf(new Reference(locParentId));
IIdType locChildId = myLocationDao.create(locChild).getId().toUnqualifiedVersionless();
IIdType locChildId = myLocationDao.create(locChild, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
Location locGrandchild = new Location();
locGrandchild.setPartOf(new Reference(locChildId));
IIdType locGrandchildId = myLocationDao.create(locGrandchild).getId().toUnqualifiedVersionless();
IIdType locGrandchildId = myLocationDao.create(locGrandchild, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
IBundleProvider found;
ReferenceParam param;
@ -1093,21 +1093,21 @@ public class FhirResourceDaoDstu3SearchNoFtTest extends BaseJpaDstu3Test {
Patient patient = new Patient();
patient.addName().addFamily("testSearchResourceLinkWithChainWithMultipleTypes01");
patient.addName().addFamily("testSearchResourceLinkWithChainWithMultipleTypesXX");
IIdType patientId01 = myPatientDao.create(patient).getId();
IIdType patientId01 = myPatientDao.create(patient, new ServletRequestDetails()).getId();
Location loc01 = new Location();
loc01.getNameElement().setValue("testSearchResourceLinkWithChainWithMultipleTypes01");
IIdType locId01 = myLocationDao.create(loc01).getId();
IIdType locId01 = myLocationDao.create(loc01, new ServletRequestDetails()).getId();
Observation obs01 = new Observation();
obs01.setEffective(new DateTimeType(new Date()));
obs01.setSubject(new Reference(patientId01));
IIdType obsId01 = myObservationDao.create(obs01).getId();
IIdType obsId01 = myObservationDao.create(obs01, new ServletRequestDetails()).getId();
Observation obs02 = new Observation();
obs02.setEffective(new DateTimeType(new Date()));
obs02.setSubject(new Reference(locId01));
IIdType obsId02 = myObservationDao.create(obs02).getId();
IIdType obsId02 = myObservationDao.create(obs02, new ServletRequestDetails()).getId();
ourLog.info("P1[{}] L1[{}] Obs1[{}] Obs2[{}]", new Object[] { patientId01, locId01, obsId01, obsId02 });
@ -1134,28 +1134,28 @@ public class FhirResourceDaoDstu3SearchNoFtTest extends BaseJpaDstu3Test {
patient.setId("testSearchResourceLinkWithTextLogicalId01");
patient.addIdentifier().setSystem("urn:system").setValue("testSearchResourceLinkWithTextLogicalIdXX");
patient.addIdentifier().setSystem("urn:system").setValue("testSearchResourceLinkWithTextLogicalId01");
IIdType patientId01 = myPatientDao.update(patient).getId();
IIdType patientId01 = myPatientDao.update(patient, new ServletRequestDetails()).getId();
Patient patient02 = new Patient();
patient02.setId("testSearchResourceLinkWithTextLogicalId02");
patient02.addIdentifier().setSystem("urn:system").setValue("testSearchResourceLinkWithTextLogicalIdXX");
patient02.addIdentifier().setSystem("urn:system").setValue("testSearchResourceLinkWithTextLogicalId02");
IIdType patientId02 = myPatientDao.update(patient02).getId();
IIdType patientId02 = myPatientDao.update(patient02, new ServletRequestDetails()).getId();
Observation obs01 = new Observation();
obs01.setEffective(new DateTimeType(new Date()));
obs01.setSubject(new Reference(patientId01));
IIdType obsId01 = myObservationDao.create(obs01).getId();
IIdType obsId01 = myObservationDao.create(obs01, new ServletRequestDetails()).getId();
Observation obs02 = new Observation();
obs02.setEffective(new DateTimeType(new Date()));
obs02.setSubject(new Reference(patientId02));
IIdType obsId02 = myObservationDao.create(obs02).getId();
IIdType obsId02 = myObservationDao.create(obs02, new ServletRequestDetails()).getId();
// Create another type, that shouldn't be returned
DiagnosticReport dr01 = new DiagnosticReport();
dr01.setSubject(new Reference(patientId01));
IIdType drId01 = myDiagnosticReportDao.create(dr01).getId();
IIdType drId01 = myDiagnosticReportDao.create(dr01, new ServletRequestDetails()).getId();
ourLog.info("P1[{}] P2[{}] O1[{}] O2[{}] D1[{}]", new Object[] { patientId01, patientId02, obsId01, obsId02, drId01 });
@ -1186,13 +1186,13 @@ public class FhirResourceDaoDstu3SearchNoFtTest extends BaseJpaDstu3Test {
Patient patient = new Patient();
patient.addIdentifier().setSystem("urn:system").setValue("001");
patient.addName().addFamily("Tester_testSearchStringParam").addGiven("Joe");
myPatientDao.create(patient);
myPatientDao.create(patient, new ServletRequestDetails());
}
{
Patient patient = new Patient();
patient.addIdentifier().setSystem("urn:system").setValue("002");
patient.addName().addFamily("Tester_testSearchStringParam").addGiven("John");
myPatientDao.create(patient);
myPatientDao.create(patient, new ServletRequestDetails());
}
Map<String, IQueryParameterType> params = new HashMap<String, IQueryParameterType>();
@ -1217,12 +1217,12 @@ public class FhirResourceDaoDstu3SearchNoFtTest extends BaseJpaDstu3Test {
Patient patient = new Patient();
patient.addIdentifier().setSystem("urn:system").setValue("001");
patient.addName().addFamily(value);
longId = myPatientDao.create(patient).getId().toUnqualifiedVersionless();
longId = myPatientDao.create(patient, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
}
{
Patient patient = new Patient();
patient.addIdentifier().setSystem("urn:system").setValue("002");
shortId = myPatientDao.create(patient).getId().toUnqualifiedVersionless();
shortId = myPatientDao.create(patient, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
}
Map<String, IQueryParameterType> params = new HashMap<String, IQueryParameterType>();
@ -1241,13 +1241,13 @@ public class FhirResourceDaoDstu3SearchNoFtTest extends BaseJpaDstu3Test {
Patient patient = new Patient();
patient.addIdentifier().setSystem("urn:system").setValue("001");
patient.addName().addGiven("testSearchStringParamWithNonNormalized_h\u00F6ra");
myPatientDao.create(patient);
myPatientDao.create(patient, new ServletRequestDetails());
}
{
Patient patient = new Patient();
patient.addIdentifier().setSystem("urn:system").setValue("002");
patient.addName().addGiven("testSearchStringParamWithNonNormalized_HORA");
myPatientDao.create(patient);
myPatientDao.create(patient, new ServletRequestDetails());
}
Map<String, IQueryParameterType> params = new HashMap<String, IQueryParameterType>();
@ -1269,12 +1269,12 @@ public class FhirResourceDaoDstu3SearchNoFtTest extends BaseJpaDstu3Test {
patient.addIdentifier().setSystem("urn:system").setValue("testSearchTokenParam001");
patient.addName().addFamily("Tester").addGiven("testSearchTokenParam1");
patient.addCommunication().getLanguage().setText("testSearchTokenParamComText").addCoding().setCode("testSearchTokenParamCode").setSystem("testSearchTokenParamSystem").setDisplay("testSearchTokenParamDisplay");
myPatientDao.create(patient);
myPatientDao.create(patient, new ServletRequestDetails());
patient = new Patient();
patient.addIdentifier().setSystem("urn:system").setValue("testSearchTokenParam002");
patient.addName().addFamily("Tester").addGiven("testSearchTokenParam2");
myPatientDao.create(patient);
myPatientDao.create(patient, new ServletRequestDetails());
{
SearchParameterMap map = new SearchParameterMap();
@ -1377,7 +1377,7 @@ public class FhirResourceDaoDstu3SearchNoFtTest extends BaseJpaDstu3Test {
Quantity q = new Quantity().setSystem("urn:bar:" + methodName).setCode(methodName + "units").setValue(100);
o.setValue(q);
myObservationDao.create(o);
myObservationDao.create(o, new ServletRequestDetails());
param = new QuantityParam(ParamPrefixEnum.GREATERTHAN_OR_EQUALS, new BigDecimal("10"), null, null);
found = myObservationDao.searchForIds("value-quantity", param);
@ -1416,25 +1416,25 @@ public class FhirResourceDaoDstu3SearchNoFtTest extends BaseJpaDstu3Test {
{
Organization org = new Organization();
org.getNameElement().setValue(methodName + "_O1Parent");
parentOrgId = myOrganizationDao.create(org).getId();
parentOrgId = myOrganizationDao.create(org, new ServletRequestDetails()).getId();
}
{
Organization org = new Organization();
org.getNameElement().setValue(methodName + "_O1");
org.setPartOf(new Reference(parentOrgId));
IIdType orgId = myOrganizationDao.create(org).getId();
IIdType orgId = myOrganizationDao.create(org, new ServletRequestDetails()).getId();
Patient patient = new Patient();
patient.addIdentifier().setSystem("urn:system").setValue("001");
patient.addName().addFamily("Tester_" + methodName + "_P1").addGiven("Joe");
patient.getManagingOrganization().setReferenceElement(orgId);
myPatientDao.create(patient);
myPatientDao.create(patient, new ServletRequestDetails());
}
{
Patient patient = new Patient();
patient.addIdentifier().setSystem("urn:system").setValue("002");
patient.addName().addFamily("Tester_" + methodName + "_P2").addGiven("John");
myPatientDao.create(patient);
myPatientDao.create(patient, new ServletRequestDetails());
}
{
@ -1523,21 +1523,21 @@ public class FhirResourceDaoDstu3SearchNoFtTest extends BaseJpaDstu3Test {
{
Organization org = new Organization();
org.getNameElement().setValue(methodName + "_O1Parent");
parentParentOrgId = myOrganizationDao.create(org).getId().toUnqualifiedVersionless();
parentParentOrgId = myOrganizationDao.create(org, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
}
IIdType parentOrgId;
{
Organization org = new Organization();
org.getNameElement().setValue(methodName + "_O1Parent");
org.setPartOf(new Reference(parentParentOrgId));
parentOrgId = myOrganizationDao.create(org).getId().toUnqualifiedVersionless();
parentOrgId = myOrganizationDao.create(org, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
}
IIdType orgId;
{
Organization org = new Organization();
org.getNameElement().setValue(methodName + "_O1");
org.setPartOf(new Reference(parentOrgId));
orgId = myOrganizationDao.create(org).getId().toUnqualifiedVersionless();
orgId = myOrganizationDao.create(org, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
}
IIdType patientId;
{
@ -1545,7 +1545,7 @@ public class FhirResourceDaoDstu3SearchNoFtTest extends BaseJpaDstu3Test {
patient.addIdentifier().setSystem("urn:system").setValue("001");
patient.addName().addFamily("Tester_" + methodName + "_P1").addGiven("Joe");
patient.getManagingOrganization().setReferenceElement(orgId);
patientId = myPatientDao.create(patient).getId().toUnqualifiedVersionless();
patientId = myPatientDao.create(patient, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
}
{
@ -1565,21 +1565,21 @@ public class FhirResourceDaoDstu3SearchNoFtTest extends BaseJpaDstu3Test {
{
Organization org = new Organization();
org.getNameElement().setValue(methodName + "_O1Parent");
parentParentOrgId = myOrganizationDao.create(org).getId().toUnqualifiedVersionless();
parentParentOrgId = myOrganizationDao.create(org, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
}
IIdType parentOrgId;
{
Organization org = new Organization();
org.getNameElement().setValue(methodName + "_O1Parent");
org.setPartOf(new Reference(parentParentOrgId));
parentOrgId = myOrganizationDao.create(org).getId().toUnqualifiedVersionless();
parentOrgId = myOrganizationDao.create(org, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
}
IIdType orgId;
{
Organization org = new Organization();
org.getNameElement().setValue(methodName + "_O1");
org.setPartOf(new Reference(parentOrgId));
orgId = myOrganizationDao.create(org).getId().toUnqualifiedVersionless();
orgId = myOrganizationDao.create(org, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
}
IIdType patientId;
{
@ -1587,7 +1587,7 @@ public class FhirResourceDaoDstu3SearchNoFtTest extends BaseJpaDstu3Test {
patient.addIdentifier().setSystem("urn:system").setValue("001");
patient.addName().addFamily("Tester_" + methodName + "_P1").addGiven("Joe");
patient.getManagingOrganization().setReferenceElement(orgId);
patientId = myPatientDao.create(patient).getId().toUnqualifiedVersionless();
patientId = myPatientDao.create(patient, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
}
{
@ -1607,21 +1607,21 @@ public class FhirResourceDaoDstu3SearchNoFtTest extends BaseJpaDstu3Test {
{
Organization org = new Organization();
org.getNameElement().setValue(methodName + "_O1Parent");
parentParentOrgId = myOrganizationDao.create(org).getId().toUnqualifiedVersionless();
parentParentOrgId = myOrganizationDao.create(org, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
}
IIdType parentOrgId;
{
Organization org = new Organization();
org.getNameElement().setValue(methodName + "_O1Parent");
org.setPartOf(new Reference(parentParentOrgId));
parentOrgId = myOrganizationDao.create(org).getId().toUnqualifiedVersionless();
parentOrgId = myOrganizationDao.create(org, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
}
IIdType orgId;
{
Organization org = new Organization();
org.getNameElement().setValue(methodName + "_O1");
org.setPartOf(new Reference(parentOrgId));
orgId = myOrganizationDao.create(org).getId().toUnqualifiedVersionless();
orgId = myOrganizationDao.create(org, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
}
IIdType patientId;
{
@ -1629,7 +1629,7 @@ public class FhirResourceDaoDstu3SearchNoFtTest extends BaseJpaDstu3Test {
patient.addIdentifier().setSystem("urn:system").setValue("001");
patient.addName().addFamily("Tester_" + methodName + "_P1").addGiven("Joe");
patient.getManagingOrganization().setReferenceElement(orgId);
patientId = myPatientDao.create(patient).getId().toUnqualifiedVersionless();
patientId = myPatientDao.create(patient, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
}
{
@ -1648,21 +1648,21 @@ public class FhirResourceDaoDstu3SearchNoFtTest extends BaseJpaDstu3Test {
{
Organization org = new Organization();
org.getNameElement().setValue(methodName + "_O1Parent");
parentParentOrgId = myOrganizationDao.create(org).getId().toUnqualifiedVersionless();
parentParentOrgId = myOrganizationDao.create(org, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
}
IIdType parentOrgId;
{
Organization org = new Organization();
org.getNameElement().setValue(methodName + "_O1Parent");
org.setPartOf(new Reference(parentParentOrgId));
parentOrgId = myOrganizationDao.create(org).getId().toUnqualifiedVersionless();
parentOrgId = myOrganizationDao.create(org, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
}
IIdType orgId;
{
Organization org = new Organization();
org.getNameElement().setValue(methodName + "_O1");
org.setPartOf(new Reference(parentOrgId));
orgId = myOrganizationDao.create(org).getId().toUnqualifiedVersionless();
orgId = myOrganizationDao.create(org, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
}
IIdType patientId;
{
@ -1670,7 +1670,7 @@ public class FhirResourceDaoDstu3SearchNoFtTest extends BaseJpaDstu3Test {
patient.addIdentifier().setSystem("urn:system").setValue("001");
patient.addName().addFamily("Tester_" + methodName + "_P1").addGiven("Joe");
patient.getManagingOrganization().setReferenceElement(orgId);
patientId = myPatientDao.create(patient).getId().toUnqualifiedVersionless();
patientId = myPatientDao.create(patient, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
}
{
@ -1691,20 +1691,20 @@ public class FhirResourceDaoDstu3SearchNoFtTest extends BaseJpaDstu3Test {
Organization org = new Organization();
org.setId("testSearchWithIncludesThatHaveTextIdid1");
org.getNameElement().setValue("testSearchWithIncludesThatHaveTextId_O1");
IIdType orgId = myOrganizationDao.update(org).getId();
IIdType orgId = myOrganizationDao.update(org, new ServletRequestDetails()).getId();
assertThat(orgId.getValue(), endsWith("Organization/testSearchWithIncludesThatHaveTextIdid1/_history/1"));
Patient patient = new Patient();
patient.addIdentifier().setSystem("urn:system").setValue("001");
patient.addName().addFamily("Tester_testSearchWithIncludesThatHaveTextId_P1").addGiven("Joe");
patient.getManagingOrganization().setReferenceElement(orgId);
myPatientDao.create(patient);
myPatientDao.create(patient, new ServletRequestDetails());
}
{
Patient patient = new Patient();
patient.addIdentifier().setSystem("urn:system").setValue("002");
patient.addName().addFamily("Tester_testSearchWithIncludesThatHaveTextId_P2").addGiven("John");
myPatientDao.create(patient);
myPatientDao.create(patient, new ServletRequestDetails());
}
SearchParameterMap params = new SearchParameterMap();
@ -1725,13 +1725,13 @@ public class FhirResourceDaoDstu3SearchNoFtTest extends BaseJpaDstu3Test {
@Test
public void testSearchWithMissingDate() {
IIdType orgId = myOrganizationDao.create(new Organization()).getId();
IIdType orgId = myOrganizationDao.create(new Organization(), new ServletRequestDetails()).getId();
IIdType notMissing;
IIdType missing;
{
Patient patient = new Patient();
patient.addIdentifier().setSystem("urn:system").setValue("001");
missing = myPatientDao.create(patient).getId().toUnqualifiedVersionless();
missing = myPatientDao.create(patient, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
}
{
Patient patient = new Patient();
@ -1739,7 +1739,7 @@ public class FhirResourceDaoDstu3SearchNoFtTest extends BaseJpaDstu3Test {
patient.addName().addFamily("Tester_testSearchStringParam").addGiven("John");
patient.setBirthDateElement(new DateType("2011-01-01"));
patient.getManagingOrganization().setReferenceElement(orgId);
notMissing = myPatientDao.create(patient).getId().toUnqualifiedVersionless();
notMissing = myPatientDao.create(patient, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
}
// Date Param
{
@ -1769,13 +1769,13 @@ public class FhirResourceDaoDstu3SearchNoFtTest extends BaseJpaDstu3Test {
{
Observation obs = new Observation();
obs.addIdentifier().setSystem("urn:system").setValue("001");
missing = myObservationDao.create(obs).getId().toUnqualifiedVersionless();
missing = myObservationDao.create(obs, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
}
{
Observation obs = new Observation();
obs.addIdentifier().setSystem("urn:system").setValue("002");
obs.setValue(new Quantity(123));
notMissing = myObservationDao.create(obs).getId().toUnqualifiedVersionless();
notMissing = myObservationDao.create(obs, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
}
// Quantity Param
{
@ -1800,13 +1800,13 @@ public class FhirResourceDaoDstu3SearchNoFtTest extends BaseJpaDstu3Test {
@Test
public void testSearchWithMissingReference() {
IIdType orgId = myOrganizationDao.create(new Organization()).getId().toUnqualifiedVersionless();
IIdType orgId = myOrganizationDao.create(new Organization(), new ServletRequestDetails()).getId().toUnqualifiedVersionless();
IIdType notMissing;
IIdType missing;
{
Patient patient = new Patient();
patient.addIdentifier().setSystem("urn:system").setValue("001");
missing = myPatientDao.create(patient).getId().toUnqualifiedVersionless();
missing = myPatientDao.create(patient, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
}
{
Patient patient = new Patient();
@ -1814,7 +1814,7 @@ public class FhirResourceDaoDstu3SearchNoFtTest extends BaseJpaDstu3Test {
patient.addName().addFamily("Tester_testSearchStringParam").addGiven("John");
patient.setBirthDateElement(new DateType("2011-01-01"));
patient.getManagingOrganization().setReferenceElement(orgId);
notMissing = myPatientDao.create(patient).getId().toUnqualifiedVersionless();
notMissing = myPatientDao.create(patient, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
}
// Reference Param
{
@ -1840,13 +1840,13 @@ public class FhirResourceDaoDstu3SearchNoFtTest extends BaseJpaDstu3Test {
@Test
public void testSearchWithMissingString() {
IIdType orgId = myOrganizationDao.create(new Organization()).getId();
IIdType orgId = myOrganizationDao.create(new Organization(), new ServletRequestDetails()).getId();
IIdType notMissing;
IIdType missing;
{
Patient patient = new Patient();
patient.addIdentifier().setSystem("urn:system").setValue("001");
missing = myPatientDao.create(patient).getId().toUnqualifiedVersionless();
missing = myPatientDao.create(patient, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
}
{
Patient patient = new Patient();
@ -1854,7 +1854,7 @@ public class FhirResourceDaoDstu3SearchNoFtTest extends BaseJpaDstu3Test {
patient.addName().addFamily("Tester_testSearchStringParam").addGiven("John");
patient.setBirthDateElement(new DateType("2011-01-01"));
patient.getManagingOrganization().setReferenceElement(orgId);
notMissing = myPatientDao.create(patient).getId().toUnqualifiedVersionless();
notMissing = myPatientDao.create(patient, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
}
// String Param
{
@ -1881,13 +1881,13 @@ public class FhirResourceDaoDstu3SearchNoFtTest extends BaseJpaDstu3Test {
public void testSearchWithNoResults() {
Device dev = new Device();
dev.addIdentifier().setSystem("Foo");
myDeviceDao.create(dev);
myDeviceDao.create(dev, new ServletRequestDetails());
IBundleProvider value = myDeviceDao.search(new SearchParameterMap());
ourLog.info("Initial size: " + value.size());
for (IBaseResource next : value.getResources(0, value.size())) {
ourLog.info("Deleting: {}", next.getIdElement());
myDeviceDao.delete(next.getIdElement());
myDeviceDao.delete((IIdType) next.getIdElement(), new ServletRequestDetails());
}
value = myDeviceDao.search(new SearchParameterMap());
@ -1911,14 +1911,14 @@ public class FhirResourceDaoDstu3SearchNoFtTest extends BaseJpaDstu3Test {
Organization org = new Organization();
org.getNameElement().setValue("FOO");
org.getMeta().addSecurity("urn:taglist", methodName + "1a", null);
tag1id = myOrganizationDao.create(org).getId().toUnqualifiedVersionless();
tag1id = myOrganizationDao.create(org, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
}
IIdType tag2id;
{
Organization org = new Organization();
org.getNameElement().setValue("FOO");
org.getMeta().addProfile("http://" + methodName);
tag2id = myOrganizationDao.create(org).getId().toUnqualifiedVersionless();
tag2id = myOrganizationDao.create(org, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
}
{
SearchParameterMap params = new SearchParameterMap();
@ -1944,7 +1944,7 @@ public class FhirResourceDaoDstu3SearchNoFtTest extends BaseJpaDstu3Test {
org.getNameElement().setValue("FOO");
org.getMeta().addTag("urn:taglist", methodName + "1a", null);
org.getMeta().addTag("urn:taglist", methodName + "1b", null);
tag1id = myOrganizationDao.create(org).getId().toUnqualifiedVersionless();
tag1id = myOrganizationDao.create(org, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
}
Date betweenDate = new Date();
@ -1955,7 +1955,7 @@ public class FhirResourceDaoDstu3SearchNoFtTest extends BaseJpaDstu3Test {
org.getNameElement().setValue("FOO");
org.getMeta().addTag("urn:taglist", methodName + "2a",null);
org.getMeta().addTag("urn:taglist", methodName + "2b",null);
tag2id = myOrganizationDao.create(org).getId().toUnqualifiedVersionless();
tag2id = myOrganizationDao.create(org, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
}
{
@ -2025,13 +2025,13 @@ public class FhirResourceDaoDstu3SearchNoFtTest extends BaseJpaDstu3Test {
{
Observation obs = new Observation();
obs.addIdentifier().setSystem("urn:system").setValue("001");
missing = myObservationDao.create(obs).getId().toUnqualifiedVersionless();
missing = myObservationDao.create(obs, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
}
{
Observation obs = new Observation();
obs.addIdentifier().setSystem("urn:system").setValue("002");
obs.getCode().addCoding().setSystem("urn:system").setCode("002");
notMissing = myObservationDao.create(obs).getId().toUnqualifiedVersionless();
notMissing = myObservationDao.create(obs, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
}
// Token Param
{
@ -2058,15 +2058,15 @@ public class FhirResourceDaoDstu3SearchNoFtTest extends BaseJpaDstu3Test {
public void testSearchWithUriParamAbove() throws Exception {
ValueSet vs1 = new ValueSet();
vs1.setUrl("http://hl7.org/foo/baz");
myValueSetDao.create(vs1).getId().toUnqualifiedVersionless();
myValueSetDao.create(vs1, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
ValueSet vs2 = new ValueSet();
vs2.setUrl("http://hl7.org/foo/bar");
IIdType id2 = myValueSetDao.create(vs2).getId().toUnqualifiedVersionless();
IIdType id2 = myValueSetDao.create(vs2, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
ValueSet vs3 = new ValueSet();
vs3.setUrl("http://hl7.org/foo/bar/baz");
IIdType id3 = myValueSetDao.create(vs3).getId().toUnqualifiedVersionless();
IIdType id3 = myValueSetDao.create(vs3, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
IBundleProvider result;
result = myValueSetDao.search(ValueSet.SP_URL, new UriParam("http://hl7.org/foo/bar/baz/boz").setQualifier(UriParamQualifierEnum.ABOVE));
@ -2090,11 +2090,11 @@ public class FhirResourceDaoDstu3SearchNoFtTest extends BaseJpaDstu3Test {
Class<ValueSet> type = ValueSet.class;
String resourceName = "/valueset-dstu2.json";
ValueSet vs = loadResourceFromClasspath(type, resourceName);
IIdType id1 = myValueSetDao.update(vs).getId().toUnqualifiedVersionless();
IIdType id1 = myValueSetDao.update(vs, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
ValueSet vs2 = new ValueSet();
vs2.setUrl("http://hl7.org/foo/bar");
myValueSetDao.create(vs2).getId().toUnqualifiedVersionless();
IIdType id2 = myValueSetDao.create(vs2, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
IBundleProvider result;
result = myValueSetDao.search(ValueSet.SP_URL, new UriParam("http://hl7.org/fhir/ValueSet/basic-resource-type"));
@ -2112,11 +2112,11 @@ public class FhirResourceDaoDstu3SearchNoFtTest extends BaseJpaDstu3Test {
Class<ValueSet> type = ValueSet.class;
String resourceName = "/valueset-dstu2.json";
ValueSet vs = loadResourceFromClasspath(type, resourceName);
IIdType id1 = myValueSetDao.update(vs).getId().toUnqualifiedVersionless();
IIdType id1 = myValueSetDao.update(vs, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
ValueSet vs2 = new ValueSet();
vs2.setUrl("http://hl7.org/foo/bar");
IIdType id2 = myValueSetDao.create(vs2).getId().toUnqualifiedVersionless();
IIdType id2 = myValueSetDao.create(vs2, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
IBundleProvider result;

View File

@ -20,9 +20,9 @@ import java.util.List;
import javax.persistence.TypedQuery;
import org.hl7.fhir.dstu3.model.Observation;
import org.hl7.fhir.dstu3.model.Observation.ObservationStatus;
import org.hl7.fhir.dstu3.model.Patient;
import org.hl7.fhir.dstu3.model.Subscription;
import org.hl7.fhir.dstu3.model.Observation.ObservationStatus;
import org.hl7.fhir.dstu3.model.Subscription.SubscriptionChannelType;
import org.hl7.fhir.dstu3.model.Subscription.SubscriptionStatus;
import org.hl7.fhir.instance.model.api.IBaseResource;
@ -38,6 +38,7 @@ import ca.uhn.fhir.jpa.entity.SubscriptionTable;
import ca.uhn.fhir.rest.server.IBundleProvider;
import ca.uhn.fhir.rest.server.exceptions.ResourceGoneException;
import ca.uhn.fhir.rest.server.exceptions.UnprocessableEntityException;
import ca.uhn.fhir.rest.server.servlet.ServletRequestDetails;
public class FhirResourceDaoDstu3SubscriptionTest extends BaseJpaDstu3Test {
@ -64,16 +65,16 @@ public class FhirResourceDaoDstu3SubscriptionTest extends BaseJpaDstu3Test {
subs.getChannel().setType(SubscriptionChannelType.WEBSOCKET);
subs.setStatus(SubscriptionStatus.REQUESTED);
IIdType id = mySubscriptionDao.create(subs).getId().toUnqualifiedVersionless();
IIdType id = mySubscriptionDao.create(subs, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
mySubscriptionDao.purgeInactiveSubscriptions();
mySubscriptionDao.read(id);
mySubscriptionDao.read(id, new ServletRequestDetails());
Thread.sleep(1500);
myDaoConfig.setSchedulingDisabled(false);
mySubscriptionDao.purgeInactiveSubscriptions();
try {
mySubscriptionDao.read(id);
mySubscriptionDao.read(id, new ServletRequestDetails());
fail();
} catch (ResourceGoneException e) {
// good
@ -95,9 +96,9 @@ public class FhirResourceDaoDstu3SubscriptionTest extends BaseJpaDstu3Test {
subs.getChannel().setType(SubscriptionChannelType.WEBSOCKET);
subs.setStatus(SubscriptionStatus.REQUESTED);
IIdType id = mySubscriptionDao.create(subs).getId().toUnqualifiedVersionless();
IIdType id = mySubscriptionDao.create(subs, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
mySubscriptionDao.purgeInactiveSubscriptions();
mySubscriptionDao.read(id);
mySubscriptionDao.read(id, new ServletRequestDetails());
mySubscriptionDao.getUndeliveredResourcesAndPurge(mySubscriptionDao.getSubscriptionTablePidForSubscriptionResource(id));
@ -106,7 +107,7 @@ public class FhirResourceDaoDstu3SubscriptionTest extends BaseJpaDstu3Test {
myDaoConfig.setSchedulingDisabled(false);
mySubscriptionDao.purgeInactiveSubscriptions();
try {
mySubscriptionDao.read(id);
mySubscriptionDao.read(id, new ServletRequestDetails());
fail();
} catch (ResourceGoneException e) {
// good
@ -120,7 +121,7 @@ public class FhirResourceDaoDstu3SubscriptionTest extends BaseJpaDstu3Test {
subs.getChannel().setType(SubscriptionChannelType.WEBSOCKET);
subs.setStatus(SubscriptionStatus.REQUESTED);
IIdType id = mySubscriptionDao.create(subs).getId().toUnqualifiedVersionless();
IIdType id = mySubscriptionDao.create(subs, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
TypedQuery<SubscriptionTable> q = myEntityManager.createQuery("SELECT t from SubscriptionTable t WHERE t.mySubscriptionResource.myId = :id", SubscriptionTable.class);
q.setParameter("id", id.getIdPartAsLong());
@ -130,15 +131,15 @@ public class FhirResourceDaoDstu3SubscriptionTest extends BaseJpaDstu3Test {
assertNotNull(table.getNextCheck());
assertEquals(table.getNextCheck(), table.getSubscriptionResource().getPublished().getValue());
assertEquals(SubscriptionStatus.REQUESTED.toCode(), myEntityManager.find(SubscriptionTable.class, table.getId()).getStatus());
assertEquals(SubscriptionStatus.REQUESTED, mySubscriptionDao.read(id).getStatusElement().getValue());
assertEquals(SubscriptionStatus.REQUESTED, mySubscriptionDao.read(id, new ServletRequestDetails()).getStatusElement().getValue());
subs.setStatus(SubscriptionStatus.ACTIVE);
mySubscriptionDao.update(subs);
mySubscriptionDao.update(subs, new ServletRequestDetails());
assertEquals(SubscriptionStatus.ACTIVE.toCode(), myEntityManager.find(SubscriptionTable.class, table.getId()).getStatus());
assertEquals(SubscriptionStatus.ACTIVE, mySubscriptionDao.read(id).getStatusElement().getValue());
assertEquals(SubscriptionStatus.ACTIVE, mySubscriptionDao.read(id, new ServletRequestDetails()).getStatusElement().getValue());
mySubscriptionDao.delete(id);
mySubscriptionDao.delete(id, new ServletRequestDetails());
assertNull(myEntityManager.find(SubscriptionTable.class, table.getId()));
@ -151,10 +152,10 @@ public class FhirResourceDaoDstu3SubscriptionTest extends BaseJpaDstu3Test {
subs.getChannel().setType(SubscriptionChannelType.WEBSOCKET);
subs.setId(id);
subs.setStatus(SubscriptionStatus.REQUESTED);
mySubscriptionDao.update(subs);
mySubscriptionDao.update(subs, new ServletRequestDetails());
assertEquals(SubscriptionStatus.REQUESTED.toCode(), myEntityManager.createQuery("SELECT t FROM SubscriptionTable t WHERE t.myResId = " + id.getIdPart(), SubscriptionTable.class).getSingleResult().getStatus());
assertEquals(SubscriptionStatus.REQUESTED, mySubscriptionDao.read(id).getStatusElement().getValue());
assertEquals(SubscriptionStatus.REQUESTED, mySubscriptionDao.read(id, new ServletRequestDetails()).getStatusElement().getValue());
}
@Test
@ -163,7 +164,7 @@ public class FhirResourceDaoDstu3SubscriptionTest extends BaseJpaDstu3Test {
subs.setStatus(SubscriptionStatus.REQUESTED);
subs.setCriteria("Observation");
try {
mySubscriptionDao.create(subs);
mySubscriptionDao.create(subs, new ServletRequestDetails());
fail();
} catch (UnprocessableEntityException e) {
assertThat(e.getMessage(), containsString("Subscription.criteria must be in the form \"{Resource Type}?[params]\""));
@ -173,7 +174,7 @@ public class FhirResourceDaoDstu3SubscriptionTest extends BaseJpaDstu3Test {
subs.setStatus(SubscriptionStatus.REQUESTED);
subs.setCriteria("http://foo.com/Observation?AAA=BBB");
try {
mySubscriptionDao.create(subs);
mySubscriptionDao.create(subs, new ServletRequestDetails());
fail();
} catch (UnprocessableEntityException e) {
assertThat(e.getMessage(), containsString("Subscription.criteria must be in the form \"{Resource Type}?[params]\""));
@ -183,7 +184,7 @@ public class FhirResourceDaoDstu3SubscriptionTest extends BaseJpaDstu3Test {
subs.setStatus(SubscriptionStatus.REQUESTED);
subs.setCriteria("ObservationZZZZ?a=b");
try {
mySubscriptionDao.create(subs);
mySubscriptionDao.create(subs, new ServletRequestDetails());
fail();
} catch (UnprocessableEntityException e) {
assertThat(e.getMessage(), containsString("Subscription.criteria contains invalid/unsupported resource type: ObservationZZZZ"));
@ -193,7 +194,7 @@ public class FhirResourceDaoDstu3SubscriptionTest extends BaseJpaDstu3Test {
subs.setStatus(SubscriptionStatus.REQUESTED);
subs.setCriteria("Observation?identifier=123");
try {
mySubscriptionDao.create(subs);
mySubscriptionDao.create(subs, new ServletRequestDetails());
fail();
} catch (UnprocessableEntityException e) {
assertThat(e.getMessage(), containsString("Subscription.channel.type must be populated on this server"));
@ -203,7 +204,7 @@ public class FhirResourceDaoDstu3SubscriptionTest extends BaseJpaDstu3Test {
subs.setStatus(SubscriptionStatus.REQUESTED);
subs.setCriteria("Observation?identifier=123");
subs.getChannel().setType(SubscriptionChannelType.WEBSOCKET);
assertTrue(mySubscriptionDao.create(subs).getId().hasIdPart());
assertTrue(mySubscriptionDao.create(subs, new ServletRequestDetails()).getId().hasIdPart());
}
@ -214,7 +215,7 @@ public class FhirResourceDaoDstu3SubscriptionTest extends BaseJpaDstu3Test {
String methodName = "testDeleteSubscriptionWithFlaggedResources";
Patient p = new Patient();
p.addName().addFamily(methodName);
IIdType pId = myPatientDao.create(p).getId().toUnqualifiedVersionless();
IIdType pId = myPatientDao.create(p, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
Subscription subs;
@ -226,7 +227,7 @@ public class FhirResourceDaoDstu3SubscriptionTest extends BaseJpaDstu3Test {
subs.getChannel().setType(SubscriptionChannelType.WEBSOCKET);
subs.setCriteria("Observation?subject=Patient/" + pId.getIdPart());
subs.setStatus(SubscriptionStatus.ACTIVE);
IIdType subsId = mySubscriptionDao.create(subs).getId().toUnqualifiedVersionless();
IIdType subsId = mySubscriptionDao.create(subs, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
Long subsPid = mySubscriptionDao.getSubscriptionTablePidForSubscriptionResource(subsId);
assertNull(mySubscriptionTableDao.findOne(subsPid).getLastClientPoll());
@ -239,12 +240,12 @@ public class FhirResourceDaoDstu3SubscriptionTest extends BaseJpaDstu3Test {
Observation obs = new Observation();
obs.getSubject().setReferenceElement(pId);
obs.setStatus(ObservationStatus.FINAL);
myObservationDao.create(obs).getId().toUnqualifiedVersionless();
myObservationDao.create(obs, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
obs = new Observation();
obs.getSubject().setReferenceElement(pId);
obs.setStatus(ObservationStatus.FINAL);
myObservationDao.create(obs).getId().toUnqualifiedVersionless();
myObservationDao.create(obs, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
Thread.sleep(100);
@ -258,7 +259,7 @@ public class FhirResourceDaoDstu3SubscriptionTest extends BaseJpaDstu3Test {
* Delete the subscription
*/
mySubscriptionDao.delete(subsId);
mySubscriptionDao.delete(subsId, new ServletRequestDetails());
assertThat(mySubscriptionFlaggedResourceDataDao.count(), not(greaterThan(0L)));
assertThat(mySubscriptionTableDao.count(), not(greaterThan(0L)));
@ -266,14 +267,14 @@ public class FhirResourceDaoDstu3SubscriptionTest extends BaseJpaDstu3Test {
/*
* Delete a second time just to make sure that works
*/
mySubscriptionDao.delete(subsId);
mySubscriptionDao.delete(subsId, new ServletRequestDetails());
/*
* Re-create the subscription
*/
subs.setId(subsId);
mySubscriptionDao.update(subs).getId();
mySubscriptionDao.update(subs, new ServletRequestDetails()).getId();
assertThat(mySubscriptionFlaggedResourceDataDao.count(), not(greaterThan(0L)));
assertThat(mySubscriptionTableDao.count(), (greaterThan(0L)));
@ -285,7 +286,7 @@ public class FhirResourceDaoDstu3SubscriptionTest extends BaseJpaDstu3Test {
obs = new Observation();
obs.getSubject().setReferenceElement(pId);
obs.setStatus(ObservationStatus.FINAL);
myObservationDao.create(obs).getId().toUnqualifiedVersionless();
myObservationDao.create(obs, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
Thread.sleep(100);
@ -302,12 +303,12 @@ public class FhirResourceDaoDstu3SubscriptionTest extends BaseJpaDstu3Test {
String methodName = "testSubscriptionResourcesAppear";
Patient p = new Patient();
p.addName().addFamily(methodName);
IIdType pId = myPatientDao.create(p).getId().toUnqualifiedVersionless();
IIdType pId = myPatientDao.create(p, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
Observation obs = new Observation();
obs.getSubject().setReferenceElement(pId);
obs.setStatus(ObservationStatus.FINAL);
myObservationDao.create(obs).getId().toUnqualifiedVersionless();
myObservationDao.create(obs, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
Subscription subs;
@ -319,13 +320,13 @@ public class FhirResourceDaoDstu3SubscriptionTest extends BaseJpaDstu3Test {
subs.getChannel().setType(SubscriptionChannelType.WEBSOCKET);
subs.setCriteria("Observation?subject=Patient/" + pId.getIdPart());
subs.setStatus(SubscriptionStatus.ACTIVE);
Long subsId1 = mySubscriptionDao.getSubscriptionTablePidForSubscriptionResource(mySubscriptionDao.create(subs).getId());
Long subsId1 = mySubscriptionDao.getSubscriptionTablePidForSubscriptionResource(mySubscriptionDao.create(subs, new ServletRequestDetails()).getId());
subs = new Subscription();
subs.getChannel().setType(SubscriptionChannelType.WEBSOCKET);
subs.setCriteria("Observation?subject=Patient/" + pId.getIdPart());
subs.setStatus(SubscriptionStatus.ACTIVE);
Long subsId2 = mySubscriptionDao.getSubscriptionTablePidForSubscriptionResource(mySubscriptionDao.create(subs).getId());
Long subsId2 = mySubscriptionDao.getSubscriptionTablePidForSubscriptionResource(mySubscriptionDao.create(subs, new ServletRequestDetails()).getId());
assertNull(mySubscriptionTableDao.findOne(subsId1).getLastClientPoll());
@ -335,12 +336,12 @@ public class FhirResourceDaoDstu3SubscriptionTest extends BaseJpaDstu3Test {
obs = new Observation();
obs.getSubject().setReferenceElement(pId);
obs.setStatus(ObservationStatus.FINAL);
IIdType afterId1 = myObservationDao.create(obs).getId().toUnqualifiedVersionless();
IIdType afterId1 = myObservationDao.create(obs, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
obs = new Observation();
obs.getSubject().setReferenceElement(pId);
obs.setStatus(ObservationStatus.FINAL);
IIdType afterId2 = myObservationDao.create(obs).getId().toUnqualifiedVersionless();
IIdType afterId2 = myObservationDao.create(obs, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
Thread.sleep(100);
@ -381,7 +382,7 @@ public class FhirResourceDaoDstu3SubscriptionTest extends BaseJpaDstu3Test {
*/
mySystemDao.markAllResourcesForReindexing();
mySystemDao.performReindexingPass(100);
mySystemDao.performReindexingPass(100, new ServletRequestDetails());
assertEquals(0, mySubscriptionDao.pollForNewUndeliveredResources());
@ -394,7 +395,7 @@ public class FhirResourceDaoDstu3SubscriptionTest extends BaseJpaDstu3Test {
ourLog.info("Updating observation");
Observation nextObs = (Observation) next;
nextObs.addPerformer().setDisplay("Some display");
myObservationDao.update(nextObs);
myObservationDao.update(nextObs, new ServletRequestDetails());
}
assertEquals(6, mySubscriptionDao.pollForNewUndeliveredResources());
@ -410,12 +411,12 @@ public class FhirResourceDaoDstu3SubscriptionTest extends BaseJpaDstu3Test {
String methodName = "testSubscriptionResourcesAppear2";
Patient p = new Patient();
p.addName().addFamily(methodName);
IIdType pId = myPatientDao.create(p).getId().toUnqualifiedVersionless();
IIdType pId = myPatientDao.create(p, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
Observation obs = new Observation();
obs.getSubject().setReferenceElement(pId);
obs.setStatus(ObservationStatus.FINAL);
IIdType oId = myObservationDao.create(obs).getId().toUnqualifiedVersionless();
IIdType oId = myObservationDao.create(obs, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
Subscription subs;
@ -427,7 +428,7 @@ public class FhirResourceDaoDstu3SubscriptionTest extends BaseJpaDstu3Test {
subs.getChannel().setType(SubscriptionChannelType.WEBSOCKET);
subs.setCriteria("Observation?subject=Patient/" + pId.getIdPart());
subs.setStatus(SubscriptionStatus.ACTIVE);
Long subsId1 = mySubscriptionDao.getSubscriptionTablePidForSubscriptionResource(mySubscriptionDao.create(subs).getId());
Long subsId1 = mySubscriptionDao.getSubscriptionTablePidForSubscriptionResource(mySubscriptionDao.create(subs, new ServletRequestDetails()).getId());
assertNull(mySubscriptionTableDao.findOne(subsId1).getLastClientPoll());
@ -435,7 +436,7 @@ public class FhirResourceDaoDstu3SubscriptionTest extends BaseJpaDstu3Test {
ourLog.info("pId: {} - oId: {}", pId, oId);
myObservationDao.update(myObservationDao.read(oId));
myObservationDao.update(myObservationDao.read(oId, new ServletRequestDetails()), new ServletRequestDetails());
assertEquals(1, mySubscriptionDao.pollForNewUndeliveredResources());
ourLog.info("Between passes");
@ -447,12 +448,12 @@ public class FhirResourceDaoDstu3SubscriptionTest extends BaseJpaDstu3Test {
obs = new Observation();
obs.getSubject().setReferenceElement(pId);
obs.setStatus(ObservationStatus.FINAL);
myObservationDao.create(obs).getId().toUnqualifiedVersionless();
myObservationDao.create(obs, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
obs = new Observation();
obs.getSubject().setReferenceElement(pId);
obs.setStatus(ObservationStatus.FINAL);
myObservationDao.create(obs).getId().toUnqualifiedVersionless();
myObservationDao.create(obs, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
Thread.sleep(100);
@ -476,7 +477,7 @@ public class FhirResourceDaoDstu3SubscriptionTest extends BaseJpaDstu3Test {
obs = new Observation();
obs.getSubject().setReferenceElement(pId);
obs.setStatus(ObservationStatus.FINAL);
myObservationDao.create(obs).getId().toUnqualifiedVersionless();
myObservationDao.create(obs, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
mySubscriptionDao.pollForNewUndeliveredResources();
assertEquals(4, mySubscriptionFlaggedResourceDataDao.count());

View File

@ -41,6 +41,7 @@ import ca.uhn.fhir.rest.server.IBundleProvider;
import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException;
import ca.uhn.fhir.rest.server.exceptions.UnprocessableEntityException;
import ca.uhn.fhir.rest.server.interceptor.IServerInterceptor.ActionRequestDetails;
import ca.uhn.fhir.rest.server.servlet.ServletRequestDetails;
public class FhirResourceDaoDstu3UpdateTest extends BaseJpaDstu3Test {
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(FhirResourceDaoDstu3UpdateTest.class);
@ -51,14 +52,14 @@ public class FhirResourceDaoDstu3UpdateTest extends BaseJpaDstu3Test {
patient.addIdentifier().setSystem("urn:system").setValue("001");
patient.addName().addFamily("Tester").addGiven("Joe");
MethodOutcome outcome = myPatientDao.create(patient);
MethodOutcome outcome = myPatientDao.create(patient, new ServletRequestDetails());
assertNotNull(outcome.getId());
assertFalse(outcome.getId().isEmpty());
assertEquals("1", outcome.getId().getVersionIdPart());
Date now = new Date();
Patient retrieved = myPatientDao.read(outcome.getId());
Patient retrieved = myPatientDao.read(outcome.getId(), new ServletRequestDetails());
InstantType updated = retrieved.getMeta().getLastUpdatedElement().copy();
assertTrue(updated.before(now));
@ -66,7 +67,7 @@ public class FhirResourceDaoDstu3UpdateTest extends BaseJpaDstu3Test {
reset(myInterceptor);
retrieved.getIdentifier().get(0).setValue("002");
MethodOutcome outcome2 = myPatientDao.update(retrieved);
MethodOutcome outcome2 = myPatientDao.update(retrieved, new ServletRequestDetails());
assertEquals(outcome.getId().getIdPart(), outcome2.getId().getIdPart());
assertNotEquals(outcome.getId().getVersionIdPart(), outcome2.getId().getVersionIdPart());
assertEquals("2", outcome2.getId().getVersionIdPart());
@ -81,7 +82,7 @@ public class FhirResourceDaoDstu3UpdateTest extends BaseJpaDstu3Test {
Date now2 = new Date();
Patient retrieved2 = myPatientDao.read(outcome.getId().toVersionless());
Patient retrieved2 = myPatientDao.read(outcome.getId().toVersionless(), new ServletRequestDetails());
assertEquals("2", retrieved2.getIdElement().getVersionIdPart());
assertEquals("002", retrieved2.getIdentifier().get(0).getValue());
@ -95,7 +96,7 @@ public class FhirResourceDaoDstu3UpdateTest extends BaseJpaDstu3Test {
* Get history
*/
IBundleProvider historyBundle = myPatientDao.history(outcome.getId(), null);
IBundleProvider historyBundle = myPatientDao.history(outcome.getId(), null, new ServletRequestDetails());
assertEquals(2, historyBundle.size());
@ -121,7 +122,7 @@ public class FhirResourceDaoDstu3UpdateTest extends BaseJpaDstu3Test {
Patient p = new Patient();
p.addIdentifier().setSystem("urn:system").setValue(methodName);
IIdType id = myPatientDao.create(p).getId();
IIdType id = myPatientDao.create(p, new ServletRequestDetails()).getId();
ourLog.info("Created patient, got it: {}", id);
p = new Patient();
@ -129,9 +130,9 @@ public class FhirResourceDaoDstu3UpdateTest extends BaseJpaDstu3Test {
p.addName().addFamily("Hello");
p.setId("Patient/" + methodName);
myPatientDao.update(p, "Patient?identifier=urn%3Asystem%7C" + methodName);
myPatientDao.update(p, "Patient?identifier=urn%3Asystem%7C" + methodName, new ServletRequestDetails());
p = myPatientDao.read(id.toVersionless());
p = myPatientDao.read(id.toVersionless(), new ServletRequestDetails());
assertThat(p.getIdElement().toVersionless().toString(), not(containsString("test")));
assertEquals(id.toVersionless(), p.getIdElement().toVersionless());
assertNotEquals(id, p.getIdElement());
@ -147,10 +148,10 @@ public class FhirResourceDaoDstu3UpdateTest extends BaseJpaDstu3Test {
p.addName().addFamily("Hello");
p.setId("Patient/" + methodName);
IIdType id = myPatientDao.update(p).getId();
IIdType id = myPatientDao.update(p, new ServletRequestDetails()).getId();
assertEquals("Patient/" + methodName, id.toUnqualifiedVersionless().getValue());
p = myPatientDao.read(id);
p = myPatientDao.read(id, new ServletRequestDetails());
assertEquals(methodName, p.getIdentifier().get(0).getValue());
}
@ -161,7 +162,7 @@ public class FhirResourceDaoDstu3UpdateTest extends BaseJpaDstu3Test {
p.setId("0" + methodName);
p.addName().addFamily(methodName);
myPatientDao.update(p);
myPatientDao.update(p, new ServletRequestDetails());
}
/**
@ -180,7 +181,7 @@ public class FhirResourceDaoDstu3UpdateTest extends BaseJpaDstu3Test {
p1.getMeta().addSecurity("sec_scheme1", "sec_term1",null);
p1.getMeta().addProfile("http://foo1");
p1id = myPatientDao.create(p1).getId().toUnqualifiedVersionless();
p1id = myPatientDao.create(p1, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
}
{
Patient p1 = new Patient();
@ -191,10 +192,10 @@ public class FhirResourceDaoDstu3UpdateTest extends BaseJpaDstu3Test {
p1.getMeta().addSecurity("sec_scheme2", "sec_term2", null);
p1.getMeta().addProfile("http://foo2");
myPatientDao.update(p1);
myPatientDao.update(p1, new ServletRequestDetails());
}
{
Patient p1 = myPatientDao.read(p1id);
Patient p1 = myPatientDao.read(p1id, new ServletRequestDetails());
List<Coding> tagList = p1.getMeta().getTag();
Set<String> secListValues = new HashSet<String>();
for (Coding next : tagList) {
@ -218,12 +219,12 @@ public class FhirResourceDaoDstu3UpdateTest extends BaseJpaDstu3Test {
Patient p1 = new Patient();
p1.addIdentifier().setSystem("urn:system").setValue("testUpdateMaintainsSearchParamsDstu2AAA");
p1.addName().addFamily("Tester").addGiven("testUpdateMaintainsSearchParamsDstu2AAA");
IIdType p1id = myPatientDao.create(p1).getId();
IIdType p1id = myPatientDao.create(p1, new ServletRequestDetails()).getId();
Patient p2 = new Patient();
p2.addIdentifier().setSystem("urn:system").setValue("testUpdateMaintainsSearchParamsDstu2BBB");
p2.addName().addFamily("Tester").addGiven("testUpdateMaintainsSearchParamsDstu2BBB");
myPatientDao.create(p2).getId();
myPatientDao.create(p2, new ServletRequestDetails()).getId();
Set<Long> ids = myPatientDao.searchForIds(Patient.SP_GIVEN, new StringParam("testUpdateMaintainsSearchParamsDstu2AAA"));
assertEquals(1, ids.size());
@ -231,7 +232,7 @@ public class FhirResourceDaoDstu3UpdateTest extends BaseJpaDstu3Test {
// Update the name
p1.getName().get(0).getGiven().get(0).setValue("testUpdateMaintainsSearchParamsDstu2BBB");
MethodOutcome update2 = myPatientDao.update(p1);
MethodOutcome update2 = myPatientDao.update(p1, new ServletRequestDetails());
IIdType p1id2 = update2.getId();
ids = myPatientDao.searchForIds(Patient.SP_GIVEN, new StringParam("testUpdateMaintainsSearchParamsDstu2AAA"));
@ -241,10 +242,10 @@ public class FhirResourceDaoDstu3UpdateTest extends BaseJpaDstu3Test {
assertEquals(2, ids.size());
// Make sure vreads work
p1 = myPatientDao.read(p1id);
p1 = myPatientDao.read(p1id, new ServletRequestDetails());
assertEquals("testUpdateMaintainsSearchParamsDstu2AAA", p1.getName().get(0).getGivenAsSingleString());
p1 = myPatientDao.read(p1id2);
p1 = myPatientDao.read(p1id2, new ServletRequestDetails());
assertEquals("testUpdateMaintainsSearchParamsDstu2BBB", p1.getName().get(0).getGivenAsSingleString());
}
@ -254,13 +255,13 @@ public class FhirResourceDaoDstu3UpdateTest extends BaseJpaDstu3Test {
Patient p1 = new Patient();
p1.addIdentifier().setSystem("urn:system").setValue("testUpdateRejectsInvalidTypes");
p1.addName().addFamily("Tester").addGiven("testUpdateRejectsInvalidTypes");
IIdType p1id = myPatientDao.create(p1).getId();
IIdType p1id = myPatientDao.create(p1, new ServletRequestDetails()).getId();
Organization p2 = new Organization();
p2.getNameElement().setValue("testUpdateRejectsInvalidTypes");
try {
p2.setId(new IdType("Organization/" + p1id.getIdPart()));
myOrganizationDao.update(p2);
myOrganizationDao.update(p2, new ServletRequestDetails());
fail();
} catch (UnprocessableEntityException e) {
// good
@ -268,7 +269,7 @@ public class FhirResourceDaoDstu3UpdateTest extends BaseJpaDstu3Test {
try {
p2.setId(new IdType("Patient/" + p1id.getIdPart()));
myOrganizationDao.update(p2);
myOrganizationDao.update(p2, new ServletRequestDetails());
fail();
} catch (UnprocessableEntityException e) {
ourLog.error("Good", e);
@ -290,12 +291,12 @@ public class FhirResourceDaoDstu3UpdateTest extends BaseJpaDstu3Test {
tl.add(new IdType("http://foo/bar"));
patient.getMeta().getProfile().addAll(tl);
id = myPatientDao.create(patient).getId().toUnqualifiedVersionless();
id = myPatientDao.create(patient, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
}
// Do a read
{
Patient patient = myPatientDao.read(id);
Patient patient = myPatientDao.read(id, new ServletRequestDetails());
List<UriType> tl = patient.getMeta().getProfile();
assertEquals(1, tl.size());
assertEquals("http://foo/bar", tl.get(0).getValue());
@ -315,12 +316,12 @@ public class FhirResourceDaoDstu3UpdateTest extends BaseJpaDstu3Test {
tl.add(new IdType("http://foo/bar"));
patient.getMeta().getProfile().addAll(tl);
id = myPatientDao.create(patient).getId().toUnqualifiedVersionless();
id = myPatientDao.create(patient, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
}
// Do a read
{
Patient patient = myPatientDao.read(id);
Patient patient = myPatientDao.read(id, new ServletRequestDetails());
List<UriType> tl = patient.getMeta().getProfile();
assertEquals(1, tl.size());
assertEquals("http://foo/bar", tl.get(0).getValue());
@ -337,12 +338,12 @@ public class FhirResourceDaoDstu3UpdateTest extends BaseJpaDstu3Test {
patient.getMeta().getProfile().clear();
patient.getMeta().getProfile().addAll(tl);
id = myPatientDao.update(patient).getId().toUnqualifiedVersionless();
id = myPatientDao.update(patient, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
}
// Do a read
{
Patient patient = myPatientDao.read(id);
Patient patient = myPatientDao.read(id, new ServletRequestDetails());
List<UriType> tl = patient.getMeta().getProfile();
assertEquals(1, tl.size());
assertEquals("http://foo/baz", tl.get(0).getValue());
@ -357,7 +358,7 @@ public class FhirResourceDaoDstu3UpdateTest extends BaseJpaDstu3Test {
p.addName().addFamily("Hello");
p.setId("Patient/9999999999999999");
try {
myPatientDao.update(p);
myPatientDao.update(p, new ServletRequestDetails());
fail();
} catch (InvalidRequestException e) {
assertThat(e.getMessage(), containsString("Can not create resource with ID[9999999999999999], no resource with this ID exists and clients may only"));
@ -371,7 +372,7 @@ public class FhirResourceDaoDstu3UpdateTest extends BaseJpaDstu3Test {
p.addName().addFamily("Hello");
p.setId("Patient/123:456");
try {
myPatientDao.update(p);
myPatientDao.update(p, new ServletRequestDetails());
fail();
} catch (InvalidRequestException e) {
assertEquals("Can not process entity with ID[123:456], this is not a valid FHIR ID", e.getMessage());
@ -385,7 +386,7 @@ public class FhirResourceDaoDstu3UpdateTest extends BaseJpaDstu3Test {
p.addName().addFamily("Hello");
p.setId("Patient/123");
try {
myPatientDao.update(p);
myPatientDao.update(p, new ServletRequestDetails());
fail();
} catch (InvalidRequestException e) {
assertThat(e.getMessage(), containsString("clients may only assign IDs which contain at least one non-numeric"));
@ -398,11 +399,11 @@ public class FhirResourceDaoDstu3UpdateTest extends BaseJpaDstu3Test {
p.addIdentifier().setSystem("urn:system").setValue("testCreateNumericIdFails");
p.addName().addFamily("Hello");
p.setId("Patient/123abc");
IIdType id = myPatientDao.update(p).getId();
IIdType id = myPatientDao.update(p, new ServletRequestDetails()).getId();
assertEquals("123abc", id.getIdPart());
assertEquals("1", id.getVersionIdPart());
p = myPatientDao.read(id.toUnqualifiedVersionless());
p = myPatientDao.read(id.toUnqualifiedVersionless(), new ServletRequestDetails());
assertEquals("Patient/123abc", p.getIdElement().toUnqualifiedVersionless().getValue());
assertEquals("Hello", p.getName().get(0).getFamily().get(0).getValue());

View File

@ -8,15 +8,15 @@ import java.io.IOException;
import org.apache.commons.io.IOUtils;
import org.hl7.fhir.dstu3.model.Bundle;
import org.hl7.fhir.dstu3.model.Bundle.BundleEntryComponent;
import org.hl7.fhir.dstu3.model.IdType;
import org.hl7.fhir.dstu3.model.Observation;
import org.hl7.fhir.dstu3.model.Observation.ObservationStatus;
import org.hl7.fhir.dstu3.model.OperationOutcome;
import org.hl7.fhir.dstu3.model.Organization;
import org.hl7.fhir.dstu3.model.Patient;
import org.hl7.fhir.dstu3.model.StructureDefinition;
import org.hl7.fhir.dstu3.model.ValueSet;
import org.hl7.fhir.dstu3.model.Bundle.BundleEntryComponent;
import org.hl7.fhir.dstu3.model.Observation.ObservationStatus;
import org.hl7.fhir.instance.model.api.IBaseResource;
import org.hl7.fhir.instance.model.api.IIdType;
import org.junit.Ignore;
@ -28,6 +28,7 @@ import ca.uhn.fhir.rest.server.EncodingEnum;
import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException;
import ca.uhn.fhir.rest.server.exceptions.PreconditionFailedException;
import ca.uhn.fhir.rest.server.exceptions.ResourceVersionConflictException;
import ca.uhn.fhir.rest.server.servlet.ServletRequestDetails;
public class FhirResourceDaoDstu3ValidateTest extends BaseJpaDstu3Test {
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(FhirResourceDaoDstu3ValidateTest.class);
@ -60,20 +61,20 @@ public class FhirResourceDaoDstu3ValidateTest extends BaseJpaDstu3Test {
private OperationOutcome doTestValidateResourceContainingProfileDeclaration(String methodName, EncodingEnum enc) throws IOException {
Bundle vss = loadResourceFromClasspath(Bundle.class, "/org/hl7/fhir/instance/model/dstu3/valueset/valuesets.xml");
myValueSetDao.update((ValueSet) findResourceByIdInBundle(vss, "observation-status"));
myValueSetDao.update((ValueSet) findResourceByIdInBundle(vss, "observation-category"));
myValueSetDao.update((ValueSet) findResourceByIdInBundle(vss, "observation-codes"));
myValueSetDao.update((ValueSet) findResourceByIdInBundle(vss, "observation-methods"));
myValueSetDao.update((ValueSet) findResourceByIdInBundle(vss, "observation-valueabsentreason"));
myValueSetDao.update((ValueSet) findResourceByIdInBundle(vss, "observation-interpretation"));
myValueSetDao.update((ValueSet) findResourceByIdInBundle(vss, "body-site"));
myValueSetDao.update((ValueSet) findResourceByIdInBundle(vss, "referencerange-meaning"));
myValueSetDao.update((ValueSet) findResourceByIdInBundle(vss, "observation-relationshiptypes"));
myValueSetDao.update((ValueSet) findResourceByIdInBundle(vss, "observation-status"), new ServletRequestDetails());
myValueSetDao.update((ValueSet) findResourceByIdInBundle(vss, "observation-category"), new ServletRequestDetails());
myValueSetDao.update((ValueSet) findResourceByIdInBundle(vss, "observation-codes"), new ServletRequestDetails());
myValueSetDao.update((ValueSet) findResourceByIdInBundle(vss, "observation-methods"), new ServletRequestDetails());
myValueSetDao.update((ValueSet) findResourceByIdInBundle(vss, "observation-valueabsentreason"), new ServletRequestDetails());
myValueSetDao.update((ValueSet) findResourceByIdInBundle(vss, "observation-interpretation"), new ServletRequestDetails());
myValueSetDao.update((ValueSet) findResourceByIdInBundle(vss, "body-site"), new ServletRequestDetails());
myValueSetDao.update((ValueSet) findResourceByIdInBundle(vss, "referencerange-meaning"), new ServletRequestDetails());
myValueSetDao.update((ValueSet) findResourceByIdInBundle(vss, "observation-relationshiptypes"), new ServletRequestDetails());
StructureDefinition sd = loadResourceFromClasspath(StructureDefinition.class, "/org/hl7/fhir/instance/model/dstu3/profile/devicemetricobservation.profile.xml");
sd.setId(new IdType());
sd.setUrl("http://example.com/foo/bar/" + methodName);
myStructureDefinitionDao.create(sd);
myStructureDefinitionDao.create(sd, new ServletRequestDetails());
Observation input = new Observation();
input.getMeta().getProfile().add(new IdType(sd.getUrl()));
@ -90,7 +91,7 @@ public class FhirResourceDaoDstu3ValidateTest extends BaseJpaDstu3Test {
case JSON:
encoded = myFhirCtx.newJsonParser().encodeResourceToString(input);
try {
myObservationDao.validate(input, null, encoded, EncodingEnum.JSON, mode, null);
myObservationDao.validate(input, null, encoded, EncodingEnum.JSON, mode, null, new ServletRequestDetails());
fail();
} catch (PreconditionFailedException e) {
return (OperationOutcome) e.getOperationOutcome();
@ -98,7 +99,7 @@ public class FhirResourceDaoDstu3ValidateTest extends BaseJpaDstu3Test {
case XML:
encoded = myFhirCtx.newXmlParser().encodeResourceToString(input);
try {
myObservationDao.validate(input, null, encoded, EncodingEnum.XML, mode, null);
myObservationDao.validate(input, null, encoded, EncodingEnum.XML, mode, null, new ServletRequestDetails());
fail();
} catch (PreconditionFailedException e) {
return (OperationOutcome) e.getOperationOutcome();
@ -123,7 +124,7 @@ public class FhirResourceDaoDstu3ValidateTest extends BaseJpaDstu3Test {
ValidationModeEnum mode = ValidationModeEnum.CREATE;
String encoded = myFhirCtx.newJsonParser().encodeResourceToString(input);
MethodOutcome outcome = myObservationDao.validate(input, null, encoded, EncodingEnum.JSON, mode, null);
MethodOutcome outcome = myObservationDao.validate(input, null, encoded, EncodingEnum.JSON, mode, null, new ServletRequestDetails());
String ooString = myFhirCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(outcome.getOperationOutcome());
ourLog.info(ooString);
@ -140,14 +141,14 @@ public class FhirResourceDaoDstu3ValidateTest extends BaseJpaDstu3Test {
pat.addName().addFamily(methodName);
try {
myPatientDao.validate(pat, null, null, null, ValidationModeEnum.CREATE, null);
myPatientDao.validate(pat, null, null, null, ValidationModeEnum.CREATE, null, new ServletRequestDetails());
fail();
} catch (InvalidRequestException e) {
assertThat(e.getMessage(), containsString("ID must not be populated"));
}
pat.setId("");
myPatientDao.validate(pat, null, null, null, ValidationModeEnum.CREATE, null);
myPatientDao.validate(pat, null, null, null, ValidationModeEnum.CREATE, null, new ServletRequestDetails());
}
@ -158,12 +159,12 @@ public class FhirResourceDaoDstu3ValidateTest extends BaseJpaDstu3Test {
Patient pat = new Patient();
pat.setId("Patient/123");
pat.addName().addFamily(methodName);
myPatientDao.validate(pat, null, null, null, ValidationModeEnum.UPDATE, null);
myPatientDao.validate(pat, null, null, null, ValidationModeEnum.UPDATE, null, new ServletRequestDetails());
pat.setId("");
try {
myPatientDao.validate(pat, null, null, null, ValidationModeEnum.UPDATE, null);
myPatientDao.validate(pat, null, null, null, ValidationModeEnum.UPDATE, null, new ServletRequestDetails());
fail();
} catch (InvalidRequestException e) {
assertThat(e.getMessage(), containsString("ID must be populated"));
@ -181,12 +182,12 @@ public class FhirResourceDaoDstu3ValidateTest extends BaseJpaDstu3Test {
Patient pat = new Patient();
pat.setId("Patient/123");
pat.addName().addFamily(methodName);
myPatientDao.validate(pat, null, null, null, ValidationModeEnum.UPDATE, null);
myPatientDao.validate(pat, null, null, null, ValidationModeEnum.UPDATE, null, new ServletRequestDetails());
pat.setId("");
try {
myPatientDao.validate(pat, null, null, null, ValidationModeEnum.UPDATE, null);
myPatientDao.validate(pat, null, null, null, ValidationModeEnum.UPDATE, null, new ServletRequestDetails());
fail();
} catch (InvalidRequestException e) {
assertThat(e.getMessage(), containsString("ID must be populated"));
@ -200,16 +201,16 @@ public class FhirResourceDaoDstu3ValidateTest extends BaseJpaDstu3Test {
Organization org = new Organization();
org.setName(methodName);
IIdType orgId = myOrganizationDao.create(org).getId().toUnqualifiedVersionless();
IIdType orgId = myOrganizationDao.create(org, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
Patient pat = new Patient();
pat.addName().addFamily(methodName);
pat.getManagingOrganization().setReference(orgId.getValue());
IIdType patId = myPatientDao.create(pat).getId().toUnqualifiedVersionless();
IIdType patId = myPatientDao.create(pat, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
OperationOutcome outcome = null;
try {
myOrganizationDao.validate(null, orgId, null, null, ValidationModeEnum.DELETE, null);
myOrganizationDao.validate(null, orgId, null, null, ValidationModeEnum.DELETE, null, new ServletRequestDetails());
fail();
} catch (ResourceVersionConflictException e) {
outcome = (OperationOutcome) e.getOperationOutcome();
@ -221,9 +222,9 @@ public class FhirResourceDaoDstu3ValidateTest extends BaseJpaDstu3Test {
pat.setId(patId);
pat.getManagingOrganization().setReference("");
myPatientDao.update(pat);
myPatientDao.update(pat, new ServletRequestDetails());
outcome = (OperationOutcome) myOrganizationDao.validate(null, orgId, null, null, ValidationModeEnum.DELETE, null).getOperationOutcome();
outcome = (OperationOutcome) myOrganizationDao.validate(null, orgId, null, null, ValidationModeEnum.DELETE, null, new ServletRequestDetails()).getOperationOutcome();
ooString = myFhirCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(outcome);
ourLog.info(ooString);
assertThat(ooString, containsString("Ok to delete"));
@ -248,7 +249,7 @@ public class FhirResourceDaoDstu3ValidateTest extends BaseJpaDstu3Test {
public void testValidateNewQuestionnaireFormat() throws Exception {
String input =IOUtils.toString(FhirResourceDaoDstu3ValidateTest.class.getResourceAsStream("/questionnaire_dstu3.xml"));
try {
MethodOutcome results = myQuestionnaireDao.validate(null, null, input, EncodingEnum.XML, ValidationModeEnum.UPDATE, null);
MethodOutcome results = myQuestionnaireDao.validate(null, null, input, EncodingEnum.XML, ValidationModeEnum.UPDATE, null, new ServletRequestDetails());
OperationOutcome oo = (OperationOutcome) results.getOperationOutcome();
ourLog.info(myFhirCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(oo));
} catch (PreconditionFailedException e) {

View File

@ -24,6 +24,7 @@ import org.junit.Test;
import org.springframework.transaction.annotation.Transactional;
import ca.uhn.fhir.jpa.dao.IFhirResourceDaoValueSet.ValidateCodeResult;
import ca.uhn.fhir.rest.server.servlet.ServletRequestDetails;
public class FhirResourceDaoValueSetDstu3Test extends BaseJpaDstu3Test {
@ -37,7 +38,7 @@ public class FhirResourceDaoValueSetDstu3Test extends BaseJpaDstu3Test {
public void before02() throws IOException {
ValueSet upload = loadResourceFromClasspath(ValueSet.class, "/extensional-case-2.1.xml");
upload.setId("");
myExtensionalVsId = myValueSetDao.create(upload).getId().toUnqualifiedVersionless();
myExtensionalVsId = myValueSetDao.create(upload, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
}
@Test

View File

@ -17,6 +17,7 @@ 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.server.Constants;
import ca.uhn.fhir.rest.server.servlet.ServletRequestDetails;
public class FhirSearchDaoDstu3Test extends BaseJpaDstu3Test {
@ -32,7 +33,7 @@ public class FhirSearchDaoDstu3Test extends BaseJpaDstu3Test {
patient.addName().addGiven("testSearchStringParamWithNonNormalized_h\u00F6ra");
patient.addName().addFamily("AAAS");
patient.addName().addFamily("CCC");
id1 = myPatientDao.create(patient).getId().toUnqualifiedVersionless().getIdPartAsLong();
id1 = myPatientDao.create(patient, new ServletRequestDetails()).getId().toUnqualifiedVersionless().getIdPartAsLong();
}
Long id2;
{
@ -41,13 +42,13 @@ public class FhirSearchDaoDstu3Test extends BaseJpaDstu3Test {
patient.addName().addGiven("testSearchStringParamWithNonNormalized_HORA");
patient.addName().addFamily("AAAB");
patient.addName().addFamily("CCC");
id2 = myPatientDao.create(patient).getId().toUnqualifiedVersionless().getIdPartAsLong();
id2 = myPatientDao.create(patient, new ServletRequestDetails()).getId().toUnqualifiedVersionless().getIdPartAsLong();
}
Long id3;
{
Organization org = new Organization();
org.setName("DDD");
id3 = myOrganizationDao.create(org).getId().toUnqualifiedVersionless().getIdPartAsLong();
id3 = myOrganizationDao.create(org, new ServletRequestDetails()).getId().toUnqualifiedVersionless().getIdPartAsLong();
}
SearchParameterMap map = new SearchParameterMap();
@ -109,13 +110,13 @@ public class FhirSearchDaoDstu3Test extends BaseJpaDstu3Test {
{
Patient patient = new Patient();
patient.getText().setDivAsString("<div>AAAS<p>FOO</p> CCC </div>");
id1 = myPatientDao.create(patient).getId().toUnqualifiedVersionless().getIdPartAsLong();
id1 = myPatientDao.create(patient, new ServletRequestDetails()).getId().toUnqualifiedVersionless().getIdPartAsLong();
}
Long id2;
{
Patient patient = new Patient();
patient.getText().setDivAsString("<div>AAAB<p>FOO</p> CCC </div>");
id2 = myPatientDao.create(patient).getId().toUnqualifiedVersionless().getIdPartAsLong();
id2 = myPatientDao.create(patient, new ServletRequestDetails()).getId().toUnqualifiedVersionless().getIdPartAsLong();
}
SearchParameterMap map = new SearchParameterMap();

View File

@ -64,6 +64,7 @@ import ca.uhn.fhir.rest.server.exceptions.PreconditionFailedException;
import ca.uhn.fhir.rest.server.exceptions.ResourceGoneException;
import ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException;
import ca.uhn.fhir.rest.server.interceptor.IServerInterceptor.ActionRequestDetails;
import ca.uhn.fhir.rest.server.servlet.ServletRequestDetails;
public class FhirSystemDaoDstu3Test extends BaseJpaDstu3SystemTest {
@ -73,11 +74,11 @@ public class FhirSystemDaoDstu3Test extends BaseJpaDstu3SystemTest {
public void testReindexing() {
Patient p = new Patient();
p.addName().addFamily("family");
final IIdType id = myPatientDao.create(p).getId().toUnqualifiedVersionless();
final IIdType id = myPatientDao.create(p, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
ValueSet vs = new ValueSet();
vs.setUrl("http://foo");
myValueSetDao.create(vs);
myValueSetDao.create(vs, new ServletRequestDetails());
ResourceTable entity = new TransactionTemplate(myTxManager).execute(new TransactionCallback<ResourceTable>() {
@Override
@ -97,7 +98,7 @@ public class FhirSystemDaoDstu3Test extends BaseJpaDstu3SystemTest {
});
assertEquals(null, entity.getIndexStatus());
mySystemDao.performReindexingPass(null);
mySystemDao.performReindexingPass(null, new ServletRequestDetails());
entity = new TransactionTemplate(myTxManager).execute(new TransactionCallback<ResourceTable>() {
@Override
@ -108,7 +109,7 @@ public class FhirSystemDaoDstu3Test extends BaseJpaDstu3SystemTest {
assertEquals(Long.valueOf(1), entity.getIndexStatus());
// Just make sure this doesn't cause a choke
mySystemDao.performReindexingPass(100000);
mySystemDao.performReindexingPass(100000, new ServletRequestDetails());
// Try making the resource unparseable
@ -130,7 +131,7 @@ public class FhirSystemDaoDstu3Test extends BaseJpaDstu3SystemTest {
}
});
mySystemDao.performReindexingPass(null);
mySystemDao.performReindexingPass(null, new ServletRequestDetails());
entity = new TransactionTemplate(myTxManager).execute(new TransactionCallback<ResourceTable>() {
@Override
@ -145,7 +146,7 @@ public class FhirSystemDaoDstu3Test extends BaseJpaDstu3SystemTest {
@Test
public void testSystemMetaOperation() {
Meta meta = mySystemDao.metaGetOperation();
Meta meta = mySystemDao.metaGetOperation(new ServletRequestDetails());
List<Coding> published = meta.getTag();
assertEquals(0, published.size());
@ -160,7 +161,7 @@ public class FhirSystemDaoDstu3Test extends BaseJpaDstu3SystemTest {
patient.getMeta().getSecurity().add(new Coding().setSystem("seclabel:sys:1").setCode("seclabel:code:1").setDisplay("seclabel:dis:1"));
patient.getMeta().getProfile().add(new IdType("http://profile/1"));
id1 = myPatientDao.create(patient).getId();
id1 = myPatientDao.create(patient, new ServletRequestDetails()).getId();
}
{
Patient patient = new Patient();
@ -171,10 +172,10 @@ public class FhirSystemDaoDstu3Test extends BaseJpaDstu3SystemTest {
patient.getMeta().getSecurity().add(new Coding().setSystem("seclabel:sys:2").setCode("seclabel:code:2").setDisplay("seclabel:dis:2"));
patient.getMeta().getProfile().add(new IdType("http://profile/2"));
myPatientDao.create(patient);
myPatientDao.create(patient, new ServletRequestDetails());
}
meta = mySystemDao.metaGetOperation();
meta = mySystemDao.metaGetOperation(new ServletRequestDetails());
published = meta.getTag();
assertEquals(2, published.size());
assertEquals(null, published.get(0).getSystem());
@ -196,11 +197,11 @@ public class FhirSystemDaoDstu3Test extends BaseJpaDstu3SystemTest {
assertEquals("http://profile/1", profiles.get(0).getValue());
assertEquals("http://profile/2", profiles.get(1).getValue());
myPatientDao.removeTag(id1, TagTypeEnum.TAG, null, "Dog");
myPatientDao.removeTag(id1, TagTypeEnum.SECURITY_LABEL, "seclabel:sys:1", "seclabel:code:1");
myPatientDao.removeTag(id1, TagTypeEnum.PROFILE, BaseHapiFhirDao.NS_JPA_PROFILE, "http://profile/1");
myPatientDao.removeTag(id1, TagTypeEnum.TAG, null, "Dog", new ServletRequestDetails());
myPatientDao.removeTag(id1, TagTypeEnum.SECURITY_LABEL, "seclabel:sys:1", "seclabel:code:1", new ServletRequestDetails());
myPatientDao.removeTag(id1, TagTypeEnum.PROFILE, BaseHapiFhirDao.NS_JPA_PROFILE, "http://profile/1", new ServletRequestDetails());
meta = mySystemDao.metaGetOperation();
meta = mySystemDao.metaGetOperation(new ServletRequestDetails());
published = meta.getTag();
assertEquals(1, published.size());
assertEquals("http://foo", published.get(0).getSystem());
@ -256,7 +257,7 @@ public class FhirSystemDaoDstu3Test extends BaseJpaDstu3SystemTest {
assertEquals("201 Created", respEntry.getStatus());
IdType createdId = new IdType(respEntry.getLocation());
assertEquals("Patient", createdId.getResourceType());
myPatientDao.read(createdId); // shouldn't fail
myPatientDao.read(createdId, new ServletRequestDetails()); // shouldn't fail
// Check GET
respEntry = resp.getEntry().get(2).getResponse();
@ -272,7 +273,7 @@ public class FhirSystemDaoDstu3Test extends BaseJpaDstu3SystemTest {
Patient p = new Patient();
p.addIdentifier().setSystem("urn:system").setValue(methodName);
p.setId("Patient/" + methodName);
IIdType id = myPatientDao.update(p).getId();
IIdType id = myPatientDao.update(p, new ServletRequestDetails()).getId();
ourLog.info("Created patient, got it: {}", id);
p = new Patient();
@ -300,7 +301,7 @@ public class FhirSystemDaoDstu3Test extends BaseJpaDstu3SystemTest {
assertThat(respEntry.getResponse().getLocation(), endsWith("/_history/1"));
assertEquals("1", respEntry.getResponse().getEtag());
o = myObservationDao.read(new IdType(respEntry.getResponse().getLocationElement()));
o = (Observation) myObservationDao.read(new IdType(respEntry.getResponse().getLocationElement()), new ServletRequestDetails());
assertEquals(id.toVersionless().getValue(), o.getSubject().getReference());
assertEquals("1", o.getIdElement().getVersionIdPart());
@ -406,12 +407,12 @@ public class FhirSystemDaoDstu3Test extends BaseJpaDstu3SystemTest {
Patient p = new Patient();
p.addIdentifier().setSystem("urn:system").setValue(methodName);
IIdType id = myPatientDao.create(p).getId();
IIdType id = myPatientDao.create(p, new ServletRequestDetails()).getId();
ourLog.info("Created patient, got it: {}", id);
p = new Patient();
p.addIdentifier().setSystem("urn:system").setValue(methodName);
id = myPatientDao.create(p).getId();
id = myPatientDao.create(p, new ServletRequestDetails()).getId();
ourLog.info("Created patient, got it: {}", id);
Bundle request = new Bundle();
@ -468,7 +469,7 @@ public class FhirSystemDaoDstu3Test extends BaseJpaDstu3SystemTest {
assertThat(respEntry.getResponse().getLocation(), endsWith("/_history/1"));
assertEquals("1", respEntry.getResponse().getEtag());
o = myObservationDao.read(new IdType(respEntry.getResponse().getLocationElement()));
o = (Observation) myObservationDao.read(new IdType(respEntry.getResponse().getLocationElement()), new ServletRequestDetails());
assertEquals(new IdType(patientId).toUnqualifiedVersionless().getValue(), o.getSubject().getReference());
}
@ -568,8 +569,8 @@ public class FhirSystemDaoDstu3Test extends BaseJpaDstu3SystemTest {
mySystemDao.transaction(myRequestDetails, request);
myObservationDao.read(new IdType("Observation/a" + methodName));
myPatientDao.read(new IdType("Patient/" + methodName));
myObservationDao.read(new IdType("Observation/a" + methodName), new ServletRequestDetails());
myPatientDao.read(new IdType("Patient/" + methodName), new ServletRequestDetails());
}
@Test
@ -659,13 +660,13 @@ public class FhirSystemDaoDstu3Test extends BaseJpaDstu3SystemTest {
Patient p1 = new Patient();
p1.addIdentifier().setSystem("urn:system").setValue(methodName);
IIdType id1 = myPatientDao.create(p1).getId();
IIdType id1 = myPatientDao.create(p1, new ServletRequestDetails()).getId();
ourLog.info("Created patient, got it: {}", id1);
Patient p2 = new Patient();
p2.addIdentifier().setSystem("urn:system").setValue(methodName);
p2.setId("Patient/" + methodName);
IIdType id2 = myPatientDao.update(p2).getId();
IIdType id2 = myPatientDao.update(p2, new ServletRequestDetails()).getId();
ourLog.info("Created patient, got it: {}", id2);
Bundle request = new Bundle();
@ -673,8 +674,8 @@ public class FhirSystemDaoDstu3Test extends BaseJpaDstu3SystemTest {
request.addEntry().getRequest().setMethod(HTTPVerb.DELETE).setUrl("Patient/" + id1.getIdPart());
request.addEntry().getRequest().setMethod(HTTPVerb.DELETE).setUrl("Patient/" + id2.getIdPart());
myPatientDao.read(id1.toVersionless());
myPatientDao.read(id2.toVersionless());
myPatientDao.read(id1.toVersionless(), new ServletRequestDetails());
myPatientDao.read(id2.toVersionless(), new ServletRequestDetails());
Bundle resp = mySystemDao.transaction(myRequestDetails, request);
@ -683,14 +684,14 @@ public class FhirSystemDaoDstu3Test extends BaseJpaDstu3SystemTest {
assertEquals("204 No Content", resp.getEntry().get(1).getResponse().getStatus());
try {
myPatientDao.read(id1.toVersionless());
myPatientDao.read(id1.toVersionless(), new ServletRequestDetails());
fail();
} catch (ResourceGoneException e) {
// good
}
try {
myPatientDao.read(id2.toVersionless());
myPatientDao.read(id2.toVersionless(), new ServletRequestDetails());
fail();
} catch (ResourceGoneException e) {
// good
@ -707,20 +708,20 @@ public class FhirSystemDaoDstu3Test extends BaseJpaDstu3SystemTest {
Patient p1 = new Patient();
p1.addIdentifier().setSystem("urn:system").setValue(methodName);
IIdType pid = myPatientDao.create(p1).getId().toUnqualifiedVersionless();
IIdType pid = myPatientDao.create(p1, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
ourLog.info("Created patient, got it: {}", pid);
Observation o1 = new Observation();
o1.getSubject().setReferenceElement(pid);
IIdType oid1 = myObservationDao.create(o1).getId().toUnqualifiedVersionless();
IIdType oid1 = myObservationDao.create(o1, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
Observation o2 = new Observation();
o2.addIdentifier().setValue(methodName);
o2.getSubject().setReferenceElement(pid);
IIdType oid2 = myObservationDao.create(o2).getId().toUnqualifiedVersionless();
IIdType oid2 = myObservationDao.create(o2, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
myPatientDao.read(pid);
myObservationDao.read(oid1);
myPatientDao.read(pid, new ServletRequestDetails());
myObservationDao.read(oid1, new ServletRequestDetails());
// The target is Patient, so try with it first in the bundle
Bundle request = new Bundle();
@ -735,21 +736,21 @@ public class FhirSystemDaoDstu3Test extends BaseJpaDstu3SystemTest {
assertEquals("204 No Content", resp.getEntry().get(2).getResponse().getStatus());
try {
myPatientDao.read(pid);
myPatientDao.read(pid, new ServletRequestDetails());
fail();
} catch (ResourceGoneException e) {
// good
}
try {
myObservationDao.read(oid1);
myObservationDao.read(oid1, new ServletRequestDetails());
fail();
} catch (ResourceGoneException e) {
// good
}
try {
myObservationDao.read(oid2);
myObservationDao.read(oid2, new ServletRequestDetails());
fail();
} catch (ResourceGoneException e) {
// good
@ -766,20 +767,20 @@ public class FhirSystemDaoDstu3Test extends BaseJpaDstu3SystemTest {
Patient p1 = new Patient();
p1.addIdentifier().setSystem("urn:system").setValue(methodName);
IIdType pid = myPatientDao.create(p1).getId().toUnqualifiedVersionless();
IIdType pid = myPatientDao.create(p1, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
ourLog.info("Created patient, got it: {}", pid);
Observation o1 = new Observation();
o1.getSubject().setReferenceElement(pid);
IIdType oid1 = myObservationDao.create(o1).getId().toUnqualifiedVersionless();
IIdType oid1 = myObservationDao.create(o1, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
Observation o2 = new Observation();
o2.addIdentifier().setValue(methodName);
o2.getSubject().setReferenceElement(pid);
IIdType oid2 = myObservationDao.create(o2).getId().toUnqualifiedVersionless();
IIdType oid2 = myObservationDao.create(o2, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
myPatientDao.read(pid);
myObservationDao.read(oid1);
myPatientDao.read(pid, new ServletRequestDetails());
myObservationDao.read(oid1, new ServletRequestDetails());
// The target is Patient, so try with it last in the bundle
Bundle request = new Bundle();
@ -794,21 +795,21 @@ public class FhirSystemDaoDstu3Test extends BaseJpaDstu3SystemTest {
assertEquals("204 No Content", resp.getEntry().get(2).getResponse().getStatus());
try {
myPatientDao.read(pid);
myPatientDao.read(pid, new ServletRequestDetails());
fail();
} catch (ResourceGoneException e) {
// good
}
try {
myObservationDao.read(oid1);
myObservationDao.read(oid1, new ServletRequestDetails());
fail();
} catch (ResourceGoneException e) {
// good
}
try {
myObservationDao.read(oid2);
myObservationDao.read(oid2, new ServletRequestDetails());
fail();
} catch (ResourceGoneException e) {
// good
@ -822,7 +823,7 @@ public class FhirSystemDaoDstu3Test extends BaseJpaDstu3SystemTest {
Patient p = new Patient();
p.addIdentifier().setSystem("urn:system").setValue(methodName);
IIdType id = myPatientDao.create(p).getId();
IIdType id = myPatientDao.create(p, new ServletRequestDetails()).getId();
ourLog.info("Created patient, got it: {}", id);
Bundle request = new Bundle();
@ -835,20 +836,20 @@ public class FhirSystemDaoDstu3Test extends BaseJpaDstu3SystemTest {
assertEquals(Constants.STATUS_HTTP_204_NO_CONTENT + " No Content", nextEntry.getResponse().getStatus());
try {
myPatientDao.read(id.toVersionless());
myPatientDao.read(id.toVersionless(), new ServletRequestDetails());
fail();
} catch (ResourceGoneException e) {
// ok
}
try {
myPatientDao.read(new IdType("Patient/" + methodName));
myPatientDao.read(new IdType("Patient/" + methodName), new ServletRequestDetails());
fail();
} catch (ResourceNotFoundException e) {
// ok
}
IBundleProvider history = myPatientDao.history(id, null);
IBundleProvider history = myPatientDao.history(id, null, new ServletRequestDetails());
assertEquals(2, history.size());
assertNotNull(ResourceMetadataKeyEnum.DELETED_AT.get((IAnyResource) history.getResources(0, 0).get(0)));
@ -865,12 +866,12 @@ public class FhirSystemDaoDstu3Test extends BaseJpaDstu3SystemTest {
Patient p = new Patient();
p.addIdentifier().setSystem("urn:system").setValue(methodName);
IIdType id = myPatientDao.create(p).getId();
IIdType id = myPatientDao.create(p, new ServletRequestDetails()).getId();
ourLog.info("Created patient, got it: {}", id);
p = new Patient();
p.addIdentifier().setSystem("urn:system").setValue(methodName);
id = myPatientDao.create(p).getId();
id = myPatientDao.create(p, new ServletRequestDetails()).getId();
ourLog.info("Created patient, got it: {}", id);
p = new Patient();
@ -914,7 +915,7 @@ public class FhirSystemDaoDstu3Test extends BaseJpaDstu3SystemTest {
Patient p = new Patient();
p.addIdentifier().setSystem("urn:system").setValue(methodName);
p.setId("Patient/" + methodName);
IIdType id = myPatientDao.update(p).getId();
IIdType id = myPatientDao.update(p, new ServletRequestDetails()).getId();
ourLog.info("Created patient, got it: {}", id);
Bundle request = new Bundle();
@ -926,7 +927,7 @@ public class FhirSystemDaoDstu3Test extends BaseJpaDstu3SystemTest {
assertEquals(Constants.STATUS_HTTP_204_NO_CONTENT + " No Content", res.getEntry().get(0).getResponse().getStatus());
try {
myPatientDao.read(id.toVersionless());
myPatientDao.read(id.toVersionless(), new ServletRequestDetails());
fail();
} catch (ResourceGoneException e) {
// ok
@ -965,7 +966,7 @@ public class FhirSystemDaoDstu3Test extends BaseJpaDstu3SystemTest {
assertThat(resp.getEntry().get(1).getResponse().getLocation(), startsWith("Patient/temp6789/_history/"));
assertThat(resp.getEntry().get(2).getResponse().getLocation(), startsWith("Organization/GHH/_history/"));
Patient p = myPatientDao.read(new IdType("Patient/a555-44-4444/_history/1"));
Patient p = myPatientDao.read(new IdType("Patient/a555-44-4444/_history/1"), new ServletRequestDetails());
assertEquals("Patient/temp6789", p.getLink().get(0).getOther().getReference());
}
@ -1118,14 +1119,14 @@ public class FhirSystemDaoDstu3Test extends BaseJpaDstu3SystemTest {
Patient p = new Patient();
p.addIdentifier().setSystem("urn:system").setValue(methodName);
p.setId("Patient/" + methodName);
IIdType idv1 = myPatientDao.update(p).getId();
IIdType idv1 = myPatientDao.update(p, new ServletRequestDetails()).getId();
ourLog.info("Created patient, got id: {}", idv1);
p = new Patient();
p.addIdentifier().setSystem("urn:system").setValue(methodName);
p.addName().addFamily("Family Name");
p.setId("Patient/" + methodName);
IIdType idv2 = myPatientDao.update(p).getId();
IIdType idv2 = myPatientDao.update(p, new ServletRequestDetails()).getId();
ourLog.info("Updated patient, got id: {}", idv2);
Bundle request = new Bundle();
@ -1188,14 +1189,14 @@ public class FhirSystemDaoDstu3Test extends BaseJpaDstu3SystemTest {
Patient p = new Patient();
p.addIdentifier().setSystem("urn:system").setValue(methodName);
p.setId("Patient/" + methodName);
IIdType idv1 = myPatientDao.update(p).getId();
IIdType idv1 = myPatientDao.update(p, new ServletRequestDetails()).getId();
ourLog.info("Created patient, got id: {}", idv1);
p = new Patient();
p.addIdentifier().setSystem("urn:system").setValue(methodName);
p.addName().addFamily("Family Name");
p.setId("Patient/" + methodName);
IIdType idv2 = myPatientDao.update(p).getId();
IIdType idv2 = myPatientDao.update(p, new ServletRequestDetails()).getId();
ourLog.info("Updated patient, got id: {}", idv2);
Bundle request = new Bundle();
@ -1233,14 +1234,14 @@ public class FhirSystemDaoDstu3Test extends BaseJpaDstu3SystemTest {
Patient p = new Patient();
p.addIdentifier().setSystem("urn:system").setValue(methodName);
p.setId("Patient/" + methodName);
IIdType idv1 = myPatientDao.update(p).getId();
IIdType idv1 = myPatientDao.update(p, new ServletRequestDetails()).getId();
ourLog.info("Created patient, got id: {}", idv1);
p = new Patient();
p.addIdentifier().setSystem("urn:system").setValue(methodName);
p.addName().addFamily("Family Name");
p.setId("Patient/" + methodName);
IIdType idv2 = myPatientDao.update(p).getId();
IIdType idv2 = myPatientDao.update(p, new ServletRequestDetails()).getId();
ourLog.info("Updated patient, got id: {}", idv2);
Bundle request = new Bundle();
@ -1296,7 +1297,7 @@ public class FhirSystemDaoDstu3Test extends BaseJpaDstu3SystemTest {
Patient p = new Patient();
p.addIdentifier().setSystem("urn:system").setValue(methodName);
IIdType id = myPatientDao.create(p).getId();
IIdType id = myPatientDao.create(p, new ServletRequestDetails()).getId();
ourLog.info("Created patient, got it: {}", id);
p = new Patient();
@ -1325,7 +1326,7 @@ public class FhirSystemDaoDstu3Test extends BaseJpaDstu3SystemTest {
assertThat(nextEntry.getResponse().getLocation(), not(emptyString()));
nextEntry = resp.getEntry().get(1);
o = myObservationDao.read(new IdType(nextEntry.getResponse().getLocation()));
o = myObservationDao.read(new IdType(nextEntry.getResponse().getLocation()), new ServletRequestDetails());
assertEquals(id.toVersionless().getValue(), o.getSubject().getReference());
}
@ -1337,12 +1338,12 @@ public class FhirSystemDaoDstu3Test extends BaseJpaDstu3SystemTest {
Patient p = new Patient();
p.addIdentifier().setSystem("urn:system").setValue(methodName);
IIdType id = myPatientDao.create(p).getId();
IIdType id = myPatientDao.create(p, new ServletRequestDetails()).getId();
ourLog.info("Created patient, got it: {}", id);
p = new Patient();
p.addIdentifier().setSystem("urn:system").setValue(methodName);
id = myPatientDao.create(p).getId();
id = myPatientDao.create(p, new ServletRequestDetails()).getId();
ourLog.info("Created patient, got it: {}", id);
p = new Patient();
@ -1371,7 +1372,7 @@ public class FhirSystemDaoDstu3Test extends BaseJpaDstu3SystemTest {
Patient p = new Patient();
p.addName().addFamily("Hello");
IIdType id = myPatientDao.create(p).getId();
IIdType id = myPatientDao.create(p, new ServletRequestDetails()).getId();
p = new Patient();
p.addIdentifier().setSystem("urn:system").setValue(methodName);
@ -1397,7 +1398,7 @@ public class FhirSystemDaoDstu3Test extends BaseJpaDstu3SystemTest {
assertThat(patientId.getValue(), endsWith("/_history/1"));
nextEntry = resp.getEntry().get(1);
o = myObservationDao.read(new IdType(nextEntry.getResponse().getLocation()));
o = myObservationDao.read(new IdType(nextEntry.getResponse().getLocation()), new ServletRequestDetails());
assertEquals(patientId.toVersionless().getValue(), o.getSubject().getReference());
}
@ -1410,7 +1411,7 @@ public class FhirSystemDaoDstu3Test extends BaseJpaDstu3SystemTest {
Patient p = new Patient();
p.addIdentifier().setSystem("urn:system").setValue(methodName);
p.setId("Patient/" + methodName);
IIdType id = myPatientDao.update(p).getId();
IIdType id = myPatientDao.update(p, new ServletRequestDetails()).getId();
ourLog.info("Created patient, got it: {}", id);
p = new Patient();
@ -1438,7 +1439,7 @@ public class FhirSystemDaoDstu3Test extends BaseJpaDstu3SystemTest {
nextEntry = resp.getEntry().get(1);
assertEquals(Constants.STATUS_HTTP_201_CREATED + " Created", nextEntry.getResponse().getStatus());
o = myObservationDao.read(new IdType(resp.getEntry().get(1).getResponse().getLocation()));
o = myObservationDao.read(new IdType(resp.getEntry().get(1).getResponse().getLocation()), new ServletRequestDetails());
assertEquals(id.toVersionless().getValue(), o.getSubject().getReference());
}
@ -1647,8 +1648,8 @@ public class FhirSystemDaoDstu3Test extends BaseJpaDstu3SystemTest {
assertTrue(resp.getEntry().get(1).getResponse().getLocation(), new IdType(resp.getEntry().get(1).getResponse().getLocation()).getIdPart().matches("^[0-9]+$"));
assertTrue(resp.getEntry().get(2).getResponse().getLocation(), new IdType(resp.getEntry().get(2).getResponse().getLocation()).getIdPart().matches("^[0-9]+$"));
o1 = myObservationDao.read(new IdType(resp.getEntry().get(1).getResponse().getLocation()));
o2 = myObservationDao.read(new IdType(resp.getEntry().get(2).getResponse().getLocation()));
o1 = myObservationDao.read(new IdType(resp.getEntry().get(1).getResponse().getLocation()), new ServletRequestDetails());
o2 = myObservationDao.read(new IdType(resp.getEntry().get(2).getResponse().getLocation()), new ServletRequestDetails());
assertThat(o1.getSubject().getReferenceElement().getValue(), endsWith("Patient/" + p1.getIdElement().getIdPart()));
assertThat(o2.getSubject().getReferenceElement().getValue(), endsWith("Patient/" + p1.getIdElement().getIdPart()));
@ -1690,8 +1691,8 @@ public class FhirSystemDaoDstu3Test extends BaseJpaDstu3SystemTest {
assertTrue(resp.getEntry().get(1).getResponse().getLocation(), new IdType(resp.getEntry().get(1).getResponse().getLocation()).getIdPart().matches("^[0-9]+$"));
assertTrue(resp.getEntry().get(2).getResponse().getLocation(), new IdType(resp.getEntry().get(2).getResponse().getLocation()).getIdPart().matches("^[0-9]+$"));
o1 = myObservationDao.read(new IdType(resp.getEntry().get(1).getResponse().getLocation()));
o2 = myObservationDao.read(new IdType(resp.getEntry().get(2).getResponse().getLocation()));
o1 = myObservationDao.read(new IdType(resp.getEntry().get(1).getResponse().getLocation()), new ServletRequestDetails());
o2 = myObservationDao.read(new IdType(resp.getEntry().get(2).getResponse().getLocation()), new ServletRequestDetails());
assertThat(o1.getSubject().getReferenceElement().getValue(), endsWith("Patient/" + p1.getIdElement().getIdPart()));
assertThat(o2.getSubject().getReferenceElement().getValue(), endsWith("Patient/" + p1.getIdElement().getIdPart()));

View File

@ -63,6 +63,7 @@ import ca.uhn.fhir.rest.server.IResourceProvider;
import ca.uhn.fhir.rest.server.RestfulServer;
import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException;
import ca.uhn.fhir.rest.server.exceptions.UnprocessableEntityException;
import ca.uhn.fhir.rest.server.servlet.ServletRequestDetails;
public class ResourceProviderDstu1Test extends BaseJpaTest {
@ -421,7 +422,7 @@ public class ResourceProviderDstu1Test extends BaseJpaTest {
// Read back directly from the DAO
{
Organization returned = ourOrganizationDao.read(orgId);
Organization returned = ourOrganizationDao.read(orgId, new ServletRequestDetails());
String val = ourCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(returned);
ourLog.info(val);
assertThat(val, containsString("<name value=\"測試醫院\"/>"));

View File

@ -99,6 +99,7 @@ import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException;
import ca.uhn.fhir.rest.server.exceptions.PreconditionFailedException;
import ca.uhn.fhir.rest.server.exceptions.ResourceGoneException;
import ca.uhn.fhir.rest.server.exceptions.UnprocessableEntityException;
import ca.uhn.fhir.rest.server.servlet.ServletRequestDetails;
import ca.uhn.fhir.util.UrlUtil;
public class ResourceProviderDstu2Test extends BaseResourceProviderDstu2Test {
@ -123,19 +124,19 @@ public class ResourceProviderDstu2Test extends BaseResourceProviderDstu2Test {
public void testEverythingInstanceWithContentFilter() {
Patient pt1 = new Patient();
pt1.addName().addFamily("Everything").addGiven("Arthur");
IIdType ptId1 = myPatientDao.create(pt1).getId().toUnqualifiedVersionless();
IIdType ptId1 = myPatientDao.create(pt1, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
Patient pt2 = new Patient();
pt2.addName().addFamily("Everything").addGiven("Arthur");
IIdType ptId2 = myPatientDao.create(pt2).getId().toUnqualifiedVersionless();
IIdType ptId2 = myPatientDao.create(pt2, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
Device dev1 = new Device();
dev1.setManufacturer("Some Manufacturer");
IIdType devId1 = myDeviceDao.create(dev1).getId().toUnqualifiedVersionless();
IIdType devId1 = myDeviceDao.create(dev1, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
Device dev2 = new Device();
dev2.setManufacturer("Some Manufacturer 2");
myDeviceDao.create(dev2).getId().toUnqualifiedVersionless();
myDeviceDao.create(dev2, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
Observation obs1 = new Observation();
obs1.getText().setDiv("<div>OBSTEXT1</div>");
@ -143,19 +144,19 @@ public class ResourceProviderDstu2Test extends BaseResourceProviderDstu2Test {
obs1.getCode().addCoding().setCode("CODE1");
obs1.setValue(new StringDt("obsvalue1"));
obs1.getDevice().setReference(devId1);
IIdType obsId1 = myObservationDao.create(obs1).getId().toUnqualifiedVersionless();
IIdType obsId1 = myObservationDao.create(obs1, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
Observation obs2 = new Observation();
obs2.getSubject().setReference(ptId1);
obs2.getCode().addCoding().setCode("CODE2");
obs2.setValue(new StringDt("obsvalue2"));
IIdType obsId2 = myObservationDao.create(obs2).getId().toUnqualifiedVersionless();
IIdType obsId2 = myObservationDao.create(obs2, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
Observation obs3 = new Observation();
obs3.getSubject().setReference(ptId2);
obs3.getCode().addCoding().setCode("CODE3");
obs3.setValue(new StringDt("obsvalue3"));
IIdType obsId3 = myObservationDao.create(obs3).getId().toUnqualifiedVersionless();
IIdType obsId3 = myObservationDao.create(obs3, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
List<IIdType> actual;
StringAndListParam param;
@ -553,12 +554,12 @@ public class ResourceProviderDstu2Test extends BaseResourceProviderDstu2Test {
Patient p = new Patient();
p.addIdentifier().setSystem("urn:system").setValue(methodName);
p.addName().addFamily("FAM1");
IIdType id1 = myPatientDao.create(p).getId().toUnqualifiedVersionless();
IIdType id1 = myPatientDao.create(p, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
p = new Patient();
p.addIdentifier().setSystem("urn:system").setValue(methodName);
p.addName().addFamily("FAM2");
IIdType id2 = myPatientDao.create(p).getId().toUnqualifiedVersionless();
IIdType id2 = myPatientDao.create(p, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
try {
//@formatter:off
@ -973,16 +974,16 @@ public class ResourceProviderDstu2Test extends BaseResourceProviderDstu2Test {
Medication med = new Medication();
med.getCode().setText(methodName);
IIdType medId = myMedicationDao.create(med).getId().toUnqualifiedVersionless();
IIdType medId = myMedicationDao.create(med, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
Patient pat = new Patient();
pat.addAddress().addLine(methodName);
IIdType patId = myPatientDao.create(pat).getId().toUnqualifiedVersionless();
IIdType patId = myPatientDao.create(pat, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
MedicationOrder mo = new MedicationOrder();
mo.getPatient().setReference(patId);
mo.setMedication(new ResourceReferenceDt(medId));
IIdType moId = myMedicationOrderDao.create(mo).getId().toUnqualifiedVersionless();
IIdType moId = myMedicationOrderDao.create(mo, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
Parameters output = ourClient.operation().onInstance(patId).named("everything").withNoParameters(Parameters.class).execute();
ca.uhn.fhir.model.dstu2.resource.Bundle b = (ca.uhn.fhir.model.dstu2.resource.Bundle) output.getParameterFirstRep().getResource();
@ -1491,13 +1492,13 @@ public class ResourceProviderDstu2Test extends BaseResourceProviderDstu2Test {
{
Patient patient = new Patient();
patient.addIdentifier().setSystem("urn:system").setValue("001");
id1 = myPatientDao.create(patient).getId().toUnqualifiedVersionless();
id1 = myPatientDao.create(patient, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
}
IIdType id2;
{
Patient patient = new Patient();
patient.addIdentifier().setSystem("urn:system").setValue("001");
id2 = myPatientDao.create(patient).getId().toUnqualifiedVersionless();
id2 = myPatientDao.create(patient, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
}
//@formatter:off
@ -1714,7 +1715,7 @@ public class ResourceProviderDstu2Test extends BaseResourceProviderDstu2Test {
public void testSearchWithInvalidSort() throws Exception {
Observation o = new Observation();
o.getCode().setText("testSearchWithInvalidSort");
myObservationDao.create(o);
myObservationDao.create(o, new ServletRequestDetails());
//@formatter:off
ourClient
.search()
@ -1957,7 +1958,7 @@ public class ResourceProviderDstu2Test extends BaseResourceProviderDstu2Test {
// Read back directly from the DAO
{
Organization returned = myOrganizationDao.read(orgId);
Organization returned = myOrganizationDao.read(orgId, new ServletRequestDetails());
String val = myFhirCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(returned);
ourLog.info(val);
assertThat(val, containsString("<name value=\"測試醫院\"/>"));

View File

@ -23,6 +23,7 @@ import ca.uhn.fhir.model.primitive.CodeDt;
import ca.uhn.fhir.model.primitive.StringDt;
import ca.uhn.fhir.model.primitive.UriDt;
import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException;
import ca.uhn.fhir.rest.server.servlet.ServletRequestDetails;
public class ResourceProviderDstu2ValueSetTest extends BaseResourceProviderDstu2Test {
@ -34,7 +35,7 @@ public class ResourceProviderDstu2ValueSetTest extends BaseResourceProviderDstu2
public void before02() throws IOException {
ValueSet upload = loadResourceFromClasspath(ValueSet.class, "/extensional-case-2.xml");
upload.setId("");
myExtensionalVsId = myValueSetDao.create(upload).getId().toUnqualifiedVersionless();
myExtensionalVsId = myValueSetDao.create(upload, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
}
@Test

View File

@ -31,6 +31,7 @@ import ca.uhn.fhir.model.dstu2.valueset.SubscriptionStatusEnum;
import ca.uhn.fhir.model.primitive.IdDt;
import ca.uhn.fhir.rest.server.EncodingEnum;
import ca.uhn.fhir.rest.server.exceptions.UnprocessableEntityException;
import ca.uhn.fhir.rest.server.servlet.ServletRequestDetails;
public class SubscriptionsDstu2Test extends BaseResourceProviderDstu2Test {
@ -177,7 +178,7 @@ public class SubscriptionsDstu2Test extends BaseResourceProviderDstu2Test {
String methodName = "testSubscriptionDynamic";
Patient p = new Patient();
p.addName().addFamily(methodName);
IIdType pId = myPatientDao.create(p).getId().toUnqualifiedVersionless();
IIdType pId = myPatientDao.create(p, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
String criteria = "Observation?subject=Patient/" + pId.getIdPart();
DynamicEchoSocket socket = new DynamicEchoSocket(criteria, EncodingEnum.JSON);
@ -190,17 +191,17 @@ public class SubscriptionsDstu2Test extends BaseResourceProviderDstu2Test {
sleepUntilPingCount(socket, 1);
mySubscriptionDao.read(new IdDt("Subscription", socket.mySubsId));
mySubscriptionDao.read(new IdDt("Subscription", socket.mySubsId), new ServletRequestDetails());
Observation obs = new Observation();
obs.getSubject().setReference(pId);
obs.setStatus(ObservationStatusEnum.FINAL);
IIdType afterId1 = myObservationDao.create(obs).getId().toUnqualifiedVersionless();
IIdType afterId1 = myObservationDao.create(obs, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
obs = new Observation();
obs.getSubject().setReference(pId);
obs.setStatus(ObservationStatusEnum.FINAL);
IIdType afterId2 = myObservationDao.create(obs).getId().toUnqualifiedVersionless();
IIdType afterId2 = myObservationDao.create(obs, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
Thread.sleep(100);
@ -215,7 +216,7 @@ public class SubscriptionsDstu2Test extends BaseResourceProviderDstu2Test {
obs = new Observation();
obs.getSubject().setReference(pId);
obs.setStatus(ObservationStatusEnum.FINAL);
IIdType afterId3 = myObservationDao.create(obs).getId().toUnqualifiedVersionless();
IIdType afterId3 = myObservationDao.create(obs, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
sleepUntilPingCount(socket, 4);
@ -242,7 +243,7 @@ public class SubscriptionsDstu2Test extends BaseResourceProviderDstu2Test {
String methodName = "testSubscriptionDynamic";
Patient p = new Patient();
p.addName().addFamily(methodName);
IIdType pId = myPatientDao.create(p).getId().toUnqualifiedVersionless();
IIdType pId = myPatientDao.create(p, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
String criteria = "Observation?subject=Patient/" + pId.getIdPart() + "&_format=xml";
DynamicEchoSocket socket = new DynamicEchoSocket(criteria, EncodingEnum.XML);
@ -255,18 +256,18 @@ public class SubscriptionsDstu2Test extends BaseResourceProviderDstu2Test {
sleepUntilPingCount(socket, 1);
mySubscriptionDao.read(new IdDt("Subscription", socket.mySubsId));
mySubscriptionDao.read(new IdDt("Subscription", socket.mySubsId), new ServletRequestDetails());
Observation obs = new Observation();
ResourceMetadataKeyEnum.PROFILES.put(obs, Collections.singletonList(new IdDt("http://foo")));
obs.getSubject().setReference(pId);
obs.setStatus(ObservationStatusEnum.FINAL);
IIdType afterId1 = myObservationDao.create(obs).getId().toUnqualifiedVersionless();
IIdType afterId1 = myObservationDao.create(obs, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
obs = new Observation();
obs.getSubject().setReference(pId);
obs.setStatus(ObservationStatusEnum.FINAL);
IIdType afterId2 = myObservationDao.create(obs).getId().toUnqualifiedVersionless();
IIdType afterId2 = myObservationDao.create(obs, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
Thread.sleep(100);
@ -281,7 +282,7 @@ public class SubscriptionsDstu2Test extends BaseResourceProviderDstu2Test {
obs = new Observation();
obs.getSubject().setReference(pId);
obs.setStatus(ObservationStatusEnum.FINAL);
IIdType afterId3 = myObservationDao.create(obs).getId().toUnqualifiedVersionless();
IIdType afterId3 = myObservationDao.create(obs, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
sleepUntilPingCount(socket, 4);
@ -307,26 +308,26 @@ public class SubscriptionsDstu2Test extends BaseResourceProviderDstu2Test {
String methodName = "testSubscriptionResourcesAppear";
Patient p = new Patient();
p.addName().addFamily(methodName);
IIdType pId = myPatientDao.create(p).getId().toUnqualifiedVersionless();
IIdType pId = myPatientDao.create(p, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
Subscription subs = new Subscription();
ResourceMetadataKeyEnum.PROFILES.put(subs, Collections.singletonList(new IdDt("http://foo")));
subs.getChannel().setType(SubscriptionChannelTypeEnum.WEBSOCKET);
subs.setCriteria("Observation?subject=Patient/" + pId.getIdPart());
subs.setStatus(SubscriptionStatusEnum.ACTIVE);
String subsId = mySubscriptionDao.create(subs).getId().getIdPart();
String subsId = mySubscriptionDao.create(subs, new ServletRequestDetails()).getId().getIdPart();
Thread.sleep(100);
Observation obs = new Observation();
obs.getSubject().setReference(pId);
obs.setStatus(ObservationStatusEnum.FINAL);
IIdType afterId1 = myObservationDao.create(obs).getId().toUnqualifiedVersionless();
IIdType afterId1 = myObservationDao.create(obs, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
obs = new Observation();
obs.getSubject().setReference(pId);
obs.setStatus(ObservationStatusEnum.FINAL);
IIdType afterId2 = myObservationDao.create(obs).getId().toUnqualifiedVersionless();
IIdType afterId2 = myObservationDao.create(obs, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
Thread.sleep(100);
@ -344,7 +345,7 @@ public class SubscriptionsDstu2Test extends BaseResourceProviderDstu2Test {
obs = new Observation();
obs.getSubject().setReference(pId);
obs.setStatus(ObservationStatusEnum.FINAL);
IIdType afterId3 = myObservationDao.create(obs).getId().toUnqualifiedVersionless();
IIdType afterId3 = myObservationDao.create(obs, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
sleepUntilPingCount(socket, 2);

View File

@ -51,6 +51,7 @@ import ca.uhn.fhir.rest.server.FifoMemoryPagingProvider;
import ca.uhn.fhir.rest.server.RestfulServer;
import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException;
import ca.uhn.fhir.rest.server.interceptor.ResponseHighlighterInterceptor;
import ca.uhn.fhir.rest.server.servlet.ServletRequestDetails;
public class SystemProviderDstu2Test extends BaseJpaDstu2Test {
@ -190,18 +191,18 @@ public class SystemProviderDstu2Test extends BaseJpaDstu2Test {
Patient patient = new Patient();
patient.addName().addFamily("testSuggest");
IIdType ptId = myPatientDao.create(patient).getId().toUnqualifiedVersionless();
IIdType ptId = myPatientDao.create(patient, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
Observation obs = new Observation();
obs.getCode().setText("ZXCVBNM ASDFGHJKL QWERTYUIOPASDFGHJKL");
obs.getSubject().setReference(ptId);
IIdType obsId = myObservationDao.create(obs).getId().toUnqualifiedVersionless();
IIdType obsId = myObservationDao.create(obs, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
obs = new Observation();
obs.setId(obsId);
obs.getSubject().setReference(ptId);
obs.getCode().setText("ZXCVBNM ASDFGHJKL QWERTYUIOPASDFGHJKL");
myObservationDao.update(obs);
myObservationDao.update(obs, new ServletRequestDetails());
HttpGet get = new HttpGet(ourServerBase + "/$suggest-keywords?context=Patient/" + ptId.getIdPart() + "/$everything&searchParam=_content&text=zxc&_pretty=true&_format=xml");
CloseableHttpResponse http = ourHttpClient.execute(get);
@ -226,12 +227,12 @@ public class SystemProviderDstu2Test extends BaseJpaDstu2Test {
public void testSuggestKeywordsInvalid() throws Exception {
Patient patient = new Patient();
patient.addName().addFamily("testSuggest");
IIdType ptId = myPatientDao.create(patient).getId().toUnqualifiedVersionless();
IIdType ptId = myPatientDao.create(patient, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
Observation obs = new Observation();
obs.getSubject().setReference(ptId);
obs.getCode().setText("ZXCVBNM ASDFGHJKL QWERTYUIOPASDFGHJKL");
myObservationDao.create(obs);
myObservationDao.create(obs, new ServletRequestDetails());
HttpGet get = new HttpGet(ourServerBase + "/$suggest-keywords");
CloseableHttpResponse http = ourHttpClient.execute(get);
@ -379,7 +380,7 @@ public class SystemProviderDstu2Test extends BaseJpaDstu2Test {
for (int i = 0; i < 20; i ++) {
Patient p = new Patient();
p.addName().addFamily("PATIENT_" + i);
myPatientDao.create(p);
myPatientDao.create(p, new ServletRequestDetails());
}
Bundle req = new Bundle();
@ -403,7 +404,7 @@ public class SystemProviderDstu2Test extends BaseJpaDstu2Test {
for (int i = 0; i < 20; i ++) {
Patient p = new Patient();
p.addName().addFamily("PATIENT_" + i);
myPatientDao.create(p);
myPatientDao.create(p, new ServletRequestDetails());
}
Bundle req = new Bundle();

View File

@ -101,6 +101,7 @@ import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException;
import ca.uhn.fhir.rest.server.exceptions.PreconditionFailedException;
import ca.uhn.fhir.rest.server.exceptions.ResourceGoneException;
import ca.uhn.fhir.rest.server.exceptions.UnprocessableEntityException;
import ca.uhn.fhir.rest.server.servlet.ServletRequestDetails;
import ca.uhn.fhir.util.UrlUtil;
public class ResourceProviderDstu3Test extends BaseResourceProviderDstu3Test {
@ -125,19 +126,19 @@ public class ResourceProviderDstu3Test extends BaseResourceProviderDstu3Test {
public void testEverythingInstanceWithContentFilter() {
Patient pt1 = new Patient();
pt1.addName().addFamily("Everything").addGiven("Arthur");
IIdType ptId1 = myPatientDao.create(pt1).getId().toUnqualifiedVersionless();
IIdType ptId1 = myPatientDao.create(pt1, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
Patient pt2 = new Patient();
pt2.addName().addFamily("Everything").addGiven("Arthur");
IIdType ptId2 = myPatientDao.create(pt2).getId().toUnqualifiedVersionless();
IIdType ptId2 = myPatientDao.create(pt2, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
Device dev1 = new Device();
dev1.setManufacturer("Some Manufacturer");
IIdType devId1 = myDeviceDao.create(dev1).getId().toUnqualifiedVersionless();
IIdType devId1 = myDeviceDao.create(dev1, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
Device dev2 = new Device();
dev2.setManufacturer("Some Manufacturer 2");
myDeviceDao.create(dev2).getId().toUnqualifiedVersionless();
myDeviceDao.create(dev2, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
Observation obs1 = new Observation();
obs1.getText().setDivAsString("<div>OBSTEXT1</div>");
@ -145,19 +146,19 @@ public class ResourceProviderDstu3Test extends BaseResourceProviderDstu3Test {
obs1.getCode().addCoding().setCode("CODE1");
obs1.setValue(new StringType("obsvalue1"));
obs1.getDevice().setReferenceElement(devId1);
IIdType obsId1 = myObservationDao.create(obs1).getId().toUnqualifiedVersionless();
IIdType obsId1 = myObservationDao.create(obs1, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
Observation obs2 = new Observation();
obs2.getSubject().setReferenceElement(ptId1);
obs2.getCode().addCoding().setCode("CODE2");
obs2.setValue(new StringType("obsvalue2"));
IIdType obsId2 = myObservationDao.create(obs2).getId().toUnqualifiedVersionless();
IIdType obsId2 = myObservationDao.create(obs2, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
Observation obs3 = new Observation();
obs3.getSubject().setReferenceElement(ptId2);
obs3.getCode().addCoding().setCode("CODE3");
obs3.setValue(new StringType("obsvalue3"));
IIdType obsId3 = myObservationDao.create(obs3).getId().toUnqualifiedVersionless();
IIdType obsId3 = myObservationDao.create(obs3, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
List<IIdType> actual;
StringAndListParam param;
@ -569,12 +570,12 @@ public class ResourceProviderDstu3Test extends BaseResourceProviderDstu3Test {
Patient p = new Patient();
p.addIdentifier().setSystem("urn:system").setValue(methodName);
p.addName().addFamily("FAM1");
IIdType id1 = myPatientDao.create(p).getId().toUnqualifiedVersionless();
IIdType id1 = myPatientDao.create(p, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
p = new Patient();
p.addIdentifier().setSystem("urn:system").setValue(methodName);
p.addName().addFamily("FAM2");
IIdType id2 = myPatientDao.create(p).getId().toUnqualifiedVersionless();
IIdType id2 = myPatientDao.create(p, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
try {
//@formatter:off
@ -989,16 +990,16 @@ public class ResourceProviderDstu3Test extends BaseResourceProviderDstu3Test {
Medication med = new Medication();
med.getCode().setText(methodName);
IIdType medId = myMedicationDao.create(med).getId().toUnqualifiedVersionless();
IIdType medId = myMedicationDao.create(med, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
Patient pat = new Patient();
pat.addAddress().addLine(methodName);
IIdType patId = myPatientDao.create(pat).getId().toUnqualifiedVersionless();
IIdType patId = myPatientDao.create(pat, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
MedicationOrder mo = new MedicationOrder();
mo.getPatient().setReferenceElement(patId);
mo.setMedication(new Reference(medId));
IIdType moId = myMedicationOrderDao.create(mo).getId().toUnqualifiedVersionless();
IIdType moId = myMedicationOrderDao.create(mo, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
Parameters output = ourClient.operation().onInstance(patId).named("everything").withNoParameters(Parameters.class).execute();
Bundle b = (Bundle) output.getParameter().get(0).getResource();
@ -1523,13 +1524,13 @@ public class ResourceProviderDstu3Test extends BaseResourceProviderDstu3Test {
{
Patient patient = new Patient();
patient.addIdentifier().setSystem("urn:system").setValue("001");
id1 = myPatientDao.create(patient).getId().toUnqualifiedVersionless();
id1 = myPatientDao.create(patient, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
}
IIdType id2;
{
Patient patient = new Patient();
patient.addIdentifier().setSystem("urn:system").setValue("001");
id2 = myPatientDao.create(patient).getId().toUnqualifiedVersionless();
id2 = myPatientDao.create(patient, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
}
//@formatter:off
@ -1750,7 +1751,7 @@ public class ResourceProviderDstu3Test extends BaseResourceProviderDstu3Test {
public void testSearchWithInvalidSort() throws Exception {
Observation o = new Observation();
o.getCode().setText("testSearchWithInvalidSort");
myObservationDao.create(o);
myObservationDao.create(o, new ServletRequestDetails());
//@formatter:off
ourClient
.search()
@ -1766,7 +1767,7 @@ public class ResourceProviderDstu3Test extends BaseResourceProviderDstu3Test {
public void testSearchWithInvalidQuantityPrefix() throws Exception {
Observation o = new Observation();
o.getCode().setText("testSearchWithInvalidSort");
myObservationDao.create(o);
myObservationDao.create(o, new ServletRequestDetails());
try {
//@formatter:off
ourClient
@ -2036,7 +2037,7 @@ public class ResourceProviderDstu3Test extends BaseResourceProviderDstu3Test {
// Read back directly from the DAO
{
Organization returned = myOrganizationDao.read(orgId);
Organization returned = myOrganizationDao.read(orgId, new ServletRequestDetails());
String val = myFhirCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(returned);
ourLog.info(val);
assertThat(val, containsString("<name value=\"測試醫院\"/>"));

View File

@ -23,6 +23,7 @@ import org.springframework.transaction.annotation.Transactional;
import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException;
import ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException;
import ca.uhn.fhir.rest.server.servlet.ServletRequestDetails;
public class ResourceProviderDstu3ValueSetTest extends BaseResourceProviderDstu3Test {
@ -34,7 +35,7 @@ public class ResourceProviderDstu3ValueSetTest extends BaseResourceProviderDstu3
public void before02() throws IOException {
ValueSet upload = loadResourceFromClasspath(ValueSet.class, "/extensional-case-2.1.xml");
upload.setId("");
myExtensionalVsId = myValueSetDao.create(upload).getId().toUnqualifiedVersionless();
myExtensionalVsId = myValueSetDao.create(upload, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
}
@Test

View File

@ -7,18 +7,17 @@ import static org.junit.Assert.fail;
import org.hl7.fhir.dstu3.model.DecimalType;
import org.hl7.fhir.dstu3.model.Patient;
import org.hl7.fhir.dstu3.model.Questionnaire;
import org.hl7.fhir.dstu3.model.QuestionnaireResponse;
import org.hl7.fhir.dstu3.model.Questionnaire.QuestionnaireItemType;
import org.hl7.fhir.dstu3.model.QuestionnaireResponse;
import org.hl7.fhir.dstu3.model.QuestionnaireResponse.QuestionnaireResponseStatus;
import org.hl7.fhir.instance.model.api.IIdType;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.Test;
import ca.uhn.fhir.rest.api.MethodOutcome;
import ca.uhn.fhir.rest.server.exceptions.UnprocessableEntityException;
import ca.uhn.fhir.rest.server.interceptor.RequestValidatingInterceptor;
import ca.uhn.fhir.rest.server.interceptor.ResponseValidatingInterceptor;
import ca.uhn.fhir.rest.server.servlet.ServletRequestDetails;
import ca.uhn.fhir.validation.IValidatorModule;
import ca.uhn.fhir.validation.ResultSeverityEnum;
@ -52,11 +51,11 @@ public class ResourceProviderQuestionnaireResponseDstu3Test extends BaseResource
public void testCreateWithLocalReference() {
Patient pt1 = new Patient();
pt1.addName().addFamily("Everything").addGiven("Arthur");
IIdType ptId1 = myPatientDao.create(pt1).getId().toUnqualifiedVersionless();
IIdType ptId1 = myPatientDao.create(pt1, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
Questionnaire q1 = new Questionnaire();
q1.addItem().setLinkId("link1").setType(QuestionnaireItemType.STRING);
IIdType qId = myQuestionnaireDao.create(q1).getId().toUnqualifiedVersionless();
IIdType qId = myQuestionnaireDao.create(q1, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
QuestionnaireResponse qr1 = new QuestionnaireResponse();
qr1.getQuestionnaire().setReferenceElement(qId);
@ -74,11 +73,11 @@ public class ResourceProviderQuestionnaireResponseDstu3Test extends BaseResource
public void testCreateWithAbsoluteReference() {
Patient pt1 = new Patient();
pt1.addName().addFamily("Everything").addGiven("Arthur");
IIdType ptId1 = myPatientDao.create(pt1).getId().toUnqualifiedVersionless();
IIdType ptId1 = myPatientDao.create(pt1, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
Questionnaire q1 = new Questionnaire();
q1.addItem().setLinkId("link1").setType(QuestionnaireItemType.STRING);
IIdType qId = myQuestionnaireDao.create(q1).getId().toUnqualifiedVersionless();
IIdType qId = myQuestionnaireDao.create(q1, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
QuestionnaireResponse qr1 = new QuestionnaireResponse();
qr1.getQuestionnaire().setReferenceElement(qId.withServerBase("http://example.com", "Questionnaire"));

View File

@ -29,6 +29,7 @@ import ca.uhn.fhir.jpa.util.SubscriptionsRequireManualActivationInterceptorDstu3
import ca.uhn.fhir.model.primitive.IdDt;
import ca.uhn.fhir.rest.server.EncodingEnum;
import ca.uhn.fhir.rest.server.exceptions.UnprocessableEntityException;
import ca.uhn.fhir.rest.server.servlet.ServletRequestDetails;
public class SubscriptionsDstu3Test extends BaseResourceProviderDstu3Test {
@ -163,7 +164,7 @@ public class SubscriptionsDstu3Test extends BaseResourceProviderDstu3Test {
String methodName = "testSubscriptionDynamic";
Patient p = new Patient();
p.addName().addFamily(methodName);
IIdType pId = myPatientDao.create(p).getId().toUnqualifiedVersionless();
IIdType pId = myPatientDao.create(p, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
String criteria = "Observation?subject=Patient/" + pId.getIdPart();
DynamicEchoSocket socket = new DynamicEchoSocket(criteria, EncodingEnum.JSON);
@ -176,17 +177,17 @@ public class SubscriptionsDstu3Test extends BaseResourceProviderDstu3Test {
sleepUntilPingCount(socket, 1);
mySubscriptionDao.read(new IdDt("Subscription", socket.mySubsId));
mySubscriptionDao.read(new IdDt("Subscription", socket.mySubsId), new ServletRequestDetails());
Observation obs = new Observation();
obs.getSubject().setReferenceElement(pId);
obs.setStatus(ObservationStatus.FINAL);
IIdType afterId1 = myObservationDao.create(obs).getId().toUnqualifiedVersionless();
IIdType afterId1 = myObservationDao.create(obs, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
obs = new Observation();
obs.getSubject().setReferenceElement(pId);
obs.setStatus(ObservationStatus.FINAL);
IIdType afterId2 = myObservationDao.create(obs).getId().toUnqualifiedVersionless();
IIdType afterId2 = myObservationDao.create(obs, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
Thread.sleep(100);
@ -201,7 +202,7 @@ public class SubscriptionsDstu3Test extends BaseResourceProviderDstu3Test {
obs = new Observation();
obs.getSubject().setReferenceElement(pId);
obs.setStatus(ObservationStatus.FINAL);
IIdType afterId3 = myObservationDao.create(obs).getId().toUnqualifiedVersionless();
IIdType afterId3 = myObservationDao.create(obs, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
sleepUntilPingCount(socket, 4);
@ -228,7 +229,7 @@ public class SubscriptionsDstu3Test extends BaseResourceProviderDstu3Test {
String methodName = "testSubscriptionDynamic";
Patient p = new Patient();
p.addName().addFamily(methodName);
IIdType pId = myPatientDao.create(p).getId().toUnqualifiedVersionless();
IIdType pId = myPatientDao.create(p, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
String criteria = "Observation?subject=Patient/" + pId.getIdPart() + "&_format=xml";
DynamicEchoSocket socket = new DynamicEchoSocket(criteria, EncodingEnum.XML);
@ -241,18 +242,18 @@ public class SubscriptionsDstu3Test extends BaseResourceProviderDstu3Test {
sleepUntilPingCount(socket, 1);
mySubscriptionDao.read(new IdDt("Subscription", socket.mySubsId));
mySubscriptionDao.read(new IdDt("Subscription", socket.mySubsId), new ServletRequestDetails());
Observation obs = new Observation();
obs.getMeta().addProfile("http://foo");
obs.getSubject().setReferenceElement(pId);
obs.setStatus(ObservationStatus.FINAL);
IIdType afterId1 = myObservationDao.create(obs).getId().toUnqualifiedVersionless();
IIdType afterId1 = myObservationDao.create(obs, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
obs = new Observation();
obs.getSubject().setReferenceElement(pId);
obs.setStatus(ObservationStatus.FINAL);
IIdType afterId2 = myObservationDao.create(obs).getId().toUnqualifiedVersionless();
IIdType afterId2 = myObservationDao.create(obs, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
Thread.sleep(100);
@ -267,7 +268,7 @@ public class SubscriptionsDstu3Test extends BaseResourceProviderDstu3Test {
obs = new Observation();
obs.getSubject().setReferenceElement(pId);
obs.setStatus(ObservationStatus.FINAL);
IIdType afterId3 = myObservationDao.create(obs).getId().toUnqualifiedVersionless();
IIdType afterId3 = myObservationDao.create(obs, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
sleepUntilPingCount(socket, 4);
@ -293,26 +294,26 @@ public class SubscriptionsDstu3Test extends BaseResourceProviderDstu3Test {
String methodName = "testSubscriptionResourcesAppear";
Patient p = new Patient();
p.addName().addFamily(methodName);
IIdType pId = myPatientDao.create(p).getId().toUnqualifiedVersionless();
IIdType pId = myPatientDao.create(p, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
Subscription subs = new Subscription();
subs.getMeta().addProfile("http://foo");
subs.getChannel().setType(SubscriptionChannelType.WEBSOCKET);
subs.setCriteria("Observation?subject=Patient/" + pId.getIdPart());
subs.setStatus(SubscriptionStatus.ACTIVE);
String subsId = mySubscriptionDao.create(subs).getId().getIdPart();
String subsId = mySubscriptionDao.create(subs, new ServletRequestDetails()).getId().getIdPart();
Thread.sleep(100);
Observation obs = new Observation();
obs.getSubject().setReferenceElement(pId);
obs.setStatus(ObservationStatus.FINAL);
IIdType afterId1 = myObservationDao.create(obs).getId().toUnqualifiedVersionless();
IIdType afterId1 = myObservationDao.create(obs, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
obs = new Observation();
obs.getSubject().setReferenceElement(pId);
obs.setStatus(ObservationStatus.FINAL);
IIdType afterId2 = myObservationDao.create(obs).getId().toUnqualifiedVersionless();
IIdType afterId2 = myObservationDao.create(obs, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
Thread.sleep(100);
@ -330,7 +331,7 @@ public class SubscriptionsDstu3Test extends BaseResourceProviderDstu3Test {
obs = new Observation();
obs.getSubject().setReferenceElement(pId);
obs.setStatus(ObservationStatus.FINAL);
IIdType afterId3 = myObservationDao.create(obs).getId().toUnqualifiedVersionless();
IIdType afterId3 = myObservationDao.create(obs, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
sleepUntilPingCount(socket, 2);

View File

@ -27,7 +27,10 @@ import org.eclipse.jetty.servlet.ServletContextHandler;
import org.eclipse.jetty.servlet.ServletHolder;
import org.hl7.fhir.dstu3.hapi.validation.FhirInstanceValidator;
import org.hl7.fhir.dstu3.model.Bundle;
import org.hl7.fhir.dstu3.model.Bundle.BundleType;
import org.hl7.fhir.dstu3.model.Bundle.HTTPVerb;
import org.hl7.fhir.dstu3.model.DecimalType;
import org.hl7.fhir.dstu3.model.Enumerations.AdministrativeGender;
import org.hl7.fhir.dstu3.model.IdType;
import org.hl7.fhir.dstu3.model.Observation;
import org.hl7.fhir.dstu3.model.OperationDefinition;
@ -35,9 +38,6 @@ import org.hl7.fhir.dstu3.model.OperationOutcome;
import org.hl7.fhir.dstu3.model.Parameters;
import org.hl7.fhir.dstu3.model.Patient;
import org.hl7.fhir.dstu3.model.StringType;
import org.hl7.fhir.dstu3.model.Bundle.BundleType;
import org.hl7.fhir.dstu3.model.Bundle.HTTPVerb;
import org.hl7.fhir.dstu3.model.Enumerations.AdministrativeGender;
import org.hl7.fhir.instance.model.api.IIdType;
import org.junit.After;
import org.junit.AfterClass;
@ -61,6 +61,7 @@ import ca.uhn.fhir.rest.server.RestfulServer;
import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException;
import ca.uhn.fhir.rest.server.interceptor.RequestValidatingInterceptor;
import ca.uhn.fhir.rest.server.interceptor.ResponseHighlighterInterceptor;
import ca.uhn.fhir.rest.server.servlet.ServletRequestDetails;
import ca.uhn.fhir.validation.ResultSeverityEnum;
public class SystemProviderDstu3Test extends BaseJpaDstu3Test {
@ -258,18 +259,18 @@ public class SystemProviderDstu3Test extends BaseJpaDstu3Test {
Patient patient = new Patient();
patient.addName().addFamily("testSuggest");
IIdType ptId = myPatientDao.create(patient).getId().toUnqualifiedVersionless();
IIdType ptId = myPatientDao.create(patient, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
Observation obs = new Observation();
obs.getCode().setText("ZXCVBNM ASDFGHJKL QWERTYUIOPASDFGHJKL");
obs.getSubject().setReferenceElement(ptId);
IIdType obsId = myObservationDao.create(obs).getId().toUnqualifiedVersionless();
IIdType obsId = myObservationDao.create(obs, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
obs = new Observation();
obs.setId(obsId);
obs.getSubject().setReferenceElement(ptId);
obs.getCode().setText("ZXCVBNM ASDFGHJKL QWERTYUIOPASDFGHJKL");
myObservationDao.update(obs);
myObservationDao.update(obs, new ServletRequestDetails());
HttpGet get = new HttpGet(ourServerBase + "/$suggest-keywords?context=Patient/" + ptId.getIdPart() + "/$everything&searchParam=_content&text=zxc&_pretty=true&_format=xml");
CloseableHttpResponse http = ourHttpClient.execute(get);
@ -294,12 +295,12 @@ public class SystemProviderDstu3Test extends BaseJpaDstu3Test {
public void testSuggestKeywordsInvalid() throws Exception {
Patient patient = new Patient();
patient.addName().addFamily("testSuggest");
IIdType ptId = myPatientDao.create(patient).getId().toUnqualifiedVersionless();
IIdType ptId = myPatientDao.create(patient, new ServletRequestDetails()).getId().toUnqualifiedVersionless();
Observation obs = new Observation();
obs.getSubject().setReferenceElement(ptId);
obs.getCode().setText("ZXCVBNM ASDFGHJKL QWERTYUIOPASDFGHJKL");
myObservationDao.create(obs);
myObservationDao.create(obs, new ServletRequestDetails());
HttpGet get = new HttpGet(ourServerBase + "/$suggest-keywords");
CloseableHttpResponse http = ourHttpClient.execute(get);
@ -464,7 +465,7 @@ public class SystemProviderDstu3Test extends BaseJpaDstu3Test {
for (int i = 0; i < 20; i ++) {
Patient p = new Patient();
p.addName().addFamily("PATIENT_" + i);
myPatientDao.create(p);
myPatientDao.create(p, new ServletRequestDetails());
}
Bundle req = new Bundle();
@ -488,7 +489,7 @@ public class SystemProviderDstu3Test extends BaseJpaDstu3Test {
for (int i = 0; i < 20; i ++) {
Patient p = new Patient();
p.addName().addFamily("PATIENT_" + i);
myPatientDao.create(p);
myPatientDao.create(p, new ServletRequestDetails());
}
Bundle req = new Bundle();

View File

@ -0,0 +1,152 @@
package ca.uhn.fhir.jpa.term;
import static org.hamcrest.Matchers.containsInAnyOrder;
import static org.hamcrest.Matchers.containsString;
import static org.junit.Assert.*;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.hl7.fhir.dstu3.model.CodeSystem;
import org.hl7.fhir.dstu3.model.CodeSystem.CodeSystemContentMode;
import org.hl7.fhir.instance.model.api.IIdType;
import org.junit.Test;
import ca.uhn.fhir.jpa.dao.dstu3.BaseJpaDstu3Test;
import ca.uhn.fhir.jpa.entity.ResourceTable;
import ca.uhn.fhir.jpa.entity.TermCodeSystemVersion;
import ca.uhn.fhir.jpa.entity.TermConcept;
import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException;
import ca.uhn.fhir.rest.server.servlet.ServletRequestDetails;
public class TerminologySvcImplTest extends BaseJpaDstu3Test {
@Test
public void testStoreCodeSystemInvalidCyclicLoop() {
CodeSystem codeSystem = new CodeSystem();
codeSystem.setUrl("http://example.com/my_code_system");
codeSystem.setContent(CodeSystemContentMode.NOTPRESENT);
IIdType id = myCodeSystemDao.create(codeSystem, new ServletRequestDetails()).getId().toUnqualified();
ResourceTable table = myResourceTableDao.findOne(id.getIdPartAsLong());
TermCodeSystemVersion cs = new TermCodeSystemVersion();
cs.setResource(table);
cs.setResourceVersionId(table.getVersion());
TermConcept parent = new TermConcept();
parent.setCodeSystem(cs);
parent.setCode("parent");
cs.getConcepts().add(parent);
TermConcept child = new TermConcept();
child.setCodeSystem(cs);
child.setCode("child");
parent.addChild(child);
child.addChild(parent);
try {
myTermSvc.storeNewCodeSystemVersion("http://foo", cs);
fail();
} catch (InvalidRequestException e) {
assertEquals("CodeSystem contains circular reference around code parent", e.getMessage());
}
}
@Test
public void testFetchIsA() {
CodeSystem codeSystem = new CodeSystem();
codeSystem.setUrl("http://example.com/my_code_system");
codeSystem.setContent(CodeSystemContentMode.NOTPRESENT);
IIdType id = myCodeSystemDao.create(codeSystem, new ServletRequestDetails()).getId().toUnqualified();
ResourceTable table = myResourceTableDao.findOne(id.getIdPartAsLong());
TermCodeSystemVersion cs = new TermCodeSystemVersion();
cs.setResource(table);
cs.setResourceVersionId(table.getVersion());
TermConcept parentA = new TermConcept(cs, "ParentA");
cs.getConcepts().add(parentA);
TermConcept childAA = new TermConcept(cs, "childAA");
parentA.addChild(childAA);
TermConcept childAAA = new TermConcept(cs, "childAAA");
childAA.addChild(childAAA);
TermConcept childAAB = new TermConcept(cs, "childAAB");
childAA.addChild(childAAB);
TermConcept childAB = new TermConcept(cs, "childAB");
parentA.addChild(childAB);
TermConcept parentB = new TermConcept(cs, "ParentB");
cs.getConcepts().add(parentB);
myTermSvc.storeNewCodeSystemVersion("http://foo", cs);
Set<TermConcept> concepts;
Set<String> codes;
concepts = myTermSvc.findCodesBelow(id.getIdPartAsLong(), id.getVersionIdPartAsLong(), "ParentA");
codes = toCodes(concepts);
assertThat(codes, containsInAnyOrder("ParentA", "childAA", "childAAA", "childAAB", "childAB"));
concepts = myTermSvc.findCodesBelow(id.getIdPartAsLong(), id.getVersionIdPartAsLong(), "childAA");
codes = toCodes(concepts);
assertThat(codes, containsInAnyOrder("childAA", "childAAA", "childAAB"));
}
@Test
public void testCreateDuplicateCodeSystemUri() {
CodeSystem codeSystem = new CodeSystem();
codeSystem.setUrl("http://example.com/my_code_system");
codeSystem.setContent(CodeSystemContentMode.NOTPRESENT);
IIdType id = myCodeSystemDao.create(codeSystem, new ServletRequestDetails()).getId().toUnqualified();
ResourceTable table = myResourceTableDao.findOne(id.getIdPartAsLong());
TermCodeSystemVersion cs = new TermCodeSystemVersion();
cs.setResource(table);
cs.setResourceVersionId(table.getVersion());
myTermSvc.storeNewCodeSystemVersion("http://example.com/my_code_system", cs);
// Update
cs = new TermCodeSystemVersion();
TermConcept parentA = new TermConcept(cs, "ParentA");
cs.getConcepts().add(parentA);
id = myCodeSystemDao.update(codeSystem, new ServletRequestDetails()).getId().toUnqualified();
table = myResourceTableDao.findOne(id.getIdPartAsLong());
cs.setResource(table);
cs.setResourceVersionId(table.getVersion());
myTermSvc.storeNewCodeSystemVersion("http://example.com/my_code_system", cs);
// Try to update to a different resource
codeSystem = new CodeSystem();
codeSystem.setUrl("http://example.com/my_code_system");
codeSystem.setContent(CodeSystemContentMode.NOTPRESENT);
id = myCodeSystemDao.create(codeSystem, new ServletRequestDetails()).getId().toUnqualified();
table = myResourceTableDao.findOne(id.getIdPartAsLong());
cs.setResource(table);
cs.setResourceVersionId(table.getVersion());
try {
myTermSvc.storeNewCodeSystemVersion("http://example.com/my_code_system", cs);
fail();
} catch (InvalidRequestException e) {
assertThat(e.getMessage(), containsString("Can not create multiple code systems with URI \"http://example.com/my_code_system\", already have one with resource ID: CodeSystem/"));
}
}
private Set<String> toCodes(Set<TermConcept> theConcepts) {
HashSet<String> retVal = new HashSet<String>();
for (TermConcept next : theConcepts) {
retVal.add(next.getCode());
}
return retVal;
}
}

View File

@ -45,9 +45,6 @@ import ca.uhn.fhir.rest.server.interceptor.IServerInterceptor;
import ca.uhn.fhir.rest.server.interceptor.IServerInterceptor.ActionRequestDetails;
import ca.uhn.fhir.util.PortUtil;
/**
* Created by dsotnikov on 2/25/2014.
*/
public class InterceptorTest {
private static CloseableHttpClient ourClient;

View File

@ -0,0 +1,277 @@
package ca.uhn.fhir.rest.server.interceptor;
import static org.hamcrest.Matchers.containsInAnyOrder;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertThat;
import static org.mockito.Mockito.mock;
import java.lang.reflect.Method;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import org.apache.commons.io.IOUtils;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClientBuilder;
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.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;
import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.model.dstu2.composite.HumanNameDt;
import ca.uhn.fhir.model.dstu2.composite.IdentifierDt;
import ca.uhn.fhir.model.dstu2.resource.Bundle;
import ca.uhn.fhir.model.dstu2.resource.Patient;
import ca.uhn.fhir.model.dstu2.valueset.AdministrativeGenderEnum;
import ca.uhn.fhir.model.dstu2.valueset.IdentifierUseEnum;
import ca.uhn.fhir.model.primitive.DateDt;
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.Operation;
import ca.uhn.fhir.rest.annotation.OperationParam;
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.method.RequestDetails;
import ca.uhn.fhir.rest.server.IResourceProvider;
import ca.uhn.fhir.rest.server.RestfulServer;
import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException;
import ca.uhn.fhir.rest.server.interceptor.IServerInterceptor.ActionRequestDetails;
import ca.uhn.fhir.util.PortUtil;
public class InterceptorUserDataMapDstu2Test {
private static CloseableHttpClient ourClient;
private static final FhirContext ourCtx = FhirContext.forDstu2();
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(InterceptorUserDataMapDstu2Test.class);
private static int ourPort;
private static Server ourServer;
private static RestfulServer servlet;
private IServerInterceptor myInterceptor;
private final Object myKey = "KEY";
private Map<Object, Object> myMap;
private Set<String> myMapCheckMethods;
private final Object myValue = "VALUE";
@Before
public void before() {
myInterceptor = mock(IServerInterceptor.class);
servlet.setInterceptors(Collections.singletonList(myInterceptor));
}
@Before
public void beforePurgeMap() {
myMap = null;
myMapCheckMethods= new HashSet<String>();
}
@Test
public void testException() throws Exception {
IServerInterceptor interceptor = mock(IServerInterceptor.class, new MyInterceptorAnswer());
servlet.setInterceptors(Collections.singletonList((IServerInterceptor) interceptor));
HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient?_id=foo");
HttpResponse status = ourClient.execute(httpGet);
IOUtils.closeQuietly(status.getEntity().getContent());
ourLog.info(myMapCheckMethods.toString());
assertThat(myMapCheckMethods, containsInAnyOrder("incomingRequestPreHandled", "handleException", "incomingRequestPostProcessed", "preProcessOutgoingException"));
}
@Test
public void testRead() throws Exception {
IServerInterceptor interceptor = mock(IServerInterceptor.class, new MyInterceptorAnswer());
servlet.setInterceptors(Collections.singletonList((IServerInterceptor) interceptor));
HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient/1");
HttpResponse status = ourClient.execute(httpGet);
IOUtils.closeQuietly(status.getEntity().getContent());
ourLog.info(myMapCheckMethods.toString());
assertThat(myMapCheckMethods, containsInAnyOrder("incomingRequestPreHandled", "incomingRequestPostProcessed", "outgoingResponse"));
}
protected void updateMapUsing(Map<Object, Object> theUserData, Method theMethod) {
assertNotNull(theUserData);
if (myMap == null) {
myMap = theUserData;
myMap.put(myKey, myValue);
} else {
assertSame(myMap, theUserData);
assertEquals(myValue, myMap.get(myKey));
}
myMapCheckMethods.add(theMethod.getName());
}
@AfterClass
public static void afterClass() throws Exception {
ourServer.stop();
}
@BeforeClass
public static void beforeClass() throws Exception {
ourPort = PortUtil.findFreePort();
ourServer = new Server(ourPort);
ServletHandler proxyHandler = new ServletHandler();
servlet = new RestfulServer(ourCtx);
servlet.setResourceProviders(new DummyPatientResourceProvider());
servlet.setPlainProviders(new PlainProvider());
ServletHolder servletHolder = new ServletHolder(servlet);
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();
}
public static class DummyPatientResourceProvider implements IResourceProvider {
private Patient createPatient1() {
Patient patient = new Patient();
patient.addIdentifier();
patient.getIdentifier().get(0).setUse(IdentifierUseEnum.OFFICIAL);
patient.getIdentifier().get(0).setSystem(new UriDt("urn:hapitest:mrns"));
patient.getIdentifier().get(0).setValue("00001");
patient.addName();
patient.getName().get(0).addFamily("Test");
patient.getName().get(0).addGiven("PatientOne");
patient.setGender(AdministrativeGenderEnum.MALE);
patient.getId().setValue("1");
return patient;
}
public Map<String, Patient> getIdToPatient() {
Map<String, Patient> idToPatient = new HashMap<String, Patient>();
{
Patient patient = createPatient1();
idToPatient.put("1", patient);
}
{
Patient patient = new Patient();
patient.getIdentifier().add(new IdentifierDt());
patient.getIdentifier().get(0).setUse(IdentifierUseEnum.OFFICIAL);
patient.getIdentifier().get(0).setSystem(new UriDt("urn:hapitest:mrns"));
patient.getIdentifier().get(0).setValue("00002");
patient.getName().add(new HumanNameDt());
patient.getName().get(0).addFamily("Test");
patient.getName().get(0).addGiven("PatientTwo");
patient.setGender(AdministrativeGenderEnum.FEMALE);
patient.getId().setValue("2");
idToPatient.put("2", patient);
}
return idToPatient;
}
/**
* Retrieve the resource by its identifier
*
* @param theId
* The resource identity
* @return The resource
*/
@Read()
public Patient getResourceById(@IdParam IdDt theId) {
if (theId.getIdPart().equals("EX")) {
throw new InvalidRequestException("FOO");
}
String key = theId.getIdPart();
Patient retVal = getIdToPatient().get(key);
return retVal;
}
/**
* Retrieve the resource by its identifier
*
* @param theId
* The resource identity
* @return The resource
*/
@Search()
public List<Patient> getResourceById(@RequiredParam(name = "_id") String theId) {
throw new InvalidRequestException("FOO");
}
@Override
public Class<Patient> getResourceType() {
return Patient.class;
}
@Operation(name = "$everything", idempotent = true)
public Bundle patientTypeOperation(@OperationParam(name = "start") DateDt theStart, @OperationParam(name = "end") DateDt theEnd) {
Bundle retVal = new Bundle();
// Populate bundle with matching resources
return retVal;
}
@Operation(name = "$everything", idempotent = true)
public Bundle patientTypeOperation(@IdParam IdDt theId, @OperationParam(name = "start") DateDt theStart, @OperationParam(name = "end") DateDt theEnd) {
Bundle retVal = new Bundle();
// Populate bundle with matching resources
return retVal;
}
}
private final class MyInterceptorAnswer implements Answer<Object> {
@Override
public Object answer(InvocationOnMock theInvocation) throws Throwable {
int index = 0;
for (Class<?> next : theInvocation.getMethod().getParameterTypes()) {
if (RequestDetails.class.isAssignableFrom(next)) {
updateMapUsing(((RequestDetails)theInvocation.getArguments()[index]).getUserData(), theInvocation.getMethod());
}
if (ActionRequestDetails.class.isAssignableFrom(next)) {
updateMapUsing(((ActionRequestDetails)theInvocation.getArguments()[index]).getUserData(), theInvocation.getMethod());
}
index++;
}
if (theInvocation.getMethod().getReturnType().equals(boolean.class)) {
return true;
}
return null;
}
}
public static class PlainProvider {
@Operation(name = "$everything", idempotent = true)
public Bundle patientTypeOperation(@OperationParam(name = "start") DateDt theStart, @OperationParam(name = "end") DateDt theEnd) {
Bundle retVal = new Bundle();
// Populate bundle with matching resources
return retVal;
}
}
}

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