Skip to content

Commit 159617f

Browse files
authored
Update UI to include Smokeless tobacco option in medical history questions (#5532)
1 parent ed1b05e commit 159617f

27 files changed

+450
-87
lines changed

app/src/androidTest/java/org/simple/clinic/medicalhistory/MedicalHistoryRepositoryAndroidTest.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ class MedicalHistoryRepositoryAndroidTest {
5454
hasHadKidneyDisease = Yes,
5555
hasDiabetes = No,
5656
isSmoking = No,
57+
isUsingSmokelessTobacco = No,
5758
)
5859

5960
repository.save(

app/src/main/java/org/simple/clinic/medicalhistory/MedicalHistory.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import org.simple.clinic.medicalhistory.MedicalHistoryQuestion.HasHadAStroke
2222
import org.simple.clinic.medicalhistory.MedicalHistoryQuestion.IsOnDiabetesTreatment
2323
import org.simple.clinic.medicalhistory.MedicalHistoryQuestion.IsOnHypertensionTreatment
2424
import org.simple.clinic.medicalhistory.MedicalHistoryQuestion.IsSmoking
25+
import org.simple.clinic.medicalhistory.MedicalHistoryQuestion.IsUsingSmokelessTobacco
2526
import org.simple.clinic.patient.PatientUuid
2627
import org.simple.clinic.patient.SyncStatus
2728
import java.time.Instant
@@ -91,6 +92,7 @@ data class MedicalHistory(
9192
is IsOnHypertensionTreatment -> copy(isOnHypertensionTreatment = answer)
9293
IsOnDiabetesTreatment -> copy(isOnDiabetesTreatment = answer)
9394
IsSmoking -> copy(isSmoking = answer)
95+
IsUsingSmokelessTobacco -> copy(isUsingSmokelessTobacco = answer)
9496
}
9597
}
9698

app/src/main/java/org/simple/clinic/medicalhistory/MedicalHistoryQuestion.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,6 @@ sealed class MedicalHistoryQuestion(
2222
)
2323

2424
object IsOnDiabetesTreatment : MedicalHistoryQuestion(R.string.medicalhistory_question_is_on_diabetes_treatment)
25-
data object IsSmoking : MedicalHistoryQuestion(R.string.medicalhistory_question_is_current_smoker)
25+
data object IsSmoking : MedicalHistoryQuestion(R.string.medicalhistory_question_is_smoking)
26+
data object IsUsingSmokelessTobacco : MedicalHistoryQuestion(R.string.medicalhistory_question_is_using_smokeless_tobacco)
2627
}

