Search in sources :

Example 51 with ElementDefn

use of org.hl7.fhir.definitions.model.ElementDefn 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 52 with ElementDefn

use of org.hl7.fhir.definitions.model.ElementDefn in project kindling by HL7.

the class ProfileGenerator method isImplicitTypeConstraint.

private String isImplicitTypeConstraint(String path) throws Exception {
    if (!path.contains("."))
        return null;
    String t = path.substring(0, path.indexOf("."));
    ElementDefn tt = definitions.getElementDefn(t);
    return isImplicitTypeConstraint(tt.getName(), tt, path);
}
Also used : ElementDefn(org.hl7.fhir.definitions.model.ElementDefn)

Example 53 with ElementDefn

use of org.hl7.fhir.definitions.model.ElementDefn in project kindling by HL7.

the class ProfileGenerator method addElementConstraint.

/*
   *     // resource
    // domain resource
    for (ElementDefn child : definitions.getBaseResources().get("DomainResource").getRoot().getElements()) 
      defineElement(null, p, p.getSnapshot(), child, r.getRoot().getName()+"."+child.getName(), containedSlices, new ArrayList<ProfileGenerator.SliceHandle>(), SnapShotMode.Resource);

   */
/*
  private String registerMapping(ConformancePackage ap, StructureDefinition p, String m) {
    for (StructureDefinitionMappingComponent map : p.getMapping()) {
      if (map.getUri().equals(m))
        return map.getIdentity();
    }
    StructureDefinitionMappingComponent map = new StructureDefinitionMappingComponent();
    MappingSpace space = definitions.getMapTypes().get(m);
    if (space != null)
      map.setIdentity(space.getId());
    else
      map.setIdentity("m" + Integer.toString(p.getMapping().size()+1));
    map.setUri(m);
    String name = ap.metadata(m+"-name");
    if (Utilities.noString(name) && space != null)
      name = space.getTitle();
    if (!Utilities.noString(name))
      map.setName(name);
    String comments = ap.metadata(m+"-comments");
    if (Utilities.noString(comments) && space != null)
        comments = space.getPreamble();
    if (!Utilities.noString(comments))
      map.setComments(comments);
    return map.getIdentity();
  }
   */
private ElementDefinition addElementConstraint(StructureDefinition sd, ElementDefinition ed) {
    if (!ed.getPath().contains(".") && sd.getKind() == StructureDefinitionKind.RESOURCE)
        return ed;
    if (hasSystemType(ed))
        return ed;
    if (isResource(ed))
        return ed;
    if (hasConstraint(ed, "ele-1"))
        return ed;
    ElementDefinitionConstraintComponent inv = ed.addConstraint();
    inv.setKey("ele-1");
    inv.setSeverity(ConstraintSeverity.ERROR);
    inv.setHuman("All FHIR elements must have a @value or children");
    inv.setExpression("hasValue() or (children().count() > id.count())");
    inv.setXpath("@value|f:*|h:div");
    inv.setSource("http://hl7.org/fhir/StructureDefinition/Element");
    return ed;
}
Also used : ElementDefinitionConstraintComponent(org.hl7.fhir.r5.model.ElementDefinition.ElementDefinitionConstraintComponent)

Example 54 with ElementDefn

use of org.hl7.fhir.definitions.model.ElementDefn in project kindling by HL7.

the class DictHTMLGenerator method describeType.

private String describeType(ElementDefn e) throws Exception {
    StringBuilder b = new StringBuilder();
    boolean first = true;
    if (e.typeCode().startsWith("@")) {
        b.append("<a href=\"#" + e.typeCode().substring(1) + "\">See " + e.typeCode().substring(1) + "</a>");
    } else {
        for (TypeRef t : e.getTypes()) {
            if (!first)
                b.append("|");
            String tn = t.getName();
            if (tn.equals("Type"))
                tn = "Element";
            if (tn.equals("*"))
                b.append("<a href=\"" + prefix + "datatypes.html#open\">*</a>");
            else
                b.append("<a href=\"" + prefix + typeLink(tn) + "\">" + tn + "</a>");
            if (t.hasParams()) {
                b.append("(");
                boolean firstp = true;
                for (String p : t.getParams()) {
                    if (!firstp)
                        b.append(" | ");
                    firstp = false;
                    if (definitions.hasLogicalModel(p)) {
                        b.append("<a href=\"" + prefix + typeLink(p) + "\">" + p + "</a>[");
                        boolean firstpn = true;
                        for (String pn : definitions.getLogicalModel(p).getImplementations()) {
                            if (!firstpn)
                                b.append(", ");
                            firstpn = false;
                            b.append("<a href=\"" + prefix + typeLink(pn) + "\">" + pn + "</a>");
                        }
                        b.append("]");
                    } else {
                        b.append("<a href=\"" + prefix + typeLink(p) + "\">" + p + "</a>");
                    }
                }
                b.append(")");
            }
            first = false;
        }
    }
    return b.toString();
}
Also used : CommaSeparatedStringBuilder(org.hl7.fhir.utilities.CommaSeparatedStringBuilder) TypeRef(org.hl7.fhir.definitions.model.TypeRef)

Example 55 with ElementDefn

use of org.hl7.fhir.definitions.model.ElementDefn in project kindling by HL7.

the class DictHTMLGenerator method generate.

public void generate(ElementDefn root) throws Exception {
    write("<table class=\"dict\">\r\n");
    writeEntry(root.getName(), "0..*", describeType(root), null, root, root.getName(), true);
    for (ElementDefn e : root.getElements()) {
        generateElement(root.getName(), e, root.getName(), false);
    }
    write("</table>\r\n");
    write("\r\n");
    flush();
    close();
}
Also used : ElementDefn(org.hl7.fhir.definitions.model.ElementDefn)

Aggregations

ElementDefn (org.hl7.fhir.definitions.model.ElementDefn)100 TypeRef (org.hl7.fhir.definitions.model.TypeRef)35 ArrayList (java.util.ArrayList)28 FHIRException (org.hl7.fhir.exceptions.FHIRException)28 CommaSeparatedStringBuilder (org.hl7.fhir.utilities.CommaSeparatedStringBuilder)21 ResourceDefn (org.hl7.fhir.definitions.model.ResourceDefn)19 Invariant (org.hl7.fhir.definitions.model.Invariant)16 IOException (java.io.IOException)14 BindingSpecification (org.hl7.fhir.definitions.model.BindingSpecification)11 FileNotFoundException (java.io.FileNotFoundException)10 URISyntaxException (java.net.URISyntaxException)10 StructureDefinition (org.hl7.fhir.r5.model.StructureDefinition)10 ProfiledType (org.hl7.fhir.definitions.model.ProfiledType)9 TransformerException (javax.xml.transform.TransformerException)8 ElementDefinition (org.hl7.fhir.r5.model.ElementDefinition)8 TransformerConfigurationException (javax.xml.transform.TransformerConfigurationException)7 NotImplementedException (org.apache.commons.lang3.NotImplementedException)7 UcumException (org.fhir.ucum.UcumException)7 TypeParser (org.hl7.fhir.definitions.parsers.TypeParser)7 DefinitionException (org.hl7.fhir.exceptions.DefinitionException)7