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