001package org.hl7.fhir.convertors.conv30_40.resources30_40;
002
003import org.hl7.fhir.convertors.context.ConversionContext30_40;
004import org.hl7.fhir.convertors.conv30_40.datatypes30_40.Reference30_40;
005import org.hl7.fhir.convertors.conv30_40.datatypes30_40.complextypes30_40.Annotation30_40;
006import org.hl7.fhir.convertors.conv30_40.datatypes30_40.complextypes30_40.CodeableConcept30_40;
007import org.hl7.fhir.convertors.conv30_40.datatypes30_40.complextypes30_40.Identifier30_40;
008import org.hl7.fhir.exceptions.FHIRException;
009
010public class Procedure30_40 {
011
012  static public org.hl7.fhir.r4.model.Procedure convertProcedure(org.hl7.fhir.dstu3.model.Procedure src) throws FHIRException {
013    if (src == null)
014      return null;
015    org.hl7.fhir.r4.model.Procedure tgt = new org.hl7.fhir.r4.model.Procedure();
016    ConversionContext30_40.INSTANCE.getVersionConvertor_30_40().copyDomainResource(src, tgt);
017    for (org.hl7.fhir.dstu3.model.Identifier t : src.getIdentifier()) {
018      tgt.addIdentifier(Identifier30_40.convertIdentifier(t));
019    }
020    for (org.hl7.fhir.dstu3.model.Reference t : src.getBasedOn()) {
021      tgt.addBasedOn(Reference30_40.convertReference(t));
022    }
023    for (org.hl7.fhir.dstu3.model.Reference t : src.getPartOf()) {
024      tgt.addPartOf(Reference30_40.convertReference(t));
025    }
026    if (src.getNotDone()) {
027      tgt.setStatus(org.hl7.fhir.r4.model.Procedure.ProcedureStatus.NOTDONE);
028    } else {
029      if (src.hasStatus())
030        tgt.setStatusElement(convertProcedureStatus(src.getStatusElement()));
031    }
032    if (src.hasNotDoneReason()) {
033      if (src.hasNotDoneReason())
034        tgt.setStatusReason(CodeableConcept30_40.convertCodeableConcept(src.getNotDoneReason()));
035    }
036    if (src.hasCategory()) {
037      if (src.hasCategory())
038        tgt.setCategory(CodeableConcept30_40.convertCodeableConcept(src.getCategory()));
039    }
040    if (src.hasCode()) {
041      if (src.hasCode())
042        tgt.setCode(CodeableConcept30_40.convertCodeableConcept(src.getCode()));
043    }
044    if (src.hasSubject()) {
045      if (src.hasSubject())
046        tgt.setSubject(Reference30_40.convertReference(src.getSubject()));
047    }
048    if (src.hasContext()) {
049      if (src.hasContext())
050        tgt.setEncounter(Reference30_40.convertReference(src.getContext()));
051    }
052    if (src.hasPerformed()) {
053      if (src.hasPerformed())
054        tgt.setPerformed(ConversionContext30_40.INSTANCE.getVersionConvertor_30_40().convertType(src.getPerformed()));
055    }
056    for (org.hl7.fhir.dstu3.model.Procedure.ProcedurePerformerComponent t : src.getPerformer()) {
057      tgt.addPerformer(convertProcedurePerformerComponent(t));
058    }
059    if (src.hasLocation()) {
060      if (src.hasLocation())
061        tgt.setLocation(Reference30_40.convertReference(src.getLocation()));
062    }
063    for (org.hl7.fhir.dstu3.model.CodeableConcept t : src.getReasonCode()) {
064      tgt.addReasonCode(CodeableConcept30_40.convertCodeableConcept(t));
065    }
066    for (org.hl7.fhir.dstu3.model.Reference t : src.getReasonReference()) {
067      tgt.addReasonReference(Reference30_40.convertReference(t));
068    }
069    for (org.hl7.fhir.dstu3.model.CodeableConcept t : src.getBodySite()) {
070      tgt.addBodySite(CodeableConcept30_40.convertCodeableConcept(t));
071    }
072    if (src.hasOutcome()) {
073      if (src.hasOutcome())
074        tgt.setOutcome(CodeableConcept30_40.convertCodeableConcept(src.getOutcome()));
075    }
076    for (org.hl7.fhir.dstu3.model.Reference t : src.getReport()) {
077      tgt.addReport(Reference30_40.convertReference(t));
078    }
079    for (org.hl7.fhir.dstu3.model.CodeableConcept t : src.getComplication()) {
080      tgt.addComplication(CodeableConcept30_40.convertCodeableConcept(t));
081    }
082    for (org.hl7.fhir.dstu3.model.Reference t : src.getComplicationDetail()) {
083      tgt.addComplicationDetail(Reference30_40.convertReference(t));
084    }
085    for (org.hl7.fhir.dstu3.model.CodeableConcept t : src.getFollowUp()) {
086      tgt.addFollowUp(CodeableConcept30_40.convertCodeableConcept(t));
087    }
088    for (org.hl7.fhir.dstu3.model.Annotation t : src.getNote()) {
089      tgt.addNote(Annotation30_40.convertAnnotation(t));
090    }
091    for (org.hl7.fhir.dstu3.model.Procedure.ProcedureFocalDeviceComponent t : src.getFocalDevice()) {
092      tgt.addFocalDevice(convertProcedureFocalDeviceComponent(t));
093    }
094    for (org.hl7.fhir.dstu3.model.Reference t : src.getUsedReference()) {
095      tgt.addUsedReference(Reference30_40.convertReference(t));
096    }
097    for (org.hl7.fhir.dstu3.model.CodeableConcept t : src.getUsedCode()) {
098      tgt.addUsedCode(CodeableConcept30_40.convertCodeableConcept(t));
099    }
100    return tgt;
101  }
102
103  static public org.hl7.fhir.dstu3.model.Procedure convertProcedure(org.hl7.fhir.r4.model.Procedure src) throws FHIRException {
104    if (src == null)
105      return null;
106    org.hl7.fhir.dstu3.model.Procedure tgt = new org.hl7.fhir.dstu3.model.Procedure();
107    ConversionContext30_40.INSTANCE.getVersionConvertor_30_40().copyDomainResource(src, tgt);
108    for (org.hl7.fhir.r4.model.Identifier t : src.getIdentifier()) {
109      tgt.addIdentifier(Identifier30_40.convertIdentifier(t));
110    }
111    for (org.hl7.fhir.r4.model.Reference t : src.getBasedOn()) {
112      tgt.addBasedOn(Reference30_40.convertReference(t));
113    }
114    for (org.hl7.fhir.r4.model.Reference t : src.getPartOf()) {
115      tgt.addPartOf(Reference30_40.convertReference(t));
116    }
117    if (src.hasStatus()) {
118      org.hl7.fhir.r4.model.Procedure.ProcedureStatus status = src.getStatus();
119      if (org.hl7.fhir.r4.model.Procedure.ProcedureStatus.NOTDONE.equals(status)) {
120        tgt.setStatus(org.hl7.fhir.dstu3.model.Procedure.ProcedureStatus.SUSPENDED);
121        tgt.setNotDone(true);
122        if (src.hasStatusReason())
123          tgt.setNotDoneReason(CodeableConcept30_40.convertCodeableConcept(src.getStatusReason()));
124      } else {
125        if (src.hasStatus())
126          tgt.setStatusElement(convertProcedureStatus(src.getStatusElement()));
127        tgt.setNotDone(false);
128      }
129    }
130    if (src.hasCategory()) {
131      if (src.hasCategory())
132        tgt.setCategory(CodeableConcept30_40.convertCodeableConcept(src.getCategory()));
133    }
134    if (src.hasCode()) {
135      if (src.hasCode())
136        tgt.setCode(CodeableConcept30_40.convertCodeableConcept(src.getCode()));
137    }
138    if (src.hasSubject()) {
139      if (src.hasSubject())
140        tgt.setSubject(Reference30_40.convertReference(src.getSubject()));
141    }
142    if (src.hasEncounter()) {
143      if (src.hasEncounter())
144        tgt.setContext(Reference30_40.convertReference(src.getEncounter()));
145    }
146    if (src.hasPerformed()) {
147      if (src.hasPerformed())
148        tgt.setPerformed(ConversionContext30_40.INSTANCE.getVersionConvertor_30_40().convertType(src.getPerformed()));
149    }
150    for (org.hl7.fhir.r4.model.Procedure.ProcedurePerformerComponent t : src.getPerformer()) {
151      tgt.addPerformer(convertProcedurePerformerComponent(t));
152    }
153    if (src.hasLocation()) {
154      if (src.hasLocation())
155        tgt.setLocation(Reference30_40.convertReference(src.getLocation()));
156    }
157    for (org.hl7.fhir.r4.model.CodeableConcept t : src.getReasonCode()) {
158      tgt.addReasonCode(CodeableConcept30_40.convertCodeableConcept(t));
159    }
160    for (org.hl7.fhir.r4.model.Reference t : src.getReasonReference()) {
161      tgt.addReasonReference(Reference30_40.convertReference(t));
162    }
163    for (org.hl7.fhir.r4.model.CodeableConcept t : src.getBodySite()) {
164      tgt.addBodySite(CodeableConcept30_40.convertCodeableConcept(t));
165    }
166    if (src.hasOutcome()) {
167      if (src.hasOutcome())
168        tgt.setOutcome(CodeableConcept30_40.convertCodeableConcept(src.getOutcome()));
169    }
170    for (org.hl7.fhir.r4.model.Reference t : src.getReport()) {
171      tgt.addReport(Reference30_40.convertReference(t));
172    }
173    for (org.hl7.fhir.r4.model.CodeableConcept t : src.getComplication()) {
174      tgt.addComplication(CodeableConcept30_40.convertCodeableConcept(t));
175    }
176    for (org.hl7.fhir.r4.model.Reference t : src.getComplicationDetail()) {
177      tgt.addComplicationDetail(Reference30_40.convertReference(t));
178    }
179    for (org.hl7.fhir.r4.model.CodeableConcept t : src.getFollowUp()) {
180      tgt.addFollowUp(CodeableConcept30_40.convertCodeableConcept(t));
181    }
182    for (org.hl7.fhir.r4.model.Annotation t : src.getNote()) {
183      tgt.addNote(Annotation30_40.convertAnnotation(t));
184    }
185    for (org.hl7.fhir.r4.model.Procedure.ProcedureFocalDeviceComponent t : src.getFocalDevice()) {
186      tgt.addFocalDevice(convertProcedureFocalDeviceComponent(t));
187    }
188    for (org.hl7.fhir.r4.model.Reference t : src.getUsedReference()) {
189      tgt.addUsedReference(Reference30_40.convertReference(t));
190    }
191    for (org.hl7.fhir.r4.model.CodeableConcept t : src.getUsedCode()) {
192      tgt.addUsedCode(CodeableConcept30_40.convertCodeableConcept(t));
193    }
194    return tgt;
195  }
196
197  static public org.hl7.fhir.dstu3.model.Procedure.ProcedureFocalDeviceComponent convertProcedureFocalDeviceComponent(org.hl7.fhir.r4.model.Procedure.ProcedureFocalDeviceComponent src) throws FHIRException {
198    if (src == null)
199      return null;
200    org.hl7.fhir.dstu3.model.Procedure.ProcedureFocalDeviceComponent tgt = new org.hl7.fhir.dstu3.model.Procedure.ProcedureFocalDeviceComponent();
201    ConversionContext30_40.INSTANCE.getVersionConvertor_30_40().copyBackboneElement(src,tgt);
202    if (src.hasAction()) {
203      if (src.hasAction())
204        tgt.setAction(CodeableConcept30_40.convertCodeableConcept(src.getAction()));
205    }
206    if (src.hasManipulated()) {
207      if (src.hasManipulated())
208        tgt.setManipulated(Reference30_40.convertReference(src.getManipulated()));
209    }
210    return tgt;
211  }
212
213  static public org.hl7.fhir.r4.model.Procedure.ProcedureFocalDeviceComponent convertProcedureFocalDeviceComponent(org.hl7.fhir.dstu3.model.Procedure.ProcedureFocalDeviceComponent src) throws FHIRException {
214    if (src == null)
215      return null;
216    org.hl7.fhir.r4.model.Procedure.ProcedureFocalDeviceComponent tgt = new org.hl7.fhir.r4.model.Procedure.ProcedureFocalDeviceComponent();
217    ConversionContext30_40.INSTANCE.getVersionConvertor_30_40().copyBackboneElement(src,tgt);
218    if (src.hasAction()) {
219      if (src.hasAction())
220        tgt.setAction(CodeableConcept30_40.convertCodeableConcept(src.getAction()));
221    }
222    if (src.hasManipulated()) {
223      if (src.hasManipulated())
224        tgt.setManipulated(Reference30_40.convertReference(src.getManipulated()));
225    }
226    return tgt;
227  }
228
229  static public org.hl7.fhir.r4.model.Procedure.ProcedurePerformerComponent convertProcedurePerformerComponent(org.hl7.fhir.dstu3.model.Procedure.ProcedurePerformerComponent src) throws FHIRException {
230    if (src == null)
231      return null;
232    org.hl7.fhir.r4.model.Procedure.ProcedurePerformerComponent tgt = new org.hl7.fhir.r4.model.Procedure.ProcedurePerformerComponent();
233    ConversionContext30_40.INSTANCE.getVersionConvertor_30_40().copyBackboneElement(src,tgt);
234    if (src.hasRole()) {
235      if (src.hasRole())
236        tgt.setFunction(CodeableConcept30_40.convertCodeableConcept(src.getRole()));
237    }
238    if (src.hasActor()) {
239      if (src.hasActor())
240        tgt.setActor(Reference30_40.convertReference(src.getActor()));
241    }
242    if (src.hasOnBehalfOf()) {
243      if (src.hasOnBehalfOf())
244        tgt.setOnBehalfOf(Reference30_40.convertReference(src.getOnBehalfOf()));
245    }
246    return tgt;
247  }
248
249  static public org.hl7.fhir.dstu3.model.Procedure.ProcedurePerformerComponent convertProcedurePerformerComponent(org.hl7.fhir.r4.model.Procedure.ProcedurePerformerComponent src) throws FHIRException {
250    if (src == null)
251      return null;
252    org.hl7.fhir.dstu3.model.Procedure.ProcedurePerformerComponent tgt = new org.hl7.fhir.dstu3.model.Procedure.ProcedurePerformerComponent();
253    ConversionContext30_40.INSTANCE.getVersionConvertor_30_40().copyBackboneElement(src,tgt);
254    if (src.hasFunction()) {
255      if (src.hasFunction())
256        tgt.setRole(CodeableConcept30_40.convertCodeableConcept(src.getFunction()));
257    }
258    if (src.hasActor()) {
259      if (src.hasActor())
260        tgt.setActor(Reference30_40.convertReference(src.getActor()));
261    }
262    if (src.hasOnBehalfOf()) {
263      if (src.hasOnBehalfOf())
264        tgt.setOnBehalfOf(Reference30_40.convertReference(src.getOnBehalfOf()));
265    }
266    return tgt;
267  }
268
269  static public org.hl7.fhir.r4.model.Enumeration<org.hl7.fhir.r4.model.Procedure.ProcedureStatus> convertProcedureStatus(org.hl7.fhir.dstu3.model.Enumeration<org.hl7.fhir.dstu3.model.Procedure.ProcedureStatus> src) throws FHIRException {
270    if (src == null || src.isEmpty())
271      return null;
272    org.hl7.fhir.r4.model.Enumeration<org.hl7.fhir.r4.model.Procedure.ProcedureStatus> tgt = new org.hl7.fhir.r4.model.Enumeration<>(new org.hl7.fhir.r4.model.Procedure.ProcedureStatusEnumFactory());
273    ConversionContext30_40.INSTANCE.getVersionConvertor_30_40().copyElement(src, tgt);
274    switch (src.getValue()) {
275      case PREPARATION:
276        tgt.setValue(org.hl7.fhir.r4.model.Procedure.ProcedureStatus.PREPARATION);
277        break;
278      case INPROGRESS:
279        tgt.setValue(org.hl7.fhir.r4.model.Procedure.ProcedureStatus.INPROGRESS);
280        break;
281      case SUSPENDED:
282        tgt.setValue(org.hl7.fhir.r4.model.Procedure.ProcedureStatus.ONHOLD);
283        break;
284      case ABORTED:
285        tgt.setValue(org.hl7.fhir.r4.model.Procedure.ProcedureStatus.STOPPED);
286        break;
287      case COMPLETED:
288        tgt.setValue(org.hl7.fhir.r4.model.Procedure.ProcedureStatus.COMPLETED);
289        break;
290      case ENTEREDINERROR:
291        tgt.setValue(org.hl7.fhir.r4.model.Procedure.ProcedureStatus.ENTEREDINERROR);
292        break;
293      case UNKNOWN:
294        tgt.setValue(org.hl7.fhir.r4.model.Procedure.ProcedureStatus.UNKNOWN);
295        break;
296      default:
297        tgt.setValue(org.hl7.fhir.r4.model.Procedure.ProcedureStatus.NULL);
298        break;
299    }
300    return tgt;
301  }
302
303  static public org.hl7.fhir.dstu3.model.Enumeration<org.hl7.fhir.dstu3.model.Procedure.ProcedureStatus> convertProcedureStatus(org.hl7.fhir.r4.model.Enumeration<org.hl7.fhir.r4.model.Procedure.ProcedureStatus> src) throws FHIRException {
304    if (src == null || src.isEmpty())
305      return null;
306    org.hl7.fhir.dstu3.model.Enumeration<org.hl7.fhir.dstu3.model.Procedure.ProcedureStatus> tgt = new org.hl7.fhir.dstu3.model.Enumeration<>(new org.hl7.fhir.dstu3.model.Procedure.ProcedureStatusEnumFactory());
307    ConversionContext30_40.INSTANCE.getVersionConvertor_30_40().copyElement(src, tgt);
308    switch (src.getValue()) {
309      case PREPARATION:
310        tgt.setValue(org.hl7.fhir.dstu3.model.Procedure.ProcedureStatus.PREPARATION);
311        break;
312      case INPROGRESS:
313        tgt.setValue(org.hl7.fhir.dstu3.model.Procedure.ProcedureStatus.INPROGRESS);
314        break;
315      case ONHOLD:
316        tgt.setValue(org.hl7.fhir.dstu3.model.Procedure.ProcedureStatus.SUSPENDED);
317        break;
318      case STOPPED:
319        tgt.setValue(org.hl7.fhir.dstu3.model.Procedure.ProcedureStatus.ABORTED);
320        break;
321      case COMPLETED:
322        tgt.setValue(org.hl7.fhir.dstu3.model.Procedure.ProcedureStatus.COMPLETED);
323        break;
324      case ENTEREDINERROR:
325        tgt.setValue(org.hl7.fhir.dstu3.model.Procedure.ProcedureStatus.ENTEREDINERROR);
326        break;
327      case UNKNOWN:
328        tgt.setValue(org.hl7.fhir.dstu3.model.Procedure.ProcedureStatus.UNKNOWN);
329        break;
330      default:
331        tgt.setValue(org.hl7.fhir.dstu3.model.Procedure.ProcedureStatus.NULL);
332        break;
333    }
334    return tgt;
335  }
336}