Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Patient profile tasks handling and color coding #1270

Merged
merged 1 commit into from
May 10, 2022
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
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@ sealed class PatientProfileEvent {
data class LoadQuestionnaire(val questionnaireId: String, val context: Context) :
PatientProfileEvent()

data class OpenTaskForm(
val context: Context,
val taskFormId: String,
val taskId: String,
val patientId: String
) : PatientProfileEvent()

data class OverflowMenuClick(
val context: Context,
val menuId: Int,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,23 @@ fun PatientProfileScreen(
title = stringResource(R.string.tasks).uppercase(),
onActionClick = {},
profileViewSection = PatientProfileViewSection.TASKS
) { profileViewData.tasks.forEach { ProfileActionableItem(it) } }
) {
profileViewData.tasks.forEach {
ProfileActionableItem(
it,
onActionClick = { taskFormId, taskId ->
patientProfileViewModel.onEvent(
PatientProfileEvent.OpenTaskForm(
context = context,
taskFormId = taskFormId,
taskId = taskId,
patientId = profileViewData.logicalId
)
)
}
)
}
}
}

// Forms: Loaded for quest app
Expand All @@ -160,12 +176,17 @@ fun PatientProfileScreen(
}

// Medical History: Show medication history for the patient
// TODO add handled events for all items action click
if (profileViewData.medicalHistoryData.isNotEmpty()) {
ProfileCard(
title = stringResource(R.string.medical_history),
onActionClick = { patientProfileViewModel.onEvent(PatientProfileEvent.SeeAll(it)) },
profileViewSection = PatientProfileViewSection.MEDICAL_HISTORY
) { profileViewData.medicalHistoryData.forEach { ProfileActionableItem(it) } }
) {
profileViewData.medicalHistoryData.forEach {
ProfileActionableItem(it, onActionClick = { _, _ -> })
}
}
}

// Upcoming Services: Display upcoming services (or tasks) for the patient
Expand All @@ -174,7 +195,11 @@ fun PatientProfileScreen(
title = stringResource(R.string.upcoming_services),
onActionClick = { patientProfileViewModel.onEvent(PatientProfileEvent.SeeAll(it)) },
profileViewSection = PatientProfileViewSection.UPCOMING_SERVICES
) { profileViewData.upcomingServices.forEach { ProfileActionableItem(it) } }
) {
profileViewData.upcomingServices.forEach {
ProfileActionableItem(it, onActionClick = { _, _ -> })
}
}
}

// Service Card: Display other vital information for ANC/PNC
Expand All @@ -183,7 +208,11 @@ fun PatientProfileScreen(
title = stringResource(R.string.service_card),
onActionClick = { patientProfileViewModel.onEvent(PatientProfileEvent.SeeAll(it)) },
profileViewSection = PatientProfileViewSection.SERVICE_CARD
) { profileViewData.ancCardData.forEach { ProfileActionableItem(it) } }
) {
profileViewData.ancCardData.forEach {
ProfileActionableItem(it, onActionClick = { _, _ -> })
}
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,14 @@ import androidx.lifecycle.viewModelScope
import dagger.hilt.android.lifecycle.HiltViewModel
import javax.inject.Inject
import kotlinx.coroutines.launch
import org.hl7.fhir.r4.model.ResourceType
import org.smartregister.fhircore.engine.appfeature.model.HealthModule
import org.smartregister.fhircore.engine.data.local.register.PatientRegisterRepository
import org.smartregister.fhircore.engine.ui.questionnaire.QuestionnaireActivity
import org.smartregister.fhircore.engine.ui.questionnaire.QuestionnaireType
import org.smartregister.fhircore.engine.util.extension.asReference
import org.smartregister.fhircore.engine.util.extension.launchQuestionnaire
import org.smartregister.fhircore.engine.util.extension.launchQuestionnaireForResult
import org.smartregister.fhircore.quest.R
import org.smartregister.fhircore.quest.navigation.NavigationArg
import org.smartregister.fhircore.quest.navigation.OverflowMenuFactory
Expand Down Expand Up @@ -104,6 +107,12 @@ constructor(
else -> {}
}
}
is PatientProfileEvent.OpenTaskForm ->
event.context.launchQuestionnaireForResult<QuestionnaireActivity>(
questionnaireId = event.taskFormId,
clientIdentifier = event.patientId,
backReference = event.taskId.asReference(ResourceType.Task).reference
)
}

