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