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.general43_50.ContactPoint43_50;
006import org.hl7.fhir.convertors.conv43_50.datatypes43_50.primitive43_50.Canonical43_50;
007import org.hl7.fhir.convertors.conv43_50.datatypes43_50.primitive43_50.String43_50;
008import org.hl7.fhir.convertors.conv43_50.datatypes43_50.primitive43_50.Url43_50;
009import org.hl7.fhir.convertors.conv43_50.datatypes43_50.special43_50.Reference43_50;
010import org.hl7.fhir.exceptions.FHIRException;
011
012/*
013  Copyright (c) 2011+, HL7, Inc.
014  All rights reserved.
015  
016  Redistribution and use in source and binary forms, with or without modification, 
017  are permitted provided that the following conditions are met:
018  
019   * Redistributions of source code must retain the above copyright notice, this 
020     list of conditions and the following disclaimer.
021   * Redistributions in binary form must reproduce the above copyright notice, 
022     this list of conditions and the following disclaimer in the documentation 
023     and/or other materials provided with the distribution.
024   * Neither the name of HL7 nor the names of its contributors may be used to 
025     endorse or promote products derived from this software without specific 
026     prior written permission.
027  
028  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 
029  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 
030  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 
031  IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 
032  INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 
033  NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 
034  PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 
035  WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
036  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
037  POSSIBILITY OF SUCH DAMAGE.
038  
039*/
040// Generated on Sun, Feb 24, 2019 11:37+1100 for FHIR v4.0.0
041public class MessageHeader43_50 {
042
043  public static org.hl7.fhir.r5.model.MessageHeader convertMessageHeader(org.hl7.fhir.r4b.model.MessageHeader src) throws FHIRException {
044    if (src == null)
045      return null;
046    org.hl7.fhir.r5.model.MessageHeader tgt = new org.hl7.fhir.r5.model.MessageHeader();
047    ConversionContext43_50.INSTANCE.getVersionConvertor_43_50().copyDomainResource(src, tgt);
048    if (src.hasEvent())
049      tgt.setEvent(ConversionContext43_50.INSTANCE.getVersionConvertor_43_50().convertType(src.getEvent()));
050    for (org.hl7.fhir.r4b.model.MessageHeader.MessageDestinationComponent t : src.getDestination())
051      tgt.addDestination(convertMessageDestinationComponent(t));
052    if (src.hasSender())
053      tgt.setSender(Reference43_50.convertReference(src.getSender()));
054//    if (src.hasEnterer())
055//      tgt.setEnterer(Reference43_50.convertReference(src.getEnterer()));
056    if (src.hasAuthor())
057      tgt.setAuthor(Reference43_50.convertReference(src.getAuthor()));
058    if (src.hasSource())
059      tgt.setSource(convertMessageSourceComponent(src.getSource()));
060    if (src.hasResponsible())
061      tgt.setResponsible(Reference43_50.convertReference(src.getResponsible()));
062    if (src.hasReason())
063      tgt.setReason(CodeableConcept43_50.convertCodeableConcept(src.getReason()));
064    if (src.hasResponse())
065      tgt.setResponse(convertMessageHeaderResponseComponent(src.getResponse()));
066    for (org.hl7.fhir.r4b.model.Reference t : src.getFocus()) tgt.addFocus(Reference43_50.convertReference(t));
067    if (src.hasDefinition())
068      tgt.setDefinitionElement(Canonical43_50.convertCanonical(src.getDefinitionElement()));
069    return tgt;
070  }
071
072  public static org.hl7.fhir.r4b.model.MessageHeader convertMessageHeader(org.hl7.fhir.r5.model.MessageHeader src) throws FHIRException {
073    if (src == null)
074      return null;
075    org.hl7.fhir.r4b.model.MessageHeader tgt = new org.hl7.fhir.r4b.model.MessageHeader();
076    ConversionContext43_50.INSTANCE.getVersionConvertor_43_50().copyDomainResource(src, tgt);
077    if (src.hasEvent())
078      tgt.setEvent(ConversionContext43_50.INSTANCE.getVersionConvertor_43_50().convertType(src.getEvent()));
079    for (org.hl7.fhir.r5.model.MessageHeader.MessageDestinationComponent t : src.getDestination())
080      tgt.addDestination(convertMessageDestinationComponent(t));
081    if (src.hasSender())
082      tgt.setSender(Reference43_50.convertReference(src.getSender()));
083//    if (src.hasEnterer())
084//      tgt.setEnterer(Reference43_50.convertReference(src.getEnterer()));
085    if (src.hasAuthor())
086      tgt.setAuthor(Reference43_50.convertReference(src.getAuthor()));
087    if (src.hasSource())
088      tgt.setSource(convertMessageSourceComponent(src.getSource()));
089    if (src.hasResponsible())
090      tgt.setResponsible(Reference43_50.convertReference(src.getResponsible()));
091    if (src.hasReason())
092      tgt.setReason(CodeableConcept43_50.convertCodeableConcept(src.getReason()));
093    if (src.hasResponse())
094      tgt.setResponse(convertMessageHeaderResponseComponent(src.getResponse()));
095    for (org.hl7.fhir.r5.model.Reference t : src.getFocus()) tgt.addFocus(Reference43_50.convertReference(t));
096    if (src.hasDefinition())
097      tgt.setDefinitionElement(Canonical43_50.convertCanonical(src.getDefinitionElement()));
098    return tgt;
099  }
100
101  public static org.hl7.fhir.r5.model.MessageHeader.MessageDestinationComponent convertMessageDestinationComponent(org.hl7.fhir.r4b.model.MessageHeader.MessageDestinationComponent src) throws FHIRException {
102    if (src == null)
103      return null;
104    org.hl7.fhir.r5.model.MessageHeader.MessageDestinationComponent tgt = new org.hl7.fhir.r5.model.MessageHeader.MessageDestinationComponent();
105    ConversionContext43_50.INSTANCE.getVersionConvertor_43_50().copyBackboneElement(src, tgt);
106    if (src.hasName())
107      tgt.setNameElement(String43_50.convertString(src.getNameElement()));
108    if (src.hasTarget())
109      tgt.setTarget(Reference43_50.convertReference(src.getTarget()));
110    if (src.hasEndpoint())
111      tgt.setEndpoint(Url43_50.convertUrl(src.getEndpointElement()));
112    if (src.hasReceiver())
113      tgt.setReceiver(Reference43_50.convertReference(src.getReceiver()));
114    return tgt;
115  }
116
117  public static org.hl7.fhir.r4b.model.MessageHeader.MessageDestinationComponent convertMessageDestinationComponent(org.hl7.fhir.r5.model.MessageHeader.MessageDestinationComponent src) throws FHIRException {
118    if (src == null)
119      return null;
120    org.hl7.fhir.r4b.model.MessageHeader.MessageDestinationComponent tgt = new org.hl7.fhir.r4b.model.MessageHeader.MessageDestinationComponent();
121    ConversionContext43_50.INSTANCE.getVersionConvertor_43_50().copyBackboneElement(src, tgt);
122    if (src.hasName())
123      tgt.setNameElement(String43_50.convertString(src.getNameElement()));
124    if (src.hasTarget())
125      tgt.setTarget(Reference43_50.convertReference(src.getTarget()));
126    if (src.hasEndpointUrlType())
127      tgt.setEndpointElement(Url43_50.convertUrl(src.getEndpointUrlType()));
128    if (src.hasReceiver())
129      tgt.setReceiver(Reference43_50.convertReference(src.getReceiver()));
130    return tgt;
131  }
132
133  public static org.hl7.fhir.r5.model.MessageHeader.MessageSourceComponent convertMessageSourceComponent(org.hl7.fhir.r4b.model.MessageHeader.MessageSourceComponent src) throws FHIRException {
134    if (src == null)
135      return null;
136    org.hl7.fhir.r5.model.MessageHeader.MessageSourceComponent tgt = new org.hl7.fhir.r5.model.MessageHeader.MessageSourceComponent();
137    ConversionContext43_50.INSTANCE.getVersionConvertor_43_50().copyBackboneElement(src, tgt);
138    if (src.hasName())
139      tgt.setNameElement(String43_50.convertString(src.getNameElement()));
140    if (src.hasSoftware())
141      tgt.setSoftwareElement(String43_50.convertString(src.getSoftwareElement()));
142    if (src.hasVersion())
143      tgt.setVersionElement(String43_50.convertString(src.getVersionElement()));
144    if (src.hasContact())
145      tgt.setContact(ContactPoint43_50.convertContactPoint(src.getContact()));
146    if (src.hasEndpoint())
147      tgt.setEndpoint(Url43_50.convertUrl(src.getEndpointElement()));
148    return tgt;
149  }
150
151  public static org.hl7.fhir.r4b.model.MessageHeader.MessageSourceComponent convertMessageSourceComponent(org.hl7.fhir.r5.model.MessageHeader.MessageSourceComponent src) throws FHIRException {
152    if (src == null)
153      return null;
154    org.hl7.fhir.r4b.model.MessageHeader.MessageSourceComponent tgt = new org.hl7.fhir.r4b.model.MessageHeader.MessageSourceComponent();
155    ConversionContext43_50.INSTANCE.getVersionConvertor_43_50().copyBackboneElement(src, tgt);
156    if (src.hasName())
157      tgt.setNameElement(String43_50.convertString(src.getNameElement()));
158    if (src.hasSoftware())
159      tgt.setSoftwareElement(String43_50.convertString(src.getSoftwareElement()));
160    if (src.hasVersion())
161      tgt.setVersionElement(String43_50.convertString(src.getVersionElement()));
162    if (src.hasContact())
163      tgt.setContact(ContactPoint43_50.convertContactPoint(src.getContact()));
164    if (src.hasEndpointUrlType())
165      tgt.setEndpointElement(Url43_50.convertUrl(src.getEndpointUrlType()));
166    return tgt;
167  }
168
169  public static org.hl7.fhir.r5.model.MessageHeader.MessageHeaderResponseComponent convertMessageHeaderResponseComponent(org.hl7.fhir.r4b.model.MessageHeader.MessageHeaderResponseComponent src) throws FHIRException {
170    if (src == null)
171      return null;
172    org.hl7.fhir.r5.model.MessageHeader.MessageHeaderResponseComponent tgt = new org.hl7.fhir.r5.model.MessageHeader.MessageHeaderResponseComponent();
173    ConversionContext43_50.INSTANCE.getVersionConvertor_43_50().copyBackboneElement(src, tgt);
174    if (src.hasIdentifier())
175      tgt.setIdentifier(new org.hl7.fhir.r5.model.Identifier().setValue(src.getIdentifier()));
176    if (src.hasCode())
177      tgt.setCodeElement(convertResponseType(src.getCodeElement()));
178    if (src.hasDetails())
179      tgt.setDetails(Reference43_50.convertReference(src.getDetails()));
180    return tgt;
181  }
182
183  public static org.hl7.fhir.r4b.model.MessageHeader.MessageHeaderResponseComponent convertMessageHeaderResponseComponent(org.hl7.fhir.r5.model.MessageHeader.MessageHeaderResponseComponent src) throws FHIRException {
184    if (src == null)
185      return null;
186    org.hl7.fhir.r4b.model.MessageHeader.MessageHeaderResponseComponent tgt = new org.hl7.fhir.r4b.model.MessageHeader.MessageHeaderResponseComponent();
187    ConversionContext43_50.INSTANCE.getVersionConvertor_43_50().copyBackboneElement(src, tgt);
188    if (src.hasIdentifier())
189      tgt.setIdentifierElement(new org.hl7.fhir.r4b.model.IdType(src.getIdentifier().getValue()));
190    if (src.hasCode())
191      tgt.setCodeElement(convertResponseType(src.getCodeElement()));
192    if (src.hasDetails())
193      tgt.setDetails(Reference43_50.convertReference(src.getDetails()));
194    return tgt;
195  }
196
197  static public org.hl7.fhir.r5.model.Enumeration<org.hl7.fhir.r5.model.MessageHeader.ResponseType> convertResponseType(org.hl7.fhir.r4b.model.Enumeration<org.hl7.fhir.r4b.model.MessageHeader.ResponseType> src) throws FHIRException {
198    if (src == null || src.isEmpty())
199      return null;
200    org.hl7.fhir.r5.model.Enumeration<org.hl7.fhir.r5.model.MessageHeader.ResponseType> tgt = new org.hl7.fhir.r5.model.Enumeration<>(new org.hl7.fhir.r5.model.MessageHeader.ResponseTypeEnumFactory());
201    ConversionContext43_50.INSTANCE.getVersionConvertor_43_50().copyElement(src, tgt);
202    switch (src.getValue()) {
203      case OK:
204        tgt.setValue(org.hl7.fhir.r5.model.MessageHeader.ResponseType.OK);
205        break;
206      case TRANSIENTERROR:
207        tgt.setValue(org.hl7.fhir.r5.model.MessageHeader.ResponseType.TRANSIENTERROR);
208        break;
209      case FATALERROR:
210        tgt.setValue(org.hl7.fhir.r5.model.MessageHeader.ResponseType.FATALERROR);
211        break;
212      default:
213        tgt.setValue(org.hl7.fhir.r5.model.MessageHeader.ResponseType.NULL);
214        break;
215    }
216    return tgt;
217  }
218
219  static public org.hl7.fhir.r4b.model.Enumeration<org.hl7.fhir.r4b.model.MessageHeader.ResponseType> convertResponseType(org.hl7.fhir.r5.model.Enumeration<org.hl7.fhir.r5.model.MessageHeader.ResponseType> src) throws FHIRException {
220    if (src == null || src.isEmpty())
221      return null;
222    org.hl7.fhir.r4b.model.Enumeration<org.hl7.fhir.r4b.model.MessageHeader.ResponseType> tgt = new org.hl7.fhir.r4b.model.Enumeration<>(new org.hl7.fhir.r4b.model.MessageHeader.ResponseTypeEnumFactory());
223    ConversionContext43_50.INSTANCE.getVersionConvertor_43_50().copyElement(src, tgt);
224    switch (src.getValue()) {
225      case OK:
226        tgt.setValue(org.hl7.fhir.r4b.model.MessageHeader.ResponseType.OK);
227        break;
228      case TRANSIENTERROR:
229        tgt.setValue(org.hl7.fhir.r4b.model.MessageHeader.ResponseType.TRANSIENTERROR);
230        break;
231      case FATALERROR:
232        tgt.setValue(org.hl7.fhir.r4b.model.MessageHeader.ResponseType.FATALERROR);
233        break;
234      default:
235        tgt.setValue(org.hl7.fhir.r4b.model.MessageHeader.ResponseType.NULL);
236        break;
237    }
238    return tgt;
239  }
240}