public void checkInvariant(ValidatorHostContext hostContext, List<ValidationMessage> errors, String path, StructureDefinition profile, Element resource, Element element, ElementDefinitionConstraintComponent inv) throws FHIRException { ExpressionNode n = (ExpressionNode) inv.getUserData("validator.expression.cache"); if (n == null) { long t = System.nanoTime(); try { n = fpe.parse(inv.getExpression()); } catch (FHIRLexerException e) { throw new FHIRException("Problem processing expression "+inv.getExpression() +" in profile " + profile.getUrl() + " path " + path + ": " + e.getMessage()); inv.setUserData("validator.expression.cache", n); if (inv.hasExtension("http://hl7.org/fhir/StructureDefinition/elementdefinition-bestpractice") && ToolingExtensions.readBooleanExtension(inv, "http://hl7.org/fhir/StructureDefinition/elementdefinition-bestpractice")) { if (bpWarnings == BestPracticeWarningLevel.Hint) hint(errors, IssueType.INVARIANT, element.line(), element.col(), path, ok, inv.getHuman()+msg+" ["+inv.getExpression()+"]"); else if (bpWarnings == BestPracticeWarningLevel.Warning) warning(errors, IssueType.INVARIANT, element.line(), element.col(), path, ok, inv.getHuman()+msg+" ["+inv.getExpression()+"]"); else if (bpWarnings == BestPracticeWarningLevel.Error) rule(errors, IssueType.INVARIANT, element.line(), element.col(), path, ok, inv.getHuman()+msg+" ["+inv.getExpression()+"]"); if (inv.getSeverity() == ConstraintSeverity.ERROR) rule(errors, IssueType.INVARIANT, element.line(), element.col(), path, ok, inv.getHuman()+msg+" ["+inv.getExpression()+"]"); else if (inv.getSeverity() == ConstraintSeverity.WARNING) warning(errors, IssueType.INVARIANT, element.line(), element.line(), path, ok, inv.getHuman()+msg+" ["+inv.getExpression()+"]");
if (!inv.hasSource() || allInvariants) { if (!c.getPieces().isEmpty()) c.addPiece(gen.new Piece("br")); c.getPieces().add(checkForNoChange(inv, gen.new Piece(null, inv.getKey()+": ", null).addStyle("font-weight:bold"))); c.getPieces().add(checkForNoChange(inv, gen.new Piece(null, gt(inv.getHumanElement()), null)));
s.setUserData(IS_DERIVED, true); if (!s.hasSource()) s.setSource(base.getId()); ElementDefinitionConstraintComponent inv = s.copy(); base.getConstraint().add(inv);
if (!inv.hasSource() || allInvariants) { if (!c.getPieces().isEmpty()) c.addPiece(gen.new Piece("br")); c.getPieces().add(checkForNoChange(inv, gen.new Piece(null, inv.getKey()+": ", null).addStyle("font-weight:bold"))); c.getPieces().add(checkForNoChange(inv, gen.new Piece(null, gt(inv.getHumanElement()), null)));
for (ElementDefinitionConstraintComponent inv : ed.getConstraint()) { if (forBuild) { if (!inExemptList(inv.getKey())) { if (rule(errors, IssueType.BUSINESSRULE, profile.getId()+"::"+ed.getPath()+"::"+inv.getKey(), inv.hasExpression(), "The invariant has no FHIR Path expression ("+inv.getXpath()+")")) { try { new FHIRPathEngine(context).check(null, profile.getType(), ed.getPath(), inv.getExpression()); // , inv.hasXpath() && inv.getXpath().startsWith("@value") } catch (Exception e) {
public void checkInvariant(ValidatorHostContext hostContext, List<ValidationMessage> errors, String path, StructureDefinition profile, Element resource, Element element, ElementDefinitionConstraintComponent inv) throws FHIRException { ExpressionNode n = (ExpressionNode) inv.getUserData("validator.expression.cache"); if (n == null) { long t = System.nanoTime(); try { n = fpe.parse(inv.getExpression()); } catch (FHIRLexerException e) { throw new FHIRException("Problem processing expression "+inv.getExpression() +" in profile " + profile.getUrl() + " path " + path + ": " + e.getMessage()); inv.setUserData("validator.expression.cache", n); if (inv.hasExtension("http://hl7.org/fhir/StructureDefinition/elementdefinition-bestpractice") && ToolingExtensions.readBooleanExtension(inv, "http://hl7.org/fhir/StructureDefinition/elementdefinition-bestpractice")) { if (bpWarnings == BestPracticeWarningLevel.Hint) hint(errors, IssueType.INVARIANT, element.line(), element.col(), path, ok, inv.getHuman()+msg+" ["+inv.getExpression()+"]"); else if (bpWarnings == BestPracticeWarningLevel.Warning) warning(errors, IssueType.INVARIANT, element.line(), element.col(), path, ok, inv.getHuman()+msg+" ["+inv.getExpression()+"]"); else if (bpWarnings == BestPracticeWarningLevel.Error) rule(errors, IssueType.INVARIANT, element.line(), element.col(), path, ok, inv.getHuman()+msg+" ["+inv.getExpression()+"]"); if (inv.getSeverity() == ConstraintSeverity.ERROR) rule(errors, IssueType.INVARIANT, element.line(), element.col(), path, ok, inv.getHuman()+msg+" ["+inv.getExpression()+"]"); else if (inv.getSeverity() == ConstraintSeverity.WARNING) warning(errors, IssueType.INVARIANT, element.line(), element.line(), path, ok, inv.getHuman()+msg+" ["+inv.getExpression()+"]");
} else if (o instanceof ElementDefinitionConstraintComponent) { ElementDefinitionConstraintComponent c = (ElementDefinitionConstraintComponent)o; val = c.getKey() + ":" + c.getHuman() + " {" + c.getExpression() + "}"; } else if (o instanceof ElementDefinitionSlicingDiscriminatorComponent) { ElementDefinitionSlicingDiscriminatorComponent c = (ElementDefinitionSlicingDiscriminatorComponent)o;
private List<ElementDefinitionConstraintComponent> unionConstraints(ElementDefinition ed, ProfileComparison outcome, String path, List<ElementDefinitionConstraintComponent> left, List<ElementDefinitionConstraintComponent> right) { List<ElementDefinitionConstraintComponent> result = new ArrayList<ElementDefinitionConstraintComponent>(); for (ElementDefinitionConstraintComponent l : left) { boolean found = false; for (ElementDefinitionConstraintComponent r : right) if (Utilities.equals(r.getId(), l.getId()) || (Utilities.equals(r.getXpath(), l.getXpath()) && r.getSeverity() == l.getSeverity())) found = true; if (!found) { outcome.messages.add(new ValidationMessage(Source.ProfileComparer, ValidationMessage.IssueType.STRUCTURE, path, "StructureDefinition "+outcome.leftName()+" has a constraint that is not found in "+outcome.rightName()+" and it is uncertain whether they are compatible ("+l.getXpath()+")", ValidationMessage.IssueSeverity.INFORMATION)); status(ed, ProfileUtilities.STATUS_WARNING); } result.add(l); } for (ElementDefinitionConstraintComponent r : right) { boolean found = false; for (ElementDefinitionConstraintComponent l : left) if (Utilities.equals(r.getId(), l.getId()) || (Utilities.equals(r.getXpath(), l.getXpath()) && r.getSeverity() == l.getSeverity())) found = true; if (!found) { outcome.messages.add(new ValidationMessage(Source.ProfileComparer, ValidationMessage.IssueType.STRUCTURE, path, "StructureDefinition "+outcome.rightName()+" has a constraint that is not found in "+outcome.leftName()+" and it is uncertain whether they are compatible ("+r.getXpath()+")", ValidationMessage.IssueSeverity.INFORMATION)); status(ed, ProfileUtilities.STATUS_WARNING); result.add(r); } } return result; }
public void checkAllInvariants(){ for (StructureDefinition sd : context.allStructures()) { if (sd.getDerivation() == TypeDerivationRule.SPECIALIZATION) { for (ElementDefinition ed : sd.getSnapshot().getElement()) { for (ElementDefinitionConstraintComponent inv : ed.getConstraint()) { if (inv.hasExpression()) { try { ExpressionNode n = (ExpressionNode) inv.getUserData("validator.expression.cache"); if (n == null) { n = fpe.parse(inv.getExpression()); inv.setUserData("validator.expression.cache", n); } fpe.check(null, sd.getKind() == StructureDefinitionKind.RESOURCE ? sd.getType() : "DomainResource", ed.getPath(), n); } catch (Exception e) { System.out.println("Error processing structure ["+sd.getId()+"] path "+ed.getPath()+":"+inv.getKey()+" (\""+inv.getExpression()+"\"): "+e.getMessage()); } } } } } } }
public static org.hl7.fhir.r4.model.ElementDefinition.ElementDefinitionConstraintComponent convertElementDefinitionConstraintComponent(org.hl7.fhir.dstu2016may.model.ElementDefinition.ElementDefinitionConstraintComponent src) throws FHIRException { if (src == null || src.isEmpty()) return null; org.hl7.fhir.r4.model.ElementDefinition.ElementDefinitionConstraintComponent tgt = new org.hl7.fhir.r4.model.ElementDefinition.ElementDefinitionConstraintComponent(); copyElement(src, tgt); tgt.setKey(src.getKey()); if (src.hasRequirements()) tgt.setRequirements(src.getRequirements()); tgt.setSeverity(convertConstraintSeverity(src.getSeverity())); tgt.setHuman(src.getHuman()); if (src.hasExpression()) tgt.setExpression(convertToR4Expression(src.getExpression())); tgt.setXpath(src.getXpath()); return tgt; }
public static org.hl7.fhir.dstu2016may.model.ElementDefinition.ElementDefinitionConstraintComponent convertElementDefinitionConstraintComponent(org.hl7.fhir.r4.model.ElementDefinition.ElementDefinitionConstraintComponent src) throws FHIRException { if (src == null || src.isEmpty()) return null; org.hl7.fhir.dstu2016may.model.ElementDefinition.ElementDefinitionConstraintComponent tgt = new org.hl7.fhir.dstu2016may.model.ElementDefinition.ElementDefinitionConstraintComponent(); copyElement(src, tgt); tgt.setKey(src.getKey()); if (src.hasRequirements()) tgt.setRequirements(src.getRequirements()); tgt.setSeverity(convertConstraintSeverity(src.getSeverity())); tgt.setHuman(src.getHuman()); if (src.hasExpression()) tgt.setExpression(convertTo2016MayExpression(src.getExpression())); tgt.setXpath(src.getXpath()); return tgt; }
public org.hl7.fhir.instance.model.ElementDefinition.ElementDefinitionConstraintComponent convertElementDefinitionConstraintComponent(org.hl7.fhir.r4.model.ElementDefinition.ElementDefinitionConstraintComponent src) throws FHIRException { if (src == null || src.isEmpty()) return null; org.hl7.fhir.instance.model.ElementDefinition.ElementDefinitionConstraintComponent tgt = new org.hl7.fhir.instance.model.ElementDefinition.ElementDefinitionConstraintComponent(); copyElement(src, tgt); tgt.setKey(src.getKey()); tgt.setRequirements(src.getRequirements()); tgt.setSeverity(convertConstraintSeverity(src.getSeverity())); tgt.setHuman(src.getHuman()); if (src.hasExpression()) ToolingExtensions.addStringExtension(tgt, ToolingExtensions.EXT_EXPRESSION, src.getExpression()); tgt.setXpath(src.getXpath()); return tgt; }
private void markDerived(ElementDefinition outcome) { for (ElementDefinitionConstraintComponent inv : outcome.getConstraint()) inv.setUserData(IS_DERIVED, true); }
public boolean hasConstraint() { if (this.constraint == null) return false; for (ElementDefinitionConstraintComponent item : this.constraint) if (!item.isEmpty()) return true; return false; }
public ElementDefinitionConstraintComponent addConstraint() { //3 ElementDefinitionConstraintComponent t = new ElementDefinitionConstraintComponent(); if (this.constraint == null) this.constraint = new ArrayList<ElementDefinitionConstraintComponent>(); this.constraint.add(t); return t; }
public org.hl7.fhir.r4.model.ElementDefinition.ElementDefinitionConstraintComponent convertElementDefinitionConstraintComponent(org.hl7.fhir.instance.model.ElementDefinition.ElementDefinitionConstraintComponent src) throws FHIRException { if (src == null || src.isEmpty()) return null; org.hl7.fhir.r4.model.ElementDefinition.ElementDefinitionConstraintComponent tgt = new org.hl7.fhir.r4.model.ElementDefinition.ElementDefinitionConstraintComponent(); copyElement(src, tgt); tgt.setKey(src.getKey()); tgt.setRequirements(src.getRequirements()); tgt.setSeverity(convertConstraintSeverity(src.getSeverity())); tgt.setHuman(src.getHuman()); tgt.setExpression(ToolingExtensions.readStringExtension(src, ToolingExtensions.EXT_EXPRESSION)); tgt.setXpath(src.getXpath()); return tgt; }
public ElementDefinitionConstraintComponent copy() { ElementDefinitionConstraintComponent dst = new ElementDefinitionConstraintComponent(); copyValues(dst); dst.key = key == null ? null : key.copy(); dst.requirements = requirements == null ? null : requirements.copy(); dst.severity = severity == null ? null : severity.copy(); dst.human = human == null ? null : human.copy(); dst.expression = expression == null ? null : expression.copy(); dst.xpath = xpath == null ? null : xpath.copy(); dst.source = source == null ? null : source.copy(); return dst; }