Search in sources :

Example 91 with ResourceType

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

the class PathlingAuthorityTest method testValidation.

@Test
void testValidation() {
    // positive cases
    PathlingAuthority.fromAuthority("pathling");
    PathlingAuthority.fromAuthority("pathling:read");
    PathlingAuthority.fromAuthority("pathling:write");
    PathlingAuthority.fromAuthority("pathling:aggregate");
    PathlingAuthority.fromAuthority("pathling:search");
    PathlingAuthority.fromAuthority("pathling:extract");
    PathlingAuthority.fromAuthority("pathling:import");
    PathlingAuthority.fromAuthority("pathling:create");
    PathlingAuthority.fromAuthority("pathling:update");
    for (final ResourceType resourceType : ResourceType.values()) {
        PathlingAuthority.fromAuthority("pathling:read:" + resourceType.toCode());
        PathlingAuthority.fromAuthority("pathling:write:" + resourceType.toCode());
    }
    // negative cases
    assertFailsValidation("*");
    assertFailsValidation("read");
    assertFailsValidation("read:Patient");
    assertFailsValidation("pathling:read:*");
    assertFailsValidation("pathling:*");
    assertFailsValidation("pathling:*:*");
    assertFailsValidation("pathling::");
    assertFailsValidation("pathling::Patient");
    assertFailsValidation("pathling:search:Patient", "Subject not supported for action: search");
    assertFailsValidation("pathling:se_arch");
    assertFailsValidation("pathling:read:Clinical_Impression");
}
Also used : ResourceType(org.hl7.fhir.r4.model.Enumerations.ResourceType) Test(org.junit.jupiter.api.Test)

Example 92 with ResourceType

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

the class BatchProvider method processEntry.

private void processEntry(final Map<ResourceType, List<IBaseResource>> resourcesForUpdate, final Bundle response, final BundleEntryComponent entry) {
    final Resource resource = entry.getResource();
    final BundleEntryRequestComponent request = entry.getRequest();
    if (resource == null || request == null || request.isEmpty()) {
        return;
    }
    checkUserInput(request.getMethod().toString().equals("PUT"), "Only update requests are supported for use within the batch operation");
    final String urlErrorMessage = "The URL for an update request must refer to the code of a " + "supported resource type, and must look like this: [resource type]/[id]";
    checkUserInput(UPDATE_URL.matcher(request.getUrl()).matches(), urlErrorMessage);
    final List<String> urlComponents = List.of(request.getUrl().split("/"));
    checkUserInput(urlComponents.size() == 2, urlErrorMessage);
    final String resourceTypeCode = urlComponents.get(0);
    final String urlId = urlComponents.get(1);
    final ResourceType resourceType = validateResourceType(entry, resourceTypeCode, urlErrorMessage);
    final IBaseResource preparedResource = prepareResourceForUpdate(resource, urlId);
    addToResourceMap(resourcesForUpdate, resourceType, preparedResource);
    addResponse(response, preparedResource);
}
Also used : BundleEntryRequestComponent(org.hl7.fhir.r4.model.Bundle.BundleEntryRequestComponent) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) Resource(org.hl7.fhir.r4.model.Resource) ResourceType(org.hl7.fhir.r4.model.Enumerations.ResourceType) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource)

Example 93 with ResourceType

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

the class BatchProvider method validateResourceType.

@SuppressWarnings("SameParameterValue")
@Nonnull
private ResourceType validateResourceType(final BundleEntryComponent entry, final String resourceTypeCode, final String urlErrorMessage) {
    final ResourceType resourceType;
    try {
        resourceType = ResourceType.fromCode(resourceTypeCode);
    } catch (final FHIRException e) {
        throw new InvalidUserInputError(urlErrorMessage);
    }
    checkUserInput(FhirServer.supportedResourceTypes().contains(resourceType), urlErrorMessage);
    final String resourceEmbeddedType = entry.getResource().fhirType();
    checkUserInput(resourceTypeCode.equals(resourceEmbeddedType), "Resource in URL does not match resource type");
    return resourceType;
}
Also used : InvalidUserInputError(au.csiro.pathling.errors.InvalidUserInputError) ResourceType(org.hl7.fhir.r4.model.Enumerations.ResourceType) FHIRException(org.hl7.fhir.exceptions.FHIRException) Nonnull(javax.annotation.Nonnull)

Example 94 with ResourceType

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

the class InvocationVisitor method visitMemberInvocation.

