Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@

### Internal
- Bump AGP to v8.12.2
- Bump Lint to v31.12.0
- Bump Lint to v31.13.0
- Bump Kotlin to v2.2.0
- Bump KSP to v2.2.0-2.0.2
- Bump dagger to v2.57
- Bump dagger to v2.57.1
- Bump okhttp to v5.1.0
- Bump retrofit to v3.0.0
- Bump sqlcipher to v4.10.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import android.view.View.GONE
import android.view.View.VISIBLE
import android.view.ViewGroup
import androidx.appcompat.app.AppCompatActivity
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
Expand Down Expand Up @@ -37,14 +38,13 @@ import org.simple.clinic.medicalhistory.Answer
import org.simple.clinic.medicalhistory.MedicalHistoryQuestion
import org.simple.clinic.medicalhistory.MedicalHistoryQuestion.DiagnosedWithDiabetes
import org.simple.clinic.medicalhistory.MedicalHistoryQuestion.DiagnosedWithHypertension
import org.simple.clinic.medicalhistory.MedicalHistoryQuestion.HasHadAHeartAttack
import org.simple.clinic.medicalhistory.MedicalHistoryQuestion.HasHadAKidneyDisease
import org.simple.clinic.medicalhistory.MedicalHistoryQuestion.HasHadAStroke
import org.simple.clinic.medicalhistory.MedicalHistoryQuestion.IsOnDiabetesTreatment
import org.simple.clinic.medicalhistory.MedicalHistoryQuestion.IsOnHypertensionTreatment
import org.simple.clinic.medicalhistory.OngoingMedicalHistoryEntry
import org.simple.clinic.medicalhistory.SelectDiagnosisErrorDialog
import org.simple.clinic.medicalhistory.SelectOngoingDiabetesTreatmentErrorDialog
import org.simple.clinic.medicalhistory.SelectOngoingHypertensionTreatmentErrorDialog
import org.simple.clinic.medicalhistory.ui.HistoryContainer
import org.simple.clinic.medicalhistory.ui.TobaccoQuestion
import org.simple.clinic.navigation.v2.Router
import org.simple.clinic.navigation.v2.ScreenKey
Expand Down Expand Up @@ -98,28 +98,16 @@ class NewMedicalHistoryScreen : BaseScreen<
private val nextButton
get() = binding.nextButton

private val heartAttackQuestionView
get() = binding.heartAttackQuestionView

private val strokeQuestionView
get() = binding.strokeQuestionView

private val kidneyDiseaseQuestionView
get() = binding.kidneyDiseaseQuestionView

private val diabetesQuestionView
get() = binding.diabetesQuestionView

private val hypertensionDiagnosis
get() = binding.hypertensionDiagnosis

private val diabetesDiagnosis
get() = binding.diabetesDiagnosis

private var showSmokerQuestion by mutableStateOf(false)
private var isSmoking by mutableStateOf<Answer>(Answer.Unanswered)
private var showSmokelessTobaccoQuestion by mutableStateOf(false)
private var isUsingSmokelessTobacco by mutableStateOf<Answer>(Answer.Unanswered)
private var showDiabetesQuestion by mutableStateOf(false)
private var ongoingMedicalHistoryEntry by mutableStateOf<OngoingMedicalHistoryEntry?>(null)

