use of org.hl7.fhir.r5.model.ElementDefinition.ElementDefinitionConstraintComponent in project kindling by HL7.
the class ProfileGenerator method convertConstraints.
private void convertConstraints(ElementDefn e, ElementDefinition ce, String source) throws FHIRException {
for (String in : e.getInvariants().keySet()) {
ElementDefinitionConstraintComponent con = new ElementDefinitionConstraintComponent();
Invariant inv = e.getInvariants().get(in);
con.setKey(inv.getId());
if (!con.hasKey()) {
profileCounter++;
con.setKey("prf-" + Integer.toString(profileCounter));
}
con.setRequirements(inv.getRequirements());
if (Utilities.noString(inv.getSeverity()))
con.setSeverity(ConstraintSeverity.ERROR);
else if (inv.getSeverity().equals("best-practice")) {
con.setSeverity(ConstraintSeverity.WARNING);
ToolingExtensions.addBooleanExtension(con, ToolingExtensions.EXT_BEST_PRACTICE, true);
if (Utilities.noString(inv.getExplanation()))
throw new FHIRException("Best Practice Invariants need to have an explanation");
con.addExtension().setUrl(ToolingExtensions.EXT_BEST_PRACTICE_EXPLANATION).setValue(new MarkdownType(inv.getExplanation()));
} else
con.setSeverity(ConstraintSeverity.fromCode(inv.getSeverity()));
con.setHuman(inv.getEnglish());
con.setXpath(inv.getXpath());
if (!Utilities.isAbsoluteUrl(source)) {
throw new Error("source : " + source);
}
con.setSource(source);
if (!"n/a".equals(inv.getExpression()))
con.setExpression(inv.getExpression());
ce.getConstraint().add(con);
}
}
use of org.hl7.fhir.r5.model.ElementDefinition.ElementDefinitionConstraintComponent in project kindling by HL7.
the class SchematronGenerator method generate.
public void generate(OutputStream out, Definitions definitions) throws Exception {
SchematronWriter sch = new SchematronWriter(out, SchematronType.ALL_RESOURCES, "All Resources");
insertGlobalRules(sch);
for (String rn : definitions.sortedResourceNames()) {
ResourceDefn root = definitions.getResources().get(rn);
Section s = sch.section(root.getName());
ArrayList<String> parents = new ArrayList<String>();
generateInvariants(s, null, root.getRoot(), definitions, parents, root.getName());
}
Set<StructureDefinition> processed = new HashSet<StructureDefinition>();
for (StructureDefinition exd : page.getWorkerContext().getExtensionDefinitions()) {
if (exd.getSnapshot().getElement().get(0).hasConstraint() && !processed.contains(exd)) {
processed.add(exd);
Section s = sch.section("Extension: " + exd.getName());
Rule r = s.rule("f:" + (exd.getSnapshot().getElementFirstRep().getIsModifier() ? "modifierExtension" : "extension") + "[@url='" + exd.getUrl() + "']");
for (ElementDefinitionConstraintComponent inv : exd.getSnapshot().getElement().get(0).getConstraint()) {
if (!isGlobal(inv.getKey()))
r.assrt(inv.getXpath().replace("\"", "'"), inv.getKey() + ": " + inv.getHuman());
}
}
}
sch.dump();
sch.close();
}
use of org.hl7.fhir.r5.model.ElementDefinition.ElementDefinitionConstraintComponent in project kindling by HL7.
the class XmlSpecGenerator method getInvariants.
private String getInvariants(ElementDefinition elem) {
StringBuilder b = new StringBuilder();
boolean first = true;
for (ElementDefinitionConstraintComponent i : elem.getConstraint()) {
if (!first)
b.append("; ");
first = false;
b.append(i.getKey() + ": " + i.getHuman());
}
return b.toString();
}
use of org.hl7.fhir.r5.model.ElementDefinition.ElementDefinitionConstraintComponent in project kindling by HL7.
the class JsonSpecGenerator method getInvariants.
private String getInvariants(ElementDefinition elem) {
StringBuilder b = new StringBuilder();
boolean first = true;
for (ElementDefinitionConstraintComponent i : elem.getConstraint()) {
if (!first)
b.append("; ");
first = false;
b.append(i.getKey() + ": " + i.getHuman());
}
return b.toString();
}
use of org.hl7.fhir.r5.model.ElementDefinition.ElementDefinitionConstraintComponent in project kindling by HL7.
the class DictHTMLGenerator method invariants.
private String invariants(List<ElementDefinitionConstraintComponent> constraints, StructureDefinition sd) throws FHIRException, Exception {
if (constraints.isEmpty())
return null;
StringBuilder s = new StringBuilder();
if (constraints.size() > 0) {
listInvariants(constraints, s, false, "Defined on this element", sd);
listInvariants(constraints, s, true, "Inherited by this element", sd);
}
if (s.length() > 0)
s.append("</table>\r\n");
return s.toString();
}
Aggregations