Search in sources :

Example 31 with DataType

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

the class DataRenderer method renderExtensionsInText.

public void renderExtensionsInText(XhtmlNode div, DataType element, String sep) throws FHIRFormatError, DefinitionException, IOException {
    boolean first = true;
    for (Extension ext : element.getExtension()) {
        if (canRender(ext)) {
            if (first) {
                first = false;
            } else {
                div.tx(sep);
                div.tx(" ");
            }
            String lbl = getExtensionLabel(ext);
            div.tx(lbl);
            div.tx(": ");
            render(div, ext.getValue());
        }
    }
}
Also used : Extension(org.hl7.fhir.r5.model.Extension)

Example 32 with DataType

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

the class StructureMapUtilities method getParam.

private TypeDetails getParam(VariablesForProfiling vars, StructureMapGroupRuleTargetParameterComponent parameter) throws DefinitionException {
    DataType p = parameter.getValue();
    if (!(p instanceof IdType))
        return new TypeDetails(CollectionStatus.SINGLETON, ProfileUtilities.sdNs(p.fhirType(), worker.getOverrideVersionNs()));
    else {
        String n = ((IdType) p).asStringValue();
        VariableForProfiling b = vars.get(VariableMode.INPUT, n);
        if (b == null)
            b = vars.get(VariableMode.OUTPUT, n);
        if (b == null)
            throw new DefinitionException("Variable " + n + " not found (" + vars.summary() + ")");
        return b.getProperty().getTypes();
    }
}
Also used : DefinitionException(org.hl7.fhir.exceptions.DefinitionException)

Example 33 with DataType

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

the class StructureMapUtilities method updateProfile.

private PropertyWithType updateProfile(VariableForProfiling var, String element, TypeDetails type, StructureMap map, List<StructureDefinition> profiles, String sliceName, DataType fixed, StructureMapGroupRuleTargetComponent tgt) throws FHIRException {
    if (var == null) {
        assert (Utilities.noString(element));
        // 1. start the new structure definition
        StructureDefinition sdn = worker.fetchResource(StructureDefinition.class, type.getType());
        if (sdn == null)
            throw new FHIRException("Unable to find definition for " + type.getType());
        ElementDefinition edn = sdn.getSnapshot().getElementFirstRep();
        PropertyWithType pn = createProfile(map, profiles, new PropertyWithType(sdn.getId(), new Property(worker, edn, sdn), null, type), sliceName, tgt);
        return pn;
    } else {
        assert (!Utilities.noString(element));
        Property pvb = var.getProperty().getBaseProperty();
        Property pvd = var.getProperty().getProfileProperty();
        Property pc = pvb.getChild(element, var.getProperty().getTypes());
        if (pc == null)
            throw new DefinitionException("Unable to find a definition for " + pvb.getDefinition().getPath() + "." + element);
        // the profile structure definition (derived)
        StructureDefinition sd = var.getProperty().getProfileProperty().getStructure();
        ElementDefinition ednew = sd.getDifferential().addElement();
        ednew.setPath(var.getProperty().getProfileProperty().getDefinition().getPath() + "." + pc.getName());
        ednew.setUserData("slice-name", sliceName);
        ednew.setFixed(fixed);
        for (ProfiledType pt : type.getProfiledTypes()) {
            if (pt.hasBindings())
                ednew.setBinding(pt.getBindings().get(0));
            if (pt.getUri().startsWith("http://hl7.org/fhir/StructureDefinition/")) {
                String t = pt.getUri().substring(40);
                t = checkType(t, pc, pt.getProfiles());
                if (t != null) {
                    if (pt.hasProfiles()) {
                        for (String p : pt.getProfiles()) if (t.equals("Reference"))
                            ednew.getType(t).addTargetProfile(p);
                        else
                            ednew.getType(t).addProfile(p);
                    } else
                        ednew.getType(t);
                }
            }
        }
        return new PropertyWithType(var.getProperty().getPath() + "." + element, pc, new Property(worker, ednew, sd), type);
    }
}
Also used : ProfiledType(org.hl7.fhir.r5.model.TypeDetails.ProfiledType) DefinitionException(org.hl7.fhir.exceptions.DefinitionException) FHIRException(org.hl7.fhir.exceptions.FHIRException) Property(org.hl7.fhir.r5.elementmodel.Property)

