001package org.hl7.fhir.convertors.conv43_50.resources43_50;
002
003import org.hl7.fhir.convertors.context.ConversionContext43_50;
004import org.hl7.fhir.convertors.conv43_50.datatypes43_50.general43_50.CodeableConcept43_50;
005import org.hl7.fhir.convertors.conv43_50.datatypes43_50.primitive43_50.Canonical43_50;
006import org.hl7.fhir.convertors.conv43_50.datatypes43_50.primitive43_50.Instant43_50;
007import org.hl7.fhir.convertors.conv43_50.datatypes43_50.primitive43_50.Integer64_43_50;
008import org.hl7.fhir.convertors.conv43_50.datatypes43_50.special43_50.Reference43_50;
009import org.hl7.fhir.r4b.model.Enumeration;
010import org.hl7.fhir.r4b.model.Enumerations;
011import org.hl7.fhir.r4b.model.SubscriptionStatus;
012
013public class SubscriptionStatus43_50 {
014  public static org.hl7.fhir.r4b.model.SubscriptionStatus convertSubscriptionStatus(org.hl7.fhir.r5.model.SubscriptionStatus src) {
015    if (src == null)
016      return null;
017    org.hl7.fhir.r4b.model.SubscriptionStatus tgt = new org.hl7.fhir.r4b.model.SubscriptionStatus();
018    ConversionContext43_50.INSTANCE.getVersionConvertor_43_50().copyResource(src, tgt);
019    ConversionContext43_50.INSTANCE.getVersionConvertor_43_50().copyDomainResource(src, tgt);
020
021    if (src.hasType())
022    {
023      tgt.setTypeElement(convertSubscriptionNotificationType(src.getTypeElement()));
024    }
025    if (src.hasStatus()) {
026      tgt.setStatusElement(convertSubscriptionStatus(src.getStatusElement()));
027    }
028    if (src.hasEventsSinceSubscriptionStart()) {
029      org.hl7.fhir.r4b.model.StringType value = new org.hl7.fhir.r4b.model.StringType();
030      value.setValue(src.getEventsSinceSubscriptionStartElement().getValueAsString());
031      tgt.setEventsSinceSubscriptionStartElement(value);
032    }
033    if (src.hasNotificationEvent()) {
034      for (org.hl7.fhir.r5.model.SubscriptionStatus.SubscriptionStatusNotificationEventComponent element : src.getNotificationEvent()) {
035        tgt.addNotificationEvent(convertSubscriptionStatusNotificationEventComponent(element));
036      }
037    }
038    if (src.hasSubscription()) {
039      tgt.setSubscription(Reference43_50.convertReference(src.getSubscription()));
040    }
041    if (src.hasTopic()) {
042      tgt.setTopicElement(Canonical43_50.convertCanonical(src.getTopicElement()));
043    }
044    if (src.hasError()) {
045      for (org.hl7.fhir.r5.model.CodeableConcept srcError : src.getError()) {
046        tgt.addError(CodeableConcept43_50.convertCodeableConcept(srcError));
047      }
048    }
049    return tgt;
050  }
051
052  private static org.hl7.fhir.r4b.model.SubscriptionStatus.SubscriptionStatusNotificationEventComponent convertSubscriptionStatusNotificationEventComponent(org.hl7.fhir.r5.model.SubscriptionStatus.SubscriptionStatusNotificationEventComponent src) {
053    org.hl7.fhir.r4b.model.SubscriptionStatus.SubscriptionStatusNotificationEventComponent tgt = new org.hl7.fhir.r4b.model.SubscriptionStatus.SubscriptionStatusNotificationEventComponent();
054    if (src.hasEventNumber()) {
055      tgt.setEventNumberElement(Integer64_43_50.convertInteger64ToString(src.getEventNumberElement()));
056    }
057    if (src.hasTimestamp()) {
058      tgt.setTimestampElement(Instant43_50.convertInstant(src.getTimestampElement()));
059    }
060    if (src.hasFocus()) {
061      tgt.setFocus(Reference43_50.convertReference(src.getFocus()));
062    }
063    if (src.hasAdditionalContext()) {
064      for (org.hl7.fhir.r5.model.Reference ref : src.getAdditionalContext()) {
065        tgt.addAdditionalContext(Reference43_50.convertReference(ref));
066      }
067    }
068    return tgt;
069  }
070
071  private static org.hl7.fhir.r4b.model.Enumeration<org.hl7.fhir.r4b.model.Enumerations.SubscriptionStatus> convertSubscriptionStatus(org.hl7.fhir.r5.model.Enumeration<org.hl7.fhir.r5.model.Enumerations.SubscriptionStatusCodes> src) {
072      Enumerations.SubscriptionStatusEnumFactory enumFactory = new Enumerations.SubscriptionStatusEnumFactory();
073      if (src.getValue() == null) {
074          return null;
075      } else {
076          switch (src.getValue()) {
077              case ACTIVE:
078                  return new Enumeration<>(enumFactory, Enumerations.SubscriptionStatus.ACTIVE);
079              case ERROR:
080                  return new Enumeration<>(enumFactory, Enumerations.SubscriptionStatus.ERROR);
081              case ENTEREDINERROR:
082                  return new Enumeration<>(enumFactory, Enumerations.SubscriptionStatus.ERROR);
083              case OFF:
084                  return new Enumeration<>(enumFactory, Enumerations.SubscriptionStatus.OFF);
085              case REQUESTED:
086                  return new Enumeration<>(enumFactory, Enumerations.SubscriptionStatus.REQUESTED);
087              case NULL:
088                  return new Enumeration<>(enumFactory, Enumerations.SubscriptionStatus.NULL);
089          }
090      }
091      return null;
092  }
093
094  private static org.hl7.fhir.r4b.model.Enumeration<org.hl7.fhir.r4b.model.SubscriptionStatus.SubscriptionNotificationType> convertSubscriptionNotificationType(org.hl7.fhir.r5.model.Enumeration<org.hl7.fhir.r5.model.SubscriptionStatus.SubscriptionNotificationType> src) {
095      SubscriptionStatus.SubscriptionNotificationTypeEnumFactory enumFactory = new SubscriptionStatus.SubscriptionNotificationTypeEnumFactory();
096      if (src.getValue() == null) {
097         return null;
098      } else {
099          switch (src.getValue()) {
100              case EVENTNOTIFICATION:
101                  return new Enumeration<>(enumFactory, SubscriptionStatus.SubscriptionNotificationType.EVENTNOTIFICATION);
102              case HANDSHAKE:
103                  return new Enumeration<>(enumFactory, SubscriptionStatus.SubscriptionNotificationType.HANDSHAKE);
104              case HEARTBEAT:
105                  return new Enumeration<>(enumFactory, SubscriptionStatus.SubscriptionNotificationType.HEARTBEAT);
106              case QUERYEVENT:
107                  return new Enumeration<>(enumFactory, SubscriptionStatus.SubscriptionNotificationType.QUERYEVENT);
108              case QUERYSTATUS:
109                  return new Enumeration<>(enumFactory, SubscriptionStatus.SubscriptionNotificationType.QUERYSTATUS);
110              case NULL:
111                  return new Enumeration<>(enumFactory, SubscriptionStatus.SubscriptionNotificationType.NULL);
112          }
113      }
114      return null;
115  }
116
117
118  public static org.hl7.fhir.r5.model.SubscriptionStatus convertSubscriptionStatus(org.hl7.fhir.r4b.model.SubscriptionStatus src) {
119    if (src == null)
120      return null;
121    org.hl7.fhir.r5.model.SubscriptionStatus tgt = new org.hl7.fhir.r5.model.SubscriptionStatus();
122    ConversionContext43_50.INSTANCE.getVersionConvertor_43_50().copyResource(src, tgt);
123    ConversionContext43_50.INSTANCE.getVersionConvertor_43_50().copyDomainResource(src, tgt);
124
125    if (src.hasType())
126    {
127      tgt.setTypeElement(convertSubscriptionNotificationType(src.getTypeElement()));
128    }
129    if (src.hasStatus()) {
130      tgt.setStatusElement(convertSubscriptionStatus(src.getStatusElement()));
131    }
132    if (src.hasEventsSinceSubscriptionStart()) {
133      org.hl7.fhir.r5.model.Integer64Type value = new org.hl7.fhir.r5.model.Integer64Type();
134      value.fromStringValue(src.getEventsSinceSubscriptionStartElement().getValueAsString());
135      tgt.setEventsSinceSubscriptionStartElement(value);
136    }
137    if (src.hasNotificationEvent()) {
138      for (org.hl7.fhir.r4b.model.SubscriptionStatus.SubscriptionStatusNotificationEventComponent element : src.getNotificationEvent()) {
139        tgt.addNotificationEvent(convertSubscriptionStatusNotificationEventComponent(element));
140      }
141    }
142    if (src.hasSubscription()) {
143      tgt.setSubscription(Reference43_50.convertReference(src.getSubscription()));
144    }
145    if (src.hasTopic()) {
146      tgt.setTopicElement(Canonical43_50.convertCanonical(src.getTopicElement()));
147    }
148    if (src.hasError()) {
149      for (org.hl7.fhir.r4b.model.CodeableConcept srcError : src.getError()) {
150        tgt.addError(CodeableConcept43_50.convertCodeableConcept(srcError));
151      }
152    }
153    return tgt;
154  }
155
156  private static org.hl7.fhir.r5.model.SubscriptionStatus.SubscriptionStatusNotificationEventComponent convertSubscriptionStatusNotificationEventComponent(org.hl7.fhir.r4b.model.SubscriptionStatus.SubscriptionStatusNotificationEventComponent src) {
157    org.hl7.fhir.r5.model.SubscriptionStatus.SubscriptionStatusNotificationEventComponent tgt = new org.hl7.fhir.r5.model.SubscriptionStatus.SubscriptionStatusNotificationEventComponent();
158    if (src.hasEventNumber()) {
159      tgt.setEventNumberElement(Integer64_43_50.convertStringToInteger64(src.getEventNumberElement()));
160    }
161    if (src.hasTimestamp()) {
162      tgt.setTimestampElement(Instant43_50.convertInstant(src.getTimestampElement()));
163    }
164    if (src.hasFocus()) {
165      tgt.setFocus(Reference43_50.convertReference(src.getFocus()));
166    }
167    if (src.hasAdditionalContext()) {
168      for (org.hl7.fhir.r4b.model.Reference ref : src.getAdditionalContext()) {
169        tgt.addAdditionalContext(Reference43_50.convertReference(ref));
170      }
171    }
172    return tgt;
173  }
174
175  private static org.hl7.fhir.r5.model.Enumeration<org.hl7.fhir.r5.model.Enumerations.SubscriptionStatusCodes> convertSubscriptionStatus(org.hl7.fhir.r4b.model.Enumeration<org.hl7.fhir.r4b.model.Enumerations.SubscriptionStatus> src) {
176      org.hl7.fhir.r5.model.Enumerations.SubscriptionStatusCodesEnumFactory enumFactory = new org.hl7.fhir.r5.model.Enumerations.SubscriptionStatusCodesEnumFactory();
177      if (src.getValue() == null) {
178         return null;
179      } else {
180          switch (src.getValue()) {
181              case ACTIVE:
182                  return new org.hl7.fhir.r5.model.Enumeration<>(enumFactory, org.hl7.fhir.r5.model.Enumerations.SubscriptionStatusCodes.ACTIVE);
183              case ERROR:
184                  return new org.hl7.fhir.r5.model.Enumeration<>(enumFactory, org.hl7.fhir.r5.model.Enumerations.SubscriptionStatusCodes.ERROR);
185              case OFF:
186                  return new org.hl7.fhir.r5.model.Enumeration<>(enumFactory, org.hl7.fhir.r5.model.Enumerations.SubscriptionStatusCodes.OFF);
187              case REQUESTED:
188                  return new org.hl7.fhir.r5.model.Enumeration<>(enumFactory, org.hl7.fhir.r5.model.Enumerations.SubscriptionStatusCodes.REQUESTED);
189              case NULL:
190                  return new org.hl7.fhir.r5.model.Enumeration<>(enumFactory, org.hl7.fhir.r5.model.Enumerations.SubscriptionStatusCodes.NULL);
191          }
192      }
193      return null;
194  }
195
196  private static org.hl7.fhir.r5.model.Enumeration<org.hl7.fhir.r5.model.SubscriptionStatus.SubscriptionNotificationType> convertSubscriptionNotificationType(org.hl7.fhir.r4b.model.Enumeration<org.hl7.fhir.r4b.model.SubscriptionStatus.SubscriptionNotificationType> src) {
197      org.hl7.fhir.r5.model.SubscriptionStatus.SubscriptionNotificationTypeEnumFactory enumFactory = new org.hl7.fhir.r5.model.SubscriptionStatus.SubscriptionNotificationTypeEnumFactory();
198      if (src.getValue() == null) {
199         return null;
200      } else {
201          switch (src.getValue()) {
202              case EVENTNOTIFICATION:
203                  return new org.hl7.fhir.r5.model.Enumeration<>(enumFactory, org.hl7.fhir.r5.model.SubscriptionStatus.SubscriptionNotificationType.EVENTNOTIFICATION);
204              case HANDSHAKE:
205                  return new org.hl7.fhir.r5.model.Enumeration<>(enumFactory, org.hl7.fhir.r5.model.SubscriptionStatus.SubscriptionNotificationType.HANDSHAKE);
206              case HEARTBEAT:
207                  return new org.hl7.fhir.r5.model.Enumeration<>(enumFactory, org.hl7.fhir.r5.model.SubscriptionStatus.SubscriptionNotificationType.HEARTBEAT);
208              case QUERYEVENT:
209                  return new org.hl7.fhir.r5.model.Enumeration<>(enumFactory, org.hl7.fhir.r5.model.SubscriptionStatus.SubscriptionNotificationType.QUERYEVENT);
210              case QUERYSTATUS:
211                  return new org.hl7.fhir.r5.model.Enumeration<>(enumFactory, org.hl7.fhir.r5.model.SubscriptionStatus.SubscriptionNotificationType.QUERYSTATUS);
212              case NULL:
213                  return new org.hl7.fhir.r5.model.Enumeration<>(enumFactory, org.hl7.fhir.r5.model.SubscriptionStatus.SubscriptionNotificationType.NULL);
214          }
215      }
216      return null;
217  }
218}