private val composeView
get() = binding.composeView
Expand Down Expand Up @@ -183,13 +171,23 @@ class NewMedicalHistoryScreen : BaseScreen<
SimpleTheme {
Column(
modifier = Modifier
.fillMaxWidth()
.padding(dimensionResource(R.dimen.spacing_8)),
.fillMaxWidth()
.padding(dimensionResource(R.dimen.spacing_8)),
verticalArrangement = Arrangement.spacedBy(dimensionResource(R.dimen.spacing_8))
) {
HistoryContainer(
heartAttackAnswer = ongoingMedicalHistoryEntry?.hasHadHeartAttack,
strokeAnswer = ongoingMedicalHistoryEntry?.hasHadStroke,
kidneyAnswer = ongoingMedicalHistoryEntry?.hasHadKidneyDisease,
diabetesAnswer = ongoingMedicalHistoryEntry?.hasDiabetes,
showDiabetesQuestion = showDiabetesQuestion,
) { question, answer ->
hotEvents.onNext(NewMedicalHistoryAnswerToggled(question, answer))
}
if (showSmokerQuestion) {
TobaccoQuestion(
isSmokingAnswer = isSmoking,
isUsingSmokelessTobaccoAnswer = isUsingSmokelessTobacco,
isSmokingAnswer = ongoingMedicalHistoryEntry?.isSmoking,
isUsingSmokelessTobaccoAnswer = ongoingMedicalHistoryEntry?.isUsingSmokelessTobacco,
showSmokelessTobaccoQuestion = showSmokelessTobaccoQuestion,
) { question, answer ->
hotEvents.onNext(NewMedicalHistoryAnswerToggled(question, answer))
Expand All @@ -213,26 +211,8 @@ class NewMedicalHistoryScreen : BaseScreen<
toolbar.title = patientName
}

override fun renderAnswerForQuestion(question: MedicalHistoryQuestion, answer: Answer) {
val view = when (question) {
HasHadAHeartAttack -> heartAttackQuestionView
HasHadAStroke -> strokeQuestionView
HasHadAKidneyDisease -> kidneyDiseaseQuestionView
DiagnosedWithDiabetes -> diabetesQuestionView
else -> null
}

view?.render(question, answer) { questionForView, newAnswer ->
hotEvents.onNext(NewMedicalHistoryAnswerToggled(questionForView, newAnswer))
}

if (question == MedicalHistoryQuestion.IsSmoking) {
isSmoking = answer
}

if (question == MedicalHistoryQuestion.IsUsingSmokelessTobacco) {
isUsingSmokelessTobacco = answer
}
override fun populateOngoingMedicalHistoryEntry(ongoingMedicalHistoryEntry: OngoingMedicalHistoryEntry) {
this.ongoingMedicalHistoryEntry = ongoingMedicalHistoryEntry
}

override fun showDiabetesDiagnosisView() {
Expand All @@ -244,14 +224,11 @@ class NewMedicalHistoryScreen : BaseScreen<
}

override fun hideDiabetesHistorySection() {
diabetesQuestionView.visibility = GONE
kidneyDiseaseQuestionView.hideDivider()
showDiabetesQuestion = false
}

override fun showDiabetesHistorySection() {
diabetesQuestionView.visibility = VISIBLE
kidneyDiseaseQuestionView.showDivider()
diabetesQuestionView.hideDivider()
showDiabetesQuestion = true
}

override fun renderDiagnosisAnswer(question: MedicalHistoryQuestion, answer: Answer) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ package org.simple.clinic.medicalhistory.newentry

import org.simple.clinic.medicalhistory.Answer
import org.simple.clinic.medicalhistory.MedicalHistoryQuestion
import org.simple.clinic.medicalhistory.OngoingMedicalHistoryEntry

interface NewMedicalHistoryUi {
fun setPatientName(patientName: String)
fun renderAnswerForQuestion(question: MedicalHistoryQuestion, answer: Answer)
fun populateOngoingMedicalHistoryEntry(ongoingMedicalHistoryEntry: OngoingMedicalHistoryEntry)
fun renderDiagnosisAnswer(question: MedicalHistoryQuestion, answer: Answer)
fun showDiabetesDiagnosisView()
fun hideDiabetesDiagnosisView()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,6 @@ package org.simple.clinic.medicalhistory.newentry

import org.simple.clinic.medicalhistory.MedicalHistoryQuestion.DiagnosedWithDiabetes
import org.simple.clinic.medicalhistory.MedicalHistoryQuestion.DiagnosedWithHypertension
import org.simple.clinic.medicalhistory.MedicalHistoryQuestion.HasHadAHeartAttack
import org.simple.clinic.medicalhistory.MedicalHistoryQuestion.HasHadAKidneyDisease
import org.simple.clinic.medicalhistory.MedicalHistoryQuestion.HasHadAStroke
import org.simple.clinic.medicalhistory.MedicalHistoryQuestion.IsSmoking
import org.simple.clinic.medicalhistory.MedicalHistoryQuestion.IsUsingSmokelessTobacco
import org.simple.clinic.mobius.ViewRenderer

class NewMedicalHistoryUiRenderer(
Expand All @@ -23,7 +18,7 @@ class NewMedicalHistoryUiRenderer(
if (model.hasLoadedCurrentFacility && model.facilityDiabetesManagementEnabled) {
renderDiabetesManagementEnabled(model)
} else {
renderDiabetesManagementDisabled(model)
renderDiabetesManagementDisabled()
}

renderSmokingQuestion(model)
Expand All @@ -38,12 +33,10 @@ class NewMedicalHistoryUiRenderer(

private fun renderMedicalHistoryQuestions(model: NewMedicalHistoryModel) {
with(model.ongoingMedicalHistoryEntry) {
ui.renderAnswerForQuestion(HasHadAHeartAttack, hasHadHeartAttack)
ui.renderAnswerForQuestion(HasHadAKidneyDisease, hasHadKidneyDisease)
ui.renderAnswerForQuestion(HasHadAStroke, hasHadStroke)
ui.renderDiagnosisAnswer(DiagnosedWithHypertension, diagnosedWithHypertension)
renderHypertensionTreatmentQuestion(model)
}
ui.populateOngoingMedicalHistoryEntry(model.ongoingMedicalHistoryEntry)
}

private fun renderHypertensionTreatmentQuestion(model: NewMedicalHistoryModel) {
Expand All @@ -69,16 +62,14 @@ class NewMedicalHistoryUiRenderer(
}
}

private fun renderDiabetesManagementDisabled(model: NewMedicalHistoryModel) {
private fun renderDiabetesManagementDisabled() {
ui.hideDiabetesDiagnosisView()
ui.showDiabetesHistorySection()
ui.renderAnswerForQuestion(DiagnosedWithDiabetes, model.ongoingMedicalHistoryEntry.hasDiabetes)
}

private fun renderSmokingQuestion(model: NewMedicalHistoryModel) {
if (model.showIsSmokingQuestion) {
ui.showCurrentSmokerQuestion()
ui.renderAnswerForQuestion(IsSmoking, model.ongoingMedicalHistoryEntry.isSmoking)
} else {
ui.hideCurrentSmokerQuestion()
}
Expand All @@ -87,7 +78,6 @@ class NewMedicalHistoryUiRenderer(
private fun renderSmokelessTobaccoQuestion(model: NewMedicalHistoryModel) {
if (model.showSmokelessTobaccoQuestion) {
ui.showSmokelessTobaccoQuestion()
ui.renderAnswerForQuestion(IsUsingSmokelessTobacco, model.ongoingMedicalHistoryEntry.isUsingSmokelessTobacco)
} else {
ui.hideSmokelessTobaccoQuestion()
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
package org.simple.clinic.medicalhistory.ui

import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.requiredHeight
import androidx.compose.material.Card
import androidx.compose.material.MaterialTheme
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.dimensionResource
import androidx.compose.ui.res.stringResource
import org.simple.clinic.R
import org.simple.clinic.common.ui.theme.SimpleTheme
import org.simple.clinic.medicalhistory.Answer
import org.simple.clinic.medicalhistory.MedicalHistoryQuestion

@Composable
fun HistoryContainer(
heartAttackAnswer: Answer?,
strokeAnswer: Answer?,
kidneyAnswer: Answer?,
diabetesAnswer: Answer?,
showDiabetesQuestion: Boolean,
modifier: Modifier = Modifier,
onAnswerChange: (MedicalHistoryQuestion, Answer) -> Unit,
) {
Card(modifier = modifier) {
Column(
modifier = Modifier
.padding(horizontal = dimensionResource(R.dimen.spacing_16))
.padding(
top = dimensionResource(R.dimen.spacing_16),
bottom = dimensionResource(R.dimen.spacing_4)
)
) {
Text(
text = stringResource(R.string.medicalhistorysummaryview_history),
style = SimpleTheme.typography.subtitle1Medium,
color = MaterialTheme.colors.onSurface,
)

Spacer(Modifier.requiredHeight(dimensionResource(R.dimen.spacing_4)))

MedicalHistoryQuestionItem(
question = MedicalHistoryQuestion.HasHadAHeartAttack,
selectedAnswer = heartAttackAnswer,
showDivider = true,
) {
onAnswerChange(MedicalHistoryQuestion.HasHadAHeartAttack, it)
}

MedicalHistoryQuestionItem(
question = MedicalHistoryQuestion.HasHadAStroke,
selectedAnswer = strokeAnswer,
showDivider = true,
) {
onAnswerChange(MedicalHistoryQuestion.HasHadAStroke, it)
}

MedicalHistoryQuestionItem(
question = MedicalHistoryQuestion.HasHadAKidneyDisease,
selectedAnswer = kidneyAnswer,
showDivider = showDiabetesQuestion,
) {
onAnswerChange(MedicalHistoryQuestion.HasHadAKidneyDisease, it)
}

if (showDiabetesQuestion) {
MedicalHistoryQuestionItem(
question = MedicalHistoryQuestion.DiagnosedWithDiabetes,
selectedAnswer = diabetesAnswer,
showDivider = false,
) {
onAnswerChange(MedicalHistoryQuestion.DiagnosedWithDiabetes, it)
}
}
}
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import org.simple.clinic.R
import org.simple.clinic.common.ui.theme.SimpleTheme
import org.simple.clinic.medicalhistory.Answer
import org.simple.clinic.medicalhistory.MedicalHistoryQuestion
import org.simple.clinic.medicalhistory.ui.HistoryContainer
import org.simple.clinic.medicalhistory.ui.MedicalHistoryQuestionItem
import org.simple.clinic.medicalhistory.ui.TobaccoQuestion

Expand Down Expand Up @@ -56,7 +57,7 @@ fun MedicalHistorySummary(
strokeAnswer = strokeAnswer,
kidneyAnswer = kidneyAnswer,
diabetesAnswer = diabetesAnswer,
diabetesManagementEnabled = diabetesManagementEnabled,
showDiabetesQuestion = !diabetesManagementEnabled,
onAnswerChange = onAnswerChange
)

Expand All @@ -71,70 +72,6 @@ fun MedicalHistorySummary(
}
}

@Composable
fun HistoryContainer(
heartAttackAnswer: Answer?,
strokeAnswer: Answer?,
kidneyAnswer: Answer?,
diabetesAnswer: Answer?,
diabetesManagementEnabled: Boolean,
modifier: Modifier = Modifier,
onAnswerChange: (MedicalHistoryQuestion, Answer) -> Unit,
) {
Card(modifier = modifier) {
Column(
modifier = Modifier
.padding(horizontal = dimensionResource(R.dimen.spacing_16))
.padding(
top = dimensionResource(R.dimen.spacing_16),
bottom = dimensionResource(R.dimen.spacing_4)
)
) {
Text(
text = stringResource(R.string.medicalhistorysummaryview_history),
style = SimpleTheme.typography.subtitle1Medium,
color = MaterialTheme.colors.onSurface,
)

Spacer(Modifier.requiredHeight(dimensionResource(R.dimen.spacing_4)))

MedicalHistoryQuestionItem(
question = MedicalHistoryQuestion.HasHadAHeartAttack,
selectedAnswer = heartAttackAnswer,
showDivider = true,
) {
onAnswerChange(MedicalHistoryQuestion.HasHadAHeartAttack, it)
}

MedicalHistoryQuestionItem(
question = MedicalHistoryQuestion.HasHadAStroke,
selectedAnswer = strokeAnswer,
showDivider = true,
) {
onAnswerChange(MedicalHistoryQuestion.HasHadAStroke, it)
}

MedicalHistoryQuestionItem(
question = MedicalHistoryQuestion.HasHadAKidneyDisease,
selectedAnswer = kidneyAnswer,
showDivider = !diabetesManagementEnabled,
) {
onAnswerChange(MedicalHistoryQuestion.HasHadAKidneyDisease, it)
}

if (!diabetesManagementEnabled) {
MedicalHistoryQuestionItem(
question = MedicalHistoryQuestion.DiagnosedWithDiabetes,
selectedAnswer = diabetesAnswer,
showDivider = false,
) {
onAnswerChange(MedicalHistoryQuestion.DiagnosedWithDiabetes, it)
}
}
}
}
}

@Composable
private fun DiagnosisContainer(
hypertensionAnswer: Answer?,
Expand Down
Loading
Loading