app/src/main/java/org/simple/clinic/medicalhistory/MedicalHistoryRepository.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ class MedicalHistoryRepository @Inject constructor(
101101
hasHadKidneyDisease = historyEntry.hasHadKidneyDisease,
102102
diagnosedWithDiabetes = historyEntry.hasDiabetes,
103103
isSmoking = historyEntry.isSmoking,
104-
isUsingSmokelessTobacco = Unanswered,
104+
isUsingSmokelessTobacco = historyEntry.isUsingSmokelessTobacco,
105105
cholesterol = null,
106106
syncStatus = SyncStatus.PENDING,
107107
createdAt = Instant.now(utcClock),

app/src/main/java/org/simple/clinic/medicalhistory/OngoingMedicalHistoryEntry.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import org.simple.clinic.medicalhistory.MedicalHistoryQuestion.HasHadAStroke
1111
import org.simple.clinic.medicalhistory.MedicalHistoryQuestion.IsOnDiabetesTreatment
1212
import org.simple.clinic.medicalhistory.MedicalHistoryQuestion.IsOnHypertensionTreatment
1313
import org.simple.clinic.medicalhistory.MedicalHistoryQuestion.IsSmoking
14+
import org.simple.clinic.medicalhistory.MedicalHistoryQuestion.IsUsingSmokelessTobacco
1415

1516
@Parcelize
1617
data class OngoingMedicalHistoryEntry(
@@ -22,6 +23,7 @@ data class OngoingMedicalHistoryEntry(
2223
val isOnDiabetesTreatment: Answer = Unanswered,
2324
val hasDiabetes: Answer = Unanswered,
2425
val isSmoking: Answer = Unanswered,
26+
val isUsingSmokelessTobacco: Answer = Unanswered,
2527
) : Parcelable {
2628

2729
fun answerChanged(question: MedicalHistoryQuestion, answer: Answer): OngoingMedicalHistoryEntry {
@@ -34,6 +36,7 @@ data class OngoingMedicalHistoryEntry(
3436
is IsOnHypertensionTreatment -> copy(isOnHypertensionTreatment = answer)
3537
IsOnDiabetesTreatment -> copy(isOnDiabetesTreatment = answer)
3638
IsSmoking -> copy(isSmoking = answer)
39+
IsUsingSmokelessTobacco -> copy(isUsingSmokelessTobacco = answer)
3740
}
3841
}
3942
}

app/src/main/java/org/simple/clinic/medicalhistory/newentry/NewMedicalHistoryModel.kt

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ data class NewMedicalHistoryModel(
2121
val nextButtonState: ButtonState?,
2222
val hasShownChangeDiagnosisError: Boolean,
2323
val showIsSmokingQuestion: Boolean,
24+
val showSmokelessTobaccoQuestion: Boolean,
2425
) : Parcelable {
2526

2627
val hasLoadedPatientEntry: Boolean
@@ -72,14 +73,19 @@ data class NewMedicalHistoryModel(
7273
get() = facilityDiabetesManagementEnabled && !hasShownChangeDiagnosisError && hasNoHypertension && hasNoDiabetes
7374

7475
companion object {
75-
fun default(country: Country, showIsSmokingQuestion: Boolean): NewMedicalHistoryModel = NewMedicalHistoryModel(
76+
fun default(
77+
country: Country,
78+
showIsSmokingQuestion: Boolean,
79+
showSmokelessTobaccoQuestion: Boolean
80+
): NewMedicalHistoryModel = NewMedicalHistoryModel(
7681
country = country,
7782
ongoingPatientEntry = null,
7883
ongoingMedicalHistoryEntry = OngoingMedicalHistoryEntry(),
7984
currentFacility = null,
8085
nextButtonState = null,
8186
hasShownChangeDiagnosisError = false,
82-
showIsSmokingQuestion = showIsSmokingQuestion
87+
showIsSmokingQuestion = showIsSmokingQuestion,
88+
showSmokelessTobaccoQuestion = showSmokelessTobaccoQuestion
8389
)
8490
}
8591

app/src/main/java/org/simple/clinic/medicalhistory/newentry/NewMedicalHistoryScreen.kt

Lines changed: 62 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,15 @@ import android.view.View.GONE
88
import android.view.View.VISIBLE
99
import android.view.ViewGroup
1010
import androidx.appcompat.app.AppCompatActivity
11+
import androidx.compose.foundation.layout.Column
12+
import androidx.compose.foundation.layout.fillMaxWidth
13+
import androidx.compose.foundation.layout.padding
14+
import androidx.compose.runtime.getValue
15+
import androidx.compose.runtime.mutableStateOf
16+
import androidx.compose.runtime.setValue
17+
import androidx.compose.ui.Modifier
18+
import androidx.compose.ui.platform.ViewCompositionStrategy
19+
import androidx.compose.ui.res.dimensionResource
1120
import com.google.android.material.dialog.MaterialAlertDialogBuilder
1221
import com.jakewharton.rxbinding3.view.clicks
1322
import com.spotify.mobius.functions.Consumer
@@ -19,6 +28,7 @@ import kotlinx.parcelize.Parcelize
1928
import org.simple.clinic.R
2029
import org.simple.clinic.ReportAnalyticsEvents
2130
import org.simple.clinic.appconfig.Country
31+
import org.simple.clinic.common.ui.theme.SimpleTheme
2232
import org.simple.clinic.databinding.ScreenNewMedicalHistoryBinding
2333
import org.simple.clinic.di.injector
2434
import org.simple.clinic.feature.Feature
@@ -32,10 +42,10 @@ import org.simple.clinic.medicalhistory.MedicalHistoryQuestion.HasHadAKidneyDise
3242
import org.simple.clinic.medicalhistory.MedicalHistoryQuestion.HasHadAStroke
3343
import org.simple.clinic.medicalhistory.MedicalHistoryQuestion.IsOnDiabetesTreatment
3444
import org.simple.clinic.medicalhistory.MedicalHistoryQuestion.IsOnHypertensionTreatment
35-
import org.simple.clinic.medicalhistory.MedicalHistoryQuestion.IsSmoking
3645
import org.simple.clinic.medicalhistory.SelectDiagnosisErrorDialog
3746
import org.simple.clinic.medicalhistory.SelectOngoingDiabetesTreatmentErrorDialog
3847
import org.simple.clinic.medicalhistory.SelectOngoingHypertensionTreatmentErrorDialog
48+
import org.simple.clinic.medicalhistory.ui.TobaccoQuestion
3949
import org.simple.clinic.navigation.v2.Router
4050
import org.simple.clinic.navigation.v2.ScreenKey
4151
import org.simple.clinic.navigation.v2.fragments.BaseScreen
@@ -100,27 +110,27 @@ class NewMedicalHistoryScreen : BaseScreen<
100110
private val diabetesQuestionView
101111
get() = binding.diabetesQuestionView
102112

103-
private val scrollView
104-
get() = binding.scrollView
105-
106113
private val hypertensionDiagnosis
107114
get() = binding.hypertensionDiagnosis
108115

109116
private val diabetesDiagnosis
110117
get() = binding.diabetesDiagnosis
111118

112-
private val currentSmokerQuestionContainer
113-
get() = binding.currentSmokerQuestionContainer
119+
private var showSmokerQuestion by mutableStateOf(false)
120+
private var isSmoking by mutableStateOf<Answer>(Answer.Unanswered)
121+
private var showSmokelessTobaccoQuestion by mutableStateOf(false)
122+
private var isUsingSmokelessTobacco by mutableStateOf<Answer>(Answer.Unanswered)
114123

115-
private val currentSmokerQuestionView
116-
get() = binding.currentSmokerQuestionView
124+
private val composeView
125+
get() = binding.composeView
117126

118127
private val hotEvents: Subject<NewMedicalHistoryEvent> = PublishSubject.create()
119128

120129
override fun defaultModel() = NewMedicalHistoryModel.default(
121130
country = country,
122131
showIsSmokingQuestion = features.isEnabled(Feature.NonLabBasedStatinNudge) ||
123-
features.isEnabled(Feature.LabBasedStatinNudge)
132+
features.isEnabled(Feature.LabBasedStatinNudge),
133+
showSmokelessTobaccoQuestion = country.isoCountryCode != Country.ETHIOPIA
124134
)
125135

126136
override fun bindView(
@@ -164,6 +174,31 @@ class NewMedicalHistoryScreen : BaseScreen<
164174
toolbar.setNavigationOnClickListener {
165175
router.pop()
166176
}
177+
178+
composeView.apply {
179+
setViewCompositionStrategy(
180+
ViewCompositionStrategy.DisposeOnViewTreeLifecycleDestroyed
181+
)
182+
setContent {
183+
SimpleTheme {
184+
Column(
185+
modifier = Modifier
186+
.fillMaxWidth()
187+
.padding(dimensionResource(R.dimen.spacing_8)),
188+
) {
189+
if (showSmokerQuestion) {
190+
TobaccoQuestion(
191+
isSmokingAnswer = isSmoking,
192+
isUsingSmokelessTobaccoAnswer = isUsingSmokelessTobacco,
193+
showSmokelessTobaccoQuestion = showSmokelessTobaccoQuestion,
194+
) { question, answer ->
195+
hotEvents.onNext(NewMedicalHistoryAnswerToggled(question, answer))
196+
}
197+
}
198+
}
199+
}
200+
}
201+
}
167202
}
168203

169204
private fun saveClicks() = nextButton
@@ -184,13 +219,20 @@ class NewMedicalHistoryScreen : BaseScreen<
184219
HasHadAStroke -> strokeQuestionView
185220
HasHadAKidneyDisease -> kidneyDiseaseQuestionView
186221
DiagnosedWithDiabetes -> diabetesQuestionView
187-
IsSmoking -> currentSmokerQuestionView
188222
else -> null
189223
}
190224

191225
view?.render(question, answer) { questionForView, newAnswer ->
192226
hotEvents.onNext(NewMedicalHistoryAnswerToggled(questionForView, newAnswer))
193227
}
228+
229+
if (question == MedicalHistoryQuestion.IsSmoking) {
230+
isSmoking = answer
231+
}
232+
233+
if (question == MedicalHistoryQuestion.IsUsingSmokelessTobacco) {
234+
isUsingSmokelessTobacco = answer
235+
}
194236
}
195237

196238
override fun showDiabetesDiagnosisView() {
@@ -268,12 +310,19 @@ class NewMedicalHistoryScreen : BaseScreen<
268310
}
269311

270312
override fun showCurrentSmokerQuestion() {
271-
currentSmokerQuestionContainer.visibility = VISIBLE
272-
currentSmokerQuestionView.hideDivider()
313+
showSmokerQuestion = true
273314
}
274315

275316
override fun hideCurrentSmokerQuestion() {
276-
currentSmokerQuestionContainer.visibility = GONE
317+
showSmokerQuestion = false
318+
}
319+
320+
override fun showSmokelessTobaccoQuestion() {
321+
showSmokelessTobaccoQuestion = true
322+
}
323+
324+
override fun hideSmokelessTobaccoQuestion() {
325+
showSmokelessTobaccoQuestion = false
277326
}
278327

279328
override fun showOngoingHypertensionTreatmentErrorDialog() {

app/src/main/java/org/simple/clinic/medicalhistory/newentry/NewMedicalHistoryUi.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,6 @@ interface NewMedicalHistoryUi {
1919
fun hideDiabetesTreatmentQuestion()
2020
fun showCurrentSmokerQuestion()
2121
fun hideCurrentSmokerQuestion()
22+
fun showSmokelessTobaccoQuestion()
23+
fun hideSmokelessTobaccoQuestion()
2224
}

app/src/main/java/org/simple/clinic/medicalhistory/newentry/NewMedicalHistoryUiRenderer.kt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import org.simple.clinic.medicalhistory.MedicalHistoryQuestion.HasHadAHeartAttac
66
import org.simple.clinic.medicalhistory.MedicalHistoryQuestion.HasHadAKidneyDisease
77
import org.simple.clinic.medicalhistory.MedicalHistoryQuestion.HasHadAStroke
88
import org.simple.clinic.medicalhistory.MedicalHistoryQuestion.IsSmoking
9+
import org.simple.clinic.medicalhistory.MedicalHistoryQuestion.IsUsingSmokelessTobacco
910
import org.simple.clinic.mobius.ViewRenderer
1011

1112
class NewMedicalHistoryUiRenderer(
@@ -26,6 +27,7 @@ class NewMedicalHistoryUiRenderer(
2627
}
2728

2829
renderSmokingQuestion(model)
30+
renderSmokelessTobaccoQuestion(model)
2931

3032
renderNextButton(model)
3133
}
@@ -82,6 +84,15 @@ class NewMedicalHistoryUiRenderer(
8284
}
8385
}
8486

87+
private fun renderSmokelessTobaccoQuestion(model: NewMedicalHistoryModel) {
88+
if (model.showSmokelessTobaccoQuestion) {
89+
ui.showSmokelessTobaccoQuestion()
90+
ui.renderAnswerForQuestion(IsUsingSmokelessTobacco, model.ongoingMedicalHistoryEntry.isUsingSmokelessTobacco)
91+
} else {
92+
ui.hideSmokelessTobaccoQuestion()
93+
}
94+
}
95+
8596
private fun renderNextButton(model: NewMedicalHistoryModel) {
8697
if (model.registeringPatient) {
8798
ui.showNextButtonProgress()

0 commit comments

Comments
 (0)