Skip to content

Commit d3fd719

Browse files
Merge pull request #580 from bcgov/feature/HAPP-1855-date-format-handling
HAPP-1855
2 parents 7028302 + 6e95c9a commit d3fd719

File tree

15 files changed

+88
-67
lines changed

15 files changed

+88
-67
lines changed

app/src/main/java/ca/bc/gov/bchealth/compose/component/Button.kt

+1-5
Original file line numberDiff line numberDiff line change
@@ -206,11 +206,7 @@ fun HGTextButton(
206206
modifier,
207207
enabled,
208208
defaultHeight,
209-
contentPadding = if (leadingIcon != null) {
210-
ButtonDefaults.TextButtonContentPadding
211-
} else {
212-
ButtonDefaults.TextButtonContentPadding
213-
}
209+
contentPadding = ButtonDefaults.TextButtonContentPadding
214210
) {
215211
HGButtonContent(
216212
{

app/src/main/java/ca/bc/gov/bchealth/model/mapper/DtoToUIModelMapper.kt

+14-12
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,11 @@ import ca.bc.gov.common.model.services.BcCancerScreeningDataDto
3232
import ca.bc.gov.common.model.services.DiagnosticImagingDataDto
3333
import ca.bc.gov.common.model.specialauthority.SpecialAuthorityDto
3434
import ca.bc.gov.common.model.test.CovidOrderWithCovidTestDto
35+
import ca.bc.gov.common.utils.dateString
3536
import ca.bc.gov.common.utils.toDate
3637
import ca.bc.gov.common.utils.toDateTimeString
3738
import ca.bc.gov.common.utils.toLocalDateTimeInstant
39+
import ca.bc.gov.common.utils.toPST
3840
import java.time.Instant
3941
import java.time.LocalDate
4042

@@ -101,7 +103,7 @@ fun ClinicalDocumentDto.toUiModel() =
101103
fun LabOrderWithLabTestDto.toUiModel(): HealthRecordItem {
102104
var description = ""
103105
description = mapOrderStatus(labOrder.orderStatus ?: "").plus("")
104-
.plus(labOrder.timelineDateTime.toDate())
106+
.plus(labOrder.timelineDateTime.dateString())
105107
return HealthRecordItem(
106108
patientId = labOrder.patientId,
107109
title = labOrder.commonName ?: "",
@@ -168,9 +170,9 @@ fun CovidOrderWithCovidTestDto.toUiModel(): HealthRecordItem {
168170
patientId = covidOrder.patientId,
169171
recordId = covidOrder.id,
170172
title = "COVID-19 test result",
171-
description = "$testOutcome${date.toDate()}",
173+
description = "$testOutcome${date.dateString()}",
172174
icon = R.drawable.ic_health_record_covid_test,
173-
date = date,
175+
date = date.toPST(),
174176
healthRecordType = HealthRecordType.COVID_TEST_RECORD,
175177
dataSource = covidOrder.dataSource.name
176178
)
@@ -182,7 +184,7 @@ fun ImmunizationRecordWithForecastDto.toUiModel(): HealthRecordItem {
182184
patientId = immunizationRecord.patientId,
183185
recordId = immunizationRecord.id,
184186
title = immunizationRecord.immunizationName ?: "",
185-
description = immunizationRecord.dateOfImmunization.toDate(),
187+
description = immunizationRecord.dateOfImmunization.dateString(),
186188
icon = R.drawable.ic_health_record_vaccine,
187189
date = immunizationRecord.dateOfImmunization,
188190
healthRecordType = HealthRecordType.IMMUNIZATION_RECORD,
@@ -207,12 +209,12 @@ fun ImmunizationRecordWithForecastAndPatientDto.toUiModel(): ImmunizationRecordD
207209
return ImmunizationRecordDetailItem(
208210
id = immunizationRecordWithForecast.immunizationRecord.id,
209211
status = immunizationRecordWithForecast.immunizationRecord.status,
210-
dueDate = immunizationRecordWithForecast.immunizationForecast?.dueDate?.toDate(),
212+
dueDate = immunizationRecordWithForecast.immunizationForecast?.dueDate?.dateString(),
211213
name = immunizationRecordWithForecast.immunizationRecord.immunizationName,
212214
doseDetails = listOf(
213215
ImmunizationDoseDetailItem(
214216
id = immunizationRecordWithForecast.immunizationRecord.id,
215-
date = immunizationRecordWithForecast.immunizationRecord.dateOfImmunization.toDate(),
217+
date = immunizationRecordWithForecast.immunizationRecord.dateOfImmunization.dateString(),
216218
productName = immunizationRecordWithForecast.immunizationRecord.productName,
217219
immunizingAgent = immunizationRecordWithForecast.immunizationRecord.agentName,
218220
providerOrClinicName = immunizationRecordWithForecast.immunizationRecord.provideOrClinic,
@@ -228,7 +230,7 @@ fun HealthVisitsDto.toUiModel() =
228230
patientId = patientId,
229231
recordId = healthVisitId,
230232
title = specialtyDescription.orEmpty(),
231-
description = practitionerName.orEmpty() + "" + encounterDate.toDate(),
233+
description = practitionerName.orEmpty() + "" + encounterDate.dateString(),
232234
icon = R.drawable.ic_health_record_health_visit,
233235
date = encounterDate,
234236
healthRecordType = HealthRecordType.HEALTH_VISIT_RECORD,
@@ -239,7 +241,7 @@ fun SpecialAuthorityDto.toUiModel() = HealthRecordItem(
239241
patientId = patientId,
240242
recordId = specialAuthorityId,
241243
title = drugName.orEmpty(),
242-
description = requestStatus.orEmpty() + "" + requestedDate?.toDate(),
244+
description = requestStatus.orEmpty() + "" + requestedDate?.dateString(),
243245
icon = R.drawable.ic_health_record_special_authority,
244246
date = requestedDate!!,
245247
healthRecordType = HealthRecordType.SPECIAL_AUTHORITY_RECORD,
@@ -261,7 +263,7 @@ fun HospitalVisitDto.toUiModel() =
261263
fun ImmunizationRecommendationsDto.toUiModel() = RecommendationDetailItem(
262264
title = this.recommendedVaccinations.orPlaceholder(),
263265
status = this.status,
264-
date = this.agentDueDate?.toDate().orPlaceholder(),
266+
date = this.agentDueDate?.dateString().orPlaceholder(),
265267
)
266268

267269
fun DependentDto.toUiModel(currentDate: LocalDate) = DependentDetailItem(
@@ -288,7 +290,7 @@ fun CommentDto.toUiModel() = Comment(
288290
private fun ImmunizationForecastDto.toUiModel() = ForecastDetailItem(
289291
name = this.displayName.orPlaceholder(),
290292
status = this.status,
291-
date = this.dueDate.toDate(),
293+
date = this.dueDate.dateString(),
292294
)
293295

294296
enum class CovidTestResultStatus {
@@ -305,7 +307,7 @@ private fun DiagnosticImagingDataDto.toUiModel() = HealthRecordItem(
305307
patientId = patientId,
306308
icon = R.drawable.ic_health_record_diagnostic_imaging,
307309
title = modality.orEmpty(),
308-
description = if (isUpdated) { "Updated" } else { examStatus } + "" + examDate?.toDate(),
310+
description = if (isUpdated) { "Updated" } else { examStatus } + "" + examDate?.dateString(),
309311
date = examDate!!,
310312
healthRecordType = HealthRecordType.DIAGNOSTIC_IMAGING,
311313
dataSource = null
@@ -320,7 +322,7 @@ fun BcCancerScreeningDataDto.toUiModel() = HealthRecordItem(
320322
patientId = patientId,
321323
icon = R.drawable.ic_health_record_bc_cancer_screening,
322324
title = if (eventType == "Recall") { "BC Cancer Screening Reminder Letter" } else { "BC Cancer Screening Result Letter" },
323-
description = programName + "" + if (eventType == "Recall") { eventDateTime } else { resultDateTime }?.toDate(),
325+
description = programName + "" + if (eventType == "Recall") { eventDateTime } else { resultDateTime }?.dateString(),
324326
date = if (eventType == "Recall") { eventDateTime !! } else { resultDateTime!! },
325327
healthRecordType = HealthRecordType.BC_CANCER_SCREENING,
326328
dataSource = null

app/src/main/java/ca/bc/gov/bchealth/ui/dependents/profile/DependentProfileViewModel.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import androidx.lifecycle.ViewModel
55
import androidx.lifecycle.viewModelScope
66
import ca.bc.gov.bchealth.R
77
import ca.bc.gov.common.model.dependents.DependentDto
8-
import ca.bc.gov.common.utils.toDate
8+
import ca.bc.gov.common.utils.dateString
99
import ca.bc.gov.repository.DependentsRepository
1010
import dagger.hilt.android.lifecycle.HiltViewModel
1111
import kotlinx.coroutines.flow.MutableStateFlow
@@ -43,7 +43,7 @@ class DependentProfileViewModel @Inject constructor(
4343
),
4444
DependentProfileItem(
4545
label = R.string.dependents_profile_dob,
46-
value = dependentDto.dateOfBirth.toDate()
46+
value = dependentDto.dateOfBirth.dateString()
4747
),
4848
)
4949

app/src/main/java/ca/bc/gov/bchealth/ui/healthrecord/HealthRecordViewModel.kt

+4-4
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import ca.bc.gov.common.exceptions.ServiceDownException
1111
import ca.bc.gov.common.model.AuthenticationStatus
1212
import ca.bc.gov.common.model.ProtectiveWordState
1313
import ca.bc.gov.common.model.relation.PatientWithMedicationRecordDto
14-
import ca.bc.gov.common.utils.toDate
14+
import ca.bc.gov.common.utils.dateToInstant
1515
import ca.bc.gov.common.utils.toStartOfDayInstant
1616
import ca.bc.gov.repository.CacheRepository
1717
import ca.bc.gov.repository.MedicationRecordRepository
@@ -128,13 +128,13 @@ class HealthRecordViewModel @Inject constructor(
128128

129129
private fun getFilterByDate(healthRecords: List<HealthRecordItem>, fromDate: String?, toDate: String?): MutableList<HealthRecordItem> {
130130
return if (!fromDate.isNullOrBlank() && !toDate.isNullOrBlank()) {
131-
healthRecords.filter { it.date.toStartOfDayInstant() >= fromDate.toDate() && it.date <= toDate.toDate() }
131+
healthRecords.filter { it.date.toStartOfDayInstant() >= fromDate.dateToInstant().toStartOfDayInstant() && it.date.toStartOfDayInstant() <= toDate.dateToInstant().toStartOfDayInstant() }
132132
.toMutableList()
133133
} else if (!fromDate.isNullOrBlank()) {
134-
healthRecords.filter { it.date.toStartOfDayInstant() >= fromDate.toDate() }
134+
healthRecords.filter { it.date.toStartOfDayInstant() >= fromDate.dateToInstant().toStartOfDayInstant() }
135135
.toMutableList()
136136
} else if (!toDate.isNullOrBlank()) {
137-
healthRecords.filter { it.date.toStartOfDayInstant() <= toDate.toDate() }.toMutableList()
137+
healthRecords.filter { it.date.toStartOfDayInstant() <= toDate.dateToInstant().toStartOfDayInstant() }.toMutableList()
138138
} else {
139139
healthRecords.toMutableList()
140140
}

app/src/main/java/ca/bc/gov/bchealth/ui/healthrecord/covidtests/CovidTestResultFragment.kt

+3-3
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import ca.bc.gov.bchealth.widget.AddCommentLayout
2222
import ca.bc.gov.common.model.patient.PatientDto
2323
import ca.bc.gov.common.model.test.CovidOrderDto
2424
import ca.bc.gov.common.model.test.CovidTestDto
25-
import ca.bc.gov.common.utils.toDateTimeString
25+
import ca.bc.gov.common.utils.dateTimeString
2626
import dagger.hilt.android.AndroidEntryPoint
2727

2828
private const val COVID_ORDER_ID = "COVID_ORDER_ID"
@@ -99,10 +99,10 @@ class CovidTestResultFragment(private val itemClickListener: ItemClickListener)
9999
getString(R.string.tested_on)
100100
.plus(" ")
101101
.plus(
102-
covidTest?.collectedDateTime?.toDateTimeString()
102+
covidTest?.collectedDateTime?.dateTimeString()
103103
)
104104
tvDot.text =
105-
covidTest?.collectedDateTime?.toDateTimeString().showIfNullOrBlank(requireContext())
105+
covidTest?.collectedDateTime?.dateTimeString().showIfNullOrBlank(requireContext())
106106
tvTestStatus.text = covidTest?.testStatus.showIfNullOrBlank(requireContext())
107107
tvTypeName.text = covidTest?.testType.showIfNullOrBlank(requireContext())
108108
tvProviderClinic.text = covidOrder.reportingLab.showIfNullOrBlank(requireContext())

app/src/main/java/ca/bc/gov/bchealth/ui/healthrecord/hospitalvisits/HospitalVisitDetailViewModel.kt

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import androidx.lifecycle.viewModelScope
55
import ca.bc.gov.bchealth.R
66
import ca.bc.gov.bchealth.ui.healthrecord.HealthRecordDetailItem
77
import ca.bc.gov.common.model.hospitalvisits.HospitalVisitDto
8-
import ca.bc.gov.common.utils.toDateTimeString
8+
import ca.bc.gov.common.utils.dateTimeString
99
import ca.bc.gov.repository.hospitalvisit.HospitalVisitRepository
1010
import dagger.hilt.android.lifecycle.HiltViewModel
1111
import kotlinx.coroutines.flow.MutableStateFlow
@@ -26,7 +26,7 @@ class HospitalVisitDetailViewModel @Inject constructor(
2626
try {
2727
val dto: HospitalVisitDto = repository.getHospitalVisit(hospitalVisitId)
2828

29-
val dischargeDate = dto.dischargeDate?.toDateTimeString().orEmpty()
29+
val dischargeDate = dto.dischargeDate?.dateTimeString().orEmpty()
3030

3131
val uiList: List<HealthRecordDetailItem> = listOf(
3232
HealthRecordDetailItem(
@@ -55,7 +55,7 @@ class HospitalVisitDetailViewModel @Inject constructor(
5555

5656
HealthRecordDetailItem(
5757
title = R.string.hospital_visits_detail_visit_date_title,
58-
description = dto.visitDate.toDateTimeString()
58+
description = dto.visitDate.dateTimeString()
5959
),
6060

6161
HealthRecordDetailItem(

app/src/main/java/ca/bc/gov/bchealth/ui/healthrecord/labtest/LabTestDetailViewModel.kt

+4-4
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ import ca.bc.gov.common.exceptions.NetworkConnectionException
88
import ca.bc.gov.common.exceptions.ServiceDownException
99
import ca.bc.gov.common.model.labtest.LabOrderWithLabTestDto
1010
import ca.bc.gov.common.model.labtest.LabOrderWithLabTestsAndPatientDto
11-
import ca.bc.gov.common.utils.toDate
12-
import ca.bc.gov.common.utils.toDateTimeString
11+
import ca.bc.gov.common.utils.dateString
12+
import ca.bc.gov.common.utils.dateTimeString
1313
import ca.bc.gov.repository.labtest.LabOrderRepository
1414
import ca.bc.gov.repository.worker.MobileConfigRepository
1515
import dagger.hilt.android.lifecycle.HiltViewModel
@@ -71,8 +71,8 @@ class LabTestDetailViewModel @Inject constructor(
7171
labTestDetails.add(
7272
LabTestDetail(
7373
title1 = R.string.collection_date,
74-
collectionDateTime = labOrderWithLabTestDto.labOrder.collectionDateTime?.toDate(),
75-
timelineDateTime = labOrderWithLabTestDto.labOrder.timelineDateTime.toDateTimeString(),
74+
collectionDateTime = labOrderWithLabTestDto.labOrder.collectionDateTime?.dateString(),
75+
timelineDateTime = labOrderWithLabTestDto.labOrder.timelineDateTime.dateTimeString(),
7676
title2 = R.string.ordering_provider,
7777
orderingProvider = labOrderWithLabTestDto.labOrder.orderingProvider,
7878
title3 = R.string.reporting_lab,

app/src/main/java/ca/bc/gov/bchealth/ui/healthrecord/specialauthority/SpecialAuthorityDetailViewModel.kt

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package ca.bc.gov.bchealth.ui.healthrecord.specialauthority
33
import androidx.lifecycle.ViewModel
44
import androidx.lifecycle.viewModelScope
55
import ca.bc.gov.bchealth.R
6-
import ca.bc.gov.common.utils.toDate
6+
import ca.bc.gov.common.utils.dateString
77
import ca.bc.gov.repository.specialauthority.SpecialAuthorityRepository
88
import dagger.hilt.android.lifecycle.HiltViewModel
99
import kotlinx.coroutines.flow.MutableStateFlow
@@ -50,13 +50,13 @@ class SpecialAuthorityDetailViewModel @Inject constructor(
5050
specialAuthorityDetailItems.add(
5151
SpecialAuthorityDetailItem(
5252
R.string.effective_date,
53-
specialAuthorityDto?.effectiveDate?.toDate() ?: "--"
53+
specialAuthorityDto?.effectiveDate?.dateString() ?: "--"
5454
)
5555
)
5656
specialAuthorityDetailItems.add(
5757
SpecialAuthorityDetailItem(
5858
R.string.expiry_date,
59-
specialAuthorityDto?.expiryDate?.toDate() ?: "--"
59+
specialAuthorityDto?.expiryDate?.dateString() ?: "--"
6060
)
6161
)
6262
specialAuthorityDetailItems.add(

app/src/main/java/ca/bc/gov/bchealth/ui/travelpass/FetchFederalTravelPassFragment.kt

+3-3
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ import ca.bc.gov.bchealth.viewmodel.RecentPhnDobViewModel
3232
import ca.bc.gov.common.model.analytics.AnalyticsAction
3333
import ca.bc.gov.common.model.analytics.AnalyticsActionData
3434
import ca.bc.gov.common.model.relation.PatientWithVaccineAndDosesDto
35-
import ca.bc.gov.common.utils.toDate
35+
import ca.bc.gov.common.utils.dateString
3636
import ca.bc.gov.common.utils.yyyy_MM_dd
3737
import ca.bc.gov.repository.model.PatientVaccineRecord
3838
import dagger.hilt.android.AndroidEntryPoint
@@ -168,8 +168,8 @@ class FetchFederalTravelPassFragment : BaseFragment(R.layout.fragment_fetch_trav
168168
patientDataDto.vaccineWithDoses?.doses?.let { doses ->
169169
viewModel.fetchVaccineRecord(
170170
phn,
171-
patientDataDto.patient.dateOfBirth.toDate(yyyy_MM_dd),
172-
doses.last().date.toDate(yyyy_MM_dd)
171+
patientDataDto.patient.dateOfBirth.dateString(yyyy_MM_dd),
172+
doses.last().date.dateString(yyyy_MM_dd)
173173
)
174174
}
175175
}

common/src/main/java/ca/bc/gov/common/utils/DateTimeExtentions.kt

+17-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ const val eee_dd_mmm_yyyy_hh_mm_ss_z = "EEE, dd MMM yyyy HH:mm:ss XXXX"
1717
private const val full_date_time_plus_time = "yyyy-MM-dd'T'HH:mm:ssXXX"
1818
private const val yyyy_MMM_dd_HH_mm_sss_long = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"
1919
private const val yyyy_MMM_dd_HH_mm_short = "yyyy-MM-dd'T'HH:mm:ss'Z'"
20+
private const val PST_ZONE_ID = "America/Los_Angeles"
2021

2122
fun Instant.toDateTimeString(dateFormat: String = yyyy_MMM_dd_HH_mm): String {
2223
val dateTime = LocalDateTime.ofInstant(this, ZoneOffset.UTC)
@@ -93,9 +94,24 @@ fun Instant.toStartOfDayInstant(): Instant {
9394
* provides the date time in UTC+00:00
9495
* */
9596
fun Instant.toLocalDateTimeInstant(): Instant? {
96-
return this.atZone(ZoneId.of("America/Los_Angeles"))
97+
return this.atZone(ZoneId.of(PST_ZONE_ID))
9798
?.toLocalDateTime()?.toInstant(ZoneOffset.UTC)
9899
}
99100

101+
fun Instant.toPST(): Instant {
102+
return this.atZone(ZoneId.of(PST_ZONE_ID))
103+
.toLocalDateTime().toInstant(ZoneOffset.UTC)
104+
}
105+
100106
fun Instant.toLocalDate(): LocalDate =
101107
this.atZone(ZoneOffset.UTC).toLocalDate()
108+
109+
fun String.dateTimeToInstant(): Instant = Instant.parse(this)
110+
111+
fun String.dateToInstant(): Instant = LocalDate.parse(this).atStartOfDay(ZoneId.of(PST_ZONE_ID)).toInstant()
112+
113+
fun Instant.dateTimeString(pattern: String = yyyy_MMM_dd_HH_mm): String {
114+
return atZone(ZoneId.of(PST_ZONE_ID)).format(DateTimeFormatter.ofPattern(pattern))
115+
}
116+
117+
fun Instant.dateString(pattern: String = yyyy_MMM_dd) = dateTimeString(pattern = pattern)

common/src/test/java/ca/bc/gov/common/model/dependents/DependentDtoTest.kt

+3
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ internal class DependentDtoTest {
4949
ownerId = "",
5050
delegateId = "",
5151
reasonCode = 0L,
52+
totalDelegateCount = 0,
5253
version = 0L,
54+
patientId = 0,
55+
isCacheValid = false
5356
)
5457
}
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
package ca.bc.gov.data.datasource.remote.model.base
22

3+
import com.google.gson.annotations.SerializedName
4+
35
/**
46
* @author Pinakin Kansara
57
*/
68
data class TermsOfServicePayload(
79
val id: String? = null,
810
val content: String? = null,
11+
@SerializedName("effectiveDateTime")
912
val effectiveDate: String? = null
1013
)

0 commit comments

Comments
 (0)