Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversion of the elm module to Kotin #1466

Merged
merged 38 commits into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
36824af
ChoiceType
JPercival Dec 6, 2024
59d0f87
ClassTypeElement
JPercival Dec 6, 2024
8954f37
InstantiationContext
JPercival Dec 7, 2024
27f89df
TupleType, TupleTypeelement, SearchType, Relationship
JPercival Dec 7, 2024
e4497d1
NamespaceInfo
JPercival Dec 7, 2024
16a4a45
ModelContext
JPercival Dec 8, 2024
3ee1968
ModelIdentifier
JPercival Dec 8, 2024
736c5e4
ModelInfoProvider, NamespaceAware, ModelInfoReader, ModelInfoReaderFa…
JPercival Dec 8, 2024
c8f8c7c
small clean up
JPercival Dec 8, 2024
7375dba
NamespaceManager, SystemModelInfoProvider
JPercival Dec 8, 2024
eff6bd2
clean up
JPercival Dec 8, 2024
b45e190
NamedType, InvalidRedeclarationException
JPercival Dec 9, 2024
3ba203d
Break out DataType interface
JPercival Dec 10, 2024
6ac7773
DataType
JPercival Dec 10, 2024
2820498
BaseDataType
JPercival Dec 10, 2024
7e561d0
Little bit of cleanup for choice types
JPercival Dec 10, 2024
ff701a2
Fixing Locale for string format
JPercival Dec 10, 2024
c7e55de
ClassType
JPercival Dec 10, 2024
23ce817
ProfileType
JPercival Dec 10, 2024
aff5257
ListType
JPercival Dec 10, 2024
31526a1
IntervalType
JPercival Dec 10, 2024
dcf26cd
TypeParameter
JPercival Dec 10, 2024
4cbfae9
TupleType, ClassType
JPercival Dec 11, 2024
dbf3c7b
Bug fixes for classes and tuples
JPercival Dec 11, 2024
d364339
GenericClassSignatureParser
JPercival Dec 11, 2024
0fba7b3
More cleanup of GenericClassSignatureParser
JPercival Dec 11, 2024
b9464ad
Remove unused assertion
JPercival Dec 11, 2024
0692d1d
TrackBack
JPercival Dec 11, 2024
1df2435
Trackable
JPercival Dec 11, 2024
420d857
ElmLibraryReader/Writer and factories
JPercival Dec 11, 2024
52cefca
SimpleElmEngine, SimpleElmEvaluator
JPercival Dec 11, 2024
d8b4a6e
ElmVisitor interfaces
JPercival Dec 11, 2024
d6c74c4
BaseElmClinicalVisitor
JPercival Dec 11, 2024
4357903
Fix spelling
JPercival Dec 11, 2024
e076a68
LibrarySourceProvider
JPercival Dec 11, 2024
45435e4
Fix spelling errors
JPercival Dec 11, 2024
e79ee6c
BaseElmVisitor
JPercival Dec 11, 2024
0227523
Remove some usages of Apache commons
JPercival Dec 11, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.io.IOException;
import java.io.InputStream;
import java.util.List;
import org.cqframework.cql.cql2elm.LibraryContentType;
import org.cqframework.cql.cql2elm.LibrarySourceProvider;
import org.hl7.elm.r1.VersionedIdentifier;
import org.hl7.fhir.r5.context.ILoggingService;
Expand Down Expand Up @@ -67,4 +68,13 @@ public InputStream getLibrarySource(VersionedIdentifier identifier) {

return null;
}

