Search in sources :

Example 1 with Database

use of au.csiro.pathling.io.Database in project pathling by aehrc.

the class ManifestConverterTest method convertsManifest.

@Test
void convertsManifest() {
    database = new Database(configuration, spark, fhirEncoders, executor);
    final PassportScope passportScope = new PassportScope();
    final VisaManifest manifest = new VisaManifest();
    manifest.setPatientIds(Arrays.asList(PATIENT_ID_1, PATIENT_ID_2, PATIENT_ID_3, PATIENT_ID_4));
    final ManifestConverter manifestConverter = new ManifestConverter(configuration, fhirContext);
    manifestConverter.populateScope(passportScope, manifest);
    // Convert the scope to JSON and compare it to a test fixture.
    final Gson gson = new GsonBuilder().create();
    final String json = gson.toJson(passportScope);
    assertJson("responses/ManifestConverterTest/convertsManifest.json", json);
    // our test patients.
    for (final ResourceType resourceType : passportScope.keySet()) {
        if (AVAILABLE_RESOURCE_TYPES.contains(resourceType)) {
            boolean found = false;
            for (final String filter : passportScope.get(resourceType)) {
                final Dataset<Row> dataset = assertThatResultOf(resourceType, filter).isElementPath(BooleanPath.class).selectResult().apply(result -> result.filter(result.columns()[1])).getDataset();
                if (dataset.count() > 0) {
                    found = true;
                }
            }
            assertTrue(found, "No results found for " + resourceType.toCode());
        }
    }
}
Also used : Arrays(java.util.Arrays) Dataset(org.apache.spark.sql.Dataset) DynamicPropertySource(org.springframework.test.context.DynamicPropertySource) Autowired(org.springframework.beans.factory.annotation.Autowired) DynamicPropertyRegistry(org.springframework.test.context.DynamicPropertyRegistry) ResourceType(org.hl7.fhir.r4.model.Enumerations.ResourceType) BooleanPath(au.csiro.pathling.fhirpath.element.BooleanPath) GsonBuilder(com.google.gson.GsonBuilder) FhirContext(ca.uhn.fhir.context.FhirContext) FhirEncoders(au.csiro.pathling.encoders.FhirEncoders) Gson(com.google.gson.Gson) Assertions.assertJson(au.csiro.pathling.test.assertions.Assertions.assertJson) Nonnull(javax.annotation.Nonnull) MockBean(org.springframework.boot.test.mock.mockito.MockBean) ThreadPoolTaskExecutor(org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor) Configuration(au.csiro.pathling.Configuration) TestPropertySource(org.springframework.test.context.TestPropertySource) Row(org.apache.spark.sql.Row) File(java.io.File) Test(org.junit.jupiter.api.Test) List(java.util.List) Slf4j(lombok.extern.slf4j.Slf4j) AbstractParserTest(au.csiro.pathling.fhirpath.parser.AbstractParserTest) Database(au.csiro.pathling.io.Database) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) GsonBuilder(com.google.gson.GsonBuilder) BooleanPath(au.csiro.pathling.fhirpath.element.BooleanPath) Gson(com.google.gson.Gson) ResourceType(org.hl7.fhir.r4.model.Enumerations.ResourceType) Database(au.csiro.pathling.io.Database) Row(org.apache.spark.sql.Row) Test(org.junit.jupiter.api.Test) AbstractParserTest(au.csiro.pathling.fhirpath.parser.AbstractParserTest)

Example 2 with Database

use of au.csiro.pathling.io.Database in project pathling by aehrc.

the class EntityTagInterceptorTest method setUp.

@BeforeEach
void setUp() {
    database = mock(Database.class);
    conformanceProvider = mock(ConformanceProvider.class);
    request = mock(HttpServletRequest.class);
    requestDetails = mock(RequestDetails.class);
    response = mock(HttpServletResponse.class);
    final Configuration configuration = mock(Configuration.class);
    final HttpCaching httpCaching = mock(HttpCaching.class);
    when(httpCaching.getVary()).thenReturn(List.of("Accept", "Accept-Encoding", "Prefer", "Authorization"));
    when(httpCaching.getCacheableControl()).thenReturn(List.of("must-revalidate", "max-age=1"));
    when(configuration.getHttpCaching()).thenReturn(httpCaching);
    interceptor = new EntityTagInterceptor(configuration, database, conformanceProvider);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) Configuration(au.csiro.pathling.Configuration) Database(au.csiro.pathling.io.Database) EntityTagInterceptor(au.csiro.pathling.caching.EntityTagInterceptor) HttpServletResponse(javax.servlet.http.HttpServletResponse) HttpCaching(au.csiro.pathling.Configuration.HttpCaching) RequestDetails(ca.uhn.fhir.rest.api.server.RequestDetails) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 3 with Database

use of au.csiro.pathling.io.Database in project pathling by aehrc.

the class CodingLiteralPathTest method setUp.

@BeforeEach
void setUp() {
    final Database database = mock(Database.class);
    final Dataset<Row> inputContextDataset = new ResourceDatasetBuilder(spark).withIdColumn().withRow("observation-1").withRow("observation-2").withRow("observation-3").withRow("observation-4").withRow("observation-5").build();
    when(database.read(ResourceType.OBSERVATION)).thenReturn(inputContextDataset);
    inputContext = new ResourcePathBuilder(spark).expression("Observation").resourceType(ResourceType.OBSERVATION).database(database).singular(true).build();
}
Also used : ResourceDatasetBuilder(au.csiro.pathling.test.builders.ResourceDatasetBuilder) Database(au.csiro.pathling.io.Database) ResourcePathBuilder(au.csiro.pathling.test.builders.ResourcePathBuilder) Row(org.apache.spark.sql.Row) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 4 with Database

