Search in sources :

Example 91 with DataType

use of org.hl7.fhir.r5.model.DataType in project org.hl7.fhir.core by hapifhir.

the class ProfileUtilities method genFixedValue.

private void genFixedValue(HierarchicalTableGenerator gen, Row erow, DataType value, boolean snapshot, boolean pattern, String corePath, boolean skipnoValue) {
    String ref = pkp.getLinkFor(corePath, value.fhirType());
    if (ref != null && ref.contains(".html")) {
        ref = ref.substring(0, ref.indexOf(".html")) + "-definitions.html#";
    } else {
        ref = "?gen-fv?";
    }
    StructureDefinition sd = context.fetchTypeDefinition(value.fhirType());
    for (org.hl7.fhir.r5.model.Property t : value.children()) {
        if (t.getValues().size() > 0 || snapshot) {
            ElementDefinition ed = findElementDefinition(sd, t.getName());
            if (t.getValues().size() == 0 || (t.getValues().size() == 1 && t.getValues().get(0).isEmpty())) {
                if (!skipnoValue) {
                    Row row = gen.new Row();
                    erow.getSubRows().add(row);
                    Cell c = gen.new Cell();
                    row.getCells().add(c);
                    c.addPiece(gen.new Piece((ed.getBase().getPath().equals(ed.getPath()) ? ref + ed.getPath() : corePath + (VersionUtilities.isR5Ver(context.getVersion()) ? "types-definitions.html#" + ed.getBase().getPath() : "element-definitions.html#" + ed.getBase().getPath())), t.getName(), null));
                    c = gen.new Cell();
                    row.getCells().add(c);
                    c.addPiece(gen.new Piece(null, null, null));
                    c = gen.new Cell();
                    row.getCells().add(c);
                    if (!pattern) {
                        c.addPiece(gen.new Piece(null, "0..0", null));
                        row.setIcon("icon_fixed.gif", "Fixed Value");
                    } else if (isPrimitive(t.getTypeCode())) {
                        row.setIcon("icon_primitive.png", HierarchicalTableGenerator.TEXT_ICON_PRIMITIVE);
                        c.addPiece(gen.new Piece(null, "0.." + (t.getMaxCardinality() == 2147483647 ? "*" : Integer.toString(t.getMaxCardinality())), null));
                    } else if (isReference(t.getTypeCode())) {
                        row.setIcon("icon_reference.png", HierarchicalTableGenerator.TEXT_ICON_REFERENCE);
                        c.addPiece(gen.new Piece(null, "0.." + (t.getMaxCardinality() == 2147483647 ? "*" : Integer.toString(t.getMaxCardinality())), null));
                    } else {
                        row.setIcon("icon_datatype.gif", HierarchicalTableGenerator.TEXT_ICON_DATATYPE);
                        c.addPiece(gen.new Piece(null, "0.." + (t.getMaxCardinality() == 2147483647 ? "*" : Integer.toString(t.getMaxCardinality())), null));
                    }
                    c = gen.new Cell();
                    row.getCells().add(c);
                    if (t.getTypeCode().contains("(")) {
                        String tc = t.getTypeCode();
                        String tn = tc.substring(0, tc.indexOf("("));
                        c.addPiece(gen.new Piece(pkp.getLinkFor(corePath, tn), tn, null));
                        c.addPiece(gen.new Piece(null, "(", null));
                        String[] p = tc.substring(tc.indexOf("(") + 1, tc.indexOf(")")).split("\\|");
                        for (String s : p) {
                            c.addPiece(gen.new Piece(pkp.getLinkFor(corePath, s), s, null));
                        }
                        c.addPiece(gen.new Piece(null, ")", null));
                    } else {
                        c.addPiece(gen.new Piece(pkp.getLinkFor(corePath, t.getTypeCode()), t.getTypeCode(), null));
                    }
                    c = gen.new Cell();
                    c.addPiece(gen.new Piece(null, ed.getShort(), null));
                    row.getCells().add(c);
                }
            } else {
                for (Base b : t.getValues()) {
                    Row row = gen.new Row();
                    erow.getSubRows().add(row);
                    row.setIcon("icon_fixed.gif", "Fixed Value");
                    Cell c = gen.new Cell();
                    row.getCells().add(c);
                    c.addPiece(gen.new Piece((ed.getBase().getPath().equals(ed.getPath()) ? ref + ed.getPath() : (VersionUtilities.isThisOrLater("4.1", context.getVersion()) ? corePath + "types-definitions.html#" + ed.getBase().getPath() : corePath + "element-definitions.html#" + ed.getBase().getPath())), t.getName(), null));
                    c = gen.new Cell();
                    row.getCells().add(c);
                    c.addPiece(gen.new Piece(null, null, null));
                    c = gen.new Cell();
                    row.getCells().add(c);
                    if (pattern)
                        c.addPiece(gen.new Piece(null, "1.." + (t.getMaxCardinality() == 2147483647 ? "*" : Integer.toString(t.getMaxCardinality())), null));
                    else
                        c.addPiece(gen.new Piece(null, "1..1", null));
                    c = gen.new Cell();
                    row.getCells().add(c);
                    if (b.fhirType().contains("(")) {
                        String tc = b.fhirType();
                        String tn = tc.substring(0, tc.indexOf("("));
                        c.addPiece(gen.new Piece(pkp.getLinkFor(corePath, tn), tn, null));
                        c.addPiece(gen.new Piece(null, "(", null));
                        String[] p = tc.substring(tc.indexOf("(") + 1, tc.indexOf(")")).split("\\|");
                        for (String s : p) {
                            c.addPiece(gen.new Piece(pkp.getLinkFor(corePath, s), s, null));
                        }
                        c.addPiece(gen.new Piece(null, ")", null));
                    } else {
                        c.addPiece(gen.new Piece(pkp.getLinkFor(corePath, b.fhirType()), b.fhirType(), null));
                    }
                    if (b.isPrimitive()) {
                        c = gen.new Cell();
                        row.getCells().add(c);
                        c.addPiece(gen.new Piece(null, ed.getShort(), null));
                        c.addPiece(gen.new Piece("br"));
                        c.getPieces().add(gen.new Piece(null, "Fixed Value: ", null).addStyle("font-weight: bold"));
                        String s = b.primitiveValue();
                        // ok. let's see if we can find a relevant link for this
                        String link = null;
                        if (Utilities.isAbsoluteUrl(s)) {
                            link = pkp.getLinkForUrl(corePath, s);
                        }
                        c.getPieces().add(gen.new Piece(link, s, null).addStyle("color: darkgreen"));
                    } else {
                        c = gen.new Cell();
                        row.getCells().add(c);
                        c.addPiece(gen.new Piece(null, ed.getShort(), null));
                        c.addPiece(gen.new Piece("br"));
                        c.getPieces().add(gen.new Piece(null, "Fixed Value: ", null).addStyle("font-weight: bold"));
                        c.getPieces().add(gen.new Piece(null, "(complex)", null).addStyle("color: darkgreen"));
                        genFixedValue(gen, row, (DataType) b, snapshot, pattern, corePath, skipnoValue);
                    }
                }
            }
        }
    }
}
Also used : StructureDefinition(org.hl7.fhir.r5.model.StructureDefinition) Piece(org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.Piece) ElementDefinition(org.hl7.fhir.r5.model.ElementDefinition) Row(org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.Row) Cell(org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.Cell) Base(org.hl7.fhir.r5.model.Base)

