001package org.hl7.fhir.convertors.conv10_50.resources10_50;
002
003import java.util.ArrayList;
004import java.util.List;
005
006import org.hl7.fhir.convertors.context.ConversionContext10_50;
007import org.hl7.fhir.convertors.conv10_50.VersionConvertor_10_50;
008import org.hl7.fhir.convertors.conv10_50.datatypes10_50.ElementDefinition10_50;
009import org.hl7.fhir.convertors.conv10_50.datatypes10_50.complextypes10_50.CodeableConcept10_50;
010import org.hl7.fhir.convertors.conv10_50.datatypes10_50.complextypes10_50.ContactPoint10_50;
011import org.hl7.fhir.convertors.conv10_50.datatypes10_50.complextypes10_50.Identifier10_50;
012import org.hl7.fhir.convertors.conv10_50.datatypes10_50.primitivetypes10_50.Boolean10_50;
013import org.hl7.fhir.convertors.conv10_50.datatypes10_50.primitivetypes10_50.DateTime10_50;
014import org.hl7.fhir.convertors.conv10_50.datatypes10_50.primitivetypes10_50.Id10_50;
015import org.hl7.fhir.convertors.conv10_50.datatypes10_50.primitivetypes10_50.String10_50;
016import org.hl7.fhir.convertors.conv10_50.datatypes10_50.primitivetypes10_50.Uri10_50;
017import org.hl7.fhir.exceptions.FHIRException;
018import org.hl7.fhir.r5.model.StructureDefinition.StructureDefinitionKind;
019import org.hl7.fhir.r5.model.StructureDefinition.TypeDerivationRule;
020
021public class DataElement10_50 {
022
023  public static org.hl7.fhir.r5.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.r5.model.StructureDefinition tgt = new org.hl7.fhir.r5.model.StructureDefinition();
027    ConversionContext10_50.INSTANCE.getVersionConvertor_10_50().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_50.convertIdentifier(t));
032    if (src.hasVersionElement())
033      tgt.setVersionElement(String10_50.convertString(src.getVersionElement()));
034    if (src.hasStatus())
035      tgt.setStatusElement(Enumerations10_50.convertConformanceResourceStatus(src.getStatusElement()));
036    if (src.hasExperimental())
037      tgt.setExperimentalElement(Boolean10_50.convertBoolean(src.getExperimentalElement()));
038    if (src.hasPublisherElement())
039      tgt.setPublisherElement(String10_50.convertString(src.getPublisherElement()));
040    if (src.hasDate())
041      tgt.setDateElement(DateTime10_50.convertDateTime(src.getDateElement()));
042    if (src.hasNameElement())
043      tgt.setNameElement(String10_50.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_50.isJurisdiction(t))
048        tgt.addJurisdiction(CodeableConcept10_50.convertCodeableConcept(t));
049      else
050        tgt.addUseContext(CodeableConcept10_50.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_50.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.r5.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_50.INSTANCE.getVersionConvertor_10_50().copyElement(src, tgt);
074    if (src.hasNameElement())
075      tgt.setNameElement(String10_50.convertString(src.getNameElement()));
076    for (org.hl7.fhir.r5.model.ContactPoint t : src.getTelecom())
077      tgt.addTelecom(ContactPoint10_50.convertContactPoint(t));
078    return tgt;
079  }
080
081  public static org.hl7.fhir.r5.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.r5.model.ContactDetail tgt = new org.hl7.fhir.r5.model.ContactDetail();
085    ConversionContext10_50.INSTANCE.getVersionConvertor_10_50().copyElement(src, tgt);
086    if (src.hasNameElement())
087      tgt.setNameElement(String10_50.convertString(src.getNameElement()));
088    for (org.hl7.fhir.dstu2.model.ContactPoint t : src.getTelecom())
089      tgt.addTelecom(ContactPoint10_50.convertContactPoint(t));
090    return tgt;
091  }
092
093  public static org.hl7.fhir.r5.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.r5.model.StructureDefinition.StructureDefinitionMappingComponent tgt = new org.hl7.fhir.r5.model.StructureDefinition.StructureDefinitionMappingComponent();
097    ConversionContext10_50.INSTANCE.getVersionConvertor_10_50().copyBackboneElement(src,tgt);
098    if (src.hasIdentityElement())
099      tgt.setIdentityElement(Id10_50.convertId(src.getIdentityElement()));
100    if (src.hasUriElement())
101      tgt.setUriElement(Uri10_50.convertUri(src.getUriElement()));
102    if (src.hasNameElement())
103      tgt.setNameElement(String10_50.convertString(src.getNameElement()));
104    if (src.hasCommentsElement())
105      tgt.setCommentElement(String10_50.convertString(src.getCommentsElement()));
106    return tgt;
107  }
108}