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