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.Annotation40_50;
005import org.hl7.fhir.convertors.conv40_50.datatypes40_50.general40_50.CodeableConcept40_50;
006import org.hl7.fhir.convertors.conv40_50.datatypes40_50.general40_50.Identifier40_50;
007import org.hl7.fhir.convertors.conv40_50.datatypes40_50.general40_50.Money40_50;
008import org.hl7.fhir.convertors.conv40_50.datatypes40_50.primitive40_50.DateTime40_50;
009import org.hl7.fhir.convertors.conv40_50.datatypes40_50.primitive40_50.MarkDown40_50;
010import org.hl7.fhir.convertors.conv40_50.datatypes40_50.primitive40_50.PositiveInt40_50;
011import org.hl7.fhir.convertors.conv40_50.datatypes40_50.primitive40_50.String40_50;
012import org.hl7.fhir.convertors.conv40_50.datatypes40_50.special40_50.Reference40_50;
013import org.hl7.fhir.exceptions.FHIRException;
014import org.hl7.fhir.r5.model.Enumeration;
015import org.hl7.fhir.r5.model.Invoice;
016
017/*
018  Copyright (c) 2011+, HL7, Inc.
019  All rights reserved.
020  
021  Redistribution and use in source and binary forms, with or without modification, 
022  are permitted provided that the following conditions are met:
023  
024   * Redistributions of source code must retain the above copyright notice, this 
025     list of conditions and the following disclaimer.
026   * Redistributions in binary form must reproduce the above copyright notice, 
027     this list of conditions and the following disclaimer in the documentation 
028     and/or other materials provided with the distribution.
029   * Neither the name of HL7 nor the names of its contributors may be used to 
030     endorse or promote products derived from this software without specific 
031     prior written permission.
032  
033  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 
034  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 
035  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 
036  IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 
037  INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 
038  NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 
039  PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 
040  WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
041  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
042  POSSIBILITY OF SUCH DAMAGE.
043  
044*/
045// Generated on Sun, Feb 24, 2019 11:37+1100 for FHIR v4.0.0
046public class Invoice40_50 {
047
048  public static org.hl7.fhir.r5.model.Invoice convertInvoice(org.hl7.fhir.r4.model.Invoice src) throws FHIRException {
049    if (src == null)
050      return null;
051    org.hl7.fhir.r5.model.Invoice tgt = new org.hl7.fhir.r5.model.Invoice();
052    ConversionContext40_50.INSTANCE.getVersionConvertor_40_50().copyDomainResource(src, tgt);
053    for (org.hl7.fhir.r4.model.Identifier t : src.getIdentifier())
054      tgt.addIdentifier(Identifier40_50.convertIdentifier(t));
055    if (src.hasStatus())
056      tgt.setStatusElement(convertInvoiceStatus(src.getStatusElement()));
057    if (src.hasCancelledReason())
058      tgt.setCancelledReasonElement(String40_50.convertString(src.getCancelledReasonElement()));
059    if (src.hasType())
060      tgt.setType(CodeableConcept40_50.convertCodeableConcept(src.getType()));
061    if (src.hasSubject())
062      tgt.setSubject(Reference40_50.convertReference(src.getSubject()));
063    if (src.hasRecipient())
064      tgt.setRecipient(Reference40_50.convertReference(src.getRecipient()));
065    if (src.hasDate())
066      tgt.setDateElement(DateTime40_50.convertDateTime(src.getDateElement()));
067    for (org.hl7.fhir.r4.model.Invoice.InvoiceParticipantComponent t : src.getParticipant())
068      tgt.addParticipant(convertInvoiceParticipantComponent(t));
069    if (src.hasIssuer())
070      tgt.setIssuer(Reference40_50.convertReference(src.getIssuer()));
071    if (src.hasAccount())
072      tgt.setAccount(Reference40_50.convertReference(src.getAccount()));
073    for (org.hl7.fhir.r4.model.Invoice.InvoiceLineItemComponent t : src.getLineItem())
074      tgt.addLineItem(convertInvoiceLineItemComponent(t));
075//    for (org.hl7.fhir.r4.model.Invoice.InvoiceLineItemPriceComponentComponent t : src.getTotalPriceComponent())
076//      tgt.addTotalPriceComponent(convertInvoiceLineItemPriceComponentComponent(t));
077    if (src.hasTotalNet())
078      tgt.setTotalNet(Money40_50.convertMoney(src.getTotalNet()));
079    if (src.hasTotalGross())
080      tgt.setTotalGross(Money40_50.convertMoney(src.getTotalGross()));
081    if (src.hasPaymentTerms())
082      tgt.setPaymentTermsElement(MarkDown40_50.convertMarkdown(src.getPaymentTermsElement()));
083    for (org.hl7.fhir.r4.model.Annotation t : src.getNote()) tgt.addNote(Annotation40_50.convertAnnotation(t));
084    return tgt;
085  }
086
087  public static org.hl7.fhir.r4.model.Invoice convertInvoice(org.hl7.fhir.r5.model.Invoice src) throws FHIRException {
088    if (src == null)
089      return null;
090    org.hl7.fhir.r4.model.Invoice tgt = new org.hl7.fhir.r4.model.Invoice();
091    ConversionContext40_50.INSTANCE.getVersionConvertor_40_50().copyDomainResource(src, tgt);
092    for (org.hl7.fhir.r5.model.Identifier t : src.getIdentifier())
093      tgt.addIdentifier(Identifier40_50.convertIdentifier(t));
094    if (src.hasStatus())
095      tgt.setStatusElement(convertInvoiceStatus(src.getStatusElement()));
096    if (src.hasCancelledReason())
097      tgt.setCancelledReasonElement(String40_50.convertString(src.getCancelledReasonElement()));
098    if (src.hasType())
099      tgt.setType(CodeableConcept40_50.convertCodeableConcept(src.getType()));
100    if (src.hasSubject())
101      tgt.setSubject(Reference40_50.convertReference(src.getSubject()));
102    if (src.hasRecipient())
103      tgt.setRecipient(Reference40_50.convertReference(src.getRecipient()));
104    if (src.hasDate())
105      tgt.setDateElement(DateTime40_50.convertDateTime(src.getDateElement()));
106    for (org.hl7.fhir.r5.model.Invoice.InvoiceParticipantComponent t : src.getParticipant())
107      tgt.addParticipant(convertInvoiceParticipantComponent(t));
108    if (src.hasIssuer())
109      tgt.setIssuer(Reference40_50.convertReference(src.getIssuer()));
110    if (src.hasAccount())
111      tgt.setAccount(Reference40_50.convertReference(src.getAccount()));
112    for (org.hl7.fhir.r5.model.Invoice.InvoiceLineItemComponent t : src.getLineItem())
113      tgt.addLineItem(convertInvoiceLineItemComponent(t));
114//    for (org.hl7.fhir.r5.model.Invoice.InvoiceLineItemPriceComponentComponent t : src.getTotalPriceComponent())
115//      tgt.addTotalPriceComponent(convertInvoiceLineItemPriceComponentComponent(t));
116    if (src.hasTotalNet())
117      tgt.setTotalNet(Money40_50.convertMoney(src.getTotalNet()));
118    if (src.hasTotalGross())
119      tgt.setTotalGross(Money40_50.convertMoney(src.getTotalGross()));
120    if (src.hasPaymentTerms())
121      tgt.setPaymentTermsElement(MarkDown40_50.convertMarkdown(src.getPaymentTermsElement()));
122    for (org.hl7.fhir.r5.model.Annotation t : src.getNote()) tgt.addNote(Annotation40_50.convertAnnotation(t));
123    return tgt;
124  }
125
126  static public org.hl7.fhir.r5.model.Enumeration<org.hl7.fhir.r5.model.Invoice.InvoiceStatus> convertInvoiceStatus(org.hl7.fhir.r4.model.Enumeration<org.hl7.fhir.r4.model.Invoice.InvoiceStatus> src) throws FHIRException {
127      if (src == null || src.isEmpty())
128          return null;
129      Enumeration<Invoice.InvoiceStatus> tgt = new Enumeration<>(new Invoice.InvoiceStatusEnumFactory());
130      ConversionContext40_50.INSTANCE.getVersionConvertor_40_50().copyElement(src, tgt);
131      if (src.getValue() == null) {
132          tgt.setValue(null);
133      } else {
134          switch (src.getValue()) {
135              case DRAFT:
136                  tgt.setValue(Invoice.InvoiceStatus.DRAFT);
137                  break;
138              case ISSUED:
139                  tgt.setValue(Invoice.InvoiceStatus.ISSUED);
140                  break;
141              case BALANCED:
142                  tgt.setValue(Invoice.InvoiceStatus.BALANCED);
143                  break;
144              case CANCELLED:
145                  tgt.setValue(Invoice.InvoiceStatus.CANCELLED);
146                  break;
147              case ENTEREDINERROR:
148                  tgt.setValue(Invoice.InvoiceStatus.ENTEREDINERROR);
149                  break;
150              default:
151                  tgt.setValue(Invoice.InvoiceStatus.NULL);
152                  break;
153          }
154      }
155      return tgt;
156  }
157
158  static public org.hl7.fhir.r4.model.Enumeration<org.hl7.fhir.r4.model.Invoice.InvoiceStatus> convertInvoiceStatus(org.hl7.fhir.r5.model.Enumeration<org.hl7.fhir.r5.model.Invoice.InvoiceStatus> src) throws FHIRException {
159      if (src == null || src.isEmpty())
160          return null;
161      org.hl7.fhir.r4.model.Enumeration<org.hl7.fhir.r4.model.Invoice.InvoiceStatus> tgt = new org.hl7.fhir.r4.model.Enumeration<>(new org.hl7.fhir.r4.model.Invoice.InvoiceStatusEnumFactory());
162      ConversionContext40_50.INSTANCE.getVersionConvertor_40_50().copyElement(src, tgt);
163      if (src.getValue() == null) {
164          tgt.setValue(null);
165      } else {
166          switch (src.getValue()) {
167              case DRAFT:
168                  tgt.setValue(org.hl7.fhir.r4.model.Invoice.InvoiceStatus.DRAFT);
169                  break;
170              case ISSUED:
171                  tgt.setValue(org.hl7.fhir.r4.model.Invoice.InvoiceStatus.ISSUED);
172                  break;
173              case BALANCED:
174                  tgt.setValue(org.hl7.fhir.r4.model.Invoice.InvoiceStatus.BALANCED);
175                  break;
176              case CANCELLED:
177                  tgt.setValue(org.hl7.fhir.r4.model.Invoice.InvoiceStatus.CANCELLED);
178                  break;
179              case ENTEREDINERROR:
180                  tgt.setValue(org.hl7.fhir.r4.model.Invoice.InvoiceStatus.ENTEREDINERROR);
181                  break;
182              default:
183                  tgt.setValue(org.hl7.fhir.r4.model.Invoice.InvoiceStatus.NULL);
184                  break;
185          }
186      }
187      return tgt;
188  }
189
190  public static org.hl7.fhir.r5.model.Invoice.InvoiceParticipantComponent convertInvoiceParticipantComponent(org.hl7.fhir.r4.model.Invoice.InvoiceParticipantComponent src) throws FHIRException {
191    if (src == null)
192      return null;
193    org.hl7.fhir.r5.model.Invoice.InvoiceParticipantComponent tgt = new org.hl7.fhir.r5.model.Invoice.InvoiceParticipantComponent();
194    ConversionContext40_50.INSTANCE.getVersionConvertor_40_50().copyBackboneElement(src, tgt);
195    if (src.hasRole())
196      tgt.setRole(CodeableConcept40_50.convertCodeableConcept(src.getRole()));
197    if (src.hasActor())
198      tgt.setActor(Reference40_50.convertReference(src.getActor()));
199    return tgt;
200  }
201
202  public static org.hl7.fhir.r4.model.Invoice.InvoiceParticipantComponent convertInvoiceParticipantComponent(org.hl7.fhir.r5.model.Invoice.InvoiceParticipantComponent src) throws FHIRException {
203    if (src == null)
204      return null;
205    org.hl7.fhir.r4.model.Invoice.InvoiceParticipantComponent tgt = new org.hl7.fhir.r4.model.Invoice.InvoiceParticipantComponent();
206    ConversionContext40_50.INSTANCE.getVersionConvertor_40_50().copyBackboneElement(src, tgt);
207    if (src.hasRole())
208      tgt.setRole(CodeableConcept40_50.convertCodeableConcept(src.getRole()));
209    if (src.hasActor())
210      tgt.setActor(Reference40_50.convertReference(src.getActor()));
211    return tgt;
212  }
213
214  public static org.hl7.fhir.r5.model.Invoice.InvoiceLineItemComponent convertInvoiceLineItemComponent(org.hl7.fhir.r4.model.Invoice.InvoiceLineItemComponent src) throws FHIRException {
215    if (src == null)
216      return null;
217    org.hl7.fhir.r5.model.Invoice.InvoiceLineItemComponent tgt = new org.hl7.fhir.r5.model.Invoice.InvoiceLineItemComponent();
218    ConversionContext40_50.INSTANCE.getVersionConvertor_40_50().copyBackboneElement(src, tgt);
219    if (src.hasSequence())
220      tgt.setSequenceElement(PositiveInt40_50.convertPositiveInt(src.getSequenceElement()));
221    if (src.hasChargeItem())
222      tgt.setChargeItem(ConversionContext40_50.INSTANCE.getVersionConvertor_40_50().convertType(src.getChargeItem()));
223//    for (org.hl7.fhir.r4.model.Invoice.InvoiceLineItemPriceComponentComponent t : src.getPriceComponent())
224//      tgt.addPriceComponent(convertInvoiceLineItemPriceComponentComponent(t));
225    return tgt;
226  }
227
228  public static org.hl7.fhir.r4.model.Invoice.InvoiceLineItemComponent convertInvoiceLineItemComponent(org.hl7.fhir.r5.model.Invoice.InvoiceLineItemComponent src) throws FHIRException {
229    if (src == null)
230      return null;
231    org.hl7.fhir.r4.model.Invoice.InvoiceLineItemComponent tgt = new org.hl7.fhir.r4.model.Invoice.InvoiceLineItemComponent();
232    ConversionContext40_50.INSTANCE.getVersionConvertor_40_50().copyBackboneElement(src, tgt);
233    if (src.hasSequence())
234      tgt.setSequenceElement(PositiveInt40_50.convertPositiveInt(src.getSequenceElement()));
235    if (src.hasChargeItem())
236      tgt.setChargeItem(ConversionContext40_50.INSTANCE.getVersionConvertor_40_50().convertType(src.getChargeItem()));
237//    for (org.hl7.fhir.r5.model.Invoice.InvoiceLineItemPriceComponentComponent t : src.getPriceComponent())
238//      tgt.addPriceComponent(convertInvoiceLineItemPriceComponentComponent(t));
239    return tgt;
240  }
241
242//  public static org.hl7.fhir.r5.model.Invoice.InvoiceLineItemPriceComponentComponent convertInvoiceLineItemPriceComponentComponent(org.hl7.fhir.r4.model.Invoice.InvoiceLineItemPriceComponentComponent src) throws FHIRException {
243//    if (src == null)
244//      return null;
245//    org.hl7.fhir.r5.model.Invoice.InvoiceLineItemPriceComponentComponent tgt = new org.hl7.fhir.r5.model.Invoice.InvoiceLineItemPriceComponentComponent();
246//    ConversionContext40_50.INSTANCE.getVersionConvertor_40_50().copyBackboneElement(src, tgt);
247//    if (src.hasType())
248//      tgt.setTypeElement(convertInvoicePriceComponentType(src.getTypeElement()));
249//    if (src.hasCode())
250//      tgt.setCode(CodeableConcept40_50.convertCodeableConcept(src.getCode()));
251//    if (src.hasFactor())
252//      tgt.setFactorElement(Decimal40_50.convertDecimal(src.getFactorElement()));
253//    if (src.hasAmount())
254//      tgt.setAmount(Money40_50.convertMoney(src.getAmount()));
255//    return tgt;
256//  }
257//
258//  public static org.hl7.fhir.r4.model.Invoice.InvoiceLineItemPriceComponentComponent convertInvoiceLineItemPriceComponentComponent(org.hl7.fhir.r5.model.Invoice.InvoiceLineItemPriceComponentComponent src) throws FHIRException {
259//    if (src == null)
260//      return null;
261//    org.hl7.fhir.r4.model.Invoice.InvoiceLineItemPriceComponentComponent tgt = new org.hl7.fhir.r4.model.Invoice.InvoiceLineItemPriceComponentComponent();
262//    ConversionContext40_50.INSTANCE.getVersionConvertor_40_50().copyBackboneElement(src, tgt);
263//    if (src.hasType())
264//      tgt.setTypeElement(convertInvoicePriceComponentType(src.getTypeElement()));
265//    if (src.hasCode())
266//      tgt.setCode(CodeableConcept40_50.convertCodeableConcept(src.getCode()));
267//    if (src.hasFactor())
268//      tgt.setFactorElement(Decimal40_50.convertDecimal(src.getFactorElement()));
269//    if (src.hasAmount())
270//      tgt.setAmount(Money40_50.convertMoney(src.getAmount()));
271//    return tgt;
272//  }
273//
274//  static public org.hl7.fhir.r5.model.Enumeration<org.hl7.fhir.r5.model.Enumerations.InvoicePriceComponentType> convertInvoicePriceComponentType(org.hl7.fhir.r4.model.Enumeration<org.hl7.fhir.r4.model.Invoice.InvoicePriceComponentType> src) throws FHIRException {
275//    if (src == null || src.isEmpty())
276//      return null;
277//    org.hl7.fhir.r5.model.Enumeration<org.hl7.fhir.r5.model.Enumerations.InvoicePriceComponentType> tgt = new org.hl7.fhir.r5.model.Enumeration<>(new org.hl7.fhir.r5.model.Enumerations.InvoicePriceComponentTypeEnumFactory());
278//    ConversionContext40_50.INSTANCE.getVersionConvertor_40_50().copyElement(src, tgt);
279//    switch (src.getValue()) {
280//      case BASE:
281//        tgt.setValue(org.hl7.fhir.r5.model.Enumerations.InvoicePriceComponentType.BASE);
282//        break;
283//      case SURCHARGE:
284//        tgt.setValue(org.hl7.fhir.r5.model.Enumerations.InvoicePriceComponentType.SURCHARGE);
285//        break;
286//      case DEDUCTION:
287//        tgt.setValue(org.hl7.fhir.r5.model.Enumerations.InvoicePriceComponentType.DEDUCTION);
288//        break;
289//      case DISCOUNT:
290//        tgt.setValue(org.hl7.fhir.r5.model.Enumerations.InvoicePriceComponentType.DISCOUNT);
291//        break;
292//      case TAX:
293//        tgt.setValue(org.hl7.fhir.r5.model.Enumerations.InvoicePriceComponentType.TAX);
294//        break;
295//      case INFORMATIONAL:
296//        tgt.setValue(org.hl7.fhir.r5.model.Enumerations.InvoicePriceComponentType.INFORMATIONAL);
297//        break;
298//      default:
299//        tgt.setValue(org.hl7.fhir.r5.model.Enumerations.InvoicePriceComponentType.NULL);
300//        break;
301//    }
302//    return tgt;
303//  }
304//
305//  static public org.hl7.fhir.r4.model.Enumeration<org.hl7.fhir.r4.model.Invoice.InvoicePriceComponentType> convertInvoicePriceComponentType(org.hl7.fhir.r5.model.Enumeration<org.hl7.fhir.r5.model.Enumerations.InvoicePriceComponentType> src) throws FHIRException {
306//    if (src == null || src.isEmpty())
307//      return null;
308//    org.hl7.fhir.r4.model.Enumeration<org.hl7.fhir.r4.model.Invoice.InvoicePriceComponentType> tgt = new org.hl7.fhir.r4.model.Enumeration<>(new org.hl7.fhir.r4.model.Invoice.InvoicePriceComponentTypeEnumFactory());
309//    ConversionContext40_50.INSTANCE.getVersionConvertor_40_50().copyElement(src, tgt);
310//    switch (src.getValue()) {
311//      case BASE:
312//        tgt.setValue(org.hl7.fhir.r4.model.Invoice.InvoicePriceComponentType.BASE);
313//        break;
314//      case SURCHARGE:
315//        tgt.setValue(org.hl7.fhir.r4.model.Invoice.InvoicePriceComponentType.SURCHARGE);
316//        break;
317//      case DEDUCTION:
318//        tgt.setValue(org.hl7.fhir.r4.model.Invoice.InvoicePriceComponentType.DEDUCTION);
319//        break;
320//      case DISCOUNT:
321//        tgt.setValue(org.hl7.fhir.r4.model.Invoice.InvoicePriceComponentType.DISCOUNT);
322//        break;
323//      case TAX:
324//        tgt.setValue(org.hl7.fhir.r4.model.Invoice.InvoicePriceComponentType.TAX);
325//        break;
326//      case INFORMATIONAL:
327//        tgt.setValue(org.hl7.fhir.r4.model.Invoice.InvoicePriceComponentType.INFORMATIONAL);
328//        break;
329//      default:
330//        tgt.setValue(org.hl7.fhir.r4.model.Invoice.InvoicePriceComponentType.NULL);
331//        break;
332//    }
333//    return tgt;
334//  }
335}