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