Search in sources :

Example 1 with TerminologyServiceErrorClass

use of org.hl7.fhir.r4b.terminologies.ValueSetExpander.TerminologyServiceErrorClass 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 2 with TerminologyServiceErrorClass

use of org.hl7.fhir.r4b.terminologies.ValueSetExpander.TerminologyServiceErrorClass in project org.hl7.fhir.core by hapifhir.

the class BaseWorkerContext method processValidationResult.

public ValidationResult processValidationResult(Parameters pOut) {
    boolean ok = false;
    String message = "No Message returned";
    String display = null;
    String system = null;
    String code = null;
    TerminologyServiceErrorClass err = TerminologyServiceErrorClass.UNKNOWN;
    for (ParametersParameterComponent p : pOut.getParameter()) {
        if (p.hasValue()) {
            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("system")) {
                system = ((StringType) p.getValue()).getValue();
            } else if (p.getName().equals("code")) {
                code = ((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.NOTFOUND) {
                        err = TerminologyServiceErrorClass.CODESYSTEM_UNSUPPORTED;
                    } else if (it == IssueType.NOTSUPPORTED) {
                        err = TerminologyServiceErrorClass.VALUESET_UNSUPPORTED;
                    } else {
                        err = null;
                    }
                } catch (FHIRException e) {
                }
            }
        }
    }
    if (!ok) {
        return new ValidationResult(IssueSeverity.ERROR, message + " (from " + txClient.getAddress() + ")", err).setTxLink(txLog.getLastId());
    } else if (message != null && !message.equals("No Message returned")) {
        return new ValidationResult(IssueSeverity.WARNING, message + " (from " + txClient.getAddress() + ")", system, new ConceptDefinitionComponent().setDisplay(display).setCode(code)).setTxLink(txLog.getLastId());
    } else if (display != null) {
        return new ValidationResult(system, new ConceptDefinitionComponent().setDisplay(display).setCode(code)).setTxLink(txLog.getLastId());
    } else {
        return new ValidationResult(system, new ConceptDefinitionComponent().setCode(code)).setTxLink(txLog.getLastId());
    }
}
Also used : TerminologyServiceErrorClass(org.hl7.fhir.r5.terminologies.ValueSetExpander.TerminologyServiceErrorClass) ConceptDefinitionComponent(org.hl7.fhir.r5.model.CodeSystem.ConceptDefinitionComponent) StringType(org.hl7.fhir.r5.model.StringType) IssueType(org.hl7.fhir.utilities.validation.ValidationMessage.IssueType) BooleanType(org.hl7.fhir.r5.model.BooleanType) FHIRException(org.hl7.fhir.exceptions.FHIRException) ParametersParameterComponent(org.hl7.fhir.r5.model.Parameters.ParametersParameterComponent)

Example 3 with TerminologyServiceErrorClass

use of org.hl7.fhir.r4b.terminologies.ValueSetExpander.TerminologyServiceErrorClass 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)

Example 4 with TerminologyServiceErrorClass

use of org.hl7.fhir.r4b.terminologies.ValueSetExpander.TerminologyServiceErrorClass in project org.hl7.fhir.core by hapifhir.

the class BaseWorkerContext method validateOnServer.

private ValidationResult validateOnServer(ValueSet vs, Parameters pin) throws FHIRException {
    if (vs != null)
        pin.addParameter().setName("valueSet").setResource(vs);
    for (ParametersParameterComponent pp : pin.getParameter()) if (pp.getName().equals("profile"))
        throw new Error("Can only specify profile in the context");
    if (expParameters == null)
        throw new Error("No ExpansionProfile provided");
    pin.addParameter().setName("profile").setResource(expParameters);
    txLog.clearLastId();
    Parameters pOut;
    if (vs == null)
        pOut = txClient.validateCS(pin);
    else
        pOut = txClient.validateVS(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)
        return new ValidationResult(IssueSeverity.ERROR, message, err).setTxLink(txLog.getLastId()).setTxLink(txLog.getLastId());
    else if (message != null && !message.equals("No Message returned"))
        return new ValidationResult(IssueSeverity.WARNING, message, new ConceptDefinitionComponent().setDisplay(display)).setTxLink(txLog.getLastId()).setTxLink(txLog.getLastId());
    else if (display != null)
        return new ValidationResult(new ConceptDefinitionComponent().setDisplay(display)).setTxLink(txLog.getLastId()).setTxLink(txLog.getLastId());
    else
        return new ValidationResult(new ConceptDefinitionComponent()).setTxLink(txLog.getLastId()).setTxLink(txLog.getLastId());
}
Also used : TerminologyServiceErrorClass(org.hl7.fhir.r4.terminologies.ValueSetExpander.TerminologyServiceErrorClass) ConceptDefinitionComponent(org.hl7.fhir.r4.model.CodeSystem.ConceptDefinitionComponent) IssueType(org.hl7.fhir.utilities.validation.ValidationMessage.IssueType) FHIRException(org.hl7.fhir.exceptions.FHIRException) ParametersParameterComponent(org.hl7.fhir.r4.model.Parameters.ParametersParameterComponent)