Example 34 with DataType

use of org.hl7.fhir.r4b.model.DataType in project bunsen by cerner.

the class DefinitionToSparkVisitor method visitChoice.

@Override
public HapiConverter<DataType> visitChoice(String elementName, Map<String, HapiConverter<DataType>> choiceTypes) {
    StructField[] fields = choiceTypes.entrySet().stream().map(entry -> {
        // Ensure first character of the field is lower case.
        String fieldName = Character.toLowerCase(entry.getKey().charAt(0)) + entry.getKey().substring(1);
        return new StructField(fieldName, entry.getValue().getDataType(), true, Metadata.empty());
    }).toArray(StructField[]::new);
    String fieldTypesString = choiceTypes.entrySet().stream().map(choiceEntry -> {
        // References need their full record name, which includes the permissible referent types
        if (choiceEntry.getKey().equals("Reference")) {
            StructType structType = (StructType) choiceEntry.getValue().getDataType();
            return Arrays.stream(structType.fields()).filter(field -> field.name().endsWith("Id") & !field.name().equals("id")).map(field -> field.name().substring(0, field.name().lastIndexOf("Id"))).sorted().map(StringUtils::capitalize).collect(Collectors.joining());
        } else {
            return choiceEntry.getKey();
        }
    }).sorted().map(StringUtils::capitalize).collect(Collectors.joining());
    String fullName = basePackage + "." + "Choice" + fieldTypesString;
    HapiConverter<DataType> converter = visitedConverters.get(fullName);
    if (converter == null) {
        converter = new HapiChoiceToSparkConverter(choiceTypes, new StructType(fields), fhirSupport);
        visitedConverters.put(fullName, converter);
    }
    return converter;
}
Also used : DataType(org.apache.spark.sql.types.DataType) PrimitiveConverter(com.cerner.bunsen.definitions.PrimitiveConverter) FhirConversionSupport(com.cerner.bunsen.definitions.FhirConversionSupport) Arrays(java.util.Arrays) IBase(org.hl7.fhir.instance.model.api.IBase) HapiObjectConverter(com.cerner.bunsen.definitions.HapiConverter.HapiObjectConverter) HashMap(java.util.HashMap) MultiValueConverter(com.cerner.bunsen.definitions.HapiConverter.MultiValueConverter) StructureField(com.cerner.bunsen.definitions.StructureField) StringUtils(org.apache.commons.lang3.StringUtils) HapiChoiceConverter(com.cerner.bunsen.definitions.HapiChoiceConverter) ArrayList(java.util.ArrayList) BigDecimal(java.math.BigDecimal) ArrayType(org.apache.spark.sql.types.ArrayType) HapiCompositeConverter(com.cerner.bunsen.definitions.HapiCompositeConverter) Map(java.util.Map) DataTypes(org.apache.spark.sql.types.DataTypes) Metadata(org.apache.spark.sql.types.Metadata) StructField(org.apache.spark.sql.types.StructField) StructType(org.apache.spark.sql.types.StructType) WrappedArray(scala.collection.mutable.WrappedArray) JavaConversions(scala.collection.JavaConversions) BaseRuntimeElementDefinition(ca.uhn.fhir.context.BaseRuntimeElementDefinition) EnumConverter(com.cerner.bunsen.definitions.EnumConverter) ImmutableMap(com.google.common.collect.ImmutableMap) RowFactory(org.apache.spark.sql.RowFactory) LeafExtensionConverter(com.cerner.bunsen.definitions.LeafExtensionConverter) Row(org.apache.spark.sql.Row) Collectors(java.util.stream.Collectors) HapiContainedConverter(com.cerner.bunsen.definitions.HapiContainedConverter) HapiConverter(com.cerner.bunsen.definitions.HapiConverter) StringConverter(com.cerner.bunsen.definitions.StringConverter) List(java.util.List) DefinitionVisitorsUtil(com.cerner.bunsen.definitions.DefinitionVisitorsUtil) GenericRowWithSchema(org.apache.spark.sql.catalyst.expressions.GenericRowWithSchema) BaseRuntimeChildDefinition(ca.uhn.fhir.context.BaseRuntimeChildDefinition) HapiFieldSetter(com.cerner.bunsen.definitions.HapiConverter.HapiFieldSetter) IPrimitiveType(org.hl7.fhir.instance.model.api.IPrimitiveType) DefinitionVisitor(com.cerner.bunsen.definitions.DefinitionVisitor) StructField(org.apache.spark.sql.types.StructField) StructType(org.apache.spark.sql.types.StructType) StringUtils(org.apache.commons.lang3.StringUtils) DataType(org.apache.spark.sql.types.DataType)

