Java Code Examples for org.hl7.fhir.utilities.validation.ValidationMessage.IssueSeverity#ERROR

The following examples show how to use org.hl7.fhir.utilities.validation.ValidationMessage.IssueSeverity#ERROR . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BaseWorkerContext.java    From org.hl7.fhir.core with Apache License 2.0 6 votes vote down vote up
private ValidationResult verifyCodeInExpansion(ValueSet vs, String system, String code,
  String display) {
  ValueSetExpansionContainsComponent cc = findCode(vs.getExpansion().getContains(), code);
  if (cc == null) {
    return new ValidationResult(IssueSeverity.ERROR,
      "Unknown Code " + code + " in " + vs.getUrl());
  }
  if (display == null) {
    return new ValidationResult(
      new ConceptDefinitionComponent().setCode(code).setDisplay(cc.getDisplay()));
  }
  if (cc.hasDisplay()) {
    if (display.equalsIgnoreCase(cc.getDisplay())) {
      return new ValidationResult(
        new ConceptDefinitionComponent().setCode(code).setDisplay(cc.getDisplay()));
    }
    return new ValidationResult(IssueSeverity.WARNING,
      "Display Name for " + code + " must be '" + cc.getDisplay() + "'",
      new ConceptDefinitionComponent().setCode(code).setDisplay(cc.getDisplay()));
  }
  return null;
}
 
Example 2
Source File: BaseWorkerContext.java    From org.hl7.fhir.core with Apache License 2.0 6 votes vote down vote up
private ValidationResult loadFromCache(String fn) throws FileNotFoundException, IOException {
  if (fn == null) {
    return null;
  }
  if (!(new File(fn).exists())) {
    return null;
  }
  String cnt = TextFile.fileToString(fn);
  if (cnt.startsWith("!error: ")) {
    return new ValidationResult(IssueSeverity.ERROR, cnt.substring(8));
  } else if (cnt.startsWith("!warning: ")) {
    return new ValidationResult(IssueSeverity.ERROR, cnt.substring(10));
  } else {
    return new ValidationResult(new ConceptDefinitionComponent().setDisplay(cnt));
  }
}
 
Example 3
Source File: BaseWorkerContext.java    From org.hl7.fhir.core with Apache License 2.0 6 votes vote down vote up
private ValidationResult serverValidateCode(Parameters pin) {
Parameters pout = txServer.operateType(ValueSet.class, "validate-code", pin);
boolean ok = false;
String message = "No Message returned";
String display = null;
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();
}
if (!ok)
  return new ValidationResult(IssueSeverity.ERROR, message);
else if (display != null)
  return new ValidationResult(new ConceptDefinitionComponent().setDisplay(display));
else
  return new ValidationResult(null);
}
 
Example 4
Source File: BaseWorkerContext.java    From org.hl7.fhir.core with Apache License 2.0 6 votes vote down vote up
private ValidationResult verifyCodeInCodeSystem(ValueSet vs, String system, String code, String display) {
  ConceptDefinitionComponent cc = findCodeInConcept(vs.getCodeSystem().getConcept(), code);
  if (cc == null)
    return new ValidationResult(IssueSeverity.ERROR, "Unknown Code "+code+" in "+vs.getCodeSystem().getSystem());
  if (display == null)
    return new ValidationResult(cc);
  CommaSeparatedStringBuilder b = new CommaSeparatedStringBuilder();
  if (cc.hasDisplay()) {
    b.append(cc.getDisplay());
    if (display.equalsIgnoreCase(cc.getDisplay()))
      return new ValidationResult(cc);
  }
  for (ConceptDefinitionDesignationComponent ds : cc.getDesignation()) {
    b.append(ds.getValue());
    if (display.equalsIgnoreCase(ds.getValue()))
      return new ValidationResult(cc);
  }
  return new ValidationResult(IssueSeverity.ERROR, "Display Name for "+code+" must be one of '"+b.toString()+"'");
}
 
Example 5
Source File: ProfileComparer.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
public String getErrorCount() {
  int c = 0;
  for (ValidationMessage vm : messages)
    if (vm.getLevel() == IssueSeverity.ERROR)
      c++;
  return Integer.toString(c);
}
 
