Search in sources :

Example 6 with IssueSeverity

use of org.hl7.fhir.utilities.validation.ValidationMessage.IssueSeverity in project org.hl7.fhir.core by hapifhir.

the class ValueSetCheckerSimple method validateCode.

public ValidationResult validateCode(Coding code) throws FHIRException {
    String warningMessage = null;
    // first, we validate the concept itself
    ValidationResult res = null;
    boolean inExpansion = false;
    boolean inInclude = false;
    String system = code.hasSystem() ? code.getSystem() : getValueSetSystemOrNull();
    if (options.getValueSetMode() != ValueSetMode.CHECK_MEMERSHIP_ONLY) {
        if (system == null && !code.hasDisplay()) {
            // dealing with just a plain code (enum)
            system = systemForCodeInValueSet(code.getCode());
        }
        if (!code.hasSystem()) {
            if (options.isGuessSystem() && system == null && Utilities.isAbsoluteUrl(code.getCode())) {
                // this arises when using URIs bound to value sets
                system = "urn:ietf:rfc:3986";
            }
            code.setSystem(system);
        }
        inExpansion = checkExpansion(code);
        inInclude = checkInclude(code);
        CodeSystem cs = resolveCodeSystem(system);
        if (cs == null) {
            warningMessage = "Unable to resolve system " + system;
            if (!inExpansion) {
                if (valueset != null && valueset.hasExpansion()) {
                    return new ValidationResult(IssueSeverity.ERROR, context.formatMessage(I18nConstants.CODESYSTEM_CS_UNK_EXPANSION, valueset.getUrl(), code.getCode().toString(), code.getSystem()));
                } else {
                    throw new FHIRException(warningMessage);
                }
            }
        }
        if (cs != null && cs.hasSupplements()) {
            return new ValidationResult(IssueSeverity.ERROR, context.formatMessage(I18nConstants.CODESYSTEM_CS_NO_SUPPLEMENT, cs.getUrl()));
        }
        if (cs != null && cs.getContent() != CodeSystemContentMode.COMPLETE) {
            warningMessage = "Resolved system " + system + ", but the definition is not complete";
            if (!inExpansion && cs.getContent() != CodeSystemContentMode.FRAGMENT) {
                // we're going to give it a go if it's a fragment
                throw new FHIRException(warningMessage);
            }
        }
        if (cs != null) /*&& (cs.getContent() == CodeSystemContentMode.COMPLETE || cs.getContent() == CodeSystemContentMode.FRAGMENT)*/
        {
            if (!(cs.getContent() == CodeSystemContentMode.COMPLETE || cs.getContent() == CodeSystemContentMode.FRAGMENT)) {
                // we can't validate that here.
                throw new FHIRException("Unable to evaluate based on empty code system");
            }
            res = validateCode(code, cs);
        } else if (cs == null && valueset.hasExpansion() && inExpansion) {
            // we just take the value set as face value then
            res = new ValidationResult(system, new ConceptDefinitionComponent().setCode(code.getCode()).setDisplay(code.getDisplay()));
        } else {
            // disabled waiting for discussion
            throw new FHIRException("No try the server");
        }
    } else {
        inExpansion = checkExpansion(code);
        inInclude = checkInclude(code);
    }
    List<String> warnings = new ArrayList<>();
    // then, if we have a value set, we check it's in the value set
    if (valueset != null && options.getValueSetMode() != ValueSetMode.NO_MEMBERSHIP_CHECK) {
        if ((res == null || res.isOk())) {
            Boolean ok = codeInValueSet(system, code.getCode(), warnings);
            if (ok == null || !ok) {
                if (res == null) {
                    res = new ValidationResult((IssueSeverity) null, null);
                }
                if (!inExpansion && !inInclude) {
                    if (warnings != null) {
                        res.setMessage("Not in value set " + valueset.getUrl() + " (" + warnings + ")").setSeverity(IssueSeverity.ERROR);
                    } else {
                        res.setMessage("Not in value set " + valueset.getUrl()).setSeverity(IssueSeverity.ERROR);
                    }
                } else if (warningMessage != null) {
                    res = new ValidationResult(IssueSeverity.WARNING, context.formatMessage(I18nConstants.CODE_FOUND_IN_EXPANSION_HOWEVER_, warningMessage));
                } else if (inExpansion) {
                    res.setMessage("Code found in expansion, however: " + res.getMessage());
                } else if (inInclude) {
                    res.setMessage("Code found in include, however: " + res.getMessage());
                }
            }
        }
    }
    return res;
}
Also used : ConceptDefinitionComponent(org.hl7.fhir.r5.model.CodeSystem.ConceptDefinitionComponent) ArrayList(java.util.ArrayList) IssueSeverity(org.hl7.fhir.utilities.validation.ValidationMessage.IssueSeverity) ValidationResult(org.hl7.fhir.r5.context.IWorkerContext.ValidationResult) CodeSystem(org.hl7.fhir.r5.model.CodeSystem) FHIRException(org.hl7.fhir.exceptions.FHIRException)

Example 7 with IssueSeverity

use of org.hl7.fhir.utilities.validation.ValidationMessage.IssueSeverity in project org.hl7.fhir.core by hapifhir.

the class BaseValidator method txWarningForLaterRemoval.

