org.hl7.fhir.utilities.validation.ValidationMessage.IssueSeverity Java Examples

The following examples show how to use org.hl7.fhir.utilities.validation.ValidationMessage.IssueSeverity. 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: TurtleParser.java    From org.hl7.fhir.core with Apache License 2.0 6 votes vote down vote up
private Element parse(Turtle src) throws FHIRException {
  // we actually ignore the stated URL here
  for (TTLComplex cmp : src.getObjects().values()) {
    for (String p : cmp.getPredicates().keySet()) {
      if ((FHIR_URI_BASE + "nodeRole").equals(p) && cmp.getPredicates().get(p).hasValue(FHIR_URI_BASE + "treeRoot")) {
        return parse(src, cmp);
      }
    }
  }
  // still here: well, we didn't find a start point
  String msg = "Error parsing Turtle: unable to find any node maked as the entry point (where " + FHIR_URI_BASE + "nodeRole = " + FHIR_URI_BASE + "treeRoot)";
  if (policy == ValidationPolicy.EVERYTHING) {
    logError(-1, -1, "(document)", IssueType.INVALID, msg, IssueSeverity.FATAL);
    return null;
  } else {
    throw new FHIRFormatError(msg);
  } 
}
 
Example #2
Source File: TurtleParser.java    From org.hl7.fhir.core with Apache License 2.0 6 votes vote down vote up
@Override
public Element parse(InputStream input) throws IOException, FHIRException {
  Turtle src = new Turtle();
  if (policy == ValidationPolicy.EVERYTHING) {
    try {
      src.parse(TextFile.streamToString(input));
    } catch (Exception e) {  
      logError(-1, -1, "(document)", IssueType.INVALID, "Error parsing Turtle: "+e.getMessage(), IssueSeverity.FATAL);
      return null;
    }
    return parse(src);  
  } else {
  src.parse(TextFile.streamToString(input));
    return parse(src);  
  } 
}
 
Example #3
Source File: TurtleParser.java    From org.hl7.fhir.core with Apache License 2.0 6 votes vote down vote up
private Element parse(Turtle src) throws FHIRException {
  // we actually ignore the stated URL here
  for (TTLComplex cmp : src.getObjects().values()) {
    for (String p : cmp.getPredicates().keySet()) {
      if ((FHIR_URI_BASE + "nodeRole").equals(p) && cmp.getPredicates().get(p).hasValue(FHIR_URI_BASE + "treeRoot")) {
        return parse(src, cmp);
      }
    }
  }
  // still here: well, we didn't find a start point
  String msg = "Error parsing Turtle: unable to find any node maked as the entry point (where " + FHIR_URI_BASE + "nodeRole = " + FHIR_URI_BASE + "treeRoot)";
  if (policy == ValidationPolicy.EVERYTHING) {
    logError(-1, -1, "(document)", IssueType.INVALID, msg, IssueSeverity.FATAL);
    return null;
  } else {
    throw new FHIRFormatError(msg);
  } 
}
 
Example #4
Source File: ProfileComparer.java    From org.hl7.fhir.core with Apache License 2.0 6 votes vote down vote up
private String mergeText(ElementDefinition ed, ProfileComparison outcome, String path, String name, String left, String right) {
  if (left == null && right == null)
    return null;
  if (left == null)
    return right;
  if (right == null)
    return left;
  left = stripLinks(left);
  right = stripLinks(right);
  if (left.equalsIgnoreCase(right))
    return left;
  if (path != null) {
    outcome.messages.add(new ValidationMessage(Source.ProfileComparer, ValidationMessage.IssueType.INFORMATIONAL, path, "Elements differ in definition for "+name+":\r\n  \""+left+"\"\r\n  \""+right+"\"", 
        "Elements differ in definition for "+name+":<br/>\""+Utilities.escapeXml(left)+"\"<br/>\""+Utilities.escapeXml(right)+"\"", ValidationMessage.IssueSeverity.INFORMATION));
    status(ed, ProfileUtilities.STATUS_HINT);
  }
  return "left: "+left+"; right: "+right;
}
 