companion object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ import org.smartregister.fhircore.quest.ui.shared.models.PatientProfileViewSecti
@Composable
fun ProfileActionableItem(
patientProfileRowItem: PatientProfileRowItem,
modifier: Modifier = Modifier
modifier: Modifier = Modifier,
onActionClick: (String, String) -> Unit,
) {
Row(
modifier = modifier.fillMaxWidth().padding(16.dp),
Expand Down Expand Up @@ -101,18 +102,26 @@ fun ProfileActionableItem(
SubtitleRow(patientProfileRowItem = patientProfileRowItem, modifier = modifier)
}
}
ActionButton(patientProfileRowItem, modifier)
ActionButton(patientProfileRowItem, modifier, onActionClick)
}
}

@Composable
private fun ActionButton(patientProfileRowItem: PatientProfileRowItem, modifier: Modifier) {
private fun ActionButton(
patientProfileRowItem: PatientProfileRowItem,
modifier: Modifier,
onActionClick: (String, String) -> Unit
) {
if (patientProfileRowItem.profileViewSection == PatientProfileViewSection.TASKS &&
patientProfileRowItem.actionButtonColor != null &&
patientProfileRowItem.actionButtonText != null
) {
OutlinedButton(
onClick = { /*TODO perform click action */},
onClick = {
patientProfileRowItem.actionFormId?.let { taskFormId ->
onActionClick(taskFormId, patientProfileRowItem.id)
}
},
colors =
ButtonDefaults.buttonColors(
backgroundColor = patientProfileRowItem.actionButtonColor.copy(alpha = 0.2f),
Expand Down Expand Up @@ -180,24 +189,28 @@ fun ProfileActionableItemForTasksPreview() {
Column {
ProfileActionableItem(
PatientProfileRowItem(
id = "1",
title = "ANC",
titleIcon = R.drawable.ic_pregnant,
subtitle = "due date",
profileViewSection = PatientProfileViewSection.TASKS,
actionButtonColor = InfoColor,
actionButtonText = "ANC visit"
)
),
onActionClick = { _, _ -> }
)
Divider()
ProfileActionableItem(
PatientProfileRowItem(
id = "2",
title = "Sick",
titleIcon = R.drawable.ic_pregnant,
subtitle = "due date",
profileViewSection = PatientProfileViewSection.TASKS,
actionButtonColor = OverdueColor,
actionButtonText = "Malaria medicine"
)
),
onActionClick = { _, _ -> }
)
}
}
Expand All @@ -208,40 +221,48 @@ fun ProfileActionableItemForAncCardPreview() {
Column {
ProfileActionableItem(
PatientProfileRowItem(
id = "1",
title = "Granuloma Annulare",
subtitle = "23 weeks (EDD: 20-Jun-2021)",
profileViewSection = PatientProfileViewSection.SERVICE_CARD
)
),
onActionClick = { _, _ -> }
)
Divider()
ProfileActionableItem(
PatientProfileRowItem(
id = "2",
title = "Blood pressure",
subtitle = "111/80",
subtitleStatus = "at risk",
subtitleStatusColor = WarningColor,
profileViewSection = PatientProfileViewSection.SERVICE_CARD
)
),
onActionClick = { _, _ -> }
)
Divider()
ProfileActionableItem(
PatientProfileRowItem(
id = "3",
title = "Heart rate",
subtitle = "186",
subtitleStatus = "danger",
subtitleStatusColor = DangerColor,
profileViewSection = PatientProfileViewSection.SERVICE_CARD
)
),
onActionClick = { _, _ -> }
)
Divider()
ProfileActionableItem(
PatientProfileRowItem(
id = "4",
title = "Weight gain",
subtitle = "+ 6.7kg",
subtitleStatus = "good",
subtitleStatusColor = DefaultColor,
profileViewSection = PatientProfileViewSection.SERVICE_CARD
)
),
onActionClick = { _, _ -> }
)
}
}
Expand All @@ -252,26 +273,32 @@ fun ProfileActionableItemForMedicalHistoryPreview() {
Column {
ProfileActionableItem(
PatientProfileRowItem(
id = "1",
title = "Diarrhoea",
subtitle = "Stomach ache, with painful running stomach",
profileViewSection = PatientProfileViewSection.MEDICAL_HISTORY
)
),
onActionClick = { _, _ -> }
)
Divider()
ProfileActionableItem(
PatientProfileRowItem(
id = "2",
title = "Malaria",
subtitle = "High temperatures and loss of appetite, long sleepless nights",
profileViewSection = PatientProfileViewSection.MEDICAL_HISTORY
)
),
onActionClick = { _, _ -> }
)
Divider()
ProfileActionableItem(
PatientProfileRowItem(
id = "3",
title = "Health issue",
subtitle = "Description of symptoms",
profileViewSection = PatientProfileViewSection.MEDICAL_HISTORY
)
),
onActionClick = { _, _ -> }
)
}
}
Expand All @@ -282,35 +309,41 @@ fun ProfileActionableItemForTestResultsPreview() {
Column {
ProfileActionableItem(
PatientProfileRowItem(
id = "1",
title = "Deficient (5-Oct-2021)",
subtitle = "G6PD: 4.4",
subtitleStatus = "Hb: 2.2",
profileViewSection = PatientProfileViewSection.TEST_RESULTS,
showDot = true,
showAngleRightIcon = true
)
),
onActionClick = { _, _ -> }
)
Divider()
ProfileActionableItem(
PatientProfileRowItem(
id = "2",
title = "Normal (30-Aug-2020)",
subtitle = "G6PD: 6.0",
subtitleStatus = "Hb: 9.0",
profileViewSection = PatientProfileViewSection.TEST_RESULTS,
showDot = true,
showAngleRightIcon = true
)
),
onActionClick = { _, _ -> }
)
Divider()
ProfileActionableItem(
PatientProfileRowItem(
id = "3",
title = "Deficient (11-Mar-2020)",
subtitle = "G6PD: 4.3",
subtitleStatus = "Hb: 2.0",
profileViewSection = PatientProfileViewSection.TEST_RESULTS,
showDot = true,
showAngleRightIcon = true
)
),
onActionClick = { _, _ -> }
)
}
}
Expand All @@ -321,32 +354,38 @@ fun ProfileActionableItemForUpcomingServicesPreview() {
Column {
ProfileActionableItem(
PatientProfileRowItem(
id = "1",
title = "ANC facility visit",
subtitle = "22-May-2021",
profileViewSection = PatientProfileViewSection.UPCOMING_SERVICES,
startIcon = R.drawable.gm_calendar_today_24,
startIconBackgroundColor = WarningColor.copy(alpha = 0.7f)
)
),
onActionClick = { _, _ -> }
)
Divider()
ProfileActionableItem(
PatientProfileRowItem(
id = "2",
title = "Sick check in",
subtitle = "25-Aug-2021",
profileViewSection = PatientProfileViewSection.UPCOMING_SERVICES,
startIcon = R.drawable.ic_households,
startIconBackgroundColor = DangerColor.copy(alpha = 0.6f)
)
),
onActionClick = { _, _ -> }
)
Divider()
ProfileActionableItem(
PatientProfileRowItem(
id = "3",
title = "Vaccination",
subtitle = "03-Sept-2021",
profileViewSection = PatientProfileViewSection.UPCOMING_SERVICES,
startIcon = R.drawable.ic_needle,
startIconBackgroundColor = InfoColor.copy(alpha = 0.5f)
)
),
onActionClick = { _, _ -> }
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -93,24 +93,28 @@ private fun PatientProfileSectionPreview() {
Column {
ProfileActionableItem(
PatientProfileRowItem(
id = "1",
title = "ANC",
titleIcon = R.drawable.ic_pregnant,
subtitle = "due date",
profileViewSection = PatientProfileViewSection.TASKS,
actionButtonColor = InfoColor,
actionButtonText = "ANC visit"
)
),
onActionClick = { _, _ -> }
)
Divider()
ProfileActionableItem(
PatientProfileRowItem(
id = "2",
title = "Sick",
titleIcon = R.drawable.ic_pregnant,
subtitle = "due date",
profileViewSection = PatientProfileViewSection.TASKS,
actionButtonColor = OverdueColor,
actionButtonText = "Malaria medicine"
)
),
onActionClick = { _, _ -> }
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ package org.smartregister.fhircore.quest.ui.shared.models
import androidx.compose.ui.graphics.Color

data class PatientProfileRowItem(
val id: String,
val actionFormId: String? = null,
val startIcon: Int? = null,
val startIconBackgroundColor: Color? = null,
val title: String,
Expand Down
Loading