-
Notifications
You must be signed in to change notification settings - Fork 121
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#684: Fixed an issue with data requirements not being reported correc…
…tly for dependencies
- Loading branch information
1 parent
db96b2e
commit 9ef9f54
Showing
12 changed files
with
1,015 additions
and
590 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/ModelResolver.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package org.cqframework.cql.cql2elm; | ||
|
||
import org.cqframework.cql.cql2elm.model.Model; | ||
|
||
public interface ModelResolver { | ||
Model getModel(String modelName); | ||
} |
136 changes: 136 additions & 0 deletions
136
Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/TypeBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
package org.cqframework.cql.cql2elm; | ||
|
||
import org.cqframework.cql.cql2elm.model.Model; | ||
import org.hl7.cql.model.*; | ||
import org.hl7.elm.r1.ObjectFactory; | ||
import org.hl7.elm.r1.ParameterTypeSpecifier; | ||
import org.hl7.elm.r1.TupleElementDefinition; | ||
import org.hl7.elm.r1.TypeSpecifier; | ||
import org.hl7.elm_modelinfo.r1.ModelInfo; | ||
|
||
import javax.xml.namespace.QName; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class TypeBuilder { | ||
|
||
private ObjectFactory of; | ||
private ModelResolver mr; | ||
|
||
public class InternalModelResolver implements ModelResolver { | ||
private ModelManager modelManager; | ||
|
||
public InternalModelResolver(ModelManager modelManager) { | ||
this.modelManager = modelManager; | ||
} | ||
|
||
public Model getModel(String modelName) { | ||
return this.modelManager.resolveModel(modelName); | ||
} | ||
} | ||
|
||
public TypeBuilder(ObjectFactory of, ModelResolver mr) { | ||
this.of = of; | ||
this.mr = mr; | ||
} | ||
|
||
public TypeBuilder(ModelManager modelManager) { | ||
this.of = new ObjectFactory(); | ||
this.mr = new InternalModelResolver(modelManager); | ||
} | ||
|
||
public QName dataTypeToQName(DataType type) { | ||
if (type instanceof NamedType) { | ||
NamedType namedType = (NamedType)type; | ||
ModelInfo modelInfo = mr.getModel(namedType.getNamespace()).getModelInfo(); | ||
return new QName(modelInfo.getTargetUrl() != null ? modelInfo.getTargetUrl() : modelInfo.getUrl(), | ||
namedType.getTarget() != null ? namedType.getTarget() : namedType.getSimpleName()); | ||
} | ||
|
||
// ERROR: | ||
throw new IllegalArgumentException("A named type is required in this context."); | ||
} | ||
|
||
public Iterable<TypeSpecifier> dataTypesToTypeSpecifiers(Iterable<DataType> types) { | ||
ArrayList<TypeSpecifier> result = new ArrayList<TypeSpecifier>(); | ||
for (DataType type : types) { | ||
result.add(dataTypeToTypeSpecifier(type)); | ||
} | ||
return result; | ||
} | ||
|
||
public TypeSpecifier dataTypeToTypeSpecifier(DataType type) { | ||
// Convert the given type into an ELM TypeSpecifier representation. | ||
if (type instanceof NamedType) { | ||
return (TypeSpecifier)of.createNamedTypeSpecifier().withName(dataTypeToQName(type)).withResultType(type); | ||
} | ||
else if (type instanceof ListType) { | ||
return listTypeToTypeSpecifier((ListType)type); | ||
} | ||
else if (type instanceof IntervalType) { | ||
return intervalTypeToTypeSpecifier((IntervalType)type); | ||
} | ||
else if (type instanceof TupleType) { | ||
return tupleTypeToTypeSpecifier((TupleType)type); | ||
} | ||
else if (type instanceof ChoiceType) { | ||
return choiceTypeToTypeSpecifier((ChoiceType)type); | ||
} | ||
else if (type instanceof TypeParameter) { | ||
return typeParameterToTypeSpecifier((TypeParameter)type); | ||
} | ||
else { | ||
throw new IllegalArgumentException(String.format("Could not convert type %s to a type specifier.", type)); | ||
} | ||
} | ||
|
||
private TypeSpecifier listTypeToTypeSpecifier(ListType type) { | ||
return (TypeSpecifier)of.createListTypeSpecifier() | ||
.withElementType(dataTypeToTypeSpecifier(type.getElementType())) | ||
.withResultType(type); | ||
} | ||
|
||
private TypeSpecifier intervalTypeToTypeSpecifier(IntervalType type) { | ||
return (TypeSpecifier)of.createIntervalTypeSpecifier() | ||
.withPointType(dataTypeToTypeSpecifier(type.getPointType())) | ||
.withResultType(type); | ||
} | ||
|
||
private TypeSpecifier tupleTypeToTypeSpecifier(TupleType type) { | ||
return (TypeSpecifier)of.createTupleTypeSpecifier() | ||
.withElement(tupleTypeElementsToTupleElementDefinitions(type.getElements())) | ||
.withResultType(type); | ||
} | ||
|
||
private TupleElementDefinition[] tupleTypeElementsToTupleElementDefinitions(Iterable<TupleTypeElement> elements) { | ||
List<TupleElementDefinition> definitions = new ArrayList<>(); | ||
|
||
for (TupleTypeElement element : elements) { | ||
definitions.add(of.createTupleElementDefinition() | ||
.withName(element.getName()) | ||
.withElementType(dataTypeToTypeSpecifier(element.getType()))); | ||
} | ||
|
||
return definitions.toArray(new TupleElementDefinition[definitions.size()]); | ||
} | ||
|
||
private TypeSpecifier choiceTypeToTypeSpecifier(ChoiceType type) { | ||
return (TypeSpecifier)of.createChoiceTypeSpecifier() | ||
.withChoice(choiceTypeTypesToTypeSpecifiers(type)) | ||
.withResultType(type); | ||
} | ||
|
||
private TypeSpecifier[] choiceTypeTypesToTypeSpecifiers(ChoiceType choiceType) { | ||
List<TypeSpecifier> specifiers = new ArrayList<>(); | ||
|
||
for (DataType type : choiceType.getTypes()) { | ||
specifiers.add(dataTypeToTypeSpecifier(type)); | ||
} | ||
|
||
return specifiers.toArray(new TypeSpecifier[specifiers.size()]); | ||
} | ||
|
||
private TypeSpecifier typeParameterToTypeSpecifier(TypeParameter type) { | ||
return new ParameterTypeSpecifier().withParameterName(type.getIdentifier()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.