Search in sources :

Example 21 with OperationOutcomeIssueComponent

use of org.hl7.fhir.r4b.model.OperationOutcome.OperationOutcomeIssueComponent in project org.hl7.fhir.core by hapifhir.

the class ValidationEngineTests method test140.

@Test
public void test140() throws Exception {
    if (inbuild) {
        Assertions.assertTrue(true);
        return;
    }
    if (!TestUtilities.silent)
        System.out.println("Test140: Validate patient-example.xml in v1.4.0 version");
    ValidationEngine ve = TestUtilities.getValidationEngine("hl7.fhir.r2b.core#1.4.0", DEF_TX, FhirPublication.DSTU2016May, "1.4.0");
    CacheVerificationLogger logger = new CacheVerificationLogger();
    ve.getContext().getTxClient().setLogger(logger);
    OperationOutcome op = ve.validate(FhirFormat.XML, TestingUtilities.loadTestResourceStream("validator", "patient140.xml"), null);
    if (!TestUtilities.silent)
        for (OperationOutcomeIssueComponent iss : op.getIssue()) {
            System.out.println("    " + iss.getDetails().getText());
        }
    int e = errors(op);
    int w = warnings(op);
    int h = hints(op);
    Assertions.assertEquals(1, e);
    Assertions.assertEquals(0, w);
    Assertions.assertEquals(0, h);
    assertTrue(logger.verifyHasNoRequests(), "Unexpected request to TX server");
    if (!TestUtilities.silent)
        System.out.println("  .. done: " + Integer.toString(e) + " errors, " + Integer.toString(w) + " warnings, " + Integer.toString(h) + " information messages");
}
Also used : OperationOutcomeIssueComponent(org.hl7.fhir.r5.model.OperationOutcome.OperationOutcomeIssueComponent) CacheVerificationLogger(org.hl7.fhir.utilities.tests.CacheVerificationLogger) OperationOutcome(org.hl7.fhir.r5.model.OperationOutcome) ValidationEngine(org.hl7.fhir.validation.ValidationEngine) Test(org.junit.jupiter.api.Test)

Example 22 with OperationOutcomeIssueComponent

use of org.hl7.fhir.r4b.model.OperationOutcome.OperationOutcomeIssueComponent in project fhir-bridge by ehrbase.

the class ValidationUtils method addIssue.

public static void addIssue(OperationOutcome outcome, IssueSeverity severity, String diagnostics, String location) {
    Assert.notNull(outcome, "OperationOutcome must not be null");
    Assert.notNull(outcome, "IssueSeverity must not be null");
    var issue = new OperationOutcomeIssueComponent().setSeverity(severity).setCode(OperationOutcome.IssueType.PROCESSING).setDiagnostics(diagnostics);
    if (location != null) {
        issue.addLocation(location);
    }
    outcome.addIssue(issue);
}
Also used : OperationOutcomeIssueComponent(org.hl7.fhir.r4.model.OperationOutcome.OperationOutcomeIssueComponent)

Example 23 with OperationOutcomeIssueComponent

use of org.hl7.fhir.r4b.model.OperationOutcome.OperationOutcomeIssueComponent in project fhir-bridge by ehrbase.

the class FhirProfileValidator method validateProfiles.

/**
 * Validates the profiles for the given resource.
 *
 * @param resource the submitted resource
 * @param exchange the current exchange
 */
private void validateProfiles(Resource resource, Exchange exchange) {
    Set<Profile> supportedProfiles = Profile.resolveAll(resource);
    Class<? extends Resource> resourceType = resource.getClass();
    OperationOutcome outcome = new OperationOutcome();
    if (supportedProfiles.isEmpty()) {
        outcome.addIssue(new OperationOutcomeIssueComponent().setSeverity(IssueSeverity.FATAL).setCode(IssueType.VALUE).setDiagnostics(messages.getMessage("validation.profile.missingSupported", new Object[] { Profile.getSupportedProfiles(resourceType) })).addExpression(profileExpression(resource)));
    } else if (supportedProfiles.size() > 1) {
        outcome.addIssue(new OperationOutcomeIssueComponent().setSeverity(IssueSeverity.FATAL).setCode(IssueType.VALUE).setDiagnostics(messages.getMessage("validation.profile.moreThanOneSupported")).addExpression(profileExpression(resource)));
    }
    if (outcome.hasIssue()) {
        throw new UnprocessableEntityException(fhirContext, outcome);
    }
    exchange.getMessage().setHeader(CamelConstants.PROFILE, supportedProfiles.iterator().next());
}
Also used : UnprocessableEntityException(ca.uhn.fhir.rest.server.exceptions.UnprocessableEntityException) OperationOutcomeIssueComponent(org.hl7.fhir.r4.model.OperationOutcome.OperationOutcomeIssueComponent) OperationOutcome(org.hl7.fhir.r4.model.OperationOutcome) Profile(org.ehrbase.fhirbridge.fhir.common.Profile)

