001package org.hl7.fhir.convertors.conv10_30.resources10_30; 002 003import org.hl7.fhir.convertors.SourceElementComponentWrapper; 004import org.hl7.fhir.convertors.context.ConversionContext10_30; 005import org.hl7.fhir.convertors.conv10_30.VersionConvertor_10_30; 006import org.hl7.fhir.convertors.conv10_30.datatypes10_30.complextypes10_30.CodeableConcept10_30; 007import org.hl7.fhir.convertors.conv10_30.datatypes10_30.complextypes10_30.ContactPoint10_30; 008import org.hl7.fhir.convertors.conv10_30.datatypes10_30.complextypes10_30.Identifier10_30; 009import org.hl7.fhir.convertors.conv10_30.datatypes10_30.primitivetypes10_30.*; 010import org.hl7.fhir.dstu3.model.ConceptMap; 011import org.hl7.fhir.dstu3.model.ConceptMap.ConceptMapGroupComponent; 012import org.hl7.fhir.exceptions.FHIRException; 013 014import java.util.ArrayList; 015import java.util.List; 016 017public class ConceptMap10_30 { 018 019 public static org.hl7.fhir.dstu2.model.ConceptMap convertConceptMap(org.hl7.fhir.dstu3.model.ConceptMap src) throws FHIRException { 020 if (src == null || src.isEmpty()) 021 return null; 022 org.hl7.fhir.dstu2.model.ConceptMap tgt = new org.hl7.fhir.dstu2.model.ConceptMap(); 023 ConversionContext10_30.INSTANCE.getVersionConvertor_10_30().copyDomainResource(src, tgt); 024 if (src.hasUrlElement()) 025 tgt.setUrlElement(Uri10_30.convertUri(src.getUrlElement())); 026 if (src.hasIdentifier()) 027 tgt.setIdentifier(Identifier10_30.convertIdentifier(src.getIdentifier())); 028 if (src.hasVersionElement()) 029 tgt.setVersionElement(String10_30.convertString(src.getVersionElement())); 030 if (src.hasNameElement()) 031 tgt.setNameElement(String10_30.convertString(src.getNameElement())); 032 if (src.hasStatus()) 033 tgt.setStatusElement(Enumerations10_30.convertConformanceResourceStatus(src.getStatusElement())); 034 if (src.hasExperimental()) 035 tgt.setExperimentalElement(Boolean10_30.convertBoolean(src.getExperimentalElement())); 036 if (src.hasPublisherElement()) 037 tgt.setPublisherElement(String10_30.convertString(src.getPublisherElement())); 038 for (org.hl7.fhir.dstu3.model.ContactDetail t : src.getContact()) 039 tgt.addContact(convertConceptMapContactComponent(t)); 040 if (src.hasDate()) 041 tgt.setDateElement(DateTime10_30.convertDateTime(src.getDateElement())); 042 if (src.hasDescription()) 043 tgt.setDescription(src.getDescription()); 044 for (org.hl7.fhir.dstu3.model.UsageContext t : src.getUseContext()) 045 if (t.hasValueCodeableConcept()) 046 tgt.addUseContext(CodeableConcept10_30.convertCodeableConcept(t.getValueCodeableConcept())); 047 for (org.hl7.fhir.dstu3.model.CodeableConcept t : src.getJurisdiction()) 048 tgt.addUseContext(CodeableConcept10_30.convertCodeableConcept(t)); 049 if (src.hasPurpose()) 050 tgt.setRequirements(src.getPurpose()); 051 if (src.hasCopyright()) 052 tgt.setCopyright(src.getCopyright()); 053 if (src.hasSource()) 054 tgt.setSource(ConversionContext10_30.INSTANCE.getVersionConvertor_10_30().convertType(src.getSource())); 055 if (src.hasTarget()) 056 tgt.setTarget(ConversionContext10_30.INSTANCE.getVersionConvertor_10_30().convertType(src.getTarget())); 057 for (org.hl7.fhir.dstu3.model.ConceptMap.ConceptMapGroupComponent g : src.getGroup()) 058 for (org.hl7.fhir.dstu3.model.ConceptMap.SourceElementComponent t : g.getElement()) 059 tgt.addElement(convertSourceElementComponent(t, g)); 060 return tgt; 061 } 062 063 public static org.hl7.fhir.dstu3.model.ConceptMap convertConceptMap(org.hl7.fhir.dstu2.model.ConceptMap src) throws FHIRException { 064 if (src == null || src.isEmpty()) 065 return null; 066 org.hl7.fhir.dstu3.model.ConceptMap tgt = new org.hl7.fhir.dstu3.model.ConceptMap(); 067 ConversionContext10_30.INSTANCE.getVersionConvertor_10_30().copyDomainResource(src, tgt); 068 if (src.hasUrlElement()) 069 tgt.setUrlElement(Uri10_30.convertUri(src.getUrlElement())); 070 if (src.hasIdentifier()) 071 tgt.setIdentifier(Identifier10_30.convertIdentifier(src.getIdentifier())); 072 if (src.hasVersionElement()) 073 tgt.setVersionElement(String10_30.convertString(src.getVersionElement())); 074 if (src.hasNameElement()) 075 tgt.setNameElement(String10_30.convertString(src.getNameElement())); 076 if (src.hasStatus()) 077 tgt.setStatusElement(Enumerations10_30.convertConformanceResourceStatus(src.getStatusElement())); 078 if (src.hasExperimental()) 079 tgt.setExperimentalElement(Boolean10_30.convertBoolean(src.getExperimentalElement())); 080 if (src.hasPublisherElement()) 081 tgt.setPublisherElement(String10_30.convertString(src.getPublisherElement())); 082 for (org.hl7.fhir.dstu2.model.ConceptMap.ConceptMapContactComponent t : src.getContact()) 083 tgt.addContact(convertConceptMapContactComponent(t)); 084 if (src.hasDate()) 085 tgt.setDateElement(DateTime10_30.convertDateTime(src.getDateElement())); 086 if (src.hasDescription()) 087 tgt.setDescription(src.getDescription()); 088 for (org.hl7.fhir.dstu2.model.CodeableConcept t : src.getUseContext()) 089 if (VersionConvertor_10_30.isJurisdiction(t)) 090 tgt.addJurisdiction(CodeableConcept10_30.convertCodeableConcept(t)); 091 else 092 tgt.addUseContext(CodeableConcept10_30.convertCodeableConceptToUsageContext(t)); 093 if (src.hasRequirements()) 094 tgt.setPurpose(src.getRequirements()); 095 if (src.hasCopyright()) 096 tgt.setCopyright(src.getCopyright()); 097 if (src.hasSource()) 098 tgt.setSource(ConversionContext10_30.INSTANCE.getVersionConvertor_10_30().convertType(src.getSource())); 099 if (src.hasTarget()) 100 tgt.setTarget(ConversionContext10_30.INSTANCE.getVersionConvertor_10_30().convertType(src.getTarget())); 101 for (org.hl7.fhir.dstu2.model.ConceptMap.SourceElementComponent t : src.getElement()) { 102 List<SourceElementComponentWrapper<ConceptMap.SourceElementComponent>> ws = convertSourceElementComponent(t); 103 for (SourceElementComponentWrapper<ConceptMap.SourceElementComponent> w : ws) 104 getGroup(tgt, w.getSource(), w.getTarget()).addElement(w.getComp()); 105 } 106 return tgt; 107 } 108 109 public static org.hl7.fhir.dstu3.model.ContactDetail convertConceptMapContactComponent(org.hl7.fhir.dstu2.model.ConceptMap.ConceptMapContactComponent src) throws FHIRException { 110 if (src == null || src.isEmpty()) 111 return null; 112 org.hl7.fhir.dstu3.model.ContactDetail tgt = new org.hl7.fhir.dstu3.model.ContactDetail(); 113 ConversionContext10_30.INSTANCE.getVersionConvertor_10_30().copyElement(src, tgt); 114 if (src.hasNameElement()) 115 tgt.setNameElement(String10_30.convertString(src.getNameElement())); 116 for (org.hl7.fhir.dstu2.model.ContactPoint t : src.getTelecom()) 117 tgt.addTelecom(ContactPoint10_30.convertContactPoint(t)); 118 return tgt; 119 } 120 121 public static org.hl7.fhir.dstu2.model.ConceptMap.ConceptMapContactComponent convertConceptMapContactComponent(org.hl7.fhir.dstu3.model.ContactDetail src) throws FHIRException { 122 if (src == null || src.isEmpty()) 123 return null; 124 org.hl7.fhir.dstu2.model.ConceptMap.ConceptMapContactComponent tgt = new org.hl7.fhir.dstu2.model.ConceptMap.ConceptMapContactComponent(); 125 ConversionContext10_30.INSTANCE.getVersionConvertor_10_30().copyElement(src, tgt); 126 if (src.hasNameElement()) 127 tgt.setNameElement(String10_30.convertString(src.getNameElement())); 128 for (org.hl7.fhir.dstu3.model.ContactPoint t : src.getTelecom()) 129 tgt.addTelecom(ContactPoint10_30.convertContactPoint(t)); 130 return tgt; 131 } 132 133 static public org.hl7.fhir.dstu3.model.Enumeration<org.hl7.fhir.dstu3.model.Enumerations.ConceptMapEquivalence> convertConceptMapEquivalence(org.hl7.fhir.dstu2.model.Enumeration<org.hl7.fhir.dstu2.model.Enumerations.ConceptMapEquivalence> src) throws FHIRException { 134 if (src == null || src.isEmpty()) 135 return null; 136 org.hl7.fhir.dstu3.model.Enumeration<org.hl7.fhir.dstu3.model.Enumerations.ConceptMapEquivalence> tgt = new org.hl7.fhir.dstu3.model.Enumeration<>(new org.hl7.fhir.dstu3.model.Enumerations.ConceptMapEquivalenceEnumFactory()); 137 ConversionContext10_30.INSTANCE.getVersionConvertor_10_30().copyElement(src, tgt); 138 switch (src.getValue()) { 139 case EQUIVALENT: 140 tgt.setValue(org.hl7.fhir.dstu3.model.Enumerations.ConceptMapEquivalence.EQUIVALENT); 141 break; 142 case EQUAL: 143 tgt.setValue(org.hl7.fhir.dstu3.model.Enumerations.ConceptMapEquivalence.EQUAL); 144 break; 145 case WIDER: 146 tgt.setValue(org.hl7.fhir.dstu3.model.Enumerations.ConceptMapEquivalence.WIDER); 147 break; 148 case SUBSUMES: 149 tgt.setValue(org.hl7.fhir.dstu3.model.Enumerations.ConceptMapEquivalence.SUBSUMES); 150 break; 151 case NARROWER: 152 tgt.setValue(org.hl7.fhir.dstu3.model.Enumerations.ConceptMapEquivalence.NARROWER); 153 break; 154 case SPECIALIZES: 155 tgt.setValue(org.hl7.fhir.dstu3.model.Enumerations.ConceptMapEquivalence.SPECIALIZES); 156 break; 157 case INEXACT: 158 tgt.setValue(org.hl7.fhir.dstu3.model.Enumerations.ConceptMapEquivalence.INEXACT); 159 break; 160 case UNMATCHED: 161 tgt.setValue(org.hl7.fhir.dstu3.model.Enumerations.ConceptMapEquivalence.UNMATCHED); 162 break; 163 case DISJOINT: 164 tgt.setValue(org.hl7.fhir.dstu3.model.Enumerations.ConceptMapEquivalence.DISJOINT); 165 break; 166 default: 167 tgt.setValue(org.hl7.fhir.dstu3.model.Enumerations.ConceptMapEquivalence.NULL); 168 break; 169 } 170 return tgt; 171 } 172 173 static public org.hl7.fhir.dstu2.model.Enumeration<org.hl7.fhir.dstu2.model.Enumerations.ConceptMapEquivalence> convertConceptMapEquivalence(org.hl7.fhir.dstu3.model.Enumeration<org.hl7.fhir.dstu3.model.Enumerations.ConceptMapEquivalence> src) throws FHIRException { 174 if (src == null || src.isEmpty()) 175 return null; 176 org.hl7.fhir.dstu2.model.Enumeration<org.hl7.fhir.dstu2.model.Enumerations.ConceptMapEquivalence> tgt = new org.hl7.fhir.dstu2.model.Enumeration<>(new org.hl7.fhir.dstu2.model.Enumerations.ConceptMapEquivalenceEnumFactory()); 177 ConversionContext10_30.INSTANCE.getVersionConvertor_10_30().copyElement(src, tgt); 178 switch (src.getValue()) { 179 case EQUIVALENT: 180 tgt.setValue(org.hl7.fhir.dstu2.model.Enumerations.ConceptMapEquivalence.EQUIVALENT); 181 break; 182 case EQUAL: 183 tgt.setValue(org.hl7.fhir.dstu2.model.Enumerations.ConceptMapEquivalence.EQUAL); 184 break; 185 case WIDER: 186 tgt.setValue(org.hl7.fhir.dstu2.model.Enumerations.ConceptMapEquivalence.WIDER); 187 break; 188 case SUBSUMES: 189 tgt.setValue(org.hl7.fhir.dstu2.model.Enumerations.ConceptMapEquivalence.SUBSUMES); 190 break; 191 case NARROWER: 192 tgt.setValue(org.hl7.fhir.dstu2.model.Enumerations.ConceptMapEquivalence.NARROWER); 193 break; 194 case SPECIALIZES: 195 tgt.setValue(org.hl7.fhir.dstu2.model.Enumerations.ConceptMapEquivalence.SPECIALIZES); 196 break; 197 case INEXACT: 198 tgt.setValue(org.hl7.fhir.dstu2.model.Enumerations.ConceptMapEquivalence.INEXACT); 199 break; 200 case UNMATCHED: 201 tgt.setValue(org.hl7.fhir.dstu2.model.Enumerations.ConceptMapEquivalence.UNMATCHED); 202 break; 203 case DISJOINT: 204 tgt.setValue(org.hl7.fhir.dstu2.model.Enumerations.ConceptMapEquivalence.DISJOINT); 205 break; 206 default: 207 tgt.setValue(org.hl7.fhir.dstu2.model.Enumerations.ConceptMapEquivalence.NULL); 208 break; 209 } 210 return tgt; 211 } 212 213 public static org.hl7.fhir.dstu3.model.ConceptMap.OtherElementComponent convertOtherElementComponent(org.hl7.fhir.dstu2.model.ConceptMap.OtherElementComponent src) throws FHIRException { 214 if (src == null || src.isEmpty()) 215 return null; 216 org.hl7.fhir.dstu3.model.ConceptMap.OtherElementComponent tgt = new org.hl7.fhir.dstu3.model.ConceptMap.OtherElementComponent(); 217 ConversionContext10_30.INSTANCE.getVersionConvertor_10_30().copyElement(src, tgt); 218 if (src.hasElementElement()) 219 tgt.setPropertyElement(Uri10_30.convertUri(src.getElementElement())); 220 if (src.hasCodeSystemElement()) 221 tgt.setSystemElement(Uri10_30.convertUri(src.getCodeSystemElement())); 222 if (src.hasCodeElement()) 223 tgt.setCodeElement(String10_30.convertString(src.getCodeElement())); 224 return tgt; 225 } 226 227 public static org.hl7.fhir.dstu2.model.ConceptMap.OtherElementComponent convertOtherElementComponent(org.hl7.fhir.dstu3.model.ConceptMap.OtherElementComponent src) throws FHIRException { 228 if (src == null || src.isEmpty()) 229 return null; 230 org.hl7.fhir.dstu2.model.ConceptMap.OtherElementComponent tgt = new org.hl7.fhir.dstu2.model.ConceptMap.OtherElementComponent(); 231 ConversionContext10_30.INSTANCE.getVersionConvertor_10_30().copyElement(src, tgt); 232 if (src.hasPropertyElement()) 233 tgt.setElementElement(Uri10_30.convertUri(src.getPropertyElement())); 234 if (src.hasSystemElement()) 235 tgt.setCodeSystemElement(Uri10_30.convertUri(src.getSystemElement())); 236 if (src.hasCodeElement()) 237 tgt.setCodeElement(String10_30.convertString(src.getCodeElement())); 238 return tgt; 239 } 240 241 public static List<SourceElementComponentWrapper<ConceptMap.SourceElementComponent>> convertSourceElementComponent(org.hl7.fhir.dstu2.model.ConceptMap.SourceElementComponent src) throws FHIRException { 242 List<SourceElementComponentWrapper<ConceptMap.SourceElementComponent>> res = new ArrayList<>(); 243 if (src == null || src.isEmpty()) 244 return res; 245 for (org.hl7.fhir.dstu2.model.ConceptMap.TargetElementComponent t : src.getTarget()) { 246 org.hl7.fhir.dstu3.model.ConceptMap.SourceElementComponent tgt = new org.hl7.fhir.dstu3.model.ConceptMap.SourceElementComponent(); 247 ConversionContext10_30.INSTANCE.getVersionConvertor_10_30().copyElement(src, tgt); 248 tgt.setCode(src.getCode()); 249 tgt.addTarget(convertTargetElementComponent(t)); 250 res.add(new SourceElementComponentWrapper<>(tgt, src.getCodeSystem(), t.getCodeSystem())); 251 } 252 return res; 253 } 254 255 public static org.hl7.fhir.dstu2.model.ConceptMap.SourceElementComponent convertSourceElementComponent(org.hl7.fhir.dstu3.model.ConceptMap.SourceElementComponent src, org.hl7.fhir.dstu3.model.ConceptMap.ConceptMapGroupComponent g) throws FHIRException { 256 if (src == null || src.isEmpty()) 257 return null; 258 org.hl7.fhir.dstu2.model.ConceptMap.SourceElementComponent tgt = new org.hl7.fhir.dstu2.model.ConceptMap.SourceElementComponent(); 259 ConversionContext10_30.INSTANCE.getVersionConvertor_10_30().copyElement(src, tgt); 260 tgt.setCodeSystem(g.getSource()); 261 if (src.hasCodeElement()) 262 tgt.setCodeElement(Code10_30.convertCode(src.getCodeElement())); 263 for (org.hl7.fhir.dstu3.model.ConceptMap.TargetElementComponent t : src.getTarget()) 264 tgt.addTarget(convertTargetElementComponent(t, g)); 265 return tgt; 266 } 267 268 public static org.hl7.fhir.dstu2.model.ConceptMap.TargetElementComponent convertTargetElementComponent(org.hl7.fhir.dstu3.model.ConceptMap.TargetElementComponent src, org.hl7.fhir.dstu3.model.ConceptMap.ConceptMapGroupComponent g) throws FHIRException { 269 if (src == null || src.isEmpty()) 270 return null; 271 org.hl7.fhir.dstu2.model.ConceptMap.TargetElementComponent tgt = new org.hl7.fhir.dstu2.model.ConceptMap.TargetElementComponent(); 272 ConversionContext10_30.INSTANCE.getVersionConvertor_10_30().copyElement(src, tgt); 273 tgt.setCodeSystem(g.getTarget()); 274 if (src.hasCodeElement()) 275 tgt.setCodeElement(Code10_30.convertCode(src.getCodeElement())); 276 if (src.hasEquivalence()) 277 tgt.setEquivalenceElement(convertConceptMapEquivalence(src.getEquivalenceElement())); 278 if (src.hasCommentElement()) 279 tgt.setCommentsElement(String10_30.convertString(src.getCommentElement())); 280 for (org.hl7.fhir.dstu3.model.ConceptMap.OtherElementComponent t : src.getDependsOn()) 281 tgt.addDependsOn(convertOtherElementComponent(t)); 282 for (org.hl7.fhir.dstu3.model.ConceptMap.OtherElementComponent t : src.getProduct()) 283 tgt.addProduct(convertOtherElementComponent(t)); 284 return tgt; 285 } 286 287 public static org.hl7.fhir.dstu3.model.ConceptMap.TargetElementComponent convertTargetElementComponent(org.hl7.fhir.dstu2.model.ConceptMap.TargetElementComponent src) throws FHIRException { 288 if (src == null || src.isEmpty()) 289 return null; 290 org.hl7.fhir.dstu3.model.ConceptMap.TargetElementComponent tgt = new org.hl7.fhir.dstu3.model.ConceptMap.TargetElementComponent(); 291 ConversionContext10_30.INSTANCE.getVersionConvertor_10_30().copyElement(src, tgt); 292 if (src.hasCodeElement()) 293 tgt.setCodeElement(Code10_30.convertCode(src.getCodeElement())); 294 if (src.hasEquivalence()) 295 tgt.setEquivalenceElement(convertConceptMapEquivalence(src.getEquivalenceElement())); 296 if (src.hasCommentsElement()) 297 tgt.setCommentElement(String10_30.convertString(src.getCommentsElement())); 298 for (org.hl7.fhir.dstu2.model.ConceptMap.OtherElementComponent t : src.getDependsOn()) 299 tgt.addDependsOn(convertOtherElementComponent(t)); 300 for (org.hl7.fhir.dstu2.model.ConceptMap.OtherElementComponent t : src.getProduct()) 301 tgt.addProduct(convertOtherElementComponent(t)); 302 return tgt; 303 } 304 305 static public ConceptMapGroupComponent getGroup(ConceptMap map, String srcs, String tgts) { 306 for (ConceptMapGroupComponent grp : map.getGroup()) { 307 if (grp.getSource().equals(srcs) && grp.getTarget().equals(tgts)) 308 return grp; 309 } 310 ConceptMapGroupComponent grp = map.addGroup(); 311 grp.setSource(srcs); 312 grp.setTarget(tgts); 313 return grp; 314 } 315}