Clean up testpage-overlay to work with DSTU2.1

This commit is contained in:
jamesagnew 2016-01-06 08:49:24 -05:00
parent 2e434650ea
commit 56620eebfb
7 changed files with 109 additions and 23 deletions

View File

@ -37,18 +37,14 @@ import ca.uhn.fhir.util.UrlUtil;
public class RuntimeResourceDefinition extends BaseRuntimeElementCompositeDefinition<IBaseResource> {
private RuntimeResourceDefinition myBaseDefinition;
private FhirContext myContext;
private String myId;
private Map<String, RuntimeSearchParam> myNameToSearchParam = new LinkedHashMap<String, RuntimeSearchParam>();
private IBaseResource myProfileDef;
private String myResourceProfile;
private List<RuntimeSearchParam> mySearchParams;
private FhirContext myContext;
private String myId;
private final FhirVersionEnum myStructureVersion;
public FhirVersionEnum getStructureVersion() {
return myStructureVersion;
}
public RuntimeResourceDefinition(FhirContext theContext, String theResourceName, Class<? extends IBaseResource> theClass, ResourceDef theResourceAnnotation, boolean theStandardType) {
super(theResourceName, theClass, theStandardType);
myContext= theContext;
@ -65,10 +61,6 @@ public class RuntimeResourceDefinition extends BaseRuntimeElementCompositeDefini
}
public String getId() {
return myId;
}
public void addSearchParam(RuntimeSearchParam theParam) {
myNameToSearchParam.put(theParam.getName(), theParam);
}
@ -91,6 +83,21 @@ public class RuntimeResourceDefinition extends BaseRuntimeElementCompositeDefini
return ChildTypeEnum.RESOURCE;
}
public String getId() {
return myId;
}
/**
* Express {@link #getImplementingClass()} as theClass (to prevent casting warnings)
*/
@SuppressWarnings("unchecked")
public <T> Class<T> getImplementingClass(Class<T> theClass) {
if (!theClass.isAssignableFrom(getImplementingClass())) {
throw new ConfigurationException("Unable to convert " + getImplementingClass() + " to " + theClass);
}
return (Class<T>) getImplementingClass();
}
@Deprecated
public String getResourceProfile() {
return myResourceProfile;
@ -127,6 +134,14 @@ public class RuntimeResourceDefinition extends BaseRuntimeElementCompositeDefini
return mySearchParams;
}
public FhirVersionEnum getStructureVersion() {
return myStructureVersion;
}
public boolean isBundle() {
return "Bundle".equals(getName());
}
public boolean isStandardProfile() {
return myResourceProfile.startsWith("http://hl7.org/fhir/profiles");
}
@ -178,8 +193,4 @@ public class RuntimeResourceDefinition extends BaseRuntimeElementCompositeDefini
return retVal;
}
public boolean isBundle() {
return "Bundle".equals(getName());
}
}

View File

