Search in sources :

Example 6 with DefinedStringPattern

use of org.hl7.fhir.definitions.model.DefinedStringPattern 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)

Example 7 with DefinedStringPattern

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

the class FhirTurtleGenerator method genDefinedStringPattern.

/**
 * DefinedStringPattern Generator
 *
 * @param dsp FHIR DefinedStringPattern Type (e.g. id, oid, uuid)
 * @throws Exception
 */
private void genDefinedStringPattern(DefinedStringPattern dsp) throws Exception {
    String dspType = dsp.getSchema();
    String dspTypeName = dspType.endsWith("+") ? dspType.substring(0, dspType.length() - 1) : dspType;
    Resource dspTypeRes = RDFTypeMap.xsd_type_for(dspTypeName, owlTarget);
    FHIRResource dspRes = fact.fhir_class(dsp.getCode(), dsp.getBase()).addDefinition(dsp.getDefinition());
    if (dspRes != null) {
        if (dspType.endsWith("+")) {
            List<Resource> facets = new ArrayList<Resource>(1);
            facets.add(fact.fhir_pattern(dsp.getRegex()));
            dspRes.restriction(fact.fhir_restriction(value, fact.fhir_datatype_restriction(dspTypeRes == XSD.xstring ? XSD.normalizedString : dspTypeRes, facets)));
        } else
            dspRes.restriction(fact.fhir_restriction(value, dspTypeRes));
    }
}
Also used : FHIRResource(org.hl7.fhir.rdf.FHIRResource) Resource(org.apache.jena.rdf.model.Resource) FHIRResource(org.hl7.fhir.rdf.FHIRResource) ArrayList(java.util.ArrayList)

Example 8 with DefinedStringPattern

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

the class XSDBaseGenerator method genPrimitives.

private void genPrimitives() throws Exception {
    for (DefinedCode cd : definitions.getPrimitives().values()) {
        if (cd instanceof PrimitiveType) {
            PrimitiveType pt = (PrimitiveType) cd;
            // two very special cases due to schema weirdness
            if (cd.getCode().equals("date")) {
                write("  <xs:simpleType name=\"date-primitive\">\r\n");
                write("    <xs:restriction>\r\n");
                write("      <xs:simpleType>\r\n");
                write("        <xs:union memberTypes=\"xs:gYear xs:gYearMonth xs:date\"/>\r\n");
                write("      </xs:simpleType>\r\n");
                write("      <xs:pattern value=\"([0-9]([0-9]([0-9][1-9]|[1-9]0)|[1-9]00)|[1-9]000)(-(0[1-9]|1[0-2])(-(0[0-9]|[1-2][0-9]|3[0-1]))?)?\"/>\r\n");
                write("    </xs:restriction>\r\n");
                write("  </xs:simpleType>\r\n");
            } else if (cd.getCode().equals("dateTime")) {
                write("  <xs:simpleType name=\"dateTime-primitive\">\r\n");
                write("    <xs:restriction>\r\n");
                write("      <xs:simpleType>\r\n");
                write("        <xs:union memberTypes=\"xs:gYear xs:gYearMonth xs:date xs:dateTime\"/>\r\n");
                write("      </xs:simpleType>\r\n");
                write("      <xs:pattern value=\"([0-9]([0-9]([0-9][1-9]|[1-9]0)|[1-9]00)|[1-9]000)(-(0[1-9]|1[0-2])(-(0[0-9]|[1-2][0-9]|3[0-1])(T([01][0-9]|2[0-3]):[0-5][0-9]:([0-5][0-9]|60)(\\.[0-9]+)?(Z|(\\+|-)((0[0-9]|1[0-3]):[0-5][0-9]|14:00)))?)?)?\"/>\r\n");
                write("    </xs:restriction>\r\n");
                write("  </xs:simpleType>\r\n");
            } else if (cd.getCode().equals("time")) {
                write("  <xs:simpleType name=\"time-primitive\">\r\n");
                write("    <xs:restriction base=\"xs:time\">\r\n");
                write("      <xs:pattern value=\"([01][0-9]|2[0-3]):[0-5][0-9]:([0-5][0-9]|60)(\\.[0-9]+)?\"/>\r\n");
                write("    </xs:restriction>\r\n");
                write("  </xs:simpleType>\r\n");
            } else {
                write("  <xs:simpleType name=\"" + pt.getCode() + "-primitive\">\r\n");
                if (pt.getSchemaType().contains(",")) {
                    write("    <xs:union memberTypes=\"" + pt.getSchemaType().replace(",", "") + "\"/>\r\n");
                } else if (pt.getSchemaType().equals("string")) {
                    write("    <xs:restriction base=\"xs:" + pt.getSchemaType() + "\">\r\n");
                    write("      <xs:minLength value=\"1\"/>\r\n");
                    write("    </xs:restriction>\r\n");
                } else if (!Utilities.noString(pt.getRegex())) {
                    write("    <xs:restriction base=\"xs:" + pt.getSchemaType() + "\">\r\n");
                    write("      <xs:pattern value=\"" + pt.getRegex() + "\"/>\r\n");
                    write("    </xs:restriction>\r\n");
                } else {
                    write("    <xs:restriction base=\"xs:" + pt.getSchemaType() + "\"/>\r\n");
                }
                write("  </xs:simpleType>\r\n");
            }
            write("  <xs:complexType name=\"" + pt.getCode() + "\">\r\n");
            write("    <xs:annotation>\r\n");
            write("      <xs:documentation xml:lang=\"en\">" + Utilities.escapeXml(pt.getDefinition()) + "</xs:documentation>\r\n");
            if (!Utilities.noString(pt.getComment()))
                write("      <xs:documentation xml:lang=\"en\">" + Utilities.escapeXml(pt.getComment()) + "</xs:documentation>\r\n");
            write("      <xs:documentation xml:lang=\"en\">If the element is present, it must have either a @value, an @id, or extensions</xs:documentation>\r\n");
            write("    </xs:annotation>\r\n");
            write("    <xs:complexContent>\r\n");
            write("      <xs:extension base=\"Element\">\r\n");
            write("        <xs:attribute name=\"value\" type=\"" + pt.getCode() + "-primitive\" use=\"optional\"/>\r\n");
            write("      </xs:extension>\r\n");
            write("    </xs:complexContent>\r\n");
            write("  </xs:complexType>\r\n");
        } else {
            DefinedStringPattern sp = (DefinedStringPattern) cd;
            write("  <xs:simpleType name=\"" + sp.getCode() + "-primitive\">\r\n");
            if (sp.getSchema().endsWith("+")) {
                write("    <xs:restriction base=\"" + sp.getSchema().substring(0, sp.getSchema().length() - 1) + "\">\r\n");
                write("      <xs:pattern value=\"" + sp.getRegex() + "\"/>\r\n");
                write("      <xs:minLength value=\"1\"/>\r\n");
                if (sp.getCode().equals("id"))
                    write("      <xs:maxLength value=\"64\"/>\r\n");
                write("    </xs:restriction>\r\n");
                write("  </xs:simpleType>\r\n");
            } else {
                write("    <xs:restriction base=\"" + sp.getSchema() + "\">\r\n");
                if (!sp.getSchema().contains("Integer")) {
                    write("      <xs:minLength value=\"1\"/>\r\n");
                }
                if (!Utilities.noString(sp.getRegex())) {
                    write("      <xs:pattern value=\"" + sp.getRegex() + "\"/>\r\n");
                }
                write("    </xs:restriction>\r\n");
                write("  </xs:simpleType>\r\n");
            }
            write("  <xs:complexType name=\"" + sp.getCode() + "\">\r\n");
            write("    <xs:annotation>\r\n");
            write("      <xs:documentation xml:lang=\"en\">" + Utilities.escapeXml(sp.getDefinition()) + "</xs:documentation>\r\n");
            if (!Utilities.noString(sp.getComment()))
                write("      <xs:documentation xml:lang=\"en\">" + Utilities.escapeXml(sp.getComment()) + "</xs:documentation>\r\n");
            write("      <xs:documentation xml:lang=\"en\">If the element is present, it must have either a @value, an @id referenced from the Narrative, or extensions</xs:documentation>\r\n");
            write("    </xs:annotation>\r\n");
            write("    <xs:complexContent>\r\n");
            write("      <xs:extension base=\"Element\">\r\n");
            write("        <xs:attribute name=\"value\" type=\"" + sp.getCode() + "-primitive\"/>\r\n");
            write("      </xs:extension>\r\n");
            write("    </xs:complexContent>\r\n");
            write("  </xs:complexType>\r\n");
        }
    }
}
Also used : DefinedStringPattern(org.hl7.fhir.definitions.model.DefinedStringPattern) DefinedCode(org.hl7.fhir.definitions.model.DefinedCode) PrimitiveType(org.hl7.fhir.definitions.model.PrimitiveType)

