001package org.hl7.fhir.convertors.conv30_50.datatypes30_50.complextypes30_50; 002 003import java.util.stream.Collectors; 004 005import org.hl7.fhir.convertors.context.ConversionContext30_50; 006import org.hl7.fhir.convertors.conv30_50.datatypes30_50.primitivetypes30_50.Decimal30_50; 007import org.hl7.fhir.convertors.conv30_50.datatypes30_50.primitivetypes30_50.UnsignedInt30_50; 008import org.hl7.fhir.exceptions.FHIRException; 009 010public class Timing30_50 { 011 public static org.hl7.fhir.r5.model.Timing convertTiming(org.hl7.fhir.dstu3.model.Timing src) throws FHIRException { 012 if (src == null) return null; 013 org.hl7.fhir.r5.model.Timing tgt = new org.hl7.fhir.r5.model.Timing(); 014 ConversionContext30_50.INSTANCE.getVersionConvertor_30_50().copyElement(src, tgt); 015 for (org.hl7.fhir.dstu3.model.DateTimeType t : src.getEvent()) tgt.addEvent(t.getValue()); 016 if (src.hasRepeat()) tgt.setRepeat(convertTimingRepeatComponent(src.getRepeat())); 017 if (src.hasCode()) tgt.setCode(CodeableConcept30_50.convertCodeableConcept(src.getCode())); 018 return tgt; 019 } 020 021 public static org.hl7.fhir.dstu3.model.Timing convertTiming(org.hl7.fhir.r5.model.Timing src) throws FHIRException { 022 if (src == null) return null; 023 org.hl7.fhir.dstu3.model.Timing tgt = new org.hl7.fhir.dstu3.model.Timing(); 024 ConversionContext30_50.INSTANCE.getVersionConvertor_30_50().copyElement(src, tgt); 025 for (org.hl7.fhir.r5.model.DateTimeType t : src.getEvent()) tgt.addEvent(t.getValue()); 026 if (src.hasRepeat()) tgt.setRepeat(convertTimingRepeatComponent(src.getRepeat())); 027 if (src.hasCode()) tgt.setCode(CodeableConcept30_50.convertCodeableConcept(src.getCode())); 028 return tgt; 029 } 030 031 public static org.hl7.fhir.r5.model.Timing.TimingRepeatComponent convertTimingRepeatComponent(org.hl7.fhir.dstu3.model.Timing.TimingRepeatComponent src) throws FHIRException { 032 if (src == null) return null; 033 org.hl7.fhir.r5.model.Timing.TimingRepeatComponent tgt = new org.hl7.fhir.r5.model.Timing.TimingRepeatComponent(); 034 ConversionContext30_50.INSTANCE.getVersionConvertor_30_50().copyElement(src, tgt); 035 if (src.hasBounds()) 036 tgt.setBounds(ConversionContext30_50.INSTANCE.getVersionConvertor_30_50().convertType(src.getBounds())); 037 if (src.hasCount()) tgt.setCount(src.getCount()); 038 if (src.hasCountMax()) tgt.setCountMax(src.getCountMax()); 039 if (src.hasDuration()) tgt.setDurationElement(Decimal30_50.convertDecimal(src.getDurationElement())); 040 if (src.hasDurationMax()) tgt.setDurationMaxElement(Decimal30_50.convertDecimal(src.getDurationMaxElement())); 041 if (src.hasDurationUnit()) tgt.setDurationUnitElement(convertUnitsOfTime(src.getDurationUnitElement())); 042 if (src.hasFrequency()) tgt.setFrequency(src.getFrequency()); 043 if (src.hasFrequencyMax()) tgt.setFrequencyMax(src.getFrequencyMax()); 044 if (src.hasPeriod()) tgt.setPeriodElement(Decimal30_50.convertDecimal(src.getPeriodElement())); 045 if (src.hasPeriodMax()) tgt.setPeriodMaxElement(Decimal30_50.convertDecimal(src.getPeriodMaxElement())); 046 if (src.hasPeriodUnit()) tgt.setPeriodUnitElement(convertUnitsOfTime(src.getPeriodUnitElement())); 047 tgt.setDayOfWeek(src.getDayOfWeek().stream().map(Timing30_50::convertDayOfWeek).collect(Collectors.toList())); 048 if (src.hasWhen()) 049 tgt.setWhen(src.getWhen().stream().map(Timing30_50::convertEventTiming).collect(Collectors.toList())); 050 for (org.hl7.fhir.dstu3.model.TimeType t : src.getTimeOfDay()) tgt.addTimeOfDay(t.getValue()); 051 if (src.hasOffset()) tgt.setOffsetElement(UnsignedInt30_50.convertUnsignedInt(src.getOffsetElement())); 052 return tgt; 053 } 054 055 public static org.hl7.fhir.dstu3.model.Timing.TimingRepeatComponent convertTimingRepeatComponent(org.hl7.fhir.r5.model.Timing.TimingRepeatComponent src) throws FHIRException { 056 if (src == null) return null; 057 org.hl7.fhir.dstu3.model.Timing.TimingRepeatComponent tgt = new org.hl7.fhir.dstu3.model.Timing.TimingRepeatComponent(); 058 ConversionContext30_50.INSTANCE.getVersionConvertor_30_50().copyElement(src, tgt); 059 if (src.hasBounds()) 060 tgt.setBounds(ConversionContext30_50.INSTANCE.getVersionConvertor_30_50().convertType(src.getBounds())); 061 if (src.hasCount()) tgt.setCount(src.getCount()); 062 if (src.hasCountMax()) tgt.setCountMax(src.getCountMax()); 063 if (src.hasDuration()) tgt.setDurationElement(Decimal30_50.convertDecimal(src.getDurationElement())); 064 if (src.hasDurationMax()) tgt.setDurationMaxElement(Decimal30_50.convertDecimal(src.getDurationMaxElement())); 065 if (src.hasDurationUnit()) tgt.setDurationUnitElement(convertUnitsOfTime(src.getDurationUnitElement())); 066 if (src.hasFrequency()) tgt.setFrequency(src.getFrequency()); 067 if (src.hasFrequencyMax()) tgt.setFrequencyMax(src.getFrequencyMax()); 068 if (src.hasPeriod()) tgt.setPeriodElement(Decimal30_50.convertDecimal(src.getPeriodElement())); 069 if (src.hasPeriodMax()) tgt.setPeriodMaxElement(Decimal30_50.convertDecimal(src.getPeriodMaxElement())); 070 if (src.hasPeriodUnit()) tgt.setPeriodUnitElement(convertUnitsOfTime(src.getPeriodUnitElement())); 071 tgt.setDayOfWeek(src.getDayOfWeek().stream().map(Timing30_50::convertDayOfWeek).collect(Collectors.toList())); 072 if (src.hasWhen()) 073 tgt.setWhen(src.getWhen().stream().map(Timing30_50::convertEventTiming).collect(Collectors.toList())); 074 for (org.hl7.fhir.r5.model.TimeType t : src.getTimeOfDay()) tgt.addTimeOfDay(t.getValue()); 075 if (src.hasOffset()) tgt.setOffsetElement(UnsignedInt30_50.convertUnsignedInt(src.getOffsetElement())); 076 return tgt; 077 } 078 079 static public org.hl7.fhir.r5.model.Enumeration<org.hl7.fhir.r5.model.Timing.UnitsOfTime> convertUnitsOfTime(org.hl7.fhir.dstu3.model.Enumeration<org.hl7.fhir.dstu3.model.Timing.UnitsOfTime> src) throws FHIRException { 080 if (src == null || src.isEmpty()) return null; 081 org.hl7.fhir.r5.model.Enumeration<org.hl7.fhir.r5.model.Timing.UnitsOfTime> tgt = new org.hl7.fhir.r5.model.Enumeration<>(new org.hl7.fhir.r5.model.Timing.UnitsOfTimeEnumFactory()); 082 ConversionContext30_50.INSTANCE.getVersionConvertor_30_50().copyElement(src, tgt); 083 if (src.getValue() == null) { 084 tgt.setValue(org.hl7.fhir.r5.model.Timing.UnitsOfTime.NULL); 085 } else { 086 switch (src.getValue()) { 087 case S: 088 tgt.setValue(org.hl7.fhir.r5.model.Timing.UnitsOfTime.S); 089 break; 090 case MIN: 091 tgt.setValue(org.hl7.fhir.r5.model.Timing.UnitsOfTime.MIN); 092 break; 093 case H: 094 tgt.setValue(org.hl7.fhir.r5.model.Timing.UnitsOfTime.H); 095 break; 096 case D: 097 tgt.setValue(org.hl7.fhir.r5.model.Timing.UnitsOfTime.D); 098 break; 099 case WK: 100 tgt.setValue(org.hl7.fhir.r5.model.Timing.UnitsOfTime.WK); 101 break; 102 case MO: 103 tgt.setValue(org.hl7.fhir.r5.model.Timing.UnitsOfTime.MO); 104 break; 105 case A: 106 tgt.setValue(org.hl7.fhir.r5.model.Timing.UnitsOfTime.A); 107 break; 108 default: 109 tgt.setValue(org.hl7.fhir.r5.model.Timing.UnitsOfTime.NULL); 110 break; 111 } 112 } 113 return tgt; 114 } 115 116 static public org.hl7.fhir.dstu3.model.Enumeration<org.hl7.fhir.dstu3.model.Timing.UnitsOfTime> convertUnitsOfTime(org.hl7.fhir.r5.model.Enumeration<org.hl7.fhir.r5.model.Timing.UnitsOfTime> src) throws FHIRException { 117 if (src == null || src.isEmpty()) return null; 118 org.hl7.fhir.dstu3.model.Enumeration<org.hl7.fhir.dstu3.model.Timing.UnitsOfTime> tgt = new org.hl7.fhir.dstu3.model.Enumeration<>(new org.hl7.fhir.dstu3.model.Timing.UnitsOfTimeEnumFactory()); 119 ConversionContext30_50.INSTANCE.getVersionConvertor_30_50().copyElement(src, tgt); 120 if (src.getValue() == null) { 121 tgt.setValue(org.hl7.fhir.dstu3.model.Timing.UnitsOfTime.NULL); 122 } else { 123 switch (src.getValue()) { 124 case S: 125 tgt.setValue(org.hl7.fhir.dstu3.model.Timing.UnitsOfTime.S); 126 break; 127 case MIN: 128 tgt.setValue(org.hl7.fhir.dstu3.model.Timing.UnitsOfTime.MIN); 129 break; 130 case H: 131 tgt.setValue(org.hl7.fhir.dstu3.model.Timing.UnitsOfTime.H); 132 break; 133 case D: 134 tgt.setValue(org.hl7.fhir.dstu3.model.Timing.UnitsOfTime.D); 135 break; 136 case WK: 137 tgt.setValue(org.hl7.fhir.dstu3.model.Timing.UnitsOfTime.WK); 138 break; 139 case MO: 140 tgt.setValue(org.hl7.fhir.dstu3.model.Timing.UnitsOfTime.MO); 141 break; 142 case A: 143 tgt.setValue(org.hl7.fhir.dstu3.model.Timing.UnitsOfTime.A); 144 break; 145 default: 146 tgt.setValue(org.hl7.fhir.dstu3.model.Timing.UnitsOfTime.NULL); 147 break; 148 } 149 } 150 return tgt; 151 } 152 153 static public org.hl7.fhir.r5.model.Enumeration<org.hl7.fhir.r5.model.Enumerations.DaysOfWeek> convertDayOfWeek(org.hl7.fhir.dstu3.model.Enumeration<org.hl7.fhir.dstu3.model.Timing.DayOfWeek> src) throws FHIRException { 154 if (src == null || src.isEmpty()) return null; 155 org.hl7.fhir.r5.model.Enumeration<org.hl7.fhir.r5.model.Enumerations.DaysOfWeek> tgt = new org.hl7.fhir.r5.model.Enumeration<>(new org.hl7.fhir.r5.model.Enumerations.DaysOfWeekEnumFactory()); 156 ConversionContext30_50.INSTANCE.getVersionConvertor_30_50().copyElement(src, tgt); 157 if (src.getValue() == null) { 158 tgt.setValue(org.hl7.fhir.r5.model.Enumerations.DaysOfWeek.NULL); 159 } else { 160 switch (src.getValue()) { 161 case MON: 162 tgt.setValue(org.hl7.fhir.r5.model.Enumerations.DaysOfWeek.MON); 163 break; 164 case TUE: 165 tgt.setValue(org.hl7.fhir.r5.model.Enumerations.DaysOfWeek.TUE); 166 break; 167 case WED: 168 tgt.setValue(org.hl7.fhir.r5.model.Enumerations.DaysOfWeek.WED); 169 break; 170 case THU: 171 tgt.setValue(org.hl7.fhir.r5.model.Enumerations.DaysOfWeek.THU); 172 break; 173 case FRI: 174 tgt.setValue(org.hl7.fhir.r5.model.Enumerations.DaysOfWeek.FRI); 175 break; 176 case SAT: 177 tgt.setValue(org.hl7.fhir.r5.model.Enumerations.DaysOfWeek.SAT); 178 break; 179 case SUN: 180 tgt.setValue(org.hl7.fhir.r5.model.Enumerations.DaysOfWeek.SUN); 181 break; 182 default: 183 tgt.setValue(org.hl7.fhir.r5.model.Enumerations.DaysOfWeek.NULL); 184 break; 185 } 186 } 187 return tgt; 188 } 189 190 static public org.hl7.fhir.dstu3.model.Enumeration<org.hl7.fhir.dstu3.model.Timing.DayOfWeek> convertDayOfWeek(org.hl7.fhir.r5.model.Enumeration<org.hl7.fhir.r5.model.Enumerations.DaysOfWeek> src) throws FHIRException { 191 if (src == null || src.isEmpty()) return null; 192 org.hl7.fhir.dstu3.model.Enumeration<org.hl7.fhir.dstu3.model.Timing.DayOfWeek> tgt = new org.hl7.fhir.dstu3.model.Enumeration<>(new org.hl7.fhir.dstu3.model.Timing.DayOfWeekEnumFactory()); 193 ConversionContext30_50.INSTANCE.getVersionConvertor_30_50().copyElement(src, tgt); 194 if (src.getValue() == null) { 195 tgt.setValue(org.hl7.fhir.dstu3.model.Timing.DayOfWeek.NULL); 196 } else { 197 switch (src.getValue()) { 198 case MON: 199 tgt.setValue(org.hl7.fhir.dstu3.model.Timing.DayOfWeek.MON); 200 break; 201 case TUE: 202 tgt.setValue(org.hl7.fhir.dstu3.model.Timing.DayOfWeek.TUE); 203 break; 204 case WED: 205 tgt.setValue(org.hl7.fhir.dstu3.model.Timing.DayOfWeek.WED); 206 break; 207 case THU: 208 tgt.setValue(org.hl7.fhir.dstu3.model.Timing.DayOfWeek.THU); 209 break; 210 case FRI: 211 tgt.setValue(org.hl7.fhir.dstu3.model.Timing.DayOfWeek.FRI); 212 break; 213 case SAT: 214 tgt.setValue(org.hl7.fhir.dstu3.model.Timing.DayOfWeek.SAT); 215 break; 216 case SUN: 217 tgt.setValue(org.hl7.fhir.dstu3.model.Timing.DayOfWeek.SUN); 218 break; 219 default: 220 tgt.setValue(org.hl7.fhir.dstu3.model.Timing.DayOfWeek.NULL); 221 break; 222 } 223 } 224 return tgt; 225 } 226 227 static public org.hl7.fhir.r5.model.Enumeration<org.hl7.fhir.r5.model.Timing.EventTiming> convertEventTiming(org.hl7.fhir.dstu3.model.Enumeration<org.hl7.fhir.dstu3.model.Timing.EventTiming> src) throws FHIRException { 228 if (src == null || src.isEmpty()) return null; 229 org.hl7.fhir.r5.model.Enumeration<org.hl7.fhir.r5.model.Timing.EventTiming> tgt = new org.hl7.fhir.r5.model.Enumeration<>(new org.hl7.fhir.r5.model.Timing.EventTimingEnumFactory()); 230 ConversionContext30_50.INSTANCE.getVersionConvertor_30_50().copyElement(src, tgt); 231 if (src.getValue() == null) { 232 tgt.setValue(org.hl7.fhir.r5.model.Timing.EventTiming.NULL); 233 } else { 234 switch (src.getValue()) { 235 case MORN: 236 tgt.setValue(org.hl7.fhir.r5.model.Timing.EventTiming.MORN); 237 break; 238 case AFT: 239 tgt.setValue(org.hl7.fhir.r5.model.Timing.EventTiming.AFT); 240 break; 241 case EVE: 242 tgt.setValue(org.hl7.fhir.r5.model.Timing.EventTiming.EVE); 243 break; 244 case NIGHT: 245 tgt.setValue(org.hl7.fhir.r5.model.Timing.EventTiming.NIGHT); 246 break; 247 case PHS: 248 tgt.setValue(org.hl7.fhir.r5.model.Timing.EventTiming.PHS); 249 break; 250 case HS: 251 tgt.setValue(org.hl7.fhir.r5.model.Timing.EventTiming.HS); 252 break; 253 case WAKE: 254 tgt.setValue(org.hl7.fhir.r5.model.Timing.EventTiming.WAKE); 255 break; 256 case C: 257 tgt.setValue(org.hl7.fhir.r5.model.Timing.EventTiming.C); 258 break; 259 case CM: 260 tgt.setValue(org.hl7.fhir.r5.model.Timing.EventTiming.CM); 261 break; 262 case CD: 263 tgt.setValue(org.hl7.fhir.r5.model.Timing.EventTiming.CD); 264 break; 265 case CV: 266 tgt.setValue(org.hl7.fhir.r5.model.Timing.EventTiming.CV); 267 break; 268 case AC: 269 tgt.setValue(org.hl7.fhir.r5.model.Timing.EventTiming.AC); 270 break; 271 case ACM: 272 tgt.setValue(org.hl7.fhir.r5.model.Timing.EventTiming.ACM); 273 break; 274 case ACD: 275 tgt.setValue(org.hl7.fhir.r5.model.Timing.EventTiming.ACD); 276 break; 277 case ACV: 278 tgt.setValue(org.hl7.fhir.r5.model.Timing.EventTiming.ACV); 279 break; 280 case PC: 281 tgt.setValue(org.hl7.fhir.r5.model.Timing.EventTiming.PC); 282 break; 283 case PCM: 284 tgt.setValue(org.hl7.fhir.r5.model.Timing.EventTiming.PCM); 285 break; 286 case PCD: 287 tgt.setValue(org.hl7.fhir.r5.model.Timing.EventTiming.PCD); 288 break; 289 case PCV: 290 tgt.setValue(org.hl7.fhir.r5.model.Timing.EventTiming.PCV); 291 break; 292 default: 293 tgt.setValue(org.hl7.fhir.r5.model.Timing.EventTiming.NULL); 294 break; 295 } 296 } 297 return tgt; 298 } 299 300 static public org.hl7.fhir.dstu3.model.Enumeration<org.hl7.fhir.dstu3.model.Timing.EventTiming> convertEventTiming(org.hl7.fhir.r5.model.Enumeration<org.hl7.fhir.r5.model.Timing.EventTiming> src) throws FHIRException { 301 if (src == null || src.isEmpty()) return null; 302 org.hl7.fhir.dstu3.model.Enumeration<org.hl7.fhir.dstu3.model.Timing.EventTiming> tgt = new org.hl7.fhir.dstu3.model.Enumeration<>(new org.hl7.fhir.dstu3.model.Timing.EventTimingEnumFactory()); 303 ConversionContext30_50.INSTANCE.getVersionConvertor_30_50().copyElement(src, tgt); 304 if (src.getValue() == null) { 305 tgt.setValue(org.hl7.fhir.dstu3.model.Timing.EventTiming.NULL); 306 } else { 307 switch (src.getValue()) { 308 case MORN: 309 tgt.setValue(org.hl7.fhir.dstu3.model.Timing.EventTiming.MORN); 310 break; 311 case AFT: 312 tgt.setValue(org.hl7.fhir.dstu3.model.Timing.EventTiming.AFT); 313 break; 314 case EVE: 315 tgt.setValue(org.hl7.fhir.dstu3.model.Timing.EventTiming.EVE); 316 break; 317 case NIGHT: 318 tgt.setValue(org.hl7.fhir.dstu3.model.Timing.EventTiming.NIGHT); 319 break; 320 case PHS: 321 tgt.setValue(org.hl7.fhir.dstu3.model.Timing.EventTiming.PHS); 322 break; 323 case HS: 324 tgt.setValue(org.hl7.fhir.dstu3.model.Timing.EventTiming.HS); 325 break; 326 case WAKE: 327 tgt.setValue(org.hl7.fhir.dstu3.model.Timing.EventTiming.WAKE); 328 break; 329 case C: 330 tgt.setValue(org.hl7.fhir.dstu3.model.Timing.EventTiming.C); 331 break; 332 case CM: 333 tgt.setValue(org.hl7.fhir.dstu3.model.Timing.EventTiming.CM); 334 break; 335 case CD: 336 tgt.setValue(org.hl7.fhir.dstu3.model.Timing.EventTiming.CD); 337 break; 338 case CV: 339 tgt.setValue(org.hl7.fhir.dstu3.model.Timing.EventTiming.CV); 340 break; 341 case AC: 342 tgt.setValue(org.hl7.fhir.dstu3.model.Timing.EventTiming.AC); 343 break; 344 case ACM: 345 tgt.setValue(org.hl7.fhir.dstu3.model.Timing.EventTiming.ACM); 346 break; 347 case ACD: 348 tgt.setValue(org.hl7.fhir.dstu3.model.Timing.EventTiming.ACD); 349 break; 350 case ACV: 351 tgt.setValue(org.hl7.fhir.dstu3.model.Timing.EventTiming.ACV); 352 break; 353 case PC: 354 tgt.setValue(org.hl7.fhir.dstu3.model.Timing.EventTiming.PC); 355 break; 356 case PCM: 357 tgt.setValue(org.hl7.fhir.dstu3.model.Timing.EventTiming.PCM); 358 break; 359 case PCD: 360 tgt.setValue(org.hl7.fhir.dstu3.model.Timing.EventTiming.PCD); 361 break; 362 case PCV: 363 tgt.setValue(org.hl7.fhir.dstu3.model.Timing.EventTiming.PCV); 364 break; 365 default: 366 tgt.setValue(org.hl7.fhir.dstu3.model.Timing.EventTiming.NULL); 367 break; 368 } 369 } 370 return tgt; 371 } 372}