Search in sources :

Example 41 with ElementDefinition

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

the class ProfileGenerator method getParent.

private ElementDefinition getParent(ElementDefinition e, List<ElementDefinition> elist) {
    String p = e.getPath();
    if (!p.contains("."))
        return null;
    p = p.substring(0, p.lastIndexOf("."));
    int i = elist.indexOf(e);
    i--;
    while (i > -1) {
        if (elist.get(i).getPath().equals(p)) {
            return elist.get(i);
        }
        i--;
    }
    return null;
}
Also used : ContactPoint(org.hl7.fhir.r5.model.ContactPoint)

Example 42 with ElementDefinition

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

the class ProfileGenerator method generateBinding.

private ElementDefinitionBindingComponent generateBinding(BindingSpecification src) throws Exception {
    if (src == null)
        return null;
    ElementDefinitionBindingComponent dst = new ElementDefinitionBindingComponent();
    dst.setDescription(src.getDescription());
    if (!Utilities.noString(src.getDefinition())) {
        dst.addExtension().setUrl(BuildExtensions.EXT_DEFINITION).setValue(new StringType(src.getDefinition()));
    }
    if (src.getBinding() != BindingMethod.Unbound) {
        dst.setStrength(src.getStrength());
        dst.setValueSet(buildValueSetReference(src));
        if (src.hasMax()) {
            dst.addExtension().setUrl("http://hl7.org/fhir/StructureDefinition/elementdefinition-maxValueSet").setValue(new CanonicalType(src.getMaxReference() != null ? src.getMaxReference() : src.getMaxValueSet().getUrl()));
        }
    } else {
        dst.setStrength(BindingStrength.EXAMPLE);
    }
    dst.addExtension().setUrl("http://hl7.org/fhir/StructureDefinition/elementdefinition-bindingName").setValue(new StringType(src.getName()));
    if (src.isShared())
        dst.addExtension().setUrl("http://hl7.org/fhir/StructureDefinition/elementdefinition-isCommonBinding").setValue(new BooleanType(true));
    return dst;
}
Also used : StringType(org.hl7.fhir.r5.model.StringType) BooleanType(org.hl7.fhir.r5.model.BooleanType) ElementDefinitionBindingComponent(org.hl7.fhir.r5.model.ElementDefinition.ElementDefinitionBindingComponent) CanonicalType(org.hl7.fhir.r5.model.CanonicalType)

Example 43 with ElementDefinition

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

the class ProfileGenerator method addSpecificDetails.

private void addSpecificDetails(PrimitiveType type, ElementDefinition ed) throws FHIRFormatError {
    if (type.getCode().equals("integer")) {
        ed.setMinValue(new IntegerType(-2147483648));
        ed.setMaxValue(new IntegerType(2147483647));
    }
    if (type.getCode().equals("integer64")) {
        ed.setMinValue(new Integer64Type(-9223372036854775808L));
        ed.setMaxValue(new Integer64Type(9223372036854775807L));
    }
    if (type.getCode().equals("string")) {
        ed.setMaxLength(1024 * 1024);
    }
}
Also used : IntegerType(org.hl7.fhir.r5.model.IntegerType) Integer64Type(org.hl7.fhir.r5.model.Integer64Type)

Example 44 with ElementDefinition

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

the class ProfileGenerator method buildDefinitionFromElement.

