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

Enable custom query running on FhirEngine #1

Closed
wants to merge 10 commits into from
2 changes: 1 addition & 1 deletion buildSrc/src/main/kotlin/Releases.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ object Releases {

object Engine {
const val artifactId = "engine"
const val version = "0.1.0-alpha06"
const val version = "0.1.0-alpha06-preview-p2p"
ndegwamartin marked this conversation as resolved.
Show resolved Hide resolved
const val name = "Android FHIR Engine Library"
}

Expand Down
7 changes: 7 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 @@ -20,6 +20,7 @@ import com.google.android.fhir.db.ResourceNotFoundException
import com.google.android.fhir.db.impl.dao.LocalChangeToken
import com.google.android.fhir.db.impl.dao.SquashedLocalChange
import com.google.android.fhir.search.Search
import com.google.android.fhir.search.SearchQuery
import java.time.OffsetDateTime
import org.hl7.fhir.r4.model.Resource
import org.hl7.fhir.r4.model.ResourceType
Expand Down Expand Up @@ -62,6 +63,12 @@ interface FhirEngine {
*/
suspend fun <R : Resource> search(search: Search): List<R>


/**
* Searches the database and returns a list resources according to the [search] specifications.
*/
suspend fun <R : Resource> search(searchQuery: SearchQuery): List<R>

/**
* Synchronizes the [upload] result in the database. The database will be updated to reflect the
* result of the [upload] operation.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import com.google.android.fhir.db.impl.dao.LocalChangeToken
import com.google.android.fhir.db.impl.dao.SquashedLocalChange
import com.google.android.fhir.db.impl.entities.SyncedResourceEntity
import com.google.android.fhir.search.Search
import com.google.android.fhir.search.SearchQuery
import com.google.android.fhir.search.count
import com.google.android.fhir.search.execute
import com.google.android.fhir.toTimeZoneString
Expand Down Expand Up @@ -54,6 +55,33 @@ internal class FhirEngineImpl(private val database: Database, private val contex
override suspend fun <R : Resource> search(search: Search): List<R> {
return search.execute(database)
}
/*
suspend fun sample(dateFrom: Long, limit: Long) {

val searchQuery =
SearchQuery(
"""
SELECT a.serializedResource, b.index_to
FROM ResourceEntity a
LEFT JOIN DateTimeIndexEntity b
ON a.resourceType = b.resourceType AND a.resourceId = b.resourceId AND b.index_name = '_lastUpdated'
WHERE a.resourceType = 'Patient'
AND a.resourceId IN (
SELECT resourceId FROM DateTimeIndexEntity
WHERE resourceType = 'Patient' AND index_name = '_lastUpdated' AND index_to > ?
)
ORDER BY b.index_from ASC
LIMIT ?
""".trimIndent(),
listOf(dateFrom, limit)
)

val patients = search<Patient>(searchQuery)
}*/

override suspend fun <R : Resource> search(searchQuery: SearchQuery): List<R> {
return database.search(searchQuery)
}

override suspend fun count(search: Search): Long {
return search.count(database)
Expand Down