Search in sources :

Example 1 with FhirEncoders

use of au.csiro.pathling.encoders.FhirEncoders 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 FhirEncoders

use of au.csiro.pathling.encoders.FhirEncoders 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

Configuration (au.csiro.pathling.Configuration)2 FhirEncoders (au.csiro.pathling.encoders.FhirEncoders)2 Database (au.csiro.pathling.io.Database)2 Assertions.assertJson (au.csiro.pathling.test.assertions.Assertions.assertJson)2 FhirContext (ca.uhn.fhir.context.FhirContext)2 List (java.util.List)2 Nonnull (javax.annotation.Nonnull)2 ResourceType (org.hl7.fhir.r4.model.Enumerations.ResourceType)2 Assertions.assertTrue (org.junit.jupiter.api.Assertions.assertTrue)2 Autowired (org.springframework.beans.factory.annotation.Autowired)2 Grouping (au.csiro.pathling.aggregate.AggregateResponse.Grouping)1 TerminologyServiceFactory (au.csiro.pathling.fhir.TerminologyServiceFactory)1 BooleanPath (au.csiro.pathling.fhirpath.element.BooleanPath)1 AbstractParserTest (au.csiro.pathling.fhirpath.parser.AbstractParserTest)1 SearchExecutor (au.csiro.pathling.search.SearchExecutor)1 TerminologyService (au.csiro.pathling.terminology.TerminologyService)1 SharedMocks (au.csiro.pathling.test.SharedMocks)1 TestHelpers (au.csiro.pathling.test.helpers.TestHelpers)1 IParser (ca.uhn.fhir.parser.IParser)1 IBundleProvider (ca.uhn.fhir.rest.api.server.IBundleProvider)1