use of org.hl7.fhir.definitions.model.Invariant in project org.hl7.fhir.core by hapifhir.
the class ProfileUtilities method describeExtensionContext.
public static String describeExtensionContext(StructureDefinition ext) {
StringBuilder b = new StringBuilder();
b.append("Use on ");
for (int i = 0; i < ext.getContext().size(); i++) {
StructureDefinitionContextComponent ec = ext.getContext().get(i);
if (i > 0)
b.append(i < ext.getContext().size() - 1 ? ", " : " or ");
b.append(ec.getType().getDisplay());
b.append(" ");
b.append(ec.getExpression());
}
if (ext.hasContextInvariant()) {
b.append(", with <a href=\"structuredefinition-definitions.html#StructureDefinition.contextInvariant\">Context Invariant</a> = ");
boolean first = true;
for (StringType s : ext.getContextInvariant()) {
if (first)
first = false;
else
b.append(", ");
b.append("<code>" + s.getValue() + "</code>");
}
}
return b.toString();
}
use of org.hl7.fhir.definitions.model.Invariant in project org.hl7.fhir.core by hapifhir.
the class ProfileValidator method validate.
public List<ValidationMessage> validate(StructureDefinition profile, boolean forBuild) {
List<ValidationMessage> errors = new ArrayList<ValidationMessage>();
// must have a FHIR version- GF#3160
warning(errors, IssueType.BUSINESSRULE, profile.getUrl(), profile.hasFhirVersion(), "Profiles SHOULD state the FHIR Version on which they are based");
warning(errors, IssueType.BUSINESSRULE, profile.getUrl(), profile.hasVersion(), "Profiles SHOULD state their own version");
// extensions must be defined
for (ElementDefinition ec : profile.getDifferential().getElement()) checkExtensions(profile, errors, "differential", ec);
rule(errors, IssueType.STRUCTURE, profile.getId(), profile.hasSnapshot(), "missing Snapshot at " + profile.getName() + "." + profile.getName());
for (ElementDefinition ec : profile.getSnapshot().getElement()) checkExtensions(profile, errors, "snapshot", ec);
if (rule(errors, IssueType.STRUCTURE, profile.getId(), profile.hasSnapshot(), "A snapshot is required")) {
Hashtable<String, ElementDefinition> snapshotElements = new Hashtable<String, ElementDefinition>();
for (ElementDefinition ed : profile.getSnapshot().getElement()) {
snapshotElements.put(ed.getId(), ed);
checkExtensions(profile, errors, "snapshot", ed);
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 {
// , inv.hasXpath() && inv.getXpath().startsWith("@value")
new FHIRPathEngine(context).check(null, profile.getType(), ed.getPath(), inv.getExpression());
} catch (Exception e) {
// rule(errors, IssueType.STRUCTURE, profile.getId()+"::"+ed.getPath()+"::"+inv.getId(), exprExt != null, e.getMessage());
}
}
}
}
}
}
if (snapshotElements != null) {
for (ElementDefinition diffElement : profile.getDifferential().getElement()) {
if (diffElement == null)
throw new Error("Diff Element is null - this is not an expected thing");
ElementDefinition snapElement = snapshotElements.get(diffElement.getId());
if (snapElement != null) {
// Happens with profiles in the main build - should be able to fix once snapshot generation is fixed - Lloyd
warning(errors, IssueType.BUSINESSRULE, diffElement.getId(), !checkMustSupport || snapElement.hasMustSupport(), "Elements included in the differential should declare mustSupport");
if (checkAggregation) {
for (TypeRefComponent type : snapElement.getType()) {
if ("http://hl7.org/fhir/Reference".equals(type.getWorkingCode()) || "http://hl7.org/fhir/canonical".equals(type.getWorkingCode())) {
warning(errors, IssueType.BUSINESSRULE, diffElement.getId(), type.hasAggregation(), "Elements with type Reference or canonical should declare aggregation");
}
}
}
}
}
}
}
return errors;
}
use of org.hl7.fhir.definitions.model.Invariant in project org.hl7.fhir.core by hapifhir.
the class ProfileUtilities method describeExtensionContext.
public static String describeExtensionContext(StructureDefinition ext) {
StringBuilder b = new StringBuilder();
b.append("Use on ");
for (int i = 0; i < ext.getContext().size(); i++) {
StructureDefinitionContextComponent ec = ext.getContext().get(i);
if (i > 0)
b.append(i < ext.getContext().size() - 1 ? ", " : " or ");
b.append(ec.getType().getDisplay());
b.append(" ");
b.append(ec.getExpression());
}
if (ext.hasContextInvariant()) {
b.append(", with <a href=\"structuredefinition-definitions.html#StructureDefinition.contextInvariant\">Context Invariant</a> = ");
boolean first = true;
for (StringType s : ext.getContextInvariant()) {
if (first)
first = false;
else
b.append(", ");
b.append("<code>" + s.getValue() + "</code>");
}
}
return b.toString();
}
Aggregations