Search in sources :

Example 16 with IssueType

use of org.hl7.fhir.r4.model.OperationOutcome.IssueType in project org.hl7.fhir.core by hapifhir.

the class BaseWorkerContext method serverValidateCode.

private ValidationResult serverValidateCode(Parameters pin, boolean doCache) throws Exception {
    if (noTerminologyServer) {
        return new ValidationResult(null, null, TerminologyServiceErrorClass.NOSERVICE);
    }
    String cacheName = doCache ? generateCacheName(pin) : null;
    ValidationResult res = loadFromCache(cacheName);
    if (res != null) {
        return res;
    }
    tlog("Terminology Server: $validate-code " + describeValidationParameters(pin));
    for (ParametersParameterComponent pp : pin.getParameter()) {
        if (pp.getName().equals("profile")) {
            throw new Error("Can only specify profile in the context");
        }
    }
    if (expProfile == null) {
        throw new Exception("No ExpansionProfile provided");
    }
    pin.addParameter().setName("profile").setResource(expProfile);
    Parameters pout = txServer.operateType(ValueSet.class, "validate-code", pin);
    boolean ok = false;
    String message = "No Message returned";
    String display = null;
    TerminologyServiceErrorClass err = TerminologyServiceErrorClass.UNKNOWN;
    for (ParametersParameterComponent p : pout.getParameter()) {
        if (p.getName().equals("result")) {
            ok = ((BooleanType) p.getValue()).getValue().booleanValue();
        } else if (p.getName().equals("message")) {
            message = ((StringType) p.getValue()).getValue();
        } else if (p.getName().equals("display")) {
            display = ((StringType) p.getValue()).getValue();
        } else if (p.getName().equals("cause")) {
            try {
                IssueType it = IssueType.fromCode(((StringType) p.getValue()).getValue());
                if (it == IssueType.UNKNOWN) {
                    err = TerminologyServiceErrorClass.UNKNOWN;
                } else if (it == IssueType.NOTSUPPORTED) {
                    err = TerminologyServiceErrorClass.VALUESET_UNSUPPORTED;
                }
            } catch (FHIRException e) {
            }
        }
    }
    if (!ok) {
        res = new ValidationResult(IssueSeverity.ERROR, message, err);
    } else if (display != null) {
        res = new ValidationResult(new ConceptDefinitionComponent().setDisplay(display));
    } else {
        res = new ValidationResult(new ConceptDefinitionComponent());
    }
    saveToCache(res, cacheName);
    return res;
}
Also used : TerminologyServiceErrorClass(org.hl7.fhir.dstu3.terminologies.ValueSetExpander.TerminologyServiceErrorClass) Parameters(org.hl7.fhir.dstu3.model.Parameters) StringType(org.hl7.fhir.dstu3.model.StringType) IssueType(org.hl7.fhir.utilities.validation.ValidationMessage.IssueType) BooleanType(org.hl7.fhir.dstu3.model.BooleanType) FHIRException(org.hl7.fhir.exceptions.FHIRException) TerminologyServiceException(org.hl7.fhir.exceptions.TerminologyServiceException) FileNotFoundException(java.io.FileNotFoundException) NoTerminologyServiceException(org.hl7.fhir.exceptions.NoTerminologyServiceException) JsonSyntaxException(com.google.gson.JsonSyntaxException) IOException(java.io.IOException) FHIRException(org.hl7.fhir.exceptions.FHIRException) ConceptDefinitionComponent(org.hl7.fhir.dstu3.model.CodeSystem.ConceptDefinitionComponent) ParametersParameterComponent(org.hl7.fhir.dstu3.model.Parameters.ParametersParameterComponent)

Example 17 with IssueType

use of org.hl7.fhir.r4.model.OperationOutcome.IssueType in project org.hl7.fhir.core by hapifhir.

the class ParserBase method logError.

// FIXME: i18n should be done here
public void logError(int line, int col, String path, IssueType type, String message, IssueSeverity level) throws FHIRFormatError {
    if (errors != null) {
        if (policy == ValidationPolicy.EVERYTHING) {
            ValidationMessage msg = new ValidationMessage(Source.InstanceValidator, type, line, col, path, message, level);
            errors.add(msg);
        } else if (level == IssueSeverity.FATAL || (level == IssueSeverity.ERROR && policy == ValidationPolicy.QUICK))
            throw new FHIRFormatError(message + String.format(" at line %d col %d", line, col));
    }
}
Also used : ValidationMessage(org.hl7.fhir.utilities.validation.ValidationMessage) FHIRFormatError(org.hl7.fhir.exceptions.FHIRFormatError)

