001package org.hl7.fhir.convertors.conv10_50;
002
003import org.hl7.fhir.convertors.advisors.impl.BaseAdvisor_10_50;
004import org.hl7.fhir.convertors.context.ConversionContext10_50;
005import org.hl7.fhir.convertors.conv10_50.datatypes10_50.Element10_50;
006import org.hl7.fhir.convertors.conv10_50.datatypes10_50.Type10_50;
007import org.hl7.fhir.convertors.conv10_50.resources10_50.Resource10_50;
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_50 {
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_50 advisor;
067  private final Element10_50 elementConvertor;
068  private final Resource10_50 resourceConvertor;
069  private final Type10_50 typeConvertor;
070
071  public VersionConvertor_10_50(@Nonnull BaseAdvisor_10_50 advisor) {
072    this.advisor = advisor;
073    this.elementConvertor = new Element10_50(advisor);
074    this.resourceConvertor = new Resource10_50(advisor);
075    this.typeConvertor = new Type10_50(advisor);
076  }
077
078  static public boolean isExemptExtension(@Nonnull String url,
079                                          @Nonnull String[] extensionsToIgnore) {
080    boolean ok = false;
081    for (String s : extensionsToIgnore) if (s.equals(url)) ok = true;
082    return ok;
083  }
084
085  static public boolean isJurisdiction(@Nonnull CodeableConcept t) {
086    return t.hasCoding()
087      && ("http://unstats.un.org/unsd/methods/m49/m49.htm".equals(t.getCoding().get(0).getSystem())
088      || "urn:iso:std:iso:3166".equals(t.getCoding().get(0).getSystem())
089      || "https://www.usps.com/".equals(t.getCoding().get(0).getSystem()));
090  }
091
092  public BaseAdvisor_10_50 advisor() {
093    return advisor;
094  }
095
096  public void copyResource(@Nonnull org.hl7.fhir.dstu2.model.Resource src,
097                           @Nonnull org.hl7.fhir.r5.model.Resource tgt) throws FHIRException {
098    resourceConvertor.copyResource(src, tgt);
099  }
100
101  public void copyResource(@Nonnull org.hl7.fhir.r5.model.Resource src,
102                           @Nonnull org.hl7.fhir.dstu2.model.Resource tgt) throws FHIRException {
103    resourceConvertor.copyResource(src, tgt);
104  }
105
106  public org.hl7.fhir.r5.model.Resource convertResource(@Nonnull org.hl7.fhir.dstu2.model.Resource src) throws FHIRException {
107    ConversionContext10_50.INSTANCE.init(this, src.fhirType());
108    try {
109      return resourceConvertor.convertResource(src);
110    } finally {
111      ConversionContext10_50.INSTANCE.close(src.fhirType());
112    }
113  }
114
115  public org.hl7.fhir.dstu2.model.Resource convertResource(@Nonnull org.hl7.fhir.r5.model.Resource src) throws FHIRException {
116    ConversionContext10_50.INSTANCE.init(this, src.fhirType());
117    try {
118      return resourceConvertor.convertResource(src);
119    } finally {
120      ConversionContext10_50.INSTANCE.close(src.fhirType());
121    }
122  }
123
124  public org.hl7.fhir.r5.model.DataType convertType(@Nonnull org.hl7.fhir.dstu2.model.Type src) throws FHIRException {
125    ConversionContext10_50.INSTANCE.init(this, src.fhirType());
126    try {
127      return typeConvertor.convertType(src);
128    } finally {
129      ConversionContext10_50.INSTANCE.close(src.fhirType());
130    }
131  }
132
133  public org.hl7.fhir.dstu2.model.Type convertType(@Nonnull org.hl7.fhir.r5.model.DataType src) throws FHIRException {
134    ConversionContext10_50.INSTANCE.init(this, src.fhirType());
135    try {
136      return typeConvertor.convertType(src);
137    } finally {
138      ConversionContext10_50.INSTANCE.close(src.fhirType());
139    }
140  }
141
142  public void copyDomainResource(@Nonnull org.hl7.fhir.dstu2.model.DomainResource src,
143                                 @Nonnull org.hl7.fhir.r5.model.DomainResource tgt) throws FHIRException {
144    resourceConvertor.copyDomainResource(src, tgt);
145  }
146
147  public void copyDomainResource(@Nonnull org.hl7.fhir.r5.model.DomainResource src,
148                                 @Nonnull org.hl7.fhir.dstu2.model.DomainResource tgt) throws FHIRException {
149    resourceConvertor.copyDomainResource(src, tgt);
150  }
151
152  public void copyElement(@Nonnull org.hl7.fhir.dstu2.model.Element src,
153                          @Nonnull org.hl7.fhir.r5.model.Element tgt,
154                          String... var) throws FHIRException {
155    elementConvertor.copyElement(src, tgt, ConversionContext10_50.INSTANCE.path(), var);
156  }
157
158  public void copyElement(@Nonnull org.hl7.fhir.r5.model.Element src,
159                          @Nonnull org.hl7.fhir.dstu2.model.Element tgt,
160                          String... var) throws FHIRException {
161    elementConvertor.copyElement(src, tgt, ConversionContext10_50.INSTANCE.path(), var);
162  }
163
164  public void copyElement(@Nonnull org.hl7.fhir.r5.model.DomainResource src,
165                          @Nonnull org.hl7.fhir.dstu2.model.Element tgt,
166                          String... var) throws FHIRException {
167    elementConvertor.copyElement(src, tgt, ConversionContext10_50.INSTANCE.path(), var);
168  }
169}