private void buildDefinitionFromElement(String path, ElementDefinition ce, ElementDefn e, Profile ap, StructureDefinition p, String inheritedType, boolean isInterface) throws Exception {
    if (!Utilities.noString(e.getComments()))
        ce.setComment(preProcessMarkdown(e.getComments(), "Element Comments"));
    if (!Utilities.noString(e.getShortDefn()))
        ce.setShort(e.getShortDefn());
    if (!Utilities.noString(e.getDefinition())) {
        ce.setDefinition(preProcessMarkdown(e.getDefinition(), "Element Definition"));
        if (!Utilities.noString(e.getShortDefn()))
            ce.setShort(e.getShortDefn());
    }
    if (path.contains(".") && !Utilities.noString(e.getRequirements()))
        ce.setRequirements(preProcessMarkdown(e.getRequirements(), "Element Requirements"));
    if (e.hasMustSupport())
        ce.setMustSupport(e.isMustSupport());
    if (!Utilities.noString(e.getMaxLength()))
        ce.setMaxLength(Integer.parseInt(e.getMaxLength()));
    // no purpose here
    if (e.getMinCardinality() != null)
        ce.setMin(e.getMinCardinality());
    if (e.getMaxCardinality() != null)
        ce.setMax(e.getMaxCardinality() == Integer.MAX_VALUE ? "*" : e.getMaxCardinality().toString());
    // we don't know mustSupport here
    if (e.hasModifier())
        ce.setIsModifier(e.isModifier());
    if (ce.getIsModifier())
        ce.setIsModifierReason(e.getModifierReason());
    // ce.setConformance(getType(e.getConformance()));
    for (Invariant id : e.getStatedInvariants()) {
        ce.addCondition(id.getId());
    }
    ce.setFixed(e.getFixed());
    ce.setPattern(e.getPattern());
    // ce.setDefaultValue(e.getDefaultValue());
    ce.setMeaningWhenMissing(e.getMeaningWhenMissing());
    if (e.getExample() != null)
        ce.addExample().setLabel("General").setValue(e.getExample());
    for (Integer i : e.getOtherExamples().keySet()) {
        Extension ex = ce.addExtension();
        ex.setUrl("http://hl7.org/fhir/StructureDefinition/structuredefinition-example");
        ex.addExtension().setUrl("index").setValue(new StringType(i.toString()));
        ex.addExtension().setUrl("exValue").setValue(e.getOtherExamples().get(i));
    }
    for (String s : e.getAliases()) ce.addAlias(s);
    if (e.hasSummaryItem() && ce.getPath().contains("."))
        ce.setIsSummaryElement(Factory.newBoolean(e.isSummary()));
    for (String n : definitions.getMapTypes().keySet()) {
        addMapping(p, ce, n, e.getMapping(n), null);
    }
    if (ap != null) {
        for (String n : ap.getMappingSpaces().keySet()) {
            addMapping(p, ce, n, e.getMapping(n), ap);
        }
    }
    ToolingExtensions.addDisplayHint(ce, e.getDisplayHint());
    if (!isInterface) {
        convertConstraints(e, ce, inheritedType == null ? p.getUrl() : "http://hl7.org/fhir/StructureDefinition/" + inheritedType);
    }
// we don't have anything to say about constraints on resources
}
Also used : Extension(org.hl7.fhir.r5.model.Extension) Invariant(org.hl7.fhir.definitions.model.Invariant) StringType(org.hl7.fhir.r5.model.StringType)

Example 45 with ElementDefinition

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

the class ProfileGenerator method generate.

