Search in sources :

Example 46 with ElementDefinition

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

the class ProfileGenerator method addExtensionConstraint.

private ElementDefinition addExtensionConstraint(StructureDefinition sd, ElementDefinition ed) {
    if (!typeIsExtension(ed))
        return ed;
    if (hasConstraint(ed, "ext-1"))
        return ed;
    ElementDefinitionConstraintComponent inv = ed.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 ed;
}
Also used : ElementDefinitionConstraintComponent(org.hl7.fhir.r5.model.ElementDefinition.ElementDefinitionConstraintComponent)

Example 47 with ElementDefinition

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

the class ProfileGenerator method generate.

public StructureDefinition generate(ProfiledType pt, List<ValidationMessage> issues) throws Exception {
    StructureDefinition p = new StructureDefinition();
    p.setId(pt.getName());
    p.setUrl("http://hl7.org/fhir/StructureDefinition/" + pt.getName());
    p.setBaseDefinition("http://hl7.org/fhir/StructureDefinition/" + pt.getBaseType());
    p.setKind(StructureDefinitionKind.COMPLEXTYPE);
    p.setType(pt.getBaseType());
    p.setDerivation(TypeDerivationRule.CONSTRAINT);
    p.setAbstract(false);
    p.setUserData("filename", pt.getName().toLowerCase());
    p.setUserData("path", "datatypes.html#" + pt.getName());
    p.setFhirVersion(version);
    p.setVersion(version.toCode());
    ToolingExtensions.setStandardsStatus(p, StandardsStatus.NORMATIVE, "4.0.0");
    p.setStatus(PublicationStatus.fromCode("active"));
    ToolResourceUtilities.updateUsage(p, "core");
    p.setName(pt.getName());
    p.setPublisher("HL7 FHIR Standard");
    p.addContact().getTelecom().add(Factory.newContactPoint(ContactPointSystem.URL, "http://hl7.org/fhir"));
    p.setDescription("Base StructureDefinition for Type " + pt.getName() + ": " + pt.getDefinition());
    p.setDescription(pt.getDefinition());
    p.setDate(genDate.getTime());
    // first, the differential
    p.setName(pt.getName());
    ElementDefinition e = new ElementDefinition();
    String idroot = e.getId();
    e.setPath(pt.getBaseType());
    // e.setSliceName(pt.getName());
    e.setShort(pt.getDefinition());
    e.setDefinition(preProcessMarkdown(pt.getDescription(), "??"));
    e.setMin(0);
    e.setMax("*");
    e.setIsModifier(false);
    String s = definitions.getTLAs().get(pt.getName().toLowerCase());
    if (s == null)
        throw new Exception("There is no TLA for '" + pt.getName() + "' in fhir.ini");
    ElementDefinitionConstraintComponent inv = new ElementDefinitionConstraintComponent();
    inv.setKey(s + "-1");
    inv.setRequirements(pt.getInvariant().getRequirements());
    inv.setSeverity(ConstraintSeverity.ERROR);
    inv.setHuman(pt.getInvariant().getEnglish());
    if (!"n/a".equals(pt.getInvariant().getExpression())) {
        fpUsages.add(new FHIRPathUsage(pt.getName(), pt.getName(), pt.getName(), null, pt.getInvariant().getExpression()));
        inv.setExpression(pt.getInvariant().getExpression());
    }
    inv.setXpath(pt.getInvariant().getXpath());
    e.getConstraint().add(inv);
    p.setDifferential(new StructureDefinitionDifferentialComponent());
    p.getDifferential().getElement().add(e);
    StructureDefinition base = getTypeSnapshot(pt.getBaseType());
    if (!pt.getRules().isEmpty()) {
        // throw new Exception("todo");
        for (String rule : pt.getRules().keySet()) {
            String[] parts = rule.split("\\.");
            String value = pt.getRules().get(rule);
            ElementDefinition er = findElement(p.getDifferential(), pt.getBaseType() + '.' + parts[0]);
            if (er == null) {
                er = new ElementDefinition();
                er.setId(pt.getBaseType() + ':' + p.getId() + '.' + parts[0]);
                er.setPath(pt.getBaseType() + '.' + parts[0]);
                p.getDifferential().getElement().add(er);
            }
            if (parts[1].equals("min"))
                er.setMin(Integer.parseInt(value));
            else if (parts[1].equals("max"))
                er.setMax(value);
            else if (parts[1].equals("defn"))
                er.setDefinition(preProcessMarkdown(value, "er"));
        }
        List<String> errors = new ArrayList<String>();
        new ProfileUtilities(context, null, pkp).sortDifferential(base, p, p.getName(), errors, true);
        for (String se : errors) issues.add(new ValidationMessage(Source.ProfileValidator, IssueType.STRUCTURE, -1, -1, p.getUrl(), se, IssueSeverity.WARNING));
    }
    reset();
    // now, the snapshot
    new ProfileUtilities(context, issues, pkp).generateSnapshot(base, p, "http://hl7.org/fhir/StructureDefinition/" + pt.getBaseType(), "http://hl7.org/fhir", p.getName());
    // for (ElementDefinition ed : p.getSnapshot().getElement())
    // generateElementDefinition(ed, getParent(ed, p.getSnapshot().getElement()));
    p.getDifferential().getElement().get(0).getType().clear();
    p.getSnapshot().getElement().get(0).getType().clear();
    XhtmlNode div = new XhtmlNode(NodeType.Element, "div");
    div.addTag("h2").addText("Data type " + pt.getName());
    div.addTag("p").addText(pt.getDefinition());
    div.addTag("h3").addText("Rule");
    div.addTag("p").addText(pt.getInvariant().getEnglish());
    div.addTag("p").addText("XPath:");
    div.addTag("blockquote").addTag("pre").addText(pt.getInvariant().getXpath());
    p.setText(new Narrative());
    p.getText().setStatus(NarrativeStatus.GENERATED);
    p.getText().setDiv(div);
    addElementConstraintToSnapshot(p);
    new ProfileUtilities(context, issues, pkp).setIds(p, false);
    checkHasTypes(p);
    return p;
}
Also used : ValidationMessage(org.hl7.fhir.utilities.validation.ValidationMessage) ArrayList(java.util.ArrayList) ElementDefinitionConstraintComponent(org.hl7.fhir.r5.model.ElementDefinition.ElementDefinitionConstraintComponent) FHIRException(org.hl7.fhir.exceptions.FHIRException) URISyntaxException(java.net.URISyntaxException) XhtmlNode(org.hl7.fhir.utilities.xhtml.XhtmlNode) StructureDefinition(org.hl7.fhir.r5.model.StructureDefinition) ProfileUtilities(org.hl7.fhir.r5.conformance.ProfileUtilities) Narrative(org.hl7.fhir.r5.model.Narrative) StructureDefinitionDifferentialComponent(org.hl7.fhir.r5.model.StructureDefinition.StructureDefinitionDifferentialComponent) ElementDefinition(org.hl7.fhir.r5.model.ElementDefinition) FHIRPathUsage(org.hl7.fhir.definitions.validation.FHIRPathUsage)

