Skip to content

Commit cf16e66

Browse files
author
Siddharth Agarwal
committed
Show the smoking dialog when risk is low or medium
1 parent 9ded4fb commit cf16e66

File tree

3 files changed

+27
-2
lines changed

3 files changed

+27
-2
lines changed

app/src/main/java/org/simple/clinic/summary/PatientSummaryEffectHandler.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ class PatientSummaryEffectHandler @AssistedInject constructor(
116116
return ObservableTransformer { effects ->
117117
effects
118118
.observeOn(schedulersProvider.io())
119-
.flatMap { effect ->
119+
.switchMap { effect ->
120120
val patient = effect.patient
121121
Observable.combineLatest(
122122
medicalHistoryRepository.historyForPatientOrDefault(

app/src/main/java/org/simple/clinic/summary/PatientSummaryUpdate.kt

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import com.spotify.mobius.Next
44
import com.spotify.mobius.Next.next
55
import com.spotify.mobius.Next.noChange
66
import com.spotify.mobius.Update
7+
import org.simple.clinic.cvdrisk.CVDRiskLevel
78
import org.simple.clinic.cvdrisk.StatinInfo
89
import org.simple.clinic.drugs.DiagnosisWarningPrescriptions
910
import org.simple.clinic.drugs.PrescribedDrug
@@ -24,6 +25,7 @@ import org.simple.clinic.summary.OpenIntention.ViewExistingPatient
2425
import org.simple.clinic.summary.OpenIntention.ViewExistingPatientWithTeleconsultLog
2526
import org.simple.clinic.summary.OpenIntention.ViewNewPatient
2627
import java.util.UUID
28+
import org.simple.clinic.medicalhistory.Answer as MedicalHistoryAnswer
2729

2830
class PatientSummaryUpdate(
2931
private val isPatientReassignmentFeatureEnabled: Boolean,
@@ -179,7 +181,13 @@ class PatientSummaryUpdate(
179181
event: StatinInfoLoaded,
180182
model: PatientSummaryModel
181183
): Next<PatientSummaryModel, PatientSummaryEffect> {
182-
return next(model.updateStatinInfo(event.statinInfo))
184+
return if ((event.statinInfo.cvdRisk?.level == CVDRiskLevel.LOW_HIGH ||
185+
event.statinInfo.cvdRisk?.level == CVDRiskLevel.MEDIUM_HIGH) &&
186+
event.statinInfo.isSmoker == MedicalHistoryAnswer.Unanswered) {
187+
next(model.updateStatinInfo(event.statinInfo), ShowSmokingStatusDialog)
188+
} else {
189+
next(model.updateStatinInfo(event.statinInfo))
190+
}
183191
}
184192

185193
private fun hypertensionNotNowClicked(continueToDiabetesDiagnosisWarning: Boolean): Next<PatientSummaryModel, PatientSummaryEffect> {

app/src/test/java/org/simple/clinic/summary/PatientSummaryUpdateTest.kt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2358,6 +2358,23 @@ class PatientSummaryUpdateTest {
23582358
))
23592359
}
23602360

2361+
@Test
2362+
fun `when statin info is loaded and risk is low-high, then update the state and show smoking status dialog`() {
2363+
val statinInfo = StatinInfo(
2364+
canPrescribeStatin = true,
2365+
CVDRiskRange(7, 14),
2366+
)
2367+
updateSpec
2368+
.given(defaultModel)
2369+
.whenEvent(StatinInfoLoaded(
2370+
statinInfo = statinInfo
2371+
))
2372+
.then(assertThatNext(
2373+
hasModel(defaultModel.updateStatinInfo(statinInfo)),
2374+
hasEffects(ShowSmokingStatusDialog)
2375+
))
2376+
}
2377+
23612378
@Test
23622379
fun `when add smoking button is clicked, then show the smoking status dialog`() {
23632380
updateSpec

0 commit comments

Comments
 (0)