Search in sources :

Example 1 with RMObjectValidationMessage

use of com.nedap.archie.rmobjectvalidator.RMObjectValidationMessage in project ehrbase by ehrbase.

the class ValidationServiceImp method check.

@Override
public void check(EhrStatus ehrStatus) {
    // case of a system generated ehr
    if (ehrStatus == null) {
        return;
    }
    // first, check the built EhrStatus using the general Archie RM-Validator
    List<RMObjectValidationMessage> rmObjectValidationMessages = RM_OBJECT_VALIDATOR.validate(ehrStatus);
    if (!rmObjectValidationMessages.isEmpty()) {
        StringBuilder stringBuilder = new StringBuilder();
        for (RMObjectValidationMessage rmObjectValidationMessage : rmObjectValidationMessages) {
            stringBuilder.append(rmObjectValidationMessage.toString());
            stringBuilder.append("\n");
        }
        throw new ValidationException(stringBuilder.toString());
    }
    if (ehrStatus.getSubject() == null) {
        throw new ValidationException("subject is required");
    }
    if (ehrStatus.getSubject().getExternalRef() != null) {
        // but if it is there it has to have an ID
        if (ehrStatus.getSubject().getExternalRef().getId() == null || ehrStatus.getSubject().getExternalRef().getId().getValue().isEmpty()) {
            throw new ValidationException("ExternalRef ID is required");
        }
        // and a namespace
        if (ehrStatus.getSubject().getExternalRef().getNamespace() == null) {
            throw new ValidationException("ExternalRef namespace is required");
        // which needs to be valid
        } else if (!NAMESPACE_PATTERN.matcher(ehrStatus.getSubject().getExternalRef().getNamespace()).matches()) {
            throw new ValidationException("Subject's namespace format invalid");
        }
    }
}
Also used : ValidationException(org.ehrbase.api.exception.ValidationException) RMObjectValidationMessage(com.nedap.archie.rmobjectvalidator.RMObjectValidationMessage)

Aggregations

RMObjectValidationMessage (com.nedap.archie.rmobjectvalidator.RMObjectValidationMessage)1 ValidationException (org.ehrbase.api.exception.ValidationException)1