Example 5 with TerminologyServiceErrorClass

use of org.hl7.fhir.r4b.terminologies.ValueSetExpander.TerminologyServiceErrorClass in project org.hl7.fhir.core by hapifhir.

the class BaseWorkerContext method processValidationResult.

public ValidationResult processValidationResult(Parameters pOut) {
    boolean ok = false;
    String message = "No Message returned";
    String display = null;
    String system = null;
    String code = null;
    TerminologyServiceErrorClass err = TerminologyServiceErrorClass.UNKNOWN;
    for (ParametersParameterComponent p : pOut.getParameter()) {
        if (p.hasValue()) {
            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("system")) {
                system = ((StringType) p.getValue()).getValue();
            } else if (p.getName().equals("code")) {
                code = ((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.NOTFOUND) {
                        err = TerminologyServiceErrorClass.CODESYSTEM_UNSUPPORTED;
                    } else if (it == IssueType.NOTSUPPORTED) {
                        err = TerminologyServiceErrorClass.VALUESET_UNSUPPORTED;
                    } else {
                        err = null;
                    }
                } catch (FHIRException e) {
                }
            }
        }
    }
    if (!ok) {
        return new ValidationResult(IssueSeverity.ERROR, message + " (from " + txClient.getAddress() + ")", err).setTxLink(txLog.getLastId());
    } else if (message != null && !message.equals("No Message returned")) {
        return new ValidationResult(IssueSeverity.WARNING, message + " (from " + txClient.getAddress() + ")", system, new ConceptDefinitionComponent().setDisplay(display).setCode(code)).setTxLink(txLog.getLastId());
    } else if (display != null) {
        return new ValidationResult(system, new ConceptDefinitionComponent().setDisplay(display).setCode(code)).setTxLink(txLog.getLastId());
    } else {
        return new ValidationResult(system, new ConceptDefinitionComponent().setCode(code)).setTxLink(txLog.getLastId());
    }
}
Also used : TerminologyServiceErrorClass(org.hl7.fhir.r4b.terminologies.ValueSetExpander.TerminologyServiceErrorClass) ConceptDefinitionComponent(org.hl7.fhir.r4b.model.CodeSystem.ConceptDefinitionComponent) StringType(org.hl7.fhir.r4b.model.StringType) IssueType(org.hl7.fhir.utilities.validation.ValidationMessage.IssueType) BooleanType(org.hl7.fhir.r4b.model.BooleanType) FHIRException(org.hl7.fhir.exceptions.FHIRException) ParametersParameterComponent(org.hl7.fhir.r4b.model.Parameters.ParametersParameterComponent)

Aggregations

FHIRException (org.hl7.fhir.exceptions.FHIRException)5 IssueType (org.hl7.fhir.utilities.validation.ValidationMessage.IssueType)4 JsonObject (com.google.gson.JsonObject)2 FileNotFoundException (java.io.FileNotFoundException)2 IOException (java.io.IOException)2 ConceptDefinitionComponent (org.hl7.fhir.r4b.model.CodeSystem.ConceptDefinitionComponent)2 TerminologyServiceErrorClass (org.hl7.fhir.r4b.terminologies.ValueSetExpander.TerminologyServiceErrorClass)2 ConceptDefinitionComponent (org.hl7.fhir.r5.model.CodeSystem.ConceptDefinitionComponent)2 TerminologyServiceErrorClass (org.hl7.fhir.r5.terminologies.ValueSetExpander.TerminologyServiceErrorClass)2 IssueSeverity (org.hl7.fhir.utilities.validation.ValidationMessage.IssueSeverity)2 JsonSyntaxException (com.google.gson.JsonSyntaxException)1 File (java.io.File)1 BooleanType (org.hl7.fhir.dstu3.model.BooleanType)1 ConceptDefinitionComponent (org.hl7.fhir.dstu3.model.CodeSystem.ConceptDefinitionComponent)1 Parameters (org.hl7.fhir.dstu3.model.Parameters)1 ParametersParameterComponent (org.hl7.fhir.dstu3.model.Parameters.ParametersParameterComponent)1 StringType (org.hl7.fhir.dstu3.model.StringType)1 TerminologyServiceErrorClass (org.hl7.fhir.dstu3.terminologies.ValueSetExpander.TerminologyServiceErrorClass)1 NoTerminologyServiceException (org.hl7.fhir.exceptions.NoTerminologyServiceException)1 TerminologyServiceException (org.hl7.fhir.exceptions.TerminologyServiceException)1