Unit Test work - still cannot get Dstu3 working after several attempts, but included the skelton of a test to capture the effort anyways.
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
package ca.uhn.fhir.jpa.starter;
|
||||
|
||||
import ca.uhn.fhir.context.FhirContext;
|
||||
import ca.uhn.fhir.cql.provider.CqlProviderLoader;
|
||||
import ca.uhn.fhir.jpa.api.dao.DaoRegistry;
|
||||
import ca.uhn.fhir.model.primitive.IdDt;
|
||||
import ca.uhn.fhir.rest.api.CacheControlDirective;
|
||||
import ca.uhn.fhir.rest.api.EncodingEnum;
|
||||
@@ -9,6 +9,7 @@ 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 org.apache.commons.io.FileUtils;
|
||||
import org.eclipse.jetty.websocket.api.Session;
|
||||
import org.eclipse.jetty.websocket.client.ClientUpgradeRequest;
|
||||
import org.eclipse.jetty.websocket.client.WebSocketClient;
|
||||
@@ -18,12 +19,16 @@ import org.junit.Assert;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.boot.web.server.LocalServerPort;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.test.context.junit.jupiter.SpringExtension;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
@@ -50,6 +55,9 @@ public class ExampleServerDstu3IT implements IServerSupport {
|
||||
private IGenericClient ourClient;
|
||||
private FhirContext ourCtx;
|
||||
|
||||
@Autowired
|
||||
DaoRegistry myDaoRegistry;
|
||||
|
||||
@LocalServerPort
|
||||
private int port;
|
||||
|
||||
@@ -76,50 +84,66 @@ public class ExampleServerDstu3IT implements IServerSupport {
|
||||
assertEquals(methodName, pt2.getName().get(0).getFamily());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCQLEvaluateMeasure() throws IOException {
|
||||
CqlProviderLoader cqlProviderLoader = null;
|
||||
// Currently fails with:
|
||||
// ca.uhn.fhir.rest.server.exceptions.InternalErrorException: HTTP 500 : Failed to call access method: java.lang.IllegalArgumentException: Could not load library source for libraries referenced in Measure/Measure/measure-EXM104-FHIR3-8.1.000/_history/1.
|
||||
//@Test
|
||||
public void testCQLEvaluateMeasureEXM104() throws IOException {
|
||||
String measureId = "measure-EXM104-FHIR3-8.1.000";
|
||||
|
||||
// FIXME KBD Remove this and put some Unit Test code here
|
||||
loadBundle("dstu3/EXM104/EXM104_FHIR3-8.1.000-bundle.json", ourCtx, ourClient);
|
||||
int numFilesLoaded = loadDataFromDirectory("dstu3/EXM104/EXM104_FHIR3-8.1.000-files");
|
||||
//assertEquals(numFilesLoaded, 3);
|
||||
ourLog.info("{} files imported successfully!", numFilesLoaded);
|
||||
//loadBundle("dstu3/EXM104/EXM104_FHIR3-8.1.000-bundle.json", ourCtx, ourClient);
|
||||
|
||||
// http://localhost:8080/fhir/Measure/measure-EXM104-FHIR3-8.1.000/$evaluate-measure?periodStart=2019-01-01&periodEnd=2019-12-31
|
||||
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"));
|
||||
// inParams.addParameter().setName("periodStart").setValue(new StringType("2019-01-01"));
|
||||
// inParams.addParameter().setName("periodEnd").setValue(new StringType("2019-12-31"));
|
||||
|
||||
Parameters outParams = ourClient
|
||||
.operation()
|
||||
.onInstance(new IdDt("Measure", "measure-EXM104-FHIR3-8.1.000"))
|
||||
.onInstance(new IdDt("Measure", measureId))
|
||||
.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();
|
||||
Assert.assertEquals("Measure/"+measureId, report.getMeasure());
|
||||
}
|
||||
|
||||
for (MeasureReport.MeasureReportGroupComponent group : report.getGroup()) {
|
||||
for (MeasureReport.MeasureReportGroupPopulationComponent population : group.getPopulation()) {
|
||||
Assert.assertTrue(population.getCount() > 0);
|
||||
private int loadDataFromDirectory(String theDirectoryName) throws IOException {
|
||||
int count = 0;
|
||||
ourLog.info("Reading files in directory: {}", theDirectoryName);
|
||||
ClassPathResource dir = new ClassPathResource(theDirectoryName);
|
||||
Collection<File> files = FileUtils.listFiles(dir.getFile(), null, false);
|
||||
ourLog.info("{} files found.", files.size());
|
||||
for (File file : files) {
|
||||
String filename = file.getAbsolutePath();
|
||||
ourLog.info("Processing filename '{}'", filename);
|
||||
if (filename.endsWith(".cql") || filename.contains("expectedresults")) {
|
||||
// Ignore .cql and expectedresults files
|
||||
ourLog.info("Ignoring file: '{}'", filename);
|
||||
} else if (filename.endsWith(".json")) {
|
||||
if (filename.contains("bundle")) {
|
||||
loadBundle(filename, ourCtx, ourClient);
|
||||
} else {
|
||||
loadResource(filename, ourCtx, myDaoRegistry);
|
||||
}
|
||||
count++;
|
||||
} else {
|
||||
ourLog.info("Ignoring file: '{}'", filename);
|
||||
}
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
private Bundle loadBundle(String theLocation, FhirContext theCtx, IGenericClient theClient) throws IOException {
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
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;
|
||||
@@ -42,10 +41,10 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
{
|
||||
"spring.batch.job.enabled=false",
|
||||
"spring.datasource.url=jdbc:h2:mem:dbr4",
|
||||
"hapi.fhir.fhir_version=R4",
|
||||
"hapi.fhir.cql_enabled=true",
|
||||
"hapi.fhir.fhir_version=r4",
|
||||
"hapi.fhir.subscription.websocket_enabled=true",
|
||||
"hapi.fhir.empi_enabled=true",
|
||||
"hapi.fhir.subscription.websocket_enabled=true",
|
||||
//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"
|
||||
})
|
||||
@@ -54,6 +53,7 @@ public class ExampleServerR4IT implements IServerSupport {
|
||||
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(ExampleServerDstu2IT.class);
|
||||
private IGenericClient ourClient;
|
||||
private FhirContext ourCtx;
|
||||
private String ourServerBaseURL;
|
||||
|
||||
@LocalServerPort
|
||||
private int port;
|
||||
@@ -63,8 +63,8 @@ public class ExampleServerR4IT implements IServerSupport {
|
||||
ourCtx = FhirContext.forR4();
|
||||
ourCtx.getRestfulClientFactory().setServerValidationMode(ServerValidationModeEnum.NEVER);
|
||||
ourCtx.getRestfulClientFactory().setSocketTimeout(1200 * 1000);
|
||||
String ourServerBase = "http://localhost:" + port + "/fhir/";
|
||||
ourClient = ourCtx.newRestfulGenericClient(ourServerBase);
|
||||
ourServerBaseURL = "http://localhost:" + port + "/fhir/";
|
||||
ourClient = ourCtx.newRestfulGenericClient(ourServerBaseURL);
|
||||
ourClient.registerInterceptor(new LoggingInterceptor(true));
|
||||
}
|
||||
|
||||
@@ -111,21 +111,21 @@ public class ExampleServerR4IT implements IServerSupport {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCQLEvaluateMeasure() throws IOException {
|
||||
CqlProviderLoader cqlProviderLoader = null;
|
||||
public void testCQLEvaluateMeasureEXM104() throws IOException {
|
||||
String measureId = "measure-EXM104-8.2.000";
|
||||
|
||||
// FIXME KBD Remove this and put some Unit Test code here
|
||||
loadBundle("r4/EXM104/EXM104-8.2.000-bundle.json", ourCtx, ourClient);
|
||||
|
||||
// http://localhost:8080/fhir/Measure/measure-EXM104-8.2.000/$evaluate-measure?periodStart=2019-01-01&periodEnd=2019-12-31
|
||||
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"));
|
||||
inParams.addParameter().setName("periodStart").setValue(new StringType("2019-01-01"));
|
||||
inParams.addParameter().setName("periodEnd").setValue(new StringType("2019-12-31"));
|
||||
|
||||
Parameters outParams = ourClient
|
||||
.operation()
|
||||
.onInstance(new IdDt("Measure", "measure-EXM104-8.2.000"))
|
||||
.onInstance(new IdDt("Measure", measureId))
|
||||
.named("$evaluate-measure")
|
||||
.withParameters(inParams)
|
||||
.cacheControl(new CacheControlDirective().setNoCache(true))
|
||||
@@ -133,29 +133,12 @@ public class ExampleServerR4IT implements IServerSupport {
|
||||
.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);
|
||||
}
|
||||
}
|
||||
Assert.assertEquals("Measure/"+measureId, report.getMeasure());
|
||||
}
|
||||
|
||||
private Bundle loadBundle(String theLocation, FhirContext theCtx, IGenericClient theClient) throws IOException {
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
package ca.uhn.fhir.jpa.starter;
|
||||
|
||||
import ca.uhn.fhir.context.FhirContext;
|
||||
import ca.uhn.fhir.rest.client.api.IGenericClient;
|
||||
import ca.uhn.fhir.jpa.api.dao.DaoRegistry;
|
||||
import ca.uhn.fhir.jpa.api.dao.IFhirResourceDao;
|
||||
import com.google.common.base.Charsets;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.hl7.fhir.instance.model.api.IBaseResource;
|
||||
@@ -12,26 +13,20 @@ 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 IBaseResource loadResource(String theLocation, FhirContext theFhirContext, DaoRegistry theDaoRegistry) throws IOException {
|
||||
String json = stringFromResource(theLocation);
|
||||
IBaseResource resource = theFhirContext.newJsonParser().parseResource(json);
|
||||
IFhirResourceDao<IBaseResource> dao = theDaoRegistry.getResourceDao(resource.getIdElement().getResourceType());
|
||||
if (dao == null) {
|
||||
return null;
|
||||
} else {
|
||||
dao.update(resource);
|
||||
return resource;
|
||||
}
|
||||
}
|
||||
|
||||
default String stringFromResource(String theLocation) throws IOException {
|
||||
InputStream is = null;
|
||||
|
||||
Reference in New Issue
Block a user