Example 24 with OperationOutcomeIssueComponent

use of org.hl7.fhir.r4b.model.OperationOutcome.OperationOutcomeIssueComponent in project fhir-bridge by ehrbase.

the class FhirProfileValidator method validateDefault.

/**
 * Validates if the default profile is supported by the resource.
 *
 * @param resource the submitted resource
 * @param exchange the current exchange
 */
private void validateDefault(Resource resource, Exchange exchange) {
    Class<? extends Resource> clazz = resource.getClass();
    Profile profile = Profile.getDefaultProfile(clazz);
    if (profile == null) {
        OperationOutcome outcome = new OperationOutcome().addIssue(new OperationOutcomeIssueComponent().setSeverity(IssueSeverity.FATAL).setCode(IssueType.VALUE).setDiagnostics(messages.getMessage("validation.profile.defaultNotSupported", new Object[] { resource.getResourceType(), Profile.getSupportedProfiles(clazz) })).addExpression(profileExpression(resource)));
        throw new UnprocessableEntityException(fhirContext, outcome);
    }
    exchange.getMessage().setHeader(CamelConstants.PROFILE, profile);
}
Also used : UnprocessableEntityException(ca.uhn.fhir.rest.server.exceptions.UnprocessableEntityException) OperationOutcomeIssueComponent(org.hl7.fhir.r4.model.OperationOutcome.OperationOutcomeIssueComponent) OperationOutcome(org.hl7.fhir.r4.model.OperationOutcome) Profile(org.ehrbase.fhirbridge.fhir.common.Profile)

Example 25 with OperationOutcomeIssueComponent

use of org.hl7.fhir.r4b.model.OperationOutcome.OperationOutcomeIssueComponent in project pathling by aehrc.

the class ImportExecutor method execute.

/**
 * Executes an import request.
 *
 * @param inParams a FHIR {@link Parameters} object describing the import request
 * @return a FHIR {@link OperationOutcome} resource describing the result
 */