Example #5
Source File: ParserBase.java    From org.hl7.fhir.core with Apache License 2.0 6 votes vote down vote up
protected StructureDefinition getDefinition(int line, int col, String ns, String name) throws FHIRFormatError {
  if (ns == null) {
    logError(line, col, name, IssueType.STRUCTURE, "This cannot be parsed as a FHIR object (no namespace)", IssueSeverity.FATAL);
    return null;
  }
  if (name == null) {
    logError(line, col, name, IssueType.STRUCTURE, "This cannot be parsed as a FHIR object (no name)", IssueSeverity.FATAL);
    return null;
	}
 for (StructureDefinition sd : context.allStructures()) {
   if (name.equals(sd.getIdElement().getIdPart())) {
     if((ns == null || ns.equals(FormatUtilities.FHIR_NS)) && !ToolingExtensions.hasExtension(sd, "http://hl7.org/fhir/StructureDefinition/elementdefinition-namespace"))
       return sd;
     String sns = ToolingExtensions.readStringExtension(sd, "http://hl7.org/fhir/StructureDefinition/elementdefinition-namespace");
     if (ns != null && ns.equals(sns))
       return sd;
   }
 }
 logError(line, col, name, IssueType.STRUCTURE, "This does not appear to be a FHIR resource (unknown namespace/name '"+ns+"::"+name+"')", IssueSeverity.FATAL);
 return null;
}
 
Example #6
Source File: TurtleParser.java    From org.hl7.fhir.core with Apache License 2.0 6 votes vote down vote up
private void parseChildInstance(Turtle src, String npath, TTLComplex object, Element context, Property property, String name, TTLObject e) throws FHIRException {
  if (property.isResource())
    parseResource(src, npath, object, context, property, name, e);
  else  if (e instanceof TTLComplex) {
    TTLComplex child = (TTLComplex) e;
    Element n = new Element(tail(name), property).markLocation(e.getLine(), e.getCol());
    context.getChildren().add(n);
    if (property.isPrimitive(property.getType(tail(name)))) {
      parseChildren(src, npath, child, n, true);
      TTLObject val = child.getPredicates().get(FHIR_URI_BASE + "value");
      if (val != null) {
        if (val instanceof TTLLiteral) {
          String value = ((TTLLiteral) val).getValue();
          String type = ((TTLLiteral) val).getType();
          // todo: check type
          n.setValue(value);
        } else
          logError(object.getLine(), object.getCol(), npath, IssueType.INVALID, "This property must be a Literal, not a "+e.getClass().getName(), IssueSeverity.ERROR);
      }
    } else 
      parseChildren(src, npath, child, n, false);

  } else 
    logError(object.getLine(), object.getCol(), npath, IssueType.INVALID, "This property must be a URI or bnode, not a "+e.getClass().getName(), IssueSeverity.ERROR);
}
 
Example #7
Source File: TurtleParser.java    From org.hl7.fhir.core with Apache License 2.0 6 votes vote down vote up
private Element parse(Turtle src) throws FHIRFormatError, DefinitionException {
  // we actually ignore the stated URL here
  for (TTLComplex cmp : src.getObjects().values()) {
    for (String p : cmp.getPredicates().keySet()) {
      if ((FHIR_URI_BASE + "nodeRole").equals(p) && cmp.getPredicates().get(p).hasValue(FHIR_URI_BASE + "treeRoot")) {
        return parse(src, cmp);
      }
    }
  }
  // still here: well, we didn't find a start point
  String msg = "Error parsing Turtle: unable to find any node maked as the entry point (where " + FHIR_URI_BASE + "nodeRole = " + FHIR_URI_BASE + "treeRoot)";
  if (policy == ValidationPolicy.EVERYTHING) {
    logError(-1, -1, "(document)", IssueType.INVALID, msg, IssueSeverity.FATAL);
    return null;
  } else {
    throw new FHIRFormatError(msg);
  } 
}
 
Example #8
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 #9
Source File: CapabilityStatementUtilities.java    From org.hl7.fhir.core with Apache License 2.0 6 votes vote down vote up
private void information(XhtmlNode x, IssueType type, String path, String message) {
  if (type != null)
    output.messages.add(new ValidationMessage(Source.ProfileComparer, type, path, message, IssueSeverity.INFORMATION));
  XhtmlNode ul;
  if ("ul".equals(x.getName())) {
    ul = x;
  } else {
    ul = null;
    for (XhtmlNode c : x.getChildNodes()) {
      if ("ul".equals(c.getName())) {
        ul = c;
      }
    }
    if (ul == null) {
      ul = x.ul();
    }
  } 
  ul.li().addText(message);
}
 
Example #10
Source File: JsonParser.java    From org.hl7.fhir.core with Apache License 2.0 6 votes vote down vote up
public Element parse(JsonObject object) throws Exception {
	JsonElement rt = object.get("resourceType");
	if (rt == null) {
		logError(line(object), col(object), "$", IssueType.INVALID, "Unable to find resourceType property", IssueSeverity.FATAL);
		return null;
	} else {
		String name = rt.getAsString();
		String path = "/"+name;

		StructureDefinition sd = getDefinition(line(object), col(object), name);
		if (sd == null)
			return null;

		Element result = new Element(name, new Property(context, sd.getSnapshot().getElement().get(0), sd));
		checkObject(object, path);
		result.markLocation(line(object), col(object));
		result.setType(name);
		parseChildren(path, object, result, true);
		result.numberChildren();
		return result;
	}
}
 
