Skip to content

Commit 89417fd

Browse files
committed
Overload FhirEngine.get()
1 parent b59acf2 commit 89417fd

File tree

3 files changed

+31
-0
lines changed

3 files changed

+31
-0
lines changed

engine/src/main/java/com/google/android/fhir/FhirEngine.kt

+24
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,17 @@ interface FhirEngine {
8383
@Throws(ResourceNotFoundException::class)
8484
suspend fun get(type: ResourceType, id: String): Resource
8585

86+
/**
87+
* Loads multiple FHIR resources given [ResourceType] and logical IDs.
88+
*
89+
* @param type The type of the resource to load.
90+
* @param ids The logical IDs of the resources.
91+
* @return The list of requested FHIR resources.
92+
* @throws ResourceNotFoundException if the resources are not found.
93+
*/
94+
@Throws(ResourceNotFoundException::class)
95+
suspend fun get(type: ResourceType, vararg ids: String): List<Resource>
96+
8697
/**
8798
* Updates one or more FHIR [Resource]s in the local storage.
8899
*
@@ -227,6 +238,19 @@ suspend inline fun <reified R : Resource> FhirEngine.get(id: String): R {
227238
return get(getResourceType(R::class.java), id) as R
228239
}
229240

241+
/**
242+
* Retrieves FHIR resources of type [R] with the given [ids] from the local storage.
243+
*
244+
* @param R The type of the FHIR resource to retrieve.
245+
* @param ids The logical IDs of the resources to retrieve.
246+
* @return The list of requested FHIR resources.
247+
* @throws ResourceNotFoundException if the resource is not found.
248+
*/
249+
@Throws(ResourceNotFoundException::class)
250+
suspend inline fun <reified R : Resource> FhirEngine.get(vararg ids: String): List<R> {
251+
return ids.map { id -> get(getResourceType(R::class.java), id) as R }
252+
}
253+
230254
/**
231255
* Deletes a FHIR resource of type [R] with the given [id] from the local storage.
232256
*

engine/src/main/java/com/google/android/fhir/impl/FhirEngineImpl.kt

+3
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ internal class FhirEngineImpl(private val database: Database, private val contex
5252
override suspend fun get(type: ResourceType, id: String) =
5353
withContext(Dispatchers.IO) { database.select(type, id) }
5454

55+
override suspend fun get(type: ResourceType, vararg ids: String) =
56+
withContext(Dispatchers.IO) { ids.map { id -> database.select(type, id) } }
57+
5558
override suspend fun update(vararg resource: Resource) =
5659
withContext(Dispatchers.IO) { database.update(*resource) }
5760

engine/src/main/java/com/google/android/fhir/testing/Utilities.kt

+4
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,10 @@ internal object TestFhirEngineImpl : FhirEngine {
151151
return Patient()
152152
}
153153

154+
override suspend fun get(type: ResourceType, vararg ids: String): List<Resource> {
155+
return ids.map { Patient().apply { id = it } }
156+
}
157+
154158
override suspend fun delete(type: ResourceType, id: String) {}
155159

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

0 commit comments

Comments
 (0)