use of au.csiro.pathling.io.Database in project pathling by aehrc.

the class ExtractQueryTest method setUp.

@BeforeEach
void setUp() {
    SharedMocks.resetAll();
    database = mock(Database.class);
    final ResultWriter resultWriter = mock(ResultWriter.class);
    final ResultRegistry resultRegistry = mock(ResultRegistry.class);
    executor = new ExtractExecutor(configuration, fhirContext, spark, database, Optional.ofNullable(terminologyServiceFactory), resultWriter, resultRegistry);
}
Also used : ResultWriter(au.csiro.pathling.io.ResultWriter) Database(au.csiro.pathling.io.Database) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 5 with Database

use of au.csiro.pathling.io.Database in project pathling by aehrc.

the class AggregateExecutorTest method runFirstGroupingThroughSearch.

/**
 * Test that the drill-down expression from the first grouping from each aggregate result can be
 * successfully executed using the FHIRPath search.
 */
@AfterEach
void runFirstGroupingThroughSearch() {
    if (response != null) {
        final Optional<Grouping> firstGroupingOptional = response.getGroupings().stream().filter(grouping -> grouping.getDrillDown().isPresent()).findFirst();
        if (firstGroupingOptional.isPresent()) {
            final Grouping firstGrouping = firstGroupingOptional.get();
            assertTrue(firstGrouping.getDrillDown().isPresent());
            final String drillDown = firstGrouping.getDrillDown().get();
            final StringAndListParam filters = new StringAndListParam();
            filters.addAnd(new StringParam(drillDown));
            final IBundleProvider searchExecutor = new SearchExecutor(configuration, fhirContext, spark, database, Optional.of(terminologyServiceFactory), fhirEncoders, subjectResource, Optional.of(filters));
            final List<IBaseResource> resources = searchExecutor.getResources(0, 100);
            assertTrue(resources.size() > 0);
        }
    }
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) IBundleProvider(ca.uhn.fhir.rest.api.server.IBundleProvider) TestHelpers(au.csiro.pathling.test.helpers.TestHelpers) Autowired(org.springframework.beans.factory.annotation.Autowired) ResourceType(org.hl7.fhir.r4.model.Enumerations.ResourceType) StringAndListParam(ca.uhn.fhir.rest.param.StringAndListParam) FhirContext(ca.uhn.fhir.context.FhirContext) Grouping(au.csiro.pathling.aggregate.AggregateResponse.Grouping) FhirEncoders(au.csiro.pathling.encoders.FhirEncoders) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) TerminologyServiceFactory(au.csiro.pathling.fhir.TerminologyServiceFactory) Assertions.assertJson(au.csiro.pathling.test.assertions.Assertions.assertJson) Tag(org.junit.jupiter.api.Tag) Nonnull(javax.annotation.Nonnull) TerminologyService(au.csiro.pathling.terminology.TerminologyService) IParser(ca.uhn.fhir.parser.IParser) SparkSession(org.apache.spark.sql.SparkSession) Configuration(au.csiro.pathling.Configuration) List(java.util.List) AfterEach(org.junit.jupiter.api.AfterEach) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Database(au.csiro.pathling.io.Database) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) SharedMocks(au.csiro.pathling.test.SharedMocks) StringParam(ca.uhn.fhir.rest.param.StringParam) SearchExecutor(au.csiro.pathling.search.SearchExecutor) Optional(java.util.Optional) Parameters(org.hl7.fhir.r4.model.Parameters) Mockito.mock(org.mockito.Mockito.mock) StringAndListParam(ca.uhn.fhir.rest.param.StringAndListParam) Grouping(au.csiro.pathling.aggregate.AggregateResponse.Grouping) IBundleProvider(ca.uhn.fhir.rest.api.server.IBundleProvider) StringParam(ca.uhn.fhir.rest.param.StringParam) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) SearchExecutor(au.csiro.pathling.search.SearchExecutor) AfterEach(org.junit.jupiter.api.AfterEach)

Aggregations

Database (au.csiro.pathling.io.Database)6 BeforeEach (org.junit.jupiter.api.BeforeEach)4 Configuration (au.csiro.pathling.Configuration)3 FhirContext (ca.uhn.fhir.context.FhirContext)3 Nonnull (javax.annotation.Nonnull)3 ResourceType (org.hl7.fhir.r4.model.Enumerations.ResourceType)3 FhirEncoders (au.csiro.pathling.encoders.FhirEncoders)2 Assertions.assertJson (au.csiro.pathling.test.assertions.Assertions.assertJson)2 List (java.util.List)2 Row (org.apache.spark.sql.Row)2 Assertions.assertTrue (org.junit.jupiter.api.Assertions.assertTrue)2 Autowired (org.springframework.beans.factory.annotation.Autowired)2 HttpCaching (au.csiro.pathling.Configuration.HttpCaching)1 Grouping (au.csiro.pathling.aggregate.AggregateResponse.Grouping)1 EntityTagInterceptor (au.csiro.pathling.caching.EntityTagInterceptor)1 TerminologyServiceFactory (au.csiro.pathling.fhir.TerminologyServiceFactory)1 BooleanPath (au.csiro.pathling.fhirpath.element.BooleanPath)1 ReferencePath (au.csiro.pathling.fhirpath.element.ReferencePath)1 AbstractParserTest (au.csiro.pathling.fhirpath.parser.AbstractParserTest)1 ResultWriter (au.csiro.pathling.io.ResultWriter)1