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

Added transform for converting datetimes to mountain time #16542

Merged
merged 2 commits into from
Nov 14, 2024
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 @@ -3,6 +3,7 @@ package gov.cdc.prime.router.fhirengine.translation.hl7.utils
import ca.uhn.fhir.model.api.TemporalPrecisionEnum
import fhirengine.translation.hl7.utils.FhirPathFunctions
import fhirengine.translation.hl7.utils.helpers.convertDateToAge
import gov.cdc.prime.router.common.DateUtilities
import gov.cdc.prime.router.fhirengine.translation.hl7.SchemaException
import org.hl7.fhir.r4.fhirpath.FHIRPathUtilityClasses.FunctionDetails
import org.hl7.fhir.r4.model.Base
Expand Down Expand Up @@ -445,11 +446,6 @@ object CustomFHIRFunctions : FhirPathFunctions {
throw SchemaException("Must call changeTimezone on a single element")
}

val inputDate = focus[0] as? BaseDateTimeType ?: throw SchemaException(
"Must call changeTimezone on a dateTime, instant, or date; " +
"was attempted on a ${focus[0].fhirType()}"
)

if (parameters == null || parameters[0].size != 1) {
throw SchemaException("Must pass a timezone as the parameter")
}
Expand All @@ -465,14 +461,41 @@ object CustomFHIRFunctions : FhirPathFunctions {
)
}

return when (inputDate.precision) {
TemporalPrecisionEnum.YEAR, TemporalPrecisionEnum.MONTH, TemporalPrecisionEnum.DAY, null -> mutableListOf(
inputDate
return if (focus[0] is StringType) {
if (focus[0].toString().length <= 8) { // we don't want to convert Date-only strings
return mutableListOf(StringType(focus[0].toString()))
}

// TODO: find a way to pass in these values from receiver settings

val dateTimeFormat = null
val convertPositiveDateTimeOffsetToNegative = null
val useHighPrecisionHeaderDateTimeFormat = null

val formattedDate = DateUtilities.formatDateForReceiver(
DateUtilities.parseDate((focus[0].toString())),
ZoneId.of(inputTimeZone),
dateTimeFormat ?: DateUtilities.DateTimeFormat.OFFSET,
convertPositiveDateTimeOffsetToNegative ?: false,
useHighPrecisionHeaderDateTimeFormat ?: false
)

TemporalPrecisionEnum.MINUTE, TemporalPrecisionEnum.SECOND, TemporalPrecisionEnum.MILLI -> mutableListOf(
DateTimeType(inputDate.value, inputDate.precision, timezonePassed)
mutableListOf(
StringType(formattedDate)
)
} else {
val inputDate = focus[0] as? BaseDateTimeType ?: throw SchemaException(
"Must call changeTimezone on a dateTime, instant, or date; " +
"was attempted on a ${focus[0].fhirType()}"
)

when (inputDate.precision) {
TemporalPrecisionEnum.YEAR, TemporalPrecisionEnum.MONTH, TemporalPrecisionEnum.DAY, null ->
mutableListOf(inputDate)

TemporalPrecisionEnum.MINUTE, TemporalPrecisionEnum.SECOND, TemporalPrecisionEnum.MILLI ->
mutableListOf(DateTimeType(inputDate.value, inputDate.precision, timezonePassed))
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
elements:
- name: hl7-datetime-to-local
resource: "Bundle.descendants().where(url='https://reportstream.cdc.gov/fhir/StructureDefinition/hl7v2-date-time')"
bundleProperty: "%resource.value[x]"
value: ["%resource.value.changeTimezone('America/Denver')"]


- name: message-date-time-to-local
resource: 'Bundle.entry.resource.ofType(MessageHeader).extension("https://reportstream.cdc.gov/fhir/StructureDefinition/msh-message-header").extension("MSH.7")'
condition: '%resource.value.exists()'
bundleProperty: '%resource.value[x]'
value: ["%resource.value.changeTimezone('America/Denver')"]