@Nonnull
public OperationOutcome execute(@Nonnull @ResourceParam final Parameters inParams) {
    // Parse and validate the JSON request.
    final List<ParametersParameterComponent> sourceParams = inParams.getParameter().stream().filter(param -> "source".equals(param.getName())).collect(Collectors.toList());
    if (sourceParams.isEmpty()) {
        throw new InvalidUserInputError("Must provide at least one source parameter");
    }
    log.info("Received $import request");
    // the corresponding table in the warehouse.
    for (final ParametersParameterComponent sourceParam : sourceParams) {
        final ParametersParameterComponent resourceTypeParam = sourceParam.getPart().stream().filter(param -> "resourceType".equals(param.getName())).findFirst().orElseThrow(() -> new InvalidUserInputError("Must provide resourceType for each source"));
        final ParametersParameterComponent urlParam = sourceParam.getPart().stream().filter(param -> "url".equals(param.getName())).findFirst().orElseThrow(() -> new InvalidUserInputError("Must provide url for each source"));
        // The mode parameter defaults to 'overwrite'.
        final ImportMode importMode = sourceParam.getPart().stream().filter(param -> "mode".equals(param.getName()) && param.getValue() instanceof CodeType).findFirst().map(param -> ImportMode.fromCode(((CodeType) param.getValue()).asStringValue())).orElse(ImportMode.OVERWRITE);
        final String resourceCode = ((CodeType) resourceTypeParam.getValue()).getCode();
        final ResourceType resourceType = ResourceType.fromCode(resourceCode);
        // Get an encoder based on the declared resource type within the source parameter.
        final ExpressionEncoder<IBaseResource> fhirEncoder;
        try {
            fhirEncoder = fhirEncoders.of(resourceType.toCode());
        } catch (final UnsupportedResourceError e) {
            throw new InvalidUserInputError("Unsupported resource type: " + resourceCode);
        }
        // Read the resources from the source URL into a dataset of strings.
        final Dataset<String> jsonStrings = readStringsFromUrl(urlParam);
        // Parse each line into a HAPI FHIR object, then encode to a Spark dataset.
        final Dataset<IBaseResource> resources = jsonStrings.map(jsonToResourceConverter(), fhirEncoder);
        log.info("Importing {} resources (mode: {})", resourceType.toCode(), importMode.getCode());
        if (importMode == ImportMode.OVERWRITE) {
            database.overwrite(resourceType, resources.toDF());
        } else {
            database.merge(resourceType, resources.toDF());
        }
    }
    // We return 200, as this operation is currently synchronous.
    log.info("Import complete");
    // Construct a response.
    final OperationOutcome opOutcome = new OperationOutcome();
    final OperationOutcomeIssueComponent issue = new OperationOutcomeIssueComponent();
    issue.setSeverity(IssueSeverity.INFORMATION);
    issue.setCode(IssueType.INFORMATIONAL);
    issue.setDiagnostics("Data import completed successfully");
    opOutcome.getIssue().add(issue);
    return opOutcome;
}
Also used : UrlType(org.hl7.fhir.r4.model.UrlType) URLDecoder(java.net.URLDecoder) Getter(lombok.Getter) Dataset(org.apache.spark.sql.Dataset) ResourceType(org.hl7.fhir.r4.model.Enumerations.ResourceType) UnsupportedResourceError(au.csiro.pathling.encoders.UnsupportedResourceError) FhirEncoders(au.csiro.pathling.encoders.FhirEncoders) AccessRules(au.csiro.pathling.io.AccessRules) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) InvalidUserInputError(au.csiro.pathling.errors.InvalidUserInputError) SecurityError(au.csiro.pathling.errors.SecurityError) Nonnull(javax.annotation.Nonnull) Nullable(javax.annotation.Nullable) MapFunction(org.apache.spark.api.java.function.MapFunction) SparkSession(org.apache.spark.sql.SparkSession) ParametersParameterComponent(org.hl7.fhir.r4.model.Parameters.ParametersParameterComponent) IssueSeverity(org.hl7.fhir.r4.model.OperationOutcome.IssueSeverity) PersistenceScheme(au.csiro.pathling.io.PersistenceScheme) Collectors(java.util.stream.Collectors) Profile(org.springframework.context.annotation.Profile) FhirContextFactory(au.csiro.pathling.fhir.FhirContextFactory) StandardCharsets(java.nio.charset.StandardCharsets) OperationOutcomeIssueComponent(org.hl7.fhir.r4.model.OperationOutcome.OperationOutcomeIssueComponent) ExpressionEncoder(org.apache.spark.sql.catalyst.encoders.ExpressionEncoder) OperationOutcome(org.hl7.fhir.r4.model.OperationOutcome) ResourceParam(ca.uhn.fhir.rest.annotation.ResourceParam) List(java.util.List) Slf4j(lombok.extern.slf4j.Slf4j) Component(org.springframework.stereotype.Component) Database(au.csiro.pathling.io.Database) IssueType(org.hl7.fhir.r4.model.OperationOutcome.IssueType) Optional(java.util.Optional) Parameters(org.hl7.fhir.r4.model.Parameters) CodeType(org.hl7.fhir.r4.model.CodeType) Preconditions.checkUserInput(au.csiro.pathling.utilities.Preconditions.checkUserInput) FilterFunction(org.apache.spark.api.java.function.FilterFunction) InvalidUserInputError(au.csiro.pathling.errors.InvalidUserInputError) OperationOutcomeIssueComponent(org.hl7.fhir.r4.model.OperationOutcome.OperationOutcomeIssueComponent) UnsupportedResourceError(au.csiro.pathling.encoders.UnsupportedResourceError) ResourceType(org.hl7.fhir.r4.model.Enumerations.ResourceType) OperationOutcome(org.hl7.fhir.r4.model.OperationOutcome) CodeType(org.hl7.fhir.r4.model.CodeType) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) ParametersParameterComponent(org.hl7.fhir.r4.model.Parameters.ParametersParameterComponent) Nonnull(javax.annotation.Nonnull)

Aggregations

OperationOutcomeIssueComponent (org.hl7.fhir.r4.model.OperationOutcome.OperationOutcomeIssueComponent)23 OperationOutcome (org.hl7.fhir.r4.model.OperationOutcome)20 Test (org.junit.jupiter.api.Test)17 OperationOutcomeIssueComponent (org.hl7.fhir.dstu3.model.OperationOutcome.OperationOutcomeIssueComponent)10 Order (org.junit.jupiter.api.Order)10 TestMethodOrder (org.junit.jupiter.api.TestMethodOrder)10 RestIntegrationTest (org.opencds.cqf.ruler.test.RestIntegrationTest)10 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)10 OperationOutcomeIssueComponent (org.hl7.fhir.r5.model.OperationOutcome.OperationOutcomeIssueComponent)8 OperationOutcome (org.hl7.fhir.dstu3.model.OperationOutcome)7 OperationOutcome (org.hl7.fhir.r5.model.OperationOutcome)5 CacheVerificationLogger (org.hl7.fhir.utilities.tests.CacheVerificationLogger)5 XhtmlNode (org.hl7.fhir.utilities.xhtml.XhtmlNode)5 ValidationEngine (org.hl7.fhir.validation.ValidationEngine)5 BufferedReader (java.io.BufferedReader)4 InputStreamReader (java.io.InputStreamReader)4 Nonnull (javax.annotation.Nonnull)4 ValueSet (org.hl7.fhir.dstu3.model.ValueSet)4 IBaseOperationOutcome (org.hl7.fhir.instance.model.api.IBaseOperationOutcome)3 CodeableConcept (org.hl7.fhir.r4.model.CodeableConcept)3