Example #11
Source File: JsonParser.java    From org.hl7.fhir.core with Apache License 2.0 6 votes vote down vote up
private void parseChildComplex(String path, JsonObject object, Element context, Set<String> processed, Property property, String name) throws FHIRException {
	processed.add(name);
	String npath = path+"/"+property.getName();
	JsonElement e = object.get(name);
	if (property.isList() && (e instanceof JsonArray)) {
		JsonArray arr = (JsonArray) e;
		for (JsonElement am : arr) {
			parseChildComplexInstance(npath, object, context, property, name, am);
		}
	} else {
	  if (property.isList()) {
      logError(line(e), col(e), npath, IssueType.INVALID, "This property must be an Array, not "+describeType(e), IssueSeverity.ERROR);
	  }
		parseChildComplexInstance(npath, object, context, property, name, e);
	}
}
 
Example #12
Source File: CareConnectProfileDbValidationSupportSTU3.java    From careconnect-reference-implementation with Apache License 2.0 6 votes vote down vote up
@Override
public CodeValidationResult validateCode(FhirContext theContext, String theCodeSystem, String theCode, String theDisplay) {
  CodeSystem cs = fetchCodeSystem(theContext, theCodeSystem);
  logD("CareConnect validateCode system = "+ theCodeSystem);

  if (cs != null) {
    boolean caseSensitive = true;
    if (cs.hasCaseSensitive()) {
      caseSensitive = cs.getCaseSensitive();
    }

    CodeValidationResult retVal = testIfConceptIsInList(theCode, cs.getConcept(), caseSensitive);

    if (retVal != null) {
      return retVal;
    }
  }

  return new CodeValidationResult(IssueSeverity.WARNING, "CareConnect Unknown code: " + theCodeSystem + " / " + theCode);
}
 
Example #13
Source File: DefaultProfileValidationSupportStu3AsR4.java    From careconnect-reference-implementation with Apache License 2.0 6 votes vote down vote up
@Override
public CodeValidationResult validateCode(FhirContext r4Context, String theCodeSystem, String theCode, String theDisplay) {
    CodeSystem cs = fetchCodeSystem(r4Context, theCodeSystem);
    if (cs != null) {
        boolean caseSensitive = true;
        if (cs.hasCaseSensitive()) {
            caseSensitive = cs.getCaseSensitive();
        }

        CodeValidationResult retVal = testIfConceptIsInList(theCode, cs.getConcept(), caseSensitive);

        if (retVal != null) {
            return retVal;
        }
    }

    return new CodeValidationResult(IssueSeverity.WARNING, "Unknown code: " + theCodeSystem + " / " + theCode);
}
 
Example #14
Source File: JsonParser.java    From org.hl7.fhir.core with Apache License 2.0 6 votes vote down vote up
private void parseChildren(String path, JsonObject object, Element element, boolean hasResourceType) throws FHIRException {
	reapComments(object, element);
	List<Property> properties = element.getProperty().getChildProperties(element.getName(), null);
	Set<String> processed = new HashSet<String>();
	if (hasResourceType)
		processed.add("resourceType");
	processed.add("fhir_comments");

	// note that we do not trouble ourselves to maintain the wire format order here - we don't even know what it was anyway
	// first pass: process the properties
	for (Property property : properties) {
		parseChildItem(path, object, element, processed, property);
	}

	// second pass: check for things not processed
	if (policy != ValidationPolicy.NONE) {
		for (Entry<String, JsonElement> e : object.entrySet()) {
			if (!processed.contains(e.getKey())) {
				logError(line(e.getValue()), col(e.getValue()), path, IssueType.STRUCTURE, context.formatMessage(I18nConstants.UNRECOGNISED_PROPERTY_, e.getKey()), IssueSeverity.ERROR);
			}
		}
	}
}
 
Example #15
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 #16
Source File: JsonParser.java    From org.hl7.fhir.core with Apache License 2.0 6 votes vote down vote up
public Element parse(JsonObject object) throws FHIRException {
	JsonElement rt = object.get("resourceType");
	if (rt == null) {
		logError(line(object), col(object), "$", IssueType.INVALID, context.formatMessage(I18nConstants.UNABLE_TO_FIND_RESOURCETYPE_PROPERTY), IssueSeverity.FATAL);
		return null;
	} else {
		String name = rt.getAsString();
		String path = name;

		StructureDefinition sd = getDefinition(line(object), col(object), name);
		if (sd == null)
			return null;

		Element result = new Element(name, new Property(context, sd.getSnapshot().getElement().get(0), sd));
		checkObject(object, path);
		result.markLocation(line(object), col(object));
		result.setType(name);
		parseChildren(path, object, result, true);
		result.numberChildren();
		return result;
	}
}
 
