From 02968b9b7a3b4dd1a99441ea6d3f36d67f46f92b Mon Sep 17 00:00:00 2001 From: dotasek Date: Tue, 15 Mar 2022 12:58:59 -0400 Subject: [PATCH] Add tests and changes for DateTime conversion --- .../primitivetypes14_30/DateTime14_30.java | 6 +-- .../primitivetypes14_40/DateTime14_40.java | 6 +-- .../primitivetypes14_50/DateTime14_50.java | 6 +-- .../VersionConvertorPrimitiveTypeTests.java | 40 ++++++++++++++++++- 4 files changed, 45 insertions(+), 13 deletions(-) diff --git a/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/conv14_30/datatypes14_30/primitivetypes14_30/DateTime14_30.java b/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/conv14_30/datatypes14_30/primitivetypes14_30/DateTime14_30.java index fd82da33d..38d3655e9 100644 --- a/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/conv14_30/datatypes14_30/primitivetypes14_30/DateTime14_30.java +++ b/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/conv14_30/datatypes14_30/primitivetypes14_30/DateTime14_30.java @@ -5,15 +5,13 @@ import org.hl7.fhir.exceptions.FHIRException; public class DateTime14_30 { public static org.hl7.fhir.dstu3.model.DateTimeType convertDateTime(org.hl7.fhir.dstu2016may.model.DateTimeType src) throws FHIRException { - org.hl7.fhir.dstu3.model.DateTimeType tgt = new org.hl7.fhir.dstu3.model.DateTimeType(); - if (src.hasValue()) tgt.setValue(src.getValue()); + org.hl7.fhir.dstu3.model.DateTimeType tgt = src.hasValue() ? new org.hl7.fhir.dstu3.model.DateTimeType(src.getValueAsString()) : new org.hl7.fhir.dstu3.model.DateTimeType(); ConversionContext14_30.INSTANCE.getVersionConvertor_14_30().copyElement(src, tgt); return tgt; } public static org.hl7.fhir.dstu2016may.model.DateTimeType convertDateTime(org.hl7.fhir.dstu3.model.DateTimeType src) throws FHIRException { - org.hl7.fhir.dstu2016may.model.DateTimeType tgt = new org.hl7.fhir.dstu2016may.model.DateTimeType(); - if (src.hasValue()) tgt.setValue(src.getValue()); + org.hl7.fhir.dstu2016may.model.DateTimeType tgt = src.hasValue() ? new org.hl7.fhir.dstu2016may.model.DateTimeType(src.getValueAsString()) : new org.hl7.fhir.dstu2016may.model.DateTimeType(); 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/DateTime14_40.java b/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/conv14_40/datatypes14_40/primitivetypes14_40/DateTime14_40.java index ddf0b36e6..53d0727d5 100644 --- a/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/conv14_40/datatypes14_40/primitivetypes14_40/DateTime14_40.java +++ b/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/conv14_40/datatypes14_40/primitivetypes14_40/DateTime14_40.java @@ -5,15 +5,13 @@ import org.hl7.fhir.exceptions.FHIRException; public class DateTime14_40 { public static org.hl7.fhir.r4.model.DateTimeType convertDateTime(org.hl7.fhir.dstu2016may.model.DateTimeType src) throws FHIRException { - org.hl7.fhir.r4.model.DateTimeType tgt = new org.hl7.fhir.r4.model.DateTimeType(); - if (src.hasValue()) tgt.setValue(src.getValue()); + org.hl7.fhir.r4.model.DateTimeType tgt = src.hasValue() ? new org.hl7.fhir.r4.model.DateTimeType(src.getValueAsString()) : new org.hl7.fhir.r4.model.DateTimeType(); ConversionContext14_40.INSTANCE.getVersionConvertor_14_40().copyElement(src, tgt); return tgt; } public static org.hl7.fhir.dstu2016may.model.DateTimeType convertDateTime(org.hl7.fhir.r4.model.DateTimeType src) throws FHIRException { - org.hl7.fhir.dstu2016may.model.DateTimeType tgt = new org.hl7.fhir.dstu2016may.model.DateTimeType(); - if (src.hasValue()) tgt.setValue(src.getValue()); + org.hl7.fhir.dstu2016may.model.DateTimeType tgt = src.hasValue() ? new org.hl7.fhir.dstu2016may.model.DateTimeType(src.getValueAsString()) : new org.hl7.fhir.dstu2016may.model.DateTimeType(); 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/DateTime14_50.java b/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/conv14_50/datatypes14_50/primitivetypes14_50/DateTime14_50.java index ecc611470..85902dc52 100644 --- a/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/conv14_50/datatypes14_50/primitivetypes14_50/DateTime14_50.java +++ b/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/conv14_50/datatypes14_50/primitivetypes14_50/DateTime14_50.java @@ -5,15 +5,13 @@ import org.hl7.fhir.exceptions.FHIRException; public class DateTime14_50 { public static org.hl7.fhir.r5.model.DateTimeType convertDateTime(org.hl7.fhir.dstu2016may.model.DateTimeType src) throws FHIRException { - org.hl7.fhir.r5.model.DateTimeType tgt = new org.hl7.fhir.r5.model.DateTimeType(); - if (src.hasValue()) tgt.setValue(src.getValue()); + org.hl7.fhir.r5.model.DateTimeType tgt = src.hasValue() ? new org.hl7.fhir.r5.model.DateTimeType(src.getValueAsString()) : new org.hl7.fhir.r5.model.DateTimeType(); ConversionContext14_50.INSTANCE.getVersionConvertor_14_50().copyElement(src, tgt); return tgt; } public static org.hl7.fhir.dstu2016may.model.DateTimeType convertDateTime(org.hl7.fhir.r5.model.DateTimeType src) throws FHIRException { - org.hl7.fhir.dstu2016may.model.DateTimeType tgt = new org.hl7.fhir.dstu2016may.model.DateTimeType(); - if (src.hasValue()) tgt.setValue(src.getValue()); + org.hl7.fhir.dstu2016may.model.DateTimeType tgt = src.hasValue() ? new org.hl7.fhir.dstu2016may.model.DateTimeType(src.getValueAsString()) : new org.hl7.fhir.dstu2016may.model.DateTimeType(); ConversionContext14_50.INSTANCE.getVersionConvertor_14_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 14925becf..c84f5e17c 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 @@ -99,8 +99,46 @@ public class VersionConvertorPrimitiveTypeTests { getDateTimeArgs(VersionConvertorFactory_10_50.class, org.hl7.fhir.dstu2.model.DateTimeType.class, org.hl7.fhir.dstu2.model.Type.class, org.hl7.fhir.r5.model.DateType.class, org.hl7.fhir.r5.model.DataType.class, - DEFAULT_DATE_PRECISION_STRINGS) + DEFAULT_DATE_PRECISION_STRINGS), + //DateTime + getDateTimeArgs(VersionConvertorFactory_10_30.class, + org.hl7.fhir.dstu2.model.DateTimeType.class, org.hl7.fhir.dstu2.model.Type.class, + org.hl7.fhir.dstu3.model.DateTimeType.class, org.hl7.fhir.dstu3.model.Type.class, + MILLISECOND_DATE_PRECISION_STRINGS), + getDateTimeArgs(VersionConvertorFactory_10_40.class, + org.hl7.fhir.dstu2.model.DateTimeType.class, org.hl7.fhir.dstu2.model.Type.class, + org.hl7.fhir.r4.model.DateTimeType.class, org.hl7.fhir.r4.model.Type.class, + MILLISECOND_DATE_PRECISION_STRINGS), + getDateTimeArgs(VersionConvertorFactory_10_50.class, + org.hl7.fhir.dstu2.model.DateTimeType.class, org.hl7.fhir.dstu2.model.Type.class, + org.hl7.fhir.r5.model.DateTimeType.class, org.hl7.fhir.r5.model.DataType.class, + MILLISECOND_DATE_PRECISION_STRINGS), + getDateTimeArgs(VersionConvertorFactory_14_30.class, + org.hl7.fhir.dstu2016may.model.DateTimeType.class, org.hl7.fhir.dstu2016may.model.Type.class, + org.hl7.fhir.dstu3.model.DateTimeType.class, org.hl7.fhir.dstu3.model.Type.class, + MILLISECOND_DATE_PRECISION_STRINGS), + getDateTimeArgs(VersionConvertorFactory_14_40.class, + org.hl7.fhir.dstu2016may.model.DateTimeType.class, org.hl7.fhir.dstu2016may.model.Type.class, + org.hl7.fhir.r4.model.DateTimeType.class, org.hl7.fhir.r4.model.Type.class, + MILLISECOND_DATE_PRECISION_STRINGS), + getDateTimeArgs(VersionConvertorFactory_14_50.class, + org.hl7.fhir.dstu2016may.model.DateTimeType.class, org.hl7.fhir.dstu2016may.model.Type.class, + org.hl7.fhir.r5.model.DateTimeType.class, org.hl7.fhir.r5.model.DataType.class, + MILLISECOND_DATE_PRECISION_STRINGS), + getDateTimeArgs(VersionConvertorFactory_30_40.class, + org.hl7.fhir.dstu3.model.DateTimeType.class, org.hl7.fhir.dstu3.model.Type.class, + org.hl7.fhir.r4.model.DateTimeType.class, org.hl7.fhir.r4.model.Type.class, + MILLISECOND_DATE_PRECISION_STRINGS), + getDateTimeArgs(VersionConvertorFactory_30_50.class, + org.hl7.fhir.dstu3.model.DateTimeType.class, org.hl7.fhir.dstu3.model.Type.class, + org.hl7.fhir.r5.model.DateTimeType.class, org.hl7.fhir.r5.model.DataType.class, + MILLISECOND_DATE_PRECISION_STRINGS), + 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) + ).flatMap(i -> i); }