Search in sources :

Example 46 with ResourceType

use of org.hl7.fhir.dstu3.model.ResourceType in project pathling by aehrc.

the class ConformanceProvider method buildResources.

@Nonnull
private List<CapabilityStatementRestResourceComponent> buildResources() {
    final List<CapabilityStatementRestResourceComponent> resources = new ArrayList<>();
    final Set<ResourceType> supported = FhirServer.supportedResourceTypes();
    final Set<ResourceType> supportedResourceTypes = supported.isEmpty() ? EnumSet.noneOf(ResourceType.class) : EnumSet.copyOf(supported);
    for (final ResourceType resourceType : supportedResourceTypes) {
        final CapabilityStatementRestResourceComponent resource = new CapabilityStatementRestResourceComponent(new CodeType(resourceType.toCode()));
        resource.setProfile(FHIR_RESOURCE_BASE + resourceType.toCode());
        // Add the search operation to all resources.
        final ResourceInteractionComponent search = new ResourceInteractionComponent();
        search.setCode(TypeRestfulInteraction.SEARCHTYPE);
        resource.getInteraction().add(search);
        // Add the create and update operations to all resources.
        final ResourceInteractionComponent create = new ResourceInteractionComponent();
        final ResourceInteractionComponent update = new ResourceInteractionComponent();
        create.setCode(TypeRestfulInteraction.CREATE);
        update.setCode(TypeRestfulInteraction.UPDATE);
        resource.getInteraction().add(create);
        resource.getInteraction().add(update);
        // Add the `aggregate` operation to all resources.
        final CanonicalType aggregateOperationUri = new CanonicalType(getOperationUri("aggregate"));
        final CapabilityStatementRestResourceOperationComponent aggregateOperation = new CapabilityStatementRestResourceOperationComponent(new StringType("aggregate"), aggregateOperationUri);
        resource.addOperation(aggregateOperation);
        // Add the `fhirPath` search parameter to all resources.
        final CapabilityStatementRestResourceOperationComponent searchOperation = new CapabilityStatementRestResourceOperationComponent();
        searchOperation.setName("fhirPath");
        searchOperation.setDefinition(getOperationUri("search"));
        resource.addOperation(searchOperation);
        resources.add(resource);
    }
    // Add the read operation to the OperationDefinition resource.
    final String opDefCode = ResourceType.OPERATIONDEFINITION.toCode();
    final CapabilityStatementRestResourceComponent opDefResource = new CapabilityStatementRestResourceComponent(new CodeType(opDefCode));
    opDefResource.setProfile(FHIR_RESOURCE_BASE + opDefCode);
    final ResourceInteractionComponent readInteraction = new ResourceInteractionComponent();
    readInteraction.setCode(TypeRestfulInteraction.READ);
    opDefResource.addInteraction(readInteraction);
    resources.add(opDefResource);
    return resources;
}
Also used : ResourceInteractionComponent(org.hl7.fhir.r4.model.CapabilityStatement.ResourceInteractionComponent) StringType(org.hl7.fhir.r4.model.StringType) ArrayList(java.util.ArrayList) CodeType(org.hl7.fhir.r4.model.CodeType) ResourceType(org.hl7.fhir.r4.model.Enumerations.ResourceType) CapabilityStatementRestResourceComponent(org.hl7.fhir.r4.model.CapabilityStatement.CapabilityStatementRestResourceComponent) CanonicalType(org.hl7.fhir.r4.model.CanonicalType) CapabilityStatementRestResourceOperationComponent(org.hl7.fhir.r4.model.CapabilityStatement.CapabilityStatementRestResourceOperationComponent) Nonnull(javax.annotation.Nonnull)

Example 47 with ResourceType

use of org.hl7.fhir.dstu3.model.ResourceType in project pathling by aehrc.

the class FhirServer method buildUpdateProviders.

@Nonnull
private List<IResourceProvider> buildUpdateProviders() {
    final List<IResourceProvider> providers = new ArrayList<>();
    for (final ResourceType resourceType : ResourceType.values()) {
        final IResourceProvider updateProvider = resourceProviderFactory.createUpdateResourceProvider(resourceType);
        providers.add(updateProvider);
    }
    return providers;
}
Also used : IResourceProvider(ca.uhn.fhir.rest.server.IResourceProvider) ArrayList(java.util.ArrayList) ResourceType(org.hl7.fhir.r4.model.ResourceType) Nonnull(javax.annotation.Nonnull)

