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