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

Feature/74 bottom sheets and record operations #87

Merged
merged 57 commits into from
Aug 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
d6a4ea9
added health date time picker
Basler182 Aug 17, 2024
8e33ee6
added NumberPicker
Basler182 Aug 17, 2024
dd40844
adjusted TimePicker
Basler182 Aug 17, 2024
a55a800
added missing BottomSheetContent Enum entries
Basler182 Aug 17, 2024
bca5c88
adjusted when Floating Button for adding records is shown
Basler182 Aug 17, 2024
d00a386
added MeasurementLocationDialog
Basler182 Aug 17, 2024
5bf1517
added BodyPositionDialog
Basler182 Aug 17, 2024
c8a69a9
added AddBloodPressureBottomSheetUiState
Basler182 Aug 17, 2024
b350657
added AddDataHeader
Basler182 Aug 18, 2024
1690ee7
added DateTimeMapper
Basler182 Aug 18, 2024
4c14870
added Add HeartRate Bottom Sheet
Basler182 Aug 18, 2024
9d371ec
added save Record to HealthRepository
Basler182 Aug 18, 2024
7ed6a8a
added AddBloodPressureBottomSheet
Basler182 Aug 18, 2024
5705400
adjusted initial UiState
Basler182 Aug 18, 2024
da27ecb
added string resources
Basler182 Aug 18, 2024
3a448b9
added AddBloodPressureBottomSheetUiStateMapper
Basler182 Aug 18, 2024
59289b4
added AddBloodPressureBottomSheetViewModel
Basler182 Aug 18, 2024
b95369c
added AddHeartRateBottomSheet
Basler182 Aug 18, 2024
a0005ad
added AddHeartRateBottomSheetUiStateMapper
Basler182 Aug 18, 2024
bcaf6dd
added AddHeartRateBottomSheetUiState
Basler182 Aug 18, 2024
4405492
added AddHeartRateBottomSheetViewModel
Basler182 Aug 18, 2024
2f62008
save new weight record
Basler182 Aug 18, 2024
4955a3f
added string resources
Basler182 Aug 18, 2024
566f62c
close bottom sheet after save
Basler182 Aug 18, 2024
5be65a0
rounded x values for chart, cause library doesn't support more precis…
Basler182 Aug 18, 2024
698151c
adjusted rounding of x values
Basler182 Aug 18, 2024
9debc45
fixed AddWeightBottomSheetViewModelTest
Basler182 Aug 18, 2024
85689ec
removed number suppression
Basler182 Aug 18, 2024
d93b992
replaced height, width with size
Basler182 Aug 18, 2024
9774e9f
refactored to intRange
Basler182 Aug 18, 2024
94cd40b
minor changes
Basler182 Aug 18, 2024
02dee44
Merge branch 'main' into feature/74-bottom-sheets-and-record-operations
Basler182 Aug 19, 2024
8b91680
added ItemsDialog
Basler182 Aug 23, 2024
5b02c93
removed default timer picker state
Basler182 Aug 23, 2024
8a28d42
minor adjustments to state handling
Basler182 Aug 23, 2024
a91e31b
renamed to firstVisibleItemIndex
Basler182 Aug 23, 2024
730130b
improved NumberPicker
Basler182 Aug 23, 2024
3e5d6ce
removed no longer need date time values
Basler182 Aug 23, 2024
ac23ec3
added kg lbs strings
Basler182 Aug 23, 2024
5b84948
adjusted Add Weight data to BP and HR
Basler182 Aug 23, 2024
27bb181
adjusted chart value formatter
Basler182 Aug 23, 2024
aec11e9
adjusted DateTimeFormatter
Basler182 Aug 23, 2024
ce85e2a
fixed magic number suppression
Basler182 Aug 23, 2024
6637163
tested AddWeightBottomSheetViewModel
Basler182 Aug 23, 2024
c5b42d9
fixed health page test
Basler182 Aug 23, 2024
908aaa3
tested DateTimeFormatter
Basler182 Aug 23, 2024
8e411a3
tested AddBloodPressureBottomSheetUiStateMapper
Basler182 Aug 23, 2024
342994e
tested AddBloodPressureBottomSheetViewModel
Basler182 Aug 23, 2024
c5e8383
tested AddHeartRateBottomSheetUiStateMapper
Basler182 Aug 23, 2024
85b1559
tested AddHeartRateBottomSheetViewModel
Basler182 Aug 23, 2024
96aab51
fixed detekt
Basler182 Aug 23, 2024
8d5440d
added missing descriptions
Basler182 Aug 23, 2024
22a5cd3
added deletion of health entries
Basler182 Aug 23, 2024
8f9bfee
Merge branch 'main' into feature/74-bottom-sheets-and-record-operations
eldcn Aug 25, 2024
2755855
address remaining comments and unit all view models
eldcn Aug 25, 2024
098a2d4
extract float rounding method
eldcn Aug 25, 2024
1e35e3c
minor adjustment
eldcn Aug 25, 2024
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 @@ -155,9 +155,10 @@ class HealthPageTest {
trend = 0f,
formattedTrend = "0.0 kg",
secondValue = null,
id = entryId
id = entryId,
)
)
),
valueFormatter = { value -> "$value" }
)
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ class BottomSheetEvents @Inject constructor(
data object DoNewMeasurement : Event
data object CloseBottomSheet : Event
data object WeightDescriptionBottomSheet : Event
data object BloodPressureDescriptionBottomSheet : Event
data object HeartRateDescriptionBottomSheet : Event
data object AddWeightRecord : Event
data object AddBloodPressureRecord : Event
data object AddHeartRateRecord : Event
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package edu.stanford.bdh.engagehf.health

sealed interface HealthAction {
data object DescriptionBottomSheet : HealthAction
data object AddRecord : HealthAction
data class DeleteRecord(val recordId: String) : HealthAction
data class UpdateTimeRange(val timeRange: TimeRange) : HealthAction
data class ToggleTimeRangeDropdown(val expanded: Boolean) : HealthAction
Expand Down
17 changes: 5 additions & 12 deletions app/src/main/kotlin/edu/stanford/bdh/engagehf/health/HealthPage.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package edu.stanford.bdh.engagehf.health

import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
Expand All @@ -11,7 +10,8 @@
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.LazyListScope
import androidx.compose.foundation.lazy.itemsIndexed
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Info
import androidx.compose.material3.CircularProgressIndicator
import androidx.compose.material3.HorizontalDivider
import androidx.compose.material3.Icon
Expand All @@ -20,8 +20,6 @@
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.shadow
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.tooling.preview.PreviewParameter
Expand All @@ -32,7 +30,6 @@
import edu.stanford.bdh.engagehf.health.components.HealthChart
import edu.stanford.bdh.engagehf.health.components.SwipeBox
import edu.stanford.bdh.engagehf.health.components.TimeRangeDropdown
import edu.stanford.spezi.core.design.theme.Colors.onPrimary
import edu.stanford.spezi.core.design.theme.Colors.primary
import edu.stanford.spezi.core.design.theme.Sizes
import edu.stanford.spezi.core.design.theme.Spacings
Expand Down Expand Up @@ -184,14 +181,9 @@
onClick = onInfoAction
) {
Icon(
painter = painterResource(id = edu.stanford.spezi.core.design.R.drawable.ic_info),
imageVector = Icons.Filled.Info,

Check warning on line 184 in app/src/main/kotlin/edu/stanford/bdh/engagehf/health/HealthPage.kt

View check run for this annotation

Codecov / codecov/patch

app/src/main/kotlin/edu/stanford/bdh/engagehf/health/HealthPage.kt#L184

Added line #L184 was not covered by tests
contentDescription = stringResource(R.string.info_icon_content_description),
modifier = Modifier
.size(Sizes.Icon.medium)
.background(primary, shape = CircleShape)
.shadow(Spacings.small, CircleShape)
.padding(Spacings.small),
tint = onPrimary
tint = primary

Check warning on line 186 in app/src/main/kotlin/edu/stanford/bdh/engagehf/health/HealthPage.kt

View check run for this annotation

Codecov / codecov/patch

app/src/main/kotlin/edu/stanford/bdh/engagehf/health/HealthPage.kt#L186

Added line #L186 was not covered by tests
)
}
}
Expand All @@ -217,6 +209,7 @@
HealthUiState.NoData("No data available"),
HealthUiState.Success(
data = HealthUiData(
valueFormatter = { "Jan 24" },

Check warning on line 212 in app/src/main/kotlin/edu/stanford/bdh/engagehf/health/HealthPage.kt

View check run for this annotation

Codecov / codecov/patch

app/src/main/kotlin/edu/stanford/bdh/engagehf/health/HealthPage.kt#L212

Added line #L212 was not covered by tests
infoRowData = InfoRowData(
selectedTimeRange = TimeRange.MONTHLY,
formattedValue = "70.0 kg",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,31 @@
import androidx.health.connect.client.records.HeartRateRecord
import androidx.health.connect.client.records.Record
import androidx.health.connect.client.records.WeightRecord
import com.google.firebase.firestore.FirebaseFirestore
import com.google.firebase.firestore.ListenerRegistration
import com.google.firebase.firestore.Query
import edu.stanford.bdh.engagehf.observations.ObservationCollection
import edu.stanford.bdh.engagehf.observations.ObservationCollectionProvider
import edu.stanford.healthconnectonfhir.ObservationsDocumentMapper
import edu.stanford.healthconnectonfhir.RecordToObservationMapper
import edu.stanford.spezi.core.coroutines.di.Dispatching
import edu.stanford.spezi.core.logging.speziLogger
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.channels.awaitClose
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.callbackFlow
import kotlinx.coroutines.tasks.await
import kotlinx.coroutines.withContext
import java.time.ZonedDateTime
import java.time.format.DateTimeFormatter
import javax.inject.Inject

class HealthRepository @Inject constructor(
private val firestore: FirebaseFirestore,

Check warning on line 27 in app/src/main/kotlin/edu/stanford/bdh/engagehf/health/HealthRepository.kt

View check run for this annotation

Codecov / codecov/patch

app/src/main/kotlin/edu/stanford/bdh/engagehf/health/HealthRepository.kt#L27

Added line #L27 was not covered by tests
private val observationCollectionProvider: ObservationCollectionProvider,
private val observationsDocumentMapper: ObservationsDocumentMapper,
private val observationMapper: ObservationsDocumentMapper,
private val recordToObservationMapper: RecordToObservationMapper,

Check warning on line 31 in app/src/main/kotlin/edu/stanford/bdh/engagehf/health/HealthRepository.kt

View check run for this annotation

Codecov / codecov/patch

app/src/main/kotlin/edu/stanford/bdh/engagehf/health/HealthRepository.kt#L30-L31

Added lines #L30 - L31 were not covered by tests
@Dispatching.IO private val ioDispatcher: CoroutineDispatcher,
) {
private val logger by speziLogger()
Expand All @@ -46,8 +52,7 @@
logger.e(error) { "Error listening for latest observation in collection: ${collection.name}" }
trySend(Result.failure(error))
} else {
val documents = snapshot?.documents
val records: List<T> = documents?.mapNotNull { document ->
val records: List<T> = snapshot?.documents?.mapNotNull { document ->
observationsDocumentMapper.map(document)
} ?: emptyList()
trySend(Result.success(records))
Expand All @@ -73,6 +78,50 @@
suspend fun observeHeartRateRecords(): Flow<Result<List<HeartRateRecord>>> =
observe(ObservationCollection.HEART_RATE)

suspend fun saveRecord(record: Record): Result<Unit> {
val observations = recordToObservationMapper.map(record)
return withContext(ioDispatcher) {
runCatching {
val batch = firestore.batch()
observations.forEach { observation ->

Check warning on line 86 in app/src/main/kotlin/edu/stanford/bdh/engagehf/health/HealthRepository.kt

View check run for this annotation

Codecov / codecov/patch

app/src/main/kotlin/edu/stanford/bdh/engagehf/health/HealthRepository.kt#L82-L86

Added lines #L82 - L86 were not covered by tests
val collection = ObservationCollection.entries.find { collection ->
observation.code.coding.any { it.code == collection.loinc.code }

Check warning on line 88 in app/src/main/kotlin/edu/stanford/bdh/engagehf/health/HealthRepository.kt

View check run for this annotation

Codecov / codecov/patch

app/src/main/kotlin/edu/stanford/bdh/engagehf/health/HealthRepository.kt#L88

Added line #L88 was not covered by tests
}
val data = observationMapper.map(observation = observation)

Check warning on line 90 in app/src/main/kotlin/edu/stanford/bdh/engagehf/health/HealthRepository.kt

View check run for this annotation

Codecov / codecov/patch

app/src/main/kotlin/edu/stanford/bdh/engagehf/health/HealthRepository.kt#L90

Added line #L90 was not covered by tests
collection?.let { observationCollectionProvider.getCollection(it).document() }
?.let { docRef ->
batch.set(docRef, data)

Check warning on line 93 in app/src/main/kotlin/edu/stanford/bdh/engagehf/health/HealthRepository.kt

View check run for this annotation

Codecov / codecov/patch

app/src/main/kotlin/edu/stanford/bdh/engagehf/health/HealthRepository.kt#L93

Added line #L93 was not covered by tests
}
}
batch.commit().await().let { }

Check warning on line 96 in app/src/main/kotlin/edu/stanford/bdh/engagehf/health/HealthRepository.kt

View check run for this annotation

Codecov / codecov/patch

app/src/main/kotlin/edu/stanford/bdh/engagehf/health/HealthRepository.kt#L96

Added line #L96 was not covered by tests
}
}
}

private suspend fun deleteRecord(
recordId: String,
observationCollection: ObservationCollection,
): Result<Unit> {
return withContext(ioDispatcher) {
runCatching {
observationCollectionProvider.getCollection(observationCollection)
.document(recordId).delete().await().let { }

Check warning on line 108 in app/src/main/kotlin/edu/stanford/bdh/engagehf/health/HealthRepository.kt

View check run for this annotation

Codecov / codecov/patch

app/src/main/kotlin/edu/stanford/bdh/engagehf/health/HealthRepository.kt#L105-L108

Added lines #L105 - L108 were not covered by tests
}
}
}

suspend fun deleteWeightRecord(recordId: String): Result<Unit> {

Check warning on line 113 in app/src/main/kotlin/edu/stanford/bdh/engagehf/health/HealthRepository.kt

View check run for this annotation

Codecov / codecov/patch

app/src/main/kotlin/edu/stanford/bdh/engagehf/health/HealthRepository.kt#L113

Added line #L113 was not covered by tests
return deleteRecord(recordId, ObservationCollection.BODY_WEIGHT)
}

suspend fun deleteBloodPressureRecord(recordId: String): Result<Unit> {

Check warning on line 117 in app/src/main/kotlin/edu/stanford/bdh/engagehf/health/HealthRepository.kt

View check run for this annotation

Codecov / codecov/patch

app/src/main/kotlin/edu/stanford/bdh/engagehf/health/HealthRepository.kt#L117

Added line #L117 was not covered by tests
return deleteRecord(recordId, ObservationCollection.BLOOD_PRESSURE)
}

suspend fun deleteHeartRateRecord(recordId: String): Result<Unit> {

Check warning on line 121 in app/src/main/kotlin/edu/stanford/bdh/engagehf/health/HealthRepository.kt

View check run for this annotation

Codecov / codecov/patch

app/src/main/kotlin/edu/stanford/bdh/engagehf/health/HealthRepository.kt#L121

Added line #L121 was not covered by tests
return deleteRecord(recordId, ObservationCollection.HEART_RATE)
}

companion object {
const val DEFAULT_MAX_MONTHS = 6L
const val DATE_TIME_FIELD = "effectiveDateTime"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ private fun BoxScope.AddRecordFloatingIcon(
tab: HealthTab,
onAction: (HealthViewModel.Action) -> Unit,
) {
if (tab != HealthTab.Weight) return
if (tab == HealthTab.Symptoms) return
FloatingActionButton(
onClick = {
onAction(HealthViewModel.Action.AddRecord(tab = tab))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ data class HealthUiData(
val newestData: NewestHealthData? = null,
val averageData: AverageHealthData? = null,
val infoRowData: InfoRowData,
val valueFormatter: (Float) -> String,
) {
val selectedTimeRange = infoRowData.selectedTimeRange
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@
import androidx.health.connect.client.records.Record
import androidx.health.connect.client.records.WeightRecord
import edu.stanford.spezi.core.utils.LocaleProvider
import edu.stanford.spezi.core.utils.extensions.roundToDecimalPlaces
import java.time.DayOfWeek
import java.time.Instant
import java.time.LocalDate
import java.time.ZoneId
import java.time.ZonedDateTime
import java.time.format.DateTimeFormatter
import java.time.temporal.TemporalAdjusters
Expand All @@ -27,6 +30,11 @@
selectedTimeRange: TimeRange,
): HealthUiState {
val engageRecords = records.map { EngageRecord.from(it) }
.filter {
it.zonedDateTime.isAfter(
ZonedDateTime.now().minusMonths(getMaxMonths(selectedTimeRange))
)
}
return if (engageRecords.isEmpty()) {
HealthUiState.NoData(message = "No data available")
} else {
Expand Down Expand Up @@ -67,7 +75,8 @@
tableData = tableData,
newestData = newestData,
averageData = getAverageData(tableData),
infoRowData = generateHealthHeaderData(selectedTimeRange, newestData)
infoRowData = generateHealthHeaderData(selectedTimeRange, newestData),
valueFormatter = { valueFormatter(it, selectedTimeRange) }
)
}

Expand Down Expand Up @@ -100,10 +109,10 @@

private fun mapXValue(selectedTimeRange: TimeRange, zonedDateTime: ZonedDateTime): Float {
return when (selectedTimeRange) {
TimeRange.DAILY -> zonedDateTime.year.toFloat() + (zonedDateTime.dayOfYear - 1) / 365f
TimeRange.DAILY -> (zonedDateTime.year.toFloat() + (zonedDateTime.dayOfYear - 1) / 365f) * 10
TimeRange.WEEKLY -> (zonedDateTime.toEpochSecond() / (7 * 24 * 60 * 60)).toFloat()
TimeRange.MONTHLY -> zonedDateTime.year.toFloat() + (zonedDateTime.monthValue - 1) / 12f
}
}.roundToDecimalPlaces(places = 2)
}

private fun groupRecordsByTimeRange(
Expand Down Expand Up @@ -308,16 +317,34 @@

private fun getDefaultLocale() = localeProvider.getDefaultLocale()

companion object {
private const val DAILY_MAX_MONTHS = 1L
private const val WEEKLY_MAX_MONTHS = 3L
private const val MONTHLY_MAX_MONTHS = 6L
private fun valueFormatter(value: Float, timeRange: TimeRange): String {
val date = when (timeRange) {
TimeRange.DAILY -> {
val actualValue = value * 10
val year = actualValue.toInt()
val dayOfYearFraction = actualValue - year
val dayOfYear = (dayOfYearFraction * 365).toInt() + 1
ZonedDateTime.of(year, 1, 1, 0, 0, 0, 0, ZoneId.systemDefault())
.plusDays((dayOfYear - 1).toLong())

Check warning on line 328 in app/src/main/kotlin/edu/stanford/bdh/engagehf/health/HealthUiStateMapper.kt

View check run for this annotation

Codecov / codecov/patch

app/src/main/kotlin/edu/stanford/bdh/engagehf/health/HealthUiStateMapper.kt#L323-L328

Added lines #L323 - L328 were not covered by tests
}

const val EPOCH_SECONDS_DIVISOR = 60.0f
const val ADAPTIVE_Y_VALUES_FRACTION = 1.05f
TimeRange.WEEKLY -> ZonedDateTime.ofInstant(
Instant.ofEpochSecond(
value.toLong() * 7 * 24 * 60 * 60
), ZoneId.systemDefault()

Check warning on line 334 in app/src/main/kotlin/edu/stanford/bdh/engagehf/health/HealthUiStateMapper.kt

View check run for this annotation

Codecov / codecov/patch

app/src/main/kotlin/edu/stanford/bdh/engagehf/health/HealthUiStateMapper.kt#L331-L334

Added lines #L331 - L334 were not covered by tests
)

private const val MONTH_DAY_TIME_PATTERN = "MMM dd HH:mm"
private const val MONTH_YEAR_PATTERN = "MMM yy"
TimeRange.MONTHLY -> {
val year = value.toInt()
val month = ((value - year) * 12).toInt() + 1
ZonedDateTime.of(year, month, 1, 0, 0, 0, 0, ZoneId.systemDefault())

Check warning on line 340 in app/src/main/kotlin/edu/stanford/bdh/engagehf/health/HealthUiStateMapper.kt

View check run for this annotation

Codecov / codecov/patch

app/src/main/kotlin/edu/stanford/bdh/engagehf/health/HealthUiStateMapper.kt#L338-L340

Added lines #L338 - L340 were not covered by tests
}
}
val pattern = when (timeRange) {
TimeRange.DAILY, TimeRange.WEEKLY -> "MMM dd"
TimeRange.MONTHLY -> "MMM yy"

Check warning on line 345 in app/src/main/kotlin/edu/stanford/bdh/engagehf/health/HealthUiStateMapper.kt

View check run for this annotation

Codecov / codecov/patch

app/src/main/kotlin/edu/stanford/bdh/engagehf/health/HealthUiStateMapper.kt#L344-L345

Added lines #L344 - L345 were not covered by tests
}
return date.format(DateTimeFormatter.ofPattern(pattern))

Check warning on line 347 in app/src/main/kotlin/edu/stanford/bdh/engagehf/health/HealthUiStateMapper.kt

View check run for this annotation

Codecov / codecov/patch

app/src/main/kotlin/edu/stanford/bdh/engagehf/health/HealthUiStateMapper.kt#L347

Added line #L347 was not covered by tests
}

private data class ValueUnit(val value: Double, val unit: String)
Expand Down Expand Up @@ -347,4 +374,16 @@
}
}
}

companion object {
private const val DAILY_MAX_MONTHS = 1L
private const val WEEKLY_MAX_MONTHS = 3L
private const val MONTHLY_MAX_MONTHS = 6L

const val EPOCH_SECONDS_DIVISOR = 60.0f
const val ADAPTIVE_Y_VALUES_FRACTION = 1.05f

private const val MONTH_DAY_TIME_PATTERN = "MMM dd HH:mm"
private const val MONTH_YEAR_PATTERN = "MMM yy"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import dagger.hilt.android.lifecycle.HiltViewModel
import edu.stanford.bdh.engagehf.bluetooth.component.BottomSheetEvents
import edu.stanford.bdh.engagehf.health.HealthAction
import edu.stanford.bdh.engagehf.health.HealthRepository
import edu.stanford.bdh.engagehf.health.HealthUiState
import edu.stanford.bdh.engagehf.health.HealthUiStateMapper
import edu.stanford.bdh.engagehf.health.TimeRange
import edu.stanford.spezi.core.logging.speziLogger
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.flow.update
Expand All @@ -19,9 +19,8 @@
class BloodPressureViewModel @Inject internal constructor(
private val uiStateMapper: HealthUiStateMapper,
private val healthRepository: HealthRepository,
private val bottomSheetEvents: BottomSheetEvents,

Check warning on line 22 in app/src/main/kotlin/edu/stanford/bdh/engagehf/health/bloodpressure/BloodPressureViewModel.kt

View check run for this annotation

Codecov / codecov/patch

app/src/main/kotlin/edu/stanford/bdh/engagehf/health/bloodpressure/BloodPressureViewModel.kt#L22

Added line #L22 was not covered by tests
) : ViewModel() {
private val logger by speziLogger()

private val _uiState = MutableStateFlow<HealthUiState>(HealthUiState.Loading)
val uiState = _uiState.asStateFlow()

Expand Down Expand Up @@ -50,9 +49,16 @@

fun onAction(healthAction: HealthAction) {
when (healthAction) {
HealthAction.AddRecord -> logger.i { "AddRecord" }
is HealthAction.DeleteRecord -> logger.i { "DeleteRecord" }
HealthAction.DescriptionBottomSheet -> logger.i { "DescriptionBottomSheet" }
is HealthAction.DeleteRecord -> {
viewModelScope.launch {

Check warning on line 53 in app/src/main/kotlin/edu/stanford/bdh/engagehf/health/bloodpressure/BloodPressureViewModel.kt

View check run for this annotation

Codecov / codecov/patch

app/src/main/kotlin/edu/stanford/bdh/engagehf/health/bloodpressure/BloodPressureViewModel.kt#L53

Added line #L53 was not covered by tests
healthRepository.deleteBloodPressureRecord(healthAction.recordId)
}
}

HealthAction.DescriptionBottomSheet -> {
bottomSheetEvents.emit(BottomSheetEvents.Event.BloodPressureDescriptionBottomSheet)

Check warning on line 59 in app/src/main/kotlin/edu/stanford/bdh/engagehf/health/bloodpressure/BloodPressureViewModel.kt

View check run for this annotation

Codecov / codecov/patch

app/src/main/kotlin/edu/stanford/bdh/engagehf/health/bloodpressure/BloodPressureViewModel.kt#L59

Added line #L59 was not covered by tests
}

is HealthAction.ToggleTimeRangeDropdown -> {
_uiState.update {
uiStateMapper.mapToggleTimeRange(healthAction, it)
Expand Down
Loading
Loading