Search in sources :

Example 11 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.r5.model.CodeableConcept)

Example 12 with IssueSeverity

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

the class CanonicalResourceComparer method compareCanonicalList.

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

Example 13 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)

Example 14 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) {
                    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.r4b.model.CodeSystem.ConceptDefinitionComponent) ArrayList(java.util.ArrayList) IssueSeverity(org.hl7.fhir.utilities.validation.ValidationMessage.IssueSeverity) ValidationResult(org.hl7.fhir.r4b.context.IWorkerContext.ValidationResult) CodeSystem(org.hl7.fhir.r4b.model.CodeSystem) FHIRException(org.hl7.fhir.exceptions.FHIRException)

Example 15 with IssueSeverity

use of org.hl7.fhir.utilities.validation.ValidationMessage.IssueSeverity in project fhir-bridge by ehrbase.

the class ValidationUtils method addIssue.

public static void addIssue(OperationOutcome outcome, IssueSeverity severity, String diagnostics, String location) {
    Assert.notNull(outcome, "OperationOutcome must not be null");
    Assert.notNull(outcome, "IssueSeverity must not be null");
    var issue = new OperationOutcomeIssueComponent().setSeverity(severity).setCode(OperationOutcome.IssueType.PROCESSING).setDiagnostics(diagnostics);
    if (location != null) {
        issue.addLocation(location);
    }
    outcome.addIssue(issue);
}
Also used : OperationOutcomeIssueComponent(org.hl7.fhir.r4.model.OperationOutcome.OperationOutcomeIssueComponent)

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