001package org.hl7.fhir.convertors.conv14_30;
002
003import org.hl7.fhir.convertors.advisors.impl.BaseAdvisor_14_30;
004import org.hl7.fhir.convertors.context.ConversionContext14_30;
005import org.hl7.fhir.convertors.conv14_30.datatypes14_30.Element14_30;
006import org.hl7.fhir.convertors.conv14_30.datatypes14_30.Type14_30;
007import org.hl7.fhir.convertors.conv14_30.resources14_30.Resource14_30;
008import org.hl7.fhir.dstu2016may.model.CodeableConcept;
009import org.hl7.fhir.exceptions.FHIRException;
010
011import javax.annotation.Nonnull;
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
041public class VersionConvertor_14_30 {
042
043  private final BaseAdvisor_14_30 advisor;
044  private final Element14_30 elementConvertor;
045  private final Resource14_30 resourceConvertor;
046  private final Type14_30 typeConvertor;
047
048  public VersionConvertor_14_30(@Nonnull BaseAdvisor_14_30 advisor) {
049    this.advisor = advisor;
050    this.elementConvertor = new Element14_30(advisor);
051    this.resourceConvertor = new Resource14_30(advisor);
052    this.typeConvertor = new Type14_30(advisor);
053  }
054
055  static public boolean isJurisdiction(@Nonnull CodeableConcept t) {
056    return t.hasCoding()
057      && ("http://unstats.un.org/unsd/methods/m49/m49.htm".equals(t.getCoding().get(0).getSystem())
058      || "urn:iso:std:iso:3166".equals(t.getCoding().get(0).getSystem())
059      || "https://www.usps.com/".equals(t.getCoding().get(0).getSystem()));
060  }
061
062  public BaseAdvisor_14_30 advisor() {
063    return advisor;
064  }
065
066  public void copyResource(@Nonnull org.hl7.fhir.dstu2016may.model.Resource src,
067                           @Nonnull org.hl7.fhir.dstu3.model.Resource tgt) throws FHIRException {
068    resourceConvertor.copyResource(src, tgt);
069  }
070
071  public void copyResource(@Nonnull org.hl7.fhir.dstu3.model.Resource src,
072                           @Nonnull org.hl7.fhir.dstu2016may.model.Resource tgt) throws FHIRException {
073    resourceConvertor.copyResource(src, tgt);
074  }
075
076  public org.hl7.fhir.dstu3.model.Resource convertResource(@Nonnull org.hl7.fhir.dstu2016may.model.Resource src) throws FHIRException {
077    ConversionContext14_30.INSTANCE.init(this, src.fhirType());
078    try {
079      return resourceConvertor.convertResource(src);
080    } finally {
081      ConversionContext14_30.INSTANCE.close(src.fhirType());
082    }
083  }
084
085  public org.hl7.fhir.dstu2016may.model.Resource convertResource(@Nonnull org.hl7.fhir.dstu3.model.Resource src) throws FHIRException {
086    ConversionContext14_30.INSTANCE.init(this, src.fhirType());
087    try {
088      return resourceConvertor.convertResource(src);
089    } finally {
090      ConversionContext14_30.INSTANCE.close(src.fhirType());
091    }
092  }
093
094  public org.hl7.fhir.dstu3.model.Type convertType(@Nonnull org.hl7.fhir.dstu2016may.model.Type src) throws FHIRException {
095    ConversionContext14_30.INSTANCE.init(this, src.fhirType());
096    try {
097      return typeConvertor.convertType(src);
098    } finally {
099      ConversionContext14_30.INSTANCE.close(src.fhirType());
100    }
101  }
102
103  public org.hl7.fhir.dstu2016may.model.Type convertType(@Nonnull org.hl7.fhir.dstu3.model.Type src) throws FHIRException {
104    ConversionContext14_30.INSTANCE.init(this, src.fhirType());
105    try {
106      return typeConvertor.convertType(src);
107    } finally {
108      ConversionContext14_30.INSTANCE.close(src.fhirType());
109    }
110  }
111
112  public void copyDomainResource(@Nonnull org.hl7.fhir.dstu2016may.model.DomainResource src,
113                                 @Nonnull org.hl7.fhir.dstu3.model.DomainResource tgt) throws FHIRException {
114    resourceConvertor.copyDomainResource(src, tgt);
115  }
116
117  public void copyDomainResource(@Nonnull org.hl7.fhir.dstu3.model.DomainResource src,
118                                 @Nonnull org.hl7.fhir.dstu2016may.model.DomainResource tgt) throws FHIRException {
119    resourceConvertor.copyDomainResource(src, tgt);
120  }
121
122  public void copyElement(@Nonnull org.hl7.fhir.dstu2016may.model.Element src,
123                          @Nonnull org.hl7.fhir.dstu3.model.Element tgt,
124                          String... var) throws FHIRException {
125    elementConvertor.copyElement(src, tgt, ConversionContext14_30.INSTANCE.path(), var);
126  }
127
128  public void copyElement(@Nonnull org.hl7.fhir.dstu3.model.Element src,
129                          @Nonnull org.hl7.fhir.dstu2016may.model.Element tgt,
130                          String... var) throws FHIRException {
131    elementConvertor.copyElement(src, tgt, ConversionContext14_30.INSTANCE.path(), var);
132  }
133}