@@ -4,8 +4,6 @@ import android.content.Context
44import android.os.Bundle
55import android.view.LayoutInflater
66import android.view.View
7- import android.view.View.GONE
8- import android.view.View.VISIBLE
97import android.view.ViewGroup
108import androidx.appcompat.app.AppCompatActivity
119import androidx.compose.foundation.layout.Arrangement
@@ -18,6 +16,7 @@ import androidx.compose.runtime.setValue
1816import androidx.compose.ui.Modifier
1917import androidx.compose.ui.platform.ViewCompositionStrategy
2018import androidx.compose.ui.res.dimensionResource
19+ import androidx.compose.ui.res.stringResource
2120import com.google.android.material.dialog.MaterialAlertDialogBuilder
2221import com.jakewharton.rxbinding3.view.clicks
2322import com.spotify.mobius.functions.Consumer
@@ -35,7 +34,6 @@ import org.simple.clinic.di.injector
3534import org.simple.clinic.feature.Feature
3635import org.simple.clinic.feature.Features
3736import org.simple.clinic.medicalhistory.Answer
38- import org.simple.clinic.medicalhistory.MedicalHistoryQuestion
3937import org.simple.clinic.medicalhistory.MedicalHistoryQuestion.DiagnosedWithDiabetes
4038import org.simple.clinic.medicalhistory.MedicalHistoryQuestion.DiagnosedWithHypertension
4139import org.simple.clinic.medicalhistory.MedicalHistoryQuestion.IsOnDiabetesTreatment
@@ -45,6 +43,7 @@ import org.simple.clinic.medicalhistory.SelectDiagnosisErrorDialog
4543import org.simple.clinic.medicalhistory.SelectOngoingDiabetesTreatmentErrorDialog
4644import org.simple.clinic.medicalhistory.SelectOngoingHypertensionTreatmentErrorDialog
4745import org.simple.clinic.medicalhistory.ui.HistoryContainer
46+ import org.simple.clinic.medicalhistory.ui.MedicalHistoryDiagnosisWithTreatment
4847import org.simple.clinic.medicalhistory.ui.TobaccoQuestion
4948import org.simple.clinic.navigation.v2.Router
5049import org.simple.clinic.navigation.v2.ScreenKey
@@ -98,15 +97,12 @@ class NewMedicalHistoryScreen : BaseScreen<
9897 private val nextButton
9998 get() = binding.nextButton
10099
101- private val hypertensionDiagnosis
102- get() = binding.hypertensionDiagnosis
103-
104- private val diabetesDiagnosis
105- get() = binding.diabetesDiagnosis
106-
107100 private var showSmokerQuestion by mutableStateOf(false )
108101 private var showSmokelessTobaccoQuestion by mutableStateOf(false )
109102 private var showDiabetesQuestion by mutableStateOf(false )
103+ private var showHypertensionTreatmentQuestion by mutableStateOf(false )
104+ private var showDiabetesTreatmentQuestion by mutableStateOf(false )
105+ private var showDiabetesDiagnosis by mutableStateOf(false )
110106 private var ongoingMedicalHistoryEntry by mutableStateOf<OngoingMedicalHistoryEntry ?>(null )
111107
112108 private val composeView
@@ -175,6 +171,28 @@ class NewMedicalHistoryScreen : BaseScreen<
175171 .padding(dimensionResource(R .dimen.spacing_8)),
176172 verticalArrangement = Arrangement .spacedBy(dimensionResource(R .dimen.spacing_8))
177173 ) {
174+ MedicalHistoryDiagnosisWithTreatment (
175+ diagnosisLabel = stringResource(R .string.medicalhistory_diagnosis_hypertension_required),
176+ diagnosisQuestion = DiagnosedWithHypertension ,
177+ diagnosisAnswer = ongoingMedicalHistoryEntry?.diagnosedWithHypertension,
178+ treatmentQuestion = IsOnHypertensionTreatment (country.isoCountryCode),
179+ treatmentAnswer = ongoingMedicalHistoryEntry?.isOnHypertensionTreatment,
180+ showTreatmentQuestion = showHypertensionTreatmentQuestion
181+ ) { question, answer ->
182+ hotEvents.onNext(NewMedicalHistoryAnswerToggled (question, answer))
183+ }
184+ if (showDiabetesDiagnosis) {
185+ MedicalHistoryDiagnosisWithTreatment (
186+ diagnosisLabel = stringResource(R .string.medicalhistory_diagnosis_diabetes_required),
187+ diagnosisQuestion = DiagnosedWithDiabetes ,
188+ diagnosisAnswer = ongoingMedicalHistoryEntry?.hasDiabetes,
189+ treatmentQuestion = IsOnDiabetesTreatment ,
190+ treatmentAnswer = ongoingMedicalHistoryEntry?.isOnDiabetesTreatment,
191+ showTreatmentQuestion = showDiabetesTreatmentQuestion
192+ ) { question, answer ->
193+ hotEvents.onNext(NewMedicalHistoryAnswerToggled (question, answer))
194+ }
195+ }
178196 HistoryContainer (
179197 heartAttackAnswer = ongoingMedicalHistoryEntry?.hasHadHeartAttack,
180198 strokeAnswer = ongoingMedicalHistoryEntry?.hasHadStroke,
@@ -216,11 +234,11 @@ class NewMedicalHistoryScreen : BaseScreen<
216234 }
217235
218236 override fun showDiabetesDiagnosisView () {
219- diabetesDiagnosis.visibility = VISIBLE
237+ showDiabetesDiagnosis = true
220238 }
221239
222240 override fun hideDiabetesDiagnosisView () {
223- diabetesDiagnosis.visibility = GONE
241+ showDiabetesDiagnosis = false
224242 }
225243
226244 override fun hideDiabetesHistorySection () {
@@ -231,24 +249,6 @@ class NewMedicalHistoryScreen : BaseScreen<
231249 showDiabetesQuestion = true
232250 }
233251
234- override fun renderDiagnosisAnswer (question : MedicalHistoryQuestion , answer : Answer ) {
235- val view = when (question) {
236- DiagnosedWithHypertension -> hypertensionDiagnosis
237- DiagnosedWithDiabetes -> diabetesDiagnosis
238- else -> null
239- }
240-
241- val label = when (question) {
242- DiagnosedWithHypertension -> R .string.medicalhistory_diagnosis_hypertension_required
243- DiagnosedWithDiabetes -> R .string.medicalhistory_diagnosis_diabetes_required
244- else -> question.questionRes
245- }
246-
247- view?.renderDiagnosis(label, question, answer) { questionForView, newAnswer ->
248- hotEvents.onNext(NewMedicalHistoryAnswerToggled (questionForView, newAnswer))
249- }
250- }
251-
252252 override fun showNextButtonProgress () {
253253 nextButton.setButtonState(InProgress )
254254 }
@@ -258,32 +258,19 @@ class NewMedicalHistoryScreen : BaseScreen<
258258 }
259259
260260 override fun showHypertensionTreatmentQuestion (answer : Answer ) {
261- hypertensionDiagnosis.renderTreatmentQuestion(
262- question = IsOnHypertensionTreatment (country.isoCountryCode),
263- answer = answer
264- ) { questionForView, newAnswer ->
265- hotEvents.onNext(NewMedicalHistoryAnswerToggled (questionForView, newAnswer))
266- }
267-
268- hypertensionDiagnosis.showTreatmentQuestion()
261+ showHypertensionTreatmentQuestion = true
269262 }
270263
271264 override fun hideHypertensionTreatmentQuestion () {
272- hypertensionDiagnosis.hideTreatmentQuestion()
273- hypertensionDiagnosis.clearTreatmentChipGroup()
265+ showHypertensionTreatmentQuestion = false
274266 }
275267
276268 override fun showDiabetesTreatmentQuestion (answer : Answer ) {
277- diabetesDiagnosis.renderTreatmentQuestion(IsOnDiabetesTreatment , answer) { questionForView, newAnswer ->
278- hotEvents.onNext(NewMedicalHistoryAnswerToggled (questionForView, newAnswer))
279- }
280-
281- diabetesDiagnosis.showTreatmentQuestion()
269+ showDiabetesTreatmentQuestion = true
282270 }
283271
284272 override fun hideDiabetesTreatmentQuestion () {
285- diabetesDiagnosis.hideTreatmentQuestion()
286- diabetesDiagnosis.clearTreatmentChipGroup()
273+ showDiabetesTreatmentQuestion = false
287274 }
288275
289276 override fun showCurrentSmokerQuestion () {
0 commit comments