Search in sources :

Example 41 with ElementDefinitionConstraintComponent

use of org.hl7.fhir.r4b.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);
    }
}
Also used : Invariant(org.hl7.fhir.definitions.model.Invariant) FHIRFormatError(org.hl7.fhir.exceptions.FHIRFormatError) MarkdownType(org.hl7.fhir.r5.model.MarkdownType) ElementDefinitionConstraintComponent(org.hl7.fhir.r5.model.ElementDefinition.ElementDefinitionConstraintComponent) FHIRException(org.hl7.fhir.exceptions.FHIRException)

Example 42 with ElementDefinitionConstraintComponent

use of org.hl7.fhir.r4b.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();
}
Also used : StructureDefinition(org.hl7.fhir.r5.model.StructureDefinition) SchematronWriter(org.hl7.fhir.utilities.xml.SchematronWriter) ArrayList(java.util.ArrayList) Rule(org.hl7.fhir.utilities.xml.SchematronWriter.Rule) ResourceDefn(org.hl7.fhir.definitions.model.ResourceDefn) Section(org.hl7.fhir.utilities.xml.SchematronWriter.Section) ElementDefinitionConstraintComponent(org.hl7.fhir.r5.model.ElementDefinition.ElementDefinitionConstraintComponent) HashSet(java.util.HashSet)

Example 43 with ElementDefinitionConstraintComponent

use of org.hl7.fhir.r4b.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();
}
Also used : CommaSeparatedStringBuilder(org.hl7.fhir.utilities.CommaSeparatedStringBuilder) ElementDefinitionConstraintComponent(org.hl7.fhir.r5.model.ElementDefinition.ElementDefinitionConstraintComponent)

Example 44 with ElementDefinitionConstraintComponent

use of org.hl7.fhir.r4b.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();
}
Also used : CommaSeparatedStringBuilder(org.hl7.fhir.utilities.CommaSeparatedStringBuilder) ElementDefinitionConstraintComponent(org.hl7.fhir.r5.model.ElementDefinition.ElementDefinitionConstraintComponent)

Example 45 with ElementDefinitionConstraintComponent

use of org.hl7.fhir.r4b.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();
}
Also used : CommaSeparatedStringBuilder(org.hl7.fhir.utilities.CommaSeparatedStringBuilder)

Aggregations

ElementDefinitionConstraintComponent (org.hl7.fhir.r5.model.ElementDefinition.ElementDefinitionConstraintComponent)31 ValidationMessage (org.hl7.fhir.utilities.validation.ValidationMessage)25 ArrayList (java.util.ArrayList)23 ElementDefinition (org.hl7.fhir.r5.model.ElementDefinition)16 CommaSeparatedStringBuilder (org.hl7.fhir.utilities.CommaSeparatedStringBuilder)15 ElementDefinitionConstraintComponent (org.hl7.fhir.r4b.model.ElementDefinition.ElementDefinitionConstraintComponent)14 StructureDefinition (org.hl7.fhir.r5.model.StructureDefinition)12 Cell (org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.Cell)10 Piece (org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.Piece)10 DefinitionException (org.hl7.fhir.exceptions.DefinitionException)9 FHIRException (org.hl7.fhir.exceptions.FHIRException)9 ElementDefinition (org.hl7.fhir.r4b.model.ElementDefinition)9 StructureDefinition (org.hl7.fhir.r4b.model.StructureDefinition)9 Test (org.junit.jupiter.api.Test)8 FHIRFormatError (org.hl7.fhir.exceptions.FHIRFormatError)7 ElementDefinitionConstraintComponent (org.hl7.fhir.r4.model.ElementDefinition.ElementDefinitionConstraintComponent)7 TypeRefComponent (org.hl7.fhir.r5.model.ElementDefinition.TypeRefComponent)7 Rule (org.hl7.fhir.utilities.xml.SchematronWriter.Rule)7 Section (org.hl7.fhir.utilities.xml.SchematronWriter.Section)7 IOException (java.io.IOException)6