From 09691c3245ebf7b7187a2119b10bc3602008a4d8 Mon Sep 17 00:00:00 2001 From: Siddharth Agarwal Date: Fri, 13 Dec 2024 17:48:53 +0530 Subject: [PATCH] Update `StatinNudge` to accept `StatinInfo` --- .../clinic/summary/PatientSummaryScreen.kt | 12 +- .../clinic/summary/PatientSummaryScreenUi.kt | 3 +- .../summary/PatientSummaryViewRenderer.kt | 6 +- .../clinic/summary/compose/StatinNudgeView.kt | 111 +++++++++--------- .../summary/PatientSummaryViewRendererTest.kt | 28 +---- 5 files changed, 67 insertions(+), 93 deletions(-) diff --git a/app/src/main/java/org/simple/clinic/summary/PatientSummaryScreen.kt b/app/src/main/java/org/simple/clinic/summary/PatientSummaryScreen.kt index 68f08ccf53f..45bf8fba13f 100644 --- a/app/src/main/java/org/simple/clinic/summary/PatientSummaryScreen.kt +++ b/app/src/main/java/org/simple/clinic/summary/PatientSummaryScreen.kt @@ -218,7 +218,7 @@ class PatientSummaryScreen : private val additionalEvents = DeferredEventSource() - private var shouldShowStatinNudge by mutableStateOf(false) + private var statinInfo by mutableStateOf(null) override fun defaultModel(): PatientSummaryModel { return PatientSummaryModel.from(screenKey.intention, screenKey.patientUuid) @@ -320,7 +320,7 @@ class PatientSummaryScreen : setContent { SimpleTheme { StatinNudge( - isVisible = shouldShowStatinNudge, + statinInfo = statinInfo, modifier = Modifier.padding(start = 8.dp, end = 8.dp, top = 8.dp) ) } @@ -764,12 +764,8 @@ class PatientSummaryScreen : clinicalDecisionSupportAlertView.visibility = GONE } - override fun showStatinAlert(statinInfo: StatinInfo) { - shouldShowStatinNudge = true - } - - override fun hideStatinAlert() { - shouldShowStatinNudge = false + override fun updateStatinAlert(statinInfo: StatinInfo) { + this.statinInfo = statinInfo } private fun showWithAnimation(view: View) { diff --git a/app/src/main/java/org/simple/clinic/summary/PatientSummaryScreenUi.kt b/app/src/main/java/org/simple/clinic/summary/PatientSummaryScreenUi.kt index 42db607609b..d04f3f155c4 100644 --- a/app/src/main/java/org/simple/clinic/summary/PatientSummaryScreenUi.kt +++ b/app/src/main/java/org/simple/clinic/summary/PatientSummaryScreenUi.kt @@ -20,6 +20,5 @@ interface PatientSummaryScreenUi { fun showClinicalDecisionSupportAlert() fun hideClinicalDecisionSupportAlert() fun hideClinicalDecisionSupportAlertWithoutAnimation() - fun showStatinAlert(statinInfo: StatinInfo) - fun hideStatinAlert() + fun updateStatinAlert(statinInfo: StatinInfo) } diff --git a/app/src/main/java/org/simple/clinic/summary/PatientSummaryViewRenderer.kt b/app/src/main/java/org/simple/clinic/summary/PatientSummaryViewRenderer.kt index a3ed0d63268..fdcdf9b1066 100644 --- a/app/src/main/java/org/simple/clinic/summary/PatientSummaryViewRenderer.kt +++ b/app/src/main/java/org/simple/clinic/summary/PatientSummaryViewRenderer.kt @@ -152,12 +152,10 @@ class PatientSummaryViewRenderer( private fun renderStatinAlert(model: PatientSummaryModel) { if (model.hasStatinInfoLoaded.not()) return + ui.updateStatinAlert(model.statinInfo!!) - if (model.statinInfo?.canPrescribeStatin == true) { - ui.showStatinAlert(model.statinInfo) + if (model.statinInfo.canPrescribeStatin) { ui.hideClinicalDecisionSupportAlertWithoutAnimation() - } else { - ui.hideStatinAlert() } } } diff --git a/app/src/main/java/org/simple/clinic/summary/compose/StatinNudgeView.kt b/app/src/main/java/org/simple/clinic/summary/compose/StatinNudgeView.kt index 514dd019e69..23c28b3116b 100644 --- a/app/src/main/java/org/simple/clinic/summary/compose/StatinNudgeView.kt +++ b/app/src/main/java/org/simple/clinic/summary/compose/StatinNudgeView.kt @@ -28,58 +28,61 @@ import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.dp import org.simple.clinic.R import org.simple.clinic.common.ui.theme.SimpleTheme +import org.simple.clinic.cvdrisk.StatinInfo import org.simple.clinic.util.toAnnotatedString @Composable fun StatinNudge( - isVisible: Boolean, + statinInfo: StatinInfo?, modifier: Modifier = Modifier ) { - AnimatedVisibility( - visible = isVisible, - enter = expandVertically( - animationSpec = tween(500), - expandFrom = Alignment.Top - ), - exit = shrinkVertically(animationSpec = tween(500)) - ) { - Card( - modifier = modifier + if (statinInfo != null) { + AnimatedVisibility( + visible = statinInfo.canPrescribeStatin, + enter = expandVertically( + animationSpec = tween(500), + expandFrom = Alignment.Top + ), + exit = shrinkVertically(animationSpec = tween(500)) ) { - Column( - modifier = Modifier - .padding(16.dp), - horizontalAlignment = Alignment.CenterHorizontally + Card( + modifier = modifier ) { - Row { - Box( - modifier = Modifier - .weight(2f) - ) - Column( - modifier = Modifier - .weight(3f), - horizontalAlignment = Alignment.CenterHorizontally - ) { - Text( + Column( + modifier = Modifier + .padding(16.dp), + horizontalAlignment = Alignment.CenterHorizontally + ) { + Row { + Box( modifier = Modifier - .background(SimpleTheme.colors.material.error, shape = RoundedCornerShape(50)) - .padding(horizontal = 8.dp, vertical = 4.dp), - style = SimpleTheme.typography.material.button, - color = SimpleTheme.colors.onToolbarPrimary, - text = stringResource(R.string.statin_alert_at_risk_patient) + .weight(2f) ) + Column( + modifier = Modifier + .weight(3f), + horizontalAlignment = Alignment.CenterHorizontally + ) { + Text( + modifier = Modifier + .background(SimpleTheme.colors.material.error, shape = RoundedCornerShape(50)) + .padding(horizontal = 8.dp, vertical = 4.dp), + style = SimpleTheme.typography.material.button, + color = SimpleTheme.colors.onToolbarPrimary, + text = stringResource(R.string.statin_alert_at_risk_patient) + ) + } } + Spacer(modifier = Modifier.height(4.dp)) + RiskProgressBar() + Spacer(modifier = Modifier.height(16.dp)) + Text( + text = stringResource(R.string.statin_alert_refer_to_doctor).toAnnotatedString(), + color = SimpleTheme.colors.material.error, + style = SimpleTheme.typography.material.body2, + ) } - Spacer(modifier = Modifier.height(4.dp)) - RiskProgressBar() - Spacer(modifier = Modifier.height(16.dp)) - Text( - text = stringResource(R.string.statin_alert_refer_to_doctor).toAnnotatedString(), - color = SimpleTheme.colors.material.error, - style = SimpleTheme.typography.material.body2, - ) } } } @@ -102,22 +105,22 @@ fun RiskProgressBar() { .fillMaxWidth() .height(14.dp) .drawWithContent { - drawContent() + drawContent() - val widthPerSegment = size.width / riskColors.size + val widthPerSegment = size.width / riskColors.size - drawLine( - color = indicatorColor, - start = Offset(2 * widthPerSegment, 0f), - end = Offset(2 * widthPerSegment, size.height), - strokeWidth = 2.dp.toPx() - ) - drawLine( - color = indicatorColor, - start = Offset(size.width, 0f), - end = Offset(size.width, size.height), - strokeWidth = 2.dp.toPx() - ) + drawLine( + color = indicatorColor, + start = Offset(2 * widthPerSegment, 0f), + end = Offset(2 * widthPerSegment, size.height), + strokeWidth = 2.dp.toPx() + ) + drawLine( + color = indicatorColor, + start = Offset(size.width, 0f), + end = Offset(size.width, size.height), + strokeWidth = 2.dp.toPx() + ) }, contentAlignment = Alignment.Center, ) { @@ -143,6 +146,6 @@ fun RiskProgressBar() { @Composable fun StatinNudgePreview() { SimpleTheme { - StatinNudge(true) + StatinNudge(StatinInfo(canPrescribeStatin = true)) } } diff --git a/app/src/test/java/org/simple/clinic/summary/PatientSummaryViewRendererTest.kt b/app/src/test/java/org/simple/clinic/summary/PatientSummaryViewRendererTest.kt index faabe40596b..3df3c56bab9 100644 --- a/app/src/test/java/org/simple/clinic/summary/PatientSummaryViewRendererTest.kt +++ b/app/src/test/java/org/simple/clinic/summary/PatientSummaryViewRendererTest.kt @@ -124,7 +124,6 @@ class PatientSummaryViewRendererTest { facility = facility ) - val model = defaultModel.patientSummaryProfileLoaded(patientSummaryProfile) // when @@ -765,7 +764,7 @@ class PatientSummaryViewRendererTest { } @Test - fun `when statin info is loaded and can prescribe statin then show the statin alert`() { + fun `when statin info is loaded then update the statin alert`() { //given val statinInfo = StatinInfo(canPrescribeStatin = true) val model = defaultModel @@ -780,27 +779,7 @@ class PatientSummaryViewRendererTest { verify(ui).hideTeleconsultButton() verify(ui).hideNextAppointmentCard() verify(ui, times(2)).hideClinicalDecisionSupportAlertWithoutAnimation() - verify(ui).showStatinAlert(statinInfo) - verifyNoMoreInteractions(ui) - } - - @Test - fun `when statin info is loaded and can not prescribe statin then hide the statin alert`() { - //given - val statinInfo = StatinInfo(canPrescribeStatin = false) - val model = defaultModel - .currentFacilityLoaded(facilityWithDiabetesManagementDisabled) - .updateStatinInfo(statinInfo) - - // when - uiRenderer.render(model) - - // then - verify(ui).hideDiabetesView() - verify(ui).hideTeleconsultButton() - verify(ui).hideNextAppointmentCard() - verify(ui).hideClinicalDecisionSupportAlertWithoutAnimation() - verify(ui).hideStatinAlert() + verify(ui).updateStatinAlert(statinInfo) verifyNoMoreInteractions(ui) } @@ -843,7 +822,6 @@ class PatientSummaryViewRendererTest { .scheduledAppointmentLoaded(appointment) .updateStatinInfo(StatinInfo(canPrescribeStatin = true)) - val uiRenderer = PatientSummaryViewRenderer( ui = ui, modelUpdateCallback = { /* no-op */ }, @@ -861,7 +839,7 @@ class PatientSummaryViewRendererTest { verify(ui).showPatientDiedStatus() verify(ui).hideDiabetesView() verify(ui).hideTeleconsultButton() - verify(ui).showStatinAlert(StatinInfo(canPrescribeStatin = true)) + verify(ui).updateStatinAlert(StatinInfo(canPrescribeStatin = true)) verify(ui).hideClinicalDecisionSupportAlertWithoutAnimation() verify(ui).showNextAppointmentCard() verifyNoMoreInteractions(ui)