use of org.hl7.fhir.r4.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;
}
use of org.hl7.fhir.r4.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;
}
use of org.hl7.fhir.r4.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);
}
use of org.hl7.fhir.r4.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);
}
}
use of org.hl7.fhir.r4.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;
}
Aggregations