Search in sources :

Example 1 with IssueSeverity

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

the class ScrTest method verifyOperationOutcome.

private void verifyOperationOutcome(String responseBody, IssueType code, IssueSeverity severity) {
    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);
}
Also used : OperationOutcome(org.hl7.fhir.r4.model.OperationOutcome)

Example 2 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 3 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 4 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")) {
            int c = 0;
            try {
                String title = fn.substring(0, fn.lastIndexOf("."));
                NamedCache nc = new NamedCache();
                nc.name = title;
                caches.put(title, nc);
                String src = TextFile.fileToString(Utilities.path(folder, fn));
                if (src.startsWith("?"))
                    src = src.substring(1);
                int i = src.indexOf(ENTRY_MARKER);
                while (i > -1) {
                    c++;
                    String s = src.substring(0, i);
                    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 {
                            String t = loadJS(o.get("severity"));
                            IssueSeverity severity = t == null ? null : IssueSeverity.fromCode(t);
                            String display = loadJS(o.get("display"));
                            String code = loadJS(o.get("code"));
                            String system = loadJS(o.get("system"));
                            String definition = loadJS(o.get("definition"));
                            t = loadJS(o.get("class"));
                            TerminologyServiceErrorClass errorClass = t == null ? null : TerminologyServiceErrorClass.valueOf(t);
                            ce.v = new ValidationResult(severity, error, system, new ConceptDefinitionComponent().setDisplay(display).setDefinition(definition).setCode(code)).setErrorClass(errorClass);
                        }
                        nc.map.put(String.valueOf(hashNWS(ce.request)), ce);
                        nc.list.add(ce);
                    }
                }
            } catch (Exception e) {
                throw new FHIRException("Error loading " + fn + ": " + e.getMessage() + " entry " + c, e);
            }
        }
    }
}
Also used : TerminologyServiceErrorClass(org.hl7.fhir.r4b.terminologies.ValueSetExpander.TerminologyServiceErrorClass) JsonObject(com.google.gson.JsonObject) ValidationResult(org.hl7.fhir.r4b.context.IWorkerContext.ValidationResult) FHIRException(org.hl7.fhir.exceptions.FHIRException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) FHIRException(org.hl7.fhir.exceptions.FHIRException) ConceptDefinitionComponent(org.hl7.fhir.r4b.model.CodeSystem.ConceptDefinitionComponent) IssueSeverity(org.hl7.fhir.utilities.validation.ValidationMessage.IssueSeverity) ValueSetExpansionOutcome(org.hl7.fhir.r4b.terminologies.ValueSetExpander.ValueSetExpansionOutcome) File(java.io.File) TextFile(org.hl7.fhir.utilities.TextFile) JsonParser(org.hl7.fhir.r4b.formats.JsonParser)

Example 5 with IssueSeverity

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

the class TerminologyCache method getCacheEntry.

private CacheEntry getCacheEntry(String request, String resultString) throws IOException {
    CacheEntry ce = new CacheEntry();
    ce.persistent = true;
    ce.request = request;
    boolean e = resultString.charAt(0) == 'e';
    resultString = resultString.substring(3);
    JsonObject o = (JsonObject) new com.google.gson.JsonParser().parse(resultString);
    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 {
        String t = loadJS(o.get("severity"));
        IssueSeverity severity = t == null ? null : IssueSeverity.fromCode(t);
        String display = loadJS(o.get("display"));
        String code = loadJS(o.get("code"));
        String system = loadJS(o.get("system"));
        String definition = loadJS(o.get("definition"));
        t = loadJS(o.get("class"));
        TerminologyServiceErrorClass errorClass = t == null ? null : TerminologyServiceErrorClass.valueOf(t);
        ce.v = new ValidationResult(severity, error, system, new ConceptDefinitionComponent().setDisplay(display).setDefinition(definition).setCode(code)).setErrorClass(errorClass);
    }
    return ce;
}
Also used : TerminologyServiceErrorClass(org.hl7.fhir.r5.terminologies.ValueSetExpander.TerminologyServiceErrorClass) ConceptDefinitionComponent(org.hl7.fhir.r5.model.CodeSystem.ConceptDefinitionComponent) IssueSeverity(org.hl7.fhir.utilities.validation.ValidationMessage.IssueSeverity) JsonObject(com.google.gson.JsonObject) ValueSetExpansionOutcome(org.hl7.fhir.r5.terminologies.ValueSetExpander.ValueSetExpansionOutcome) ValidationResult(org.hl7.fhir.r5.context.IWorkerContext.ValidationResult) JsonParser(org.hl7.fhir.r5.formats.JsonParser)

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