Search in sources :

Example 66 with DataType

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

the class TurtleParser method parse.

private Element parse(Turtle src, TTLComplex cmp) throws FHIRFormatError, DefinitionException {
    TTLObject type = cmp.getPredicates().get("http://www.w3.org/2000/01/rdf-schema#type");
    if (type == null) {
        logError(cmp.getLine(), cmp.getCol(), "(document)", IssueType.INVALID, "Unknown resource type (missing rdfs:type)", IssueSeverity.FATAL);
        return null;
    }
    if (type instanceof TTLList) {
        // this is actually broken - really we have to look through the structure definitions at this point
        for (TTLObject obj : ((TTLList) type).getList()) {
            if (obj instanceof TTLURL && ((TTLURL) obj).getUri().startsWith(FHIR_URI_BASE)) {
                type = obj;
                break;
            }
        }
    }
    if (!(type instanceof TTLURL)) {
        logError(cmp.getLine(), cmp.getCol(), "(document)", IssueType.INVALID, "Unexpected datatype for rdfs:type)", IssueSeverity.FATAL);
        return null;
    }
    String name = ((TTLURL) type).getUri();
    String ns = name.substring(0, name.lastIndexOf("/"));
    name = name.substring(name.lastIndexOf("/") + 1);
    String path = "/" + name;
    StructureDefinition sd = getDefinition(cmp.getLine(), cmp.getCol(), ns, name);
    if (sd == null)
        return null;
    Element result = new Element(name, new Property(context, sd.getSnapshot().getElement().get(0), sd));
    result.markLocation(cmp.getLine(), cmp.getCol());
    result.setType(name);
    parseChildren(src, path, cmp, result, false);
    result.numberChildren();
    return result;
}
Also used : StructureDefinition(org.hl7.fhir.dstu3.model.StructureDefinition) SpecialElement(org.hl7.fhir.dstu3.elementmodel.Element.SpecialElement) TTLURL(org.hl7.fhir.dstu3.utils.formats.Turtle.TTLURL) TTLObject(org.hl7.fhir.dstu3.utils.formats.Turtle.TTLObject) TTLList(org.hl7.fhir.dstu3.utils.formats.Turtle.TTLList)

Example 67 with DataType

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

the class JsonParser method composeType.

