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