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

Quirks patches [DNM] #9

Open
wants to merge 50 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
7a45e18
New API to support saving local only resources
ndegwamartin Aug 23, 2023
0cae350
API access for data in the LocalChangeEntity table
ndegwamartin Aug 23, 2023
bb1f2eb
Add a SyncJobStatus result callback amid Sync retries
ndegwamartin Aug 23, 2023
49ca6fa
Merge branch 'master' into quirks-patches
ndegwamartin Sep 13, 2023
95633d2
Refactor SquashedLocalChanges to LocalChanges
ndegwamartin Sep 14, 2023
8de5078
Merge branch 'master' into quirks-patches
f-odhiambo Sep 14, 2023
b9ded79
Merge branch 'master' into quirks-patches
ndegwamartin Sep 20, 2023
1721a4a
Revert "New API to support saving local only resources"
ndegwamartin Sep 20, 2023
110c322
Merge branch 'master' into quirks-patches
ndegwamartin Sep 21, 2023
e325ba4
Merge branch 'master' into quirks-patches
ndegwamartin Oct 13, 2023
c9ca366
Disable eTAGs for Uploads
ndegwamartin Oct 13, 2023
136833a
Apply Spotless
ndegwamartin Oct 13, 2023
ea0ebef
Merge branch 'master' into quirks-patches
ndegwamartin Oct 30, 2023
de504eb
Merge branch 'master' into quirks-patches
Rkareko Nov 24, 2023
8c43299
Merge master into quirks-patches
Rkareko Dec 20, 2023
6ebc36d
Disable eTAGs for Uploads
Rkareko Dec 20, 2023
320ee39
Merge branch 'master' into quirks-patches
ndegwamartin Feb 7, 2024
65a342d
Merge branch 'master' into quirks-patches
ndegwamartin Feb 9, 2024
e6439e3
Update Clinical Reasoning version to PRE9
ndegwamartin Feb 9, 2024
7097dfb
Expose overloaded API for evaluateMeasure
ndegwamartin Feb 9, 2024
1942489
Merge branch 'master' into quirks-patches
ndegwamartin Mar 19, 2024
c3d476f
Merge branch 'master' into quirks-patches
ndegwamartin Mar 22, 2024
a3932bc
Merge branch 'master' into quirks-patches
ndegwamartin Mar 27, 2024
6dee127
Merge branch 'master' into quirks-patches
ndegwamartin Apr 19, 2024
7a75afb
Merge branch 'master' into quirks-patches
ndegwamartin Jun 21, 2024
6a669eb
Merge branch 'master' into quirks-patches
ndegwamartin Jul 9, 2024
4eb2ca2
Merge branch 'master' into quirks-patches
ndegwamartin Jul 30, 2024
3e8fdb5
Sync HAPI FHIR Exceptions Logging for the FHIR SDK
ndegwamartin Sep 4, 2024
66b0963
x
ndegwamartin Sep 10, 2024
4992100
Rename install API to index for file in knowledge manager (#2634)
jingtang10 Aug 2, 2024
ae0e4ce
Update CODEOWNERS to use group instead of individuals (#2659)
ktarasenko Aug 20, 2024
7522e98
Clean up UI navigation item (#2658)
jingtang10 Aug 21, 2024
cd6268e
Add missing response items to repeated group child items (#2657)
FikriMilano Aug 22, 2024
e0cebb2
Add flyover text as secondary dialog title (#2648)
FikriMilano Aug 22, 2024
4f3bad5
Small changes for more code readability (#2656)
MJ1998 Aug 26, 2024
9a923af
Add missing use of viewItem.questionText (#2665)
FikriMilano Aug 27, 2024
a0dab66
Load resources with url and optional version (#2666)
jingtang10 Aug 28, 2024
2036be9
Fix keyboard hiding bug (#2652)
FikriMilano Sep 3, 2024
8d64417
Add condition to not populate string value if it's empty (#2521)
FikriMilano Sep 4, 2024
52c257e
Bump up knowledge manager version to beta01 (#2667)
jingtang10 Sep 4, 2024
c1e6a95
Per question custom style (#2636)
santosh-pingle Sep 4, 2024
5787c7f
Remove eTag param override
ndegwamartin Sep 4, 2024
d871fa3
Parallelize DB resource deserialization to Optimize Database API
ndegwamartin Sep 4, 2024
5720eb2
Revert "Expose overloaded API for evaluateMeasure"
ndegwamartin Sep 6, 2024
60e7d6d
Merge branch 'master' into quirks-patches
ndegwamartin Sep 10, 2024
9b4c893
Reset FhirOperator.kt
ndegwamartin Sep 13, 2024
545aa69
Disable eTag for bundle uploads
ndegwamartin Sep 13, 2024
45b96ff
Fix error validation highlighting not working when submit button is c…
Rkareko Sep 30, 2024
c6715e6
Add empty questionnaire response items for repeat groups without answers
Rkareko Oct 10, 2024
e60758b
Merge branch 'master' into quirks-patches
ndegwamartin Nov 4, 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 @@ -1123,7 +1123,7 @@ internal class QuestionnaireViewModel(application: Application, state: SavedStat
// Results in a new questionnaire state being generated synchronously, i.e., the current
// thread will be suspended until the new state is generated.
modificationCount.update { it + 1 }
forceValidation = false
//forceValidation = false
}

if (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -941,13 +941,10 @@ internal fun QuestionnaireItemComponent.createQuestionnaireResponseItem():
) {
this.copyNestedItemsToChildlessAnswers(this@createQuestionnaireResponseItem)
} else if (
[email protected] == Questionnaire.QuestionnaireItemType.GROUP &&
!repeats
[email protected] == Questionnaire.QuestionnaireItemType.GROUP
) {
[email protected] {
if (!it.isRepeatedGroup) {
this.addItem(it.createQuestionnaireResponseItem())
}
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions engine/src/main/java/com/google/android/fhir/FhirEngine.kt
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,8 @@ interface FhirEngine {
*/
suspend fun getLocalChanges(type: ResourceType, id: String): List<LocalChange>

suspend fun getUnsyncedLocalChanges(): List<LocalChange>

/**
* Purges a resource from the database without deleting data from the server.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ import com.google.android.fhir.toLocalChange
import com.google.android.fhir.updateMeta
import java.time.Instant
import java.util.UUID
import kotlinx.coroutines.async
import kotlinx.coroutines.awaitAll
import kotlinx.coroutines.coroutineScope
import kotlinx.coroutines.Dispatchers
import org.hl7.fhir.r4.model.IdType
import org.hl7.fhir.r4.model.Resource
Expand Down Expand Up @@ -320,8 +323,8 @@ internal class DatabaseImpl(
val currentResourceEntity = selectEntity(updatedResource.resourceType, currentResourceId)
val oldResource = iParser.parseResource(currentResourceEntity.serializedResource) as Resource
val resourceUuid = currentResourceEntity.resourceUuid
updateResourceEntity(resourceUuid, updatedResource)

updateResourceEntity(resourceUuid, updatedResource)
if (currentResourceId == updatedResource.logicalId) {
return@withTransaction
}
Expand Down Expand Up @@ -449,6 +452,11 @@ internal class DatabaseImpl(
}
}

/** Implementation of a parallelized map */
suspend fun <A, B> Iterable<A>.pmap(f: suspend (A) -> B): List<B> = coroutineScope {
map { async { f(it) } }.awaitAll()
}

companion object {
/**
* The name for unencrypted database.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ internal class FhirEngineImpl(private val database: Database, private val contex
override suspend fun getLocalChanges(type: ResourceType, id: String) =
withContext(Dispatchers.IO) { database.getLocalChanges(type, id) }

override suspend fun getUnsyncedLocalChanges(): List<LocalChange> = database.getAllLocalChanges()

override suspend fun purge(type: ResourceType, id: String, forcePurge: Boolean) =
withContext(Dispatchers.IO) { database.purge(type, setOf(id), forcePurge) }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import androidx.work.CoroutineWorker
import androidx.work.Data
import androidx.work.WorkerParameters
import androidx.work.workDataOf
import ca.uhn.fhir.context.FhirContext
import com.google.android.fhir.FhirEngine
import com.google.android.fhir.FhirEngineProvider
import com.google.android.fhir.OffsetDateTimeTypeAdapter
Expand All @@ -32,11 +33,15 @@ import com.google.android.fhir.sync.upload.request.UploadRequestGeneratorFactory
import com.google.gson.ExclusionStrategy
import com.google.gson.FieldAttributes
import com.google.gson.GsonBuilder
import java.nio.charset.StandardCharsets
import java.time.OffsetDateTime
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.cancel
import kotlinx.coroutines.launch
import org.apache.commons.io.IOUtils
import org.hl7.fhir.r4.model.OperationOutcome
import retrofit2.HttpException
import timber.log.Timber

/**
Expand Down Expand Up @@ -131,6 +136,8 @@ abstract class FhirSyncWorker(appContext: Context, workerParams: WorkerParameter
}

val result = synchronizer.synchronize()
if (result is SyncJobStatus.Failed) onFailedSyncJobResult(result)

val output = buildWorkData(result)

// await/join is needed to collect states completely
Expand All @@ -151,6 +158,34 @@ abstract class FhirSyncWorker(appContext: Context, workerParams: WorkerParameter
}
}

open fun onFailedSyncJobResult(failedSyncJobStatus: SyncJobStatus.Failed) {
try {
val jsonParser = FhirContext.forR4().newJsonParser()
val exceptions = (failedSyncJobStatus).exceptions

exceptions.forEach { resourceSyncException ->
val operationOutcome =
jsonParser.parseResource(
IOUtils.toString(
(resourceSyncException.exception as HttpException)
.response()
?.errorBody()
?.byteStream(),
StandardCharsets.UTF_8,
),
) as OperationOutcome

operationOutcome.issue.forEach { operationOutcome ->
Timber.e(
"SERVER ${operationOutcome.severity} - HTTP ${resourceSyncException.exception.code()} | Code - ${operationOutcome.code} | Diagnostics - ${operationOutcome.diagnostics}",
)
}
}
} catch (e: Exception) {
Timber.e(e)
}
}

private fun buildWorkData(state: SyncJobStatus): Data {
return workDataOf(
// send serialized state and type so that consumer can convert it back
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ internal object UploadRequestGeneratorFactory {
mode.httpVerbToUseForCreate,
mode.httpVerbToUseForUpdate,
mode.bundleSize,
useETagForUpload = false
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,10 @@ internal object TestFhirEngineImpl : FhirEngine {
)
}

override suspend fun getUnsyncedLocalChanges(): List<LocalChange> {
TODO("Not yet implemented")
}

override suspend fun purge(type: ResourceType, id: String, forcePurge: Boolean) {}

override suspend fun purge(type: ResourceType, ids: Set<String>, forcePurge: Boolean) {}
Expand Down
Loading