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