001package org.hl7.fhir.convertors.conv10_30.resources10_30;
002
003import org.hl7.fhir.convertors.context.ConversionContext10_30;
004import org.hl7.fhir.convertors.conv10_30.datatypes10_30.Reference10_30;
005import org.hl7.fhir.convertors.conv10_30.datatypes10_30.complextypes10_30.Annotation10_30;
006import org.hl7.fhir.convertors.conv10_30.datatypes10_30.complextypes10_30.CodeableConcept10_30;
007import org.hl7.fhir.convertors.conv10_30.datatypes10_30.complextypes10_30.Identifier10_30;
008import org.hl7.fhir.convertors.conv10_30.datatypes10_30.primitivetypes10_30.Boolean10_30;
009import org.hl7.fhir.exceptions.FHIRException;
010
011public class Procedure10_30 {
012
013  public static org.hl7.fhir.dstu2.model.Procedure convertProcedure(org.hl7.fhir.dstu3.model.Procedure src) throws FHIRException {
014    if (src == null || src.isEmpty())
015      return null;
016    org.hl7.fhir.dstu2.model.Procedure tgt = new org.hl7.fhir.dstu2.model.Procedure();
017    ConversionContext10_30.INSTANCE.getVersionConvertor_10_30().copyDomainResource(src, tgt);
018    for (org.hl7.fhir.dstu3.model.Identifier t : src.getIdentifier())
019      tgt.addIdentifier(Identifier10_30.convertIdentifier(t));
020    if (src.hasSubject())
021      tgt.setSubject(Reference10_30.convertReference(src.getSubject()));
022    if (src.hasStatus())
023      tgt.setStatusElement(convertProcedureStatus(src.getStatusElement()));
024    if (src.hasCategory())
025      tgt.setCategory(CodeableConcept10_30.convertCodeableConcept(src.getCategory()));
026    if (src.hasCode())
027      tgt.setCode(CodeableConcept10_30.convertCodeableConcept(src.getCode()));
028    if (src.hasNotDoneElement())
029      tgt.setNotPerformedElement(Boolean10_30.convertBoolean(src.getNotDoneElement()));
030    if (src.hasNotDoneReason())
031      tgt.addReasonNotPerformed(CodeableConcept10_30.convertCodeableConcept(src.getNotDoneReason()));
032    for (org.hl7.fhir.dstu3.model.CodeableConcept t : src.getBodySite())
033      tgt.addBodySite(CodeableConcept10_30.convertCodeableConcept(t));
034    if (src.hasReasonCode())
035      tgt.setReason(ConversionContext10_30.INSTANCE.getVersionConvertor_10_30().convertType(src.getReasonCodeFirstRep()));
036    for (org.hl7.fhir.dstu3.model.Procedure.ProcedurePerformerComponent t : src.getPerformer())
037      tgt.addPerformer(convertProcedurePerformerComponent(t));
038    if (src.hasPerformed())
039      tgt.setPerformed(ConversionContext10_30.INSTANCE.getVersionConvertor_10_30().convertType(src.getPerformed()));
040    if (src.hasContext())
041      tgt.setEncounter(Reference10_30.convertReference(src.getContext()));
042    if (src.hasLocation())
043      tgt.setLocation(Reference10_30.convertReference(src.getLocation()));
044    if (src.hasOutcome())
045      tgt.setOutcome(CodeableConcept10_30.convertCodeableConcept(src.getOutcome()));
046    for (org.hl7.fhir.dstu3.model.Reference t : src.getReport()) tgt.addReport(Reference10_30.convertReference(t));
047    for (org.hl7.fhir.dstu3.model.CodeableConcept t : src.getComplication())
048      tgt.addComplication(CodeableConcept10_30.convertCodeableConcept(t));
049    for (org.hl7.fhir.dstu3.model.CodeableConcept t : src.getFollowUp())
050      tgt.addFollowUp(CodeableConcept10_30.convertCodeableConcept(t));
051    if (src.hasBasedOn())
052      tgt.setRequest(Reference10_30.convertReference(src.getBasedOnFirstRep()));
053    for (org.hl7.fhir.dstu3.model.Procedure.ProcedureFocalDeviceComponent t : src.getFocalDevice())
054      tgt.addFocalDevice(convertProcedureFocalDeviceComponent(t));
055    for (org.hl7.fhir.dstu3.model.Annotation note : src.getNote())
056      tgt.addNotes(Annotation10_30.convertAnnotation(note));
057    for (org.hl7.fhir.dstu3.model.Reference r : src.getUsedReference()) tgt.addUsed(Reference10_30.convertReference(r));
058    return tgt;
059  }
060
061  public static org.hl7.fhir.dstu3.model.Procedure convertProcedure(org.hl7.fhir.dstu2.model.Procedure src) throws FHIRException {
062    if (src == null || src.isEmpty())
063      return null;
064    org.hl7.fhir.dstu3.model.Procedure tgt = new org.hl7.fhir.dstu3.model.Procedure();
065    ConversionContext10_30.INSTANCE.getVersionConvertor_10_30().copyDomainResource(src, tgt);
066    for (org.hl7.fhir.dstu2.model.Identifier t : src.getIdentifier())
067      tgt.addIdentifier(Identifier10_30.convertIdentifier(t));
068    if (src.hasSubject())
069      tgt.setSubject(Reference10_30.convertReference(src.getSubject()));
070    if (src.hasStatus())
071      tgt.setStatusElement(convertProcedureStatus(src.getStatusElement()));
072    if (src.hasCategory())
073      tgt.setCategory(CodeableConcept10_30.convertCodeableConcept(src.getCategory()));
074    if (src.hasCode())
075      tgt.setCode(CodeableConcept10_30.convertCodeableConcept(src.getCode()));
076    if (src.hasNotPerformedElement())
077      tgt.setNotDoneElement(Boolean10_30.convertBoolean(src.getNotPerformedElement()));
078    if (src.hasReasonNotPerformed())
079      tgt.setNotDoneReason(CodeableConcept10_30.convertCodeableConcept(src.getReasonNotPerformed().get(0)));
080    for (org.hl7.fhir.dstu2.model.CodeableConcept t : src.getBodySite())
081      tgt.addBodySite(CodeableConcept10_30.convertCodeableConcept(t));
082    if (src.hasReasonCodeableConcept())
083      tgt.addReasonCode(CodeableConcept10_30.convertCodeableConcept(src.getReasonCodeableConcept()));
084    for (org.hl7.fhir.dstu2.model.Procedure.ProcedurePerformerComponent t : src.getPerformer())
085      tgt.addPerformer(convertProcedurePerformerComponent(t));
086    if (src.hasPerformed())
087      tgt.setPerformed(ConversionContext10_30.INSTANCE.getVersionConvertor_10_30().convertType(src.getPerformed()));
088    if (src.hasEncounter())
089      tgt.setContext(Reference10_30.convertReference(src.getEncounter()));
090    if (src.hasLocation())
091      tgt.setLocation(Reference10_30.convertReference(src.getLocation()));
092    if (src.hasOutcome())
093      tgt.setOutcome(CodeableConcept10_30.convertCodeableConcept(src.getOutcome()));
094    for (org.hl7.fhir.dstu2.model.Reference t : src.getReport()) tgt.addReport(Reference10_30.convertReference(t));
095    for (org.hl7.fhir.dstu2.model.CodeableConcept t : src.getComplication())
096      tgt.addComplication(CodeableConcept10_30.convertCodeableConcept(t));
097    for (org.hl7.fhir.dstu2.model.CodeableConcept t : src.getFollowUp())
098      tgt.addFollowUp(CodeableConcept10_30.convertCodeableConcept(t));
099    if (src.hasRequest())
100      tgt.addBasedOn(Reference10_30.convertReference(src.getRequest()));
101    for (org.hl7.fhir.dstu2.model.Procedure.ProcedureFocalDeviceComponent t : src.getFocalDevice())
102      tgt.addFocalDevice(convertProcedureFocalDeviceComponent(t));
103    for (org.hl7.fhir.dstu2.model.Annotation note : src.getNotes())
104      tgt.addNote(Annotation10_30.convertAnnotation(note));
105    for (org.hl7.fhir.dstu2.model.Reference r : src.getUsed()) tgt.addUsedReference(Reference10_30.convertReference(r));
106    return tgt;
107  }
108
109  public static org.hl7.fhir.dstu3.model.Procedure.ProcedureFocalDeviceComponent convertProcedureFocalDeviceComponent(org.hl7.fhir.dstu2.model.Procedure.ProcedureFocalDeviceComponent src) throws FHIRException {
110    if (src == null || src.isEmpty())
111      return null;
112    org.hl7.fhir.dstu3.model.Procedure.ProcedureFocalDeviceComponent tgt = new org.hl7.fhir.dstu3.model.Procedure.ProcedureFocalDeviceComponent();
113    ConversionContext10_30.INSTANCE.getVersionConvertor_10_30().copyBackboneElement(src,tgt);
114    if (src.hasAction())
115      tgt.setAction(CodeableConcept10_30.convertCodeableConcept(src.getAction()));
116    if (src.hasManipulated())
117      tgt.setManipulated(Reference10_30.convertReference(src.getManipulated()));
118    return tgt;
119  }
120
121  public static org.hl7.fhir.dstu2.model.Procedure.ProcedureFocalDeviceComponent convertProcedureFocalDeviceComponent(org.hl7.fhir.dstu3.model.Procedure.ProcedureFocalDeviceComponent src) throws FHIRException {
122    if (src == null || src.isEmpty())
123      return null;
124    org.hl7.fhir.dstu2.model.Procedure.ProcedureFocalDeviceComponent tgt = new org.hl7.fhir.dstu2.model.Procedure.ProcedureFocalDeviceComponent();
125    ConversionContext10_30.INSTANCE.getVersionConvertor_10_30().copyBackboneElement(src,tgt);
126    if (src.hasAction())
127      tgt.setAction(CodeableConcept10_30.convertCodeableConcept(src.getAction()));
128    if (src.hasManipulated())
129      tgt.setManipulated(Reference10_30.convertReference(src.getManipulated()));
130    return tgt;
131  }
132
133  public static org.hl7.fhir.dstu2.model.Procedure.ProcedurePerformerComponent convertProcedurePerformerComponent(org.hl7.fhir.dstu3.model.Procedure.ProcedurePerformerComponent src) throws FHIRException {
134    if (src == null || src.isEmpty())
135      return null;
136    org.hl7.fhir.dstu2.model.Procedure.ProcedurePerformerComponent tgt = new org.hl7.fhir.dstu2.model.Procedure.ProcedurePerformerComponent();
137    ConversionContext10_30.INSTANCE.getVersionConvertor_10_30().copyBackboneElement(src,tgt);
138    if (src.hasActor())
139      tgt.setActor(Reference10_30.convertReference(src.getActor()));
140    if (src.hasRole())
141      tgt.setRole(CodeableConcept10_30.convertCodeableConcept(src.getRole()));
142    return tgt;
143  }
144
145  public static org.hl7.fhir.dstu3.model.Procedure.ProcedurePerformerComponent convertProcedurePerformerComponent(org.hl7.fhir.dstu2.model.Procedure.ProcedurePerformerComponent src) throws FHIRException {
146    if (src == null || src.isEmpty())
147      return null;
148    org.hl7.fhir.dstu3.model.Procedure.ProcedurePerformerComponent tgt = new org.hl7.fhir.dstu3.model.Procedure.ProcedurePerformerComponent();
149    ConversionContext10_30.INSTANCE.getVersionConvertor_10_30().copyBackboneElement(src,tgt);
150    if (src.hasActor())
151      tgt.setActor(Reference10_30.convertReference(src.getActor()));
152    if (src.hasRole())
153      tgt.setRole(CodeableConcept10_30.convertCodeableConcept(src.getRole()));
154    return tgt;
155  }
156
157  static public org.hl7.fhir.dstu3.model.Enumeration<org.hl7.fhir.dstu3.model.Procedure.ProcedureStatus> convertProcedureStatus(org.hl7.fhir.dstu2.model.Enumeration<org.hl7.fhir.dstu2.model.Procedure.ProcedureStatus> src) throws FHIRException {
158    if (src == null || src.isEmpty())
159      return null;
160    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());
161    ConversionContext10_30.INSTANCE.getVersionConvertor_10_30().copyElement(src, tgt);
162    switch (src.getValue()) {
163      case INPROGRESS:
164        tgt.setValue(org.hl7.fhir.dstu3.model.Procedure.ProcedureStatus.INPROGRESS);
165        break;
166      case ABORTED:
167        tgt.setValue(org.hl7.fhir.dstu3.model.Procedure.ProcedureStatus.ABORTED);
168        break;
169      case COMPLETED:
170        tgt.setValue(org.hl7.fhir.dstu3.model.Procedure.ProcedureStatus.COMPLETED);
171        break;
172      case ENTEREDINERROR:
173        tgt.setValue(org.hl7.fhir.dstu3.model.Procedure.ProcedureStatus.ENTEREDINERROR);
174        break;
175      default:
176        tgt.setValue(org.hl7.fhir.dstu3.model.Procedure.ProcedureStatus.NULL);
177        break;
178    }
179    return tgt;
180  }
181
182  static public org.hl7.fhir.dstu2.model.Enumeration<org.hl7.fhir.dstu2.model.Procedure.ProcedureStatus> convertProcedureStatus(org.hl7.fhir.dstu3.model.Enumeration<org.hl7.fhir.dstu3.model.Procedure.ProcedureStatus> src) throws FHIRException {
183    if (src == null || src.isEmpty())
184      return null;
185    org.hl7.fhir.dstu2.model.Enumeration<org.hl7.fhir.dstu2.model.Procedure.ProcedureStatus> tgt = new org.hl7.fhir.dstu2.model.Enumeration<>(new org.hl7.fhir.dstu2.model.Procedure.ProcedureStatusEnumFactory());
186    ConversionContext10_30.INSTANCE.getVersionConvertor_10_30().copyElement(src, tgt);
187    switch (src.getValue()) {
188      case INPROGRESS:
189        tgt.setValue(org.hl7.fhir.dstu2.model.Procedure.ProcedureStatus.INPROGRESS);
190        break;
191      case ABORTED:
192        tgt.setValue(org.hl7.fhir.dstu2.model.Procedure.ProcedureStatus.ABORTED);
193        break;
194      case COMPLETED:
195        tgt.setValue(org.hl7.fhir.dstu2.model.Procedure.ProcedureStatus.COMPLETED);
196        break;
197      case ENTEREDINERROR:
198        tgt.setValue(org.hl7.fhir.dstu2.model.Procedure.ProcedureStatus.ENTEREDINERROR);
199        break;
200      default:
201        tgt.setValue(org.hl7.fhir.dstu2.model.Procedure.ProcedureStatus.NULL);
202        break;
203    }
204    return tgt;
205  }
206}