Search in sources :

Example 16 with IssueSeverity

use of org.hl7.fhir.utilities.validation.ValidationMessage.IssueSeverity in project summary-care-record-api by NHSDigital.

the class GetScrControllerTest method verifyOperationOutcome.

private void verifyOperationOutcome(String responseBody, IssueType code, IssueSeverity severity, String details) {
    var response = parser.parseResource(responseBody);
    assertThat(response).isInstanceOf(OperationOutcome.class);
    OperationOutcome operationOutcome = (OperationOutcome) response;
    assertThat(operationOutcome.getIssueFirstRep().getCode()).isEqualTo(code);
    assertThat(operationOutcome.getIssueFirstRep().getSeverity()).isEqualTo(severity);
    assertThat(operationOutcome.getIssueFirstRep().getDetails().getText()).isEqualTo(details);
}
Also used : OperationOutcome(org.hl7.fhir.r4.model.OperationOutcome)

Example 17 with IssueSeverity

use of org.hl7.fhir.utilities.validation.ValidationMessage.IssueSeverity in project kindling by HL7.

the class RDFValidator method assertion.

public List<ValidationMessage> assertion(String sparql, String id, String rowType, String message, String description, IssueSeverity level) {
    List<ValidationMessage> msgs = new ArrayList<ValidationMessage>();
    Query query = QueryFactory.create(prefixes + sparql);
    // Execute the query and obtain results
    QueryExecution qe = QueryExecutionFactory.create(query, model);
    ResultSet results = qe.execSelect();
    if (results.hasNext()) {
        // Output query results
        ByteArrayOutputStream ba = new ByteArrayOutputStream();
        msgs.add(new ValidationMessage(Source.Publisher, IssueType.INVALID, -1, -1, "rdf:" + id, description, level));
        while (results.hasNext()) {
            QuerySolution row = results.next();
            String cell = row.getResource(results.getResultVars().get(0)).getURI();
            if (cell.startsWith("http://hl7.org/fhir/"))
                cell = cell.substring(20);
            msgs.add(new ValidationMessage(Source.Publisher, IssueType.INVALID, -1, -1, "rdf:" + id, cell + ": " + message, level));
        }
    }
    // Important - free up resources used running the query
    qe.close();
    return msgs;
}
Also used : ValidationMessage(org.hl7.fhir.utilities.validation.ValidationMessage) ArrayList(java.util.ArrayList) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 18 with IssueSeverity

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

the class ParserBase method logError.

public void logError(int line, int col, String path, IssueType type, String message, IssueSeverity level) throws FHIRFormatError {
    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 IssueSeverity

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

the class TerminologyCache method load.

private void load() throws FHIRException {
    for (String fn : new File(folder).list()) {
        if (fn.endsWith(".cache") && !fn.equals("validation.cache")) {
            try {
                // System.out.println("Load "+fn);
                String title = fn.substring(0, fn.lastIndexOf("."));
                NamedCache nc = new NamedCache();
                nc.name = title;
                caches.put(title, nc);
                System.out.print(" - load " + title + ".cache");
                String src = TextFile.fileToString(Utilities.path(folder, fn));
                if (src.startsWith("?"))
                    src = src.substring(1);
                int i = src.indexOf(ENTRY_MARKER);
                while (i > -1) {
                    String s = src.substring(0, i);
                    System.out.print(".");
                    src = src.substring(i + ENTRY_MARKER.length() + 1);
                    i = src.indexOf(ENTRY_MARKER);
                    if (!Utilities.noString(s)) {
                        int j = s.indexOf(BREAK);
                        String q = s.substring(0, j);
                        String p = s.substring(j + BREAK.length() + 1).trim();
                        CacheEntry ce = new CacheEntry();
                        ce.persistent = true;
                        ce.request = q;
                        boolean e = p.charAt(0) == 'e';
                        p = p.substring(3);
                        JsonObject o = (JsonObject) new com.google.gson.JsonParser().parse(p);
                        String error = loadJS(o.get("error"));
                        if (e) {
                            if (o.has("valueSet"))
                                ce.e = new ValueSetExpansionOutcome((ValueSet) new JsonParser().parse(o.getAsJsonObject("valueSet")), error, TerminologyServiceErrorClass.UNKNOWN);
                            else
                                ce.e = new ValueSetExpansionOutcome(error, TerminologyServiceErrorClass.UNKNOWN);
                        } else {
                            IssueSeverity severity = o.get("severity") instanceof JsonNull ? null : IssueSeverity.fromCode(o.get("severity").getAsString());
                            String display = loadJS(o.get("display"));
                            ce.v = new ValidationResult(severity, error, new ConceptDefinitionComponent().setDisplay(display));
                        }
                        nc.map.put(String.valueOf(hashNWS(ce.request)), ce);
                        nc.list.add(ce);
                    }
                }
                System.out.println("done");
            } catch (Exception e) {
                throw new FHIRException("Error loading " + fn + ": " + e.getMessage(), e);
            }
        }
    }
}
Also used : JsonObject(com.google.gson.JsonObject) ValidationResult(org.hl7.fhir.r4.context.IWorkerContext.ValidationResult) FHIRException(org.hl7.fhir.exceptions.FHIRException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) FHIRException(org.hl7.fhir.exceptions.FHIRException) JsonNull(com.google.gson.JsonNull) ConceptDefinitionComponent(org.hl7.fhir.r4.model.CodeSystem.ConceptDefinitionComponent) IssueSeverity(org.hl7.fhir.utilities.validation.ValidationMessage.IssueSeverity) ValueSetExpansionOutcome(org.hl7.fhir.r4.terminologies.ValueSetExpander.ValueSetExpansionOutcome) File(java.io.File) TextFile(org.hl7.fhir.utilities.TextFile) JsonParser(org.hl7.fhir.r4.formats.JsonParser)

Example 20 with IssueSeverity

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

the class CanonicalResourceComparer method compareCodeList.

protected void compareCodeList(String name, List<CodeType> left, List<CodeType> right, Map<String, StructuralMatch<String>> comp, IssueSeverity level, CanonicalResourceComparison<? extends CanonicalResource> res, List<CodeType> union, List<CodeType> intersection) {
    List<CodeType> matchR = new ArrayList<>();
    StructuralMatch<String> combined = new StructuralMatch<String>();
    for (CodeType l : left) {
        CodeType r = findCodeInList(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 (CodeType 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) CodeType(org.hl7.fhir.r5.model.CodeType)

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