From 7876bfc3bddd46e65f029c50fdf4aebc103766df Mon Sep 17 00:00:00 2001 From: Lucero Velasco Date: Thu, 14 Nov 2024 09:43:52 -0700 Subject: [PATCH 1/2] added transform for converting datetimes to mountain time --- .../hl7/utils/CustomFHIRFunctions.kt | 41 ++++++++++++++----- .../common/datetime-to-local-mtz.yml | 21 ++++++++++ 2 files changed, 52 insertions(+), 10 deletions(-) create mode 100644 prime-router/src/main/resources/metadata/fhir_transforms/common/datetime-to-local-mtz.yml diff --git a/prime-router/src/main/kotlin/fhirengine/translation/hl7/utils/CustomFHIRFunctions.kt b/prime-router/src/main/kotlin/fhirengine/translation/hl7/utils/CustomFHIRFunctions.kt index c6900d23a94..b8aeb55183d 100644 --- a/prime-router/src/main/kotlin/fhirengine/translation/hl7/utils/CustomFHIRFunctions.kt +++ b/prime-router/src/main/kotlin/fhirengine/translation/hl7/utils/CustomFHIRFunctions.kt @@ -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 @@ -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") } @@ -465,14 +461,39 @@ 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())) + } + + 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)) + } } } } \ No newline at end of file diff --git a/prime-router/src/main/resources/metadata/fhir_transforms/common/datetime-to-local-mtz.yml b/prime-router/src/main/resources/metadata/fhir_transforms/common/datetime-to-local-mtz.yml new file mode 100644 index 00000000000..9d854f275dc --- /dev/null +++ b/prime-router/src/main/resources/metadata/fhir_transforms/common/datetime-to-local-mtz.yml @@ -0,0 +1,21 @@ + + +#elements: +# - name: datetime-to-local +# resource: "Bundle.entry.resource.ofType(Specimen).receivedTime.extension('https://reportstream.cdc.gov/fhir/StructureDefinition/hl7v2-date-time')" +# bundleProperty: "%resource.value[x]" +# value: ["%resource.value.changeTimezone('America/Denver')"] + + +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')"] From d5720aade7f5c122237d2b79157c6c407dcc3030 Mon Sep 17 00:00:00 2001 From: Lucero Velasco Date: Thu, 14 Nov 2024 09:51:30 -0700 Subject: [PATCH 2/2] todo and comment remove --- .../translation/hl7/utils/CustomFHIRFunctions.kt | 2 ++ .../fhir_transforms/common/datetime-to-local-mtz.yml | 9 --------- 2 files changed, 2 insertions(+), 9 deletions(-) diff --git a/prime-router/src/main/kotlin/fhirengine/translation/hl7/utils/CustomFHIRFunctions.kt b/prime-router/src/main/kotlin/fhirengine/translation/hl7/utils/CustomFHIRFunctions.kt index b8aeb55183d..819df5d2def 100644 --- a/prime-router/src/main/kotlin/fhirengine/translation/hl7/utils/CustomFHIRFunctions.kt +++ b/prime-router/src/main/kotlin/fhirengine/translation/hl7/utils/CustomFHIRFunctions.kt @@ -466,6 +466,8 @@ object CustomFHIRFunctions : FhirPathFunctions { 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 diff --git a/prime-router/src/main/resources/metadata/fhir_transforms/common/datetime-to-local-mtz.yml b/prime-router/src/main/resources/metadata/fhir_transforms/common/datetime-to-local-mtz.yml index 9d854f275dc..f87b4e3c7df 100644 --- a/prime-router/src/main/resources/metadata/fhir_transforms/common/datetime-to-local-mtz.yml +++ b/prime-router/src/main/resources/metadata/fhir_transforms/common/datetime-to-local-mtz.yml @@ -1,12 +1,3 @@ - - -#elements: -# - name: datetime-to-local -# resource: "Bundle.entry.resource.ofType(Specimen).receivedTime.extension('https://reportstream.cdc.gov/fhir/StructureDefinition/hl7v2-date-time')" -# bundleProperty: "%resource.value[x]" -# value: ["%resource.value.changeTimezone('America/Denver')"] - - elements: - name: hl7-datetime-to-local resource: "Bundle.descendants().where(url='https://reportstream.cdc.gov/fhir/StructureDefinition/hl7v2-date-time')"