Example 48 with ElementDefinition

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

the class ProfileGenerator method generateXhtml.

public StructureDefinition generateXhtml() throws Exception {
    uml.getTypes().put("html:div", new UMLPrimitive("html:div"));
    StructureDefinition p = new StructureDefinition();
    p.setId("xhtml");
    p.setUrl("http://hl7.org/fhir/StructureDefinition/xhtml");
    p.setKind(StructureDefinitionKind.PRIMITIVETYPE);
    p.setAbstract(false);
    p.setUserData("filename", "xhtml");
    p.setUserData("path", "narrative.html#xhtml");
    p.setBaseDefinition("http://hl7.org/fhir/StructureDefinition/Element");
    p.setType("xhtml");
    p.setDerivation(TypeDerivationRule.SPECIALIZATION);
    p.setFhirVersion(version);
    p.setVersion(version.toCode());
    ToolingExtensions.setStandardsStatus(p, StandardsStatus.NORMATIVE, "4.0.0");
    ToolResourceUtilities.updateUsage(p, "core");
    p.setName("xhtml");
    p.setPublisher("HL7 FHIR Standard");
    p.addContact().getTelecom().add(Factory.newContactPoint(ContactPointSystem.URL, "http://hl7.org/fhir"));
    p.setDescription("Base StructureDefinition for xhtml Type");
    p.setDate(genDate.getTime());
    p.setStatus(PublicationStatus.fromCode("active"));
    Set<String> containedSlices = new HashSet<String>();
    // first, the differential
    p.setDifferential(new StructureDefinitionDifferentialComponent());
    ElementDefinition ec = new ElementDefinition();
    p.getDifferential().getElement().add(ec);
    ec.setId("xhtml");
    ec.setPath("xhtml");
    ec.setShort("Primitive Type " + "xhtml");
    ec.setDefinition("XHTML");
    ec.setMin(0);
    ec.setMax("*");
    ec = new ElementDefinition();
    p.getDifferential().getElement().add(ec);
    ec.setId("xhtml" + ".extension");
    ec.setPath("xhtml" + ".extension");
    ec.setMax("0");
    ec = new ElementDefinition();
    p.getDifferential().getElement().add(ec);
    ec.setId("xhtml" + ".value");
    ec.setPath("xhtml" + ".value");
    ec.addRepresentation(PropertyRepresentation.XHTML);
    ec.setShort("Actual xhtml");
    ec.setDefinition("Actual xhtml");
    ec.setMin(1);
    ec.setMax("1");
    TypeRefComponent t = ec.addType();
    t.setCodeElement(new UriType());
    t.getFormatCommentsPre().add("Note: special primitive values have a FHIRPath system type. e.g. this is compiler magic (d)");
    t.setCode(Constants.NS_SYSTEM_TYPE + "String");
    ToolingExtensions.addUriExtension(t, ToolingExtensions.EXT_FHIR_TYPE, "string");
    reset();
    // now. the snapshot
    p.setSnapshot(new StructureDefinitionSnapshotComponent());
    ElementDefinition ec1 = new ElementDefinition(true, ElementDefinition.NOT_MODIFIER, ElementDefinition.NOT_IN_SUMMARY);
    p.getSnapshot().getElement().add(ec1);
    ec1.setId("xhtml");
    ec1.setPath("xhtml");
    ec1.setShort("Primitive Type " + "xhtml");
    ec1.setDefinition("XHTML");
    ec1.setMin(0);
    ec1.setMin(0);
    ec1.setMax("*");
    ec1.makeBase();
    generateElementDefinition(p, ec1, null);
    ElementDefinition ec2 = new ElementDefinition(true, ElementDefinition.NOT_MODIFIER, ElementDefinition.NOT_IN_SUMMARY);
    p.getSnapshot().getElement().add(ec2);
    ec2.setId("xhtml.id");
    ec2.setPath("xhtml.id");
    ec2.addRepresentation(PropertyRepresentation.XMLATTR);
    ec2.setDefinition("unique id for the element within a resource (for internal references)");
    ec2.setMin(0);
    ec2.setMax("1");
    ec2.setShort("xml:id (or equivalent in JSON)");
    TypeRefComponent tr = ec2.addType();
    t.getFormatCommentsPre().add("Note: special primitive values have a FHIRPath system type. e.g. this is compiler magic (e)");
    tr.setCode(Constants.NS_SYSTEM_TYPE + "String");
    ToolingExtensions.addUriExtension(t, ToolingExtensions.EXT_FHIR_TYPE, "string");
    generateElementDefinition(p, ec2, ec1);
    ec2.makeBase("Element.id", 0, "1");
    ElementDefinition ex = makeExtensionSlice("extension", p, p.getSnapshot(), null, "xhtml");
    ex.setMax("0");
    ElementDefinition ec3 = new ElementDefinition(true, ElementDefinition.NOT_MODIFIER, ElementDefinition.NOT_IN_SUMMARY);
    p.getSnapshot().getElement().add(ec3);
    ec3.setId("xhtml.value");
    ec3.setPath("xhtml.value");
    ec3.addRepresentation(PropertyRepresentation.XHTML);
    ec3.setShort("Actual xhtml");
    ec3.setDefinition("Actual xhtml");
    ec3.setMin(1);
    ec3.setMax("1");
    t = ec3.addType();
    t.setCodeElement(new UriType());
    t.getFormatCommentsPre().add("Note: special primitive values have a FHIRPath system type. e.g. this is compiler magic (f)");
    t.setCode(Constants.NS_SYSTEM_TYPE + "String");
    ToolingExtensions.addUriExtension(t, ToolingExtensions.EXT_FHIR_TYPE, "string");
    ec3.makeBase();
    generateElementDefinition(p, ec3, ec);
    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) UMLPrimitive(org.hl7.fhir.definitions.uml.UMLPrimitive) 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)

