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: [ANDROAPPP-5753] formatting issues with attribute values on tei card dashboard #3702

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 @@ -6,6 +6,7 @@ import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.rule.ActivityTestRule
import org.dhis2.common.mockwebserver.MockWebServerRobot.Companion.API_OLD_TRACKED_ENTITY_PATH
import org.dhis2.common.mockwebserver.MockWebServerRobot.Companion.API_OLD_TRACKED_ENTITY_RESPONSE
import org.dhis2.commons.date.DateUtils
import org.dhis2.usescases.BaseTest
import org.dhis2.usescases.flow.teiFlow.entity.DateRegistrationUIModel
import org.dhis2.usescases.flow.teiFlow.entity.EnrollmentListUIModel
Expand All @@ -16,7 +17,6 @@ import org.hisp.dhis.android.core.mockwebserver.ResponseController
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
import java.text.SimpleDateFormat
import java.util.Date


Expand Down Expand Up @@ -95,9 +95,9 @@ class TeiFlowTest : BaseTest() {
)

private fun getCurrentDate(): String {
val sdf = SimpleDateFormat(DATE_FORMAT)
val sdf = DateUtils.uiDateFormat()
val dateFormat = sdf.format(Date())
return dateFormat.removePrefix("0")
return dateFormat
}

private fun prepareWomanProgrammeIntentAndLaunchActivity(ruleSearch: ActivityTestRule<SearchTEActivity>) {
Expand All @@ -117,7 +117,5 @@ class TeiFlowTest : BaseTest() {
const val ORG_UNIT = "Ngelehun CHC"
const val NAME = "Marta"
const val LASTNAME = "Stuart"

const val DATE_FORMAT = "dd/M/yyyy"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,13 @@ class ProgramEventTest : BaseTest() {
}
composeTestRule.waitForIdle()
programEventsRobot(composeTestRule) {
checkEventWasCreatedAndClosed("1/1/2001")
checkEventWasCreatedAndClosed()
}
}

@Test
fun shouldOpenExistingEvent() {
val eventDate = "15/3/2020"
val eventDate = "15/03/2020"
val eventOrgUnit = "Ngelehun CHC"

prepareProgramAndLaunchActivity(antenatalCare)
Expand All @@ -81,7 +81,7 @@ class ProgramEventTest : BaseTest() {
@Ignore("Flaky test, will be look om issue ANDROAPP-6030")
@Test
fun shouldCompleteAnEventAndReopenIt() {
val eventDate = "15/3/2020"
val eventDate = "15/03/2020"

prepareProgramAndLaunchActivity(antenatalCare)

Expand All @@ -107,7 +107,7 @@ class ProgramEventTest : BaseTest() {

@Test
fun shouldDeleteEvent() {
val eventDate = "15/3/2020"
val eventDate = "15/03/2020"

prepareProgramAndLaunchActivity(antenatalCare)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ import androidx.compose.ui.test.hasTestTag
import androidx.compose.ui.test.hasText
import androidx.compose.ui.test.junit4.ComposeContentTestRule
import androidx.compose.ui.test.onNodeWithText
import androidx.compose.ui.test.onRoot
import androidx.compose.ui.test.performClick
import androidx.compose.ui.test.printToLog
import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.action.ViewActions.click
import androidx.test.espresso.assertion.ViewAssertions.matches
Expand Down Expand Up @@ -44,7 +42,7 @@ class ProgramEventsRobot(val composeTestRule: ComposeContentTestRule) : BaseRobo
}

@OptIn(ExperimentalTestApi::class)
fun checkEventWasCreatedAndClosed(eventDate: String) {
fun checkEventWasCreatedAndClosed() {
composeTestRule.waitUntilAtLeastOneExists(hasTestTag("EVENT_ITEM"))
composeTestRule.onNode(
hasTestTag("EVENT_ITEM")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ class SearchTETest : BaseTest() {
private fun createDisplayListFields() = DisplayListFieldsUIModel(
"Sarah",
"Thompson",
"2001-01-01",
"01/01/2001",
"[email protected]",
"Main street 1",
"56",
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/org/dhis2/bindings/StringExtensions.kt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package org.dhis2.bindings

import android.content.Context
import org.dhis2.commons.date.DateUtils
import org.dhis2.commons.date.toDateSpan
import org.dhis2.utils.DateUtils
import timber.log.Timber
import java.util.Date

Expand Down Expand Up @@ -38,7 +38,7 @@ fun String.toDate(): Date {
}
if (date == null) {
try {
date = DateUtils.databaseDateFormatMillis().parse(this)
date = DateUtils.databaseDateFormat().parse(this)
} catch (e: Exception) {
Timber.d("wrong format")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ package org.dhis2.usescases.datasets.dataSetTable.dataSetSection

import org.dhis2.R
import org.dhis2.bindings.toDate
import org.dhis2.commons.date.DateUtils
import org.dhis2.commons.resources.ResourceManager
import org.dhis2.data.forms.dataentry.tablefields.FieldViewModel
import org.dhis2.utils.DateUtils
import org.hisp.dhis.android.core.common.ValueType
import org.hisp.dhis.android.core.dataelement.DataElement

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ private void setAttributeValue(SearchTeiModel searchTei, TrackedEntitySearchItem
String value = attribute.getValue();
String transformedValue;
if (value != null) {
transformedValue = ValueUtils.transformValue(d2, value, attribute.getValueType(), attribute.getOptionSet());
transformedValue = ValueUtils.Companion.transformValue(d2, value, attribute.getValueType(), attribute.getOptionSet());
} else {
transformedValue = sortingValueSetter.getUnknownLabel();
}
Expand Down Expand Up @@ -409,8 +409,8 @@ private void setOverdueEvents(@NonNull SearchTeiModel tei, Program selectedProgr

if (count > 0) {
tei.setHasOverdue(true);
Date scheduleDate = scheduleList.size() > 0 ? scheduleList.get(0).dueDate() : null;
Date overdueDate = overdueList.size() > 0 ? overdueList.get(0).dueDate() : null;
Date scheduleDate = !scheduleList.isEmpty() ? scheduleList.get(0).dueDate() : null;
Date overdueDate = !overdueList.isEmpty() ? overdueList.get(0).dueDate() : null;
Date dateToShow = null;
if (scheduleDate != null && overdueDate != null) {
if (scheduleDate.before(overdueDate)) {
Expand Down Expand Up @@ -530,8 +530,8 @@ private List<String> getTETypeAttributeUids(String teTypeUid) {
}

private int getTeiDefaultRes(TrackedEntityInstance tei) {
TrackedEntityType teiType = d2.trackedEntityModule().trackedEntityTypes().uid(tei.trackedEntityType()).blockingGet();
return resources.getObjectStyleDrawableResource(teiType.style().icon(), R.drawable.photo_temp_gray);
TrackedEntityType teiTypeValues = d2.trackedEntityModule().trackedEntityTypes().uid(tei.trackedEntityType()).blockingGet();
return resources.getObjectStyleDrawableResource(teiTypeValues.style().icon(), R.drawable.photo_temp_gray);
}

private List<TrackedEntityAttributeValue> getTrackedEntityAttributesForRelationship(TrackedEntityInstance tei, Program selectedProgram) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import org.dhis2.R
import org.dhis2.commons.data.SearchTeiModel
import org.dhis2.commons.date.DateUtils
import org.dhis2.commons.extensions.toFriendlyDate
import org.dhis2.commons.extensions.toFriendlyDateTime
import org.dhis2.commons.extensions.toPercentage
import org.dhis2.commons.filters.FilterManager
import org.dhis2.commons.idlingresource.SearchIdlingResourceSingleton
import org.dhis2.commons.network.NetworkUtils
Expand All @@ -38,7 +40,6 @@ import org.hisp.dhis.android.core.arch.helpers.Result
import org.hisp.dhis.android.core.common.ValueType
import org.hisp.dhis.android.core.maintenance.D2ErrorCode
import timber.log.Timber
import java.text.ParseException

const val TEI_TYPE_SEARCH_MAX_RESULTS = 5

Expand Down Expand Up @@ -223,7 +224,9 @@ class SearchTEIViewModel(
SearchScreenState.LIST -> setListScreen()
SearchScreenState.MAP -> setMapScreen()
SearchScreenState.ANALYTICS -> setAnalyticsScreen()
else -> {}
else -> {
// no-op
}
}
}

Expand Down Expand Up @@ -927,38 +930,21 @@ class SearchTEIViewModel(
val map = mutableMapOf<String, String>()
uiState.items.filter { !it.value.isNullOrEmpty() }
.forEach { item ->

when (item.valueType) {
ValueType.ORGANISATION_UNIT, ValueType.MULTI_TEXT -> {
map[item.uid] = (item.displayName ?: "")
}

ValueType.DATE, ValueType.AGE -> {
item.value?.let {
if (it.isNotEmpty()) {
val date = try {
DateUtils.oldUiDateFormat().parse(it)
} catch (e: ParseException) {
null
}
map[item.uid] = date?.let {
DateUtils.uiDateFormat().format(date)
} ?: it
}
map[item.uid] = it.toFriendlyDate()
}
}

ValueType.DATETIME -> {
item.value?.let {
if (it.isNotEmpty()) {
val date = try {
DateUtils.databaseDateFormatNoSeconds().parse(it)
} catch (e: ParseException) {
null
}
map[item.uid] = date?.let {
DateUtils.uiDateTimeFormat().format(date)
} ?: it
}
map[item.uid] = it.toFriendlyDateTime()
}
}

Expand All @@ -975,7 +961,9 @@ class SearchTEIViewModel(
}

ValueType.PERCENTAGE -> {
map[item.uid] = "${item.value}%"
item.value?.let {
map[item.uid] = it.toPercentage()
}
}

else -> {
Expand Down
Loading