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