diff --git a/android/quest/src/main/java/org/smartregister/fhircore/quest/ui/patient/profile/PatientProfileEvent.kt b/android/quest/src/main/java/org/smartregister/fhircore/quest/ui/patient/profile/PatientProfileEvent.kt index e50c7d626b..b11a684dc6 100644 --- a/android/quest/src/main/java/org/smartregister/fhircore/quest/ui/patient/profile/PatientProfileEvent.kt +++ b/android/quest/src/main/java/org/smartregister/fhircore/quest/ui/patient/profile/PatientProfileEvent.kt @@ -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, diff --git a/android/quest/src/main/java/org/smartregister/fhircore/quest/ui/patient/profile/PatientProfileScreen.kt b/android/quest/src/main/java/org/smartregister/fhircore/quest/ui/patient/profile/PatientProfileScreen.kt index ded36c9aba..130613ba72 100644 --- a/android/quest/src/main/java/org/smartregister/fhircore/quest/ui/patient/profile/PatientProfileScreen.kt +++ b/android/quest/src/main/java/org/smartregister/fhircore/quest/ui/patient/profile/PatientProfileScreen.kt @@ -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 @@ -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 @@ -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 @@ -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 = { _, _ -> }) + } + } } } } diff --git a/android/quest/src/main/java/org/smartregister/fhircore/quest/ui/patient/profile/PatientProfileViewModel.kt b/android/quest/src/main/java/org/smartregister/fhircore/quest/ui/patient/profile/PatientProfileViewModel.kt index 8a9422a68d..6ee3a6a1ef 100644 --- a/android/quest/src/main/java/org/smartregister/fhircore/quest/ui/patient/profile/PatientProfileViewModel.kt +++ b/android/quest/src/main/java/org/smartregister/fhircore/quest/ui/patient/profile/PatientProfileViewModel.kt @@ -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 @@ -104,6 +107,12 @@ constructor( else -> {} } } + is PatientProfileEvent.OpenTaskForm -> + event.context.launchQuestionnaireForResult( + questionnaireId = event.taskFormId, + clientIdentifier = event.patientId, + backReference = event.taskId.asReference(ResourceType.Task).reference + ) } companion object { diff --git a/android/quest/src/main/java/org/smartregister/fhircore/quest/ui/patient/profile/components/ProfileActionableItem.kt b/android/quest/src/main/java/org/smartregister/fhircore/quest/ui/patient/profile/components/ProfileActionableItem.kt index e35f8f7060..7c0231bdc4 100644 --- a/android/quest/src/main/java/org/smartregister/fhircore/quest/ui/patient/profile/components/ProfileActionableItem.kt +++ b/android/quest/src/main/java/org/smartregister/fhircore/quest/ui/patient/profile/components/ProfileActionableItem.kt @@ -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), @@ -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), @@ -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 = { _, _ -> } ) } } @@ -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 = { _, _ -> } ) } } @@ -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 = { _, _ -> } ) } } @@ -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 = { _, _ -> } ) } } @@ -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 = { _, _ -> } ) } } diff --git a/android/quest/src/main/java/org/smartregister/fhircore/quest/ui/patient/profile/components/ProfileCard.kt b/android/quest/src/main/java/org/smartregister/fhircore/quest/ui/patient/profile/components/ProfileCard.kt index 4dc7e24512..85bfb65d19 100644 --- a/android/quest/src/main/java/org/smartregister/fhircore/quest/ui/patient/profile/components/ProfileCard.kt +++ b/android/quest/src/main/java/org/smartregister/fhircore/quest/ui/patient/profile/components/ProfileCard.kt @@ -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 = { _, _ -> } ) } } diff --git a/android/quest/src/main/java/org/smartregister/fhircore/quest/ui/shared/models/PatientProfileRowItem.kt b/android/quest/src/main/java/org/smartregister/fhircore/quest/ui/shared/models/PatientProfileRowItem.kt index 28dd7b78c4..1ca732980c 100644 --- a/android/quest/src/main/java/org/smartregister/fhircore/quest/ui/shared/models/PatientProfileRowItem.kt +++ b/android/quest/src/main/java/org/smartregister/fhircore/quest/ui/shared/models/PatientProfileRowItem.kt @@ -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, diff --git a/android/quest/src/main/java/org/smartregister/fhircore/quest/util/mappers/ProfileViewDataMapper.kt b/android/quest/src/main/java/org/smartregister/fhircore/quest/util/mappers/ProfileViewDataMapper.kt index 7fc081abd2..209c7304bf 100644 --- a/android/quest/src/main/java/org/smartregister/fhircore/quest/util/mappers/ProfileViewDataMapper.kt +++ b/android/quest/src/main/java/org/smartregister/fhircore/quest/util/mappers/ProfileViewDataMapper.kt @@ -30,6 +30,7 @@ import org.smartregister.fhircore.engine.domain.util.DataMapper import org.smartregister.fhircore.engine.ui.theme.DefaultColor import org.smartregister.fhircore.engine.ui.theme.InfoColor import org.smartregister.fhircore.engine.ui.theme.OverdueColor +import org.smartregister.fhircore.engine.ui.theme.SuccessColor import org.smartregister.fhircore.engine.util.extension.extractId import org.smartregister.fhircore.engine.util.extension.makeItReadable import org.smartregister.fhircore.engine.util.extension.translateGender @@ -67,12 +68,17 @@ class ProfileViewDataMapper @Inject constructor(@ApplicationContext val context: tasks = inputModel.tasks.take(DEFAULT_TASKS_COUNT).map { PatientProfileRowItem( + id = it.logicalId, + actionFormId = + if (it.status == Task.TaskStatus.READY && it.hasReasonReference()) + it.reasonReference.extractId() + else null, title = it.description, subtitle = context.getString(R.string.due_on, it.executionPeriod.start.makeItReadable()), profileViewSection = PatientProfileViewSection.TASKS, actionButtonColor = it.status.retrieveColorCode(), - actionButtonText = it.description + actionButtonText = it.description, ) } ) @@ -118,6 +124,7 @@ class ProfileViewDataMapper @Inject constructor(@ApplicationContext val context: Task.TaskStatus.READY -> InfoColor Task.TaskStatus.CANCELLED -> OverdueColor Task.TaskStatus.FAILED -> OverdueColor + Task.TaskStatus.COMPLETED -> SuccessColor else -> DefaultColor }