Skip to content

Commit 9ded4fb

Browse files
author
Siddharth Agarwal
committed
Add CVDRiskLevel
1 parent 79ffae9 commit 9ded4fb

File tree

3 files changed

+51
-28
lines changed

3 files changed

+51
-28
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package org.simple.clinic.cvdrisk
2+
3+
import androidx.compose.ui.graphics.Color
4+
import org.simple.clinic.R
5+
6+
enum class CVDRiskLevel(val displayStringResId: Int, val color: Color) {
7+
LOW_HIGH(R.string.statin_alert_low_high_risk_patient_x, Color(0xFFFF7A00)),
8+
MEDIUM_HIGH(R.string.statin_alert_medium_high_risk_patient_x, Color(0xFFFF7A00)),
9+
HIGH(R.string.statin_alert_high_risk_patient_x, Color(0xFFFF3355));
10+
11+
companion object {
12+
fun compute(cvdRiskRange: CVDRiskRange): CVDRiskLevel {
13+
return when {
14+
cvdRiskRange.min < 5 -> LOW_HIGH
15+
cvdRiskRange.min < 10 -> MEDIUM_HIGH
16+
else -> HIGH
17+
}
18+
}
19+
}
20+
}

app/src/main/java/org/simple/clinic/cvdrisk/CVDRiskRange.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import android.os.Parcelable
44
import androidx.room.TypeConverter
55
import com.squareup.moshi.FromJson
66
import com.squareup.moshi.ToJson
7+
import kotlinx.parcelize.IgnoredOnParcel
78
import kotlinx.parcelize.Parcelize
89

910
@Parcelize
@@ -12,6 +13,10 @@ data class CVDRiskRange(
1213
val max: Int,
1314
) : Parcelable {
1415

16+
@Transient
17+
@IgnoredOnParcel
18+
val level = CVDRiskLevel.compute(this)
19+
1520
class RoomTypeConverter {
1621

1722
@TypeConverter

app/src/main/java/org/simple/clinic/summary/compose/StatinNudgeView.kt

Lines changed: 26 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ import org.simple.clinic.R
4040
import org.simple.clinic.common.ui.components.FilledButton
4141
import org.simple.clinic.common.ui.theme.SimpleInverseTheme
4242
import org.simple.clinic.common.ui.theme.SimpleTheme
43+
import org.simple.clinic.cvdrisk.CVDRiskLevel
4344
import org.simple.clinic.cvdrisk.CVDRiskRange
4445
import org.simple.clinic.cvdrisk.StatinInfo
4546
import org.simple.clinic.medicalhistory.Answer
@@ -119,15 +120,10 @@ fun RiskText(
119120
val riskText = when {
120121
hasCVD -> stringResource(R.string.statin_alert_very_high_risk_patient)
121122
cvdRiskRange == null -> stringResource(R.string.statin_alert_at_risk_patient)
122-
cvdRiskRange.min > 10 -> stringResource(R.string.statin_alert_high_risk_patient_x, riskPercentage)
123-
cvdRiskRange.min < 5 -> stringResource(R.string.statin_alert_low_high_risk_patient_x, riskPercentage)
124-
else -> stringResource(R.string.statin_alert_medium_high_risk_patient_x, riskPercentage)
123+
else -> stringResource(cvdRiskRange.level.displayStringResId, riskPercentage)
125124
}
126125

127-
val riskColor = when {
128-
cvdRiskRange == null || cvdRiskRange.min > 10 -> SimpleTheme.colors.material.error
129-
else -> Color(0xFFFF7A00)
130-
}
126+
val riskColor = cvdRiskRange?.level?.color ?: SimpleTheme.colors.material.error
131127

132128
val textMeasurer = rememberTextMeasurer()
133129
val textWidth = textMeasurer.measure(
@@ -164,11 +160,11 @@ fun RiskProgressBar(
164160
endOffset: Float
165161
) {
166162
val riskColors = listOf(
167-
Color(0xFF00B849), // Very Low
168-
Color(0xFFFFC800), // Low
169-
SimpleTheme.colors.material.error, // Medium
170-
Color(0xFFB81631), // High
171-
Color(0xFF731814) // Very High
163+
Color(0xFF00B849), // Low
164+
Color(0xFFFFC800), // MEDIUM
165+
SimpleTheme.colors.material.error, // HIGH
166+
Color(0xFFB81631), // VERY HIGH
167+
Color(0xFF731814) // CRITICAL
172168
)
173169

174170
val indicatorColor = Color(0xFF2F363D)
@@ -240,26 +236,28 @@ fun DescriptionText(
240236
statinInfo: StatinInfo
241237
) {
242238
val text = when {
243-
statinInfo.cvdRisk == null ||
244-
statinInfo.cvdRisk.min >= 10 -> stringResource(R.string.statin_alert_refer_to_doctor)
239+
statinInfo.cvdRisk == null || statinInfo.cvdRisk.level == CVDRiskLevel.HIGH ->
240+
stringResource(R.string.statin_alert_refer_to_doctor)
245241

246-
statinInfo.isSmoker == Answer.Unanswered &&
247-
statinInfo.bmiReading == null -> stringResource(R.string.statin_alert_add_smoking_and_bmi_info)
242+
statinInfo.isSmoker == Answer.Unanswered && statinInfo.bmiReading == null ->
243+
stringResource(R.string.statin_alert_add_smoking_and_bmi_info)
248244

249-
statinInfo.isSmoker == Answer.Unanswered &&
250-
statinInfo.bmiReading != null -> stringResource(R.string.statin_alert_add_smoking_info)
245+
statinInfo.isSmoker == Answer.Unanswered && statinInfo.bmiReading != null ->
246+
stringResource(R.string.statin_alert_add_smoking_info)
251247

252-
statinInfo.isSmoker != Answer.Unanswered &&
253-
statinInfo.bmiReading == null -> stringResource(R.string.statin_alert_add_bmi_info)
248+
statinInfo.isSmoker != Answer.Unanswered && statinInfo.bmiReading == null ->
249+
stringResource(R.string.statin_alert_add_bmi_info)
254250

255251
else -> stringResource(R.string.statin_alert_refer_to_doctor)
256252
}.toAnnotatedString()
257253

258254
val textColor = when {
259-
statinInfo.cvdRisk == null ||
260-
statinInfo.cvdRisk.min >= 10 -> SimpleTheme.colors.material.error
255+
statinInfo.cvdRisk == null || statinInfo.cvdRisk.level == CVDRiskLevel.HIGH
256+
-> SimpleTheme.colors.material.error
257+
258+
statinInfo.isSmoker == Answer.Unanswered || statinInfo.bmiReading == null ->
259+
SimpleTheme.colors.onSurface67
261260

262-
statinInfo.isSmoker == Answer.Unanswered || statinInfo.bmiReading == null -> SimpleTheme.colors.onSurface67
263261
else -> SimpleTheme.colors.material.error
264262
}
265263

@@ -324,11 +322,11 @@ fun StainNudgeAddButtons(
324322

325323
fun getOffsets(cvdRiskRange: CVDRiskRange?, size: Size): Pair<Float, Float> {
326324
val riskRanges = listOf(
327-
0..4, // Very Low
328-
5..9, // Low
329-
10..19, // Medium
330-
20..29, // High
331-
30..33 // Very High
325+
0..4, // LOW
326+
5..9, // MEDIUM
327+
10..19, // HIGH
328+
20..29, // VERY HIGH
329+
30..33 // CRITICAL
332330
)
333331

334332
val startRatio: Float

0 commit comments

Comments
 (0)