001package org.hl7.fhir.convertors.conv10_30;
002
003import org.hl7.fhir.convertors.advisors.impl.BaseAdvisor_10_30;
004import org.hl7.fhir.convertors.context.ConversionContext10_30;
005import org.hl7.fhir.convertors.conv10_30.datatypes10_30.Element10_30;
006import org.hl7.fhir.convertors.conv10_30.datatypes10_30.Type10_30;
007import org.hl7.fhir.convertors.conv10_30.resources10_30.Resource10_30;
008import org.hl7.fhir.dstu2.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_10_30 {
042
043  private final BaseAdvisor_10_30 advisor;
044  private final Element10_30 elementConvertor;
045  private final Resource10_30 resourceConvertor;
046  private final Type10_30 typeConvertor;
047
048  public VersionConvertor_10_30(@Nonnull BaseAdvisor_10_30 advisor) {
049    this.advisor = advisor;
050    this.elementConvertor = new Element10_30(advisor);
051    this.resourceConvertor = new Resource10_30(advisor);
052    this.typeConvertor = new Type10_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_10_30 advisor() {
063    return advisor;
064  }
065
066  public void copyResource(@Nonnull org.hl7.fhir.dstu2.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.dstu2.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.dstu2.model.Resource src) throws FHIRException {
077    ConversionContext10_30.INSTANCE.init(this, src.fhirType());
078    try {
079      return resourceConvertor.convertResource(src);
080    } finally {
081      ConversionContext10_30.INSTANCE.close(src.fhirType());
082    }
083  }
084
085  public org.hl7.fhir.dstu2.model.Resource convertResource(@Nonnull org.hl7.fhir.dstu3.model.Resource src) throws FHIRException {
086    ConversionContext10_30.INSTANCE.init(this, src.fhirType());
087    try {
088      return resourceConvertor.convertResource(src);
089    } finally {
090      ConversionContext10_30.INSTANCE.close(src.fhirType());
091    }
092  }
093
094  public org.hl7.fhir.dstu3.model.Type convertType(@Nonnull org.hl7.fhir.dstu2.model.Type src) throws FHIRException {
095    ConversionContext10_30.INSTANCE.init(this, src.fhirType());
096    try {
097      return typeConvertor.convertType(src);
098    } finally {
099      ConversionContext10_30.INSTANCE.close(src.fhirType());
100    }
101  }
102
103  public org.hl7.fhir.dstu2.model.Type convertType(@Nonnull org.hl7.fhir.dstu3.model.Type src) throws FHIRException {
104    ConversionContext10_30.INSTANCE.init(this, src.fhirType());
105    try {
106      return typeConvertor.convertType(src);
107    } finally {
108      ConversionContext10_30.INSTANCE.close(src.fhirType());
109    }
110  }
111
112  public void copyDomainResource(@Nonnull org.hl7.fhir.dstu2.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.dstu2.model.DomainResource tgt) throws FHIRException {
119    resourceConvertor.copyDomainResource(src, tgt);
120  }
121
122  public void copyElement(@Nonnull org.hl7.fhir.dstu2.model.Element src,
123                          @Nonnull org.hl7.fhir.dstu3.model.Element tgt, String... var) throws FHIRException {
124    elementConvertor.copyElement(src, tgt, ConversionContext10_30.INSTANCE.path(), var);
125  }
126
127  public void copyElement(@Nonnull org.hl7.fhir.dstu3.model.Element src,
128                          @Nonnull org.hl7.fhir.dstu2.model.Element tgt,
129                          String... var) throws FHIRException {
130    elementConvertor.copyElement(src, tgt, ConversionContext10_30.INSTANCE.path(), var);
131  }
132
133  public void copyElement(@Nonnull org.hl7.fhir.dstu3.model.DomainResource src,
134                          @Nonnull org.hl7.fhir.dstu2.model.Element tgt,
135                          String... var) throws FHIRException {
136    elementConvertor.copyElement(src, tgt, ConversionContext10_30.INSTANCE.path(), var);
137  }
138
139}