001package org.hl7.fhir.convertors.conv10_40.datatypes10_40.complextypes10_40;
002
003import java.util.Collections;
004
005import org.hl7.fhir.convertors.context.ConversionContext10_40;
006import org.hl7.fhir.convertors.conv10_40.datatypes10_40.primitivetypes10_40.Decimal10_40;
007import org.hl7.fhir.exceptions.FHIRException;
008
009public class Timing10_40 {
010  public static org.hl7.fhir.r4.model.Timing convertTiming(org.hl7.fhir.dstu2.model.Timing src) throws FHIRException {
011    if (src == null || src.isEmpty()) return null;
012    org.hl7.fhir.r4.model.Timing tgt = new org.hl7.fhir.r4.model.Timing();
013    ConversionContext10_40.INSTANCE.getVersionConvertor_10_40().copyElement(src, tgt);
014    for (org.hl7.fhir.dstu2.model.DateTimeType t : src.getEvent()) tgt.addEvent(t.getValue());
015    if (src.hasRepeat()) tgt.setRepeat(convertTimingRepeatComponent(src.getRepeat()));
016    if (src.hasCode()) tgt.setCode(CodeableConcept10_40.convertCodeableConcept(src.getCode()));
017    return tgt;
018  }
019
020  public static org.hl7.fhir.dstu2.model.Timing convertTiming(org.hl7.fhir.r4.model.Timing src) throws FHIRException {
021    if (src == null || src.isEmpty()) return null;
022    org.hl7.fhir.dstu2.model.Timing tgt = new org.hl7.fhir.dstu2.model.Timing();
023    ConversionContext10_40.INSTANCE.getVersionConvertor_10_40().copyElement(src, tgt);
024    for (org.hl7.fhir.r4.model.DateTimeType t : src.getEvent()) tgt.addEvent(t.getValue());
025    if (src.hasRepeat()) tgt.setRepeat(convertTimingRepeatComponent(src.getRepeat()));
026    if (src.hasCode()) tgt.setCode(CodeableConcept10_40.convertCodeableConcept(src.getCode()));
027    return tgt;
028  }
029
030  public static org.hl7.fhir.r4.model.Timing.TimingRepeatComponent convertTimingRepeatComponent(org.hl7.fhir.dstu2.model.Timing.TimingRepeatComponent src) throws FHIRException {
031    if (src == null || src.isEmpty()) return null;
032    org.hl7.fhir.r4.model.Timing.TimingRepeatComponent tgt = new org.hl7.fhir.r4.model.Timing.TimingRepeatComponent();
033    ConversionContext10_40.INSTANCE.getVersionConvertor_10_40().copyElement(src, tgt);
034    if (src.hasBounds())
035      tgt.setBounds(ConversionContext10_40.INSTANCE.getVersionConvertor_10_40().convertType(src.getBounds()));
036    if (src.hasCount()) tgt.setCount(src.getCount());
037    if (src.hasDurationElement()) tgt.setDurationElement(Decimal10_40.convertDecimal(src.getDurationElement()));
038    if (src.hasDurationMaxElement())
039      tgt.setDurationMaxElement(Decimal10_40.convertDecimal(src.getDurationMaxElement()));
040    if (src.hasDurationUnits()) tgt.setDurationUnitElement(convertUnitsOfTime(src.getDurationUnitsElement()));
041    if (src.hasFrequency()) tgt.setFrequency(src.getFrequency());
042    if (src.hasFrequencyMax()) tgt.setFrequencyMax(src.getFrequencyMax());
043    if (src.hasPeriodElement()) tgt.setPeriodElement(Decimal10_40.convertDecimal(src.getPeriodElement()));
044    if (src.hasPeriodMaxElement()) tgt.setPeriodMaxElement(Decimal10_40.convertDecimal(src.getPeriodMaxElement()));
045    if (src.hasPeriodUnits()) tgt.setPeriodUnitElement(convertUnitsOfTime(src.getPeriodUnitsElement()));
046    if (src.hasWhen()) tgt.setWhen(Collections.singletonList(convertEventTiming(src.getWhenElement())));
047    return tgt;
048  }
049
050  public static org.hl7.fhir.dstu2.model.Timing.TimingRepeatComponent convertTimingRepeatComponent(org.hl7.fhir.r4.model.Timing.TimingRepeatComponent src) throws FHIRException {
051    if (src == null || src.isEmpty()) return null;
052    org.hl7.fhir.dstu2.model.Timing.TimingRepeatComponent tgt = new org.hl7.fhir.dstu2.model.Timing.TimingRepeatComponent();
053    ConversionContext10_40.INSTANCE.getVersionConvertor_10_40().copyElement(src, tgt);
054    if (src.hasBounds())
055      tgt.setBounds(ConversionContext10_40.INSTANCE.getVersionConvertor_10_40().convertType(src.getBounds()));
056    if (src.hasCount()) tgt.setCount(src.getCount());
057    if (src.hasDurationElement()) tgt.setDurationElement(Decimal10_40.convertDecimal(src.getDurationElement()));
058    if (src.hasDurationMaxElement())
059      tgt.setDurationMaxElement(Decimal10_40.convertDecimal(src.getDurationMaxElement()));
060    if (src.hasDurationUnit()) tgt.setDurationUnitsElement(convertUnitsOfTime(src.getDurationUnitElement()));
061    if (src.hasFrequency()) tgt.setFrequency(src.getFrequency());
062    if (src.hasFrequencyMax()) tgt.setFrequencyMax(src.getFrequencyMax());
063    if (src.hasPeriodElement()) tgt.setPeriodElement(Decimal10_40.convertDecimal(src.getPeriodElement()));
064    if (src.hasPeriodMaxElement()) tgt.setPeriodMaxElement(Decimal10_40.convertDecimal(src.getPeriodMaxElement()));
065    if (src.hasPeriodUnit()) tgt.setPeriodUnitsElement(convertUnitsOfTime(src.getPeriodUnitElement()));
066    if (src.hasWhen()) tgt.setWhenElement(convertEventTiming(src.getWhen().get(0)));
067    return tgt;
068  }
069
070  static public org.hl7.fhir.r4.model.Enumeration<org.hl7.fhir.r4.model.Timing.UnitsOfTime> convertUnitsOfTime(org.hl7.fhir.dstu2.model.Enumeration<org.hl7.fhir.dstu2.model.Timing.UnitsOfTime> src) throws FHIRException {
071    if (src == null || src.isEmpty()) return null;
072    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());
073    ConversionContext10_40.INSTANCE.getVersionConvertor_10_40().copyElement(src, tgt);
074    if (src.getValue() == null) {
075      tgt.setValue(org.hl7.fhir.r4.model.Timing.UnitsOfTime.NULL);
076    } else {
077      switch (src.getValue()) {
078        case S:
079          tgt.setValue(org.hl7.fhir.r4.model.Timing.UnitsOfTime.S);
080          break;
081        case MIN:
082          tgt.setValue(org.hl7.fhir.r4.model.Timing.UnitsOfTime.MIN);
083          break;
084        case H:
085          tgt.setValue(org.hl7.fhir.r4.model.Timing.UnitsOfTime.H);
086          break;
087        case D:
088          tgt.setValue(org.hl7.fhir.r4.model.Timing.UnitsOfTime.D);
089          break;
090        case WK:
091          tgt.setValue(org.hl7.fhir.r4.model.Timing.UnitsOfTime.WK);
092          break;
093        case MO:
094          tgt.setValue(org.hl7.fhir.r4.model.Timing.UnitsOfTime.MO);
095          break;
096        case A:
097          tgt.setValue(org.hl7.fhir.r4.model.Timing.UnitsOfTime.A);
098          break;
099        default:
100          tgt.setValue(org.hl7.fhir.r4.model.Timing.UnitsOfTime.NULL);
101          break;
102      }
103    }
104    return tgt;
105  }
106
107  static public org.hl7.fhir.dstu2.model.Enumeration<org.hl7.fhir.dstu2.model.Timing.UnitsOfTime> convertUnitsOfTime(org.hl7.fhir.r4.model.Enumeration<org.hl7.fhir.r4.model.Timing.UnitsOfTime> src) throws FHIRException {
108    if (src == null || src.isEmpty()) return null;
109    org.hl7.fhir.dstu2.model.Enumeration<org.hl7.fhir.dstu2.model.Timing.UnitsOfTime> tgt = new org.hl7.fhir.dstu2.model.Enumeration<>(new org.hl7.fhir.dstu2.model.Timing.UnitsOfTimeEnumFactory());
110    ConversionContext10_40.INSTANCE.getVersionConvertor_10_40().copyElement(src, tgt);
111    if (src.getValue() == null) {
112      tgt.setValue(org.hl7.fhir.dstu2.model.Timing.UnitsOfTime.NULL);
113    } else {
114      switch (src.getValue()) {
115        case S:
116          tgt.setValue(org.hl7.fhir.dstu2.model.Timing.UnitsOfTime.S);
117          break;
118        case MIN:
119          tgt.setValue(org.hl7.fhir.dstu2.model.Timing.UnitsOfTime.MIN);
120          break;
121        case H:
122          tgt.setValue(org.hl7.fhir.dstu2.model.Timing.UnitsOfTime.H);
123          break;
124        case D:
125          tgt.setValue(org.hl7.fhir.dstu2.model.Timing.UnitsOfTime.D);
126          break;
127        case WK:
128          tgt.setValue(org.hl7.fhir.dstu2.model.Timing.UnitsOfTime.WK);
129          break;
130        case MO:
131          tgt.setValue(org.hl7.fhir.dstu2.model.Timing.UnitsOfTime.MO);
132          break;
133        case A:
134          tgt.setValue(org.hl7.fhir.dstu2.model.Timing.UnitsOfTime.A);
135          break;
136        default:
137          tgt.setValue(org.hl7.fhir.dstu2.model.Timing.UnitsOfTime.NULL);
138          break;
139      }
140    }
141    return tgt;
142  }
143
144  static public org.hl7.fhir.r4.model.Enumeration<org.hl7.fhir.r4.model.Timing.EventTiming> convertEventTiming(org.hl7.fhir.dstu2.model.Enumeration<org.hl7.fhir.dstu2.model.Timing.EventTiming> src) throws FHIRException {
145    if (src == null || src.isEmpty()) return null;
146    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());
147    ConversionContext10_40.INSTANCE.getVersionConvertor_10_40().copyElement(src, tgt);
148    if (src.getValue() == null) {
149      tgt.setValue(org.hl7.fhir.r4.model.Timing.EventTiming.NULL);
150    } else {
151      switch (src.getValue()) {
152        case HS:
153          tgt.setValue(org.hl7.fhir.r4.model.Timing.EventTiming.HS);
154          break;
155        case WAKE:
156          tgt.setValue(org.hl7.fhir.r4.model.Timing.EventTiming.WAKE);
157          break;
158        case C:
159          tgt.setValue(org.hl7.fhir.r4.model.Timing.EventTiming.C);
160          break;
161        case CM:
162          tgt.setValue(org.hl7.fhir.r4.model.Timing.EventTiming.CM);
163          break;
164        case CD:
165          tgt.setValue(org.hl7.fhir.r4.model.Timing.EventTiming.CD);
166          break;
167        case CV:
168          tgt.setValue(org.hl7.fhir.r4.model.Timing.EventTiming.CV);
169          break;
170        case AC:
171          tgt.setValue(org.hl7.fhir.r4.model.Timing.EventTiming.AC);
172          break;
173        case ACM:
174          tgt.setValue(org.hl7.fhir.r4.model.Timing.EventTiming.ACM);
175          break;
176        case ACD:
177          tgt.setValue(org.hl7.fhir.r4.model.Timing.EventTiming.ACD);
178          break;
179        case ACV:
180          tgt.setValue(org.hl7.fhir.r4.model.Timing.EventTiming.ACV);
181          break;
182        case PC:
183          tgt.setValue(org.hl7.fhir.r4.model.Timing.EventTiming.PC);
184          break;
185        case PCM:
186          tgt.setValue(org.hl7.fhir.r4.model.Timing.EventTiming.PCM);
187          break;
188        case PCD:
189          tgt.setValue(org.hl7.fhir.r4.model.Timing.EventTiming.PCD);
190          break;
191        case PCV:
192          tgt.setValue(org.hl7.fhir.r4.model.Timing.EventTiming.PCV);
193          break;
194        default:
195          tgt.setValue(org.hl7.fhir.r4.model.Timing.EventTiming.NULL);
196          break;
197      }
198    }
199    return tgt;
200  }
201
202  static public org.hl7.fhir.dstu2.model.Enumeration<org.hl7.fhir.dstu2.model.Timing.EventTiming> convertEventTiming(org.hl7.fhir.r4.model.Enumeration<org.hl7.fhir.r4.model.Timing.EventTiming> src) throws FHIRException {
203    if (src == null || src.isEmpty()) return null;
204    org.hl7.fhir.dstu2.model.Enumeration<org.hl7.fhir.dstu2.model.Timing.EventTiming> tgt = new org.hl7.fhir.dstu2.model.Enumeration<>(new org.hl7.fhir.dstu2.model.Timing.EventTimingEnumFactory());
205    ConversionContext10_40.INSTANCE.getVersionConvertor_10_40().copyElement(src, tgt);
206    if (src.getValue() == null) {
207      tgt.setValue(org.hl7.fhir.dstu2.model.Timing.EventTiming.NULL);
208    } else {
209      switch (src.getValue()) {
210        case HS:
211          tgt.setValue(org.hl7.fhir.dstu2.model.Timing.EventTiming.HS);
212          break;
213        case WAKE:
214          tgt.setValue(org.hl7.fhir.dstu2.model.Timing.EventTiming.WAKE);
215          break;
216        case C:
217          tgt.setValue(org.hl7.fhir.dstu2.model.Timing.EventTiming.C);
218          break;
219        case CM:
220          tgt.setValue(org.hl7.fhir.dstu2.model.Timing.EventTiming.CM);
221          break;
222        case CD:
223          tgt.setValue(org.hl7.fhir.dstu2.model.Timing.EventTiming.CD);
224          break;
225        case CV:
226          tgt.setValue(org.hl7.fhir.dstu2.model.Timing.EventTiming.CV);
227          break;
228        case AC:
229          tgt.setValue(org.hl7.fhir.dstu2.model.Timing.EventTiming.AC);
230          break;
231        case ACM:
232          tgt.setValue(org.hl7.fhir.dstu2.model.Timing.EventTiming.ACM);
233          break;
234        case ACD:
235          tgt.setValue(org.hl7.fhir.dstu2.model.Timing.EventTiming.ACD);
236          break;
237        case ACV:
238          tgt.setValue(org.hl7.fhir.dstu2.model.Timing.EventTiming.ACV);
239          break;
240        case PC:
241          tgt.setValue(org.hl7.fhir.dstu2.model.Timing.EventTiming.PC);
242          break;
243        case PCM:
244          tgt.setValue(org.hl7.fhir.dstu2.model.Timing.EventTiming.PCM);
245          break;
246        case PCD:
247          tgt.setValue(org.hl7.fhir.dstu2.model.Timing.EventTiming.PCD);
248          break;
249        case PCV:
250          tgt.setValue(org.hl7.fhir.dstu2.model.Timing.EventTiming.PCV);
251          break;
252        default:
253          tgt.setValue(org.hl7.fhir.dstu2.model.Timing.EventTiming.NULL);
254          break;
255      }
256    }
257    return tgt;
258  }
259}