Skip to content

Commit

Permalink
Merge remote-tracking branch 'd-tree-org/mwcore-dev' into mwcore-sdk-…
Browse files Browse the repository at this point in the history
…upgrade
  • Loading branch information
LZRS committed Mar 5, 2024
2 parents 325371f + 133a40f commit aaf28e6
Show file tree
Hide file tree
Showing 18 changed files with 187 additions and 142 deletions.
40 changes: 40 additions & 0 deletions .github/workflows/ci-mwcore.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,40 @@ env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}

jobs:
dataclerk:
runs-on: macos-latest
steps:
- name: Cancel Previous workflow runs
uses: styfle/[email protected]
with:
access_token: ${{ github.token }}

- name: Checkout 🛎️
uses: actions/checkout@v2
with:
fetch-depth: 2

- name: Set up JDK 17
uses: actions/setup-java@v1
with:
java-version: 17

- name: Decode google-services.json
run: echo $ENCODED_GOOGLE_SERVICES_JSON | base64 -d > android/quest/google-services.json
env:
ENCODED_GOOGLE_SERVICES_JSON: ${{ secrets.MWCORE_GOOGLE_SERVICES_JSON }}

- name: Grant execute permission for gradlew
run: chmod +x gradlew
working-directory: android

- name: Spotless check engine module
run: ./gradlew :dataclerk:spotlessCheck
working-directory: android

- name: Builds
run: ./gradlew :dataclerk:assembleDebug

engine-tests:
runs-on: macos-latest
steps:
Expand Down Expand Up @@ -43,6 +77,9 @@ jobs:
run: ./gradlew :engine:spotlessCheck
working-directory: android

- name: Builds
run: ./gradlew :engine:assembleDebug

# - name: Run Engine unit tests with Gradle
# run: ./gradlew :engine:clean && ./gradlew :engine:jacocoTestReport -x :engine:testReleaseUnitTest --stacktrace
# working-directory: android
Expand Down Expand Up @@ -83,6 +120,9 @@ jobs:
run: ./gradlew :quest:spotlessCheck
working-directory: android

- name: Builds
run: ./gradlew :quest:assembleMwcoreDevDebug

# - name: Run Quest unit tests with Gradle
# run: ./gradlew :quest:clean && ./gradlew :quest:jacocoTestReportMwcoreDebug -x :quest:testMwcoreReleaseUnitTest --stacktrace
# working-directory: android
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,13 @@

package org.smartregister.fhircore.engine.data.local.register.dao

