Skip to content

Commit 974340e

Browse files
authored
Update tobacco use answer on dialog selection (#5542)
1 parent 159617f commit 974340e

File tree

6 files changed

+32
-16
lines changed

6 files changed

+32
-16
lines changed

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,11 @@ data class UpdateCVDRisk(
7777

7878
data class LoadStatinInfo(val patientUuid: UUID) : PatientSummaryEffect()
7979

80-
data class UpdateSmokingStatus(val patientId: UUID, val isSmoker: MedicalHistoryAnswer) : PatientSummaryEffect()
80+
data class UpdateTobaccoUse(
81+
val patientId: UUID,
82+
val isSmoker: MedicalHistoryAnswer,
83+
val isUsingSmokelessTobacco: MedicalHistoryAnswer
84+
) : PatientSummaryEffect()
8185

8286
sealed class PatientSummaryViewEffect : PatientSummaryEffect()
8387

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ class PatientSummaryEffectHandler @AssistedInject constructor(
111111
.addTransformer(UpdateCVDRisk::class.java, updateCVDRisk())
112112
.addTransformer(SaveCVDRisk::class.java, saveCVDRisk())
113113
.addTransformer(LoadStatinInfo::class.java, loadStatinInfo())
114-
.addConsumer(UpdateSmokingStatus::class.java, { updateSmokingStatus(it.patientId, it.isSmoker) }, schedulersProvider.io())
114+
.addConsumer(UpdateTobaccoUse::class.java, { updateTobaccoUse(it.patientId, it.isSmoker, it.isUsingSmokelessTobacco) }, schedulersProvider.io())
115115
.build()
116116
}
117117

@@ -302,14 +302,21 @@ class PatientSummaryEffectHandler @AssistedInject constructor(
302302
}
303303
}
304304

305-
private fun updateSmokingStatus(patientUuid: UUID, isSmoker: MedicalHistoryAnswer) {
305+
private fun updateTobaccoUse(
306+
patientUuid: UUID,
307+
isSmoker: MedicalHistoryAnswer,
308+
isUsingSmokelessTobacco: MedicalHistoryAnswer
309+
) {
306310
val medicalHistory = medicalHistoryRepository.historyForPatientOrDefaultImmediate(
307311
patientUuid = patientUuid,
308312
defaultHistoryUuid = uuidGenerator.v4()
309313
)
310314
val updatedMedicalHistory = medicalHistory.answered(
311315
question = MedicalHistoryQuestion.IsSmoking,
312316
answer = isSmoker
317+
).answered(
318+
question = MedicalHistoryQuestion.IsUsingSmokelessTobacco,
319+
answer = isUsingSmokelessTobacco
313320
)
314321

315322
medicalHistoryRepository.save(updatedMedicalHistory, Instant.now(clock))

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,8 +172,9 @@ data class StatinInfoLoaded(
172172

173173
data object AddTobaccoUseClicked : PatientSummaryEvent()
174174

175-
data class SmokingStatusAnswered(
176-
val isSmoker: Answer
175+
data class TobaccoUseAnswered(
176+
val isSmoker: Answer,
177+
val isUsingSmokelessTobacco: Answer = Answer.Unanswered
177178
) : PatientSummaryEvent()
178179

179180
data object BMIReadingAdded : PatientSummaryEvent()

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

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -714,11 +714,14 @@ class PatientSummaryScreen :
714714
checkedItems[index] = isChecked
715715
}
716716
.setPositiveButton(R.string.tobacco_status_dialog_title_positive_button) { _, _ ->
717-
if (checkedItems[0]) {
718-
hotEvents.onNext(SmokingStatusAnswered(Answer.Yes))
719-
} else {
720-
hotEvents.onNext(SmokingStatusAnswered(Answer.No))
721-
}
717+
val answeredNo = checkedItems[2]
718+
val isSmoker = if (checkedItems[0] && !answeredNo) Answer.Yes else Answer.No
719+
val isUsingSmokeless = if (checkedItems[1] && !answeredNo) Answer.Yes else Answer.No
720+
721+
hotEvents.onNext(TobaccoUseAnswered(
722+
isSmoker = isSmoker,
723+
isUsingSmokelessTobacco = isUsingSmokeless
724+
))
722725
}
723726
.setNegativeButton(R.string.tobacco_status_dialog_title_negative_button, null)
724727
.show()
@@ -738,8 +741,8 @@ class PatientSummaryScreen :
738741
}
739742
.setPositiveButton(R.string.tobacco_status_dialog_title_positive_button) { _, _ ->
740743
when (selectedOption) {
741-
0 -> hotEvents.onNext(SmokingStatusAnswered(Answer.Yes))
742-
1 -> hotEvents.onNext(SmokingStatusAnswered(Answer.No))
744+
0 -> hotEvents.onNext(TobaccoUseAnswered(Answer.Yes))
745+
1 -> hotEvents.onNext(TobaccoUseAnswered(Answer.No))
743746
else -> {}
744747
}
745748
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ class PatientSummaryUpdate(
106106
is CVDRiskUpdated -> dispatch(LoadStatinInfo(model.patientUuid))
107107
is StatinInfoLoaded -> statinInfoLoaded(event, model)
108108
is AddTobaccoUseClicked -> dispatch(ShowTobaccoStatusDialog)
109-
is SmokingStatusAnswered -> dispatch(UpdateSmokingStatus(model.patientUuid, event.isSmoker))
109+
is TobaccoUseAnswered -> dispatch(UpdateTobaccoUse(model.patientUuid, event.isSmoker, event.isUsingSmokelessTobacco))
110110
is BMIReadingAdded -> dispatch(CalculateNonLabBasedCVDRisk(model.patientSummaryProfile!!.patient))
111111
is AddBMIClicked -> dispatch(OpenBMIEntrySheet(model.patientUuid))
112112
is AddCholesterolClicked -> dispatch(OpenCholesterolEntrySheet(model.patientUuid))

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2535,11 +2535,12 @@ class PatientSummaryUpdateTest {
25352535
fun `when smoking is answered, then update the smoking status`() {
25362536
updateSpec
25372537
.given(defaultModel)
2538-
.whenEvent(SmokingStatusAnswered(
2539-
isSmoker = No
2538+
.whenEvent(TobaccoUseAnswered(
2539+
isSmoker = No,
2540+
isUsingSmokelessTobacco = Yes
25402541
))
25412542
.then(assertThatNext(
2542-
hasEffects(UpdateSmokingStatus(patientId = patientUuid, isSmoker = No)),
2543+
hasEffects(UpdateTobaccoUse(patientId = patientUuid, isSmoker = No, isUsingSmokelessTobacco = Yes)),
25432544
hasNoModel()
25442545
))
25452546
}

0 commit comments

Comments
 (0)