001package org.hl7.fhir.convertors.conv40_50.resources40_50;
002
003import org.hl7.fhir.convertors.context.ConversionContext40_50;
004import org.hl7.fhir.convertors.conv40_50.datatypes40_50.general40_50.*;
005import org.hl7.fhir.convertors.conv40_50.datatypes40_50.primitive40_50.Boolean40_50;
006import org.hl7.fhir.convertors.conv40_50.datatypes40_50.primitive40_50.Decimal40_50;
007import org.hl7.fhir.convertors.conv40_50.datatypes40_50.primitive40_50.String40_50;
008import org.hl7.fhir.convertors.conv40_50.datatypes40_50.primitive40_50.Time40_50;
009import org.hl7.fhir.convertors.conv40_50.datatypes40_50.special40_50.Reference40_50;
010import org.hl7.fhir.exceptions.FHIRException;
011
012import java.util.stream.Collectors;
013
014/*
015  Copyright (c) 2011+, HL7, Inc.
016  All rights reserved.
017  
018  Redistribution and use in source and binary forms, with or without modification, 
019  are permitted provided that the following conditions are met:
020  
021   * Redistributions of source code must retain the above copyright notice, this 
022     list of conditions and the following disclaimer.
023   * Redistributions in binary form must reproduce the above copyright notice, 
024     this list of conditions and the following disclaimer in the documentation 
025     and/or other materials provided with the distribution.
026   * Neither the name of HL7 nor the names of its contributors may be used to 
027     endorse or promote products derived from this software without specific 
028     prior written permission.
029  
030  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 
031  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 
032  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 
033  IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 
034  INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 
035  NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 
036  PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 
037  WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
038  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
039  POSSIBILITY OF SUCH DAMAGE.
040  
041*/
042// Generated on Sun, Feb 24, 2019 11:37+1100 for FHIR v4.0.0
043public class Location40_50 {
044
045  public static org.hl7.fhir.r5.model.Location convertLocation(org.hl7.fhir.r4.model.Location src) throws FHIRException {
046    if (src == null)
047      return null;
048    org.hl7.fhir.r5.model.Location tgt = new org.hl7.fhir.r5.model.Location();
049    ConversionContext40_50.INSTANCE.getVersionConvertor_40_50().copyDomainResource(src, tgt);
050    for (org.hl7.fhir.r4.model.Identifier t : src.getIdentifier())
051      tgt.addIdentifier(Identifier40_50.convertIdentifier(t));
052    if (src.hasStatus())
053      tgt.setStatusElement(convertLocationStatus(src.getStatusElement()));
054    if (src.hasOperationalStatus())
055      tgt.setOperationalStatus(Coding40_50.convertCoding(src.getOperationalStatus()));
056    if (src.hasName())
057      tgt.setNameElement(String40_50.convertString(src.getNameElement()));
058    for (org.hl7.fhir.r4.model.StringType t : src.getAlias()) tgt.getAlias().add(String40_50.convertString(t));
059    if (src.hasDescription())
060      tgt.setDescriptionElement(String40_50.convertString(src.getDescriptionElement()));
061    if (src.hasMode())
062      tgt.setModeElement(convertLocationMode(src.getModeElement()));
063    for (org.hl7.fhir.r4.model.CodeableConcept t : src.getType())
064      tgt.addType(CodeableConcept40_50.convertCodeableConcept(t));
065    for (org.hl7.fhir.r4.model.ContactPoint t : src.getTelecom())
066      tgt.addTelecom(ContactPoint40_50.convertContactPoint(t));
067    if (src.hasAddress())
068      tgt.setAddress(Address40_50.convertAddress(src.getAddress()));
069    if (src.hasPhysicalType())
070      tgt.setPhysicalType(CodeableConcept40_50.convertCodeableConcept(src.getPhysicalType()));
071    if (src.hasPosition())
072      tgt.setPosition(convertLocationPositionComponent(src.getPosition()));
073    if (src.hasManagingOrganization())
074      tgt.setManagingOrganization(Reference40_50.convertReference(src.getManagingOrganization()));
075    if (src.hasPartOf())
076      tgt.setPartOf(Reference40_50.convertReference(src.getPartOf()));
077    for (org.hl7.fhir.r4.model.Location.LocationHoursOfOperationComponent t : src.getHoursOfOperation())
078      tgt.addHoursOfOperation(convertLocationHoursOfOperationComponent(t));
079    if (src.hasAvailabilityExceptions())
080      tgt.setAvailabilityExceptionsElement(String40_50.convertString(src.getAvailabilityExceptionsElement()));
081    for (org.hl7.fhir.r4.model.Reference t : src.getEndpoint()) tgt.addEndpoint(Reference40_50.convertReference(t));
082    return tgt;
083  }
084
085  public static org.hl7.fhir.r4.model.Location convertLocation(org.hl7.fhir.r5.model.Location src) throws FHIRException {
086    if (src == null)
087      return null;
088    org.hl7.fhir.r4.model.Location tgt = new org.hl7.fhir.r4.model.Location();
089    ConversionContext40_50.INSTANCE.getVersionConvertor_40_50().copyDomainResource(src, tgt);
090    for (org.hl7.fhir.r5.model.Identifier t : src.getIdentifier())
091      tgt.addIdentifier(Identifier40_50.convertIdentifier(t));
092    if (src.hasStatus())
093      tgt.setStatusElement(convertLocationStatus(src.getStatusElement()));
094    if (src.hasOperationalStatus())
095      tgt.setOperationalStatus(Coding40_50.convertCoding(src.getOperationalStatus()));
096    if (src.hasName())
097      tgt.setNameElement(String40_50.convertString(src.getNameElement()));
098    for (org.hl7.fhir.r5.model.StringType t : src.getAlias()) tgt.getAlias().add(String40_50.convertString(t));
099    if (src.hasDescription())
100      tgt.setDescriptionElement(String40_50.convertString(src.getDescriptionElement()));
101    if (src.hasMode())
102      tgt.setModeElement(convertLocationMode(src.getModeElement()));
103    for (org.hl7.fhir.r5.model.CodeableConcept t : src.getType())
104      tgt.addType(CodeableConcept40_50.convertCodeableConcept(t));
105    for (org.hl7.fhir.r5.model.ContactPoint t : src.getTelecom())
106      tgt.addTelecom(ContactPoint40_50.convertContactPoint(t));
107    if (src.hasAddress())
108      tgt.setAddress(Address40_50.convertAddress(src.getAddress()));
109    if (src.hasPhysicalType())
110      tgt.setPhysicalType(CodeableConcept40_50.convertCodeableConcept(src.getPhysicalType()));
111    if (src.hasPosition())
112      tgt.setPosition(convertLocationPositionComponent(src.getPosition()));
113    if (src.hasManagingOrganization())
114      tgt.setManagingOrganization(Reference40_50.convertReference(src.getManagingOrganization()));
115    if (src.hasPartOf())
116      tgt.setPartOf(Reference40_50.convertReference(src.getPartOf()));
117    for (org.hl7.fhir.r5.model.Location.LocationHoursOfOperationComponent t : src.getHoursOfOperation())
118      tgt.addHoursOfOperation(convertLocationHoursOfOperationComponent(t));
119    if (src.hasAvailabilityExceptions())
120      tgt.setAvailabilityExceptionsElement(String40_50.convertString(src.getAvailabilityExceptionsElement()));
121    for (org.hl7.fhir.r5.model.Reference t : src.getEndpoint()) tgt.addEndpoint(Reference40_50.convertReference(t));
122    return tgt;
123  }
124
125  static public org.hl7.fhir.r5.model.Enumeration<org.hl7.fhir.r5.model.Location.LocationStatus> convertLocationStatus(org.hl7.fhir.r4.model.Enumeration<org.hl7.fhir.r4.model.Location.LocationStatus> src) throws FHIRException {
126    if (src == null || src.isEmpty())
127      return null;
128    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());
129    ConversionContext40_50.INSTANCE.getVersionConvertor_40_50().copyElement(src, tgt);
130    switch (src.getValue()) {
131      case ACTIVE:
132        tgt.setValue(org.hl7.fhir.r5.model.Location.LocationStatus.ACTIVE);
133        break;
134      case SUSPENDED:
135        tgt.setValue(org.hl7.fhir.r5.model.Location.LocationStatus.SUSPENDED);
136        break;
137      case INACTIVE:
138        tgt.setValue(org.hl7.fhir.r5.model.Location.LocationStatus.INACTIVE);
139        break;
140      default:
141        tgt.setValue(org.hl7.fhir.r5.model.Location.LocationStatus.NULL);
142        break;
143    }
144    return tgt;
145  }
146
147  static public org.hl7.fhir.r4.model.Enumeration<org.hl7.fhir.r4.model.Location.LocationStatus> convertLocationStatus(org.hl7.fhir.r5.model.Enumeration<org.hl7.fhir.r5.model.Location.LocationStatus> src) throws FHIRException {
148    if (src == null || src.isEmpty())
149      return null;
150    org.hl7.fhir.r4.model.Enumeration<org.hl7.fhir.r4.model.Location.LocationStatus> tgt = new org.hl7.fhir.r4.model.Enumeration<>(new org.hl7.fhir.r4.model.Location.LocationStatusEnumFactory());
151    ConversionContext40_50.INSTANCE.getVersionConvertor_40_50().copyElement(src, tgt);
152    switch (src.getValue()) {
153      case ACTIVE:
154        tgt.setValue(org.hl7.fhir.r4.model.Location.LocationStatus.ACTIVE);
155        break;
156      case SUSPENDED:
157        tgt.setValue(org.hl7.fhir.r4.model.Location.LocationStatus.SUSPENDED);
158        break;
159      case INACTIVE:
160        tgt.setValue(org.hl7.fhir.r4.model.Location.LocationStatus.INACTIVE);
161        break;
162      default:
163        tgt.setValue(org.hl7.fhir.r4.model.Location.LocationStatus.NULL);
164        break;
165    }
166    return tgt;
167  }
168
169  static public org.hl7.fhir.r5.model.Enumeration<org.hl7.fhir.r5.model.Location.LocationMode> convertLocationMode(org.hl7.fhir.r4.model.Enumeration<org.hl7.fhir.r4.model.Location.LocationMode> src) throws FHIRException {
170    if (src == null || src.isEmpty())
171      return null;
172    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());
173    ConversionContext40_50.INSTANCE.getVersionConvertor_40_50().copyElement(src, tgt);
174    switch (src.getValue()) {
175      case INSTANCE:
176        tgt.setValue(org.hl7.fhir.r5.model.Location.LocationMode.INSTANCE);
177        break;
178      case KIND:
179        tgt.setValue(org.hl7.fhir.r5.model.Location.LocationMode.KIND);
180        break;
181      default:
182        tgt.setValue(org.hl7.fhir.r5.model.Location.LocationMode.NULL);
183        break;
184    }
185    return tgt;
186  }
187
188  static public org.hl7.fhir.r4.model.Enumeration<org.hl7.fhir.r4.model.Location.LocationMode> convertLocationMode(org.hl7.fhir.r5.model.Enumeration<org.hl7.fhir.r5.model.Location.LocationMode> src) throws FHIRException {
189    if (src == null || src.isEmpty())
190      return null;
191    org.hl7.fhir.r4.model.Enumeration<org.hl7.fhir.r4.model.Location.LocationMode> tgt = new org.hl7.fhir.r4.model.Enumeration<>(new org.hl7.fhir.r4.model.Location.LocationModeEnumFactory());
192    ConversionContext40_50.INSTANCE.getVersionConvertor_40_50().copyElement(src, tgt);
193    switch (src.getValue()) {
194      case INSTANCE:
195        tgt.setValue(org.hl7.fhir.r4.model.Location.LocationMode.INSTANCE);
196        break;
197      case KIND:
198        tgt.setValue(org.hl7.fhir.r4.model.Location.LocationMode.KIND);
199        break;
200      default:
201        tgt.setValue(org.hl7.fhir.r4.model.Location.LocationMode.NULL);
202        break;
203    }
204    return tgt;
205  }
206
207  public static org.hl7.fhir.r5.model.Location.LocationPositionComponent convertLocationPositionComponent(org.hl7.fhir.r4.model.Location.LocationPositionComponent src) throws FHIRException {
208    if (src == null)
209      return null;
210    org.hl7.fhir.r5.model.Location.LocationPositionComponent tgt = new org.hl7.fhir.r5.model.Location.LocationPositionComponent();
211    ConversionContext40_50.INSTANCE.getVersionConvertor_40_50().copyElement(src, tgt);
212    if (src.hasLongitude())
213      tgt.setLongitudeElement(Decimal40_50.convertDecimal(src.getLongitudeElement()));
214    if (src.hasLatitude())
215      tgt.setLatitudeElement(Decimal40_50.convertDecimal(src.getLatitudeElement()));
216    if (src.hasAltitude())
217      tgt.setAltitudeElement(Decimal40_50.convertDecimal(src.getAltitudeElement()));
218    return tgt;
219  }
220
221  public static org.hl7.fhir.r4.model.Location.LocationPositionComponent convertLocationPositionComponent(org.hl7.fhir.r5.model.Location.LocationPositionComponent src) throws FHIRException {
222    if (src == null)
223      return null;
224    org.hl7.fhir.r4.model.Location.LocationPositionComponent tgt = new org.hl7.fhir.r4.model.Location.LocationPositionComponent();
225    ConversionContext40_50.INSTANCE.getVersionConvertor_40_50().copyElement(src, tgt);
226    if (src.hasLongitude())
227      tgt.setLongitudeElement(Decimal40_50.convertDecimal(src.getLongitudeElement()));
228    if (src.hasLatitude())
229      tgt.setLatitudeElement(Decimal40_50.convertDecimal(src.getLatitudeElement()));
230    if (src.hasAltitude())
231      tgt.setAltitudeElement(Decimal40_50.convertDecimal(src.getAltitudeElement()));
232    return tgt;
233  }
234
235  public static org.hl7.fhir.r5.model.Location.LocationHoursOfOperationComponent convertLocationHoursOfOperationComponent(org.hl7.fhir.r4.model.Location.LocationHoursOfOperationComponent src) throws FHIRException {
236    if (src == null)
237      return null;
238    org.hl7.fhir.r5.model.Location.LocationHoursOfOperationComponent tgt = new org.hl7.fhir.r5.model.Location.LocationHoursOfOperationComponent();
239    ConversionContext40_50.INSTANCE.getVersionConvertor_40_50().copyElement(src, tgt);
240    tgt.setDaysOfWeek(src.getDaysOfWeek().stream()
241      .map(Location40_50::convertDaysOfWeek)
242      .collect(Collectors.toList()));
243    if (src.hasAllDay())
244      tgt.setAllDayElement(Boolean40_50.convertBoolean(src.getAllDayElement()));
245    if (src.hasOpeningTime())
246      tgt.setOpeningTimeElement(Time40_50.convertTime(src.getOpeningTimeElement()));
247    if (src.hasClosingTime())
248      tgt.setClosingTimeElement(Time40_50.convertTime(src.getClosingTimeElement()));
249    return tgt;
250  }
251
252  public static org.hl7.fhir.r4.model.Location.LocationHoursOfOperationComponent convertLocationHoursOfOperationComponent(org.hl7.fhir.r5.model.Location.LocationHoursOfOperationComponent src) throws FHIRException {
253    if (src == null)
254      return null;
255    org.hl7.fhir.r4.model.Location.LocationHoursOfOperationComponent tgt = new org.hl7.fhir.r4.model.Location.LocationHoursOfOperationComponent();
256    ConversionContext40_50.INSTANCE.getVersionConvertor_40_50().copyElement(src, tgt);
257    tgt.setDaysOfWeek(src.getDaysOfWeek().stream()
258      .map(Location40_50::convertDaysOfWeek)
259      .collect(Collectors.toList()));
260    if (src.hasAllDay())
261      tgt.setAllDayElement(Boolean40_50.convertBoolean(src.getAllDayElement()));
262    if (src.hasOpeningTime())
263      tgt.setOpeningTimeElement(Time40_50.convertTime(src.getOpeningTimeElement()));
264    if (src.hasClosingTime())
265      tgt.setClosingTimeElement(Time40_50.convertTime(src.getClosingTimeElement()));
266    return tgt;
267  }
268
269  static public org.hl7.fhir.r5.model.Enumeration<org.hl7.fhir.r5.model.Enumerations.DaysOfWeek> convertDaysOfWeek(org.hl7.fhir.r4.model.Enumeration<org.hl7.fhir.r4.model.Location.DaysOfWeek> src) throws FHIRException {
270    if (src == null || src.isEmpty())
271      return null;
272    org.hl7.fhir.r5.model.Enumeration<org.hl7.fhir.r5.model.Enumerations.DaysOfWeek> tgt = new org.hl7.fhir.r5.model.Enumeration<>(new org.hl7.fhir.r5.model.Enumerations.DaysOfWeekEnumFactory());
273    ConversionContext40_50.INSTANCE.getVersionConvertor_40_50().copyElement(src, tgt);
274    switch (src.getValue()) {
275      case MON:
276        tgt.setValue(org.hl7.fhir.r5.model.Enumerations.DaysOfWeek.MON);
277        break;
278      case TUE:
279        tgt.setValue(org.hl7.fhir.r5.model.Enumerations.DaysOfWeek.TUE);
280        break;
281      case WED:
282        tgt.setValue(org.hl7.fhir.r5.model.Enumerations.DaysOfWeek.WED);
283        break;
284      case THU:
285        tgt.setValue(org.hl7.fhir.r5.model.Enumerations.DaysOfWeek.THU);
286        break;
287      case FRI:
288        tgt.setValue(org.hl7.fhir.r5.model.Enumerations.DaysOfWeek.FRI);
289        break;
290      case SAT:
291        tgt.setValue(org.hl7.fhir.r5.model.Enumerations.DaysOfWeek.SAT);
292        break;
293      case SUN:
294        tgt.setValue(org.hl7.fhir.r5.model.Enumerations.DaysOfWeek.SUN);
295        break;
296      default:
297        tgt.setValue(org.hl7.fhir.r5.model.Enumerations.DaysOfWeek.NULL);
298        break;
299    }
300    return tgt;
301  }
302
303  static public org.hl7.fhir.r4.model.Enumeration<org.hl7.fhir.r4.model.Location.DaysOfWeek> convertDaysOfWeek(org.hl7.fhir.r5.model.Enumeration<org.hl7.fhir.r5.model.Enumerations.DaysOfWeek> src) throws FHIRException {
304    if (src == null || src.isEmpty())
305      return null;
306    org.hl7.fhir.r4.model.Enumeration<org.hl7.fhir.r4.model.Location.DaysOfWeek> tgt = new org.hl7.fhir.r4.model.Enumeration<>(new org.hl7.fhir.r4.model.Location.DaysOfWeekEnumFactory());
307    ConversionContext40_50.INSTANCE.getVersionConvertor_40_50().copyElement(src, tgt);
308    switch (src.getValue()) {
309      case MON:
310        tgt.setValue(org.hl7.fhir.r4.model.Location.DaysOfWeek.MON);
311        break;
312      case TUE:
313        tgt.setValue(org.hl7.fhir.r4.model.Location.DaysOfWeek.TUE);
314        break;
315      case WED:
316        tgt.setValue(org.hl7.fhir.r4.model.Location.DaysOfWeek.WED);
317        break;
318      case THU:
319        tgt.setValue(org.hl7.fhir.r4.model.Location.DaysOfWeek.THU);
320        break;
321      case FRI:
322        tgt.setValue(org.hl7.fhir.r4.model.Location.DaysOfWeek.FRI);
323        break;
324      case SAT:
325        tgt.setValue(org.hl7.fhir.r4.model.Location.DaysOfWeek.SAT);
326        break;
327      case SUN:
328        tgt.setValue(org.hl7.fhir.r4.model.Location.DaysOfWeek.SUN);
329        break;
330      default:
331        tgt.setValue(org.hl7.fhir.r4.model.Location.DaysOfWeek.NULL);
332        break;
333    }
334    return tgt;
335  }
336}