Skip to content

Commit

Permalink
Update StatinNudge to accept StatinInfo
Browse files Browse the repository at this point in the history
  • Loading branch information
Siddharth Agarwal committed Dec 20, 2024
1 parent 01898df commit 09691c3
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 93 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ class PatientSummaryScreen :

private val additionalEvents = DeferredEventSource<PatientSummaryEvent>()

private var shouldShowStatinNudge by mutableStateOf(false)
private var statinInfo by mutableStateOf<StatinInfo?>(null)

override fun defaultModel(): PatientSummaryModel {
return PatientSummaryModel.from(screenKey.intention, screenKey.patientUuid)
Expand Down Expand Up @@ -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)
)
}
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,5 @@ interface PatientSummaryScreenUi {
fun showClinicalDecisionSupportAlert()
fun hideClinicalDecisionSupportAlert()
fun hideClinicalDecisionSupportAlertWithoutAnimation()
fun showStatinAlert(statinInfo: StatinInfo)
fun hideStatinAlert()
fun updateStatinAlert(statinInfo: StatinInfo)
}
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}
}
111 changes: 57 additions & 54 deletions app/src/main/java/org/simple/clinic/summary/compose/StatinNudgeView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
}
}
}
Expand All @@ -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,
) {
Expand All @@ -143,6 +146,6 @@ fun RiskProgressBar() {
@Composable
fun StatinNudgePreview() {
SimpleTheme {
StatinNudge(true)
StatinNudge(StatinInfo(canPrescribeStatin = true))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,6 @@ class PatientSummaryViewRendererTest {
facility = facility
)


val model = defaultModel.patientSummaryProfileLoaded(patientSummaryProfile)

// when
Expand Down Expand Up @@ -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
Expand All @@ -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)
}

Expand Down Expand Up @@ -843,7 +822,6 @@ class PatientSummaryViewRendererTest {
.scheduledAppointmentLoaded(appointment)
.updateStatinInfo(StatinInfo(canPrescribeStatin = true))


val uiRenderer = PatientSummaryViewRenderer(
ui = ui,
modelUpdateCallback = { /* no-op */ },
Expand All @@ -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)
Expand Down

0 comments on commit 09691c3

Please sign in to comment.