Example 35 with DataType

use of org.hl7.fhir.r4b.model.DataType in project clinical_quality_language by cqframework.

the class Cql2ElmVisitor method visitContextDefinition.

@Override
public Object visitContextDefinition(cqlParser.ContextDefinitionContext ctx) {
    String modelIdentifier = parseString(ctx.modelIdentifier());
    String unqualifiedIdentifier = parseString(ctx.identifier());
    currentContext = modelIdentifier != null ? modelIdentifier + "." + unqualifiedIdentifier : unqualifiedIdentifier;
    if (!isUnfilteredContext(unqualifiedIdentifier)) {
        ModelContext modelContext = libraryBuilder.resolveContextName(modelIdentifier, unqualifiedIdentifier);
        // If this is the first time a context definition is encountered, construct a context definition:
        // define <Context> = element of [<Context model type>]
        Element modelContextDefinition = contextDefinitions.get(modelContext.getName());
        if (modelContextDefinition == null) {
            if (libraryBuilder.hasUsings()) {
                ModelInfo modelInfo = modelIdentifier == null ? libraryBuilder.getModel(libraryInfo.getDefaultModelName()).getModelInfo() : libraryBuilder.getModel(modelIdentifier).getModelInfo();
                // String contextTypeName = modelContext.getName();
                // DataType contextType = libraryBuilder.resolveTypeName(modelInfo.getName(), contextTypeName);
                DataType contextType = modelContext.getType();
                modelContextDefinition = libraryBuilder.resolveParameterRef(modelContext.getName());
                if (modelContextDefinition != null) {
                    contextDefinitions.put(modelContext.getName(), modelContextDefinition);
                } else {
                    Retrieve contextRetrieve = of.createRetrieve().withDataType(libraryBuilder.dataTypeToQName(contextType));
                    track(contextRetrieve, ctx);
                    contextRetrieve.setResultType(new ListType(contextType));
                    String contextClassIdentifier = ((ClassType) contextType).getIdentifier();
                    if (contextClassIdentifier != null) {
                        contextRetrieve.setTemplateId(contextClassIdentifier);
                    }
                    modelContextDefinition = of.createExpressionDef().withName(unqualifiedIdentifier).withContext(currentContext).withExpression(of.createSingletonFrom().withOperand(contextRetrieve));
                    track(modelContextDefinition, ctx);
                    ((ExpressionDef) modelContextDefinition).getExpression().setResultType(contextType);
                    modelContextDefinition.setResultType(contextType);
                    libraryBuilder.addExpression((ExpressionDef) modelContextDefinition);
                    contextDefinitions.put(modelContext.getName(), modelContextDefinition);
                }
            } else {
                modelContextDefinition = of.createExpressionDef().withName(unqualifiedIdentifier).withContext(currentContext).withExpression(of.createNull());
                track(modelContextDefinition, ctx);
                ((ExpressionDef) modelContextDefinition).getExpression().setResultType(libraryBuilder.resolveTypeName("System", "Any"));
                modelContextDefinition.setResultType(((ExpressionDef) modelContextDefinition).getExpression().getResultType());
                libraryBuilder.addExpression((ExpressionDef) modelContextDefinition);
                contextDefinitions.put(modelContext.getName(), modelContextDefinition);
            }
        }
    }
    ContextDef contextDef = of.createContextDef().withName(currentContext);
    track(contextDef, ctx);
    if (libraryBuilder.isCompatibleWith("1.5")) {
        libraryBuilder.addContext(contextDef);
    }
    return currentContext;
}
Also used : ModelInfo(org.hl7.elm_modelinfo.r1.ModelInfo) Element(org.hl7.elm.r1.Element)

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