protected void composeType(String prefix, DataType type) throws IOException {
    if (type == null) {
        ;
    } else if (type instanceof Address) {
        composeAddress(prefix + "Address", (Address) type);
    } else if (type instanceof Age) {
        composeAge(prefix + "Age", (Age) type);
    } else if (type instanceof Annotation) {
        composeAnnotation(prefix + "Annotation", (Annotation) type);
    } else if (type instanceof Attachment) {
        composeAttachment(prefix + "Attachment", (Attachment) type);
    } else if (type instanceof CodeableConcept) {
        composeCodeableConcept(prefix + "CodeableConcept", (CodeableConcept) type);
    } else if (type instanceof CodeableReference) {
        composeCodeableReference(prefix + "CodeableReference", (CodeableReference) type);
    } else if (type instanceof Coding) {
        composeCoding(prefix + "Coding", (Coding) type);
    } else if (type instanceof ContactDetail) {
        composeContactDetail(prefix + "ContactDetail", (ContactDetail) type);
    } else if (type instanceof ContactPoint) {
        composeContactPoint(prefix + "ContactPoint", (ContactPoint) type);
    } else if (type instanceof Contributor) {
        composeContributor(prefix + "Contributor", (Contributor) type);
    } else if (type instanceof Count) {
        composeCount(prefix + "Count", (Count) type);
    } else if (type instanceof DataRequirement) {
        composeDataRequirement(prefix + "DataRequirement", (DataRequirement) type);
    } else if (type instanceof Distance) {
        composeDistance(prefix + "Distance", (Distance) type);
    } else if (type instanceof Dosage) {
        composeDosage(prefix + "Dosage", (Dosage) type);
    } else if (type instanceof Duration) {
        composeDuration(prefix + "Duration", (Duration) type);
    } else if (type instanceof ElementDefinition) {
        composeElementDefinition(prefix + "ElementDefinition", (ElementDefinition) type);
    } else if (type instanceof Expression) {
        composeExpression(prefix + "Expression", (Expression) type);
    } else if (type instanceof Extension) {
        composeExtension(prefix + "Extension", (Extension) type);
    } else if (type instanceof HumanName) {
        composeHumanName(prefix + "HumanName", (HumanName) type);
    } else if (type instanceof Identifier) {
        composeIdentifier(prefix + "Identifier", (Identifier) type);
    } else if (type instanceof MarketingStatus) {
        composeMarketingStatus(prefix + "MarketingStatus", (MarketingStatus) type);
    } else if (type instanceof Meta) {
        composeMeta(prefix + "Meta", (Meta) type);
    } else if (type instanceof Money) {
        composeMoney(prefix + "Money", (Money) type);
    } else if (type instanceof Narrative) {
        composeNarrative(prefix + "Narrative", (Narrative) type);
    } else if (type instanceof ParameterDefinition) {
        composeParameterDefinition(prefix + "ParameterDefinition", (ParameterDefinition) type);
    } else if (type instanceof Period) {
        composePeriod(prefix + "Period", (Period) type);
    } else if (type instanceof Population) {
        composePopulation(prefix + "Population", (Population) type);
    } else if (type instanceof ProdCharacteristic) {
        composeProdCharacteristic(prefix + "ProdCharacteristic", (ProdCharacteristic) type);
    } else if (type instanceof ProductShelfLife) {
        composeProductShelfLife(prefix + "ProductShelfLife", (ProductShelfLife) type);
    } else if (type instanceof Quantity) {
        composeQuantity(prefix + "Quantity", (Quantity) type);
    } else if (type instanceof Range) {
        composeRange(prefix + "Range", (Range) type);
    } else if (type instanceof Ratio) {
        composeRatio(prefix + "Ratio", (Ratio) type);
    } else if (type instanceof RatioRange) {
        composeRatioRange(prefix + "RatioRange", (RatioRange) type);
    } else if (type instanceof Reference) {
        composeReference(prefix + "Reference", (Reference) type);
    } else if (type instanceof RelatedArtifact) {
        composeRelatedArtifact(prefix + "RelatedArtifact", (RelatedArtifact) type);
    } else if (type instanceof SampledData) {
        composeSampledData(prefix + "SampledData", (SampledData) type);
    } else if (type instanceof Signature) {
        composeSignature(prefix + "Signature", (Signature) type);
    } else if (type instanceof Timing) {
        composeTiming(prefix + "Timing", (Timing) type);
    } else if (type instanceof TriggerDefinition) {
        composeTriggerDefinition(prefix + "TriggerDefinition", (TriggerDefinition) type);
    } else if (type instanceof UsageContext) {
        composeUsageContext(prefix + "UsageContext", (UsageContext) type);
    } else if (type instanceof CodeType) {
        composeCodeCore(prefix + "Code", (CodeType) type, false);
        composeCodeExtras(prefix + "Code", (CodeType) type, false);
    } else if (type instanceof OidType) {
        composeOidCore(prefix + "Oid", (OidType) type, false);
        composeOidExtras(prefix + "Oid", (OidType) type, false);
    } else if (type instanceof CanonicalType) {
        composeCanonicalCore(prefix + "Canonical", (CanonicalType) type, false);
        composeCanonicalExtras(prefix + "Canonical", (CanonicalType) type, false);
    } else if (type instanceof UuidType) {
        composeUuidCore(prefix + "Uuid", (UuidType) type, false);
        composeUuidExtras(prefix + "Uuid", (UuidType) type, false);
    } else if (type instanceof UrlType) {
        composeUrlCore(prefix + "Url", (UrlType) type, false);
        composeUrlExtras(prefix + "Url", (UrlType) type, false);
    } else if (type instanceof UnsignedIntType) {
        composeUnsignedIntCore(prefix + "UnsignedInt", (UnsignedIntType) type, false);
        composeUnsignedIntExtras(prefix + "UnsignedInt", (UnsignedIntType) type, false);
    } else if (type instanceof MarkdownType) {
        composeMarkdownCore(prefix + "Markdown", (MarkdownType) type, false);
        composeMarkdownExtras(prefix + "Markdown", (MarkdownType) type, false);
    } else if (type instanceof IdType) {
        composeIdCore(prefix + "Id", (IdType) type, false);
        composeIdExtras(prefix + "Id", (IdType) type, false);
    } else if (type instanceof PositiveIntType) {
        composePositiveIntCore(prefix + "PositiveInt", (PositiveIntType) type, false);
        composePositiveIntExtras(prefix + "PositiveInt", (PositiveIntType) type, false);
    } else if (type instanceof DateType) {
        composeDateCore(prefix + "Date", (DateType) type, false);
        composeDateExtras(prefix + "Date", (DateType) type, false);
    } else if (type instanceof DateTimeType) {
        composeDateTimeCore(prefix + "DateTime", (DateTimeType) type, false);
        composeDateTimeExtras(prefix + "DateTime", (DateTimeType) type, false);
    } else if (type instanceof StringType) {
        composeStringCore(prefix + "String", (StringType) type, false);
        composeStringExtras(prefix + "String", (StringType) type, false);
    } else if (type instanceof IntegerType) {
        composeIntegerCore(prefix + "Integer", (IntegerType) type, false);
        composeIntegerExtras(prefix + "Integer", (IntegerType) type, false);
    } else if (type instanceof Integer64Type) {
        composeInteger64Core(prefix + "Integer64", (Integer64Type) type, false);
        composeInteger64Extras(prefix + "Integer64", (Integer64Type) type, false);
    } else if (type instanceof UriType) {
        composeUriCore(prefix + "Uri", (UriType) type, false);
        composeUriExtras(prefix + "Uri", (UriType) type, false);
    } else if (type instanceof InstantType) {
        composeInstantCore(prefix + "Instant", (InstantType) type, false);
        composeInstantExtras(prefix + "Instant", (InstantType) type, false);
    } else if (type instanceof BooleanType) {
        composeBooleanCore(prefix + "Boolean", (BooleanType) type, false);
        composeBooleanExtras(prefix + "Boolean", (BooleanType) type, false);
    } else if (type instanceof Base64BinaryType) {
        composeBase64BinaryCore(prefix + "Base64Binary", (Base64BinaryType) type, false);
        composeBase64BinaryExtras(prefix + "Base64Binary", (Base64BinaryType) type, false);
    } else if (type instanceof TimeType) {
        composeTimeCore(prefix + "Time", (TimeType) type, false);
        composeTimeExtras(prefix + "Time", (TimeType) type, false);
    } else if (type instanceof DecimalType) {
        composeDecimalCore(prefix + "Decimal", (DecimalType) type, false);
        composeDecimalExtras(prefix + "Decimal", (DecimalType) type, false);
    } else
        throw new Error("Unhandled type");
}
Also used : FHIRFormatError(org.hl7.fhir.exceptions.FHIRFormatError)

