001package org.hl7.fhir.convertors.conv30_50.resources30_50;
002
003
004import org.hl7.fhir.convertors.context.ConversionContext30_50;
005import org.hl7.fhir.convertors.conv30_50.datatypes30_50.Reference30_50;
006import org.hl7.fhir.convertors.conv30_50.datatypes30_50.complextypes30_50.CodeableConcept30_50;
007import org.hl7.fhir.convertors.conv30_50.datatypes30_50.complextypes30_50.Coding30_50;
008import org.hl7.fhir.convertors.conv30_50.datatypes30_50.complextypes30_50.Period30_50;
009import org.hl7.fhir.convertors.conv30_50.datatypes30_50.complextypes30_50.Signature30_50;
010import org.hl7.fhir.convertors.conv30_50.datatypes30_50.primitivetypes30_50.Instant30_50;
011import org.hl7.fhir.convertors.conv30_50.datatypes30_50.primitivetypes30_50.Uri30_50;
012import org.hl7.fhir.exceptions.FHIRException;
013import org.hl7.fhir.r5.model.CodeableReference;
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 Provenance30_50 {
045
046  public static org.hl7.fhir.r5.model.Provenance convertProvenance(org.hl7.fhir.dstu3.model.Provenance src) throws FHIRException {
047    if (src == null)
048      return null;
049    org.hl7.fhir.r5.model.Provenance tgt = new org.hl7.fhir.r5.model.Provenance();
050    ConversionContext30_50.INSTANCE.getVersionConvertor_30_50().copyDomainResource(src, tgt);
051    for (org.hl7.fhir.dstu3.model.Reference t : src.getTarget()) tgt.addTarget(Reference30_50.convertReference(t));
052    if (src.hasPeriod())
053      tgt.setOccurred(ConversionContext30_50.INSTANCE.getVersionConvertor_30_50().convertType(src.getPeriod()));
054    if (src.hasRecorded())
055      tgt.setRecordedElement(Instant30_50.convertInstant(src.getRecordedElement()));
056    for (org.hl7.fhir.dstu3.model.UriType t : src.getPolicy()) tgt.getPolicy().add(Uri30_50.convertUri(t));
057    if (src.hasLocation())
058      tgt.setLocation(Reference30_50.convertReference(src.getLocation()));
059    for (org.hl7.fhir.dstu3.model.Coding t : src.getReason())
060      tgt.addAuthorization().getConcept().addCoding(Coding30_50.convertCoding(t));
061    if (src.hasActivity())
062      tgt.getActivity().addCoding(Coding30_50.convertCoding(src.getActivity()));
063    for (org.hl7.fhir.dstu3.model.Provenance.ProvenanceAgentComponent t : src.getAgent())
064      tgt.addAgent(convertProvenanceAgentComponent(t));
065    for (org.hl7.fhir.dstu3.model.Provenance.ProvenanceEntityComponent t : src.getEntity())
066      tgt.addEntity(convertProvenanceEntityComponent(t));
067    for (org.hl7.fhir.dstu3.model.Signature t : src.getSignature())
068      tgt.addSignature(Signature30_50.convertSignature(t));
069    return tgt;
070  }
071
072  public static org.hl7.fhir.dstu3.model.Provenance convertProvenance(org.hl7.fhir.r5.model.Provenance src) throws FHIRException {
073    if (src == null)
074      return null;
075    org.hl7.fhir.dstu3.model.Provenance tgt = new org.hl7.fhir.dstu3.model.Provenance();
076    ConversionContext30_50.INSTANCE.getVersionConvertor_30_50().copyDomainResource(src, tgt);
077    for (org.hl7.fhir.r5.model.Reference t : src.getTarget()) tgt.addTarget(Reference30_50.convertReference(t));
078    if (src.hasOccurredPeriod())
079      tgt.setPeriod(Period30_50.convertPeriod(src.getOccurredPeriod()));
080    if (src.hasRecorded())
081      tgt.setRecordedElement(Instant30_50.convertInstant(src.getRecordedElement()));
082    for (org.hl7.fhir.r5.model.UriType t : src.getPolicy()) tgt.getPolicy().add(Uri30_50.convertUri(t));
083    if (src.hasLocation())
084      tgt.setLocation(Reference30_50.convertReference(src.getLocation()));
085    for (CodeableReference t : src.getAuthorization())
086      if (t.hasConcept())
087        for (org.hl7.fhir.r5.model.Coding t2 : t.getConcept().getCoding())
088          tgt.addReason(Coding30_50.convertCoding(t2));
089    if (src.hasActivity())
090      tgt.setActivity(Coding30_50.convertCoding(src.getActivity().getCodingFirstRep()));
091    for (org.hl7.fhir.r5.model.Provenance.ProvenanceAgentComponent t : src.getAgent())
092      tgt.addAgent(convertProvenanceAgentComponent(t));
093    for (org.hl7.fhir.r5.model.Provenance.ProvenanceEntityComponent t : src.getEntity())
094      tgt.addEntity(convertProvenanceEntityComponent(t));
095    for (org.hl7.fhir.r5.model.Signature t : src.getSignature()) tgt.addSignature(Signature30_50.convertSignature(t));
096    return tgt;
097  }
098
099  public static org.hl7.fhir.r5.model.Provenance.ProvenanceAgentComponent convertProvenanceAgentComponent(org.hl7.fhir.dstu3.model.Provenance.ProvenanceAgentComponent src) throws FHIRException {
100    if (src == null)
101      return null;
102    org.hl7.fhir.r5.model.Provenance.ProvenanceAgentComponent tgt = new org.hl7.fhir.r5.model.Provenance.ProvenanceAgentComponent();
103    ConversionContext30_50.INSTANCE.getVersionConvertor_30_50().copyBackboneElement(src,tgt);
104    for (org.hl7.fhir.dstu3.model.CodeableConcept t : src.getRole())
105      tgt.addRole(CodeableConcept30_50.convertCodeableConcept(t));
106    if (src.hasWhoReference())
107      tgt.setWho(Reference30_50.convertReference(src.getWhoReference()));
108    if (src.hasOnBehalfOfReference())
109      tgt.setOnBehalfOf(Reference30_50.convertReference(src.getOnBehalfOfReference()));
110    return tgt;
111  }
112
113  public static org.hl7.fhir.dstu3.model.Provenance.ProvenanceAgentComponent convertProvenanceAgentComponent(org.hl7.fhir.r5.model.Provenance.ProvenanceAgentComponent src) throws FHIRException {
114    if (src == null)
115      return null;
116    org.hl7.fhir.dstu3.model.Provenance.ProvenanceAgentComponent tgt = new org.hl7.fhir.dstu3.model.Provenance.ProvenanceAgentComponent();
117    ConversionContext30_50.INSTANCE.getVersionConvertor_30_50().copyBackboneElement(src,tgt);
118    for (org.hl7.fhir.r5.model.CodeableConcept t : src.getRole())
119      tgt.addRole(CodeableConcept30_50.convertCodeableConcept(t));
120    if (src.hasWho())
121      tgt.setWho(Reference30_50.convertReference(src.getWho()));
122    if (src.hasOnBehalfOf())
123      tgt.setOnBehalfOf(Reference30_50.convertReference(src.getOnBehalfOf()));
124    return tgt;
125  }
126
127  public static org.hl7.fhir.r5.model.Provenance.ProvenanceEntityComponent convertProvenanceEntityComponent(org.hl7.fhir.dstu3.model.Provenance.ProvenanceEntityComponent src) throws FHIRException {
128    if (src == null)
129      return null;
130    org.hl7.fhir.r5.model.Provenance.ProvenanceEntityComponent tgt = new org.hl7.fhir.r5.model.Provenance.ProvenanceEntityComponent();
131    ConversionContext30_50.INSTANCE.getVersionConvertor_30_50().copyBackboneElement(src,tgt);
132    if (src.hasRole())
133      tgt.setRoleElement(convertProvenanceEntityRole(src.getRoleElement()));
134    if (src.hasWhatReference())
135      tgt.setWhat(Reference30_50.convertReference(src.getWhatReference()));
136    for (org.hl7.fhir.dstu3.model.Provenance.ProvenanceAgentComponent t : src.getAgent())
137      tgt.addAgent(convertProvenanceAgentComponent(t));
138    return tgt;
139  }
140
141  public static org.hl7.fhir.dstu3.model.Provenance.ProvenanceEntityComponent convertProvenanceEntityComponent(org.hl7.fhir.r5.model.Provenance.ProvenanceEntityComponent src) throws FHIRException {
142    if (src == null)
143      return null;
144    org.hl7.fhir.dstu3.model.Provenance.ProvenanceEntityComponent tgt = new org.hl7.fhir.dstu3.model.Provenance.ProvenanceEntityComponent();
145    ConversionContext30_50.INSTANCE.getVersionConvertor_30_50().copyBackboneElement(src,tgt);
146    if (src.hasRole())
147      tgt.setRoleElement(convertProvenanceEntityRole(src.getRoleElement()));
148    if (src.hasWhat())
149      tgt.setWhat(Reference30_50.convertReference(src.getWhat()));
150    for (org.hl7.fhir.r5.model.Provenance.ProvenanceAgentComponent t : src.getAgent())
151      tgt.addAgent(convertProvenanceAgentComponent(t));
152    return tgt;
153  }
154
155  static public org.hl7.fhir.r5.model.Enumeration<org.hl7.fhir.r5.model.Provenance.ProvenanceEntityRole> convertProvenanceEntityRole(org.hl7.fhir.dstu3.model.Enumeration<org.hl7.fhir.dstu3.model.Provenance.ProvenanceEntityRole> src) throws FHIRException {
156    if (src == null || src.isEmpty())
157      return null;
158    org.hl7.fhir.r5.model.Enumeration<org.hl7.fhir.r5.model.Provenance.ProvenanceEntityRole> tgt = new org.hl7.fhir.r5.model.Enumeration<>(new org.hl7.fhir.r5.model.Provenance.ProvenanceEntityRoleEnumFactory());
159    ConversionContext30_50.INSTANCE.getVersionConvertor_30_50().copyElement(src, tgt);
160    switch (src.getValue()) {
161      case DERIVATION:
162        tgt.setValue(org.hl7.fhir.r5.model.Provenance.ProvenanceEntityRole.INSTANTIATES);
163        break;
164      case REVISION:
165        tgt.setValue(org.hl7.fhir.r5.model.Provenance.ProvenanceEntityRole.REVISION);
166        break;
167      case QUOTATION:
168        tgt.setValue(org.hl7.fhir.r5.model.Provenance.ProvenanceEntityRole.QUOTATION);
169        break;
170      case SOURCE:
171        tgt.setValue(org.hl7.fhir.r5.model.Provenance.ProvenanceEntityRole.SOURCE);
172        break;
173      case REMOVAL:
174        tgt.setValue(org.hl7.fhir.r5.model.Provenance.ProvenanceEntityRole.REMOVAL);
175        break;
176      default:
177        tgt.setValue(org.hl7.fhir.r5.model.Provenance.ProvenanceEntityRole.NULL);
178        break;
179    }
180    return tgt;
181  }
182
183  static public org.hl7.fhir.dstu3.model.Enumeration<org.hl7.fhir.dstu3.model.Provenance.ProvenanceEntityRole> convertProvenanceEntityRole(org.hl7.fhir.r5.model.Enumeration<org.hl7.fhir.r5.model.Provenance.ProvenanceEntityRole> src) throws FHIRException {
184    if (src == null || src.isEmpty())
185      return null;
186    org.hl7.fhir.dstu3.model.Enumeration<org.hl7.fhir.dstu3.model.Provenance.ProvenanceEntityRole> tgt = new org.hl7.fhir.dstu3.model.Enumeration<>(new org.hl7.fhir.dstu3.model.Provenance.ProvenanceEntityRoleEnumFactory());
187    ConversionContext30_50.INSTANCE.getVersionConvertor_30_50().copyElement(src, tgt);
188    switch (src.getValue()) {
189      case INSTANTIATES:
190        tgt.setValue(org.hl7.fhir.dstu3.model.Provenance.ProvenanceEntityRole.DERIVATION);
191        break;
192      case REVISION:
193        tgt.setValue(org.hl7.fhir.dstu3.model.Provenance.ProvenanceEntityRole.REVISION);
194        break;
195      case QUOTATION:
196        tgt.setValue(org.hl7.fhir.dstu3.model.Provenance.ProvenanceEntityRole.QUOTATION);
197        break;
198      case SOURCE:
199        tgt.setValue(org.hl7.fhir.dstu3.model.Provenance.ProvenanceEntityRole.SOURCE);
200        break;
201      case REMOVAL:
202        tgt.setValue(org.hl7.fhir.dstu3.model.Provenance.ProvenanceEntityRole.REMOVAL);
203        break;
204      default:
205        tgt.setValue(org.hl7.fhir.dstu3.model.Provenance.ProvenanceEntityRole.NULL);
206        break;
207    }
208    return tgt;
209  }
210}