001package org.hl7.fhir.convertors.conv10_40.resources10_40; 002 003import java.util.ArrayList; 004import java.util.List; 005 006import org.hl7.fhir.convertors.context.ConversionContext10_40; 007import org.hl7.fhir.convertors.conv10_40.VersionConvertor_10_40; 008import org.hl7.fhir.convertors.conv10_40.datatypes10_40.ElementDefinition10_40; 009import org.hl7.fhir.convertors.conv10_40.datatypes10_40.complextypes10_40.CodeableConcept10_40; 010import org.hl7.fhir.convertors.conv10_40.datatypes10_40.complextypes10_40.ContactPoint10_40; 011import org.hl7.fhir.convertors.conv10_40.datatypes10_40.complextypes10_40.Identifier10_40; 012import org.hl7.fhir.convertors.conv10_40.datatypes10_40.primitivetypes10_40.Boolean10_40; 013import org.hl7.fhir.convertors.conv10_40.datatypes10_40.primitivetypes10_40.DateTime10_40; 014import org.hl7.fhir.convertors.conv10_40.datatypes10_40.primitivetypes10_40.Id10_40; 015import org.hl7.fhir.convertors.conv10_40.datatypes10_40.primitivetypes10_40.String10_40; 016import org.hl7.fhir.convertors.conv10_40.datatypes10_40.primitivetypes10_40.Uri10_40; 017import org.hl7.fhir.exceptions.FHIRException; 018import org.hl7.fhir.r4.model.StructureDefinition.StructureDefinitionKind; 019import org.hl7.fhir.r4.model.StructureDefinition.TypeDerivationRule; 020 021public class DataElement10_40 { 022 023 public static org.hl7.fhir.r4.model.StructureDefinition convertDataElement(org.hl7.fhir.dstu2.model.DataElement src) throws FHIRException { 024 if (src == null || src.isEmpty()) 025 return null; 026 org.hl7.fhir.r4.model.StructureDefinition tgt = new org.hl7.fhir.r4.model.StructureDefinition(); 027 ConversionContext10_40.INSTANCE.getVersionConvertor_10_40().copyDomainResource(src, tgt); 028 if (src.hasUrl()) 029 tgt.setUrl(src.getUrl().replace("/DataElement/", "/StructureDefinition/de-")); 030 for (org.hl7.fhir.dstu2.model.Identifier t : src.getIdentifier()) 031 tgt.addIdentifier(Identifier10_40.convertIdentifier(t)); 032 if (src.hasVersionElement()) 033 tgt.setVersionElement(String10_40.convertString(src.getVersionElement())); 034 if (src.hasStatus()) 035 tgt.setStatusElement(Enumerations10_40.convertConformanceResourceStatus(src.getStatusElement())); 036 if (src.hasExperimental()) 037 tgt.setExperimentalElement(Boolean10_40.convertBoolean(src.getExperimentalElement())); 038 if (src.hasPublisherElement()) 039 tgt.setPublisherElement(String10_40.convertString(src.getPublisherElement())); 040 if (src.hasDate()) 041 tgt.setDateElement(DateTime10_40.convertDateTime(src.getDateElement())); 042 if (src.hasNameElement()) 043 tgt.setNameElement(String10_40.convertString(src.getNameElement())); 044 for (org.hl7.fhir.dstu2.model.DataElement.DataElementContactComponent t : src.getContact()) 045 tgt.addContact(convertDataElementContactComponent(t)); 046 for (org.hl7.fhir.dstu2.model.CodeableConcept t : src.getUseContext()) 047 if (VersionConvertor_10_40.isJurisdiction(t)) 048 tgt.addJurisdiction(CodeableConcept10_40.convertCodeableConcept(t)); 049 else 050 tgt.addUseContext(CodeableConcept10_40.convertCodeableConceptToUsageContext(t)); 051 if (src.hasCopyright()) 052 tgt.setCopyright(src.getCopyright()); 053 for (org.hl7.fhir.dstu2.model.DataElement.DataElementMappingComponent t : src.getMapping()) 054 tgt.addMapping(convertDataElementMappingComponent(t)); 055 List<String> slicePaths = new ArrayList<String>(); 056 for (org.hl7.fhir.dstu2.model.ElementDefinition t : src.getElement()) { 057 if (t.hasSlicing()) 058 slicePaths.add(t.getPath()); 059 tgt.getSnapshot().addElement(ElementDefinition10_40.convertElementDefinition(t, slicePaths, src.getElement(), src.getElement().indexOf(t))); 060 } 061 tgt.setKind(StructureDefinitionKind.COMPLEXTYPE); 062 tgt.setAbstract(false); 063 tgt.setType(tgt.getName()); 064 tgt.setBaseDefinition("http://hl7.org/fhir/StructureDefinition/Element"); 065 tgt.setDerivation(TypeDerivationRule.SPECIALIZATION); 066 return tgt; 067 } 068 069 public static org.hl7.fhir.dstu2.model.DataElement.DataElementContactComponent convertDataElementContactComponent(org.hl7.fhir.r4.model.ContactDetail src) throws FHIRException { 070 if (src == null || src.isEmpty()) 071 return null; 072 org.hl7.fhir.dstu2.model.DataElement.DataElementContactComponent tgt = new org.hl7.fhir.dstu2.model.DataElement.DataElementContactComponent(); 073 ConversionContext10_40.INSTANCE.getVersionConvertor_10_40().copyElement(src, tgt); 074 if (src.hasNameElement()) 075 tgt.setNameElement(String10_40.convertString(src.getNameElement())); 076 for (org.hl7.fhir.r4.model.ContactPoint t : src.getTelecom()) 077 tgt.addTelecom(ContactPoint10_40.convertContactPoint(t)); 078 return tgt; 079 } 080 081 public static org.hl7.fhir.r4.model.ContactDetail convertDataElementContactComponent(org.hl7.fhir.dstu2.model.DataElement.DataElementContactComponent src) throws FHIRException { 082 if (src == null || src.isEmpty()) 083 return null; 084 org.hl7.fhir.r4.model.ContactDetail tgt = new org.hl7.fhir.r4.model.ContactDetail(); 085 ConversionContext10_40.INSTANCE.getVersionConvertor_10_40().copyElement(src, tgt); 086 if (src.hasNameElement()) 087 tgt.setNameElement(String10_40.convertString(src.getNameElement())); 088 for (org.hl7.fhir.dstu2.model.ContactPoint t : src.getTelecom()) 089 tgt.addTelecom(ContactPoint10_40.convertContactPoint(t)); 090 return tgt; 091 } 092 093 public static org.hl7.fhir.r4.model.StructureDefinition.StructureDefinitionMappingComponent convertDataElementMappingComponent(org.hl7.fhir.dstu2.model.DataElement.DataElementMappingComponent src) throws FHIRException { 094 if (src == null || src.isEmpty()) 095 return null; 096 org.hl7.fhir.r4.model.StructureDefinition.StructureDefinitionMappingComponent tgt = new org.hl7.fhir.r4.model.StructureDefinition.StructureDefinitionMappingComponent(); 097 ConversionContext10_40.INSTANCE.getVersionConvertor_10_40().copyBackboneElement(src,tgt); 098 if (src.hasIdentityElement()) 099 tgt.setIdentityElement(Id10_40.convertId(src.getIdentityElement())); 100 if (src.hasUriElement()) 101 tgt.setUriElement(Uri10_40.convertUri(src.getUriElement())); 102 if (src.hasNameElement()) 103 tgt.setNameElement(String10_40.convertString(src.getNameElement())); 104 if (src.hasCommentsElement()) 105 tgt.setCommentElement(String10_40.convertString(src.getCommentsElement())); 106 return tgt; 107 } 108}