From 6730275277705ecc4fe343f798b6fa2bc89eed89 Mon Sep 17 00:00:00 2001 From: dotasek Date: Tue, 15 Mar 2022 15:59:22 -0400 Subject: [PATCH] Add tests and changes for Instant --- .../primitivetypes10_40/Instant10_40.java | 4 +- .../primitivetypes10_50/Instant10_50.java | 4 +- .../primitivetypes14_30/Instant14_30.java | 6 +-- .../primitivetypes14_40/Instant14_40.java | 6 +-- .../primitivetypes14_50/Instant14_50.java | 6 +-- .../primitive40_50/Instant40_50.java | 2 +- .../VersionConvertorPrimitiveTypeTests.java | 46 ++++++++++++++++++- 7 files changed, 55 insertions(+), 19 deletions(-) diff --git a/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/conv10_40/datatypes10_40/primitivetypes10_40/Instant10_40.java b/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/conv10_40/datatypes10_40/primitivetypes10_40/Instant10_40.java index 39b6b35a6..f314565c4 100644 --- a/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/conv10_40/datatypes10_40/primitivetypes10_40/Instant10_40.java +++ b/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/conv10_40/datatypes10_40/primitivetypes10_40/Instant10_40.java @@ -5,13 +5,13 @@ import org.hl7.fhir.exceptions.FHIRException; public class Instant10_40 { public static org.hl7.fhir.r4.model.InstantType convertInstant(org.hl7.fhir.dstu2.model.InstantType src) throws FHIRException { - org.hl7.fhir.r4.model.InstantType tgt = src.hasValue() ? new org.hl7.fhir.r4.model.InstantType(src.getValue()) : new org.hl7.fhir.r4.model.InstantType(); + org.hl7.fhir.r4.model.InstantType tgt = src.hasValue() ? new org.hl7.fhir.r4.model.InstantType(src.getValueAsString()) : new org.hl7.fhir.r4.model.InstantType(); ConversionContext10_40.INSTANCE.getVersionConvertor_10_40().copyElement(src, tgt); return tgt; } public static org.hl7.fhir.dstu2.model.InstantType convertInstant(org.hl7.fhir.r4.model.InstantType src) throws FHIRException { - org.hl7.fhir.dstu2.model.InstantType tgt = src.hasValue() ? new org.hl7.fhir.dstu2.model.InstantType(src.getValue()) : new org.hl7.fhir.dstu2.model.InstantType(); + org.hl7.fhir.dstu2.model.InstantType tgt = src.hasValue() ? new org.hl7.fhir.dstu2.model.InstantType(src.getValueAsString()) : new org.hl7.fhir.dstu2.model.InstantType(); ConversionContext10_40.INSTANCE.getVersionConvertor_10_40().copyElement(src, tgt); return tgt; } diff --git a/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/conv10_50/datatypes10_50/primitivetypes10_50/Instant10_50.java b/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/conv10_50/datatypes10_50/primitivetypes10_50/Instant10_50.java index b89ac9a91..ddc970d25 100644 --- a/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/conv10_50/datatypes10_50/primitivetypes10_50/Instant10_50.java +++ b/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/conv10_50/datatypes10_50/primitivetypes10_50/Instant10_50.java @@ -5,13 +5,13 @@ import org.hl7.fhir.exceptions.FHIRException; public class Instant10_50 { public static org.hl7.fhir.r5.model.InstantType convertInstant(org.hl7.fhir.dstu2.model.InstantType src) throws FHIRException { - org.hl7.fhir.r5.model.InstantType tgt = src.hasValue() ? new org.hl7.fhir.r5.model.InstantType(src.getValue()) : new org.hl7.fhir.r5.model.InstantType(); + org.hl7.fhir.r5.model.InstantType tgt = src.hasValue() ? new org.hl7.fhir.r5.model.InstantType(src.getValueAsString()) : new org.hl7.fhir.r5.model.InstantType(); ConversionContext10_50.INSTANCE.getVersionConvertor_10_50().copyElement(src, tgt); return tgt; } public static org.hl7.fhir.dstu2.model.InstantType convertInstant(org.hl7.fhir.r5.model.InstantType src) throws FHIRException { - org.hl7.fhir.dstu2.model.InstantType tgt = src.hasValue() ? new org.hl7.fhir.dstu2.model.InstantType(src.getValue()) : new org.hl7.fhir.dstu2.model.InstantType(); + org.hl7.fhir.dstu2.model.InstantType tgt = src.hasValue() ? new org.hl7.fhir.dstu2.model.InstantType(src.getValueAsString()) : new org.hl7.fhir.dstu2.model.InstantType(); ConversionContext10_50.INSTANCE.getVersionConvertor_10_50().copyElement(src, tgt); return tgt; } diff --git a/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/conv14_30/datatypes14_30/primitivetypes14_30/Instant14_30.java b/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/conv14_30/datatypes14_30/primitivetypes14_30/Instant14_30.java index fd2625a64..14615c8ac 100644 --- a/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/conv14_30/datatypes14_30/primitivetypes14_30/Instant14_30.java +++ b/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/conv14_30/datatypes14_30/primitivetypes14_30/Instant14_30.java @@ -5,15 +5,13 @@ import org.hl7.fhir.exceptions.FHIRException; public class Instant14_30 { public static org.hl7.fhir.dstu3.model.InstantType convertInstant(org.hl7.fhir.dstu2016may.model.InstantType src) throws FHIRException { - org.hl7.fhir.dstu3.model.InstantType tgt = new org.hl7.fhir.dstu3.model.InstantType(); - if (src.hasValue()) tgt.setValue(src.getValue()); + org.hl7.fhir.dstu3.model.InstantType tgt = src.hasValue() ? new org.hl7.fhir.dstu3.model.InstantType(src.getValueAsString()) : new org.hl7.fhir.dstu3.model.InstantType(); ConversionContext14_30.INSTANCE.getVersionConvertor_14_30().copyElement(src, tgt); return tgt; } public static org.hl7.fhir.dstu2016may.model.InstantType convertInstant(org.hl7.fhir.dstu3.model.InstantType src) throws FHIRException { - org.hl7.fhir.dstu2016may.model.InstantType tgt = new org.hl7.fhir.dstu2016may.model.InstantType(); - if (src.hasValue()) tgt.setValue(src.getValue()); + org.hl7.fhir.dstu2016may.model.InstantType tgt = src.hasValue() ? new org.hl7.fhir.dstu2016may.model.InstantType(src.getValueAsString()) : new org.hl7.fhir.dstu2016may.model.InstantType(); ConversionContext14_30.INSTANCE.getVersionConvertor_14_30().copyElement(src, tgt); return tgt; } diff --git a/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/conv14_40/datatypes14_40/primitivetypes14_40/Instant14_40.java b/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/conv14_40/datatypes14_40/primitivetypes14_40/Instant14_40.java index 971d4824a..501e0648e 100644 --- a/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/conv14_40/datatypes14_40/primitivetypes14_40/Instant14_40.java +++ b/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/conv14_40/datatypes14_40/primitivetypes14_40/Instant14_40.java @@ -5,15 +5,13 @@ import org.hl7.fhir.exceptions.FHIRException; public class Instant14_40 { public static org.hl7.fhir.r4.model.InstantType convertInstant(org.hl7.fhir.dstu2016may.model.InstantType src) throws FHIRException { - org.hl7.fhir.r4.model.InstantType tgt = new org.hl7.fhir.r4.model.InstantType(); - if (src.hasValue()) tgt.setValue(src.getValue()); + org.hl7.fhir.r4.model.InstantType tgt = src.hasValue() ? new org.hl7.fhir.r4.model.InstantType(src.getValueAsString()) : new org.hl7.fhir.r4.model.InstantType(); ConversionContext14_40.INSTANCE.getVersionConvertor_14_40().copyElement(src, tgt); return tgt; } public static org.hl7.fhir.dstu2016may.model.InstantType convertInstant(org.hl7.fhir.r4.model.InstantType src) throws FHIRException { - org.hl7.fhir.dstu2016may.model.InstantType tgt = new org.hl7.fhir.dstu2016may.model.InstantType(); - if (src.hasValue()) tgt.setValue(src.getValue()); + org.hl7.fhir.dstu2016may.model.InstantType tgt = src.hasValue() ? new org.hl7.fhir.dstu2016may.model.InstantType(src.getValueAsString()) : new org.hl7.fhir.dstu2016may.model.InstantType(); ConversionContext14_40.INSTANCE.getVersionConvertor_14_40().copyElement(src, tgt); return tgt; } diff --git a/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/conv14_50/datatypes14_50/primitivetypes14_50/Instant14_50.java b/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/conv14_50/datatypes14_50/primitivetypes14_50/Instant14_50.java index 0367ffc8e..83ab811c2 100644 --- a/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/conv14_50/datatypes14_50/primitivetypes14_50/Instant14_50.java +++ b/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/conv14_50/datatypes14_50/primitivetypes14_50/Instant14_50.java @@ -5,15 +5,13 @@ import org.hl7.fhir.exceptions.FHIRException; public class Instant14_50 { public static org.hl7.fhir.r5.model.InstantType convertInstant(org.hl7.fhir.dstu2016may.model.InstantType src) throws FHIRException { - org.hl7.fhir.r5.model.InstantType tgt = new org.hl7.fhir.r5.model.InstantType(); - if (src.hasValue()) tgt.setValue(src.getValue()); + org.hl7.fhir.r5.model.InstantType tgt = src.hasValue() ? new org.hl7.fhir.r5.model.InstantType(src.getValueAsString()) : new org.hl7.fhir.r5.model.InstantType(); ConversionContext14_50.INSTANCE.getVersionConvertor_14_50().copyElement(src, tgt); return tgt; } public static org.hl7.fhir.dstu2016may.model.InstantType convertInstant(org.hl7.fhir.r5.model.InstantType src) throws FHIRException { - org.hl7.fhir.dstu2016may.model.InstantType tgt = new org.hl7.fhir.dstu2016may.model.InstantType(); - if (src.hasValue()) tgt.setValue(src.getValue()); + org.hl7.fhir.dstu2016may.model.InstantType tgt = src.hasValue() ? new org.hl7.fhir.dstu2016may.model.InstantType(src.getValueAsString()) : new org.hl7.fhir.dstu2016may.model.InstantType(); ConversionContext14_50.INSTANCE.getVersionConvertor_14_50().copyElement(src, tgt); return tgt; } diff --git a/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/conv40_50/datatypes40_50/primitive40_50/Instant40_50.java b/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/conv40_50/datatypes40_50/primitive40_50/Instant40_50.java index 11aa91e5d..7c9c9e3aa 100644 --- a/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/conv40_50/datatypes40_50/primitive40_50/Instant40_50.java +++ b/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/conv40_50/datatypes40_50/primitive40_50/Instant40_50.java @@ -5,7 +5,7 @@ import org.hl7.fhir.exceptions.FHIRException; public class Instant40_50 { public static org.hl7.fhir.r5.model.InstantType convertInstant(org.hl7.fhir.r4.model.InstantType src) throws FHIRException { - org.hl7.fhir.r5.model.InstantType tgt = src.hasValue() ? new org.hl7.fhir.r5.model.InstantType(src.getValue()) : new org.hl7.fhir.r5.model.InstantType(); + org.hl7.fhir.r5.model.InstantType tgt = src.hasValue() ? new org.hl7.fhir.r5.model.InstantType(src.getValueAsString()) : new org.hl7.fhir.r5.model.InstantType(); ConversionContext40_50.INSTANCE.getVersionConvertor_40_50().copyElement(src, tgt); return tgt; } diff --git a/org.hl7.fhir.convertors/src/test/java/org/hl7/fhir/convertors/VersionConvertorPrimitiveTypeTests.java b/org.hl7.fhir.convertors/src/test/java/org/hl7/fhir/convertors/VersionConvertorPrimitiveTypeTests.java index c84f5e17c..4081b0275 100644 --- a/org.hl7.fhir.convertors/src/test/java/org/hl7/fhir/convertors/VersionConvertorPrimitiveTypeTests.java +++ b/org.hl7.fhir.convertors/src/test/java/org/hl7/fhir/convertors/VersionConvertorPrimitiveTypeTests.java @@ -27,6 +27,10 @@ public class VersionConvertorPrimitiveTypeTests { Stream.concat(Arrays.stream(SECOND_DATE_PRECISION_STRINGS),Stream.of("1933-01-02T13:45:12.3", "1933-01-02T13:45:12.3456")) .toArray(size -> (String[]) Array.newInstance(String.class, size)); + private static String[] INSTANT_PRECISION_STRINGS = { + "1933-01-02T13:45:12", "1933-01-02T13:45:12.3", "1933-01-02T13:45:12.3456" + }; + private static Stream getDateTimeArgs(Class versionConverterFactoryClazz, Class firstTypeClazz, Class firstTypeMethodClazz, Class secondTypeClazz, Class secondTypeMethodClazz, String[] testStrings) { return Arrays.stream(testStrings).map( it -> Arguments.of(versionConverterFactoryClazz, @@ -137,8 +141,46 @@ public class VersionConvertorPrimitiveTypeTests { getDateTimeArgs(VersionConvertorFactory_40_50.class, org.hl7.fhir.r4.model.DateTimeType.class, org.hl7.fhir.r4.model.Type.class, org.hl7.fhir.r5.model.DateTimeType.class, org.hl7.fhir.r5.model.DataType.class, - MILLISECOND_DATE_PRECISION_STRINGS) - + MILLISECOND_DATE_PRECISION_STRINGS), + + //Instant + getDateTimeArgs(VersionConvertorFactory_10_30.class, + org.hl7.fhir.dstu2.model.InstantType.class, org.hl7.fhir.dstu2.model.Type.class, + org.hl7.fhir.dstu3.model.InstantType.class, org.hl7.fhir.dstu3.model.Type.class, + INSTANT_PRECISION_STRINGS), + getDateTimeArgs(VersionConvertorFactory_10_40.class, + org.hl7.fhir.dstu2.model.InstantType.class, org.hl7.fhir.dstu2.model.Type.class, + org.hl7.fhir.r4.model.InstantType.class, org.hl7.fhir.r4.model.Type.class, + INSTANT_PRECISION_STRINGS), + getDateTimeArgs(VersionConvertorFactory_10_50.class, + org.hl7.fhir.dstu2.model.InstantType.class, org.hl7.fhir.dstu2.model.Type.class, + org.hl7.fhir.r5.model.InstantType.class, org.hl7.fhir.r5.model.DataType.class, + INSTANT_PRECISION_STRINGS), + getDateTimeArgs(VersionConvertorFactory_14_30.class, + org.hl7.fhir.dstu2016may.model.InstantType.class, org.hl7.fhir.dstu2016may.model.Type.class, + org.hl7.fhir.dstu3.model.InstantType.class, org.hl7.fhir.dstu3.model.Type.class, + INSTANT_PRECISION_STRINGS), + getDateTimeArgs(VersionConvertorFactory_14_40.class, + org.hl7.fhir.dstu2016may.model.InstantType.class, org.hl7.fhir.dstu2016may.model.Type.class, + org.hl7.fhir.r4.model.InstantType.class, org.hl7.fhir.r4.model.Type.class, + INSTANT_PRECISION_STRINGS), + getDateTimeArgs(VersionConvertorFactory_14_50.class, + org.hl7.fhir.dstu2016may.model.InstantType.class, org.hl7.fhir.dstu2016may.model.Type.class, + org.hl7.fhir.r5.model.InstantType.class, org.hl7.fhir.r5.model.DataType.class, + INSTANT_PRECISION_STRINGS), + getDateTimeArgs(VersionConvertorFactory_30_40.class, + org.hl7.fhir.dstu3.model.InstantType.class, org.hl7.fhir.dstu3.model.Type.class, + org.hl7.fhir.r4.model.InstantType.class, org.hl7.fhir.r4.model.Type.class, + INSTANT_PRECISION_STRINGS), + getDateTimeArgs(VersionConvertorFactory_30_50.class, + org.hl7.fhir.dstu3.model.InstantType.class, org.hl7.fhir.dstu3.model.Type.class, + org.hl7.fhir.r5.model.InstantType.class, org.hl7.fhir.r5.model.DataType.class, + INSTANT_PRECISION_STRINGS), + getDateTimeArgs(VersionConvertorFactory_40_50.class, + org.hl7.fhir.r4.model.InstantType.class, org.hl7.fhir.r4.model.Type.class, + org.hl7.fhir.r5.model.InstantType.class, org.hl7.fhir.r5.model.DataType.class, + INSTANT_PRECISION_STRINGS) + ).flatMap(i -> i); }