001package org.hl7.fhir.convertors.conv10_40;
002
003import org.hl7.fhir.convertors.advisors.impl.BaseAdvisor_10_40;
004import org.hl7.fhir.convertors.context.ConversionContext10_40;
005import org.hl7.fhir.convertors.conv10_40.datatypes10_40.Element10_40;
006import org.hl7.fhir.convertors.conv10_40.datatypes10_40.Type10_40;
007import org.hl7.fhir.convertors.conv10_40.resources10_40.Resource10_40;
008import org.hl7.fhir.dstu2.model.CodeableConcept;
009import org.hl7.fhir.exceptions.FHIRException;
010
011import javax.annotation.Nonnull;
012import java.util.ArrayList;
013import java.util.List;
014
015/*
016  Copyright (c) 2011+, HL7, Inc.
017  All rights reserved.
018
019  Redistribution and use in source and binary forms, with or without modification,
020  are permitted provided that the following conditions are met:
021
022 * Redistributions of source code must retain the above copyright notice, this
023     list of conditions and the following disclaimer.
024 * Redistributions in binary form must reproduce the above copyright notice,
025     this list of conditions and the following disclaimer in the documentation
026     and/or other materials provided with the distribution.
027 * Neither the name of HL7 nor the names of its contributors may be used to
028     endorse or promote products derived from this software without specific
029     prior written permission.
030
031  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
032  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
033  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
034  IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
035  INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
036  NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
037  PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
038  WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
039  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
040  POSSIBILITY OF SUCH DAMAGE.
041 */
042
043public class VersionConvertor_10_40 {
044  static public List<String> CANONICAL_URLS = new ArrayList<String>();
045
046  static {
047    CANONICAL_URLS.add("http://hl7.org/fhir/StructureDefinition/11179-permitted-value-conceptmap");
048    CANONICAL_URLS.add("http://hl7.org/fhir/StructureDefinition/11179-permitted-value-valueset");
049    CANONICAL_URLS.add("http://hl7.org/fhir/StructureDefinition/codesystem-map");
050    CANONICAL_URLS.add("http://hl7.org/fhir/StructureDefinition/cqif-library");
051    CANONICAL_URLS.add("http://hl7.org/fhir/StructureDefinition/elementdefinition-allowedUnits");
052    CANONICAL_URLS.add("http://hl7.org/fhir/StructureDefinition/elementdefinition-inheritedExtensibleValueSet");
053    CANONICAL_URLS.add("http://hl7.org/fhir/StructureDefinition/elementdefinition-maxValueSet");
054    CANONICAL_URLS.add("http://hl7.org/fhir/StructureDefinition/elementdefinition-minValueSet");
055    CANONICAL_URLS.add("http://hl7.org/fhir/StructureDefinition/event-instantiatesCanonical");
056    CANONICAL_URLS.add("http://hl7.org/fhir/StructureDefinition/questionnaire-allowedProfile");
057    CANONICAL_URLS.add("http://hl7.org/fhir/StructureDefinition/questionnaire-deMap");
058    CANONICAL_URLS.add("http://hl7.org/fhir/StructureDefinition/questionnaire-sourceStructureMap");
059    CANONICAL_URLS.add("http://hl7.org/fhir/StructureDefinition/questionnaire-targetStructureMap");
060    CANONICAL_URLS.add("http://hl7.org/fhir/StructureDefinition/questionnaire-unit-valueSet");
061    CANONICAL_URLS.add("http://hl7.org/fhir/StructureDefinition/valueset-map");
062    CANONICAL_URLS.add("http://hl7.org/fhir/StructureDefinition/valueset-supplement");
063    CANONICAL_URLS.add("http://hl7.org/fhir/StructureDefinition/valueset-system");
064  }
065
066  private final BaseAdvisor_10_40 advisor;
067  private final Element10_40 elementConvertor;
068  private final Resource10_40 resourceConvertor;
069  private final Type10_40 typeConvertor;
070
071  public VersionConvertor_10_40(@Nonnull BaseAdvisor_10_40 advisor) {
072    this.advisor = advisor;
073    this.elementConvertor = new Element10_40(advisor);
074    this.resourceConvertor = new Resource10_40(advisor);
075    this.typeConvertor = new Type10_40(advisor);
076  }
077
078  static public boolean isExemptExtension(@Nonnull String url, @Nonnull String[] extensionsToIgnore) {
079    boolean ok = false;
080    for (String s : extensionsToIgnore) if (s.equals(url)) ok = true;
081    return ok;
082  }
083
084  static public boolean isJurisdiction(@Nonnull CodeableConcept t) {
085    return t.hasCoding()
086      && ("http://unstats.un.org/unsd/methods/m49/m49.htm".equals(t.getCoding().get(0).getSystem())
087      || "urn:iso:std:iso:3166".equals(t.getCoding().get(0).getSystem())
088      || "https://www.usps.com/".equals(t.getCoding().get(0).getSystem()));
089  }
090
091  public BaseAdvisor_10_40 advisor() {
092    return advisor;
093  }
094
095  public void copyResource(@Nonnull org.hl7.fhir.dstu2.model.Resource src,
096                           @Nonnull org.hl7.fhir.r4.model.Resource tgt) throws FHIRException {
097    resourceConvertor.copyResource(src, tgt);
098  }
099
100  public void copyResource(@Nonnull org.hl7.fhir.r4.model.Resource src,
101                           @Nonnull org.hl7.fhir.dstu2.model.Resource tgt) throws FHIRException {
102    resourceConvertor.copyResource(src, tgt);
103  }
104
105  public org.hl7.fhir.r4.model.Resource convertResource(@Nonnull org.hl7.fhir.dstu2.model.Resource src) throws FHIRException {
106    ConversionContext10_40.INSTANCE.init(this, src.fhirType());
107    try {
108      return resourceConvertor.convertResource(src);
109    } finally {
110      ConversionContext10_40.INSTANCE.close(src.fhirType());
111    }
112  }
113
114  public org.hl7.fhir.dstu2.model.Resource convertResource(@Nonnull org.hl7.fhir.r4.model.Resource src) throws FHIRException {
115    ConversionContext10_40.INSTANCE.init(this, src.fhirType());
116    try {
117      return resourceConvertor.convertResource(src);
118    } finally {
119      ConversionContext10_40.INSTANCE.close(src.fhirType());
120    }
121  }
122
123  public org.hl7.fhir.r4.model.Type convertType(@Nonnull org.hl7.fhir.dstu2.model.Type src) throws FHIRException {
124    ConversionContext10_40.INSTANCE.init(this, src.fhirType());
125    try {
126      return typeConvertor.convertType(src);
127    } finally {
128      ConversionContext10_40.INSTANCE.close(src.fhirType());
129    }
130  }
131
132  public org.hl7.fhir.dstu2.model.Type convertType(@Nonnull org.hl7.fhir.r4.model.Type src) throws FHIRException {
133    ConversionContext10_40.INSTANCE.init(this, src.fhirType());
134    try {
135      return typeConvertor.convertType(src);
136    } finally {
137      ConversionContext10_40.INSTANCE.close(src.fhirType());
138    }
139  }
140
141  public void copyDomainResource(@Nonnull org.hl7.fhir.dstu2.model.DomainResource src,
142                                 @Nonnull org.hl7.fhir.r4.model.DomainResource tgt) throws FHIRException {
143    resourceConvertor.copyDomainResource(src, tgt);
144  }
145
146  public void copyDomainResource(@Nonnull org.hl7.fhir.r4.model.DomainResource src,
147                                 @Nonnull org.hl7.fhir.dstu2.model.DomainResource tgt) throws FHIRException {
148    resourceConvertor.copyDomainResource(src, tgt);
149  }
150
151  public void copyElement(@Nonnull org.hl7.fhir.dstu2.model.Element src,
152                          @Nonnull org.hl7.fhir.r4.model.Element tgt,
153                          String... var) throws FHIRException {
154    elementConvertor.copyElement(src, tgt, ConversionContext10_40.INSTANCE.path(), var);
155  }
156
157  public void copyElement(@Nonnull org.hl7.fhir.r4.model.Element src,
158                          @Nonnull org.hl7.fhir.dstu2.model.Element tgt,
159                          String... var) throws FHIRException {
160    elementConvertor.copyElement(src, tgt, ConversionContext10_40.INSTANCE.path(), var);
161  }
162
163  public void copyElement(@Nonnull org.hl7.fhir.r4.model.DomainResource src,
164                          @Nonnull org.hl7.fhir.dstu2.model.Element tgt,
165                          String... var) throws FHIRException {
166    elementConvertor.copyElement(src, tgt, ConversionContext10_40.INSTANCE.path(), var);
167  }
168
169}