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