Example 6
Source File: BaseWorkerContext.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
private ValidationResult verifyCodeInCodeSystem(CodeSystem cs, String system, String code,
  String display) throws Exception {
  ConceptDefinitionComponent cc = findCodeInConcept(cs.getConcept(), code);
  if (cc == null) {
    if (cs.getContent().equals(CodeSystem.CodeSystemContentMode.COMPLETE)) {
      return new ValidationResult(IssueSeverity.ERROR,
        "Unknown Code " + code + " in " + cs.getUrl());
    } else if (!cs.getContent().equals(CodeSystem.CodeSystemContentMode.NOTPRESENT)) {
      return new ValidationResult(IssueSeverity.WARNING,
        "Unknown Code " + code + " in partial code list of " + cs.getUrl());
    } else {
      return verifyCodeExternal(null,
        new Coding().setSystem(system).setCode(code).setDisplay(display), false);
    }
  }
  //
  //        return new ValidationResult(IssueSeverity.WARNING, "A definition was found for "+cs.getUrl()+", but it has no codes in the definition");
  //      return new ValidationResult(IssueSeverity.ERROR, "Unknown Code "+code+" in "+cs.getUrl());
  if (display == null) {
    return new ValidationResult(cc);
  }
  CommaSeparatedStringBuilder b = new CommaSeparatedStringBuilder();
  if (cc.hasDisplay()) {
    b.append(cc.getDisplay());
    if (display.equalsIgnoreCase(cc.getDisplay())) {
      return new ValidationResult(cc);
    }
  }
  for (ConceptDefinitionDesignationComponent ds : cc.getDesignation()) {
    b.append(ds.getValue());
    if (display.equalsIgnoreCase(ds.getValue())) {
      return new ValidationResult(cc);
    }
  }
  return new ValidationResult(IssueSeverity.WARNING,
    "Display Name for " + code + " must be one of '" + b.toString() + "'", cc);
}
 
Example 7
Source File: BaseWorkerContext.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
private ValidationResult verifyCodeInternal(ValueSet vs, CodeableConcept code) throws Exception {
  for (Coding c : code.getCoding()) {
    ValidationResult res = verifyCodeInternal(vs, c.getSystem(), c.getCode(), c.getDisplay());
    if (res.isOk()) {
      return res;
    }
  }
  if (code.getCoding().isEmpty()) {
    return new ValidationResult(IssueSeverity.ERROR, "None code provided");
  } else {
    return new ValidationResult(IssueSeverity.ERROR,
      "None of the codes are in the specified value set");
  }
}
 
Example 8
Source File: ParserBase.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
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));
}
 
Example 9
Source File: ProfileComparer.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
public String getErrorCount() {
  int c = 0;
  for (ValidationMessage vm : messages)
    if (vm.getLevel() == IssueSeverity.ERROR)
      c++;
  return Integer.toString(c);
}
 
Example 10
Source File: ParserBase.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
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));
}
 
Example 11
Source File: ParserBase.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
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));
}
 
Example 12
Source File: BaseWorkerContext.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
private ValidationResult verifyCodeInternal(ValueSet vs, CodeableConcept code) throws FileNotFoundException, ETooCostly, IOException {
  for (Coding c : code.getCoding()) {
    ValidationResult res = verifyCodeInternal(vs, c.getSystem(), c.getCode(), c.getDisplay());
    if (res.isOk())
      return res;
  }
  if (code.getCoding().isEmpty())
    return new ValidationResult(IssueSeverity.ERROR, "None code provided");
  else
    return new ValidationResult(IssueSeverity.ERROR, "None of the codes are in the specified value set");
}
 
Example 13
Source File: ComparisonTests.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
private void checkOutcomes(List<ValidationMessage> errors, JsonObject focus) {
  JsonObject output = focus.getAsJsonObject("output");
  int ec = 0;
  int wc = 0;
  int hc = 0;
  List<String> errLocs = new ArrayList<>();
  for (ValidationMessage vm : errors) {
    if (vm.getLevel() == IssueSeverity.FATAL || vm.getLevel() == IssueSeverity.ERROR) {
      ec++;
      if (PRINT_OUTPUT_TO_CONSOLE) {
        System.out.println(vm.getDisplay());
      }
      errLocs.add(vm.getLocation());
    }
    if (vm.getLevel() == IssueSeverity.WARNING) {
      wc++;
      if (PRINT_OUTPUT_TO_CONSOLE) {
        System.out.println(vm.getDisplay());
      }
    }
    if (vm.getLevel() == IssueSeverity.INFORMATION) {
      hc++;
      if (PRINT_OUTPUT_TO_CONSOLE) {
        System.out.println(vm.getDisplay());
      }
    }
  }
  Assertions.assertEquals(output.get("errorCount").getAsInt(), ec, "Expected " + Integer.toString(output.get("errorCount").getAsInt()) + " errors, but found " + Integer.toString(ec) + ".");
  if (output.has("warningCount"))
    Assertions.assertEquals(output.get("warningCount").getAsInt(), wc, "Expected " + Integer.toString(output.get("warningCount").getAsInt()) + " warnings, but found " + Integer.toString(wc) + ".");
  if (output.has("infoCount"))
    Assertions.assertEquals(output.get("infoCount").getAsInt(), hc, "Expected " + Integer.toString(output.get("infoCount").getAsInt()) + " hints, but found " + Integer.toString(hc) + ".");
}
 
