Search in sources :

Example 1 with ElementDefinitionBaseComponent

use of org.hl7.fhir.r5.model.ElementDefinition.ElementDefinitionBaseComponent in project kindling by HL7.

the class ProfileGenerator method makeExtensionSlice.

private ElementDefinition makeExtensionSlice(String extensionName, StructureDefinition p, StructureDefinitionSnapshotComponent c, ElementDefn e, String path) throws URISyntaxException, Exception {
    ElementDefinition ex = createBaseDefinition(p, path, definitions.getBaseResources().get("DomainResource").getRoot().getElementByName(definitions, extensionName, false, false, null));
    c.getElement().add(ex);
    if (!ex.hasBase())
        ex.setBase(new ElementDefinitionBaseComponent());
    ex.getBase().setPath("Element.extension");
    ex.getBase().setMin(0);
    ex.getBase().setMax("*");
    ElementDefinitionConstraintComponent inv = ex.addConstraint();
    inv.setKey("ext-1");
    inv.setSeverity(ConstraintSeverity.ERROR);
    inv.setHuman("Must have either extensions or value[x], not both");
    inv.setExpression("extension.exists() != value.exists()");
    inv.setXpath("exists(f:extension)!=exists(f:*[starts-with(local-name(.), 'value')])");
    inv.setSource("http://hl7.org/fhir/StructureDefinition/Extension");
    return ex;
}
Also used : ElementDefinition(org.hl7.fhir.r5.model.ElementDefinition) ElementDefinitionBaseComponent(org.hl7.fhir.r5.model.ElementDefinition.ElementDefinitionBaseComponent) ElementDefinitionConstraintComponent(org.hl7.fhir.r5.model.ElementDefinition.ElementDefinitionConstraintComponent)

Example 2 with ElementDefinitionBaseComponent

use of org.hl7.fhir.r5.model.ElementDefinition.ElementDefinitionBaseComponent in project kindling by HL7.

the class ProfileGenerator method defineAncestorElements.

private void defineAncestorElements(String type, String path, SnapShotMode snapshot, Set<String> containedSlices, StructureDefinition p, List<ElementDefinition> elements, String dt, boolean defaults) throws Exception {
    ElementDefn e = definitions.getElementDefn(actualTypeName(type));
    if (!Utilities.noString(e.typeCode()))
        defineAncestorElements(e.typeCode(), path, snapshot, containedSlices, p, elements, dt, defaults);
    if (!definitions.getBaseResources().containsKey(e.getName()) || !definitions.getBaseResources().get(e.getName()).isInterface()) {
        for (ElementDefn child : e.getElements()) {
            ElementDefinition ed = defineElement(null, p, elements, child, path + "." + child.getName(), containedSlices, new ArrayList<ProfileGenerator.SliceHandle>(), snapshot, false, dt, null, defaults);
            if (!ed.hasBase())
                ed.setBase(new ElementDefinitionBaseComponent());
            ed.getBase().setPath(e.getName() + "." + child.getName());
            if (child.getMinCardinality() != null)
                ed.getBase().setMin(child.getMinCardinality());
            if (child.getMaxCardinality() != null)
                ed.getBase().setMax(child.getMaxCardinality() == Integer.MAX_VALUE ? "*" : child.getMaxCardinality().toString());
            if (snapshot == SnapShotMode.DataType && ed.getPath().endsWith(".extension") && !ed.hasSlicing())
                ed.getSlicing().setDescription("Extensions are always sliced by (at least) url").setRules(SlicingRules.OPEN).addDiscriminator().setType(DiscriminatorType.VALUE).setPath("url");
        }
    }
}
Also used : ElementDefn(org.hl7.fhir.definitions.model.ElementDefn) ElementDefinition(org.hl7.fhir.r5.model.ElementDefinition) ElementDefinitionBaseComponent(org.hl7.fhir.r5.model.ElementDefinition.ElementDefinitionBaseComponent)

Aggregations

ElementDefinition (org.hl7.fhir.r5.model.ElementDefinition)2 ElementDefinitionBaseComponent (org.hl7.fhir.r5.model.ElementDefinition.ElementDefinitionBaseComponent)2 ElementDefn (org.hl7.fhir.definitions.model.ElementDefn)1 ElementDefinitionConstraintComponent (org.hl7.fhir.r5.model.ElementDefinition.ElementDefinitionConstraintComponent)1