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;
}
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;
}
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 {
}
}
}
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);
}
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());
}
}
Aggregations