/**
 * Test a rule and add a {@link IssueSeverity#WARNING} validation message if the validation fails. Also, keep track of it later in case we want to remove it if we find a required binding for this element later
 *
 * @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 txWarningForLaterRemoval(Object location, List<ValidationMessage> errors, String txLink, IssueType type, int line, int col, String path, boolean thePass, String msg, Object... theMessageArguments) {
    if (!thePass && doingWarnings()) {
        String nmsg = context.formatMessage(msg, theMessageArguments);
        ValidationMessage vmsg = new ValidationMessage(Source.TerminologyEngine, type, line, col, path, nmsg, IssueSeverity.WARNING).setTxLink(txLink).setMessageId(msg);
        if (checkMsgId(msg, vmsg)) {
            errors.add(vmsg);
        }
        trackedMessages.add(new TrackedLocationRelatedMessage(location, vmsg));
    }
    return thePass;
}
Also used : ValidationMessage(org.hl7.fhir.utilities.validation.ValidationMessage)

Example 8 with IssueSeverity

use of org.hl7.fhir.utilities.validation.ValidationMessage.IssueSeverity in project org.hl7.fhir.core by hapifhir.

the class BaseValidator method txWarning.

/**
 * 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 txWarning(List<ValidationMessage> errors, String txLink, IssueType type, int line, int col, String path, boolean thePass, String msg, Object... theMessageArguments) {
    if (!thePass && doingWarnings()) {
        String nmsg = context.formatMessage(msg, theMessageArguments);
        ValidationMessage vmsg = new ValidationMessage(Source.TerminologyEngine, type, line, col, path, nmsg, IssueSeverity.WARNING).setTxLink(txLink).setMessageId(msg);
        if (checkMsgId(msg, vmsg)) {
            errors.add(vmsg);
        }
    }
    return thePass;
}
Also used : ValidationMessage(org.hl7.fhir.utilities.validation.ValidationMessage)

Example 9 with IssueSeverity

use of org.hl7.fhir.utilities.validation.ValidationMessage.IssueSeverity in project org.hl7.fhir.core by hapifhir.

the class CanonicalResourceComparer method compareCodeableConceptList.

protected void compareCodeableConceptList(String name, List<CodeableConcept> left, List<CodeableConcept> right, Map<String, StructuralMatch<String>> comp, IssueSeverity level, CanonicalResourceComparison<? extends CanonicalResource> res, List<CodeableConcept> union, List<CodeableConcept> intersection) {
    List<CodeableConcept> matchR = new ArrayList<>();
    StructuralMatch<String> combined = new StructuralMatch<String>();
    for (CodeableConcept l : left) {
        CodeableConcept r = findCodeableConceptInList(right, l);
        if (r == null) {
            union.add(l);
            combined.getChildren().add(new StructuralMatch<String>(gen(l), vm(IssueSeverity.INFORMATION, "Removed the item '" + gen(l) + "'", fhirType() + "." + name, res.getMessages())));
        } else {
            matchR.add(r);
            union.add(r);
            intersection.add(r);
            StructuralMatch<String> sm = new StructuralMatch<String>(gen(l), gen(r));
            combined.getChildren().add(sm);
        }
    }
    for (CodeableConcept r : right) {
        if (!matchR.contains(r)) {
            union.add(r);
            combined.getChildren().add(new StructuralMatch<String>(vm(IssueSeverity.INFORMATION, "Added the item '" + gen(r) + "'", fhirType() + "." + name, res.getMessages()), gen(r)));
        }
    }
    comp.put(name, combined);
}
Also used : ArrayList(java.util.ArrayList) CodeableConcept(org.hl7.fhir.r4b.model.CodeableConcept)

Example 10 with IssueSeverity

use of org.hl7.fhir.utilities.validation.ValidationMessage.IssueSeverity in project org.hl7.fhir.core by hapifhir.

the class ResourceComparer method vm.

protected void vm(IssueSeverity level, String message, String path, List<ValidationMessage> genMessages, List<ValidationMessage> specMessages) {
    ValidationMessage vm = new ValidationMessage(Source.ProfileComparer, IssueType.INFORMATIONAL, path, message, level == IssueSeverity.NULL ? IssueSeverity.INFORMATION : level);
    genMessages.add(vm);
    if (specMessages != null) {
        specMessages.add(vm);
    }
}
Also used : ValidationMessage(org.hl7.fhir.utilities.validation.ValidationMessage)

Aggregations

ValidationMessage (org.hl7.fhir.utilities.validation.ValidationMessage)12 ArrayList (java.util.ArrayList)9 IssueSeverity (org.hl7.fhir.utilities.validation.ValidationMessage.IssueSeverity)9 FHIRFormatError (org.hl7.fhir.exceptions.FHIRFormatError)5 FHIRException (org.hl7.fhir.exceptions.FHIRException)4 JsonObject (com.google.gson.JsonObject)3 File (java.io.File)2 FileNotFoundException (java.io.FileNotFoundException)2 IOException (java.io.IOException)2 OperationOutcome (org.hl7.fhir.r4.model.OperationOutcome)2 ValidationResult (org.hl7.fhir.r4b.context.IWorkerContext.ValidationResult)2 ConceptDefinitionComponent (org.hl7.fhir.r4b.model.CodeSystem.ConceptDefinitionComponent)2 ValidationResult (org.hl7.fhir.r5.context.IWorkerContext.ValidationResult)2 ConceptDefinitionComponent (org.hl7.fhir.r5.model.CodeSystem.ConceptDefinitionComponent)2 TextFile (org.hl7.fhir.utilities.TextFile)2 JsonNull (com.google.gson.JsonNull)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 Meta (org.hl7.fhir.dstu3.model.Meta)1 OperationOutcome (org.hl7.fhir.dstu3.model.OperationOutcome)1 UriType (org.hl7.fhir.dstu3.model.UriType)1