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

The following examples show how to use org.hl7.fhir.utilities.validation.ValidationMessage.IssueSeverity#FATAL . 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
@Override
public ValidationResult validateCode(String system, String code, String display, ValueSet vs) {
  try {
    if (system == null && display == null) {
      return verifyCodeInternal(vs, code);
    }
    if ((codeSystems.containsKey(system) && codeSystems.get(system) != null) || vs
      .hasExpansion()) {
      return verifyCodeInternal(vs, system, code, display);
    } else {
      return verifyCodeExternal(vs,
        new Coding().setSystem(system).setCode(code).setDisplay(display), true);
    }
  } catch (Exception e) {
    return new ValidationResult(IssueSeverity.FATAL,
      "Error validating code \"" + code + "\" in system \"" + system + "\": " + e.getMessage(),
      TerminologyServiceErrorClass.SERVER_ERROR);
  }
}
 
Example 2
Source File: BaseWorkerContext.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
@Override
public ValidationResult validateCode(String system, String code, String display, ConceptSetComponent vsi) {
  try {
    ValueSet vs = new ValueSet().setUrl(Utilities.makeUuidUrn());
    vs.getCompose().addInclude(vsi);
    return verifyCodeExternal(vs, new Coding().setSystem(system).setCode(code).setDisplay(display), true);
  } catch (Exception e) {
    return new ValidationResult(IssueSeverity.FATAL, "Error validating code \""+code+"\" in system \""+system+"\": "+e.getMessage());
  }
}
 
Example 3
Source File: SimpleWorkerContext.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
private void seeProfile(String url, StructureDefinition p) throws FHIRException {
   if (Utilities.noString(url))
     url = p.getUrl();
   if (!p.hasSnapshot()) {
     if (!p.hasBaseDefinition())
       throw new DefinitionException("Profile "+p.getName()+" ("+p.getUrl()+") has no base and no snapshot");
     StructureDefinition sd = fetchResource(StructureDefinition.class, p.getBaseDefinition());
     if (sd == null)
       throw new DefinitionException("Profile "+p.getName()+" ("+p.getUrl()+") base "+p.getBaseDefinition()+" could not be resolved");
     List<ValidationMessage> msgs = new ArrayList<ValidationMessage>();
     ProfileUtilities pu = new ProfileUtilities(this, msgs, this);
     pu.generateSnapshot(sd, p, p.getUrl(), p.getName());
     for (ValidationMessage msg : msgs) {
       if (msg.getLevel() == IssueSeverity.ERROR || msg.getLevel() == IssueSeverity.FATAL)
         throw new DefinitionException("Profile "+p.getName()+" ("+p.getUrl()+"). Error generating snapshot: "+msg.getMessage());
     }
     if (!p.hasSnapshot())
       throw new DefinitionException("Profile "+p.getName()+" ("+p.getUrl()+"). Error generating snapshot");
     pu = null;
   }
	if (structures.containsKey(p.getUrl()))
		throw new DefinitionException("Duplicate structures " + p.getUrl());
	structures.put(p.getId(), p);
	structures.put(p.getUrl(), p);
	if (!p.getUrl().equals(url))
		structures.put(url, p);
}
 
Example 4
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 5
Source File: BaseWorkerContext.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
@Override
public ValidationResult validateCode(String system, String code, String display,
  ConceptSetComponent vsi) {
  try {
    ValueSet vs = new ValueSet();
    vs.setUrl(Utilities.makeUuidUrn());
    vs.getCompose().addInclude(vsi);
    return verifyCodeExternal(vs,
      new Coding().setSystem(system).setCode(code).setDisplay(display), true);
  } catch (Exception e) {
    return new ValidationResult(IssueSeverity.FATAL,
      "Error validating code \"" + code + "\" in system \"" + system + "\": " + e.getMessage());
  }
}
 
Example 6
Source File: BaseWorkerContext.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
@Override
public ValidationResult validateCode(String system, String code, String display) {
  try {
    if (codeSystems.containsKey(system) && codeSystems.get(system) != null) {
      return verifyCodeInCodeSystem(codeSystems.get(system), system, code, display);
    } else {
      return verifyCodeExternal(null,
        new Coding().setSystem(system).setCode(code).setDisplay(display), false);
    }
  } catch (Exception e) {
    return new ValidationResult(IssueSeverity.FATAL,
      "Error validating code \"" + code + "\" in system \"" + system + "\": " + e.getMessage());
  }
}
 
