Skip to content

Commit d8e1ff8

Browse files
siddh1004sagarwal
andauthored
Migrate patient status view to Jetpack Compose (#5460)
https://app.shortcut.com/simpledotorg/story/15922/migrate-patient-status-view-to-jetpack-compose --------- Co-authored-by: sagarwal <[email protected]>
1 parent 6605bb8 commit d8e1ff8

File tree

4 files changed

+89
-24
lines changed

4 files changed

+89
-24
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
- Migrate medical history summary view to Jetpack Compose
1717
- Migrate assigned facility view to Jetpack Compose
1818
- Migrate next appointment view to Jetpack Compose
19+
- Migrate patient status view to Jetpack Compose
1920

2021
## 2025.05.20
2122

app/src/main/java/org/simple/clinic/summary/PatientSummaryScreen.kt

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ import androidx.compose.runtime.mutableStateOf
1616
import androidx.compose.runtime.setValue
1717
import androidx.compose.ui.Modifier
1818
import androidx.compose.ui.platform.ViewCompositionStrategy
19+
import androidx.compose.ui.res.dimensionResource
20+
import androidx.compose.ui.res.painterResource
21+
import androidx.compose.ui.res.stringResource
1922
import androidx.compose.ui.unit.dp
2023
import androidx.dynamicanimation.animation.DynamicAnimation
2124
import androidx.transition.AutoTransition
@@ -77,6 +80,7 @@ import org.simple.clinic.util.messagesender.WhatsAppMessageSender
7780
import org.simple.clinic.util.setFragmentResultListener
7881
import org.simple.clinic.util.toLocalDateAtZone
7982
import org.simple.clinic.widgets.UiEvent
83+
import org.simple.clinic.widgets.compose.PatientStatusView
8084
import org.simple.clinic.widgets.hideKeyboard
8185
import org.simple.clinic.widgets.scrollToChild
8286
import org.simple.clinic.widgets.spring
@@ -147,17 +151,14 @@ class PatientSummaryScreen :
147151
private val doneButtonFrame
148152
get() = binding.doneButtonFrame
149153

150-
private val patientDiedStatusView
151-
get() = binding.patientDiedStatusView
152-
153154
private val nextAppointmentFacilityView
154155
get() = binding.nextAppointmentFacilityView
155156

156157
private val clinicalDecisionSupportAlertView
157158
get() = binding.clinicalDecisionSupportBpHighAlert.rootView
158159

159-
private val statinComposeView
160-
get() = binding.statinComposeView
160+
private val composeView
161+
get() = binding.composeView
161162

162163
@Inject
163164
lateinit var router: Router
@@ -197,6 +198,8 @@ class PatientSummaryScreen :
197198

198199
private var statinInfo by mutableStateOf(StatinInfo.default())
199200

201+
private var showPatientDiedStatusView by mutableStateOf(false)
202+
200203
override fun defaultModel(): PatientSummaryModel {
201204
return PatientSummaryModel.from(screenKey.intention, screenKey.patientUuid)
202205
}
@@ -295,7 +298,7 @@ class PatientSummaryScreen :
295298

296299
subscriptions.add(setupChildViewVisibility())
297300

298-
statinComposeView.apply {
301+
composeView.apply {
299302
setViewCompositionStrategy(ViewCompositionStrategy.DisposeOnViewTreeLifecycleDestroyed)
300303
setContent {
301304
SimpleTheme {
@@ -308,6 +311,18 @@ class PatientSummaryScreen :
308311
addBMIClick = { additionalEvents.notify(AddBMIClicked) },
309312
addCholesterol = { additionalEvents.notify(AddCholesterolClicked) }
310313
)
314+
315+
if (showPatientDiedStatusView) {
316+
PatientStatusView(
317+
modifier = Modifier.padding(
318+
start = dimensionResource(R.dimen.spacing_8),
319+
end = dimensionResource(R.dimen.spacing_8),
320+
top = dimensionResource(R.dimen.spacing_8),
321+
),
322+
text = stringResource(R.string.patient_status_died),
323+
icon = painterResource(R.drawable.ic_patient_dead_32dp)
324+
)
325+
}
311326
}
312327
}
313328
}
@@ -708,11 +723,11 @@ class PatientSummaryScreen :
708723
}
709724