Example 68 with DataType

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

the class XmlParserBase method compose.

@Override
public void compose(OutputStream stream, DataType type, String rootName) throws IOException {
    xml = new XMLWriter(stream, "UTF-8");
    xml.setPretty(style == OutputStyle.PRETTY);
    xml.start();
    xml.setDefaultNamespace(FHIR_NS);
    composeType(Utilities.noString(rootName) ? "value" : rootName, type);
    xml.end();
}
Also used : IXMLWriter(org.hl7.fhir.utilities.xml.IXMLWriter) XMLWriter(org.hl7.fhir.utilities.xml.XMLWriter)

Example 69 with DataType

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

the class OperationDefinition10_50 method convertOperationDefinitionParameterBindingComponent.

public static org.hl7.fhir.r5.model.OperationDefinition.OperationDefinitionParameterBindingComponent convertOperationDefinitionParameterBindingComponent(org.hl7.fhir.dstu2.model.OperationDefinition.OperationDefinitionParameterBindingComponent src) throws FHIRException {
    if (src == null || src.isEmpty())
        return null;
    org.hl7.fhir.r5.model.OperationDefinition.OperationDefinitionParameterBindingComponent tgt = new org.hl7.fhir.r5.model.OperationDefinition.OperationDefinitionParameterBindingComponent();
    ConversionContext10_50.INSTANCE.getVersionConvertor_10_50().copyElement(src, tgt);
    if (src.hasStrength())
        tgt.setStrengthElement(Enumerations10_50.convertBindingStrength(src.getStrengthElement()));
    DataType t = ConversionContext10_50.INSTANCE.getVersionConvertor_10_50().convertType(src.getValueSet());
    if (t != null) {
        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 : Reference(org.hl7.fhir.dstu2.model.Reference) DataType(org.hl7.fhir.r5.model.DataType)

Example 70 with DataType

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

the class JavaResourceGenerator method generateAbstractAccessors.

private void generateAbstractAccessors(Analysis analysis, TypeInfo ti, ElementDefinition e, String indent) throws Exception {
    String tn = e.getUserString("java.type");
    if (Utilities.noString(tn)) {
        throw new Error("??");
    }
    boolean isReferenceRefField = (ti.getDefn().getName().equals("Reference") && e.getName().equals("reference"));
    jdoc(indent, "How many allowed for this property by the implementation");
    write(indent + "public int get" + getTitle(getElementName(e.getName(), false)) + "Max() { \r\n");
    write(indent + "  return " + (e.getMax().equals("*") ? "Integer.MAX_VALUE" : "1") + ";\r\n");
    write(indent + "}\r\n");
    String simpleType = getSimpleType(tn);
    if (e.unbounded()) {
        /*
       * getXXX()for repeatable type
       */
        jdoc(indent, "@return {@link #" + getElementName(e.getName(), true) + "} (" + replaceTitle(analysis.getName(), e.getDefinition()) + ")");
        String listGenericType;
        // if (tn == null && e.hasContentReference()) {
        // listGenericType = root.getName();
        // } else {
        listGenericType = tn;
        // }
        write(indent + "public abstract List<" + listGenericType + "> get" + getTitle(getElementName(e.getName(), false)) + "(); \r\n");
        /*
       * setXXX(List<foo>) for repeating type
       */
        jdoc(indent, "@return Returns a reference to <code>this</code> for easy method chaining");
        write(indent + "public abstract " + ti.getName() + " set" + getTitle(getElementName(e.getName(), false)) + "(" + "List<" + listGenericType + "> the" + getTitle(getElementName(e.getName(), false)) + "); \r\n");
        /*
       * hasXXX() for repeatable type
       */
        write(indent + "public abstract boolean has" + getTitle(getElementName(e.getName(), false)) + "(); \r\n");
        write("\r\n");
        if (e.getType().size() == 1 && (definitions.hasPrimitiveType(e.typeSummary()) || e.typeSummary().equals("xml:lang") || e.typeSummary().startsWith("canonical("))) {
            /*
         * addXXXElement() for repeatable primitive
         */
            jdoc(indent, "@return {@link #" + getElementName(e.getName(), true) + "} (" + replaceTitle(analysis.getName(), e.getDefinition()) + ")");
            write(indent + "public abstract " + tn + " add" + getTitle(getElementName(e.getName(), false)) + "Element();//2 \r\n");
            /*
         * addXXX(foo) for repeatable primitive
         */
            jdoc(indent, "@param value {@link #" + getElementName(e.getName(), true) + "} (" + replaceTitle(analysis.getName(), e.getDefinition()) + ")");
            write(indent + "public abstract " + ti.getName() + " add" + getTitle(getElementName(e.getName(), false)) + "(" + simpleType + " value); //1\r\n");
            /*
         * hasXXX(foo) for repeatable primitive
         */
            jdoc(indent, "@param value {@link #" + getElementName(e.getName(), true) + "} (" + replaceTitle(analysis.getName(), e.getDefinition()) + ")");
            write(indent + "public abstract boolean has" + getTitle(getElementName(e.getName(), false)) + "(" + simpleType + " value); \r\n");
        } else {
            if (!definitions.hasResource(tn)) {
                /*
           * addXXX() for repeatable composite
           */
                write(indent + "public abstract " + tn + " add" + getTitle(getElementName(e.getName(), false)) + "(); //3\r\n");
                /*
           * addXXX(foo) for repeatable composite
           */
                write(indent + "public abstract " + ti.getName() + " add" + getTitle(getElementName(e.getName(), false)) + "(" + tn + " t); //3\r\n");
            } else {
                /*
           * addXXX(foo) for repeatable composite
           */
                write(indent + "public abstract " + ti.getName() + " add" + getTitle(getElementName(e.getName(), false)) + "(" + tn + " t); //3\r\n");
            }
            /*
         * getXXXFirstRep() for repeatable element
         */
            if (!"DomainResource".equals(ti.getName())) {
                jdoc(indent, "@return The first repetition of repeating field {@link #" + getElementName(e.getName(), true) + "}, creating it if it does not already exist {1}");
                write(indent + "public abstract " + tn + " get" + getTitle(getElementName(e.getName(), false)) + "FirstRep(); \r\n");
            }
        }
    } else {
        if (!"xhtml".equals(e.typeSummary()) && isJavaPrimitive(e) || (e.getType().size() == 1 && e.typeSummary().startsWith("canonical("))) {
            jdoc(indent, "@return {@link #" + getElementName(e.getName(), true) + "} (" + replaceTitle(analysis.getName(), e.getDefinition()) + "). This is the underlying object with id, value and extensions. The accessor \"get" + getTitle(getElementName(e.getName(), false)) + "\" gives direct access to the value");
            if (isReferenceRefField) {
                /*
           * Reference#getReferenceElement is defined differently in BaseReference.java?
           */
                write(indent + "public abstract " + tn + " get" + getTitle(getElementName(e.getName(), false)) + "Element_(); \r\n");
            } else {
                write(indent + "public abstract " + tn + " get" + getTitle(getElementName(e.getName(), false)) + "Element(); \r\n");
            }
            write("\r\n");
            write(indent + "public abstract boolean has" + getTitle(getElementName(e.getName(), false)) + "Element(); \r\n");
            write(indent + "public abstract boolean has" + getTitle(getElementName(e.getName(), false)) + "(); \r\n");
            write("\r\n");
            jdoc(indent, "@param value {@link #" + getElementName(e.getName(), true) + "} (" + replaceTitle(analysis.getName(), e.getDefinition()) + "). This is the underlying object with id, value and extensions. The accessor \"get" + getTitle(getElementName(e.getName(), false)) + "\" gives direct access to the value");
            write(indent + "public abstract " + ti.getName() + " set" + getTitle(getElementName(e.getName(), false)) + "Element(" + tn + " value); \r\n");
            jdoc(indent, "@return " + replaceTitle(analysis.getName(), e.getDefinition()));
            write(indent + "public abstract " + simpleType + " get" + getTitle(getElementName(e.getName(), false)) + "(); \r\n");
            generateAbstractSetter(e, indent, ti.getName(), tn, simpleType, analysis.getName());
            // BigDecimal sugar methods
            if (simpleType.equals("BigDecimal")) {
                generateAbstractSetter(e, indent, ti.getName(), tn, "long", analysis.getName());
                generateAbstractSetter(e, indent, ti.getName(), tn, "double", analysis.getName());
            }
        } else {
            jdoc(indent, "@return {@link #" + getElementName(e.getName(), true) + "} (" + replaceTitle(analysis.getName(), e.getDefinition()) + ")");
            write(indent + "public abstract " + tn + " get" + getTitle(getElementName(e.getName(), false)) + "(); \r\n");
            if (e.getType().size() > 1 && (tn.equals("DataType") || !tn.endsWith(".DataType"))) {
                for (TypeRefComponent t : e.getType()) {
                    jdoc(indent, "@return {@link #" + getElementName(e.getName(), true) + "} (" + replaceTitle(analysis.getName(), e.getDefinition()) + ")");
                    String ttn = getTypename(t);
                    write(indent + "public abstract " + ttn + " get" + getTitle(getElementName(e.getName(), false)) + ttn + "() throws FHIRException; \r\n");
                    write(indent + "public abstract boolean has" + getTitle(getElementName(e.getName(), false)) + ttn + "(); \r\n");
                }
            }
            write(indent + "public abstract boolean has" + getTitle(getElementName(e.getName(), false)) + "(); \r\n");
            jdoc(indent, "@param value {@link #" + getElementName(e.getName(), true) + "} (" + replaceTitle(analysis.getName(), e.getDefinition()) + ")");
            write(indent + "public abstract " + ti.getName() + " set" + getTitle(getElementName(e.getName(), false)) + "(" + tn + " value); \r\n");
            write("\r\n");
        }
    }
}
Also used : TypeRefComponent(org.hl7.fhir.r5.model.ElementDefinition.TypeRefComponent)

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