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