Skip to content

Commit

Permalink
Add feature flag for statin nudge (#5076)
Browse files Browse the repository at this point in the history
  • Loading branch information
msasikanth authored Sep 11, 2024
1 parent 73c1ea6 commit 509a319
Show file tree
Hide file tree
Showing 8 changed files with 83 additions and 13 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@
- Bump AndroidX ViewModel to v2.8.5
- Bump AndroidX Lifecycle to v2.8.5
- Check statin nudge status in patient summary screen
- Show statin nudge alert when statins can be prescribed
- Add feature flag for statin nudge

### Features

- Show statin nudge alert when statins can be prescribed

## 2024-08-05-9175

Expand Down
5 changes: 5 additions & 0 deletions app/src/main/java/org/simple/clinic/ClinicApp.kt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import org.simple.clinic.platform.analytics.AnalyticsReporter
import org.simple.clinic.platform.crash.CrashReporter
import org.simple.clinic.plumbing.infrastructure.UpdateInfrastructureUserDetails
import org.simple.clinic.remoteconfig.ConfigReader
import org.simple.clinic.remoteconfig.UpdateFacilityRemoteConfig
import org.simple.clinic.storage.DatabaseEncryptor
import org.simple.clinic.storage.monitoring.DatadogSqlPerformanceReportingSink
import org.simple.clinic.storage.monitoring.SqlPerformanceReporter
Expand Down Expand Up @@ -64,6 +65,9 @@ abstract class ClinicApp : Application(), CameraXConfig.Provider {
@Inject
lateinit var schedulersProvider: SchedulersProvider

@Inject
lateinit var updateFacilityRemoteConfig: UpdateFacilityRemoteConfig

protected open val analyticsReporters = emptyList<AnalyticsReporter>()

protected open val crashReporterSinks = emptyList<CrashReporter.Sink>()
Expand All @@ -83,6 +87,7 @@ abstract class ClinicApp : Application(), CameraXConfig.Provider {
updateInfrastructureUserDetails.track()
updateAnalyticsUserId.listen()
closeActivitiesWhenUserIsUnauthorized.listen()
updateFacilityRemoteConfig.track()
}

crashReporterSinks.forEach(CrashReporter::addSink)
Expand Down
3 changes: 2 additions & 1 deletion app/src/main/java/org/simple/clinic/feature/Feature.kt
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,6 @@ enum class Feature(
OverdueSelectAndDownload(false, "overdue_select_and_download_v2"),
PatientLineListDownload(false, "patient_line_list_download_v2"),
LogoutUser(false, "logout_user_v1"),
PatientReassignment(false, "patient_reassignment_v0")
PatientReassignment(false, "patient_reassignment_v0"),
PatientStatinNudge(false, "patient_statin_nudge_v0")
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package org.simple.clinic.remoteconfig

import android.annotation.SuppressLint
import androidx.work.ExistingWorkPolicy.REPLACE
import androidx.work.WorkManager
import io.reactivex.Observable
import org.simple.clinic.facility.Facility
import org.simple.clinic.remoteconfig.UpdateRemoteConfigWorker.Companion.REMOTE_CONFIG_SYNC_WORKER
import org.simple.clinic.util.scheduler.SchedulersProvider
import javax.inject.Inject

class UpdateFacilityRemoteConfig @Inject constructor(
private val currentFacilityStream: Observable<Facility>,
private val workManager: WorkManager,
private val schedulers: SchedulersProvider,
) {

/**
* When facility is changed, then update remote config, since
* user properties are updated in Firebase which are used in
* remote config conditionals
*
* https://firebase.google.com/docs/analytics/user-properties?platform=android
*/
@SuppressLint("CheckResult")
fun track() {
currentFacilityStream
.subscribeOn(schedulers.io())
.distinctUntilChanged()
.subscribe {
workManager.enqueueUniqueWork(REMOTE_CONFIG_SYNC_WORKER, REPLACE, UpdateRemoteConfigWorker.createWorkRequest())
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,8 @@ class PatientSummaryScreen :

override fun createUpdate(): Update<PatientSummaryModel, PatientSummaryEvent, PatientSummaryEffect> {
return PatientSummaryUpdate(
isPatientReassignmentFeatureEnabled = features.isEnabled(Feature.PatientReassignment)
isPatientReassignmentFeatureEnabled = features.isEnabled(Feature.PatientReassignment),
isPatientStatinNudgeEnabled = features.isEnabled(Feature.PatientStatinNudge),
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ import org.simple.clinic.summary.OpenIntention.ViewNewPatient
import java.util.UUID

class PatientSummaryUpdate(
private val isPatientReassignmentFeatureEnabled: Boolean
private val isPatientReassignmentFeatureEnabled: Boolean,
private val isPatientStatinNudgeEnabled: Boolean,
) : Update<PatientSummaryModel, PatientSummaryEvent, PatientSummaryEffect> {

override fun update(
Expand Down Expand Up @@ -311,9 +312,12 @@ class PatientSummaryUpdate(
model: PatientSummaryModel,
event: PatientSummaryProfileLoaded
): Next<PatientSummaryModel, PatientSummaryEffect> {
val effects = mutableSetOf<PatientSummaryEffect>(
LoadStatinPrescriptionCheckInfo(patient = event.patientSummaryProfile.patient)
)
val effects = mutableSetOf<PatientSummaryEffect>()

if (isPatientStatinNudgeEnabled) {
effects.add(LoadStatinPrescriptionCheckInfo(patient = event.patientSummaryProfile.patient))
}

if (model.openIntention is LinkIdWithPatient &&
!event.patientSummaryProfile.hasIdentifier(model.openIntention.identifier)) {
effects.add(ShowLinkIdWithPatientView(model.patientUuid, model.openIntention.identifier))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ class PatientSummaryScreenLogicTest {
events = uiEvents.ofType(),
defaultModel = PatientSummaryModel.from(openIntention, patientUuid),
init = PatientSummaryInit(),
update = PatientSummaryUpdate(false),
update = PatientSummaryUpdate(isPatientReassignmentFeatureEnabled = false, isPatientStatinNudgeEnabled = false),
effectHandler = effectHandler.build(),
modelUpdateListener = viewRenderer::render
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,10 @@ class PatientSummaryUpdateTest {
)
)

private val updateSpec = UpdateSpec(PatientSummaryUpdate(true))
private val updateSpec = UpdateSpec(PatientSummaryUpdate(
isPatientReassignmentFeatureEnabled = true,
isPatientStatinNudgeEnabled = false,
))

@Test
fun `when the current facility is loaded, update the UI`() {
Expand All @@ -102,6 +105,22 @@ class PatientSummaryUpdateTest {

@Test
fun `when the patient summary profile is loaded, then update the UI`() {
updateSpec
.given(defaultModel)
.whenEvent(PatientSummaryProfileLoaded(patientSummaryProfile))
.then(assertThatNext(
hasModel(defaultModel.patientSummaryProfileLoaded(patientSummaryProfile)),
hasNoEffects()
))
}

@Test
fun `when the patient summary profile is loaded and statin nudge feature flag is enabled, then update the UI and load statin check info`() {
val updateSpec = UpdateSpec(PatientSummaryUpdate(
isPatientReassignmentFeatureEnabled = true,
isPatientStatinNudgeEnabled = true,
))

updateSpec
.given(defaultModel)
.whenEvent(PatientSummaryProfileLoaded(patientSummaryProfile))
Expand Down Expand Up @@ -129,7 +148,6 @@ class PatientSummaryUpdateTest {
.then(assertThatNext(
hasModel(linkIdWithPatientModel.patientSummaryProfileLoaded(patientSummaryProfile)),
hasEffects(
LoadStatinPrescriptionCheckInfo(patient = patient),
ShowLinkIdWithPatientView(patientUuid, bpPassportIdentifier)
)
))
Expand Down Expand Up @@ -1647,7 +1665,8 @@ class PatientSummaryUpdateTest {
@Test
fun `when patient reassignment feature is disabled, and patient is not dead, and done is clicked, then load data for done click`() {
val updateSpec = UpdateSpec(PatientSummaryUpdate(
isPatientReassignmentFeatureEnabled = false
isPatientReassignmentFeatureEnabled = false,
isPatientStatinNudgeEnabled = false
))
val model = defaultModel
.currentFacilityLoaded(facility)
Expand All @@ -1674,7 +1693,8 @@ class PatientSummaryUpdateTest {
@Test
fun `when patient reassignment feature is disabled, and patient is not dead, and back is clicked, then load data for back click`() {
val updateSpec = UpdateSpec(PatientSummaryUpdate(
isPatientReassignmentFeatureEnabled = false
isPatientReassignmentFeatureEnabled = false,
isPatientStatinNudgeEnabled = false
))
val model = defaultModel
.currentFacilityLoaded(facility)
Expand All @@ -1701,7 +1721,8 @@ class PatientSummaryUpdateTest {
@Test
fun `when patient reassignment feature is disabled and measurement warning not now is clicked, then load data for back click`() {
val updateSpec = UpdateSpec(PatientSummaryUpdate(
isPatientReassignmentFeatureEnabled = false
isPatientReassignmentFeatureEnabled = false,
isPatientStatinNudgeEnabled = false
))
val model = defaultModel
.currentFacilityLoaded(facility)
Expand Down

0 comments on commit 509a319

Please sign in to comment.