Adding Integration Tests for Measure Reports. There's still more work to do to get them to Pass...
This commit is contained in:
@@ -9,13 +9,10 @@ import ca.uhn.fhir.rest.api.MethodOutcome;
|
||||
import ca.uhn.fhir.rest.client.api.IGenericClient;
|
||||
import ca.uhn.fhir.rest.client.api.ServerValidationModeEnum;
|
||||
import ca.uhn.fhir.rest.client.interceptor.LoggingInterceptor;
|
||||
import com.google.common.base.Charsets;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.eclipse.jetty.websocket.api.Session;
|
||||
import org.eclipse.jetty.websocket.client.ClientUpgradeRequest;
|
||||
import org.eclipse.jetty.websocket.client.WebSocketClient;
|
||||
import org.hl7.fhir.dstu3.model.*;
|
||||
import org.hl7.fhir.instance.model.api.IBaseResource;
|
||||
import org.hl7.fhir.instance.model.api.IIdType;
|
||||
import org.junit.Assert;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
@@ -23,17 +20,11 @@ import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.boot.web.server.LocalServerPort;
|
||||
import org.springframework.core.io.DefaultResourceLoader;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.test.context.junit.jupiter.SpringExtension;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.URI;
|
||||
import java.util.List;
|
||||
import java.util.Scanner;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@@ -53,7 +44,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
})
|
||||
|
||||
|
||||
public class ExampleServerDstu3IT {
|
||||
public class ExampleServerDstu3IT implements IServerSupport {
|
||||
|
||||
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(ExampleServerDstu2IT.class);
|
||||
private IGenericClient ourClient;
|
||||
@@ -62,6 +53,16 @@ public class ExampleServerDstu3IT {
|
||||
@LocalServerPort
|
||||
private int port;
|
||||
|
||||
@BeforeEach
|
||||
void beforeEach() {
|
||||
ourCtx = FhirContext.forDstu3();
|
||||
ourCtx.getRestfulClientFactory().setServerValidationMode(ServerValidationModeEnum.NEVER);
|
||||
ourCtx.getRestfulClientFactory().setSocketTimeout(1200 * 1000);
|
||||
String ourServerBase = "http://localhost:" + port + "/fhir/";
|
||||
ourClient = ourCtx.newRestfulGenericClient(ourServerBase);
|
||||
ourClient.registerInterceptor(new LoggingInterceptor(true));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateAndRead() {
|
||||
|
||||
@@ -80,10 +81,11 @@ public class ExampleServerDstu3IT {
|
||||
CqlProviderLoader cqlProviderLoader = null;
|
||||
|
||||
// FIXME KBD Remove this and put some Unit Test code here
|
||||
loadBundle("dstu3/EXM104/EXM104_FHIR3-8.1.000-bundle.json");
|
||||
loadBundle("dstu3/EXM104/EXM104_FHIR3-8.1.000-bundle.json", ourCtx, ourClient);
|
||||
|
||||
Parameters inParams = new Parameters();
|
||||
inParams.addParameter().setName("patientId").setValue(new StringType("Patient/numer-EXM104-FHIR3"));
|
||||
// inParams.addParameter().setName("measure").setValue(new StringType("Measure/measure-EXM104-8.2.000"));
|
||||
// inParams.addParameter().setName("patient").setValue(new StringType("Patient/numer-EXM104-FHIR3"));
|
||||
inParams.addParameter().setName("periodStart").setValue(new DateType("2019-01-01"));
|
||||
inParams.addParameter().setName("periodEnd").setValue(new DateType("2019-12-31"));
|
||||
|
||||
@@ -95,6 +97,14 @@ public class ExampleServerDstu3IT {
|
||||
.useHttpGet()
|
||||
.execute();
|
||||
|
||||
// Parameters outParams = ourClient
|
||||
// .operation()
|
||||
// .onType(Measure.class)
|
||||
// .named("$evaluate-measure")
|
||||
// .withParameters(inParams)
|
||||
// .useHttpGet()
|
||||
// .execute();
|
||||
|
||||
List<Parameters.ParametersParameterComponent> response = outParams.getParameter();
|
||||
|
||||
Assert.assertTrue(!response.isEmpty());
|
||||
@@ -112,42 +122,13 @@ public class ExampleServerDstu3IT {
|
||||
}
|
||||
}
|
||||
|
||||
private void putResource(String resourceFileName, String id) {
|
||||
InputStream is = ExampleServerDstu3IT.class.getResourceAsStream(resourceFileName);
|
||||
Scanner scanner = new Scanner(is).useDelimiter("\\A");
|
||||
String json = scanner.hasNext() ? scanner.next() : "";
|
||||
|
||||
boolean isJson = resourceFileName.endsWith("json");
|
||||
|
||||
IBaseResource resource = isJson ? ourCtx.newJsonParser().parseResource(json) : ourCtx.newXmlParser().parseResource(json);
|
||||
|
||||
if (resource instanceof Bundle) {
|
||||
ourClient.transaction().withBundle((Bundle) resource).execute();
|
||||
}
|
||||
else {
|
||||
ourClient.update().resource(resource).withId(id).execute();
|
||||
}
|
||||
}
|
||||
|
||||
private Bundle loadBundle(String theLocation) throws IOException {
|
||||
private Bundle loadBundle(String theLocation, FhirContext theCtx, IGenericClient theClient) throws IOException {
|
||||
String json = stringFromResource(theLocation);
|
||||
Bundle bundle = (Bundle) ourCtx.newJsonParser().parseResource(json);
|
||||
Bundle result = (Bundle) ourClient.transaction().withBundle(bundle).execute();
|
||||
Bundle bundle = (Bundle) theCtx.newJsonParser().parseResource(json);
|
||||
Bundle result = (Bundle) theClient.transaction().withBundle(bundle).execute();
|
||||
return result;
|
||||
}
|
||||
|
||||
private String stringFromResource(String theLocation) throws IOException {
|
||||
InputStream is = null;
|
||||
if (theLocation.startsWith(File.separator)) {
|
||||
is = new FileInputStream(theLocation);
|
||||
} else {
|
||||
DefaultResourceLoader resourceLoader = new DefaultResourceLoader();
|
||||
Resource resource = resourceLoader.getResource(theLocation);
|
||||
is = resource.getInputStream();
|
||||
}
|
||||
return IOUtils.toString(is, Charsets.UTF_8);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWebsocketSubscription() throws Exception {
|
||||
/*
|
||||
@@ -206,15 +187,4 @@ public class ExampleServerDstu3IT {
|
||||
ourClient.delete().resourceById(mySubscriptionId).execute();
|
||||
}
|
||||
|
||||
@BeforeEach
|
||||
void beforeEach() {
|
||||
|
||||
ourCtx = FhirContext.forDstu3();
|
||||
ourCtx.getRestfulClientFactory().setServerValidationMode(ServerValidationModeEnum.NEVER);
|
||||
ourCtx.getRestfulClientFactory().setSocketTimeout(1200 * 1000);
|
||||
String ourServerBase = "http://localhost:" + port + "/fhir/";
|
||||
ourClient = ourCtx.newRestfulGenericClient(ourServerBase);
|
||||
ourClient.registerInterceptor(new LoggingInterceptor(true));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package ca.uhn.fhir.jpa.starter;
|
||||
|
||||
import ca.uhn.fhir.context.FhirContext;
|
||||
import ca.uhn.fhir.cql.provider.CqlProviderLoader;
|
||||
import ca.uhn.fhir.model.primitive.IdDt;
|
||||
import ca.uhn.fhir.rest.api.CacheControlDirective;
|
||||
import ca.uhn.fhir.rest.api.EncodingEnum;
|
||||
import ca.uhn.fhir.rest.api.MethodOutcome;
|
||||
@@ -13,6 +15,8 @@ import org.eclipse.jetty.websocket.client.ClientUpgradeRequest;
|
||||
import org.eclipse.jetty.websocket.client.WebSocketClient;
|
||||
import org.hl7.fhir.instance.model.api.IIdType;
|
||||
import org.hl7.fhir.r4.model.*;
|
||||
import org.junit.Assert;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
@@ -20,6 +24,7 @@ import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.boot.web.server.LocalServerPort;
|
||||
import org.springframework.test.context.junit.jupiter.SpringExtension;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
@@ -44,7 +49,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
//Override is currently required when using Empi as the construction of the Empi beans are ambiguous as they are constructed multiple places. This is evident when running in a spring boot environment
|
||||
"spring.main.allow-bean-definition-overriding=true"
|
||||
})
|
||||
public class ExampleServerR4IT {
|
||||
public class ExampleServerR4IT implements IServerSupport {
|
||||
|
||||
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(ExampleServerDstu2IT.class);
|
||||
private IGenericClient ourClient;
|
||||
@@ -53,6 +58,20 @@ public class ExampleServerR4IT {
|
||||
@LocalServerPort
|
||||
private int port;
|
||||
|
||||
@BeforeEach
|
||||
void beforeEach() {
|
||||
ourCtx = FhirContext.forR4();
|
||||
ourCtx.getRestfulClientFactory().setServerValidationMode(ServerValidationModeEnum.NEVER);
|
||||
ourCtx.getRestfulClientFactory().setSocketTimeout(1200 * 1000);
|
||||
String ourServerBase = "http://localhost:" + port + "/fhir/";
|
||||
ourClient = ourCtx.newRestfulGenericClient(ourServerBase);
|
||||
ourClient.registerInterceptor(new LoggingInterceptor(true));
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
void afterEach() {
|
||||
ourLog.info("Finished running a test...");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testCreateAndRead() {
|
||||
@@ -91,6 +110,61 @@ public class ExampleServerR4IT {
|
||||
return BundleUtil.toListOfResourcesOfType(ourCtx, bundle, Person.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCQLEvaluateMeasure() throws IOException {
|
||||
CqlProviderLoader cqlProviderLoader = null;
|
||||
|
||||
// FIXME KBD Remove this and put some Unit Test code here
|
||||
loadBundle("r4/EXM104/EXM104-8.2.000-bundle.json", ourCtx, ourClient);
|
||||
|
||||
Parameters inParams = new Parameters();
|
||||
// inParams.addParameter().setName("measure").setValue(new StringType("Measure/measure-EXM104-8.2.000"));
|
||||
// inParams.addParameter().setName("patient").setValue(new StringType("Patient/numer-EXM104-FHIR3"));
|
||||
inParams.addParameter().setName("periodStart").setValue(new DateType("2019-01-01"));
|
||||
inParams.addParameter().setName("periodEnd").setValue(new DateType("2019-12-31"));
|
||||
|
||||
Parameters outParams = ourClient
|
||||
.operation()
|
||||
.onInstance(new IdDt("Measure", "measure-EXM104-8.2.000"))
|
||||
.named("$evaluate-measure")
|
||||
.withParameters(inParams)
|
||||
.cacheControl(new CacheControlDirective().setNoCache(true))
|
||||
.withAdditionalHeader("Content-Type", "application/json")
|
||||
.useHttpGet()
|
||||
.execute();
|
||||
|
||||
// Parameters outParams = ourClient
|
||||
// .operation()
|
||||
// .onType(Measure.class)
|
||||
// .named("$evaluate-measure")
|
||||
// .withParameters(inParams)
|
||||
// .useHttpGet()
|
||||
// .execute();
|
||||
|
||||
List<Parameters.ParametersParameterComponent> response = outParams.getParameter();
|
||||
|
||||
Assert.assertTrue(!response.isEmpty());
|
||||
|
||||
Parameters.ParametersParameterComponent component = response.get(0);
|
||||
|
||||
Assert.assertTrue(component.getResource() instanceof MeasureReport);
|
||||
|
||||
MeasureReport report = (MeasureReport) component.getResource();
|
||||
|
||||
for (MeasureReport.MeasureReportGroupComponent group : report.getGroup()) {
|
||||
for (MeasureReport.MeasureReportGroupPopulationComponent population : group.getPopulation()) {
|
||||
Assert.assertTrue(population.getCount() > 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private Bundle loadBundle(String theLocation, FhirContext theCtx, IGenericClient theClient) throws IOException {
|
||||
String json = stringFromResource(theLocation);
|
||||
Bundle bundle = (Bundle) theCtx.newJsonParser().parseResource(json);
|
||||
Bundle result = (Bundle) theClient.transaction().withBundle(bundle).execute();
|
||||
return result;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWebsocketSubscription() throws Exception {
|
||||
/*
|
||||
@@ -152,16 +226,4 @@ public class ExampleServerR4IT {
|
||||
private int activeSubscriptionCount() {
|
||||
return ourClient.search().forResource(Subscription.class).where(Subscription.STATUS.exactly().code("active")).cacheControl(new CacheControlDirective().setNoCache(true)).returnBundle(Bundle.class).execute().getEntry().size();
|
||||
}
|
||||
|
||||
|
||||
@BeforeEach
|
||||
void beforeEach() {
|
||||
|
||||
ourCtx = FhirContext.forR4();
|
||||
ourCtx.getRestfulClientFactory().setServerValidationMode(ServerValidationModeEnum.NEVER);
|
||||
ourCtx.getRestfulClientFactory().setSocketTimeout(1200 * 1000);
|
||||
String ourServerBase = "http://localhost:" + port + "/fhir/";
|
||||
ourClient = ourCtx.newRestfulGenericClient(ourServerBase);
|
||||
ourClient.registerInterceptor(new LoggingInterceptor(true));
|
||||
}
|
||||
}
|
||||
|
||||
47
src/test/java/ca/uhn/fhir/jpa/starter/IServerSupport.java
Normal file
47
src/test/java/ca/uhn/fhir/jpa/starter/IServerSupport.java
Normal file
@@ -0,0 +1,47 @@
|
||||
package ca.uhn.fhir.jpa.starter;
|
||||
|
||||
import ca.uhn.fhir.context.FhirContext;
|
||||
import ca.uhn.fhir.rest.client.api.IGenericClient;
|
||||
import com.google.common.base.Charsets;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.hl7.fhir.instance.model.api.IBaseResource;
|
||||
import org.springframework.core.io.DefaultResourceLoader;
|
||||
import org.springframework.core.io.Resource;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.Scanner;
|
||||
|
||||
public interface IServerSupport {
|
||||
|
||||
// default void putResourceDstu3(String resourceFileName, String id, FhirContext theCtx, IGenericClient theClient) {
|
||||
// InputStream is = ExampleServerDstu3IT.class.getResourceAsStream(resourceFileName);
|
||||
// Scanner scanner = new Scanner(is).useDelimiter("\\A");
|
||||
// String json = scanner.hasNext() ? scanner.next() : "";
|
||||
//
|
||||
// boolean isJson = resourceFileName.endsWith("json");
|
||||
//
|
||||
// IBaseResource resource = isJson ? theCtx.newJsonParser().parseResource(json) : theCtx.newXmlParser().parseResource(json);
|
||||
//
|
||||
// if (resource instanceof Bundle) {
|
||||
// theClient.transaction().withBundle((Bundle) resource).execute();
|
||||
// }
|
||||
// else {
|
||||
// theClient.update().resource(resource).withId(id).execute();
|
||||
// }
|
||||
// }
|
||||
|
||||
default String stringFromResource(String theLocation) throws IOException {
|
||||
InputStream is = null;
|
||||
if (theLocation.startsWith(File.separator)) {
|
||||
is = new FileInputStream(theLocation);
|
||||
} else {
|
||||
DefaultResourceLoader resourceLoader = new DefaultResourceLoader();
|
||||
Resource resource = resourceLoader.getResource(theLocation);
|
||||
is = resource.getInputStream();
|
||||
}
|
||||
return IOUtils.toString(is, Charsets.UTF_8);
|
||||
}
|
||||
}
|
||||
4021
src/test/resources/r4/EXM104/EXM104-8.2.000-bundle.json
Normal file
4021
src/test/resources/r4/EXM104/EXM104-8.2.000-bundle.json
Normal file
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user