Example #17
Source File: TurtleParser.java    From org.hl7.fhir.core with Apache License 2.0 6 votes vote down vote up
private void parseChildInstance(Turtle src, String npath, TTLComplex object, Element element, Property property, String name, TTLObject e) throws FHIRException {
  if (property.isResource())
    parseResource(src, npath, object, element, property, name, e);
  else  if (e instanceof TTLComplex) {
    TTLComplex child = (TTLComplex) e;
    Element n = new Element(tail(name), property).markLocation(e.getLine(), e.getCol());
    element.getChildren().add(n);
    if (property.isPrimitive(property.getType(tail(name)))) {
      parseChildren(src, npath, child, n, true);
      TTLObject val = child.getPredicates().get(FHIR_URI_BASE + "value");
      if (val != null) {
        if (val instanceof TTLLiteral) {
          String value = ((TTLLiteral) val).getValue();
          String type = ((TTLLiteral) val).getType();
          // todo: check type
          n.setValue(value);
        } else
          logError(object.getLine(), object.getCol(), npath, IssueType.INVALID, context.formatMessage(I18nConstants.THIS_PROPERTY_MUST_BE_A_LITERAL_NOT_A_, e.getClass().getName()), IssueSeverity.ERROR);
      }
    } else 
      parseChildren(src, npath, child, n, false);

  } else 
    logError(object.getLine(), object.getCol(), npath, IssueType.INVALID, context.formatMessage(I18nConstants.THIS_PROPERTY_MUST_BE_A_URI_OR_BNODE_NOT_A_, e.getClass().getName()), IssueSeverity.ERROR);
}
 
Example #18
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 #19
Source File: ProfileComparer.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
private boolean rule(ElementDefinition ed, boolean test, String path, String message) {
  if (!test)  {
    messages.add(new ValidationMessage(Source.ProfileComparer, IssueType.STRUCTURE, path, message, IssueSeverity.ERROR));
    status(ed, ProfileUtilities.STATUS_ERROR);
  }
  return test;
}
 
Example #20
Source File: JsonParser.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
private void parseChildComplexInstance(String npath, JsonObject object, Element context, Property property, String name, JsonElement e) throws FHIRException {
	if (e instanceof JsonObject) {
		JsonObject child = (JsonObject) e;
		Element n = new Element(name, property).markLocation(line(child), col(child));
		checkObject(child, npath);
		context.getChildren().add(n);
		if (property.isResource())
			parseResource(npath, child, n, property);
		else
			parseChildren(npath, child, n, false);
	} else 
		logError(line(e), col(e), npath, IssueType.INVALID, "This property must be "+(property.isList() ? "an Array" : "an Object")+", not a "+e.getClass().getName(), IssueSeverity.ERROR);
}
 
Example #21
Source File: BaseValidator.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
/**
 * Test a rule and add a {@link IssueSeverity#INFORMATION} validation message if the validation fails. And mark it as a slicing hint for later recovery if appropriate
 * 
 * @param thePass
 *          Set this parameter to <code>false</code> if the validation does not pass
 * @return Returns <code>thePass</code> (in other words, returns <code>true</code> if the rule did not fail validation)
 */
//FIXME: formatMessage should be done here
protected boolean slicingHint(List<ValidationMessage> errors, IssueType type, int line, int col, String path, boolean thePass, String msg, String html) {
  if (!thePass) {
    addValidationMessage(errors, type, line, col, path, msg, IssueSeverity.INFORMATION, null).setSlicingHint(true).setSliceHtml(html);
  }
  return thePass;
}
 
Example #22
Source File: ProfileComparer.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
private boolean ruleEqual(String path, ElementDefinition ed, String vLeft, String vRight, String description, boolean nullOK) {
  if (vLeft == null && vRight == null && nullOK)
    return true;
  if (vLeft == null && vRight == null) {
    messages.add(new ValidationMessage(Source.ProfileComparer, ValidationMessage.IssueType.STRUCTURE, path, description+" and not null (null/null)", ValidationMessage.IssueSeverity.ERROR));
    if (ed != null)
      status(ed, ProfileUtilities.STATUS_ERROR);
  }
  if (vLeft == null || !vLeft.equals(vRight)) {
    messages.add(new ValidationMessage(Source.ProfileComparer, ValidationMessage.IssueType.STRUCTURE, path, description+" ("+vLeft+"/"+vRight+")", ValidationMessage.IssueSeverity.ERROR));
    if (ed != null)
      status(ed, ProfileUtilities.STATUS_ERROR);
  }
  return true;
}
 
