Add tests
This commit is contained in:
parent
e2934d2654
commit
4ad5033b13
|
@ -0,0 +1,60 @@
|
|||
package example;
|
||||
|
||||
import ca.uhn.fhir.context.FhirContext;
|
||||
import ca.uhn.fhir.model.dstu2.resource.Bundle;
|
||||
import ca.uhn.fhir.model.dstu2.valueset.BundleTypeEnum;
|
||||
import ca.uhn.fhir.model.dstu2.valueset.HTTPVerbEnum;
|
||||
import ca.uhn.fhir.rest.client.api.IGenericClient;
|
||||
import ca.uhn.fhir.util.ResourceReferenceInfo;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.hl7.fhir.instance.model.api.IBaseResource;
|
||||
import org.hl7.fhir.instance.model.api.IIdType;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileReader;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
public class Uploader {
|
||||
private static final Logger ourLog = LoggerFactory.getLogger(Uploader.class);
|
||||
public static void main(String[] theArgs) throws FileNotFoundException {
|
||||
|
||||
FhirContext ctx = FhirContext.forDstu2();
|
||||
IGenericClient client = ctx.newRestfulGenericClient("http://localhost:8080/baseDstu2/");
|
||||
|
||||
Collection<File> files = FileUtils.listFiles(new File("/home/james/tmp/download"), new String[]{"json"}, false);
|
||||
for (File nextFile : files) {
|
||||
Bundle bundle = (Bundle) ctx.newJsonParser().parseResource(new FileReader(nextFile));
|
||||
for (Bundle.Entry nextEntry : bundle.getEntry()) {
|
||||
IBaseResource nextResource = nextEntry.getResource();
|
||||
IIdType oldId = nextResource.getIdElement();
|
||||
String newId = oldId.getResourceType() + "/A" + oldId.getIdPart();
|
||||
ourLog.info("Changing resource ID from {} to {}", oldId.toUnqualifiedVersionless(), newId);
|
||||
nextResource.setId(newId);
|
||||
|
||||
List<ResourceReferenceInfo> refs = ctx.newTerser().getAllResourceReferences(nextResource);
|
||||
for (ResourceReferenceInfo nextRefInfo : refs) {
|
||||
IIdType nextRef = nextRefInfo.getResourceReference().getReferenceElement();
|
||||
String newRef = nextRef.getResourceType() + "/A" + nextRef.getIdPart();
|
||||
ourLog.info("Changing ref from {} to {}", nextRef.getValue(), newRef);
|
||||
nextRefInfo.getResourceReference().setReference(newRef);
|
||||
}
|
||||
|
||||
nextEntry.getRequest().setMethod(HTTPVerbEnum.PUT);
|
||||
nextEntry.getRequest().setUrl(newId);
|
||||
nextEntry.setFullUrl(newId);
|
||||
|
||||
}
|
||||
|
||||
bundle.setType(BundleTypeEnum.TRANSACTION);
|
||||
ourLog.info("Uploading transaction for {}", nextFile.getName());
|
||||
client.transaction().withBundle(bundle).execute();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
File diff suppressed because it is too large
Load Diff
|
@ -1621,6 +1621,27 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test {
|
|||
assertThat(ids, empty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetResourceCountsOperation() throws Exception {
|
||||
String methodName = "testMetaOperations";
|
||||
|
||||
Patient pt = new Patient();
|
||||
pt.addName().setFamily(methodName);
|
||||
myClient.create().resource(pt).execute().getId().toUnqualifiedVersionless();
|
||||
|
||||
HttpGet get = new HttpGet(ourServerBase + "/$get-resource-counts");
|
||||
CloseableHttpResponse response = ourHttpClient.execute(get);
|
||||
try {
|
||||
assertEquals(200, response.getStatusLine().getStatusCode());
|
||||
String output = IOUtils.toString(response.getEntity().getContent(), StandardCharsets.UTF_8);
|
||||
IOUtils.closeQuietly(response.getEntity().getContent());
|
||||
ourLog.info(output);
|
||||
assertThat(output, containsString("<parameter><name value=\"Patient\"/><valueInteger value=\""));
|
||||
} finally {
|
||||
response.close();
|
||||
}
|
||||
}
|
||||
|
||||
// private void delete(String theResourceType, String theParamName, String theParamValue) {
|
||||
// Bundle resources;
|
||||
// do {
|
||||
|
@ -1646,27 +1667,6 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test {
|
|||
// }
|
||||
// }
|
||||
|
||||
@Test
|
||||
public void testGetResourceCountsOperation() throws Exception {
|
||||
String methodName = "testMetaOperations";
|
||||
|
||||
Patient pt = new Patient();
|
||||
pt.addName().setFamily(methodName);
|
||||
myClient.create().resource(pt).execute().getId().toUnqualifiedVersionless();
|
||||
|
||||
HttpGet get = new HttpGet(ourServerBase + "/$get-resource-counts");
|
||||
CloseableHttpResponse response = ourHttpClient.execute(get);
|
||||
try {
|
||||
assertEquals(200, response.getStatusLine().getStatusCode());
|
||||
String output = IOUtils.toString(response.getEntity().getContent(), StandardCharsets.UTF_8);
|
||||
IOUtils.closeQuietly(response.getEntity().getContent());
|
||||
ourLog.info(output);
|
||||
assertThat(output, containsString("<parameter><name value=\"Patient\"/><valueInteger value=\""));
|
||||
} finally {
|
||||
response.close();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHasParameter() throws Exception {
|
||||
IIdType pid0;
|
||||
|
@ -3645,6 +3645,32 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test {
|
|||
testSearchReturnsResults("/Observation?code%3Atext=THIS_IS_THE_disp");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSmallResultIncludes() {
|
||||
Patient p = new Patient();
|
||||
p.setId("p");
|
||||
p.setActive(true);
|
||||
myClient.update().resource(p).execute();
|
||||
|
||||
CarePlan cp = new CarePlan();
|
||||
cp.setId("cp");
|
||||
cp.getSubject().setResource(p);
|
||||
cp.addActivity().getDetail().getCode().addCoding().setSystem("FOO").setCode("BAR");
|
||||
myClient.update().resource(cp).execute();
|
||||
|
||||
Bundle b = myClient
|
||||
.search()
|
||||
.forResource(CarePlan.class)
|
||||
.where(CarePlan.ACTIVITY_CODE.exactly().systemAndCode("FOO", "BAR"))
|
||||
.sort().ascending(CarePlan.SP_ACTIVITY_DATE)
|
||||
.include(CarePlan.INCLUDE_SUBJECT)
|
||||
.returnBundle(Bundle.class)
|
||||
.execute();
|
||||
|
||||
assertEquals(2, b.getEntry().size());
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* See #198
|
||||
*/
|
||||
|
|
|
@ -18,10 +18,9 @@ import ca.uhn.fhir.rest.client.interceptor.LoggingInterceptor;
|
|||
|
||||
public class ExampleServerIT {
|
||||
|
||||
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(ExampleServerIT.class);
|
||||
private static IGenericClient ourClient;
|
||||
private static FhirContext ourCtx = FhirContext.forDstu3();
|
||||
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(ExampleServerIT.class);
|
||||
|
||||
private static int ourPort;
|
||||
|
||||
private static Server ourServer;
|
||||
|
@ -57,7 +56,9 @@ public class ExampleServerIT {
|
|||
|
||||
ourLog.info("Project base path is: {}", path);
|
||||
|
||||
ourPort = RandomServerPortProvider.findFreePort();
|
||||
if (ourPort == 0) {
|
||||
ourPort = RandomServerPortProvider.findFreePort();
|
||||
}
|
||||
ourServer = new Server(ourPort);
|
||||
|
||||
WebAppContext webAppContext = new WebAppContext();
|
||||
|
@ -77,4 +78,10 @@ public class ExampleServerIT {
|
|||
|
||||
}
|
||||
|
||||
public static void main(String[] theArgs) throws Exception {
|
||||
ourPort = 8080;
|
||||
beforeClass();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue