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.Annotation43_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.Identifier43_50;
007import org.hl7.fhir.convertors.conv43_50.datatypes43_50.primitive43_50.DateTime43_50;
008import org.hl7.fhir.convertors.conv43_50.datatypes43_50.special43_50.Reference43_50;
009import org.hl7.fhir.exceptions.FHIRException;
010import org.hl7.fhir.r5.model.CodeableReference;
011
012/*
013  Copyright (c) 2011+, HL7, Inc.
014  All rights reserved.
015  
016  Redistribution and use in source and binary forms, with or without modification, 
017  are permitted provided that the following conditions are met:
018  
019   * Redistributions of source code must retain the above copyright notice, this 
020     list of conditions and the following disclaimer.
021   * Redistributions in binary form must reproduce the above copyright notice, 
022     this list of conditions and the following disclaimer in the documentation 
023     and/or other materials provided with the distribution.
024   * Neither the name of HL7 nor the names of its contributors may be used to 
025     endorse or promote products derived from this software without specific 
026     prior written permission.
027  
028  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 
029  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 
030  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 
031  IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 
032  INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 
033  NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 
034  PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 
035  WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
036  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
037  POSSIBILITY OF SUCH DAMAGE.
038  
039*/
040// Generated on Sun, Feb 24, 2019 11:37+1100 for FHIR v4.0.0
041public class DeviceUseStatement43_50 {
042
043  public static org.hl7.fhir.r5.model.DeviceUsage convertDeviceUseStatement(org.hl7.fhir.r4b.model.DeviceUseStatement src) throws FHIRException {
044    if (src == null)
045      return null;
046    org.hl7.fhir.r5.model.DeviceUsage tgt = new org.hl7.fhir.r5.model.DeviceUsage();
047    ConversionContext43_50.INSTANCE.getVersionConvertor_43_50().copyDomainResource(src, tgt);
048    for (org.hl7.fhir.r4b.model.Identifier t : src.getIdentifier())
049      tgt.addIdentifier(Identifier43_50.convertIdentifier(t));
050    for (org.hl7.fhir.r4b.model.Reference t : src.getBasedOn()) tgt.addBasedOn(Reference43_50.convertReference(t));
051    if (src.hasStatus())
052      tgt.setStatusElement(convertDeviceUseStatementStatus(src.getStatusElement()));
053    if (src.hasSubject())
054      tgt.setPatient(Reference43_50.convertReference(src.getSubject()));
055    for (org.hl7.fhir.r4b.model.Reference t : src.getDerivedFrom())
056      tgt.addDerivedFrom(Reference43_50.convertReference(t));
057    if (src.hasTiming())
058      tgt.setTiming(ConversionContext43_50.INSTANCE.getVersionConvertor_43_50().convertType(src.getTiming()));
059    if (src.hasRecordedOn())
060      tgt.setDateAssertedElement(DateTime43_50.convertDateTime(src.getRecordedOnElement()));
061    if (src.hasSource())
062      tgt.setInformationSource(Reference43_50.convertReference(src.getSource()));
063    if (src.hasDevice())
064      tgt.getDevice().setReference(Reference43_50.convertReference(src.getDevice()));
065    for (org.hl7.fhir.r4b.model.CodeableConcept t : src.getReasonCode())
066      tgt.addReason(CodeableConcept43_50.convertCodeableConceptToCodeableReference(t));
067    for (org.hl7.fhir.r4b.model.Reference t : src.getReasonReference())
068      tgt.addReason(Reference43_50.convertReferenceToCodeableReference(t));
069    if (src.hasBodySite())
070      tgt.getBodySite().setConcept(CodeableConcept43_50.convertCodeableConcept(src.getBodySite()));
071    for (org.hl7.fhir.r4b.model.Annotation t : src.getNote()) tgt.addNote(Annotation43_50.convertAnnotation(t));
072    return tgt;
073  }
074
075  public static org.hl7.fhir.r4b.model.DeviceUseStatement convertDeviceUseStatement(org.hl7.fhir.r5.model.DeviceUsage src) throws FHIRException {
076    if (src == null)
077      return null;
078    org.hl7.fhir.r4b.model.DeviceUseStatement tgt = new org.hl7.fhir.r4b.model.DeviceUseStatement();
079    ConversionContext43_50.INSTANCE.getVersionConvertor_43_50().copyDomainResource(src, tgt);
080    for (org.hl7.fhir.r5.model.Identifier t : src.getIdentifier())
081      tgt.addIdentifier(Identifier43_50.convertIdentifier(t));
082    for (org.hl7.fhir.r5.model.Reference t : src.getBasedOn()) tgt.addBasedOn(Reference43_50.convertReference(t));
083    if (src.hasStatus())
084      tgt.setStatusElement(convertDeviceUseStatementStatus(src.getStatusElement()));
085    if (src.hasPatient())
086      tgt.setSubject(Reference43_50.convertReference(src.getPatient()));
087    for (org.hl7.fhir.r5.model.Reference t : src.getDerivedFrom())
088      tgt.addDerivedFrom(Reference43_50.convertReference(t));
089    if (src.hasTiming())
090      tgt.setTiming(ConversionContext43_50.INSTANCE.getVersionConvertor_43_50().convertType(src.getTiming()));
091    if (src.hasDateAsserted())
092      tgt.setRecordedOnElement(DateTime43_50.convertDateTime(src.getDateAssertedElement()));
093    if (src.hasInformationSource())
094      tgt.setSource(Reference43_50.convertReference(src.getInformationSource()));
095    if (src.getDevice().hasReference())
096      tgt.setDevice(Reference43_50.convertReference(src.getDevice().getReference()));
097    for (CodeableReference t : src.getReason())
098      if (t.hasConcept())
099        tgt.addReasonCode(CodeableConcept43_50.convertCodeableConcept(t.getConcept()));
100    for (CodeableReference t : src.getReason())
101      if (t.hasReference())
102        tgt.addReasonReference(Reference43_50.convertReference(t.getReference()));
103    if (src.getBodySite().hasConcept())
104      tgt.setBodySite(CodeableConcept43_50.convertCodeableConcept(src.getBodySite().getConcept()));
105    for (org.hl7.fhir.r5.model.Annotation t : src.getNote()) tgt.addNote(Annotation43_50.convertAnnotation(t));
106    return tgt;
107  }
108
109  static public org.hl7.fhir.r5.model.Enumeration<org.hl7.fhir.r5.model.DeviceUsage.DeviceUsageStatus> convertDeviceUseStatementStatus(org.hl7.fhir.r4b.model.Enumeration<org.hl7.fhir.r4b.model.DeviceUseStatement.DeviceUseStatementStatus> src) throws FHIRException {
110    if (src == null || src.isEmpty())
111      return null;
112    org.hl7.fhir.r5.model.Enumeration<org.hl7.fhir.r5.model.DeviceUsage.DeviceUsageStatus> tgt = new org.hl7.fhir.r5.model.Enumeration<>(new org.hl7.fhir.r5.model.DeviceUsage.DeviceUsageStatusEnumFactory());
113    ConversionContext43_50.INSTANCE.getVersionConvertor_43_50().copyElement(src, tgt);
114    switch (src.getValue()) {
115      case ACTIVE:
116        tgt.setValue(org.hl7.fhir.r5.model.DeviceUsage.DeviceUsageStatus.ACTIVE);
117        break;
118      case COMPLETED:
119        tgt.setValue(org.hl7.fhir.r5.model.DeviceUsage.DeviceUsageStatus.COMPLETED);
120        break;
121      case ENTEREDINERROR:
122        tgt.setValue(org.hl7.fhir.r5.model.DeviceUsage.DeviceUsageStatus.ENTEREDINERROR);
123        break;
124      case INTENDED:
125        tgt.setValue(org.hl7.fhir.r5.model.DeviceUsage.DeviceUsageStatus.INTENDED);
126        break;
127      case STOPPED:
128        tgt.setValue(org.hl7.fhir.r5.model.DeviceUsage.DeviceUsageStatus.STOPPED);
129        break;
130      case ONHOLD:
131        tgt.setValue(org.hl7.fhir.r5.model.DeviceUsage.DeviceUsageStatus.ONHOLD);
132        break;
133      default:
134        tgt.setValue(org.hl7.fhir.r5.model.DeviceUsage.DeviceUsageStatus.NULL);
135        break;
136    }
137    return tgt;
138  }
139
140  static public org.hl7.fhir.r4b.model.Enumeration<org.hl7.fhir.r4b.model.DeviceUseStatement.DeviceUseStatementStatus> convertDeviceUseStatementStatus(org.hl7.fhir.r5.model.Enumeration<org.hl7.fhir.r5.model.DeviceUsage.DeviceUsageStatus> src) throws FHIRException {
141    if (src == null || src.isEmpty())
142      return null;
143    org.hl7.fhir.r4b.model.Enumeration<org.hl7.fhir.r4b.model.DeviceUseStatement.DeviceUseStatementStatus> tgt = new org.hl7.fhir.r4b.model.Enumeration<>(new org.hl7.fhir.r4b.model.DeviceUseStatement.DeviceUseStatementStatusEnumFactory());
144    ConversionContext43_50.INSTANCE.getVersionConvertor_43_50().copyElement(src, tgt);
145    switch (src.getValue()) {
146      case ACTIVE:
147        tgt.setValue(org.hl7.fhir.r4b.model.DeviceUseStatement.DeviceUseStatementStatus.ACTIVE);
148        break;
149      case COMPLETED:
150        tgt.setValue(org.hl7.fhir.r4b.model.DeviceUseStatement.DeviceUseStatementStatus.COMPLETED);
151        break;
152      case ENTEREDINERROR:
153        tgt.setValue(org.hl7.fhir.r4b.model.DeviceUseStatement.DeviceUseStatementStatus.ENTEREDINERROR);
154        break;
155      case INTENDED:
156        tgt.setValue(org.hl7.fhir.r4b.model.DeviceUseStatement.DeviceUseStatementStatus.INTENDED);
157        break;
158      case STOPPED:
159        tgt.setValue(org.hl7.fhir.r4b.model.DeviceUseStatement.DeviceUseStatementStatus.STOPPED);
160        break;
161      case ONHOLD:
162        tgt.setValue(org.hl7.fhir.r4b.model.DeviceUseStatement.DeviceUseStatementStatus.ONHOLD);
163        break;
164      default:
165        tgt.setValue(org.hl7.fhir.r4b.model.DeviceUseStatement.DeviceUseStatementStatus.NULL);
166        break;
167    }
168    return tgt;
169  }
170}