001package org.hl7.fhir.convertors.conv10_40.resources10_40;
002
003import org.hl7.fhir.convertors.context.ConversionContext10_40;
004import org.hl7.fhir.convertors.conv10_40.datatypes10_40.Reference10_40;
005import org.hl7.fhir.convertors.conv10_40.datatypes10_40.complextypes10_40.CodeableConcept10_40;
006import org.hl7.fhir.convertors.conv10_40.datatypes10_40.complextypes10_40.Identifier10_40;
007import org.hl7.fhir.convertors.conv10_40.datatypes10_40.complextypes10_40.Period10_40;
008import org.hl7.fhir.convertors.conv10_40.datatypes10_40.primitivetypes10_40.Boolean10_40;
009import org.hl7.fhir.convertors.conv10_40.datatypes10_40.primitivetypes10_40.String10_40;
010import org.hl7.fhir.convertors.conv10_40.datatypes10_40.primitivetypes10_40.UnsignedInt10_40;
011import org.hl7.fhir.dstu2.model.Enumeration;
012import org.hl7.fhir.dstu2.model.Group;
013import org.hl7.fhir.exceptions.FHIRException;
014
015public class Group10_40 {
016
017  public static org.hl7.fhir.r4.model.Group convertGroup(org.hl7.fhir.dstu2.model.Group src) throws FHIRException {
018    if (src == null || src.isEmpty())
019      return null;
020    org.hl7.fhir.r4.model.Group tgt = new org.hl7.fhir.r4.model.Group();
021    ConversionContext10_40.INSTANCE.getVersionConvertor_10_40().copyDomainResource(src, tgt);
022    for (org.hl7.fhir.dstu2.model.Identifier t : src.getIdentifier())
023      tgt.addIdentifier(Identifier10_40.convertIdentifier(t));
024    if (src.hasType())
025      tgt.setTypeElement(convertGroupType(src.getTypeElement()));
026    if (src.hasActualElement())
027      tgt.setActualElement(Boolean10_40.convertBoolean(src.getActualElement()));
028    if (src.hasCode())
029      tgt.setCode(CodeableConcept10_40.convertCodeableConcept(src.getCode()));
030    if (src.hasNameElement())
031      tgt.setNameElement(String10_40.convertString(src.getNameElement()));
032    if (src.hasQuantityElement())
033      tgt.setQuantityElement(UnsignedInt10_40.convertUnsignedInt(src.getQuantityElement()));
034    for (org.hl7.fhir.dstu2.model.Group.GroupCharacteristicComponent t : src.getCharacteristic())
035      tgt.addCharacteristic(convertGroupCharacteristicComponent(t));
036    for (org.hl7.fhir.dstu2.model.Group.GroupMemberComponent t : src.getMember())
037      tgt.addMember(convertGroupMemberComponent(t));
038    return tgt;
039  }
040
041  public static org.hl7.fhir.dstu2.model.Group convertGroup(org.hl7.fhir.r4.model.Group src) throws FHIRException {
042    if (src == null || src.isEmpty())
043      return null;
044    org.hl7.fhir.dstu2.model.Group tgt = new org.hl7.fhir.dstu2.model.Group();
045    ConversionContext10_40.INSTANCE.getVersionConvertor_10_40().copyDomainResource(src, tgt);
046    for (org.hl7.fhir.r4.model.Identifier t : src.getIdentifier())
047      tgt.addIdentifier(Identifier10_40.convertIdentifier(t));
048    if (src.hasType())
049      tgt.setTypeElement(convertGroupType(src.getTypeElement()));
050    if (src.hasActualElement())
051      tgt.setActualElement(Boolean10_40.convertBoolean(src.getActualElement()));
052    if (src.hasCode())
053      tgt.setCode(CodeableConcept10_40.convertCodeableConcept(src.getCode()));
054    if (src.hasNameElement())
055      tgt.setNameElement(String10_40.convertString(src.getNameElement()));
056    if (src.hasQuantityElement())
057      tgt.setQuantityElement(UnsignedInt10_40.convertUnsignedInt(src.getQuantityElement()));
058    for (org.hl7.fhir.r4.model.Group.GroupCharacteristicComponent t : src.getCharacteristic())
059      tgt.addCharacteristic(convertGroupCharacteristicComponent(t));
060    for (org.hl7.fhir.r4.model.Group.GroupMemberComponent t : src.getMember())
061      tgt.addMember(convertGroupMemberComponent(t));
062    return tgt;
063  }
064
065  public static org.hl7.fhir.r4.model.Group.GroupCharacteristicComponent convertGroupCharacteristicComponent(org.hl7.fhir.dstu2.model.Group.GroupCharacteristicComponent src) throws FHIRException {
066    if (src == null || src.isEmpty())
067      return null;
068    org.hl7.fhir.r4.model.Group.GroupCharacteristicComponent tgt = new org.hl7.fhir.r4.model.Group.GroupCharacteristicComponent();
069    ConversionContext10_40.INSTANCE.getVersionConvertor_10_40().copyBackboneElement(src,tgt);
070    if (src.hasCode())
071      tgt.setCode(CodeableConcept10_40.convertCodeableConcept(src.getCode()));
072    if (src.hasValue())
073      tgt.setValue(ConversionContext10_40.INSTANCE.getVersionConvertor_10_40().convertType(src.getValue()));
074    if (src.hasExcludeElement())
075      tgt.setExcludeElement(Boolean10_40.convertBoolean(src.getExcludeElement()));
076    if (src.hasPeriod())
077      tgt.setPeriod(Period10_40.convertPeriod(src.getPeriod()));
078    return tgt;
079  }
080
081  public static org.hl7.fhir.dstu2.model.Group.GroupCharacteristicComponent convertGroupCharacteristicComponent(org.hl7.fhir.r4.model.Group.GroupCharacteristicComponent src) throws FHIRException {
082    if (src == null || src.isEmpty())
083      return null;
084    org.hl7.fhir.dstu2.model.Group.GroupCharacteristicComponent tgt = new org.hl7.fhir.dstu2.model.Group.GroupCharacteristicComponent();
085    ConversionContext10_40.INSTANCE.getVersionConvertor_10_40().copyBackboneElement(src,tgt);
086    if (src.hasCode())
087      tgt.setCode(CodeableConcept10_40.convertCodeableConcept(src.getCode()));
088    if (src.hasValue())
089      tgt.setValue(ConversionContext10_40.INSTANCE.getVersionConvertor_10_40().convertType(src.getValue()));
090    if (src.hasExcludeElement())
091      tgt.setExcludeElement(Boolean10_40.convertBoolean(src.getExcludeElement()));
092    if (src.hasPeriod())
093      tgt.setPeriod(Period10_40.convertPeriod(src.getPeriod()));
094    return tgt;
095  }
096
097  public static org.hl7.fhir.r4.model.Group.GroupMemberComponent convertGroupMemberComponent(org.hl7.fhir.dstu2.model.Group.GroupMemberComponent src) throws FHIRException {
098    if (src == null || src.isEmpty())
099      return null;
100    org.hl7.fhir.r4.model.Group.GroupMemberComponent tgt = new org.hl7.fhir.r4.model.Group.GroupMemberComponent();
101    ConversionContext10_40.INSTANCE.getVersionConvertor_10_40().copyBackboneElement(src,tgt);
102    if (src.hasEntity())
103      tgt.setEntity(Reference10_40.convertReference(src.getEntity()));
104    if (src.hasPeriod())
105      tgt.setPeriod(Period10_40.convertPeriod(src.getPeriod()));
106    if (src.hasInactiveElement())
107      tgt.setInactiveElement(Boolean10_40.convertBoolean(src.getInactiveElement()));
108    return tgt;
109  }
110
111  public static org.hl7.fhir.dstu2.model.Group.GroupMemberComponent convertGroupMemberComponent(org.hl7.fhir.r4.model.Group.GroupMemberComponent src) throws FHIRException {
112    if (src == null || src.isEmpty())
113      return null;
114    org.hl7.fhir.dstu2.model.Group.GroupMemberComponent tgt = new org.hl7.fhir.dstu2.model.Group.GroupMemberComponent();
115    ConversionContext10_40.INSTANCE.getVersionConvertor_10_40().copyBackboneElement(src,tgt);
116    if (src.hasEntity())
117      tgt.setEntity(Reference10_40.convertReference(src.getEntity()));
118    if (src.hasPeriod())
119      tgt.setPeriod(Period10_40.convertPeriod(src.getPeriod()));
120    if (src.hasInactiveElement())
121      tgt.setInactiveElement(Boolean10_40.convertBoolean(src.getInactiveElement()));
122    return tgt;
123  }
124
125  static public org.hl7.fhir.dstu2.model.Enumeration<org.hl7.fhir.dstu2.model.Group.GroupType> convertGroupType(org.hl7.fhir.r4.model.Enumeration<org.hl7.fhir.r4.model.Group.GroupType> src) throws FHIRException {
126      if (src == null || src.isEmpty())
127          return null;
128      Enumeration<Group.GroupType> tgt = new Enumeration<>(new Group.GroupTypeEnumFactory());
129      ConversionContext10_40.INSTANCE.getVersionConvertor_10_40().copyElement(src, tgt);
130      if (src.getValue() == null) {
131          tgt.setValue(null);
132      } else {
133          switch (src.getValue()) {
134              case PERSON:
135                  tgt.setValue(Group.GroupType.PERSON);
136                  break;
137              case ANIMAL:
138                  tgt.setValue(Group.GroupType.ANIMAL);
139                  break;
140              case PRACTITIONER:
141                  tgt.setValue(Group.GroupType.PRACTITIONER);
142                  break;
143              case DEVICE:
144                  tgt.setValue(Group.GroupType.DEVICE);
145                  break;
146              case MEDICATION:
147                  tgt.setValue(Group.GroupType.MEDICATION);
148                  break;
149              case SUBSTANCE:
150                  tgt.setValue(Group.GroupType.SUBSTANCE);
151                  break;
152              default:
153                  tgt.setValue(Group.GroupType.NULL);
154                  break;
155          }
156      }
157      return tgt;
158  }
159
160  static public org.hl7.fhir.r4.model.Enumeration<org.hl7.fhir.r4.model.Group.GroupType> convertGroupType(org.hl7.fhir.dstu2.model.Enumeration<org.hl7.fhir.dstu2.model.Group.GroupType> src) throws FHIRException {
161      if (src == null || src.isEmpty())
162          return null;
163      org.hl7.fhir.r4.model.Enumeration<org.hl7.fhir.r4.model.Group.GroupType> tgt = new org.hl7.fhir.r4.model.Enumeration<>(new org.hl7.fhir.r4.model.Group.GroupTypeEnumFactory());
164      ConversionContext10_40.INSTANCE.getVersionConvertor_10_40().copyElement(src, tgt);
165      if (src.getValue() == null) {
166          tgt.setValue(null);
167      } else {
168          switch (src.getValue()) {
169              case PERSON:
170                  tgt.setValue(org.hl7.fhir.r4.model.Group.GroupType.PERSON);
171                  break;
172              case ANIMAL:
173                  tgt.setValue(org.hl7.fhir.r4.model.Group.GroupType.ANIMAL);
174                  break;
175              case PRACTITIONER:
176                  tgt.setValue(org.hl7.fhir.r4.model.Group.GroupType.PRACTITIONER);
177                  break;
178              case DEVICE:
179                  tgt.setValue(org.hl7.fhir.r4.model.Group.GroupType.DEVICE);
180                  break;
181              case MEDICATION:
182                  tgt.setValue(org.hl7.fhir.r4.model.Group.GroupType.MEDICATION);
183                  break;
184              case SUBSTANCE:
185                  tgt.setValue(org.hl7.fhir.r4.model.Group.GroupType.SUBSTANCE);
186                  break;
187              default:
188                  tgt.setValue(org.hl7.fhir.r4.model.Group.GroupType.NULL);
189                  break;
190          }
191      }
192      return tgt;
193  }
194}