public StructureDefinition generate(DefinedStringPattern type) throws Exception {
    genUml(type);
    StructureDefinition p = new StructureDefinition();
    p.setId(type.getCode());
    p.setUrl("http://hl7.org/fhir/StructureDefinition/" + type.getCode());
    p.setBaseDefinition("http://hl7.org/fhir/StructureDefinition/" + type.getBase());
    p.setType(type.getCode());
    p.setDerivation(TypeDerivationRule.SPECIALIZATION);
    p.setKind(StructureDefinitionKind.PRIMITIVETYPE);
    p.setAbstract(false);
    p.setUserData("filename", type.getCode().toLowerCase());
    p.setUserData("path", "datatypes.html#" + type.getCode());
    p.setFhirVersion(version);
    p.setVersion(version.toCode());
    ToolingExtensions.setStandardsStatus(p, StandardsStatus.NORMATIVE, "4.0.0");
    ToolResourceUtilities.updateUsage(p, "core");
    p.setName(type.getCode());
    p.setPublisher("HL7 FHIR Standard");
    p.addContact().getTelecom().add(Factory.newContactPoint(ContactPointSystem.URL, "http://hl7.org/fhir"));
    p.setDescription("Base StructureDefinition for " + type.getCode() + " type: " + type.getDefinition());
    p.setDate(genDate.getTime());
    p.setStatus(PublicationStatus.fromCode("active"));
    Set<String> containedSlices = new HashSet<String>();
    // first, the differential
    p.setDifferential(new StructureDefinitionDifferentialComponent());
    ElementDefinition ec1 = new ElementDefinition();
    p.getDifferential().getElement().add(ec1);
    ec1.setId(type.getCode());
    ec1.setPath(type.getCode());
    ec1.setShort("Primitive Type " + type.getCode());
    ec1.setDefinition(type.getDefinition());
    ec1.setComment(type.getComment());
    ec1.setMin(0);
    ec1.setMax("*");
    ElementDefinition ec2 = new ElementDefinition();
    p.getDifferential().getElement().add(ec2);
    ec2.setId(type.getCode() + ".value");
    ec2.setPath(type.getCode() + ".value");
    ec2.addRepresentation(PropertyRepresentation.XMLATTR);
    ec2.setShort("Primitive value for " + type.getCode());
    ec2.setDefinition("Primitive value for " + type.getCode());
    ec2.setMin(0);
    ec2.setMax("1");
    TypeRefComponent t = ec2.addType();
    t.setCodeElement(new UriType());
    t.getFormatCommentsPre().add("Note: special primitive values have a FHIRPath system type. e.g. this is compiler magic (g)");
    t.setCode(Constants.NS_SYSTEM_TYPE + type.getFHIRPathType());
    ToolingExtensions.addUriExtension(t, ToolingExtensions.EXT_FHIR_TYPE, type.getCode());
    if (!Utilities.noString(type.getRegex())) {
        ToolingExtensions.addStringExtension(t, ToolingExtensions.EXT_REGEX, type.getRegex());
    }
    reset();
    // now. the snapshot
    p.setSnapshot(new StructureDefinitionSnapshotComponent());
    ElementDefinition ecA = new ElementDefinition(true, ElementDefinition.NOT_MODIFIER, ElementDefinition.NOT_IN_SUMMARY);
    p.getSnapshot().getElement().add(ecA);
    ecA.setId(type.getCode());
    ecA.setPath(type.getCode());
    ecA.setShort("Primitive Type " + type.getCode());
    ecA.setDefinition(type.getDefinition());
    ecA.setComment(type.getComment());
    ecA.setMin(0);
    ecA.setMax("*");
    ecA.makeBase(type.getCode(), 0, "*");
    addElementConstraints("Element", ecA);
    ElementDefinition ecid = new ElementDefinition(true, ElementDefinition.NOT_MODIFIER, ElementDefinition.NOT_IN_SUMMARY);
    p.getSnapshot().getElement().add(ecid);
    ecid.setId(type.getCode() + ".id");
    ecid.setPath(type.getCode() + ".id");
    ecid.addRepresentation(PropertyRepresentation.XMLATTR);
    ecid.setDefinition("unique id for the element within a resource (for internal references)");
    ecid.setMin(0);
    ecid.setMax("1");
    ecid.setShort("xml:id (or equivalent in JSON)");
    TypeRefComponent tr = ecid.addType();
    tr.getFormatCommentsPre().add("Note: special primitive values have a FHIRPath system type. e.g. this is compiler magic (h)");
    tr.setCode(Constants.NS_SYSTEM_TYPE + "String");
    ToolingExtensions.addUriExtension(tr, ToolingExtensions.EXT_FHIR_TYPE, "string");
    ecid.makeBase("Element.id", 0, "1");
    makeExtensionSlice("extension", p, p.getSnapshot(), null, type.getCode());
    ElementDefinition ecB = new ElementDefinition(true, ElementDefinition.NOT_MODIFIER, ElementDefinition.NOT_IN_SUMMARY);
    p.getSnapshot().getElement().add(ecB);
    ecB.setPath(type.getCode() + ".value");
    ecB.setId(type.getCode() + ".value");
    ecB.addRepresentation(PropertyRepresentation.XMLATTR);
    ecB.setDefinition("Primitive value for " + type.getCode());
    ecB.setShort("Primitive value for " + type.getCode());
    ecB.setMin(0);
    ecB.setMax("1");
    ecB.makeBase(type.getBase() + ".value", 0, "1");
    t = ecB.addType();
    t.getFormatCommentsPre().add("Note: special primitive values have a FHIRPath system type. e.g. this is compiler magic (i)");
    t.setCode(Constants.NS_SYSTEM_TYPE + "String");
    ToolingExtensions.addUriExtension(t, ToolingExtensions.EXT_FHIR_TYPE, "string");
    if (!Utilities.noString(type.getRegex()))
        ToolingExtensions.addStringExtension(t, ToolingExtensions.EXT_REGEX, type.getRegex());
    // generateElementDefinition(ecB, ecA);
    containedSlices.clear();
    addElementConstraintToSnapshot(p);
    XhtmlNode div = new XhtmlNode(NodeType.Element, "div");
    div.addText("to do");
    p.setText(new Narrative());
    p.getText().setStatus(NarrativeStatus.GENERATED);
    p.getText().setDiv(div);
    checkHasTypes(p);
    return p;
}
Also used : StructureDefinition(org.hl7.fhir.r5.model.StructureDefinition) TypeRefComponent(org.hl7.fhir.r5.model.ElementDefinition.TypeRefComponent) Narrative(org.hl7.fhir.r5.model.Narrative) StructureDefinitionSnapshotComponent(org.hl7.fhir.r5.model.StructureDefinition.StructureDefinitionSnapshotComponent) StructureDefinitionDifferentialComponent(org.hl7.fhir.r5.model.StructureDefinition.StructureDefinitionDifferentialComponent) ElementDefinition(org.hl7.fhir.r5.model.ElementDefinition) HashSet(java.util.HashSet) UriType(org.hl7.fhir.r5.model.UriType) XhtmlNode(org.hl7.fhir.utilities.xhtml.XhtmlNode)

