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");
}
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);
}
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;
}
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);
}
}
}
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;
}
Aggregations