/**
 * This method gets called when an element is on the right-hand side of the invocation expression,
 * or when an identifier is referred to as a term (e.g. "Encounter" or "type").
 *
 * @param ctx The {@link MemberInvocationContext}
 * @return A {@link FhirPath} expression
 */
@Override
@Nonnull
public FhirPath visitMemberInvocation(@Nullable final MemberInvocationContext ctx) {
    @Nullable final String fhirPath = checkNotNull(ctx).getText();
    checkNotNull(fhirPath);
    if (invoker != null) {
        // If there is an invoker, we treat this as a path traversal from the invoker.
        final PathTraversalInput pathTraversalInput = new PathTraversalInput(context, invoker, fhirPath);
        return new PathTraversalOperator().invoke(pathTraversalInput);
    } else {
        if (context.getThisContext().isEmpty()) {
            // See https://hl7.org/fhirpath/2018Sep/index.html#path-selection.
            if (fhirPath.equals(context.getInputContext().getExpression())) {
                return context.getInputContext();
            } else {
                // If the expression is not a reference to the subject resource, treat it as a path
                // traversal from the input context.
                final PathTraversalInput pathTraversalInput = new PathTraversalInput(context, context.getInputContext(), fhirPath);
                return new PathTraversalOperator().invoke(pathTraversalInput);
            }
        } else {
            // If we're in the context of a function's arguments, there are two valid things this
            // could be:
            // (1) a path traversal from the input context;
            // (2) a reference to a resource type.
            // Check if the expression is a reference to a known resource type.
            final ResourceType resourceType;
            try {
                resourceType = ResourceType.fromCode(fhirPath);
            } catch (final FHIRException e) {
                // If the expression is not a resource reference, treat it as a path traversal from the
                // input context.
                final PathTraversalInput pathTraversalInput = new PathTraversalInput(context, context.getThisContext().get(), fhirPath);
                return new PathTraversalOperator().invoke(pathTraversalInput);
            }
            // the current resource reference.
            return ResourcePath.build(context.getFhirContext(), context.getDatabase(), resourceType, fhirPath, true);
        }
    }
}
Also used : PathTraversalInput(au.csiro.pathling.fhirpath.operator.PathTraversalInput) PathTraversalOperator(au.csiro.pathling.fhirpath.operator.PathTraversalOperator) ResourceType(org.hl7.fhir.r4.model.Enumerations.ResourceType) FHIRException(org.hl7.fhir.exceptions.FHIRException) Nullable(javax.annotation.Nullable) Nonnull(javax.annotation.Nonnull)

Example 95 with ResourceType

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

the class ResolveFunction method resolveMonomorphicReference.

@Nonnull
private FhirPath resolveMonomorphicReference(@Nonnull final NamedFunctionInput input, @Nonnull final Database database, @Nonnull final FhirContext fhirContext, @Nonnull final Collection<ResourceType> referenceTypes, final String expression) {
    final ReferencePath referencePath = (ReferencePath) input.getInput();
    // If this is a monomorphic reference, we just need to retrieve the appropriate table and
    // create a dataset with the full resources.
    final ResourceType resourceType = (ResourceType) referenceTypes.toArray()[0];
    final ResourcePath resourcePath = ResourcePath.build(fhirContext, database, resourceType, expression, referencePath.isSingular());
    // Join the resource dataset to the reference dataset.
    final Column joinCondition = referencePath.getResourceEquality(resourcePath);
    final Dataset<Row> dataset = join(referencePath.getDataset(), resourcePath.getDataset(), joinCondition, JoinType.LEFT_OUTER);
    final Column inputId = referencePath.getIdColumn();
    final Optional<Column> inputEid = referencePath.getEidColumn();
    // We need to add the resource ID column to the parser context so that it can be used within
    // joins in certain situations, e.g. extract.
    input.getContext().getNodeIdColumns().putIfAbsent(expression, resourcePath.getElementColumn("id"));
    final ResourcePath result = resourcePath.copy(expression, dataset, inputId, inputEid, resourcePath.getValueColumn(), referencePath.isSingular(), referencePath.getThisColumn());
    result.setCurrentResource(resourcePath);
    return result;
}
Also used : ResourcePath(au.csiro.pathling.fhirpath.ResourcePath) UntypedResourcePath(au.csiro.pathling.fhirpath.UntypedResourcePath) Column(org.apache.spark.sql.Column) ReferencePath(au.csiro.pathling.fhirpath.element.ReferencePath) ResourceType(org.hl7.fhir.r4.model.Enumerations.ResourceType) Row(org.apache.spark.sql.Row) 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