Aggregations

ArrayList (java.util.ArrayList)226 ElementDefinition (org.hl7.fhir.r5.model.ElementDefinition)199 DefinitionException (org.hl7.fhir.exceptions.DefinitionException)120 FHIRException (org.hl7.fhir.exceptions.FHIRException)116 StructureDefinition (org.hl7.fhir.r5.model.StructureDefinition)92 ElementDefinition (org.hl7.fhir.r4b.model.ElementDefinition)91 ValidationMessage (org.hl7.fhir.utilities.validation.ValidationMessage)85 ElementDefinition (org.hl7.fhir.dstu3.model.ElementDefinition)82 ElementDefinition (org.hl7.fhir.r4.model.ElementDefinition)68 TypeRefComponent (org.hl7.fhir.r5.model.ElementDefinition.TypeRefComponent)60 CommaSeparatedStringBuilder (org.hl7.fhir.utilities.CommaSeparatedStringBuilder)57 Cell (org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.Cell)51 StructureDefinition (org.hl7.fhir.r4b.model.StructureDefinition)50 StructureDefinition (org.hl7.fhir.dstu3.model.StructureDefinition)46 Piece (org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.Piece)44 ElementDefinition (org.hl7.fhir.dstu2016may.model.ElementDefinition)42 ElementDefinition (org.hl7.fhir.dstu2.model.ElementDefinition)41 FHIRFormatError (org.hl7.fhir.exceptions.FHIRFormatError)41 XhtmlNode (org.hl7.fhir.utilities.xhtml.XhtmlNode)38 List (java.util.List)37