import ca.uhn.fhir.rest.gclient.TokenClientParam
import ca.uhn.fhir.rest.param.ParamPrefixEnum
import com.google.android.fhir.FhirEngine
import com.google.android.fhir.logicalId
import com.google.android.fhir.search.Operation
import com.google.android.fhir.search.filter.TokenParamFilterCriterion
import com.google.android.fhir.search.has
import com.google.android.fhir.search.search
import java.util.Calendar
import javax.inject.Inject
Expand All @@ -44,7 +48,7 @@ import org.smartregister.fhircore.engine.domain.model.RegisterData
import org.smartregister.fhircore.engine.domain.repository.RegisterDao
import org.smartregister.fhircore.engine.domain.util.PaginationConstant
import org.smartregister.fhircore.engine.util.DefaultDispatcherProvider
import org.smartregister.fhircore.engine.util.LOGGED_IN_PRACTITIONER
import org.smartregister.fhircore.engine.util.SharedPreferenceKey
import org.smartregister.fhircore.engine.util.SharedPreferencesHelper
import org.smartregister.fhircore.engine.util.extension.asReference
import org.smartregister.fhircore.engine.util.extension.extractAge
Expand All @@ -65,7 +69,10 @@ constructor(
) : RegisterDao {

private val currentPractitioner by lazy {
sharedPreferencesHelper.read<Practitioner>(key = LOGGED_IN_PRACTITIONER, decodeWithGson = true)
sharedPreferencesHelper.read(
key = SharedPreferenceKey.PRACTITIONER_ID.name,
defaultValue = null,
)
}

private fun Appointment.patientRef() =
Expand All @@ -85,7 +92,6 @@ constructor(
return fhirEngine
.search<Appointment> {
filter(Appointment.STATUS, { value = of(Appointment.AppointmentStatus.BOOKED.toCode()) })
filter(Appointment.DATE, { value = of(DateTimeType.today()) })
}
.map { it.resource }
.count {
Expand Down Expand Up @@ -116,6 +122,7 @@ constructor(
page: Int = -1,
): List<Appointment> {
filters as AppointmentRegisterFilter
val patientTypeFilterTag = applicationConfiguration().patientTypeFilterTagViaMetaCodingSystem
val searchResults =
fhirEngine.search<Appointment> {
if (!loadAll) count = PaginationConstant.DEFAULT_PAGE_SIZE
Expand All @@ -139,33 +146,36 @@ constructor(
},
)

// if (filters.myPatients && currentPractititoner != null)
// filter(Appointment.PRACTITIONER, { value =
// currentPractititoner!!.referenceValue() })
//
// filters.patientCategory?.let {
// val paramQueries: List<(TokenParamFilterCriterion.() -> Unit)> =
// it.flatMap { healthStatus ->
// val coding: Coding =
// Coding().apply {
// system = "https://d-tree.org"
// code = healthStatus.name.lowercase().replace("_", "-")
// }
// val alternativeCoding: Coding =
// Coding().apply {
// system = "https://d-tree.org"
// code = healthStatus.name.lowercase()
// }
//
// return@flatMap listOf<Coding>(coding, alternativeCoding).map<
// Coding, TokenParamFilterCriterion.() -> Unit> { c -> { value = of(c) } }
// }
//
// has<Patient>(Appointment.PATIENT){
// filter(TokenClientParam("_tag"), *paramQueries.toTypedArray(), operation =
// Operation.OR)
// }
// }
if (filters.myPatients && currentPractitioner != null) {
filter(Appointment.PRACTITIONER, { value = currentPractitioner!! })
}

filters.patientCategory?.let {
val paramQueries: List<(TokenParamFilterCriterion.() -> Unit)> =
it.flatMap { healthStatus ->
val coding: Coding =
Coding().apply {
system = patientTypeFilterTag
code = healthStatus.name.lowercase().replace("_", "-")
}
val alternativeCoding: Coding =
Coding().apply {
system = patientTypeFilterTag
code = healthStatus.name.lowercase()
}

return@flatMap listOf<Coding>(coding, alternativeCoding).map<
Coding,
TokenParamFilterCriterion.() -> Unit,
> { c ->
{ value = of(c) }
}
}

has<Patient>(Appointment.PATIENT) {
filter(TokenClientParam("_tag"), *paramQueries.toTypedArray(), operation = Operation.OR)
}
}

filters.reasonCode?.let {
val codeableConcept =
Expand All @@ -186,7 +196,8 @@ constructor(
.filter {
val patientAssignmentFilter =
!filters.myPatients ||
(it.practitionerRef()?.reference == currentPractitioner?.asReference()?.reference)
(it.practitionerRef()?.reference ==
currentPractitioner?.asReference(ResourceType.Practitioner)?.reference)
val patientCategoryFilter =
filters.patientCategory == null || (patientCategoryMatches(it, filters.patientCategory))

Expand All @@ -197,7 +208,8 @@ constructor(
it.hasStart() &&
patientAssignmentFilter &&
patientCategoryFilter &&
appointmentReasonFilter
appointmentReasonFilter &&
it.patientRef() != null
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,10 @@ constructor(
sharedPreferencesHelper,
) {

override val tracingCoding: Coding = Coding("https://d-tree.org", "home-tracing", "Home Tracing")
override val tracingCoding: Coding = taskCode

companion object {
val taskCode: Coding =
Coding("https://d-tree.org/fhir/contact-tracing", "home-tracing", "Home Tracing")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ constructor(
sharedPreferencesHelper,
) {

override val tracingCoding: Coding =
Coding("https://d-tree.org", "phone-tracing", "Phone Tracing")
override val tracingCoding: Coding = taskCode

companion object {
val taskCode: Coding =
Coding("https://d-tree.org/fhir/contact-tracing", "phone-tracing", "Phone Tracing")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,7 @@ import org.smartregister.fhircore.engine.domain.model.ProfileData
import org.smartregister.fhircore.engine.domain.model.RegisterData
import org.smartregister.fhircore.engine.domain.repository.RegisterDao
import org.smartregister.fhircore.engine.domain.util.PaginationConstant
import org.smartregister.fhircore.engine.util.DispatcherProvider
import org.smartregister.fhircore.engine.util.LOGGED_IN_PRACTITIONER
import org.smartregister.fhircore.engine.util.SharedPreferenceKey
import org.smartregister.fhircore.engine.util.SharedPreferencesHelper
import org.smartregister.fhircore.engine.util.extension.asDdMmmYyyy
import org.smartregister.fhircore.engine.util.extension.asReference
Expand Down Expand Up @@ -94,7 +93,10 @@ abstract class TracingRegisterDao(
patient.extractOfficialIdentifier() ?: HivRegisterDao.ResourceValue.BLANK

private val currentPractitioner by lazy {
sharedPreferencesHelper.read<Practitioner>(key = LOGGED_IN_PRACTITIONER, decodeWithGson = true)
sharedPreferencesHelper.read(
key = SharedPreferenceKey.PRACTITIONER_ID.name,
defaultValue = null,
)
}

private val filtersForValidTask: BaseSearch.() -> Unit = {
Expand Down Expand Up @@ -125,6 +127,7 @@ abstract class TracingRegisterDao(
page: Int = -1,
): List<Pair<Patient, Iterable<Task>>> {
filters as TracingRegisterFilter
val filterFilter = applicationConfiguration().patientTypeFilterTagViaMetaCodingSystem
val patients: List<Patient> =
fhirEngine
.search<Patient> {
Expand All @@ -139,12 +142,12 @@ abstract class TracingRegisterDao(
it.flatMap { healthStatus ->
val coding: Coding =
Coding().apply {
system = "https://d-tree.org"
system = filterFilter
code = healthStatus.name.lowercase().replace("_", "-")
}
val alternativeCoding: Coding =
Coding().apply {
system = "https://d-tree.org"
system = filterFilter
code = healthStatus.name.lowercase()
}

Expand All @@ -159,8 +162,11 @@ abstract class TracingRegisterDao(
filter(TokenClientParam("_tag"), *paramQueries.toTypedArray(), operation = Operation.OR)
}

if (filters.isAssignedToMe) {
filter(Patient.GENERAL_PRACTITIONER, { value = currentPractitioner!!.referenceValue() })
if (filters.isAssignedToMe && currentPractitioner != null) {
filter(
Patient.GENERAL_PRACTITIONER,
{ value = currentPractitioner?.asReference(ResourceType.Practitioner)?.reference },
)
}
}
.map { it.resource }
Expand Down Expand Up @@ -310,8 +316,9 @@ abstract class TracingRegisterDao(
.patientTypeFilterTagViaMetaCodingSystem
val tasks = validTasks(patient)

val attempt = tracingRepository.getTracingAttempt(patient)
val attempt = tracingRepository.getTracingAttempt(patient, tasks)
var dueData = getDueDate(it)

if (dueData == null) {
tasks.minOfOrNull { task -> task.authoredOn }?.let { date -> dueData = date }
}
Expand Down Expand Up @@ -367,7 +374,7 @@ abstract class TracingRegisterDao(
subjectType = ResourceType.Patient,
subjectParam = CarePlan.SUBJECT,
)
.filter { carePlan -> carePlan.status.equals(CarePlan.CarePlanStatus.ACTIVE) }
.filter { carePlan -> carePlan.status == CarePlan.CarePlanStatus.ACTIVE }

suspend fun Patient.activeConditions() =
defaultRepository.patientConditions(this.logicalId).filter { condition ->
Expand All @@ -377,6 +384,7 @@ abstract class TracingRegisterDao(
suspend fun Patient.practitioners(): List<Practitioner> {
return generalPractitioner.mapNotNull {
try {
if (it.reference == null) return@mapNotNull null
val id = it.reference.replace("Practitioner/", "")
fhirEngine.get(ResourceType.Practitioner, id) as Practitioner
} catch (e: Exception) {
Expand Down Expand Up @@ -439,6 +447,7 @@ abstract class TracingRegisterDao(
tracingRepository
.getTracingAttempt(list = listResource)
.copy(reasons = tasks.mapNotNull { task -> task.reasonCode?.codingFirstRep?.code })

val oldestTaskDate = tasks.minOfOrNull { it.authoredOn }
return RegisterData.TracingRegisterData(
logicalId = this.logicalId,
Expand Down
Loading

0 comments on commit aaf28e6

Please sign in to comment.