Example 48 with ResourceType

use of org.hl7.fhir.dstu3.model.ResourceType in project pathling by aehrc.

the class TestDataImporter method run.

@Override
public void run(final String... args) {
    final String sourcePath = args[0];
    final File srcNdJsonDir = new File(sourcePath);
    final FileFilter fileFilter = new WildcardFileFilter("*.ndjson");
    final File[] srcNdJsonFiles = srcNdJsonDir.listFiles(fileFilter);
    final List<ParametersParameterComponent> sources = Stream.of(Objects.requireNonNull(srcNdJsonFiles)).map(file -> {
        final String resourceName = FilenameUtils.getBaseName(file.getName());
        final ResourceType subjectResource = ResourceType.valueOf(resourceName.toUpperCase());
        final ParametersParameterComponent source = new ParametersParameterComponent();
        source.setName("source");
        final ParametersParameterComponent resourceType = new ParametersParameterComponent();
        resourceType.setName("resourceType");
        resourceType.setValue(new CodeType(subjectResource.toCode()));
        source.addPart(resourceType);
        final ParametersParameterComponent url = new ParametersParameterComponent();
        url.setName("url");
        url.setValue(new UrlType("file://" + file.toPath()));
        source.addPart(url);
        return source;
    }).collect(Collectors.toList());
    final Parameters parameters = new Parameters();
    parameters.setParameter(sources);
    importExecutor.execute(parameters);
}
Also used : ParametersParameterComponent(org.hl7.fhir.r4.model.Parameters.ParametersParameterComponent) UrlType(org.hl7.fhir.r4.model.UrlType) SpringBootApplication(org.springframework.boot.autoconfigure.SpringBootApplication) Autowired(org.springframework.beans.factory.annotation.Autowired) ResourceType(org.hl7.fhir.r4.model.Enumerations.ResourceType) Collectors(java.util.stream.Collectors) Profile(org.springframework.context.annotation.Profile) File(java.io.File) ComponentScan(org.springframework.context.annotation.ComponentScan) ImportExecutor(au.csiro.pathling.update.ImportExecutor) Objects(java.util.Objects) SpringApplication(org.springframework.boot.SpringApplication) List(java.util.List) Slf4j(lombok.extern.slf4j.Slf4j) FileFilter(java.io.FileFilter) Stream(java.util.stream.Stream) WildcardFileFilter(jodd.io.filter.WildcardFileFilter) Parameters(org.hl7.fhir.r4.model.Parameters) CodeType(org.hl7.fhir.r4.model.CodeType) CommandLineRunner(org.springframework.boot.CommandLineRunner) Nonnull(javax.annotation.Nonnull) FilenameUtils(org.apache.commons.io.FilenameUtils) SparkSession(org.apache.spark.sql.SparkSession) Parameters(org.hl7.fhir.r4.model.Parameters) CodeType(org.hl7.fhir.r4.model.CodeType) ResourceType(org.hl7.fhir.r4.model.Enumerations.ResourceType) FileFilter(java.io.FileFilter) WildcardFileFilter(jodd.io.filter.WildcardFileFilter) File(java.io.File) WildcardFileFilter(jodd.io.filter.WildcardFileFilter) UrlType(org.hl7.fhir.r4.model.UrlType) ParametersParameterComponent(org.hl7.fhir.r4.model.Parameters.ParametersParameterComponent)

Example 49 with ResourceType

use of org.hl7.fhir.dstu3.model.ResourceType in project pathling by aehrc.

the class BatchTest method batch.