710725
override fun hidePatientDiedStatus() {
711-
patientDiedStatusView.visibility = GONE
726+
showPatientDiedStatusView = false
712727
}
713728

714729
override fun showPatientDiedStatus() {
715-
patientDiedStatusView.visibility = VISIBLE
730+
showPatientDiedStatusView = true
716731
}
717732

718733
override fun showNextAppointmentCard() {
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
package org.simple.clinic.widgets.compose
2+
3+
import androidx.compose.foundation.layout.Arrangement
4+
import androidx.compose.foundation.layout.Row
5+
import androidx.compose.foundation.layout.fillMaxWidth
6+
import androidx.compose.foundation.layout.padding
7+
import androidx.compose.material.Card
8+
import androidx.compose.material.Icon
9+
import androidx.compose.material.MaterialTheme
10+
import androidx.compose.material.Text
11+
import androidx.compose.runtime.Composable
12+
import androidx.compose.ui.Alignment
13+
import androidx.compose.ui.Modifier
14+
import androidx.compose.ui.graphics.Color
15+
import androidx.compose.ui.graphics.painter.Painter
16+
import androidx.compose.ui.res.dimensionResource
17+
import androidx.compose.ui.res.painterResource
18+
import androidx.compose.ui.res.stringResource
19+
import androidx.compose.ui.tooling.preview.Preview
20+
import org.simple.clinic.R
21+
import org.simple.clinic.common.ui.theme.SimpleTheme
22+
23+
@Composable
24+
fun PatientStatusView(
25+
text: String,
26+
icon: Painter,
27+
modifier: Modifier = Modifier,
28+
iconTint: Color = MaterialTheme.colors.onError,
29+
textColor: Color = MaterialTheme.colors.onError
30+
) {
31+
Card(
32+
modifier = modifier.fillMaxWidth(),
33+
backgroundColor = MaterialTheme.colors.error
34+
) {
35+
Row(
36+
modifier = Modifier
37+
.padding(dimensionResource(R.dimen.spacing_16)),
38+
verticalAlignment = Alignment.CenterVertically,
39+
horizontalArrangement = Arrangement.spacedBy(dimensionResource(R.dimen.spacing_8))
40+
) {
41+
Icon(
42+
painter = icon,
43+
contentDescription = null,
44+
tint = iconTint
45+
)
46+
Text(
47+
text = text,
48+
style = MaterialTheme.typography.h6,
49+
color = textColor
50+
)
51+
}
52+
}
53+
}
54+
55+
@Preview
56+
@Composable
57+
private fun PatientStatusDiedPreview() {
58+
SimpleTheme {
59+
PatientStatusView(
60+
text = stringResource(id = R.string.patient_status_died),
61+
icon = painterResource(id = R.drawable.ic_patient_dead_32dp)
62+
)
63+
}
64+
}

app/src/main/res/layout/screen_patient_summary.xml

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -48,25 +48,10 @@
4848
layout="@layout/view_clinical_decision_support_bp_high" />
4949

5050
<androidx.compose.ui.platform.ComposeView
51-
android:id="@+id/statin_compose_view"
51+
android:id="@+id/compose_view"
5252
android:layout_width="match_parent"
5353
android:layout_height="match_parent" />
5454

55-
<org.simple.clinic.widgets.PatientStatusView
56-
android:id="@+id/patientDiedStatusView"
57-
android:layout_width="match_parent"
58-
android:layout_height="wrap_content"
59-
android:layout_marginStart="@dimen/spacing_8"
60-
android:layout_marginTop="@dimen/spacing_8"
61-
android:layout_marginEnd="@dimen/spacing_8"
62-
android:visibility="gone"
63-
app:cardBackgroundColor="?attr/colorError"
64-
app:statusIcon="@drawable/ic_patient_dead_32dp"
65-
app:statusIconTint="?attr/colorOnError"
66-
app:statusText="@string/patient_status_died"
67-
app:statusTextColor="?attr/colorOnError"
68-
tools:visibility="visible" />
69-
7055
<org.simple.clinic.summary.prescribeddrugs.DrugSummaryView
7156
android:id="@+id/drugSummaryView"
7257
android:layout_width="match_parent"

0 commit comments

Comments
 (0)