@ -1045,7 +1045,7 @@ public class GenericClient extends BaseClient implements IGenericClient {
private Integer myCount;
private IIdType myId;
private Class<? extends IBaseBundle> myReturnType;
private InstantDt mySince;
private IPrimitiveType mySince;
private Class<? extends IBaseResource> myType;
@SuppressWarnings("unchecked")
@ -1126,7 +1126,7 @@ public class GenericClient extends BaseClient implements IGenericClient {
}
@Override
public IHistoryTyped since(InstantDt theCutoff) {
public IHistoryTyped since(IPrimitiveType theCutoff) {
mySince = theCutoff;
return this;
}

View File

@ -22,7 +22,7 @@ package ca.uhn.fhir.rest.gclient;
import java.util.Date;
import ca.uhn.fhir.model.primitive.InstantDt;
import org.hl7.fhir.instance.model.api.IPrimitiveType;
public interface IHistoryTyped<T> extends IClientExecutable<IHistoryTyped<T>, T> {
@ -33,8 +33,12 @@ public interface IHistoryTyped<T> extends IClientExecutable<IHistoryTyped<T>, T>
/**
* Request that the server return only resource versions that were created at or after the given time (inclusive)
* <p>
* Parameter theCutoff can be any priitive type which accepts a date, such as
* a <code>DateTimeDt</code>, <code>InstantType</code>, etc.
* </p>
*/
IHistoryTyped<T> since(InstantDt theCutoff);
IHistoryTyped<T> since(IPrimitiveType<Date> theCutoff);
/**
* Request that the server return only up to <code>theCount</code> number of resources

View File

@ -24,15 +24,16 @@ import static org.apache.commons.lang3.StringUtils.isNotBlank;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.Date;
import java.util.List;
import org.apache.commons.lang3.StringUtils;
import org.hl7.fhir.instance.model.api.IBaseResource;
import org.hl7.fhir.instance.model.api.IPrimitiveType;
import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.model.api.IResource;
import ca.uhn.fhir.model.api.ResourceMetadataKeyEnum;
import ca.uhn.fhir.model.primitive.BaseDateTimeDt;
import ca.uhn.fhir.model.primitive.IdDt;
import ca.uhn.fhir.model.primitive.InstantDt;
import ca.uhn.fhir.model.valueset.BundleTypeEnum;
@ -154,7 +155,7 @@ public class HistoryMethodBinding extends BaseResourceReturningMethodBinding {
}
@Override
public IBundleProvider invokeServer(IRestfulServer theServer, RequestDetails theRequest, Object[] theMethodParams) throws InvalidRequestException, InternalErrorException {
public IBundleProvider invokeServer(IRestfulServer<?> theServer, RequestDetails theRequest, Object[] theMethodParams) throws InvalidRequestException, InternalErrorException {
if (myIdParamIndex != null) {
theMethodParams[myIdParamIndex] = theRequest.getId();
}
@ -205,7 +206,7 @@ public class HistoryMethodBinding extends BaseResourceReturningMethodBinding {
};
}
public static HttpGetClientInvocation createHistoryInvocation(String theResourceName, String theId, BaseDateTimeDt theSince, Integer theLimit) {
public static HttpGetClientInvocation createHistoryInvocation(String theResourceName, String theId, IPrimitiveType<Date> theSince, Integer theLimit) {
StringBuilder b = new StringBuilder();
if (theResourceName != null) {
b.append(theResourceName);

View File

@ -31,6 +31,11 @@
<artifactId>hapi-fhir-structures-dstu2</artifactId>
<version>1.4-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>ca.uhn.hapi.fhir</groupId>
<artifactId>hapi-fhir-structures-dstu2.1</artifactId>
<version>1.4-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>ca.uhn.hapi.fhir</groupId>
<artifactId>hapi-fhir-structures-hl7org-dstu2</artifactId>
@ -41,6 +46,11 @@
<artifactId>hapi-fhir-validation-resources-dstu2</artifactId>
<version>1.4-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>ca.uhn.hapi.fhir</groupId>
<artifactId>hapi-fhir-validation-resources-dstu2.1</artifactId>
<version>1.4-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>ca.uhn.hapi.fhir</groupId>
<artifactId>hapi-fhir-jpaserver-base</artifactId>
@ -227,7 +237,6 @@
<plugin>
<groupId>org.eluder.coveralls</groupId>
<artifactId>coveralls-maven-plugin</artifactId>
<version>3.1.0</version>
<configuration>
<coberturaReports>
<coberturaReport>
@ -275,6 +284,7 @@
<source>../hapi-fhir-structures-dstu/src/test/java</source>
<source>../hapi-fhir-structures-dstu2/src/test/java</source>
<source>../hapi-fhir-structures-hl7org-dstu2/src/test/java</source>
<source>../hapi-fhir-structures-dstu2.1/src/test/java</source>
<source>../hapi-fhir-jpaserver-base/src/test/java</source>
</sources>
</configuration>
@ -342,6 +352,9 @@
<testResource>
<directory>../hapi-fhir-structures-hl7org-dstu2/src/test/resources</directory>
</testResource>
<testResource>
<directory>../hapi-fhir-structures-dstu2.1/src/test/resources</directory>
</testResource>
</testResources>
</build>
<reporting>

View File

@ -0,0 +1,23 @@
package ca.uhn.fhir.context;
import static org.junit.Assert.*;
import org.hl7.fhir.dstu21.model.Bundle;
import org.hl7.fhir.dstu21.model.Patient;
import org.junit.Test;
public class RuntimeResourceDefinitionTest {
private FhirContext ourCtx = FhirContext.forDstu2_1();
@Test
public void testAsClass() {
assertEquals(Bundle.class, ourCtx.getResourceDefinition("Bundle").getImplementingClass(Bundle.class));
}
@Test(expected=ConfigurationException.class)
public void testAsClassWrong() {
ourCtx.getResourceDefinition("Bundle").getImplementingClass(Patient.class);
}
}

View File

@ -22,11 +22,13 @@ import org.hl7.fhir.dstu21.model.Conformance.ConformanceRestComponent;
import org.hl7.fhir.dstu21.model.Conformance.ConformanceRestResourceComponent;
import org.hl7.fhir.dstu21.model.Conformance.ConformanceRestResourceSearchParamComponent;
import org.hl7.fhir.dstu21.model.StringType;
import org.hl7.fhir.instance.model.api.IBaseBundle;
import org.hl7.fhir.instance.model.api.IBaseResource;
import org.springframework.ui.ModelMap;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.RequestMapping;
import ca.uhn.fhir.context.FhirVersionEnum;
import ca.uhn.fhir.context.RuntimeResourceDefinition;
import ca.uhn.fhir.model.api.Bundle;
import ca.uhn.fhir.model.api.ExtensionDt;
@ -45,6 +47,9 @@ import ca.uhn.fhir.model.primitive.StringDt;
import ca.uhn.fhir.parser.DataFormatException;
import ca.uhn.fhir.rest.client.GenericClient;
import ca.uhn.fhir.rest.gclient.ICreateTyped;
import ca.uhn.fhir.rest.gclient.IHistory;
import ca.uhn.fhir.rest.gclient.IHistoryTyped;
import ca.uhn.fhir.rest.gclient.IHistoryUntyped;
import ca.uhn.fhir.rest.gclient.IQuery;
import ca.uhn.fhir.rest.gclient.IUntypedQuery;
import ca.uhn.fhir.rest.gclient.NumberClientParam.IMatches;
@ -454,6 +459,10 @@ public class Controller extends BaseController {
}
}
if (client.getFhirContext().getVersion().getVersion() != FhirVersionEnum.DSTU1) {
query.returnBundle(client.getFhirContext().getResourceDefinition("Bundle").getImplementingClass());
}
long start = System.currentTimeMillis();
ResultType returnsResource;
try {
@ -646,7 +655,32 @@ public class Controller extends BaseController {
long start = System.currentTimeMillis();
try {
ourLog.info(logPrefix(theModel) + "Retrieving history for type {} ID {} since {}", new Object[] { type, id, since });
client.history(type, id, since, limit);
IHistory hist0 = client.history();
IHistoryUntyped hist1;
if (isNotBlank(id)) {
hist1 = hist0.onInstance(new IdDt(theRequest.getResource(), id));
} else if (type != null) {
hist1 = hist0.onType(type);
} else {
hist1 = hist0.onServer();
}
IHistoryTyped<?> hist2;
if (client.getFhirContext().getVersion().getVersion() == FhirVersionEnum.DSTU1) {
hist2 = hist1.andReturnDstu1Bundle();
} else {
hist2 = hist1.andReturnBundle(client.getFhirContext().getResourceDefinition("Bundle").getImplementingClass(IBaseBundle.class));
}
if (since != null) {
hist2.since(since);
}
if (limit != null) {
hist2.count(limit);
}
hist2.execute();
} catch (Exception e) {
returnsResource = handleClientException(client, e, theModel);
}