001package org.hl7.fhir.convertors.conv10_50.resources10_50;
002
003import org.hl7.fhir.convertors.context.ConversionContext10_50;
004import org.hl7.fhir.convertors.conv10_50.datatypes10_50.Reference10_50;
005import org.hl7.fhir.convertors.conv10_50.datatypes10_50.complextypes10_50.Address10_50;
006import org.hl7.fhir.convertors.conv10_50.datatypes10_50.complextypes10_50.CodeableConcept10_50;
007import org.hl7.fhir.convertors.conv10_50.datatypes10_50.complextypes10_50.ContactPoint10_50;
008import org.hl7.fhir.convertors.conv10_50.datatypes10_50.complextypes10_50.Identifier10_50;
009import org.hl7.fhir.convertors.conv10_50.datatypes10_50.primitivetypes10_50.Decimal10_50;
010import org.hl7.fhir.convertors.conv10_50.datatypes10_50.primitivetypes10_50.String10_50;
011import org.hl7.fhir.exceptions.FHIRException;
012import org.hl7.fhir.r5.model.ContactPoint;
013import org.hl7.fhir.r5.model.ExtendedContactDetail;
014
015public class Location10_50 {
016
017  public static org.hl7.fhir.dstu2.model.Location convertLocation(org.hl7.fhir.r5.model.Location src) throws FHIRException {
018    if (src == null || src.isEmpty())
019      return null;
020    org.hl7.fhir.dstu2.model.Location tgt = new org.hl7.fhir.dstu2.model.Location();
021    ConversionContext10_50.INSTANCE.getVersionConvertor_10_50().copyDomainResource(src, tgt);
022    for (org.hl7.fhir.r5.model.Identifier t : src.getIdentifier())
023      tgt.addIdentifier(Identifier10_50.convertIdentifier(t));
024    if (src.hasStatus())
025      tgt.setStatusElement(convertLocationStatus(src.getStatusElement()));
026    if (src.hasNameElement())
027      tgt.setNameElement(String10_50.convertString(src.getNameElement()));
028    if (src.hasDescriptionElement())
029      tgt.setDescriptionElement(String10_50.convertString(src.getDescriptionElement()));
030    if (src.hasMode())
031      tgt.setModeElement(convertLocationMode(src.getModeElement()));
032    if (src.hasType())
033      tgt.setType(CodeableConcept10_50.convertCodeableConcept(src.getTypeFirstRep()));
034    for (ExtendedContactDetail t1 : src.getContact())
035      for (ContactPoint t : t1.getTelecom())
036        tgt.addTelecom(ContactPoint10_50.convertContactPoint(t));
037    if (src.hasAddress())
038      tgt.setAddress(Address10_50.convertAddress(src.getAddress()));
039    if (src.hasForm())
040      tgt.setPhysicalType(CodeableConcept10_50.convertCodeableConcept(src.getForm()));
041    if (src.hasPosition())
042      tgt.setPosition(convertLocationPositionComponent(src.getPosition()));
043    if (src.hasManagingOrganization())
044      tgt.setManagingOrganization(Reference10_50.convertReference(src.getManagingOrganization()));
045    if (src.hasPartOf())
046      tgt.setPartOf(Reference10_50.convertReference(src.getPartOf()));
047    return tgt;
048  }
049
050  public static org.hl7.fhir.r5.model.Location convertLocation(org.hl7.fhir.dstu2.model.Location src) throws FHIRException {
051    if (src == null || src.isEmpty())
052      return null;
053    org.hl7.fhir.r5.model.Location tgt = new org.hl7.fhir.r5.model.Location();
054    ConversionContext10_50.INSTANCE.getVersionConvertor_10_50().copyDomainResource(src, tgt);
055    for (org.hl7.fhir.dstu2.model.Identifier t : src.getIdentifier())
056      tgt.addIdentifier(Identifier10_50.convertIdentifier(t));
057    if (src.hasStatus())
058      tgt.setStatusElement(convertLocationStatus(src.getStatusElement()));
059    if (src.hasNameElement())
060      tgt.setNameElement(String10_50.convertString(src.getNameElement()));
061    if (src.hasDescriptionElement())
062      tgt.setDescriptionElement(String10_50.convertStringToMarkdown(src.getDescriptionElement()));
063    if (src.hasMode())
064      tgt.setModeElement(convertLocationMode(src.getModeElement()));
065    if (src.hasType())
066      tgt.addType(CodeableConcept10_50.convertCodeableConcept(src.getType()));
067    for (org.hl7.fhir.dstu2.model.ContactPoint t : src.getTelecom())
068      tgt.getContactFirstRep().addTelecom(ContactPoint10_50.convertContactPoint(t));
069    if (src.hasAddress())
070      tgt.setAddress(Address10_50.convertAddress(src.getAddress()));
071    if (src.hasPhysicalType())
072      tgt.setForm(CodeableConcept10_50.convertCodeableConcept(src.getPhysicalType()));
073    if (src.hasPosition())
074      tgt.setPosition(convertLocationPositionComponent(src.getPosition()));
075    if (src.hasManagingOrganization())
076      tgt.setManagingOrganization(Reference10_50.convertReference(src.getManagingOrganization()));
077    if (src.hasPartOf())
078      tgt.setPartOf(Reference10_50.convertReference(src.getPartOf()));
079    return tgt;
080  }
081
082  static public org.hl7.fhir.r5.model.Enumeration<org.hl7.fhir.r5.model.Location.LocationMode> convertLocationMode(org.hl7.fhir.dstu2.model.Enumeration<org.hl7.fhir.dstu2.model.Location.LocationMode> src) throws FHIRException {
083    if (src == null || src.isEmpty())
084      return null;
085    org.hl7.fhir.r5.model.Enumeration<org.hl7.fhir.r5.model.Location.LocationMode> tgt = new org.hl7.fhir.r5.model.Enumeration<>(new org.hl7.fhir.r5.model.Location.LocationModeEnumFactory());
086    ConversionContext10_50.INSTANCE.getVersionConvertor_10_50().copyElement(src, tgt);
087    switch (src.getValue()) {
088      case INSTANCE:
089        tgt.setValue(org.hl7.fhir.r5.model.Location.LocationMode.INSTANCE);
090        break;
091      case KIND:
092        tgt.setValue(org.hl7.fhir.r5.model.Location.LocationMode.KIND);
093        break;
094      default:
095        tgt.setValue(org.hl7.fhir.r5.model.Location.LocationMode.NULL);
096        break;
097    }
098    return tgt;
099  }
100
101  static public org.hl7.fhir.dstu2.model.Enumeration<org.hl7.fhir.dstu2.model.Location.LocationMode> convertLocationMode(org.hl7.fhir.r5.model.Enumeration<org.hl7.fhir.r5.model.Location.LocationMode> src) throws FHIRException {
102    if (src == null || src.isEmpty())
103      return null;
104    org.hl7.fhir.dstu2.model.Enumeration<org.hl7.fhir.dstu2.model.Location.LocationMode> tgt = new org.hl7.fhir.dstu2.model.Enumeration<>(new org.hl7.fhir.dstu2.model.Location.LocationModeEnumFactory());
105    ConversionContext10_50.INSTANCE.getVersionConvertor_10_50().copyElement(src, tgt);
106    switch (src.getValue()) {
107      case INSTANCE:
108        tgt.setValue(org.hl7.fhir.dstu2.model.Location.LocationMode.INSTANCE);
109        break;
110      case KIND:
111        tgt.setValue(org.hl7.fhir.dstu2.model.Location.LocationMode.KIND);
112        break;
113      default:
114        tgt.setValue(org.hl7.fhir.dstu2.model.Location.LocationMode.NULL);
115        break;
116    }
117    return tgt;
118  }
119
120  public static org.hl7.fhir.r5.model.Location.LocationPositionComponent convertLocationPositionComponent(org.hl7.fhir.dstu2.model.Location.LocationPositionComponent src) throws FHIRException {
121    if (src == null || src.isEmpty())
122      return null;
123    org.hl7.fhir.r5.model.Location.LocationPositionComponent tgt = new org.hl7.fhir.r5.model.Location.LocationPositionComponent();
124    ConversionContext10_50.INSTANCE.getVersionConvertor_10_50().copyBackboneElement(src,tgt);
125    if (src.hasLongitudeElement())
126      tgt.setLongitudeElement(Decimal10_50.convertDecimal(src.getLongitudeElement()));
127    if (src.hasLatitudeElement())
128      tgt.setLatitudeElement(Decimal10_50.convertDecimal(src.getLatitudeElement()));
129    if (src.hasAltitudeElement())
130      tgt.setAltitudeElement(Decimal10_50.convertDecimal(src.getAltitudeElement()));
131    return tgt;
132  }
133
134  public static org.hl7.fhir.dstu2.model.Location.LocationPositionComponent convertLocationPositionComponent(org.hl7.fhir.r5.model.Location.LocationPositionComponent src) throws FHIRException {
135    if (src == null || src.isEmpty())
136      return null;
137    org.hl7.fhir.dstu2.model.Location.LocationPositionComponent tgt = new org.hl7.fhir.dstu2.model.Location.LocationPositionComponent();
138    ConversionContext10_50.INSTANCE.getVersionConvertor_10_50().copyBackboneElement(src,tgt);
139    if (src.hasLongitudeElement())
140      tgt.setLongitudeElement(Decimal10_50.convertDecimal(src.getLongitudeElement()));
141    if (src.hasLatitudeElement())
142      tgt.setLatitudeElement(Decimal10_50.convertDecimal(src.getLatitudeElement()));
143    if (src.hasAltitudeElement())
144      tgt.setAltitudeElement(Decimal10_50.convertDecimal(src.getAltitudeElement()));
145    return tgt;
146  }
147
148  static public org.hl7.fhir.dstu2.model.Enumeration<org.hl7.fhir.dstu2.model.Location.LocationStatus> convertLocationStatus(org.hl7.fhir.r5.model.Enumeration<org.hl7.fhir.r5.model.Location.LocationStatus> src) throws FHIRException {
149    if (src == null || src.isEmpty())
150      return null;
151    org.hl7.fhir.dstu2.model.Enumeration<org.hl7.fhir.dstu2.model.Location.LocationStatus> tgt = new org.hl7.fhir.dstu2.model.Enumeration<>(new org.hl7.fhir.dstu2.model.Location.LocationStatusEnumFactory());
152    ConversionContext10_50.INSTANCE.getVersionConvertor_10_50().copyElement(src, tgt);
153    switch (src.getValue()) {
154      case ACTIVE:
155        tgt.setValue(org.hl7.fhir.dstu2.model.Location.LocationStatus.ACTIVE);
156        break;
157      case SUSPENDED:
158        tgt.setValue(org.hl7.fhir.dstu2.model.Location.LocationStatus.SUSPENDED);
159        break;
160      case INACTIVE:
161        tgt.setValue(org.hl7.fhir.dstu2.model.Location.LocationStatus.INACTIVE);
162        break;
163      default:
164        tgt.setValue(org.hl7.fhir.dstu2.model.Location.LocationStatus.NULL);
165        break;
166    }
167    return tgt;
168  }
169
170  static public org.hl7.fhir.r5.model.Enumeration<org.hl7.fhir.r5.model.Location.LocationStatus> convertLocationStatus(org.hl7.fhir.dstu2.model.Enumeration<org.hl7.fhir.dstu2.model.Location.LocationStatus> src) throws FHIRException {
171    if (src == null || src.isEmpty())
172      return null;
173    org.hl7.fhir.r5.model.Enumeration<org.hl7.fhir.r5.model.Location.LocationStatus> tgt = new org.hl7.fhir.r5.model.Enumeration<>(new org.hl7.fhir.r5.model.Location.LocationStatusEnumFactory());
174    ConversionContext10_50.INSTANCE.getVersionConvertor_10_50().copyElement(src, tgt);
175    switch (src.getValue()) {
176      case ACTIVE:
177        tgt.setValue(org.hl7.fhir.r5.model.Location.LocationStatus.ACTIVE);
178        break;
179      case SUSPENDED:
180        tgt.setValue(org.hl7.fhir.r5.model.Location.LocationStatus.SUSPENDED);
181        break;
182      case INACTIVE:
183        tgt.setValue(org.hl7.fhir.r5.model.Location.LocationStatus.INACTIVE);
184        break;
185      default:
186        tgt.setValue(org.hl7.fhir.r5.model.Location.LocationStatus.NULL);
187        break;
188    }
189    return tgt;
190  }
191}