Example 18 with IssueType

use of org.hl7.fhir.r4.model.OperationOutcome.IssueType in project org.hl7.fhir.core by hapifhir.

the class ParserBase method logError.

// FIXME: i18n should be done here
public void logError(int line, int col, String path, IssueType type, String message, IssueSeverity level) throws FHIRFormatError {
    if (errors != null) {
        if (policy == ValidationPolicy.EVERYTHING) {
            ValidationMessage msg = new ValidationMessage(Source.InstanceValidator, type, line, col, path, message, level);
            errors.add(msg);
        } else if (level == IssueSeverity.FATAL || (level == IssueSeverity.ERROR && policy == ValidationPolicy.QUICK))
            throw new FHIRFormatError(message + String.format(" at line %d col %d", line, col));
    }
}
Also used : ValidationMessage(org.hl7.fhir.utilities.validation.ValidationMessage) FHIRFormatError(org.hl7.fhir.exceptions.FHIRFormatError)

Example 19 with IssueType

use of org.hl7.fhir.r4.model.OperationOutcome.IssueType in project org.hl7.fhir.core by hapifhir.

the class BaseValidator method warningOrError.

protected boolean warningOrError(boolean isError, List<ValidationMessage> errors, IssueType type, int line, int col, String path, boolean thePass, String msg, Object... theMessageArguments) {
    if (!thePass) {
        String nmsg = context.formatMessage(msg, theMessageArguments);
        IssueSeverity lvl = isError ? IssueSeverity.ERROR : IssueSeverity.WARNING;
        if (doingLevel(lvl)) {
            addValidationMessage(errors, type, line, col, path, nmsg, lvl, msg);
        }
    }
    return thePass;
}
Also used : IssueSeverity(org.hl7.fhir.utilities.validation.ValidationMessage.IssueSeverity)

Example 20 with IssueType

use of org.hl7.fhir.r4.model.OperationOutcome.IssueType in project org.hl7.fhir.core by hapifhir.

the class BaseValidator method warning.

/**
 * Test a rule and add a {@link IssueSeverity#WARNING} validation message if the validation fails
 *
 * @param thePass
 *          Set this parameter to <code>false</code> if the validation does not pass
 * @return Returns <code>thePass</code> (in other words, returns <code>true</code> if the rule did not fail validation)
 */
protected boolean warning(List<ValidationMessage> errors, IssueType type, int line, int col, String path, boolean thePass, String msg, Object... theMessageArguments) {
    if (!thePass && doingWarnings()) {
        String nmsg = context.formatMessage(msg, theMessageArguments);
        IssueSeverity severity = IssueSeverity.WARNING;
        addValidationMessage(errors, type, line, col, path, nmsg, severity, msg);
    }
    return thePass;
}
Also used : IssueSeverity(org.hl7.fhir.utilities.validation.ValidationMessage.IssueSeverity)

Aggregations

ValidationMessage (org.hl7.fhir.utilities.validation.ValidationMessage)8 OperationOutcome (org.hl7.fhir.r4.model.OperationOutcome)6 FHIRFormatError (org.hl7.fhir.exceptions.FHIRFormatError)5 FHIRException (org.hl7.fhir.exceptions.FHIRException)4 OperationOutcomeIssueComponent (org.hl7.fhir.r4.model.OperationOutcome.OperationOutcomeIssueComponent)4 IssueSeverity (org.hl7.fhir.utilities.validation.ValidationMessage.IssueSeverity)4 IssueType (org.hl7.fhir.utilities.validation.ValidationMessage.IssueType)4 OperationOutcome (org.hl7.fhir.dstu3.model.OperationOutcome)2 OperationOutcomeIssueComponent (org.hl7.fhir.dstu3.model.OperationOutcome.OperationOutcomeIssueComponent)2 BaseServerResponseException (ca.uhn.fhir.rest.server.exceptions.BaseServerResponseException)1 JsonSyntaxException (com.google.gson.JsonSyntaxException)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 Nonnull (javax.annotation.Nonnull)1 BooleanType (org.hl7.fhir.dstu3.model.BooleanType)1 ConceptDefinitionComponent (org.hl7.fhir.dstu3.model.CodeSystem.ConceptDefinitionComponent)1 CodeableConcept (org.hl7.fhir.dstu3.model.CodeableConcept)1 Coding (org.hl7.fhir.dstu3.model.Coding)1 Meta (org.hl7.fhir.dstu3.model.Meta)1 Parameters (org.hl7.fhir.dstu3.model.Parameters)1