Search in sources :

Example 6 with TerminologyServiceErrorClass

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

the class BaseWorkerContext method serverValidateCode.

private ValidationResult serverValidateCode(Parameters pin, boolean doCache) throws Exception {
    if (noTerminologyServer) {
        return new ValidationResult(null, null, TerminologyServiceErrorClass.NOSERVICE);
    }
    String cacheName = doCache ? generateCacheName(pin) : null;
    ValidationResult res = loadFromCache(cacheName);
    if (res != null) {
        return res;
    }
    tlog("Terminology Server: $validate-code " + describeValidationParameters(pin));
    for (ParametersParameterComponent pp : pin.getParameter()) {
        if (pp.getName().equals("profile")) {
            throw new Error("Can only specify profile in the context");
        }
    }
    if (expProfile == null) {
        throw new Exception("No ExpansionProfile provided");
    }
    pin.addParameter().setName("profile").setResource(expProfile);
    Parameters pout = txServer.operateType(ValueSet.class, "validate-code", 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) {
        res = new ValidationResult(IssueSeverity.ERROR, message, err);
    } else if (display != null) {
        res = new ValidationResult(new ConceptDefinitionComponent().setDisplay(display));
    } else {
        res = new ValidationResult(new ConceptDefinitionComponent());
    }
    saveToCache(res, cacheName);
    return res;
}
Also used : TerminologyServiceErrorClass(org.hl7.fhir.dstu3.terminologies.ValueSetExpander.TerminologyServiceErrorClass) Parameters(org.hl7.fhir.dstu3.model.Parameters) StringType(org.hl7.fhir.dstu3.model.StringType) IssueType(org.hl7.fhir.utilities.validation.ValidationMessage.IssueType) BooleanType(org.hl7.fhir.dstu3.model.BooleanType) FHIRException(org.hl7.fhir.exceptions.FHIRException) TerminologyServiceException(org.hl7.fhir.exceptions.TerminologyServiceException) FileNotFoundException(java.io.FileNotFoundException) NoTerminologyServiceException(org.hl7.fhir.exceptions.NoTerminologyServiceException) JsonSyntaxException(com.google.gson.JsonSyntaxException) IOException(java.io.IOException) FHIRException(org.hl7.fhir.exceptions.FHIRException) ConceptDefinitionComponent(org.hl7.fhir.dstu3.model.CodeSystem.ConceptDefinitionComponent) ParametersParameterComponent(org.hl7.fhir.dstu3.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