Search in sources :

Example 36 with DataType

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

the class DataRequirementsProcessor method toFHIRResultTypeCode.

private String toFHIRResultTypeCode(org.hl7.cql.model.DataType dataType, String defName, AtomicBoolean isList) {
    AtomicBoolean isValid = new AtomicBoolean(true);
    String resultCode = toFHIRTypeCode(dataType, isValid, isList);
    if (!isValid.get()) {
        // Issue a warning that the result type is not supported
        validationMessages.add(new ValidationMessage(ValidationMessage.Source.Publisher, ValidationMessage.IssueType.NOTSUPPORTED, "CQL Library Packaging", String.format("Result type %s of definition %s is not supported; implementations may not be able to use the result of this expression", dataType.toLabel(), defName), ValidationMessage.IssueSeverity.WARNING));
    }
    return resultCode;
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ValidationMessage(org.hl7.fhir.utilities.validation.ValidationMessage)

Example 37 with DataType

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

the class DataRequirementsProcessor method toFHIRParameterTypeCode.

private String toFHIRParameterTypeCode(org.hl7.cql.model.DataType dataType, String parameterName, AtomicBoolean isList) {
    AtomicBoolean isValid = new AtomicBoolean(true);
    String resultCode = toFHIRTypeCode(dataType, isValid, isList);
    if (!isValid.get()) {
        // Issue a warning that the parameter type is not supported
        validationMessages.add(new ValidationMessage(ValidationMessage.Source.Publisher, ValidationMessage.IssueType.NOTSUPPORTED, "CQL Library Packaging", String.format("Parameter type %s of parameter %s is not supported; reported as FHIR.Any", dataType.toLabel(), parameterName), ValidationMessage.IssueSeverity.WARNING));
    }
    return resultCode;
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ValidationMessage(org.hl7.fhir.utilities.validation.ValidationMessage)

Example 38 with DataType

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

the class ElmDataRequirement method applyConditionRequirementTo.

private void applyConditionRequirementTo(ElmConditionRequirement conditionRequirement, Retrieve retrieve, ElmRequirementsContext context) {
    if (retrieve.getDataType() == null) {
        // If the retrieve has no data type, it is neither useful nor possible to apply requirements to it
        return;
    }
    if (!conditionRequirement.isTargetable()) {
        // If the comparand of the condition requirement is not targetable, requirements cannot be applied
        return;
    }
    // if the column is terminology-valued, express as a code filter
    // if the column is date-valued, express as a date filter
    // else express as an other filter
    Property property = conditionRequirement.getProperty().getProperty();
    // DataType propertyType = property.getResultType();
    // Use the comparison type due to the likelihood of conversion operators along the property
    DataType comparisonType = conditionRequirement.getComparand().getExpression().getResultType();
    if (comparisonType != null) {
        if (context.getTypeResolver().isTerminologyType(comparisonType)) {
            CodeFilterElement codeFilter = new CodeFilterElement();
            if (property instanceof Search) {
                codeFilter.setSearch(property.getPath());
            } else {
                codeFilter.setProperty(property.getPath());
            }
            switch(conditionRequirement.getElement().getClass().getSimpleName()) {
                case "Equal":
                    codeFilter.setComparator("=");
                    break;
                case "Equivalent":
                    codeFilter.setComparator("~");
                    break;
                case "In":
                case "InValueSet":
                case "AnyInValueSet":
                    codeFilter.setComparator("in");
                    break;
            }
            if (codeFilter.getComparator() != null && (conditionRequirement.isTargetable())) {
                codeFilter.setValue(conditionRequirement.getComparand().getExpression());
                if (!ComparableElmRequirement.hasCodeFilter(retrieve.getCodeFilter(), codeFilter)) {
                    retrieve.getCodeFilter().add(codeFilter);
                }
            }
        } else if (context.getTypeResolver().isDateType(comparisonType)) {
            DateFilterElement dateFilter = new DateFilterElement();
            if (property instanceof Search) {
                dateFilter.setSearch(property.getPath());
            } else {
                dateFilter.setProperty(property.getPath());
            }
            // Determine operation and appropriate range
            // If right is interval-valued
            // If the operation is equal, equivalent, same as, in, or included in, the date range is the comparand
            Expression comparand = conditionRequirement.getComparand().getExpression();
            if (conditionRequirement.isTargetable()) {
                if (context.getTypeResolver().isIntervalType(comparisonType)) {
                    switch(conditionRequirement.getElement().getClass().getSimpleName()) {
                        case "Equal":
                        case "Equivalent":
                        case "SameAs":
                        case "In":
                        case "IncludedIn":
                            dateFilter.setValue(comparand);
                            break;
                        case "Before":
                            dateFilter.setValue(new Interval().withLowClosed(true).withHigh(new Start().withOperand(comparand)).withHighClosed(false));
                            break;
                        case "SameOrBefore":
                            dateFilter.setValue(new Interval().withLowClosed(true).withHigh(new Start().withOperand(comparand)).withHighClosed(true));
                            break;
                        case "After":
                            dateFilter.setValue(new Interval().withLow(new End().withOperand(comparand)).withLowClosed(false).withHighClosed(true));
                            break;
                        case "SameOrAfter":
                            dateFilter.setValue(new Interval().withLow(new End().withOperand(comparand)).withLowClosed(true).withHighClosed(true));
                            break;
                        case "Includes":
                        case "Meets":
                        case "MeetsBefore":
                        case "MeetsAfter":
                        case "Overlaps":
                        case "OverlapsBefore":
                        case "OverlapsAfter":
                        case "Starts":
                        case "Ends":
                            // TODO: Might be better to turn these into date-based conjunctive requirements as part of condition requirement inference
                            break;
                    }
                } else {
                    switch(conditionRequirement.getElement().getClass().getSimpleName()) {
                        case "Equal":
                        case "Equivalent":
                        case "SameAs":
                            dateFilter.setValue(new Interval().withLow(comparand).withLowClosed(true).withHigh(comparand).withHighClosed(true));
                            break;
                        case "Less":
                        case "Before":
                            dateFilter.setValue(new Interval().withLowClosed(true).withHigh(comparand).withHighClosed(false));
                            break;
                        case "LessOrEqual":
                        case "SameOrBefore":
                            dateFilter.setValue(new Interval().withLowClosed(true).withHigh(comparand).withHighClosed(true));
                            break;
                        case "Greater":
                        case "After":
                            dateFilter.setValue(new Interval().withLow(comparand).withLowClosed(false).withHighClosed(true));
                            break;
                        case "GreaterOrEqual":
                        case "SameOrAfter":
                            dateFilter.setValue(new Interval().withLow(comparand).withLowClosed(true).withHighClosed(true));
                            break;
                    }
                }
            }
            if (dateFilter.getValue() != null) {
                if (!ComparableElmRequirement.hasDateFilter(retrieve.getDateFilter(), dateFilter)) {
                    retrieve.getDateFilter().add(dateFilter);
                }
            }
        } else {
        }
    }
}
Also used : DataType(org.hl7.cql.model.DataType)

Example 39 with DataType

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

the class DefinitionToSparkVisitor method visitContained.

@Override
public HapiConverter visitContained(String elementPath, String elementTypeUrl, Map<String, StructureField<HapiConverter<DataType>>> contained) {
    StructField[] fields = contained.values().stream().map(containedEntry -> new StructField(containedEntry.fieldName(), containedEntry.result().getDataType(), true, Metadata.empty())).toArray(StructField[]::new);
    ArrayType container = new ArrayType(new StructType(fields), true);
    return new HapiContainedToSparkConverter(contained, container);
}
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) ArrayType(org.apache.spark.sql.types.ArrayType) StructField(org.apache.spark.sql.types.StructField) StructType(org.apache.spark.sql.types.StructType)

Example 40 with DataType

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

the class ElmRequirementsContext method reportFunctionRef.

public void reportFunctionRef(FunctionRef functionRef) {
    CompiledLibrary targetLibrary = prepareLibraryVisit(getCurrentLibraryIdentifier(), functionRef.getLibraryName());
    try {
        List<DataType> signature;
        signature = new ArrayList<DataType>();
        for (TypeSpecifier ts : functionRef.getSignature()) {
            signature.add(typeResolver.resolveTypeSpecifier(ts));
        }
        // Signature sizes will only be different in the case that the signature is not present in the ELM, so needs to be constructed
        if (signature.size() != functionRef.getOperand().size()) {
            for (Expression e : functionRef.getOperand()) {
                if (e.getResultType() != null) {
                    signature.add(e.getResultType());
                } else if (e.getResultTypeName() != null) {
                    signature.add(typeResolver.resolveTypeName(e.getResultTypeName()));
                } else if (e.getResultTypeSpecifier() != null) {
                    signature.add(typeResolver.resolveTypeSpecifier(e.getResultTypeSpecifier()));
                } else {
                    // Signature could not be constructed, fall back to reporting all function defs
                    signature = null;
                    break;
                }
            }
        }
        Iterable<FunctionDef> fds = targetLibrary.resolveFunctionRef(functionRef.getName(), signature);
        for (FunctionDef fd : fds) {
            if (!visited.contains(fd)) {
                visitor.visitElement(fd, this);
            }
        }
    } finally {
        unprepareLibraryVisit(functionRef.getLibraryName());
    }
}
Also used : CompiledLibrary(org.cqframework.cql.cql2elm.model.CompiledLibrary) DataType(org.hl7.cql.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