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.Reference10_30;
005import org.hl7.fhir.convertors.conv10_30.datatypes10_30.complextypes10_30.CodeableConcept10_30;
006import org.hl7.fhir.convertors.conv10_30.datatypes10_30.complextypes10_30.Coding10_30;
007import org.hl7.fhir.convertors.conv10_30.datatypes10_30.complextypes10_30.ContactPoint10_30;
008import org.hl7.fhir.convertors.conv10_30.datatypes10_30.primitivetypes10_30.Id10_30;
009import org.hl7.fhir.convertors.conv10_30.datatypes10_30.primitivetypes10_30.Instant10_30;
010import org.hl7.fhir.convertors.conv10_30.datatypes10_30.primitivetypes10_30.String10_30;
011import org.hl7.fhir.convertors.conv10_30.datatypes10_30.primitivetypes10_30.Uri10_30;
012import org.hl7.fhir.dstu3.model.Enumeration;
013import org.hl7.fhir.dstu3.model.MessageHeader;
014import org.hl7.fhir.exceptions.FHIRException;
015
016public class MessageHeader10_30 {
017
018  public static org.hl7.fhir.dstu3.model.MessageHeader.MessageDestinationComponent convertMessageDestinationComponent(org.hl7.fhir.dstu2.model.MessageHeader.MessageDestinationComponent src) throws FHIRException {
019    if (src == null || src.isEmpty())
020      return null;
021    org.hl7.fhir.dstu3.model.MessageHeader.MessageDestinationComponent tgt = new org.hl7.fhir.dstu3.model.MessageHeader.MessageDestinationComponent();
022    ConversionContext10_30.INSTANCE.getVersionConvertor_10_30().copyBackboneElement(src,tgt);
023    if (src.hasNameElement())
024      tgt.setNameElement(String10_30.convertString(src.getNameElement()));
025    if (src.hasTarget())
026      tgt.setTarget(Reference10_30.convertReference(src.getTarget()));
027    if (src.hasEndpointElement())
028      tgt.setEndpointElement(Uri10_30.convertUri(src.getEndpointElement()));
029    return tgt;
030  }
031
032  public static org.hl7.fhir.dstu2.model.MessageHeader.MessageDestinationComponent convertMessageDestinationComponent(org.hl7.fhir.dstu3.model.MessageHeader.MessageDestinationComponent src) throws FHIRException {
033    if (src == null || src.isEmpty())
034      return null;
035    org.hl7.fhir.dstu2.model.MessageHeader.MessageDestinationComponent tgt = new org.hl7.fhir.dstu2.model.MessageHeader.MessageDestinationComponent();
036    ConversionContext10_30.INSTANCE.getVersionConvertor_10_30().copyBackboneElement(src,tgt);
037    if (src.hasNameElement())
038      tgt.setNameElement(String10_30.convertString(src.getNameElement()));
039    if (src.hasTarget())
040      tgt.setTarget(Reference10_30.convertReference(src.getTarget()));
041    if (src.hasEndpointElement())
042      tgt.setEndpointElement(Uri10_30.convertUri(src.getEndpointElement()));
043    return tgt;
044  }
045
046  public static org.hl7.fhir.dstu2.model.MessageHeader convertMessageHeader(org.hl7.fhir.dstu3.model.MessageHeader src) throws FHIRException {
047    if (src == null || src.isEmpty())
048      return null;
049    org.hl7.fhir.dstu2.model.MessageHeader tgt = new org.hl7.fhir.dstu2.model.MessageHeader();
050    ConversionContext10_30.INSTANCE.getVersionConvertor_10_30().copyDomainResource(src, tgt);
051    if (src.hasTimestampElement())
052      tgt.setTimestampElement(Instant10_30.convertInstant(src.getTimestampElement()));
053    if (src.hasEvent())
054      tgt.setEvent(Coding10_30.convertCoding(src.getEvent()));
055    if (src.hasResponse())
056      tgt.setResponse(convertMessageHeaderResponseComponent(src.getResponse()));
057    if (src.hasSource())
058      tgt.setSource(convertMessageSourceComponent(src.getSource()));
059    for (org.hl7.fhir.dstu3.model.MessageHeader.MessageDestinationComponent t : src.getDestination())
060      tgt.addDestination(convertMessageDestinationComponent(t));
061    if (src.hasEnterer())
062      tgt.setEnterer(Reference10_30.convertReference(src.getEnterer()));
063    if (src.hasAuthor())
064      tgt.setAuthor(Reference10_30.convertReference(src.getAuthor()));
065    if (src.hasReceiver())
066      tgt.setReceiver(Reference10_30.convertReference(src.getReceiver()));
067    if (src.hasResponsible())
068      tgt.setResponsible(Reference10_30.convertReference(src.getResponsible()));
069    if (src.hasReason())
070      tgt.setReason(CodeableConcept10_30.convertCodeableConcept(src.getReason()));
071    for (org.hl7.fhir.dstu3.model.Reference t : src.getFocus()) tgt.addData(Reference10_30.convertReference(t));
072    return tgt;
073  }
074
075  public static org.hl7.fhir.dstu3.model.MessageHeader convertMessageHeader(org.hl7.fhir.dstu2.model.MessageHeader src) throws FHIRException {
076    if (src == null || src.isEmpty())
077      return null;
078    org.hl7.fhir.dstu3.model.MessageHeader tgt = new org.hl7.fhir.dstu3.model.MessageHeader();
079    ConversionContext10_30.INSTANCE.getVersionConvertor_10_30().copyDomainResource(src, tgt);
080    if (src.hasTimestampElement())
081      tgt.setTimestampElement(Instant10_30.convertInstant(src.getTimestampElement()));
082    if (src.hasEvent())
083      tgt.setEvent(Coding10_30.convertCoding(src.getEvent()));
084    if (src.hasResponse())
085      tgt.setResponse(convertMessageHeaderResponseComponent(src.getResponse()));
086    if (src.hasSource())
087      tgt.setSource(convertMessageSourceComponent(src.getSource()));
088    for (org.hl7.fhir.dstu2.model.MessageHeader.MessageDestinationComponent t : src.getDestination())
089      tgt.addDestination(convertMessageDestinationComponent(t));
090    if (src.hasEnterer())
091      tgt.setEnterer(Reference10_30.convertReference(src.getEnterer()));
092    if (src.hasAuthor())
093      tgt.setAuthor(Reference10_30.convertReference(src.getAuthor()));
094    if (src.hasReceiver())
095      tgt.setReceiver(Reference10_30.convertReference(src.getReceiver()));
096    if (src.hasResponsible())
097      tgt.setResponsible(Reference10_30.convertReference(src.getResponsible()));
098    if (src.hasReason())
099      tgt.setReason(CodeableConcept10_30.convertCodeableConcept(src.getReason()));
100    for (org.hl7.fhir.dstu2.model.Reference t : src.getData()) tgt.addFocus(Reference10_30.convertReference(t));
101    return tgt;
102  }
103
104  public static org.hl7.fhir.dstu2.model.MessageHeader.MessageHeaderResponseComponent convertMessageHeaderResponseComponent(org.hl7.fhir.dstu3.model.MessageHeader.MessageHeaderResponseComponent src) throws FHIRException {
105    if (src == null || src.isEmpty())
106      return null;
107    org.hl7.fhir.dstu2.model.MessageHeader.MessageHeaderResponseComponent tgt = new org.hl7.fhir.dstu2.model.MessageHeader.MessageHeaderResponseComponent();
108    ConversionContext10_30.INSTANCE.getVersionConvertor_10_30().copyBackboneElement(src,tgt);
109    if (src.hasIdentifierElement())
110      tgt.setIdentifierElement(Id10_30.convertId(src.getIdentifierElement()));
111    if (src.hasCode())
112      tgt.setCodeElement(convertResponseType(src.getCodeElement()));
113    if (src.hasDetails())
114      tgt.setDetails(Reference10_30.convertReference(src.getDetails()));
115    return tgt;
116  }
117
118  public static org.hl7.fhir.dstu3.model.MessageHeader.MessageHeaderResponseComponent convertMessageHeaderResponseComponent(org.hl7.fhir.dstu2.model.MessageHeader.MessageHeaderResponseComponent src) throws FHIRException {
119    if (src == null || src.isEmpty())
120      return null;
121    org.hl7.fhir.dstu3.model.MessageHeader.MessageHeaderResponseComponent tgt = new org.hl7.fhir.dstu3.model.MessageHeader.MessageHeaderResponseComponent();
122    ConversionContext10_30.INSTANCE.getVersionConvertor_10_30().copyBackboneElement(src,tgt);
123    if (src.hasIdentifierElement())
124      tgt.setIdentifierElement(Id10_30.convertId(src.getIdentifierElement()));
125    if (src.hasCode())
126      tgt.setCodeElement(convertResponseType(src.getCodeElement()));
127    if (src.hasDetails())
128      tgt.setDetails(Reference10_30.convertReference(src.getDetails()));
129    return tgt;
130  }
131
132  public static org.hl7.fhir.dstu3.model.MessageHeader.MessageSourceComponent convertMessageSourceComponent(org.hl7.fhir.dstu2.model.MessageHeader.MessageSourceComponent src) throws FHIRException {
133    if (src == null || src.isEmpty())
134      return null;
135    org.hl7.fhir.dstu3.model.MessageHeader.MessageSourceComponent tgt = new org.hl7.fhir.dstu3.model.MessageHeader.MessageSourceComponent();
136    ConversionContext10_30.INSTANCE.getVersionConvertor_10_30().copyBackboneElement(src,tgt);
137    if (src.hasNameElement())
138      tgt.setNameElement(String10_30.convertString(src.getNameElement()));
139    if (src.hasSoftwareElement())
140      tgt.setSoftwareElement(String10_30.convertString(src.getSoftwareElement()));
141    if (src.hasVersionElement())
142      tgt.setVersionElement(String10_30.convertString(src.getVersionElement()));
143    if (src.hasContact())
144      tgt.setContact(ContactPoint10_30.convertContactPoint(src.getContact()));
145    if (src.hasEndpointElement())
146      tgt.setEndpointElement(Uri10_30.convertUri(src.getEndpointElement()));
147    return tgt;
148  }
149
150  public static org.hl7.fhir.dstu2.model.MessageHeader.MessageSourceComponent convertMessageSourceComponent(org.hl7.fhir.dstu3.model.MessageHeader.MessageSourceComponent src) throws FHIRException {
151    if (src == null || src.isEmpty())
152      return null;
153    org.hl7.fhir.dstu2.model.MessageHeader.MessageSourceComponent tgt = new org.hl7.fhir.dstu2.model.MessageHeader.MessageSourceComponent();
154    ConversionContext10_30.INSTANCE.getVersionConvertor_10_30().copyBackboneElement(src,tgt);
155    if (src.hasNameElement())
156      tgt.setNameElement(String10_30.convertString(src.getNameElement()));
157    if (src.hasSoftwareElement())
158      tgt.setSoftwareElement(String10_30.convertString(src.getSoftwareElement()));
159    if (src.hasVersionElement())
160      tgt.setVersionElement(String10_30.convertString(src.getVersionElement()));
161    if (src.hasContact())
162      tgt.setContact(ContactPoint10_30.convertContactPoint(src.getContact()));
163    if (src.hasEndpointElement())
164      tgt.setEndpointElement(Uri10_30.convertUri(src.getEndpointElement()));
165    return tgt;
166  }
167
168  static public org.hl7.fhir.dstu3.model.Enumeration<org.hl7.fhir.dstu3.model.MessageHeader.ResponseType> convertResponseType(org.hl7.fhir.dstu2.model.Enumeration<org.hl7.fhir.dstu2.model.MessageHeader.ResponseType> src) throws FHIRException {
169      if (src == null || src.isEmpty())
170          return null;
171      Enumeration<MessageHeader.ResponseType> tgt = new Enumeration<>(new MessageHeader.ResponseTypeEnumFactory());
172      ConversionContext10_30.INSTANCE.getVersionConvertor_10_30().copyElement(src, tgt);
173      if (src.getValue() == null) {
174          tgt.setValue(null);
175      } else {
176          switch (src.getValue()) {
177              case OK:
178                  tgt.setValue(MessageHeader.ResponseType.OK);
179                  break;
180              case TRANSIENTERROR:
181                  tgt.setValue(MessageHeader.ResponseType.TRANSIENTERROR);
182                  break;
183              case FATALERROR:
184                  tgt.setValue(MessageHeader.ResponseType.FATALERROR);
185                  break;
186              default:
187                  tgt.setValue(MessageHeader.ResponseType.NULL);
188                  break;
189          }
190      }
191      return tgt;
192  }
193
194  static public org.hl7.fhir.dstu2.model.Enumeration<org.hl7.fhir.dstu2.model.MessageHeader.ResponseType> convertResponseType(org.hl7.fhir.dstu3.model.Enumeration<org.hl7.fhir.dstu3.model.MessageHeader.ResponseType> src) throws FHIRException {
195      if (src == null || src.isEmpty())
196          return null;
197      org.hl7.fhir.dstu2.model.Enumeration<org.hl7.fhir.dstu2.model.MessageHeader.ResponseType> tgt = new org.hl7.fhir.dstu2.model.Enumeration<>(new org.hl7.fhir.dstu2.model.MessageHeader.ResponseTypeEnumFactory());
198      ConversionContext10_30.INSTANCE.getVersionConvertor_10_30().copyElement(src, tgt);
199      if (src.getValue() == null) {
200          tgt.setValue(null);
201      } else {
202          switch (src.getValue()) {
203              case OK:
204                  tgt.setValue(org.hl7.fhir.dstu2.model.MessageHeader.ResponseType.OK);
205                  break;
206              case TRANSIENTERROR:
207                  tgt.setValue(org.hl7.fhir.dstu2.model.MessageHeader.ResponseType.TRANSIENTERROR);
208                  break;
209              case FATALERROR:
210                  tgt.setValue(org.hl7.fhir.dstu2.model.MessageHeader.ResponseType.FATALERROR);
211                  break;
212              default:
213                  tgt.setValue(org.hl7.fhir.dstu2.model.MessageHeader.ResponseType.NULL);
214                  break;
215          }
216      }
217      return tgt;
218  }
219}