Skip to content

Commit

Permalink
Overload FhirEngine.get()
Browse files Browse the repository at this point in the history
  • Loading branch information
qiarie committed Nov 27, 2024
1 parent b59acf2 commit 89417fd
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
24 changes: 24 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 @@ -83,6 +83,17 @@ interface FhirEngine {
@Throws(ResourceNotFoundException::class)
suspend fun get(type: ResourceType, id: String): Resource

/**
* Loads multiple FHIR resources given [ResourceType] and logical IDs.
*
* @param type The type of the resource to load.
* @param ids The logical IDs of the resources.
* @return The list of requested FHIR resources.
* @throws ResourceNotFoundException if the resources are not found.
*/
@Throws(ResourceNotFoundException::class)
suspend fun get(type: ResourceType, vararg ids: String): List<Resource>

/**
* Updates one or more FHIR [Resource]s in the local storage.
*
Expand Down Expand Up @@ -227,6 +238,19 @@ suspend inline fun <reified R : Resource> FhirEngine.get(id: String): R {
return get(getResourceType(R::class.java), id) as R
}

/**
* Retrieves FHIR resources of type [R] with the given [ids] from the local storage.
*
* @param R The type of the FHIR resource to retrieve.
* @param ids The logical IDs of the resources to retrieve.
* @return The list of requested FHIR resources.
* @throws ResourceNotFoundException if the resource is not found.
*/
@Throws(ResourceNotFoundException::class)
suspend inline fun <reified R : Resource> FhirEngine.get(vararg ids: String): List<R> {
return ids.map { id -> get(getResourceType(R::class.java), id) as R }
}

/**
* Deletes a FHIR resource of type [R] with the given [id] from the local storage.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ internal class FhirEngineImpl(private val database: Database, private val contex
override suspend fun get(type: ResourceType, id: String) =
withContext(Dispatchers.IO) { database.select(type, id) }

override suspend fun get(type: ResourceType, vararg ids: String) =
withContext(Dispatchers.IO) { ids.map { id -> database.select(type, id) } }

override suspend fun update(vararg resource: Resource) =
withContext(Dispatchers.IO) { database.update(*resource) }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,10 @@ internal object TestFhirEngineImpl : FhirEngine {
return Patient()
}

override suspend fun get(type: ResourceType, vararg ids: String): List<Resource> {
return ids.map { Patient().apply { id = it } }
}

override suspend fun delete(type: ResourceType, id: String) {}

override suspend fun <R : Resource> search(search: Search): List<SearchResult<R>> {
Expand Down

0 comments on commit 89417fd

Please sign in to comment.