Search in sources :

Example 61 with DataType

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

the class OperationDefinition30_50 method convertOperationDefinitionParameterBindingComponent.

public static org.hl7.fhir.r5.model.OperationDefinition.OperationDefinitionParameterBindingComponent convertOperationDefinitionParameterBindingComponent(org.hl7.fhir.dstu3.model.OperationDefinition.OperationDefinitionParameterBindingComponent src) throws FHIRException {
    if (src == null)
        return null;
    org.hl7.fhir.r5.model.OperationDefinition.OperationDefinitionParameterBindingComponent tgt = new org.hl7.fhir.r5.model.OperationDefinition.OperationDefinitionParameterBindingComponent();
    ConversionContext30_50.INSTANCE.getVersionConvertor_30_50().copyElement(src, tgt);
    if (src.hasStrength())
        tgt.setStrengthElement(Enumerations30_50.convertBindingStrength(src.getStrengthElement()));
    if (src.hasValueSet()) {
        DataType t = ConversionContext30_50.INSTANCE.getVersionConvertor_30_50().convertType(src.getValueSet());
        if (t instanceof org.hl7.fhir.r5.model.Reference)
            tgt.setValueSet(((org.hl7.fhir.r5.model.Reference) t).getReference());
        else
            tgt.setValueSet(t.primitiveValue());
        tgt.setValueSet(VersionConvertorConstants.refToVS(tgt.getValueSet()));
    }
    return tgt;
}
Also used : DataType(org.hl7.fhir.r5.model.DataType)

Example 62 with DataType

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

the class ProfileUtilities method createExampleElement.

private org.hl7.fhir.r4b.elementmodel.Element createExampleElement(StructureDefinition profile, ElementDefinition ed, ExampleValueAccessor accessor) throws FHIRException {
    DataType v = accessor.getExampleValue(ed);
    if (v != null) {
        return new ObjectConverter(context).convert(new Property(context, ed, profile), v);
    } else {
        org.hl7.fhir.r4b.elementmodel.Element res = new org.hl7.fhir.r4b.elementmodel.Element(tail(ed.getPath()), new Property(context, ed, profile));
        boolean hasValue = false;
        List<ElementDefinition> children = getChildMap(profile, ed);
        for (ElementDefinition child : children) {
            if (!child.hasContentReference()) {
                org.hl7.fhir.r4b.elementmodel.Element e = createExampleElement(profile, child, accessor);
                if (e != null) {
                    hasValue = true;
                    res.getChildren().add(e);
                }
            }
        }
        if (hasValue)
            return res;
        else
            return null;
    }
}
Also used : ObjectConverter(org.hl7.fhir.r4b.elementmodel.ObjectConverter) Element(org.hl7.fhir.r4b.model.Element) DataType(org.hl7.fhir.r4b.model.DataType) ElementDefinition(org.hl7.fhir.r4b.model.ElementDefinition) Property(org.hl7.fhir.r4b.elementmodel.Property)

Example 63 with DataType

use of org.hl7.fhir.r4b.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.r4b.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.r4b.model.StructureDefinition) Piece(org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.Piece) ElementDefinition(org.hl7.fhir.r4b.model.ElementDefinition) Row(org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.Row) Cell(org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.Cell) Base(org.hl7.fhir.r4b.model.Base)

Example 64 with DataType

use of org.hl7.fhir.r4b.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.getWorkingCode().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.r4b.model.DataType)

Example 65 with DataType

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

the class ImplementationGuide14_50 method convertImplementationGuidePackageResourceComponent.

public static org.hl7.fhir.r5.model.ImplementationGuide.ImplementationGuideDefinitionResourceComponent convertImplementationGuidePackageResourceComponent(org.hl7.fhir.dstu2016may.model.ImplementationGuide.ImplementationGuidePackageResourceComponent src) throws FHIRException {
    if (src == null || src.isEmpty())
        return null;
    org.hl7.fhir.r5.model.ImplementationGuide.ImplementationGuideDefinitionResourceComponent tgt = new org.hl7.fhir.r5.model.ImplementationGuide.ImplementationGuideDefinitionResourceComponent();
    ConversionContext14_50.INSTANCE.getVersionConvertor_14_50().copyElement(src, tgt);
    if (src.hasExampleFor()) {
        DataType t = ConversionContext14_50.INSTANCE.getVersionConvertor_14_50().convertType(src.getExampleFor());
        tgt.setExample(t instanceof org.hl7.fhir.r5.model.Reference ? new CanonicalType(((org.hl7.fhir.r5.model.Reference) t).getReference()) : t);
    } else if (src.hasExample())
        tgt.setExample(new org.hl7.fhir.r5.model.BooleanType(src.getExample()));
    if (src.hasName())
        tgt.setNameElement(String14_50.convertString(src.getNameElement()));
    if (src.hasDescription())
        tgt.setDescriptionElement(String14_50.convertString(src.getDescriptionElement()));
    if (src.hasSourceReference())
        tgt.setReference(Reference14_50.convertReference(src.getSourceReference()));
    else if (src.hasSourceUriType())
        tgt.setReference(new org.hl7.fhir.r5.model.Reference(src.getSourceUriType().getValue()));
    return tgt;
}
Also used : ImplementationGuide(org.hl7.fhir.dstu2016may.model.ImplementationGuide) CanonicalType(org.hl7.fhir.r5.model.CanonicalType) 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