use of io.github.linuxforhealth.core.config.ConverterConfiguration in project hl7v2-fhir-converter by LinuxForHealth.
the class JvmTimeZoneIdTest method testEmptyDefaultTimeZoneYieldsJVMZoneId.
@Test
void testEmptyDefaultTimeZoneYieldsJVMZoneId() throws IOException {
// Create our own properties file
File configFile = new File(folder, "config.properties");
writeSimpleProperties(configFile);
System.setProperty(CONF_PROP_HOME, configFile.getParent());
ConverterConfiguration.reset();
// Prove that we're using our custom properties file with no ZoneId
ConverterConfiguration theConvConfig = ConverterConfiguration.getInstance();
// Four messages supported. (Proves we're using our created file, not the default.)
assertThat(theConvConfig.getSupportedMessageTemplates()).hasSize(13);
// Purposely empty
assertThat(theConvConfig.getZoneId()).isNull();
// IMPORTANT: TimeZoneId's are different than an offset. TimeZoneId's are a location.
// The offset of the location changes depending on whether Daylight savings time is in effect.
// Because we compare after processing, we can't compare locations, only offsets.
// It is critical that when we compare offsets, we start with the same date, so the same daylight savings rules apply!
// Otherwise a test might work only half of the year.
// Calculate the local server zone offset
// 20020202020000
LocalDateTime localDateTime = LocalDateTime.of(2002, Month.FEBRUARY, 2, 2, 0, 0);
String defaultLocalZone = TimeZone.getDefault().getID();
ZoneId localZoneId = ZoneId.of(defaultLocalZone);
ZonedDateTime localZonedDateTime = localDateTime.atZone(localZoneId);
ZoneOffset localOffset = localZonedDateTime.getOffset();
// PART 1
// Test the format utility (which will fallback to local server time and zone offset)
String testDateTime = DateUtil.formatToDateTimeWithDefaultZone("20020202020000");
DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ISO_OFFSET_DATE_TIME;
ZonedDateTime testZonedDateTime = ZonedDateTime.parse(testDateTime, dateTimeFormatter);
ZoneOffset testOffset = testZonedDateTime.getOffset();
// Offset from our function call test should equal offset of the local time
assertThat(testOffset).isEqualTo(localOffset);
// PART 2
// Do the same for a date going through the entire conversion
String hl7message = "MSH|^~\\&|||||20020202020000|1|PPR^PC1|331|P|2.3.1||\r" + "PID||||||||||||||||||||||||||||||\r" + "PV1||I||||||||||||||||||||||||||||||||||||||||||\r" + // PRB.2 to recordedDateTime (check time ZoneId)
"PRB|AD|20020202020000|K80.00^Cholelithiasis^I10|53956||||||||||||\r";
ConverterOptions customOptionsWithTenant = new Builder().withValidateResource().withPrettyPrint().build();
List<BundleEntryComponent> e = ResourceUtils.createFHIRBundleFromHL7MessageReturnEntryList(ftv, hl7message, customOptionsWithTenant);
// Find the condition from the FHIR bundle.
List<Resource> conditionResource = ResourceUtils.getResourceList(e, ResourceType.Condition);
assertThat(conditionResource).hasSize(1);
Condition condition = (Condition) conditionResource.get(0);
// Get the recordedDate value; convert it back to a zoned time; get the offset for comparison
// PRB.2
testDateTime = condition.getRecordedDateElement().getValueAsString();
testZonedDateTime = ZonedDateTime.parse(testDateTime, dateTimeFormatter);
testOffset = testZonedDateTime.getOffset();
// Offset from our test should equal offset of the local time
assertThat(testOffset).isEqualTo(localOffset);
// After the test, the properties file resets.
}
Aggregations