Example 92 with DataType

use of org.hl7.fhir.r5.model.DataType in project org.hl7.fhir.core by hapifhir.

the class ShExGenerator method genTypeRef.

/**
 * Generate a type reference
 * @param sd Containing structure definition
 * @param ed Containing element definition
 * @param id Element id
 * @param typ Element type
 * @return Type reference string
 */
private String genTypeRef(StructureDefinition sd, ElementDefinition ed, String id, ElementDefinition.TypeRefComponent typ) {
    if (typ.hasProfile()) {
        if (typ.getWorkingCode().equals("Reference"))
            return genReference("", typ);
        else if (profileUtilities.getChildList(sd, ed).size() > 0) {
            // inline anonymous type - give it a name and factor it out
            innerTypes.add(new ImmutablePair<StructureDefinition, ElementDefinition>(sd, ed));
            return simpleElement(sd, ed, id);
        } else {
            String ref = getTypeName(typ);
            datatypes.add(ref);
            return simpleElement(sd, ed, ref);
        }
    } else if (typ.getCode().startsWith(Constants.NS_SYSTEM_TYPE)) {
        String xt = typ.getWorkingCode();
        // TODO: Remove the next line when the type of token gets switched to string
        // TODO: Add a rdf-type entry for valueInteger to xsd:integer (instead of int)
        ST td_entry = tmplt(PRIMITIVE_ELEMENT_DEFN_TEMPLATE).add("typ", xt.replace("xsd:token", "xsd:string").replace("xsd:int", "xsd:integer"));
        StringBuilder facets = new StringBuilder();
        if (ed.hasMinValue()) {
            DataType mv = ed.getMinValue();
            facets.append(tmplt(MINVALUE_TEMPLATE).add("val", mv.primitiveValue()).render());
        }
        if (ed.hasMaxValue()) {
            DataType mv = ed.getMaxValue();
            facets.append(tmplt(MAXVALUE_TEMPLATE).add("val", mv.primitiveValue()).render());
        }
        if (ed.hasMaxLength()) {
            int ml = ed.getMaxLength();
            facets.append(tmplt(MAXLENGTH_TEMPLATE).add("val", ml).render());
        }
        if (ed.hasPattern()) {
            DataType pat = ed.getPattern();
            facets.append(tmplt(PATTERN_TEMPLATE).add("val", pat.primitiveValue()).render());
        }
        td_entry.add("facets", facets.toString());
        return td_entry.render();
    } else if (typ.getWorkingCode() == null) {
        ST primitive_entry = tmplt(PRIMITIVE_ELEMENT_DEFN_TEMPLATE);
        primitive_entry.add("typ", "xsd:string");
        return primitive_entry.render();
    } else if (typ.getWorkingCode().equals("xhtml")) {
        return tmplt(XHTML_TYPE_TEMPLATE).render();
    } else {
        datatypes.add(typ.getWorkingCode());
        return simpleElement(sd, ed, typ.getWorkingCode());
    }
}
Also used : ST(org.stringtemplate.v4.ST) ImmutablePair(org.apache.commons.lang3.tuple.ImmutablePair) DataType(org.hl7.fhir.r5.model.DataType)

Aggregations

DataType (org.hl7.fhir.r5.model.DataType)14 FHIRException (org.hl7.fhir.exceptions.FHIRException)11 XhtmlNode (org.hl7.fhir.utilities.xhtml.XhtmlNode)11 DefinitionException (org.hl7.fhir.exceptions.DefinitionException)8 HashMap (java.util.HashMap)7 List (java.util.List)7 Map (java.util.Map)7 FHIRFormatError (org.hl7.fhir.exceptions.FHIRFormatError)7 Collectors (java.util.stream.Collectors)6 DataType (org.hl7.cql.model.DataType)6 ModelInfo (org.hl7.elm_modelinfo.r1.ModelInfo)6 Piece (org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.Piece)6 ArrayList (java.util.ArrayList)5 StructType (org.apache.spark.sql.types.StructType)5 BooleanType (org.hl7.fhir.r5.model.BooleanType)5 ValueSet (org.hl7.fhir.r5.model.ValueSet)5 Arrays (java.util.Arrays)4 QName (javax.xml.namespace.QName)4 DataType (org.hl7.fhir.r4b.model.DataType)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3