001package org.hl7.fhir.convertors.conv10_30.resources10_30;
002
003import org.hl7.fhir.convertors.context.ConversionContext10_30;
004import org.hl7.fhir.convertors.conv10_30.datatypes10_30.complextypes10_30.Coding10_30;
005import org.hl7.fhir.convertors.conv10_30.datatypes10_30.complextypes10_30.ContactPoint10_30;
006import org.hl7.fhir.convertors.conv10_30.datatypes10_30.primitivetypes10_30.Instant10_30;
007import org.hl7.fhir.convertors.conv10_30.datatypes10_30.primitivetypes10_30.String10_30;
008import org.hl7.fhir.convertors.conv10_30.datatypes10_30.primitivetypes10_30.Uri10_30;
009import org.hl7.fhir.dstu3.model.Enumeration;
010import org.hl7.fhir.dstu3.model.Subscription;
011import org.hl7.fhir.exceptions.FHIRException;
012
013public class Subscription10_30 {
014
015  public static org.hl7.fhir.dstu3.model.Subscription convertSubscription(org.hl7.fhir.dstu2.model.Subscription src) throws FHIRException {
016    if (src == null || src.isEmpty())
017      return null;
018    org.hl7.fhir.dstu3.model.Subscription tgt = new org.hl7.fhir.dstu3.model.Subscription();
019    ConversionContext10_30.INSTANCE.getVersionConvertor_10_30().copyDomainResource(src, tgt);
020    if (src.hasCriteriaElement())
021      tgt.setCriteriaElement(String10_30.convertString(src.getCriteriaElement()));
022    for (org.hl7.fhir.dstu2.model.ContactPoint t : src.getContact())
023      tgt.addContact(ContactPoint10_30.convertContactPoint(t));
024    if (src.hasReasonElement())
025      tgt.setReasonElement(String10_30.convertString(src.getReasonElement()));
026    if (src.hasStatus())
027      tgt.setStatusElement(convertSubscriptionStatus(src.getStatusElement()));
028    if (src.hasErrorElement())
029      tgt.setErrorElement(String10_30.convertString(src.getErrorElement()));
030    if (src.hasChannel())
031      tgt.setChannel(convertSubscriptionChannelComponent(src.getChannel()));
032    if (src.hasEndElement())
033      tgt.setEndElement(Instant10_30.convertInstant(src.getEndElement()));
034    for (org.hl7.fhir.dstu2.model.Coding t : src.getTag()) tgt.addTag(Coding10_30.convertCoding(t));
035    return tgt;
036  }
037
038  public static org.hl7.fhir.dstu2.model.Subscription convertSubscription(org.hl7.fhir.dstu3.model.Subscription src) throws FHIRException {
039    if (src == null || src.isEmpty())
040      return null;
041    org.hl7.fhir.dstu2.model.Subscription tgt = new org.hl7.fhir.dstu2.model.Subscription();
042    ConversionContext10_30.INSTANCE.getVersionConvertor_10_30().copyDomainResource(src, tgt);
043    if (src.hasCriteriaElement())
044      tgt.setCriteriaElement(String10_30.convertString(src.getCriteriaElement()));
045    for (org.hl7.fhir.dstu3.model.ContactPoint t : src.getContact())
046      tgt.addContact(ContactPoint10_30.convertContactPoint(t));
047    if (src.hasReasonElement())
048      tgt.setReasonElement(String10_30.convertString(src.getReasonElement()));
049    if (src.hasStatus())
050      tgt.setStatusElement(convertSubscriptionStatus(src.getStatusElement()));
051    if (src.hasErrorElement())
052      tgt.setErrorElement(String10_30.convertString(src.getErrorElement()));
053    if (src.hasChannel())
054      tgt.setChannel(convertSubscriptionChannelComponent(src.getChannel()));
055    if (src.hasEndElement())
056      tgt.setEndElement(Instant10_30.convertInstant(src.getEndElement()));
057    for (org.hl7.fhir.dstu3.model.Coding t : src.getTag()) tgt.addTag(Coding10_30.convertCoding(t));
058    return tgt;
059  }
060
061  public static org.hl7.fhir.dstu2.model.Subscription.SubscriptionChannelComponent convertSubscriptionChannelComponent(org.hl7.fhir.dstu3.model.Subscription.SubscriptionChannelComponent src) throws FHIRException {
062    if (src == null || src.isEmpty())
063      return null;
064    org.hl7.fhir.dstu2.model.Subscription.SubscriptionChannelComponent tgt = new org.hl7.fhir.dstu2.model.Subscription.SubscriptionChannelComponent();
065    ConversionContext10_30.INSTANCE.getVersionConvertor_10_30().copyBackboneElement(src,tgt);
066    if (src.hasType())
067      tgt.setTypeElement(convertSubscriptionChannelType(src.getTypeElement()));
068    if (src.hasEndpointElement())
069      tgt.setEndpointElement(Uri10_30.convertUri(src.getEndpointElement()));
070    if (src.hasPayloadElement())
071      tgt.setPayloadElement(String10_30.convertString(src.getPayloadElement()));
072    if (src.hasHeader())
073      tgt.setHeaderElement(String10_30.convertString(src.getHeader().get(0)));
074    return tgt;
075  }
076
077  public static org.hl7.fhir.dstu3.model.Subscription.SubscriptionChannelComponent convertSubscriptionChannelComponent(org.hl7.fhir.dstu2.model.Subscription.SubscriptionChannelComponent src) throws FHIRException {
078    if (src == null || src.isEmpty())
079      return null;
080    org.hl7.fhir.dstu3.model.Subscription.SubscriptionChannelComponent tgt = new org.hl7.fhir.dstu3.model.Subscription.SubscriptionChannelComponent();
081    ConversionContext10_30.INSTANCE.getVersionConvertor_10_30().copyBackboneElement(src,tgt);
082    if (src.hasType())
083      tgt.setTypeElement(convertSubscriptionChannelType(src.getTypeElement()));
084    if (src.hasEndpointElement())
085      tgt.setEndpointElement(Uri10_30.convertUri(src.getEndpointElement()));
086    if (src.hasPayloadElement())
087      tgt.setPayloadElement(String10_30.convertString(src.getPayloadElement()));
088    tgt.addHeader(src.getHeader());
089    return tgt;
090  }
091
092  static public org.hl7.fhir.dstu3.model.Enumeration<org.hl7.fhir.dstu3.model.Subscription.SubscriptionChannelType> convertSubscriptionChannelType(org.hl7.fhir.dstu2.model.Enumeration<org.hl7.fhir.dstu2.model.Subscription.SubscriptionChannelType> src) throws FHIRException {
093      if (src == null || src.isEmpty())
094          return null;
095      Enumeration<Subscription.SubscriptionChannelType> tgt = new Enumeration<>(new Subscription.SubscriptionChannelTypeEnumFactory());
096      ConversionContext10_30.INSTANCE.getVersionConvertor_10_30().copyElement(src, tgt);
097      if (src.getValue() == null) {
098          tgt.setValue(null);
099      } else {
100          switch (src.getValue()) {
101              case RESTHOOK:
102                  tgt.setValue(Subscription.SubscriptionChannelType.RESTHOOK);
103                  break;
104              case WEBSOCKET:
105                  tgt.setValue(Subscription.SubscriptionChannelType.WEBSOCKET);
106                  break;
107              case EMAIL:
108                  tgt.setValue(Subscription.SubscriptionChannelType.EMAIL);
109                  break;
110              case SMS:
111                  tgt.setValue(Subscription.SubscriptionChannelType.SMS);
112                  break;
113              case MESSAGE:
114                  tgt.setValue(Subscription.SubscriptionChannelType.MESSAGE);
115                  break;
116              default:
117                  tgt.setValue(Subscription.SubscriptionChannelType.NULL);
118                  break;
119          }
120      }
121      return tgt;
122  }
123
124  static public org.hl7.fhir.dstu2.model.Enumeration<org.hl7.fhir.dstu2.model.Subscription.SubscriptionChannelType> convertSubscriptionChannelType(org.hl7.fhir.dstu3.model.Enumeration<org.hl7.fhir.dstu3.model.Subscription.SubscriptionChannelType> src) throws FHIRException {
125      if (src == null || src.isEmpty())
126          return null;
127      org.hl7.fhir.dstu2.model.Enumeration<org.hl7.fhir.dstu2.model.Subscription.SubscriptionChannelType> tgt = new org.hl7.fhir.dstu2.model.Enumeration<>(new org.hl7.fhir.dstu2.model.Subscription.SubscriptionChannelTypeEnumFactory());
128      ConversionContext10_30.INSTANCE.getVersionConvertor_10_30().copyElement(src, tgt);
129      if (src.getValue() == null) {
130          tgt.setValue(null);
131      } else {
132          switch (src.getValue()) {
133              case RESTHOOK:
134                  tgt.setValue(org.hl7.fhir.dstu2.model.Subscription.SubscriptionChannelType.RESTHOOK);
135                  break;
136              case WEBSOCKET:
137                  tgt.setValue(org.hl7.fhir.dstu2.model.Subscription.SubscriptionChannelType.WEBSOCKET);
138                  break;
139              case EMAIL:
140                  tgt.setValue(org.hl7.fhir.dstu2.model.Subscription.SubscriptionChannelType.EMAIL);
141                  break;
142              case SMS:
143                  tgt.setValue(org.hl7.fhir.dstu2.model.Subscription.SubscriptionChannelType.SMS);
144                  break;
145              case MESSAGE:
146                  tgt.setValue(org.hl7.fhir.dstu2.model.Subscription.SubscriptionChannelType.MESSAGE);
147                  break;
148              default:
149                  tgt.setValue(org.hl7.fhir.dstu2.model.Subscription.SubscriptionChannelType.NULL);
150                  break;
151          }
152      }
153      return tgt;
154  }
155
156  static public org.hl7.fhir.dstu3.model.Enumeration<org.hl7.fhir.dstu3.model.Subscription.SubscriptionStatus> convertSubscriptionStatus(org.hl7.fhir.dstu2.model.Enumeration<org.hl7.fhir.dstu2.model.Subscription.SubscriptionStatus> src) throws FHIRException {
157      if (src == null || src.isEmpty())
158          return null;
159      Enumeration<Subscription.SubscriptionStatus> tgt = new Enumeration<>(new Subscription.SubscriptionStatusEnumFactory());
160      ConversionContext10_30.INSTANCE.getVersionConvertor_10_30().copyElement(src, tgt);
161      if (src.getValue() == null) {
162          tgt.setValue(null);
163      } else {
164          switch (src.getValue()) {
165              case REQUESTED:
166                  tgt.setValue(Subscription.SubscriptionStatus.REQUESTED);
167                  break;
168              case ACTIVE:
169                  tgt.setValue(Subscription.SubscriptionStatus.ACTIVE);
170                  break;
171              case ERROR:
172                  tgt.setValue(Subscription.SubscriptionStatus.ERROR);
173                  break;
174              case OFF:
175                  tgt.setValue(Subscription.SubscriptionStatus.OFF);
176                  break;
177              default:
178                  tgt.setValue(Subscription.SubscriptionStatus.NULL);
179                  break;
180          }
181      }
182      return tgt;
183  }
184
185  static public org.hl7.fhir.dstu2.model.Enumeration<org.hl7.fhir.dstu2.model.Subscription.SubscriptionStatus> convertSubscriptionStatus(org.hl7.fhir.dstu3.model.Enumeration<org.hl7.fhir.dstu3.model.Subscription.SubscriptionStatus> src) throws FHIRException {
186      if (src == null || src.isEmpty())
187          return null;
188      org.hl7.fhir.dstu2.model.Enumeration<org.hl7.fhir.dstu2.model.Subscription.SubscriptionStatus> tgt = new org.hl7.fhir.dstu2.model.Enumeration<>(new org.hl7.fhir.dstu2.model.Subscription.SubscriptionStatusEnumFactory());
189      ConversionContext10_30.INSTANCE.getVersionConvertor_10_30().copyElement(src, tgt);
190      if (src.getValue() == null) {
191          tgt.setValue(null);
192      } else {
193          switch (src.getValue()) {
194              case REQUESTED:
195                  tgt.setValue(org.hl7.fhir.dstu2.model.Subscription.SubscriptionStatus.REQUESTED);
196                  break;
197              case ACTIVE:
198                  tgt.setValue(org.hl7.fhir.dstu2.model.Subscription.SubscriptionStatus.ACTIVE);
199                  break;
200              case ERROR:
201                  tgt.setValue(org.hl7.fhir.dstu2.model.Subscription.SubscriptionStatus.ERROR);
202                  break;
203              case OFF:
204                  tgt.setValue(org.hl7.fhir.dstu2.model.Subscription.SubscriptionStatus.OFF);
205                  break;
206              default:
207                  tgt.setValue(org.hl7.fhir.dstu2.model.Subscription.SubscriptionStatus.NULL);
208                  break;
209          }
210      }
211      return tgt;
212  }
213}