Example 49 with ElementDefinition

use of org.hl7.fhir.r4b.model.ElementDefinition 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 50 with ElementDefinition

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

the class ProfileGenerator method produceOpParam.

private void produceOpParam(String path, List<OperationDefinitionParameterComponent> opd, OperationParameter p, OperationParameterUse defUse) throws Exception {
    OperationDefinitionParameterComponent pp = new OperationDefinitionParameterComponent();
    pp.setName(p.getName());
    if (path.contains("."))
        pp.setUse(defUse);
    else if (p.getUse().equals("in"))
        pp.setUse(OperationParameterUse.IN);
    else if (p.getUse().equals("out"))
        pp.setUse(OperationParameterUse.OUT);
    else
        // but this is validated elsewhere
        throw new Exception("Unable to determine parameter use: " + p.getUse() + " at " + path + "." + p.getName());
    pp.setDocumentation(preProcessMarkdown(p.getDoc(), "Operation Parameter Doco"));
    pp.setMin(p.getMin());
    pp.setMax(p.getMax());
    if (p.getBs() != null) {
        if (p.getBs().hasMax())
            throw new Error("Max binding not handled yet");
        pp.setBinding(new OperationDefinitionParameterBindingComponent().setStrength(p.getBs().getStrength()).setValueSet(buildValueSetReference(p.getBs())));
        if (!Utilities.noString(p.getBinding().getName())) {
            pp.getBinding().addExtension("http://hl7.org/fhir/StructureDefinition/elementdefinition-bindingName", new StringType(p.getBinding().getName()));
        }
    }
    if (!Utilities.noString(p.getProfile())) {
        pp.addTargetProfile(p.getProfile());
    }
    opd.add(pp);
    if (p.getFhirType().equals("Tuple")) {
        for (OperationParameter part : p.getParts()) {
            produceOpParam(path + "." + p.getName(), pp.getPart(), part, pp.getUse());
        }
    } else {
        List<TypeRef> trs = new TypeParser(version.toCode()).parse(p.getFhirType(), false, null, null, false);
        if (trs.size() > 1) {
            if (p.getSearchType() != null)
                pp.setSearchType(SearchParamType.fromCode(p.getSearchType()));
            pp.setType(Enumerations.FHIRAllTypes.fromCode("Element"));
            for (TypeRef tr : trs) {
                pp.addExtension(ToolingExtensions.EXT_ALLOWED_TYPE, new UriType(tr.getName()));
                if (tr.getParams().size() > 0)
                    throw new Error("Multiple types for an operation parameter, where one is a reference, is not supported by the build tools");
            }
        } else {
            TypeRef tr = trs.get(0);
            if (definitions.getConstraints().containsKey(tr.getName())) {
                ProfiledType pt = definitions.getConstraints().get(tr.getName());
                pp.setType(Enumerations.FHIRAllTypes.fromCode(pt.getBaseType().equals("*") ? "Type" : pt.getBaseType()));
                pp.addTargetProfile("http://hl7.org/fhir/StructureDefinition/" + pt.getName());
            } else {
                if (p.getSearchType() != null)
                    pp.setSearchType(SearchParamType.fromCode(p.getSearchType()));
                pp.setType(Enumerations.FHIRAllTypes.fromCode(tr.getName().equals("*") ? "Type" : tr.getName()));
                if (tr.getParams().size() == 1 && !tr.getParams().get(0).equals("Any"))
                    pp.addTargetProfile("http://hl7.org/fhir/StructureDefinition/" + tr.getParams().get(0));
            }
        }
    }
}
Also used : TypeParser(org.hl7.fhir.definitions.parsers.TypeParser) ProfiledType(org.hl7.fhir.definitions.model.ProfiledType) StringType(org.hl7.fhir.r5.model.StringType) TypeRef(org.hl7.fhir.definitions.model.TypeRef) OperationDefinitionParameterBindingComponent(org.hl7.fhir.r5.model.OperationDefinition.OperationDefinitionParameterBindingComponent) OperationParameter(org.hl7.fhir.definitions.model.OperationParameter) FHIRFormatError(org.hl7.fhir.exceptions.FHIRFormatError) FHIRException(org.hl7.fhir.exceptions.FHIRException) URISyntaxException(java.net.URISyntaxException) OperationDefinitionParameterComponent(org.hl7.fhir.r5.model.OperationDefinition.OperationDefinitionParameterComponent) UriType(org.hl7.fhir.r5.model.UriType)

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