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

Fix currently taking and medications that might help sections #176

Merged
merged 1 commit into from
Jan 28, 2025
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 @@ -130,17 +130,15 @@
}
}
}
if (model.dosageInformation != null) {
HorizontalDivider(
modifier = Modifier.padding(
top = Spacings.small,
bottom = Spacings.small
)
HorizontalDivider(
modifier = Modifier.padding(
top = Spacings.small,
bottom = Spacings.small

Check warning on line 136 in app/src/main/kotlin/edu/stanford/bdh/engagehf/medication/components/MedicationCard.kt

View check run for this annotation

Codecov / codecov/patch

app/src/main/kotlin/edu/stanford/bdh/engagehf/medication/components/MedicationCard.kt#L133-L136

Added lines #L133 - L136 were not covered by tests
)
DosageInformation(dosageInformationUiModel = model.dosageInformation)
VerticalSpacer()
MedicationProgressBar(progress = model.dosageInformation.progress)
}
)
DosageInformation(dosageInformationUiModel = model.dosageInformation)
VerticalSpacer()
MedicationProgressBar(progress = model.dosageInformation.progress)

Check warning on line 141 in app/src/main/kotlin/edu/stanford/bdh/engagehf/medication/components/MedicationCard.kt

View check run for this annotation

Codecov / codecov/patch

app/src/main/kotlin/edu/stanford/bdh/engagehf/medication/components/MedicationCard.kt#L139-L141

Added lines #L139 - L141 were not covered by tests
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ data class MedicationRecommendation(
val description: String,
val type: MedicationRecommendationType,
val videoPath: String?,
val dosageInformation: DosageInformation?,
val dosageInformation: DosageInformation,
)

@Suppress("MagicNumber")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,20 +34,16 @@ class MedicationRecommendationMapper @Inject constructor(
}
}