Example 14
Source File: ToolingExtensions.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
private static IssueSeverity mapSeverity(org.hl7.fhir.r4.model.OperationOutcome.IssueSeverity severity) {
  switch (severity) {
  case ERROR: return IssueSeverity.ERROR;
  case FATAL: return IssueSeverity.FATAL;
  case INFORMATION: return IssueSeverity.INFORMATION;
  case WARNING: return IssueSeverity.WARNING;
  default: return null;
  }
}
 
Example 15
Source File: ParserBase.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
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));
}
 
Example 16
Source File: ToolingExtensions.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
private static IssueSeverity mapSeverity(org.hl7.fhir.r5.model.OperationOutcome.IssueSeverity severity) {
  switch (severity) {
  case ERROR: return IssueSeverity.ERROR;
  case FATAL: return IssueSeverity.FATAL;
  case INFORMATION: return IssueSeverity.INFORMATION;
  case WARNING: return IssueSeverity.WARNING;
  default: return null;
  }
}
 
Example 17
Source File: StructuralMatch.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
public boolean hasErrors() {
  for (ValidationMessage vm : messages) {
    if (vm.getLevel() == IssueSeverity.ERROR) {
      return true;
    }
  }
  return false;
}
 
Example 18
Source File: ValidationSupportSTU3.java    From synthea with Apache License 2.0 4 votes vote down vote up
@Override
public CodeValidationResult validateCode(FhirContext theContext, String theCodeSystem,
    String theCode, String theDisplay, String theValueSetUrl) {
  IssueSeverity severity = IssueSeverity.WARNING;
  String message = "Unsupported CodeSystem";

  if (isCodeSystemSupported(theContext, theCodeSystem)) {
    severity = IssueSeverity.ERROR;
    message = "Code not found";

    CodeSystem cs = codeSystemMap.get(theCodeSystem);
    for (ConceptDefinitionComponent def : cs.getConcept()) {
      if (def.getCode().equals(theCode)) {
        if (def.getDisplay() != null && theDisplay != null) {
          if (def.getDisplay().equals(theDisplay)) {
            severity = IssueSeverity.INFORMATION;
            message = "Validated Successfully";
          } else {
            severity = IssueSeverity.WARNING;
            message = "Validated Code; Display mismatch";
          }
        } else {
          severity = IssueSeverity.WARNING;
          message = "Validated Code; No display";
        }
      }
    }
  }

  ValueSet vs = fetchValueSet(theContext, theValueSetUrl);
  if (vs != null && vs.hasCompose() && vs.getCompose().hasExclude()) {
    for (ConceptSetComponent exclude : vs.getCompose().getExclude()) {
      if (exclude.getSystem().equals(theCodeSystem) && exclude.hasConcept()) {
        for (ConceptReferenceComponent concept : exclude.getConcept()) {
          if (concept.getCode().equals(theCode)) {
            severity = IssueSeverity.ERROR;
            message += "; Code Excluded from ValueSet";
          }
        }
      }
    }
  }

  return new CodeValidationResult(severity, message);
}
 
Example 19
Source File: BaseWorkerContext.java    From org.hl7.fhir.core with Apache License 2.0 4 votes vote down vote up
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;
}
 
Example 20
Source File: ValidationSupportR4.java    From synthea with Apache License 2.0 4 votes vote down vote up
@Override
public CodeValidationResult validateCode(FhirContext theContext, String theCodeSystem,
    String theCode, String theDisplay, String theValueSetUrl) {
  IssueSeverity severity = IssueSeverity.WARNING;
  String message = "Unsupported CodeSystem";

  if (isCodeSystemSupported(theContext, theCodeSystem)) {
    severity = IssueSeverity.ERROR;
    message = "Code not found";

    CodeSystem cs = codeSystemMap.get(theCodeSystem);
    for (ConceptDefinitionComponent def : cs.getConcept()) {
      if (def.getCode().equals(theCode)) {
        if (def.getDisplay() != null && theDisplay != null) {
          if (def.getDisplay().equals(theDisplay)) {
            severity = IssueSeverity.INFORMATION;
            message = "Validated Successfully";
          } else {
            severity = IssueSeverity.WARNING;
            message = "Validated Code; Display mismatch";
          }
        } else {
          severity = IssueSeverity.WARNING;
          message = "Validated Code; No display";
        }
      }
    }
  }

  ValueSet vs = fetchValueSet(theContext, theValueSetUrl);
  if (vs != null && vs.hasCompose() && vs.getCompose().hasExclude()) {
    for (ConceptSetComponent exclude : vs.getCompose().getExclude()) {
      if (exclude.getSystem().equals(theCodeSystem) && exclude.hasConcept()) {
        for (ConceptReferenceComponent concept : exclude.getConcept()) {
          if (concept.getCode().equals(theCode)) {
            severity = IssueSeverity.ERROR;
            message += "; Code Excluded from ValueSet";
          }
        }
      }
    }
  }

  return new CodeValidationResult(severity, message);
}