Search in sources :

Example 1 with Profile

use of org.ehrbase.fhirbridge.fhir.common.Profile 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 2 with Profile

use of org.ehrbase.fhirbridge.fhir.common.Profile 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)

Aggregations

UnprocessableEntityException (ca.uhn.fhir.rest.server.exceptions.UnprocessableEntityException)2 Profile (org.ehrbase.fhirbridge.fhir.common.Profile)2 OperationOutcome (org.hl7.fhir.r4.model.OperationOutcome)2 OperationOutcomeIssueComponent (org.hl7.fhir.r4.model.OperationOutcome.OperationOutcomeIssueComponent)2