001package org.hl7.fhir.convertors.conv40_50;
002
003import org.hl7.fhir.convertors.advisors.impl.BaseAdvisor_40_50;
004import org.hl7.fhir.convertors.context.ConversionContext40_50;
005import org.hl7.fhir.convertors.conv40_50.datatypes40_50.Element40_50;
006import org.hl7.fhir.convertors.conv40_50.datatypes40_50.Type40_50;
007import org.hl7.fhir.convertors.conv40_50.resources40_50.Resource40_50;
008import org.hl7.fhir.exceptions.FHIRException;
009
010import javax.annotation.Nonnull;
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/**
041 * Our conversion class needs to be able to handle all the base data-types in FHIR; Resources, DomainResource, Element
042 */
043public class VersionConvertor_40_50 {
044  private final BaseAdvisor_40_50 advisor;
045  private final Element40_50 elementConvertor;
046  private final Resource40_50 resourceConvertor;
047  private final Type40_50 typeConvertor;
048
049  public VersionConvertor_40_50(@Nonnull BaseAdvisor_40_50 advisor) {
050    this.advisor = advisor;
051    this.elementConvertor = new Element40_50(advisor);
052    this.resourceConvertor = new Resource40_50(advisor);
053    this.typeConvertor = new Type40_50(advisor);
054  }
055
056  public BaseAdvisor_40_50 advisor() {
057    return advisor;
058  }
059
060  public void copyResource(@Nonnull org.hl7.fhir.r4.model.Resource src,
061                           @Nonnull org.hl7.fhir.r5.model.Resource tgt) throws FHIRException {
062    resourceConvertor.copyResource(src, tgt);
063  }
064
065  public void copyResource(@Nonnull org.hl7.fhir.r5.model.Resource src,
066                           @Nonnull org.hl7.fhir.r4.model.Resource tgt) throws FHIRException {
067    resourceConvertor.copyResource(src, tgt);
068  }
069
070  public org.hl7.fhir.r5.model.Resource convertResource(@Nonnull org.hl7.fhir.r4.model.Resource src) throws FHIRException {
071    ConversionContext40_50.INSTANCE.init(this, src.fhirType());
072    try {
073      return resourceConvertor.convertResource(src);
074    } finally {
075      ConversionContext40_50.INSTANCE.close(src.fhirType());
076    }
077  }
078
079  public org.hl7.fhir.r4.model.Resource convertResource(@Nonnull org.hl7.fhir.r5.model.Resource src) throws FHIRException {
080    ConversionContext40_50.INSTANCE.init(this, src.fhirType());
081    try {
082      return resourceConvertor.convertResource(src);
083    } finally {
084      ConversionContext40_50.INSTANCE.close(src.fhirType());
085    }
086  }
087
088  public org.hl7.fhir.r5.model.DataType convertType(@Nonnull org.hl7.fhir.r4.model.Type src) throws FHIRException {
089    ConversionContext40_50.INSTANCE.init(this, src.fhirType());
090    try {
091      return typeConvertor.convertType(src);
092    } finally {
093      ConversionContext40_50.INSTANCE.close(src.fhirType());
094    }
095  }
096
097  public org.hl7.fhir.r4.model.Type convertType(@Nonnull org.hl7.fhir.r5.model.DataType src) throws FHIRException {
098    ConversionContext40_50.INSTANCE.init(this, src.fhirType());
099    try {
100      return typeConvertor.convertType(src);
101    } finally {
102      ConversionContext40_50.INSTANCE.close(src.fhirType());
103    }
104  }
105
106  public void copyDomainResource(@Nonnull org.hl7.fhir.r4.model.DomainResource src,
107                                 @Nonnull org.hl7.fhir.r5.model.DomainResource tgt) throws FHIRException {
108    resourceConvertor.copyDomainResource(src, tgt);
109  }
110
111  public void copyDomainResource(@Nonnull org.hl7.fhir.r5.model.DomainResource src,
112                                 @Nonnull org.hl7.fhir.r4.model.DomainResource tgt) throws FHIRException {
113    resourceConvertor.copyDomainResource(src, tgt);
114  }
115
116  public void copyElement(@Nonnull org.hl7.fhir.r4.model.Element src,
117                          @Nonnull org.hl7.fhir.r5.model.Element tgt,
118                          String... var) throws FHIRException {
119    elementConvertor.copyElement(src, tgt, ConversionContext40_50.INSTANCE.path(), var);
120  }
121
122  public void copyElement(@Nonnull org.hl7.fhir.r5.model.Element src,
123                          @Nonnull org.hl7.fhir.r4.model.Element tgt,
124                          String... var) throws FHIRException {
125    elementConvertor.copyElement(src, tgt, ConversionContext40_50.INSTANCE.path(), var);
126  }
127}