Example 7
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 8
Source File: ArgonautConverter.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
private void validate(byte[] src, String url, Resource resource, Stats stats) throws Exception {
		if (!WANT_VALIDATE)
			return;
		if (url == null)
			url = "http://hl7.org/fhir/StructureDefinition/"+resource.getResourceType().toString();
		StructureDefinition def = context.fetchResource(StructureDefinition.class, url);
		if (def == null)
			throw new Exception("Unable to find Structure Definition "+url);

//		validator.reset();
//		validator.setProfile(def);
//		validator.setSource(src);
//		validator.process();
		List<ValidationMessage> msgs = null; // validator.getOutputs();
		boolean ok = false;
		boolean first = true;
		for (ValidationMessage m : msgs) {
			if (m.getLevel() == IssueSeverity.ERROR && !msgOk(m.getMessage())) {
				if (first) {
					System.out.println("  validate "+resource.getId()+".xml against "+url);
					first = false;
				}
				System.out.println("    "+m.getLevel().toCode()+": "+m.getMessage()+" @ "+m.getLocation());
				if (m.getLevel() == IssueSeverity.WARNING) {
					stats.warnings++;
					warnings++;
				}
				if (m.getLevel() == IssueSeverity.ERROR || m.getLevel() == IssueSeverity.FATAL) {
					stats.errors++;
					errors++;
				}
			}

			ok = ok && !(m.getLevel() == IssueSeverity.ERROR || m.getLevel() == IssueSeverity.FATAL);
		}
	}
 
Example 9
Source File: SimpleWorkerContext.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
private void seeProfile(String url, StructureDefinition p) throws FHIRException {
   if (Utilities.noString(url))
     url = p.getUrl();
   if (!p.hasSnapshot()) {
     if (!p.hasBase())
       throw new DefinitionException("Profile "+p.getName()+" ("+p.getUrl()+") has no base and no snapshot");
     StructureDefinition sd = fetchResource(StructureDefinition.class, p.getBase());
     if (sd == null)
       throw new DefinitionException("Profile "+p.getName()+" ("+p.getUrl()+") base "+p.getBase()+" could not be resolved");
     List<ValidationMessage> msgs = new ArrayList<ValidationMessage>();
     ProfileUtilities pu = new ProfileUtilities(this, msgs, this);
     pu.generateSnapshot(sd, p, p.getUrl(), p.getName());
     for (ValidationMessage msg : msgs) {
       if (msg.getLevel() == IssueSeverity.ERROR || msg.getLevel() == IssueSeverity.FATAL)
         throw new DefinitionException("Profile "+p.getName()+" ("+p.getUrl()+"). Error generating snapshot: "+msg.getMessage());
     }
     if (!p.hasSnapshot())
       throw new DefinitionException("Profile "+p.getName()+" ("+p.getUrl()+"). Error generating snapshot");
     pu = null;
   }
	if (structures.containsKey(p.getUrl()))
		throw new DefinitionException("Duplicate structures " + p.getUrl());
	structures.put(p.getId(), p);
	structures.put(p.getUrl(), p);
	if (!p.getUrl().equals(url))
		structures.put(url, p);
}
 
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: BaseWorkerContext.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
@Override
public ValidationResult validateCode(String system, String code, String display, ValueSet vs) {
  try {
    if (system == null && vs.hasCodeSystem())
      return verifyCodeInternal(vs, vs.getCodeSystem().getSystem(), code, display);
    else if (codeSystems.containsKey(system) || vs.hasExpansion())
      return verifyCodeInternal(vs, system, code, display);
    else
      return verifyCodeExternal(vs, new Coding().setSystem(system).setCode(code).setDisplay(display), true);
  } catch (Exception e) {
    return new ValidationResult(IssueSeverity.FATAL, "Error validating code \""+code+"\" in system \""+system+"\": "+e.getMessage());
  }
}
 
Example 12
Source File: BaseWorkerContext.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
@Override
public ValidationResult validateCode(CodeableConcept code, ValueSet vs) {
  try {
    if (vs.hasCodeSystem() || vs.hasExpansion())
      return verifyCodeInternal(vs, code);
    else
      return verifyCodeExternal(vs, code, true);
  } catch (Exception e) {
    return new ValidationResult(IssueSeverity.FATAL, "Error validating code \""+code.toString()+"\": "+e.getMessage());
  }
}
 
Example 13
Source File: BaseWorkerContext.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
@Override
public ValidationResult validateCode(Coding code, ValueSet vs) {
  try {
    if (codeSystems.containsKey(code.getSystem()) || vs.hasExpansion())
      return verifyCodeInternal(codeSystems.get(code.getSystem()), code.getSystem(), code.getCode(), code.getDisplay());
    else
      return verifyCodeExternal(vs, code, true);
  } catch (Exception e) {
    return new ValidationResult(IssueSeverity.FATAL, "Error validating code \""+code+"\" in system \""+code.getSystem()+"\": "+e.getMessage());
  }
}
 
Example 14
Source File: BaseWorkerContext.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
@Override
public ValidationResult validateCode(String system, String code, String display) {
  try {
    if (codeSystems.containsKey(system))
      return verifyCodeInternal(codeSystems.get(system), system, code, display);
    else
      return verifyCodeExternal(null, new Coding().setSystem(system).setCode(code).setDisplay(display), true);
  } catch (Exception e) {
    return new ValidationResult(IssueSeverity.FATAL, "Error validating code \""+code+"\" in system \""+system+"\": "+e.getMessage());
  }
}
 
Example 15
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 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.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 17
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 18
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;
  }
}