private fun getDosageInformation(jsonMap: JsonMap?): DosageInformation? {
private fun getDosageInformation(jsonMap: JsonMap?): DosageInformation {
val dosageInformationMap = jsonMap?.get("dosageInformation") as? JsonMap
val unit = dosageInformationMap?.get("unit") as? String
val currentScheduleMap = getDosage(key = "currentSchedule", jsonMap = dosageInformationMap)
val targetSchedule = getDosage(key = "targetSchedule", jsonMap = dosageInformationMap)
return if (unit != null) {
DosageInformation(
currentSchedule = currentScheduleMap,
targetSchedule = targetSchedule,
unit = unit,
)
} else {
null
}
return DosageInformation(
currentSchedule = currentScheduleMap,
targetSchedule = targetSchedule,
unit = unit ?: "",
)
}

private fun getDosage(key: String, jsonMap: JsonMap?): List<DoseSchedule> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ data class MedicationCardUiModel(
val isExpanded: Boolean,
val statusIconResId: Int?,
val statusColor: MedicationColor,
val dosageInformation: DosageInformationUiModel?,
val dosageInformation: DosageInformationUiModel,
)

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ class MedicationUiStateMapper @Inject constructor(
MedicationUiState.Success(
medicationsTaking =
Medications(
medications = recommendations.filter { it.type != MedicationRecommendationType.NOT_STARTED }
medications = recommendations.filter { it.dosageInformation.currentDailyIntake > 0.0 }
.sortedByDescending { it.type.priority }
.map { map(it) },
expanded = true,
),
medicationsThatMayHelp = Medications(
medications = recommendations.filter { it.type == MedicationRecommendationType.NOT_STARTED }
medications = recommendations.filter { it.dosageInformation.currentDailyIntake == 0.0 }
.sortedByDescending { it.type.priority }
.map { map(it) },
expanded = false,
Expand Down Expand Up @@ -134,8 +134,7 @@ class MedicationUiStateMapper @Inject constructor(
}
}

private fun mapDosageInformation(dosageInformation: DosageInformation?): DosageInformationUiModel? {
dosageInformation ?: return null
private fun mapDosageInformation(dosageInformation: DosageInformation): DosageInformationUiModel {
val currentDailyIntake = dosageInformation.currentDailyIntake
val targetDailyIntake = dosageInformation.targetDailyIntake
val progress = if (targetDailyIntake == 0.0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,31 @@ class MedicationUiStateMapperTest {
}

@Test
fun `given medication details when mapMedicationUiState then return filtered success state`() {
fun `it should map medications taking and that may help correctly if current daily intake is greater zero`() {
// given
val recommendations = getRecommendations()
val recommendations = getRecommendations(currentDailyIntake = 20.0)

// when
val result = medicationUiStateMapper.mapMedicationUiState(recommendations)

// then
assertThat(result).isInstanceOf(MedicationUiState.Success::class.java)
assertThat((result as MedicationUiState.Success).medicationsTaking.medications).hasSize(1)
assertThat(result.medicationsTaking.medications[0].id).isEqualTo("1")
assertThat((result).medicationsThatMayHelp.medications).isEmpty()
}

@Test
fun `it should map medications taking and that may help correctly if current daily intake is zero`() {
// given
val recommendations = getRecommendations(currentDailyIntake = 0.0)

// when
val result = medicationUiStateMapper.mapMedicationUiState(recommendations)

// then
assertThat(result).isInstanceOf(MedicationUiState.Success::class.java)
assertThat((result as MedicationUiState.Success).medicationsTaking.medications).isEmpty()
assertThat((result).medicationsThatMayHelp.medications).hasSize(1)
}

@Test
Expand Down Expand Up @@ -108,20 +122,6 @@ class MedicationUiStateMapperTest {
assertThat((result as MedicationUiState.NoData).message).isEqualTo("some-string")
}

@Test
fun `given recommendations with dosage information when mapMedicationUiState then return success state with dosage information`() {
// given
val recommendations = getRecommendationsWithDosage()

// when
val result = medicationUiStateMapper.mapMedicationUiState(recommendations)

// then
assertThat(result).isInstanceOf(MedicationUiState.Success::class.java)
assertThat((result as MedicationUiState.Success).medicationsTaking.medications).hasSize(1)
assertThat(result.medicationsTaking.medications[0].dosageInformation).isNotNull()
}

@Test
fun `given SuccessState when toggleItemExpand then return updated SuccessState`() {
// given
Expand Down Expand Up @@ -171,7 +171,7 @@ class MedicationUiStateMapperTest {
isExpanded: Boolean = false,
statusIconResId: Int? = null,
statusColor: MedicationColor = MedicationColor.BLUE,
dosageInformation: DosageInformationUiModel? = null,
dosageInformation: DosageInformationUiModel = mockk(),
videoPath: String = "",
) = MedicationCardUiModel(
id = id,
Expand All @@ -185,28 +185,7 @@ class MedicationUiStateMapperTest {
videoPath = videoPath
)

private fun getRecommendations() = listOf(
MedicationRecommendation(
id = "2",
title = "Medication B",
subtitle = "Subtitle B",
description = "Description B",
type = MedicationRecommendationType.NOT_STARTED,
dosageInformation = null,
videoPath = null
),
MedicationRecommendation(
id = "1",
title = "Medication A",
subtitle = "Subtitle A",
description = "Description A",
type = MedicationRecommendationType.TARGET_DOSE_REACHED, // higher priority than NOT_STARTED
dosageInformation = null,
videoPath = "/videoSections/1/videos/1"
)
)

private fun getRecommendationsWithDosage() = listOf(
private fun getRecommendations(currentDailyIntake: Double = 1.0) = listOf(
MedicationRecommendation(
id = "1",
title = "Medication A",
Expand All @@ -218,7 +197,7 @@ class MedicationUiStateMapperTest {
currentSchedule = listOf(
DoseSchedule(
frequency = 2.0,
quantity = listOf(20.0)
quantity = listOf(currentDailyIntake)
)
),
targetSchedule = listOf(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import com.google.common.truth.Truth.assertThat
import edu.stanford.bdh.engagehf.bluetooth.data.mapper.MessageActionMapper
import edu.stanford.bdh.engagehf.education.EngageEducationRepository
import edu.stanford.bdh.engagehf.medication.data.MedicationRecommendation
import edu.stanford.bdh.engagehf.medication.data.MedicationRecommendationType
import edu.stanford.bdh.engagehf.medication.data.MedicationRepository
import edu.stanford.bdh.engagehf.messages.MessagesAction
import edu.stanford.spezi.core.navigation.Navigator
Expand All @@ -29,7 +28,7 @@ class MedicationViewModelTest {

private val medicationRepository: MedicationRepository = mockk()
private val medicationUiStateMapper: MedicationUiStateMapper = mockk()
private val recommendations = getMedicationRecommendations()
private val recommendations: List<MedicationRecommendation> = mockk()
private val uiModels: List<MedicationCardUiModel> = mockk()
private val navigator: Navigator = mockk(relaxed = true)
private val engageEducationRepository: EngageEducationRepository = mockk()
Expand Down Expand Up @@ -166,25 +165,4 @@ class MedicationViewModelTest {
// then
verify { navigator.navigateTo(EducationNavigationEvent.VideoSectionClicked(video)) }
}

private fun getMedicationRecommendations() = listOf(
MedicationRecommendation(
id = "1",
title = "Medication A",
subtitle = "Subtitle A",
description = "Description A",
type = MedicationRecommendationType.TARGET_DOSE_REACHED,
dosageInformation = null,
videoPath = null
),
MedicationRecommendation(
id = "2",
title = "Medication B",
subtitle = "Subtitle B",
description = "Description B",
type = MedicationRecommendationType.NOT_STARTED,
dosageInformation = null,
videoPath = null
)
)
}
Loading