diff --git a/engine/src/androidTest/java/com/google/android/fhir/db/impl/DatabaseImplTest.kt b/engine/src/androidTest/java/com/google/android/fhir/db/impl/DatabaseImplTest.kt index e3c2d96986..1807b4b2d6 100644 --- a/engine/src/androidTest/java/com/google/android/fhir/db/impl/DatabaseImplTest.kt +++ b/engine/src/androidTest/java/com/google/android/fhir/db/impl/DatabaseImplTest.kt @@ -118,7 +118,7 @@ class DatabaseImplTest { @JvmField @Parameterized.Parameter(0) var encrypted: Boolean = false private val context: Context = ApplicationProvider.getApplicationContext() - private val parser = FhirContext.forCached(FhirVersionEnum.R4).newJsonParser() + private val parser = FhirContext.forR4Cached().newJsonParser() private lateinit var services: FhirServices private lateinit var database: Database diff --git a/engine/src/androidTest/java/com/google/android/fhir/db/impl/EncryptedDatabaseErrorTest.kt b/engine/src/androidTest/java/com/google/android/fhir/db/impl/EncryptedDatabaseErrorTest.kt index 0283e41c31..3a8f436ce3 100644 --- a/engine/src/androidTest/java/com/google/android/fhir/db/impl/EncryptedDatabaseErrorTest.kt +++ b/engine/src/androidTest/java/com/google/android/fhir/db/impl/EncryptedDatabaseErrorTest.kt @@ -49,8 +49,7 @@ import org.junit.runner.RunWith @RunWith(AndroidJUnit4::class) class EncryptedDatabaseErrorTest { private val context: Context = ApplicationProvider.getApplicationContext() - private val parser = FhirContext.forR4().newJsonParser() - private val terser = FhirTerser(FhirContext.forCached(FhirVersionEnum.R4)) + private val terser = FhirTerser(FhirContext.forR4Cached()) private val resourceIndexer = ResourceIndexer(SearchParamDefinitionsProviderImpl()) @After diff --git a/engine/src/main/java/com/google/android/fhir/db/impl/DatabaseImpl.kt b/engine/src/main/java/com/google/android/fhir/db/impl/DatabaseImpl.kt index 736d39e385..5e93450acb 100644 --- a/engine/src/main/java/com/google/android/fhir/db/impl/DatabaseImpl.kt +++ b/engine/src/main/java/com/google/android/fhir/db/impl/DatabaseImpl.kt @@ -121,18 +121,9 @@ internal class DatabaseImpl( .build() } - private val resourceDao by lazy { - db.resourceDao().also { - it.iParser = FhirContext.forCached(FhirVersionEnum.R4).newJsonParser() - it.resourceIndexer = resourceIndexer - } - } + private val resourceDao by lazy { db.resourceDao().also { it.resourceIndexer = resourceIndexer } } - private val localChangeDao = - db.localChangeDao().also { - it.iParser = FhirContext.forCached(FhirVersionEnum.R4).newJsonParser() - it.fhirTerser = fhirTerser - } + private val localChangeDao = db.localChangeDao().also { it.fhirTerser = fhirTerser } override suspend fun insert(vararg resource: R): List { val logicalIds = mutableListOf() @@ -204,7 +195,7 @@ internal class DatabaseImpl( override suspend fun select(type: ResourceType, id: String): Resource { return resourceDao.getResource(resourceId = id, resourceType = type)?.let { - FhirContext.forCached(FhirVersionEnum.R4).newJsonParser().parseResource(it) as Resource + FhirContext.forR4Cached().newJsonParser().parseResource(it) as Resource } ?: throw ResourceNotFoundException(type.name, id) } @@ -380,7 +371,7 @@ internal class DatabaseImpl( val updatedReferenceValue = "${updatedResource.resourceType.name}/${updatedResource.logicalId}" referringResourcesUuids.forEach { resourceUuid -> resourceDao.getResourceEntity(resourceUuid)?.let { - val iParser = FhirContext.forCached(FhirVersionEnum.R4).newJsonParser() + val iParser = FhirContext.forR4Cached().newJsonParser() val referringResource = iParser.parseResource(it.serializedResource) as Resource val updatedReferringResource = addUpdatedReferenceToResource( diff --git a/engine/src/main/java/com/google/android/fhir/db/impl/dao/LocalChangeDao.kt b/engine/src/main/java/com/google/android/fhir/db/impl/dao/LocalChangeDao.kt index 68069b8ab7..158067cb85 100644 --- a/engine/src/main/java/com/google/android/fhir/db/impl/dao/LocalChangeDao.kt +++ b/engine/src/main/java/com/google/android/fhir/db/impl/dao/LocalChangeDao.kt @@ -21,6 +21,7 @@ import androidx.room.Insert import androidx.room.OnConflictStrategy import androidx.room.Query import androidx.room.Transaction +import ca.uhn.fhir.context.FhirContext import ca.uhn.fhir.parser.IParser import ca.uhn.fhir.util.FhirTerser import ca.uhn.fhir.util.ResourceReferenceInfo @@ -50,8 +51,6 @@ import timber.log.Timber */ @Dao internal abstract class LocalChangeDao { - - lateinit var iParser: IParser lateinit var fhirTerser: FhirTerser @Insert(onConflict = OnConflictStrategy.REPLACE) @@ -70,7 +69,7 @@ internal abstract class LocalChangeDao { open suspend fun addInsert(resource: Resource, resourceUuid: UUID, timeOfLocalChange: Instant) { val resourceId = resource.logicalId val resourceType = resource.resourceType - val resourceString = iParser.encodeResourceToString(resource) + val resourceString = FhirContext.forR4Cached().newJsonParser().encodeResourceToString(resource) val localChangeEntity = LocalChangeEntity( @@ -128,6 +127,7 @@ internal abstract class LocalChangeDao { "Unexpected DELETE when updating $resourceType/$resourceId. UPDATE failed.", ) } + val iParser = FhirContext.forR4Cached().newJsonParser() val oldResource = iParser.parseResource(oldEntity.serializedResource) as Resource val jsonDiff = diff(iParser, oldResource, updatedResource) if (jsonDiff.length() == 0) { @@ -475,6 +475,7 @@ internal abstract class LocalChangeDao { oldReference: String, updatedReference: String, ): LocalChangeEntity { + val iParser = FhirContext.forR4Cached().newJsonParser() return when (localChange.type) { LocalChangeEntity.Type.INSERT -> { val insertResourcePayload = iParser.parseResource(localChange.payload) as Resource diff --git a/engine/src/main/java/com/google/android/fhir/db/impl/dao/ResourceDao.kt b/engine/src/main/java/com/google/android/fhir/db/impl/dao/ResourceDao.kt index 0f219d84dd..65015fc9c8 100644 --- a/engine/src/main/java/com/google/android/fhir/db/impl/dao/ResourceDao.kt +++ b/engine/src/main/java/com/google/android/fhir/db/impl/dao/ResourceDao.kt @@ -24,7 +24,7 @@ import androidx.room.OnConflictStrategy import androidx.room.Query import androidx.room.RawQuery import androidx.sqlite.db.SupportSQLiteQuery -import ca.uhn.fhir.parser.IParser +import ca.uhn.fhir.context.FhirContext import com.google.android.fhir.db.ResourceNotFoundException import com.google.android.fhir.db.impl.entities.DateIndexEntity import com.google.android.fhir.db.impl.entities.DateTimeIndexEntity @@ -55,7 +55,6 @@ import org.hl7.fhir.r4.model.ResourceType internal abstract class ResourceDao { // this is ugly but there is no way to inject these right now in Room as it is the one creating // the dao - lateinit var iParser: IParser lateinit var resourceIndexer: ResourceIndexer /** @@ -69,7 +68,8 @@ internal abstract class ResourceDao { getResourceEntity(resource.logicalId, resource.resourceType)?.let { val entity = it.copy( - serializedResource = iParser.encodeResourceToString(resource), + serializedResource = + FhirContext.forR4Cached().newJsonParser().encodeResourceToString(resource), lastUpdatedLocal = timeOfLocalChange, lastUpdatedRemote = resource.meta.lastUpdated?.toInstant() ?: it.lastUpdatedRemote, ) @@ -86,7 +86,8 @@ internal abstract class ResourceDao { val entity = it.copy( resourceId = updatedResource.logicalId, - serializedResource = iParser.encodeResourceToString(updatedResource), + serializedResource = + FhirContext.forR4Cached().newJsonParser().encodeResourceToString(updatedResource), lastUpdatedRemote = updatedResource.lastUpdated ?: it.lastUpdatedRemote, versionId = updatedResource.versionId ?: it.versionId, ) @@ -107,7 +108,8 @@ internal abstract class ResourceDao { getResourceEntity(resource.logicalId, resource.resourceType)?.let { val entity = it.copy( - serializedResource = iParser.encodeResourceToString(resource), + serializedResource = + FhirContext.forR4Cached().newJsonParser().encodeResourceToString(resource), lastUpdatedRemote = resource.meta.lastUpdated?.toInstant(), versionId = resource.versionId, ) @@ -267,7 +269,8 @@ internal abstract class ResourceDao { resourceType = resource.resourceType, resourceUuid = resourceUuid, resourceId = resource.logicalId, - serializedResource = iParser.encodeResourceToString(resource), + serializedResource = + FhirContext.forR4Cached().newJsonParser().encodeResourceToString(resource), versionId = resource.versionId, lastUpdatedRemote = resource.lastUpdated, lastUpdatedLocal = lastUpdatedLocal, @@ -297,7 +300,10 @@ internal abstract class ResourceDao { lastUpdatedRemote: Instant?, ) { getResourceEntity(resourceId, resourceType)?.let { oldResourceEntity -> - val resource = iParser.parseResource(oldResourceEntity.serializedResource) as Resource + val resource = + FhirContext.forR4Cached() + .newJsonParser() + .parseResource(oldResourceEntity.serializedResource) as Resource resource.updateMeta(versionId, lastUpdatedRemote) updateResourceWithUuid(oldResourceEntity.resourceUuid, resource) } diff --git a/engine/src/main/java/com/google/android/fhir/sync/upload/request/UrlRequestGenerator.kt b/engine/src/main/java/com/google/android/fhir/sync/upload/request/UrlRequestGenerator.kt index 8e576760c3..d868cf2467 100644 --- a/engine/src/main/java/com/google/android/fhir/sync/upload/request/UrlRequestGenerator.kt +++ b/engine/src/main/java/com/google/android/fhir/sync/upload/request/UrlRequestGenerator.kt @@ -17,7 +17,6 @@ package com.google.android.fhir.sync.upload.request import ca.uhn.fhir.context.FhirContext -import ca.uhn.fhir.context.FhirVersionEnum import com.google.android.fhir.ContentTypes import com.google.android.fhir.sync.upload.patch.Patch import com.google.android.fhir.sync.upload.patch.PatchMapping @@ -58,8 +57,6 @@ internal class UrlRequestGenerator( companion object Factory { - private val parser = FhirContext.forCached(FhirVersionEnum.R4).newJsonParser() - private val createMapping = mapOf( HttpVerb.POST to this::postForCreateResource, @@ -107,21 +104,24 @@ internal class UrlRequestGenerator( UrlUploadRequest( httpVerb = HttpVerb.DELETE, url = "${patch.resourceType}/${patch.resourceId}", - resource = parser.parseResource(patch.payload) as Resource, + resource = + FhirContext.forR4Cached().newJsonParser().parseResource(patch.payload) as Resource, ) private fun postForCreateResource(patch: Patch) = UrlUploadRequest( httpVerb = HttpVerb.POST, url = patch.resourceType, - resource = parser.parseResource(patch.payload) as Resource, + resource = + FhirContext.forR4Cached().newJsonParser().parseResource(patch.payload) as Resource, ) private fun putForCreateResource(patch: Patch) = UrlUploadRequest( httpVerb = HttpVerb.PUT, url = "${patch.resourceType}/${patch.resourceId}", - resource = parser.parseResource(patch.payload) as Resource, + resource = + FhirContext.forR4Cached().newJsonParser().parseResource(patch.payload) as Resource, ) private fun patchForUpdateResource(patch: Patch) = diff --git a/engine/src/test/java/com/google/android/fhir/impl/FhirEngineImplTest.kt b/engine/src/test/java/com/google/android/fhir/impl/FhirEngineImplTest.kt index 7fc0803492..64bfc6ace4 100644 --- a/engine/src/test/java/com/google/android/fhir/impl/FhirEngineImplTest.kt +++ b/engine/src/test/java/com/google/android/fhir/impl/FhirEngineImplTest.kt @@ -18,7 +18,6 @@ package com.google.android.fhir.impl import androidx.test.core.app.ApplicationProvider import ca.uhn.fhir.context.FhirContext -import ca.uhn.fhir.context.FhirVersionEnum import ca.uhn.fhir.rest.gclient.TokenClientParam import ca.uhn.fhir.rest.param.ParamPrefixEnum import com.google.android.fhir.FhirServices.Companion.builder @@ -76,7 +75,7 @@ import org.robolectric.RobolectricTestRunner class FhirEngineImplTest { private val services = builder(ApplicationProvider.getApplicationContext()).inMemory().build() private val fhirEngine = services.fhirEngine - private val parser = FhirContext.forCached(FhirVersionEnum.R4).newJsonParser() + private val parser = FhirContext.forR4Cached().newJsonParser() @Before fun setUp(): Unit = runBlocking { fhirEngine.create(TEST_PATIENT_1) } diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 8f273e2bd1..79fc02d4d8 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -4,7 +4,7 @@ android-fhir-common = "0.1.0-alpha05" android-fhir-engine = "0.1.0-beta05" android-fhir-knowledge = "0.1.0-beta01" -androidx-acivity = "1.7.2" +androidx-activity = "1.7.2" androidx-appcompat = "1.6.1" androidx-arch-core = "2.2.0" androidx-benchmark = "1.1.1" @@ -37,7 +37,7 @@ material = "1.9.0" android-fhir-common = { module = "com.google.android.fhir:common", version.ref = "android-fhir-common" } android-fhir-engine = { module = "com.google.android.fhir:engine", version.ref = "android-fhir-engine" } android-fhir-knowledge = { module = "com.google.android.fhir:knowledge", version.ref = "android-fhir-knowledge" } -androidx-activity = { module = "androidx.activity:activity", version.ref = "androidx-acivity" } +androidx-activity = { module = "androidx.activity:activity", version.ref = "androidx-activity" } androidx-appcompat = { module = "androidx.appcompat:appcompat", version.ref = "androidx-appcompat" } androidx-arch-core-testing = { module = "androidx.arch.core:core-testing", version.ref = "androidx-arch-core" } androidx-benchmark-junit4 = { module = "androidx.benchmark:benchmark-junit4", version.ref = "androidx-benchmark" } diff --git a/knowledge/src/main/java/com/google/android/fhir/knowledge/KnowledgeManager.kt b/knowledge/src/main/java/com/google/android/fhir/knowledge/KnowledgeManager.kt index 4d0c0ad1b0..953b936e26 100644 --- a/knowledge/src/main/java/com/google/android/fhir/knowledge/KnowledgeManager.kt +++ b/knowledge/src/main/java/com/google/android/fhir/knowledge/KnowledgeManager.kt @@ -19,7 +19,6 @@ package com.google.android.fhir.knowledge import android.content.Context import androidx.room.Room import ca.uhn.fhir.context.FhirContext -import ca.uhn.fhir.context.FhirVersionEnum import com.google.android.fhir.knowledge.db.KnowledgeDatabase import com.google.android.fhir.knowledge.db.entities.ImplementationGuideEntity import com.google.android.fhir.knowledge.db.entities.ResourceMetadataEntity @@ -295,8 +294,7 @@ internal constructor( private suspend fun readResourceOrNull(file: File): IBaseResource? = withContext(Dispatchers.IO) { try { - FileInputStream(file) - .use(FhirContext.forCached(FhirVersionEnum.R4).newJsonParser()::parseResource) + FileInputStream(file).use(FhirContext.forR4Cached().newJsonParser()::parseResource) } catch (e: Exception) { Timber.e(e, "Unable to load resource from $file") null