@Override
public InputStream getLibraryContent(VersionedIdentifier libraryIdentifier, LibraryContentType type) {
if (LibraryContentType.CQL == type) {
return getLibrarySource(libraryIdentifier);
}

return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ class Cql2ElmVisitor(
}
if (param.default != null) {
if (paramType != null) {
libraryBuilder.verifyType(param.default.resultType, paramType)
libraryBuilder.verifyType(param.default.resultType!!, paramType)
} else {
paramType = param.default.resultType
}
Expand Down Expand Up @@ -476,7 +476,7 @@ class Cql2ElmVisitor(
)
track(modelContextDefinition, ctx)
modelContextDefinition.expression.resultType = contextType
modelContextDefinition.setResultType(contextType)
modelContextDefinition.resultType = contextType
libraryBuilder.addExpression(modelContextDefinition)
contextDefinitions[modelContext.name] = modelContextDefinition
}
Expand All @@ -489,9 +489,7 @@ class Cql2ElmVisitor(
track(modelContextDefinition, ctx)
modelContextDefinition.expression.resultType =
libraryBuilder.resolveTypeName("System", "Any")
modelContextDefinition.setResultType(
modelContextDefinition.expression.resultType
)
modelContextDefinition.resultType = modelContextDefinition.expression.resultType
libraryBuilder.addExpression(modelContextDefinition)
contextDefinitions[modelContext.name] = modelContextDefinition
}
Expand Down Expand Up @@ -635,7 +633,7 @@ class Cql2ElmVisitor(
val tupleType = TupleType()
for (elementContext in ctx.tupleElementSelector()) {
val element = visit(elementContext) as TupleElement
tupleType.addElement(TupleTypeElement(element.name, element.resultType))
tupleType.addElement(TupleTypeElement(element.name, element.resultType!!))
tuple.element.add(element)
}
tuple.resultType = tupleType
Expand Down Expand Up @@ -701,7 +699,7 @@ class Cql2ElmVisitor(
val listTypeSpecifier =
of.createListTypeSpecifier().withElementType(elementTypeSpecifier)
track(listTypeSpecifier, ctx.typeSpecifier()!!)
listType = ListType(elementTypeSpecifier.resultType)
listType = ListType(elementTypeSpecifier.resultType!!)
listTypeSpecifier.resultType = listType
}
var elementType = elementTypeSpecifier?.resultType
Expand All @@ -714,7 +712,7 @@ class Cql2ElmVisitor(
?: @Suppress("TooGenericExceptionThrown")
throw RuntimeException("Element failed to parse")
if (elementType != null) {
libraryBuilder.verifyType(element.resultType, elementType)
libraryBuilder.verifyType(element.resultType!!, elementType)
} else {
if (initialInferredElementType == null) {
initialInferredElementType = element.resultType
Expand Down Expand Up @@ -746,9 +744,9 @@ class Cql2ElmVisitor(
elementType = inferredElementType ?: libraryBuilder.resolveTypeName("System", "Any")
}
for (element in elements) {
if (!elementType!!.isSuperTypeOf(element.resultType)) {
if (!elementType!!.isSuperTypeOf(element.resultType!!)) {
val conversion =
libraryBuilder.findConversion(element.resultType, elementType, true, false)
libraryBuilder.findConversion(element.resultType!!, elementType, true, false)
if (conversion != null) {
list.element.add(libraryBuilder.convertExpression(element, conversion))
} else {
Expand Down Expand Up @@ -1252,10 +1250,10 @@ class Cql2ElmVisitor(
parseExpression(ctx.expressionTerm(1))
)
libraryBuilder.resolveBinaryCall("System", operatorName, (exp as BinaryExpression?)!!)
if (exp.getResultType() === libraryBuilder.resolveTypeName("System", "String")) {
if (exp.resultType === libraryBuilder.resolveTypeName("System", "String")) {
val concatenate: Concatenate = of.createConcatenate()
concatenate.operand.addAll(exp.operand)
concatenate.resultType = exp.getResultType()
concatenate.resultType = exp.resultType
exp = concatenate
}
} else {
Expand Down Expand Up @@ -1833,8 +1831,8 @@ class Cql2ElmVisitor(
if (!equal(operand!!.resultType, targetType!!.resultType)) {
val conversion: Conversion =
libraryBuilder.findConversion(
operand.resultType,
targetType.resultType,
operand.resultType!!,
targetType.resultType!!,
false,
true
)
Expand Down Expand Up @@ -2753,7 +2751,7 @@ class Cql2ElmVisitor(
val resultType: DataType? =
libraryBuilder.ensureCompatibleTypes(
ifObject.then.resultType,
ifObject.getElse().resultType
ifObject.getElse().resultType!!
)
ifObject.resultType = resultType
ifObject.then = libraryBuilder.ensureCompatible(ifObject.then, resultType)
Expand Down Expand Up @@ -2785,7 +2783,7 @@ class Cql2ElmVisitor(
resultType =
libraryBuilder.ensureCompatibleTypes(
resultType,
result.getElse().resultType
result.getElse().resultType!!
)
} else {
result.comparand = parseExpression(pt)
Expand All @@ -2795,8 +2793,8 @@ class Cql2ElmVisitor(
val caseItem = visit(pt) as CaseItem
if (result.comparand != null) {
libraryBuilder.verifyType(
caseItem.getWhen().resultType,
result.comparand.resultType
caseItem.getWhen().resultType!!,
result.comparand.resultType!!
)
} else {
verifyType(
Expand All @@ -2808,7 +2806,7 @@ class Cql2ElmVisitor(
if (resultType == null) {
caseItem.then.resultType
} else {
libraryBuilder.ensureCompatibleTypes(resultType, caseItem.then.resultType)
libraryBuilder.ensureCompatibleTypes(resultType, caseItem.then.resultType!!)
}
result.caseItem.add(caseItem)
}
Expand Down Expand Up @@ -3105,7 +3103,7 @@ class Cql2ElmVisitor(
} else if (libraryBuilder.isCompatibleWith("1.5")) {
mCodeComparator =
if (
terminology.resultType.isSubTypeOf(
terminology.resultType!!.isSubTypeOf(
libraryBuilder.resolveTypeName("System", "Vocabulary")!!
)
)
Expand Down Expand Up @@ -3225,15 +3223,15 @@ class Cql2ElmVisitor(
))
) {
if (
terminology.resultType.isSubTypeOf(
terminology.resultType!!.isSubTypeOf(
libraryBuilder.resolveTypeName("System", "Vocabulary")!!
)
)
"~"
else "contains"
} else {
if (
terminology.resultType.isSubTypeOf(
terminology.resultType!!.isSubTypeOf(
libraryBuilder.resolveTypeName("System", "Vocabulary")!!
)
)
Expand Down Expand Up @@ -3318,7 +3316,7 @@ class Cql2ElmVisitor(
!((equivalent.operand[1].resultType is ListType ||
(libraryBuilder.isCompatibleWith("1.5") &&
equivalent.operand[1]
.resultType
.resultType!!
.isSubTypeOf(
libraryBuilder.resolveTypeName("System", "Vocabulary")!!
))))
Expand All @@ -3340,7 +3338,7 @@ class Cql2ElmVisitor(
!((equal.operand[1].resultType is ListType ||
(libraryBuilder.isCompatibleWith("1.5") &&
equal.operand[1]
.resultType
.resultType!!
.isSubTypeOf(
libraryBuilder.resolveTypeName("System", "Vocabulary")!!
))))
Expand Down Expand Up @@ -3419,7 +3417,7 @@ class Cql2ElmVisitor(
// retrieve typing
if (
((libraryBuilder.isCompatibleWith("1.5") &&
!(terminology.resultType.isSubTypeOf(
!(terminology.resultType!!.isSubTypeOf(
libraryBuilder.resolveTypeName("System", "Vocabulary")!!
))) ||
(!libraryBuilder.isCompatibleWith("1.5") &&
Expand Down Expand Up @@ -3536,7 +3534,7 @@ class Cql2ElmVisitor(
element.value.resultType =
sourceType // Doesn't use the fluent API to avoid casting
element.resultType = element.value.resultType
returnType.addElement(TupleTypeElement(element.name, element.resultType))
returnType.addElement(TupleTypeElement(element.name, element.resultType!!))
returnExpression.element.add(element)
}
returnExpression.resultType =
Expand Down Expand Up @@ -3730,8 +3728,8 @@ class Cql2ElmVisitor(
) {
val o: Operator? =
libraryBuilder.conversionMap.getConversionOperator(
functionRef.operand[0].resultType,
functionRef.resultType
functionRef.operand[0].resultType!!,
functionRef.resultType!!
)
if (
((o != null) &&
Expand Down Expand Up @@ -3829,10 +3827,10 @@ class Cql2ElmVisitor(
* @return `true` if the RHS supports refactoring to a `Retrieve`, `false` otherwise.
*/
private fun isRHSEligibleForDateRangeOptimization(rhs: Expression): Boolean {
return (rhs.resultType.isSubTypeOf(
return (rhs.resultType!!.isSubTypeOf(
libraryBuilder.resolveTypeName("System", "DateTime")!!
) ||
rhs.resultType.isSubTypeOf(
rhs.resultType!!.isSubTypeOf(
IntervalType(libraryBuilder.resolveTypeName("System", "DateTime")!!)
))

Expand Down Expand Up @@ -3962,7 +3960,7 @@ class Cql2ElmVisitor(
returnClause.expression = parseExpression(ctx.expression())
returnClause.resultType =
if (libraryBuilder.peekQueryContext().isSingular) returnClause.expression.resultType
else ListType(returnClause.expression.resultType)
else ListType(returnClause.expression.resultType!!)
return returnClause
}

Expand Down Expand Up @@ -4011,7 +4009,7 @@ class Cql2ElmVisitor(
aggregateClause.expression = parseExpression(ctx.expression())
aggregateClause.resultType = aggregateClause.expression.resultType
if (aggregateClause.starting == null) {
accumulator.setResultType(aggregateClause.resultType)
accumulator.resultType = aggregateClause.resultType
aggregateClause.starting = accumulator
}
return aggregateClause
Expand All @@ -4033,7 +4031,7 @@ class Cql2ElmVisitor(
of.createByColumn()
.withPath(sortExpression.name)
.withDirection(parseSortDirection(ctx.sortDirection()))
.withResultType(sortExpression.getResultType()) as SortByItem
.withResultType(sortExpression.resultType) as SortByItem
} else
of.createByExpression()
.withExpression(sortExpression)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ class CqlTranslator(
compiler.run(`is`)
}

private fun toXml(library: Library?): String {
private fun toXml(library: Library): String {
return try {
convertToXml(library)
} catch (e: IOException) {
throw IllegalArgumentException("Could not convert library to XML.", e)
}
}

private fun toJson(library: Library?): String {
private fun toJson(library: Library): String {
return try {
convertToJson(library)
} catch (e: IOException) {
Expand All @@ -48,11 +48,11 @@ class CqlTranslator(
}

fun toXml(): String {
return toXml(compiler.library)
return toXml(compiler.library!!)
}

fun toJson(): String {
return toJson(compiler.library)
return toJson(compiler.library!!)
}

fun toELM(): Library? {
Expand Down Expand Up @@ -251,7 +251,7 @@ class CqlTranslator(
}

@Throws(IOException::class)
fun convertToXml(library: Library?): String {
fun convertToXml(library: Library): String {
val writer = StringWriter()
ElmLibraryWriterFactory.getWriter(LibraryContentType.XML.mimeType())
.write(library, writer)
Expand All @@ -260,7 +260,7 @@ class CqlTranslator(

@JvmStatic
@Throws(IOException::class)
fun convertToJson(library: Library?): String {
fun convertToJson(library: Library): String {
val writer = StringWriter()
ElmLibraryWriterFactory.getWriter(LibraryContentType.JSON.mimeType())
.write(library, writer)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,4 +117,15 @@ class DefaultLibrarySourceProvider(path: Path) : LibrarySourceProvider, PathAwar
}
return null
}

override fun getLibraryContent(
libraryIdentifier: VersionedIdentifier,
type: LibraryContentType
): InputStream? {
if (LibraryContentType.CQL == type) {
return getLibrarySource(libraryIdentifier)
}

return null
}
}
Loading
Loading