Skip to content

Commit

Permalink
Show the smoking dialog when risk is low or medium
Browse files Browse the repository at this point in the history
  • Loading branch information
Siddharth Agarwal committed Jan 31, 2025
1 parent 9ded4fb commit cf16e66
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ class PatientSummaryEffectHandler @AssistedInject constructor(
return ObservableTransformer { effects ->
effects
.observeOn(schedulersProvider.io())
.flatMap { effect ->
.switchMap { effect ->
val patient = effect.patient
Observable.combineLatest(
medicalHistoryRepository.historyForPatientOrDefault(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import com.spotify.mobius.Next
import com.spotify.mobius.Next.next
import com.spotify.mobius.Next.noChange
import com.spotify.mobius.Update
import org.simple.clinic.cvdrisk.CVDRiskLevel
import org.simple.clinic.cvdrisk.StatinInfo
import org.simple.clinic.drugs.DiagnosisWarningPrescriptions
import org.simple.clinic.drugs.PrescribedDrug
Expand All @@ -24,6 +25,7 @@ import org.simple.clinic.summary.OpenIntention.ViewExistingPatient
import org.simple.clinic.summary.OpenIntention.ViewExistingPatientWithTeleconsultLog
import org.simple.clinic.summary.OpenIntention.ViewNewPatient
import java.util.UUID
import org.simple.clinic.medicalhistory.Answer as MedicalHistoryAnswer

class PatientSummaryUpdate(
private val isPatientReassignmentFeatureEnabled: Boolean,
Expand Down Expand Up @@ -179,7 +181,13 @@ class PatientSummaryUpdate(
event: StatinInfoLoaded,
model: PatientSummaryModel
): Next<PatientSummaryModel, PatientSummaryEffect> {
return next(model.updateStatinInfo(event.statinInfo))
return if ((event.statinInfo.cvdRisk?.level == CVDRiskLevel.LOW_HIGH ||
event.statinInfo.cvdRisk?.level == CVDRiskLevel.MEDIUM_HIGH) &&
event.statinInfo.isSmoker == MedicalHistoryAnswer.Unanswered) {
next(model.updateStatinInfo(event.statinInfo), ShowSmokingStatusDialog)
} else {
next(model.updateStatinInfo(event.statinInfo))
}
}

private fun hypertensionNotNowClicked(continueToDiabetesDiagnosisWarning: Boolean): Next<PatientSummaryModel, PatientSummaryEffect> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2358,6 +2358,23 @@ class PatientSummaryUpdateTest {
))
}

@Test
fun `when statin info is loaded and risk is low-high, then update the state and show smoking status dialog`() {
val statinInfo = StatinInfo(
canPrescribeStatin = true,
CVDRiskRange(7, 14),
)
updateSpec
.given(defaultModel)
.whenEvent(StatinInfoLoaded(
statinInfo = statinInfo
))
.then(assertThatNext(
hasModel(defaultModel.updateStatinInfo(statinInfo)),
hasEffects(ShowSmokingStatusDialog)
))
}

@Test
fun `when add smoking button is clicked, then show the smoking status dialog`() {
updateSpec
Expand Down

0 comments on commit cf16e66

Please sign in to comment.