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