Search in sources :

Example 6 with ElementDefinitionSlicingComponent

use of org.hl7.fhir.r5.model.ElementDefinition.ElementDefinitionSlicingComponent in project org.hl7.fhir.core by hapifhir.

the class ProfileUtilities method makeExtensionSlicing.

private ElementDefinitionSlicingComponent makeExtensionSlicing() {
    ElementDefinitionSlicingComponent slice = new ElementDefinitionSlicingComponent();
    nextSliceId++;
    slice.setId(Integer.toString(nextSliceId));
    slice.addDiscriminator().setPath("url").setType(DiscriminatorType.VALUE);
    slice.setOrdered(false);
    slice.setRules(SlicingRules.OPEN);
    return slice;
}
Also used : ElementDefinitionSlicingComponent(org.hl7.fhir.dstu3.model.ElementDefinition.ElementDefinitionSlicingComponent)

Example 7 with ElementDefinitionSlicingComponent

use of org.hl7.fhir.r5.model.ElementDefinition.ElementDefinitionSlicingComponent in project org.hl7.fhir.core by hapifhir.

the class ProfileUtilities method summariseSlicing.

private String summariseSlicing(ElementDefinitionSlicingComponent slice) {
    StringBuilder b = new StringBuilder();
    boolean first = true;
    for (ElementDefinitionSlicingDiscriminatorComponent d : slice.getDiscriminator()) {
        if (first)
            first = false;
        else
            b.append(", ");
        b.append(d);
    }
    b.append("(");
    if (slice.hasOrdered())
        b.append(slice.getOrderedElement().asStringValue());
    b.append("/");
    if (slice.hasRules())
        b.append(slice.getRules().toCode());
    b.append(")");
    if (slice.hasDescription()) {
        b.append(" \"");
        b.append(slice.getDescription());
        b.append("\"");
    }
    return b.toString();
}
Also used : ElementDefinitionSlicingDiscriminatorComponent(org.hl7.fhir.dstu3.model.ElementDefinition.ElementDefinitionSlicingDiscriminatorComponent) CommaSeparatedStringBuilder(org.hl7.fhir.utilities.CommaSeparatedStringBuilder)

Example 8 with ElementDefinitionSlicingComponent

use of org.hl7.fhir.r5.model.ElementDefinition.ElementDefinitionSlicingComponent in project org.hl7.fhir.core by hapifhir.

the class ProfileUtilities method summariseSlicing.

private String summariseSlicing(ElementDefinitionSlicingComponent slice) {
    StringBuilder b = new StringBuilder();
    boolean first = true;
    for (StringType d : slice.getDiscriminator()) {
        if (first)
            first = false;
        else
            b.append(", ");
        b.append(d);
    }
    b.append("(");
    if (slice.hasOrdered())
        b.append(slice.getOrderedElement().asStringValue());
    b.append("/");
    if (slice.hasRules())
        b.append(slice.getRules().toCode());
    b.append(")");
    if (slice.hasDescription()) {
        b.append(" \"");
        b.append(slice.getDescription());
        b.append("\"");
    }
    return b.toString();
}
Also used : CommaSeparatedStringBuilder(org.hl7.fhir.utilities.CommaSeparatedStringBuilder) StringType(org.hl7.fhir.dstu2.model.StringType)

Example 9 with ElementDefinitionSlicingComponent

use of org.hl7.fhir.r5.model.ElementDefinition.ElementDefinitionSlicingComponent in project org.hl7.fhir.core by hapifhir.

the class ProfileUtilities method generateSlicer.

private Slicer generateSlicer(ElementDefinition child, ElementDefinitionSlicingComponent slicing, StructureDefinition structure) {
    // given a child in a structure, it's sliced. figure out the slicing xpath
    if (child.getPath().endsWith(".extension")) {
        ElementDefinition ued = getUrlFor(structure, child);
        if ((ued == null || !ued.hasFixed()) && !(child.getType().get(0).hasProfile()))
            return new Slicer(false);
        else {
            Slicer s = new Slicer(true);
            String url = (ued == null || !ued.hasFixed()) ? child.getType().get(0).getProfile().get(0).asStringValue() : ((UriType) ued.getFixed()).asStringValue();
            s.name = " with URL = '" + url + "'";
            s.criteria = "[@url = '" + url + "']";
            return s;
        }
    } else
        return new Slicer(false);
}
Also used : ElementDefinition(org.hl7.fhir.dstu2.model.ElementDefinition)

Example 10 with ElementDefinitionSlicingComponent

use of org.hl7.fhir.r5.model.ElementDefinition.ElementDefinitionSlicingComponent in project org.hl7.fhir.core by hapifhir.

the class ProfileUtilities method generateForChildren.