Example #23
Source File: ValidationEngine.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
private OperationOutcome exceptionToOutcome(Exception ex) throws IOException, FHIRException, EOperationOutcome {
  OperationOutcome op = new OperationOutcome();
  op.addIssue().setCode(org.hl7.fhir.r5.model.OperationOutcome.IssueType.EXCEPTION).setSeverity(org.hl7.fhir.r5.model.OperationOutcome.IssueSeverity.FATAL).getDetails().setText(ex.getMessage());
  RenderingContext rc = new RenderingContext(context, null, null, "http://hl7.org/fhir", "", null, ResourceRendererMode.RESOURCE);
  RendererFactory.factory(op, rc).render(op);
  return op;
}
 
Example #24
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, String code)
  throws FileNotFoundException, ETooCostly, IOException, FHIRException {
  if (vs.hasExpansion()) {
    return verifyCodeInExpansion(vs, code);
  } else {
    ValueSetExpansionOutcome vse = expansionCache.getExpander().expand(vs, null);
    if (vse.getValueset() == null) {
      return new ValidationResult(IssueSeverity.ERROR, vse.getError(), vse.getErrorClass());
    } else {
      return verifyCodeInExpansion(vse.getValueset(), code);
    }
  }
}
 
Example #25
Source File: BaseValidator.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
protected boolean fail(List<ValidationMessage> errors, IssueType type, int line, int col, String path, boolean thePass, String theMessage, Object... theMessageArguments) {
  if (!thePass) {
    String msg = context.formatMessage(theMessage, theMessageArguments);
    addValidationMessage(errors, type, line, col, path, msg, IssueSeverity.FATAL, theMessage);
  }
  return thePass;
}
 
Example #26
Source File: ProfileComparer.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
public int getWarningCount() {
  int c = 0;
  for (ValidationMessage vm : messages)
    if (vm.getLevel() == ValidationMessage.IssueSeverity.WARNING)
      c++;
  return c;
}
 
Example #27
Source File: ProfileComparer.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
public int getErrorCount() {
  int c = 0;
  for (ValidationMessage vm : messages)
    if (vm.getLevel() == ValidationMessage.IssueSeverity.ERROR)
      c++;
  return c;
}
 
Example #28
Source File: BaseValidator.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
/**
 * Test a rule and add a {@link IssueSeverity#WARNING} validation message if the validation fails
 * 
 * @param thePass
 *          Set this parameter to <code>false</code> if the validation does not pass
 * @return Returns <code>thePass</code> (in other words, returns <code>true</code> if the rule did not fail validation)
 */
protected boolean suppressedwarning(List<ValidationMessage> errors, IssueType type, String path, boolean thePass, String msg, String html, Object... theMessageArguments) {
  if (!thePass) {
    String nmsg = context.formatMessage(msg, theMessageArguments);
    addValidationMessage(errors, type, path, nmsg, html, IssueSeverity.INFORMATION, msg);
  }
  return thePass;
}
 
Example #29
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 #30
Source File: TurtleParser.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
private void parseChildren(Turtle src, String path, TTLComplex object, Element context, boolean primitive) throws FHIRFormatError, DefinitionException {

    List<Property> properties = context.getProperty().getChildProperties(context.getName(), null);
    Set<String> processed = new HashSet<String>();
    if (primitive)
      processed.add(FHIR_URI_BASE + "value");

    // note that we do not trouble ourselves to maintain the wire format order here - we don't even know what it was anyway
    // first pass: process the properties
    for (Property property : properties) {
      if (property.isChoice()) {
        for (TypeRefComponent type : property.getDefinition().getType()) {
          String eName = property.getName().substring(0, property.getName().length()-3) + Utilities.capitalize(type.getCode());
          parseChild(src, object, context, processed, property, path, getFormalName(property, eName));
        }
      } else  {
        parseChild(src, object, context, processed, property, path, getFormalName(property));
      } 
    }

    // second pass: check for things not processed
    if (policy != ValidationPolicy.NONE) {
      for (String u : object.getPredicates().keySet()) {
        if (!processed.contains(u)) {
          TTLObject n = object.getPredicates().get(u);
          logError(n.getLine(), n.getCol(), path, IssueType.STRUCTURE, "Unrecognised predicate '"+u+"'", IssueSeverity.ERROR);         
        }
      }
    }
  }