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

Updating cqf library version #2527

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion buildSrc/src/main/kotlin/Dependencies.kt
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ object Dependencies {
}

object Cql {
const val clinicalReasoning = "3.0.0-PRE9-SNAPSHOT"
const val clinicalReasoning = "3.4.0"
}

object Kotlin {
Expand Down
16 changes: 12 additions & 4 deletions buildSrc/src/main/kotlin/LicenseeConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,12 @@ fun Project.configureLicensee() {
allow("BSD-2-Clause")
allow("BSD-3-Clause")
allow("MIT")
allow("EPL-1.0")
allow("LGPL-2.1-only")

ignoreDependencies("com.ibm.icu", "icu4j") {
because(
"ICU uses an ICU license that was mispaced and cannot be loaded by this tool right now",
"ICU uses an ICU license that was misplaced and cannot be loaded by this tool right now",
)
}

Expand Down Expand Up @@ -72,17 +74,23 @@ fun Project.configureLicensee() {
}

// Jakarta XML Binding API
allowDependency("jakarta.xml.bind", "jakarta.xml.bind-api", "2.3.3") {
allowDependency("jakarta.xml.bind", "jakarta.xml.bind-api", "4.0.1") {
because("BSD 3-clause.")
}

// Jakarta Activation API 2.1 Specification
allowDependency("jakarta.activation", "jakarta.activation-api", "1.2.2") {
allowDependency("jakarta.activation", "jakarta.activation-api", "2.1.2") {
because(
"Licensed under Eclipse Distribution License 1.0. http:https://www.eclipse.org/org/documents/edl-v10.php",
)
}

allowDependency("jakarta.annotation", "jakarta.annotation-api", "2.1.1") {
because(
"Licensed under Eclipse EPL-2.0 license http:https://www.eclipse.org/legal/epl-2.0'",
)
}

// Javax Annotation API
allowDependency("javax.annotation", "javax.annotation-api", "1.3.2") {
because("Dual-licensed under CDDL 1.1 and GPL v2 with classpath exception.")
Expand All @@ -108,7 +116,7 @@ fun Project.configureLicensee() {
because("BSD 3-clause. http:https://www.antlr.org/license.html")
}
// ANTLR 4
allowDependency("org.antlr", "antlr4-runtime", "4.10.1") {
allowDependency("org.antlr", "antlr4-runtime", "4.13.1") {
because("BSD 3-clause. http:https://www.antlr.org/license.html")
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2023 Google LLC
* Copyright 2023-2024 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -20,15 +20,14 @@ import ca.uhn.fhir.context.FhirContext
import ca.uhn.fhir.context.FhirVersionEnum
import ca.uhn.fhir.model.api.IQueryParameterType
import ca.uhn.fhir.parser.IParser
import ca.uhn.fhir.rest.api.EncodingEnum
import ca.uhn.fhir.rest.api.MethodOutcome
import ca.uhn.fhir.rest.param.TokenParam
import ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException
import ca.uhn.fhir.util.BundleBuilder
import com.google.common.collect.ImmutableMap
import com.google.common.collect.Sets
import java.io.File
import java.io.FileNotFoundException
import java.util.Locale
import java.util.Objects
import java.util.function.Consumer
import org.hl7.fhir.instance.model.api.IBaseBundle
Expand All @@ -40,9 +39,7 @@ import org.opencds.cqf.fhir.api.Repository
import org.opencds.cqf.fhir.utility.Ids
import org.opencds.cqf.fhir.utility.dstu3.AttachmentUtil
import org.opencds.cqf.fhir.utility.matcher.ResourceMatcher
import org.opencds.cqf.fhir.utility.repository.IGLayoutMode
import org.opencds.cqf.fhir.utility.repository.Repositories
import org.opencds.cqf.fhir.utility.repository.ResourceCategory

/**
* This class implements the Repository interface on onto a directory structure that matches the
Expand All @@ -51,11 +48,9 @@ import org.opencds.cqf.fhir.utility.repository.ResourceCategory
class IGInputStreamStructureRepository(
private val fhirContext: FhirContext,
private val root: String? = null,
private val layoutMode: IGLayoutMode = IGLayoutMode.DIRECTORY,
private val encodingEnum: EncodingEnum = EncodingEnum.JSON,
) : Loadable(), Repository {
private val resourceCache: MutableMap<String, IBaseResource> = HashMap()
private val parser: IParser = parserForEncoding(fhirContext, encodingEnum)
private val parser: IParser = fhirContext.newJsonParser()
private val resourceMatcher: ResourceMatcher = Repositories.getResourceMatcher(fhirContext)

fun clearCache() {
Expand All @@ -71,13 +66,8 @@ class IGInputStreamStructureRepository(
}

protected fun fileNameForLayoutAndEncoding(resourceType: String, resourceId: String): String {
val name = resourceId + fileExtensions[encodingEnum]
return if (layoutMode === IGLayoutMode.DIRECTORY) {
// TODO: case sensitivity!!
resourceType.lowercase(Locale.getDefault()) + "/" + name
} else {
"$resourceType-$name"
}
val name = "$resourceId.json"
return "$resourceType-$name"
}

protected fun <T : IBaseResource?> directoryForType(resourceType: Class<T>): String {
Expand All @@ -89,12 +79,7 @@ class IGInputStreamStructureRepository(
}

protected fun <T : IBaseResource?> directoryForResource(resourceType: Class<T>): String {
val directory = directoryForType(resourceType)
return if (layoutMode === IGLayoutMode.DIRECTORY) {
directory + "/" + resourceType.simpleName.lowercase(Locale.getDefault())
} else {
directory
}
return directoryForType(resourceType)
}

protected fun <T : IBaseResource, I : IIdType> readLocation(
Expand Down Expand Up @@ -178,19 +163,13 @@ class IGInputStreamStructureRepository(
val inputFiles = listFiles(location)

for (file in inputFiles) {
if (
layoutMode.equals(IGLayoutMode.DIRECTORY) ||
(layoutMode.equals(IGLayoutMode.TYPE_PREFIX) &&
file.startsWith(resourceClass.simpleName + "-"))
) {
try {
val r = this.readLocation<T, IIdType>(resourceClass, "$location/$file")
if (r.fhirType() == resourceClass.simpleName) {
resources[r.idElement.toUnqualifiedVersionless()] = r
}
} catch (e: RuntimeException) {
e.printStackTrace()
try {
val r = this.readLocation<T, IIdType>(resourceClass, "$location/$file")
if (r.fhirType() == resourceClass.simpleName) {
resources[r.idElement.toUnqualifiedVersionless()] = r
}
} catch (e: RuntimeException) {
e.printStackTrace()
}
}
return resources
Expand Down Expand Up @@ -282,7 +261,7 @@ class IGInputStreamStructureRepository(
): B {
val builder = BundleBuilder(fhirContext)
val resourceIdMap = readLocation(resourceType)
if (searchParameters == null || searchParameters.isEmpty()) {
if (searchParameters.isEmpty()) {
resourceIdMap.values.forEach(
Consumer { theResource: T ->
builder.addCollectionEntry(
Expand Down Expand Up @@ -442,30 +421,43 @@ class IGInputStreamStructureRepository(
}

companion object {

enum class ResourceCategory {
DATA,
TERMINOLOGY,
CONTENT,
;

companion object {
private val TERMINOLOGY_RESOURCES: Set<String> =
Sets.newHashSet(*arrayOf("ValueSet", "CodeSystem"))
private val CONTENT_RESOURCES: Set<String> =
Sets.newHashSet(
*arrayOf(
"Library",
"Questionnaire",
"Measure",
"PlanDefinition",
"StructureDefinition",
"ActivityDefinition",
),
)

fun forType(resourceType: String): ResourceCategory {
return if (TERMINOLOGY_RESOURCES.contains(resourceType)) {
TERMINOLOGY
} else {
if (CONTENT_RESOURCES.contains(resourceType)) CONTENT else DATA
}
}
}
}

private val categoryDirectories: Map<ResourceCategory, String> =
ImmutableMap.Builder<ResourceCategory, String>()
.put(ResourceCategory.CONTENT, "resources")
.put(ResourceCategory.DATA, "tests")
.put(ResourceCategory.TERMINOLOGY, "vocabulary")
.build()
private val fileExtensions: Map<EncodingEnum?, String> =
ImmutableMap.Builder<EncodingEnum?, String>()
.put(EncodingEnum.JSON, ".json")
.put(EncodingEnum.XML, ".xml")
.put(EncodingEnum.RDF, ".rdf")
.build()

private fun parserForEncoding(
fhirContext: FhirContext,
encodingEnum: EncodingEnum?,
): IParser {
return when (encodingEnum) {
EncodingEnum.JSON -> fhirContext.newJsonParser()
EncodingEnum.XML -> fhirContext.newXmlParser()
EncodingEnum.RDF -> fhirContext.newRDFParser()
EncodingEnum.NDJSON -> throw IllegalArgumentException("NDJSON is not supported")
else -> throw IllegalArgumentException("NDJSON is not supported")
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2022-2023 Google LLC
* Copyright 2022-2024 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -18,10 +18,8 @@ package com.google.android.fhir.workflow.testing

import ca.uhn.fhir.context.FhirContext
import ca.uhn.fhir.context.FhirVersionEnum
import ca.uhn.fhir.rest.api.EncodingEnum
import java.io.IOException
import org.hl7.fhir.instance.model.api.IBaseResource
import org.hl7.fhir.instance.model.api.IPrimitiveType
import org.hl7.fhir.r4.model.Bundle
import org.hl7.fhir.r4.model.CarePlan
import org.hl7.fhir.r4.model.CommunicationRequest
Expand All @@ -38,8 +36,8 @@ import org.junit.Assert.fail
import org.opencds.cqf.fhir.api.Repository
import org.opencds.cqf.fhir.cql.EvaluationSettings
import org.opencds.cqf.fhir.cql.LibraryEngine
import org.opencds.cqf.fhir.cr.plandefinition.r4.PlanDefinitionProcessor
import org.opencds.cqf.fhir.utility.repository.IGLayoutMode
import org.opencds.cqf.fhir.cr.plandefinition.PlanDefinitionProcessor
import org.opencds.cqf.fhir.utility.monad.Eithers
import org.opencds.cqf.fhir.utility.repository.InMemoryFhirRepository
import org.opencds.cqf.fhir.utility.repository.Repositories
import org.skyscreamer.jsonassert.JSONAssert
Expand Down Expand Up @@ -152,8 +150,6 @@ object PlanDefinition : Loadable() {
IGInputStreamStructureRepository(
fhirContext,
repositoryPath ?: ".",
IGLayoutMode.TYPE_PREFIX,
EncodingEnum.JSON,
)
if (dataRepository == null && contentRepository == null && terminologyRepository == null) {
return local
Expand Down Expand Up @@ -200,14 +196,12 @@ object PlanDefinition : Loadable() {

return GeneratedBundle(
buildProcessor(repository)
.applyR5<IPrimitiveType<String>>(
/* id = */ IdType("PlanDefinition", planDefinitionID),
/* canonical = */ null,
/* planDefinition = */ null,
/* patientId = */ patientID,
/* encounterId = */ encounterID,
/* practitionerId = */ practitionerID,
/* organizationId = */ null,
.applyR5(
/* planDefinition = */ Eithers.forMiddle3(IdType("PlanDefinition", planDefinitionID)),
/* subject = */ patientID,
/* encounter = */ encounterID,
/* practitioner = */ practitionerID,
/* organization = */ null,
/* userType = */ null,
/* userLanguage = */ null,
/* userTaskContext = */ null,
Expand Down Expand Up @@ -253,10 +247,8 @@ object PlanDefinition : Loadable() {

return GeneratedCarePlan(
(buildProcessor(repository)
.apply<IPrimitiveType<String>>(
IdType("PlanDefinition", planDefinitionID),
null,
null,
.apply(
Eithers.forMiddle3(IdType("PlanDefinition", planDefinitionID)),
patientID,
encounterID,
practitionerID,
Expand All @@ -280,10 +272,8 @@ object PlanDefinition : Loadable() {
val repository = overrideRepository ?: buildRepository()
return GeneratedPackage(
(buildProcessor(repository)
.packagePlanDefinition<IPrimitiveType<String>>(
IdType("PlanDefinition", planDefinitionID),
null,
null,
.packagePlanDefinition(
Eithers.forMiddle3(IdType("PlanDefinition", planDefinitionID)),
true,
) as Bundle),
null,
Expand Down Expand Up @@ -388,10 +378,10 @@ object PlanDefinition : Loadable() {
assertEquals(count, generatedCarePlan.contained.size)
}

fun hasOperationOutcome() {
fun hasRequestGroup() {
assertTrue(
generatedCarePlan.getContained().stream().anyMatch { r ->
r.resourceType.equals(ResourceType.OperationOutcome)
r.resourceType.equals(ResourceType.RequestGroup)
},
)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,28 +1,18 @@
package com.google.android.fhir.workflow.testing;

import org.opencds.cqf.fhir.api.Repository;
import org.opencds.cqf.fhir.utility.repository.IGFileStructureRepository;
import org.opencds.cqf.fhir.utility.repository.IGLayoutMode;

import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.rest.api.EncodingEnum;

public class TestRepositoryFactory {
private TestRepositoryFactory() {
// intentionally empty
}

public static Repository createRepository(FhirContext fhirContext, String path) {
return createRepository(fhirContext, path, IGLayoutMode.TYPE_PREFIX);
}

public static Repository createRepository(
FhirContext fhirContext, String path, IGLayoutMode layoutMode) {
return new IGInputStreamStructureRepository(
fhirContext,
path,
layoutMode,
EncodingEnum.JSON
path
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
"status": "draft",
"intent": "proposal",
"subject": {
"reference": "helloworld-patient-1"
"reference": "Patient/helloworld-patient-1"
},
"encounter": {
"reference": "helloworld-patient-1-encounter-1"
"reference": "Encounter/helloworld-patient-1-encounter-1"
},
"action": [
{
Expand All @@ -40,10 +40,10 @@
"status": "draft",
"intent": "proposal",
"subject": {
"reference": "helloworld-patient-1"
"reference": "Patient/helloworld-patient-1"
},
"encounter": {
"reference": "helloworld-patient-1-encounter-1"
"reference": "Encounter/helloworld-patient-1-encounter-1"
},
"activity": [
{
Expand Down
1 change: 1 addition & 0 deletions workflow/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ android {
"META-INF/sun-jaxb.episode",
"META-INF/*.kotlin_module",
"readme.html",
"META-INF/INDEX.LIST",
),
)
}
Expand Down
Loading
Loading