Example 9 with DefinedStringPattern

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

the class SourceParser method processStringPattern.

private void processStringPattern(Sheet sheet, int row) throws Exception {
    DefinedStringPattern prim = new DefinedStringPattern();
    prim.setCode(sheet.getColumn(row, "Data Type"));
    prim.setDefinition(sheet.getColumn(row, "Definition"));
    prim.setComment(sheet.getColumn(row, "Comments"));
    prim.setRegex(sheet.getColumn(row, "RegEx"));
    prim.setSchema(sheet.getColumn(row, "Schema"));
    prim.setJsonType(sheet.getColumn(row, "Json"));
    prim.setBase(sheet.getColumn(row, "Base"));
    TypeRef td = new TypeRef();
    td.setName(prim.getCode());
    definitions.getKnownTypes().add(td);
    definitions.getPrimitives().put(prim.getCode(), prim);
}
Also used : DefinedStringPattern(org.hl7.fhir.definitions.model.DefinedStringPattern) TypeRef(org.hl7.fhir.definitions.model.TypeRef)

Aggregations

DefinedStringPattern (org.hl7.fhir.definitions.model.DefinedStringPattern)5 DefinedCode (org.hl7.fhir.definitions.model.DefinedCode)4 ProfiledType (org.hl7.fhir.definitions.model.ProfiledType)3 StructureDefinition (org.hl7.fhir.r5.model.StructureDefinition)3 FileNotFoundException (java.io.FileNotFoundException)2 IOException (java.io.IOException)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 TransformerException (javax.xml.transform.TransformerException)2 ProfileGenerator (org.hl7.fhir.definitions.generators.specification.ProfileGenerator)2 ElementDefn (org.hl7.fhir.definitions.model.ElementDefn)2 PrimitiveType (org.hl7.fhir.definitions.model.PrimitiveType)2 FHIRException (org.hl7.fhir.exceptions.FHIRException)2 XhtmlNode (org.hl7.fhir.utilities.xhtml.XhtmlNode)2 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 Resource (org.apache.jena.rdf.model.Resource)1 ResourceTableGenerator (org.hl7.fhir.definitions.generators.specification.ResourceTableGenerator)1 ConstraintStructure (org.hl7.fhir.definitions.model.ConstraintStructure)1 ImplementationGuideDefn (org.hl7.fhir.definitions.model.ImplementationGuideDefn)1 LogicalModel (org.hl7.fhir.definitions.model.LogicalModel)1