001package org.hl7.fhir.convertors.conv30_40.resources30_40;
002
003
004import java.util.Collections;
005import java.util.stream.Collectors;
006
007import org.hl7.fhir.convertors.context.ConversionContext30_40;
008import org.hl7.fhir.convertors.conv30_40.datatypes30_40.Reference30_40;
009import org.hl7.fhir.convertors.conv30_40.datatypes30_40.complextypes30_40.Annotation30_40;
010import org.hl7.fhir.convertors.conv30_40.datatypes30_40.complextypes30_40.CodeableConcept30_40;
011import org.hl7.fhir.convertors.conv30_40.datatypes30_40.complextypes30_40.ContactPoint30_40;
012import org.hl7.fhir.convertors.conv30_40.datatypes30_40.complextypes30_40.Identifier30_40;
013import org.hl7.fhir.convertors.conv30_40.datatypes30_40.primitivetypes30_40.Base64Binary30_40;
014import org.hl7.fhir.convertors.conv30_40.datatypes30_40.primitivetypes30_40.DateTime30_40;
015import org.hl7.fhir.convertors.conv30_40.datatypes30_40.primitivetypes30_40.String30_40;
016import org.hl7.fhir.convertors.conv30_40.datatypes30_40.primitivetypes30_40.Uri30_40;
017import org.hl7.fhir.dstu3.model.Device;
018import org.hl7.fhir.exceptions.FHIRException;
019import org.hl7.fhir.r4.model.Enumeration;
020
021/*
022  Copyright (c) 2011+, HL7, Inc.
023  All rights reserved.
024
025  Redistribution and use in source and binary forms, with or without modification,
026  are permitted provided that the following conditions are met:
027
028   * Redistributions of source code must retain the above copyright notice, this
029     list of conditions and the following disclaimer.
030   * Redistributions in binary form must reproduce the above copyright notice,
031     this list of conditions and the following disclaimer in the documentation
032     and/or other materials provided with the distribution.
033   * Neither the name of HL7 nor the names of its contributors may be used to
034     endorse or promote products derived from this software without specific
035     prior written permission.
036
037  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
038  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
039  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
040  IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
041  INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
042  NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
043  PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
044  WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
045  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
046  POSSIBILITY OF SUCH DAMAGE.
047
048*/
049// Generated on Sun, Feb 24, 2019 11:37+1100 for FHIR v4.0.0
050public class Device30_40 {
051
052  public static org.hl7.fhir.r4.model.Device convertDevice(org.hl7.fhir.dstu3.model.Device src) throws FHIRException {
053    if (src == null)
054      return null;
055    org.hl7.fhir.r4.model.Device tgt = new org.hl7.fhir.r4.model.Device();
056    ConversionContext30_40.INSTANCE.getVersionConvertor_30_40().copyDomainResource(src, tgt);
057    for (org.hl7.fhir.dstu3.model.Identifier t : src.getIdentifier())
058      tgt.addIdentifier(Identifier30_40.convertIdentifier(t));
059    if (src.hasUdi()) {
060      org.hl7.fhir.r4.model.Device.DeviceUdiCarrierComponent carrierComponent = tgt.getUdiCarrierFirstRep();
061      carrierComponent.setDeviceIdentifierElement(String30_40.convertString(src.getUdi().getDeviceIdentifierElement()));
062      carrierComponent.setJurisdictionElement(Uri30_40.convertUri(src.getUdi().getJurisdictionElement()));
063      carrierComponent.setCarrierHRFElement(String30_40.convertString(src.getUdi().getCarrierHRFElement()));
064      carrierComponent.setCarrierAIDCElement(Base64Binary30_40.convertBase64Binary(src.getUdi().getCarrierAIDCElement()));
065      carrierComponent.setIssuerElement(Uri30_40.convertUri(src.getUdi().getIssuerElement()));
066      carrierComponent.setEntryTypeElement(convertUDIEntryType(src.getUdi().getEntryTypeElement()));
067      tgt.setUdiCarrier(Collections.singletonList(carrierComponent));
068      org.hl7.fhir.r4.model.Device.DeviceDeviceNameComponent nameComponent = tgt.getDeviceNameFirstRep();
069      nameComponent.setNameElement(String30_40.convertString(src.getUdi().getNameElement()));
070      nameComponent.setType(org.hl7.fhir.r4.model.Device.DeviceNameType.UDILABELNAME);
071    }
072    if (src.hasStatus())
073      tgt.setStatusElement(convertFHIRDeviceStatus(src.getStatusElement()));
074    if (src.hasType())
075      tgt.setType(CodeableConcept30_40.convertCodeableConcept(src.getType()));
076    if (src.hasLotNumber())
077      tgt.setLotNumberElement(String30_40.convertString(src.getLotNumberElement()));
078    if (src.hasManufacturer())
079      tgt.setManufacturerElement(String30_40.convertString(src.getManufacturerElement()));
080    if (src.hasManufactureDate())
081      tgt.setManufactureDateElement(DateTime30_40.convertDateTime(src.getManufactureDateElement()));
082    if (src.hasExpirationDate())
083      tgt.setExpirationDateElement(DateTime30_40.convertDateTime(src.getExpirationDateElement()));
084    if (src.hasModelElement())
085      tgt.setModelNumberElement(String30_40.convertString(src.getModelElement()));
086    if (src.hasVersionElement())
087      tgt.setVersion(Collections.singletonList(tgt.getVersionFirstRep().setValueElement(String30_40.convertString(src.getVersionElement()))));
088    if (src.hasPatient())
089      tgt.setPatient(Reference30_40.convertReference(src.getPatient()));
090    if (src.hasOwner())
091      tgt.setOwner(Reference30_40.convertReference(src.getOwner()));
092    if (src.hasContact())
093      tgt.setContact(src.getContact().stream().map(ContactPoint30_40::convertContactPoint).collect(Collectors.toList()));
094    if (src.hasLocation())
095      tgt.setLocation(Reference30_40.convertReference(src.getLocation()));
096    if (src.hasUrl())
097      tgt.setUrlElement(Uri30_40.convertUri(src.getUrlElement()));
098    for (org.hl7.fhir.dstu3.model.Annotation t : src.getNote()) tgt.addNote(Annotation30_40.convertAnnotation(t));
099    for (org.hl7.fhir.dstu3.model.CodeableConcept t : src.getSafety())
100      tgt.addSafety(CodeableConcept30_40.convertCodeableConcept(t));
101    return tgt;
102  }
103
104  public static org.hl7.fhir.dstu3.model.Device convertDevice(org.hl7.fhir.r4.model.Device src) throws FHIRException {
105    if (src == null)
106      return null;
107    org.hl7.fhir.dstu3.model.Device tgt = new org.hl7.fhir.dstu3.model.Device();
108    ConversionContext30_40.INSTANCE.getVersionConvertor_30_40().copyDomainResource(src, tgt);
109    for (org.hl7.fhir.r4.model.Identifier t : src.getIdentifier())
110      tgt.addIdentifier(Identifier30_40.convertIdentifier(t));
111    if (src.hasUdiCarrier()) {
112      Device.DeviceUdiComponent udi = tgt.getUdi();
113      udi.setDeviceIdentifierElement(String30_40.convertString(src.getUdiCarrierFirstRep().getDeviceIdentifierElement()));
114      udi.setJurisdictionElement(Uri30_40.convertUri(src.getUdiCarrierFirstRep().getJurisdictionElement()));
115      udi.setCarrierHRFElement(String30_40.convertString(src.getUdiCarrierFirstRep().getCarrierHRFElement()));
116      udi.setCarrierAIDCElement(Base64Binary30_40.convertBase64Binary(src.getUdiCarrierFirstRep().getCarrierAIDCElement()));
117      udi.setIssuerElement(Uri30_40.convertUri(src.getUdiCarrierFirstRep().getIssuerElement()));
118      udi.setEntryTypeElement(convertUDIEntryType(src.getUdiCarrierFirstRep().getEntryTypeElement()));
119      tgt.setUdi(udi);
120    }
121    if (src.hasStatus())
122      tgt.setStatusElement(convertFHIRDeviceStatus(src.getStatusElement()));
123    if (src.hasType())
124      tgt.setType(CodeableConcept30_40.convertCodeableConcept(src.getType()));
125    if (src.hasLotNumber())
126      tgt.setLotNumberElement(String30_40.convertString(src.getLotNumberElement()));
127    if (src.hasManufacturer())
128      tgt.setManufacturerElement(String30_40.convertString(src.getManufacturerElement()));
129    if (src.hasManufactureDate())
130      tgt.setManufactureDateElement(DateTime30_40.convertDateTime(src.getManufactureDateElement()));
131    if (src.hasExpirationDate())
132      tgt.setExpirationDateElement(DateTime30_40.convertDateTime(src.getExpirationDateElement()));
133    if (src.hasModelNumber())
134      tgt.setModel(src.getModelNumber());
135    if (src.hasVersion())
136      tgt.setVersionElement(String30_40.convertString(src.getVersion().get(0).getValueElement()));
137    if (src.hasDeviceName())
138      tgt.setUdi(tgt.getUdi().setName(src.getDeviceName().get(0).getName()));
139    if (src.hasPatient())
140      tgt.setPatient(Reference30_40.convertReference(src.getPatient()));
141    if (src.hasOwner())
142      tgt.setOwner(Reference30_40.convertReference(src.getOwner()));
143    if (src.hasContact())
144      tgt.setContact(src.getContact().stream().map(ContactPoint30_40::convertContactPoint).collect(Collectors.toList()));
145    if (src.hasLocation())
146      tgt.setLocation(Reference30_40.convertReference(src.getLocation()));
147    for (org.hl7.fhir.r4.model.ContactPoint t : src.getContact())
148      tgt.addContact(ContactPoint30_40.convertContactPoint(t));
149    if (src.hasLocation())
150      tgt.setLocation(Reference30_40.convertReference(src.getLocation()));
151    if (src.hasUrl())
152      tgt.setUrlElement(Uri30_40.convertUri(src.getUrlElement()));
153    for (org.hl7.fhir.r4.model.Annotation t : src.getNote()) tgt.addNote(Annotation30_40.convertAnnotation(t));
154    for (org.hl7.fhir.r4.model.CodeableConcept t : src.getSafety())
155      tgt.addSafety(CodeableConcept30_40.convertCodeableConcept(t));
156    return tgt;
157  }
158
159  static public org.hl7.fhir.r4.model.Enumeration<org.hl7.fhir.r4.model.Device.FHIRDeviceStatus> convertFHIRDeviceStatus(org.hl7.fhir.dstu3.model.Enumeration<org.hl7.fhir.dstu3.model.Device.FHIRDeviceStatus> src) throws FHIRException {
160      if (src == null || src.isEmpty())
161          return null;
162      Enumeration<org.hl7.fhir.r4.model.Device.FHIRDeviceStatus> tgt = new Enumeration<>(new org.hl7.fhir.r4.model.Device.FHIRDeviceStatusEnumFactory());
163      ConversionContext30_40.INSTANCE.getVersionConvertor_30_40().copyElement(src, tgt);
164      if (src.getValue() == null) {
165          tgt.setValue(null);
166      } else {
167          switch (src.getValue()) {
168              case ACTIVE:
169                  tgt.setValue(org.hl7.fhir.r4.model.Device.FHIRDeviceStatus.ACTIVE);
170                  break;
171              case INACTIVE:
172                  tgt.setValue(org.hl7.fhir.r4.model.Device.FHIRDeviceStatus.INACTIVE);
173                  break;
174              case ENTEREDINERROR:
175                  tgt.setValue(org.hl7.fhir.r4.model.Device.FHIRDeviceStatus.ENTEREDINERROR);
176                  break;
177              case UNKNOWN:
178                  tgt.setValue(org.hl7.fhir.r4.model.Device.FHIRDeviceStatus.UNKNOWN);
179                  break;
180              default:
181                  tgt.setValue(org.hl7.fhir.r4.model.Device.FHIRDeviceStatus.NULL);
182                  break;
183          }
184      }
185      return tgt;
186  }
187
188  static public org.hl7.fhir.dstu3.model.Enumeration<org.hl7.fhir.dstu3.model.Device.FHIRDeviceStatus> convertFHIRDeviceStatus(org.hl7.fhir.r4.model.Enumeration<org.hl7.fhir.r4.model.Device.FHIRDeviceStatus> src) throws FHIRException {
189      if (src == null || src.isEmpty())
190          return null;
191      org.hl7.fhir.dstu3.model.Enumeration<Device.FHIRDeviceStatus> tgt = new org.hl7.fhir.dstu3.model.Enumeration<>(new Device.FHIRDeviceStatusEnumFactory());
192      ConversionContext30_40.INSTANCE.getVersionConvertor_30_40().copyElement(src, tgt);
193      if (src.getValue() == null) {
194          tgt.setValue(null);
195      } else {
196          switch (src.getValue()) {
197              case ACTIVE:
198                  tgt.setValue(Device.FHIRDeviceStatus.ACTIVE);
199                  break;
200              case INACTIVE:
201                  tgt.setValue(Device.FHIRDeviceStatus.INACTIVE);
202                  break;
203              case ENTEREDINERROR:
204                  tgt.setValue(Device.FHIRDeviceStatus.ENTEREDINERROR);
205                  break;
206              case UNKNOWN:
207                  tgt.setValue(Device.FHIRDeviceStatus.UNKNOWN);
208                  break;
209              default:
210                  tgt.setValue(Device.FHIRDeviceStatus.NULL);
211                  break;
212          }
213      }
214      return tgt;
215  }
216
217  static public org.hl7.fhir.r4.model.Enumeration<org.hl7.fhir.r4.model.Device.UDIEntryType> convertUDIEntryType(org.hl7.fhir.dstu3.model.Enumeration<org.hl7.fhir.dstu3.model.Device.UDIEntryType> src) throws FHIRException {
218      if (src == null || src.isEmpty())
219          return null;
220      Enumeration<org.hl7.fhir.r4.model.Device.UDIEntryType> tgt = new Enumeration<>(new org.hl7.fhir.r4.model.Device.UDIEntryTypeEnumFactory());
221      ConversionContext30_40.INSTANCE.getVersionConvertor_30_40().copyElement(src, tgt);
222      if (src.getValue() == null) {
223          tgt.setValue(null);
224      } else {
225          switch (src.getValue()) {
226              case BARCODE:
227                  tgt.setValue(org.hl7.fhir.r4.model.Device.UDIEntryType.BARCODE);
228                  break;
229              case RFID:
230                  tgt.setValue(org.hl7.fhir.r4.model.Device.UDIEntryType.RFID);
231                  break;
232              case MANUAL:
233                  tgt.setValue(org.hl7.fhir.r4.model.Device.UDIEntryType.MANUAL);
234                  break;
235              case CARD:
236                  tgt.setValue(org.hl7.fhir.r4.model.Device.UDIEntryType.CARD);
237                  break;
238              case SELFREPORTED:
239                  tgt.setValue(org.hl7.fhir.r4.model.Device.UDIEntryType.SELFREPORTED);
240                  break;
241              case UNKNOWN:
242                  tgt.setValue(org.hl7.fhir.r4.model.Device.UDIEntryType.UNKNOWN);
243                  break;
244              default:
245                  tgt.setValue(org.hl7.fhir.r4.model.Device.UDIEntryType.NULL);
246                  break;
247          }
248      }
249      return tgt;
250  }
251
252  static public org.hl7.fhir.dstu3.model.Enumeration<org.hl7.fhir.dstu3.model.Device.UDIEntryType> convertUDIEntryType(org.hl7.fhir.r4.model.Enumeration<org.hl7.fhir.r4.model.Device.UDIEntryType> src) throws FHIRException {
253      if (src == null || src.isEmpty())
254          return null;
255      org.hl7.fhir.dstu3.model.Enumeration<Device.UDIEntryType> tgt = new org.hl7.fhir.dstu3.model.Enumeration<>(new Device.UDIEntryTypeEnumFactory());
256      ConversionContext30_40.INSTANCE.getVersionConvertor_30_40().copyElement(src, tgt);
257      if (src.getValue() == null) {
258          tgt.setValue(null);
259      } else {
260          switch (src.getValue()) {
261              case BARCODE:
262                  tgt.setValue(Device.UDIEntryType.BARCODE);
263                  break;
264              case RFID:
265                  tgt.setValue(Device.UDIEntryType.RFID);
266                  break;
267              case MANUAL:
268                  tgt.setValue(Device.UDIEntryType.MANUAL);
269                  break;
270              case CARD:
271                  tgt.setValue(Device.UDIEntryType.CARD);
272                  break;
273              case SELFREPORTED:
274                  tgt.setValue(Device.UDIEntryType.SELFREPORTED);
275                  break;
276              case UNKNOWN:
277                  tgt.setValue(Device.UDIEntryType.UNKNOWN);
278                  break;
279              default:
280                  tgt.setValue(Device.UDIEntryType.NULL);
281                  break;
282          }
283      }
284      return tgt;
285  }
286}