private void generateForChildren(SchematronWriter sch, String xpath, ElementDefinition ed, StructureDefinition structure, StructureDefinition base) throws IOException {
    // generateForChild(txt, structure, child);
    List<ElementDefinition> children = getChildList(structure, ed);
    String sliceName = null;
    ElementDefinitionSlicingComponent slicing = null;
    for (ElementDefinition child : children) {
        String name = tail(child.getPath());
        if (child.hasSlicing()) {
            sliceName = name;
            slicing = child.getSlicing();
        } else if (!name.equals(sliceName))
            slicing = null;
        ElementDefinition based = getByPath(base, child.getPath());
        boolean doMin = (child.getMin() > 0) && (based == null || (child.getMin() != based.getMin()));
        boolean doMax = !child.getMax().equals("*") && (based == null || (!child.getMax().equals(based.getMax())));
        Slicer slicer = slicing == null ? new Slicer(true) : generateSlicer(child, slicing, structure);
        if (slicer.check) {
            if (doMin || doMax) {
                Section s = sch.section(xpath);
                Rule r = s.rule(xpath);
                if (doMin)
                    r.assrt("count(f:" + name + slicer.criteria + ") >= " + Integer.toString(child.getMin()), name + slicer.name + ": minimum cardinality of '" + name + "' is " + Integer.toString(child.getMin()));
                if (doMax)
                    r.assrt("count(f:" + name + slicer.criteria + ") <= " + child.getMax(), name + slicer.name + ": maximum cardinality of '" + name + "' is " + child.getMax());
            }
        }
    }
    for (ElementDefinitionConstraintComponent inv : ed.getConstraint()) {
        if (inv.hasXpath()) {
            Section s = sch.section(ed.getPath());
            Rule r = s.rule(xpath);
            r.assrt(inv.getXpath(), (inv.hasId() ? inv.getId() + ": " : "") + inv.getHuman() + (inv.hasUserData(IS_DERIVED) ? " (inherited)" : ""));
        }
    }
    for (ElementDefinition child : children) {
        String name = tail(child.getPath());
        generateForChildren(sch, xpath + "/f:" + name, child, structure, base);
    }
}
Also used : ElementDefinitionSlicingComponent(org.hl7.fhir.dstu2.model.ElementDefinition.ElementDefinitionSlicingComponent) ElementDefinition(org.hl7.fhir.dstu2.model.ElementDefinition) Rule(org.hl7.fhir.utilities.xml.SchematronWriter.Rule) Section(org.hl7.fhir.utilities.xml.SchematronWriter.Section) ElementDefinitionConstraintComponent(org.hl7.fhir.dstu2.model.ElementDefinition.ElementDefinitionConstraintComponent)

Aggregations

CommaSeparatedStringBuilder (org.hl7.fhir.utilities.CommaSeparatedStringBuilder)11 DefinitionException (org.hl7.fhir.exceptions.DefinitionException)7 ElementDefinitionSlicingDiscriminatorComponent (org.hl7.fhir.r5.model.ElementDefinition.ElementDefinitionSlicingDiscriminatorComponent)6 Rule (org.hl7.fhir.utilities.xml.SchematronWriter.Rule)6 Section (org.hl7.fhir.utilities.xml.SchematronWriter.Section)6 FHIRException (org.hl7.fhir.exceptions.FHIRException)4 FHIRFormatError (org.hl7.fhir.exceptions.FHIRFormatError)4 ElementDefinition (org.hl7.fhir.r4.model.ElementDefinition)4 ElementDefinitionSlicingComponent (org.hl7.fhir.r4.model.ElementDefinition.ElementDefinitionSlicingComponent)4 ElementDefinition (org.hl7.fhir.r4b.model.ElementDefinition)4 ElementDefinition (org.hl7.fhir.r5.model.ElementDefinition)4 ElementDefinitionSlicingComponent (org.hl7.fhir.r5.model.ElementDefinition.ElementDefinitionSlicingComponent)4 ArrayList (java.util.ArrayList)3 List (java.util.List)3 ElementDefinition (org.hl7.fhir.dstu2.model.ElementDefinition)3 ElementDefinitionSlicingComponent (org.hl7.fhir.dstu2.model.ElementDefinition.ElementDefinitionSlicingComponent)3 ElementDefinition (org.hl7.fhir.dstu2016may.model.ElementDefinition)3 ElementDefinitionSlicingComponent (org.hl7.fhir.dstu2016may.model.ElementDefinition.ElementDefinitionSlicingComponent)3 ElementDefinition (org.hl7.fhir.dstu3.model.ElementDefinition)3 ElementDefinitionSlicingComponent (org.hl7.fhir.dstu3.model.ElementDefinition.ElementDefinitionSlicingComponent)3