@Test
void batch() throws URISyntaxException {
    // Check the counts for each resource type.
    for (final ResourceType resourceType : RESOURCE_TYPES) {
        assertResourceCount(resourceType, expectedCounts.get(resourceType));
    }
    // Send a batch request with a new Patient, Practitioner and Organization resource.
    final String request = getResourceAsString("requests/BatchTest/batch.Bundle.json");
    final Bundle requestBundle = (Bundle) jsonParser.parseResource(request);
    final String url = "http://localhost:" + port + "/fhir";
    final ResponseEntity<String> response = restTemplate.exchange(url, HttpMethod.POST, RequestEntity.put(new URI(url)).contentType(TestHelpers.FHIR_MEDIA_TYPE).accept(TestHelpers.FHIR_MEDIA_TYPE).body(request), String.class);
    assertEquals(200, response.getStatusCode().value());
    assertNotNull(response.getBody());
    // Check the response bundle is successful and matches the requests.
    final Bundle responseBundle = (Bundle) jsonParser.parseResource(response.getBody());
    assertEquals(requestBundle.getEntry().size(), responseBundle.getEntry().size());
    for (final BundleEntryComponent entry : responseBundle.getEntry()) {
        assertTrue(entry.getResponse().getStatus().startsWith("200"));
        assertNotNull(entry.getResource());
        final String resourceId = entry.getResource().getIdElement().getIdPart();
        final ResourceType resourceType = ResourceType.fromCode(entry.getResource().getResourceType().toString());
        getResourceResult(resourceType, resourceId);
    }
    // Check that the new resource counts are one greater than before the operation.
    for (final ResourceType resourceType : RESOURCE_TYPES) {
        assertResourceCount(resourceType, expectedCounts.get(resourceType) + 1);
    }
}
Also used : BundleEntryComponent(org.hl7.fhir.r4.model.Bundle.BundleEntryComponent) Bundle(org.hl7.fhir.r4.model.Bundle) ResourceType(org.hl7.fhir.r4.model.Enumerations.ResourceType) TestHelpers.getResourceAsString(au.csiro.pathling.test.helpers.TestHelpers.getResourceAsString) URI(java.net.URI) Test(org.junit.jupiter.api.Test)

Example 50 with ResourceType

use of org.hl7.fhir.dstu3.model.ResourceType in project pathling by aehrc.

the class ModificationTest method getResourceResult.

@Nonnull
BundleEntryComponent getResourceResult(@Nonnull final ResourceType resourceType, @Nonnull final String id) throws URISyntaxException {
    final String searchUrl = "http://localhost:" + port + "/fhir/" + resourceType.toCode() + "?_query=fhirPath&filter=id+=+'" + id + "'";
    final ResponseEntity<String> searchResponse = restTemplate.exchange(searchUrl, HttpMethod.GET, RequestEntity.get(new URI(searchUrl)).accept(TestHelpers.FHIR_MEDIA_TYPE).build(), String.class);
    assertTrue(searchResponse.getStatusCode().is2xxSuccessful());
    assertNotNull(searchResponse.getBody());
    final Bundle searchBundle = (Bundle) jsonParser.parseResource(searchResponse.getBody());
    assertEquals(1, searchBundle.getTotal());
    assertEquals(1, searchBundle.getEntry().size());
    final BundleEntryComponent bundleEntryComponent = searchBundle.getEntry().get(0);
    assertEquals(id, bundleEntryComponent.getResource().getIdElement().getIdPart());
    return bundleEntryComponent;
}
Also used : BundleEntryComponent(org.hl7.fhir.r4.model.Bundle.BundleEntryComponent) Bundle(org.hl7.fhir.r4.model.Bundle) URI(java.net.URI) Nonnull(javax.annotation.Nonnull)

Aggregations

JsonElement (com.google.gson.JsonElement)33 HashSet (java.util.HashSet)26 Bundle (org.hl7.fhir.r4.model.Bundle)24 ResourceType (org.hl7.fhir.r4.model.Enumerations.ResourceType)21 Test (org.junit.Test)20 Nonnull (javax.annotation.Nonnull)18 ArrayList (java.util.ArrayList)15 IBaseResource (org.hl7.fhir.instance.model.api.IBaseResource)10 FhirContext (ca.uhn.fhir.context.FhirContext)9 File (java.io.File)9 Row (org.apache.spark.sql.Row)9 IdType (org.hl7.fhir.dstu3.model.IdType)9 BundleEntryComponent (org.hl7.fhir.r4.model.Bundle.BundleEntryComponent)9 JsonObject (com.google.gson.JsonObject)8 Test (org.junit.jupiter.api.Test)8 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)8 IOException (java.io.IOException)7 List (java.util.List)7 Bundle (org.hl7.fhir.dstu3.model.Bundle)7 Resource (org.hl7.fhir.r4.model.Resource)7