001package org.hl7.fhir.convertors.conv10_40.resources10_40;
002
003import org.hl7.fhir.convertors.context.ConversionContext10_40;
004import org.hl7.fhir.convertors.conv10_40.datatypes10_40.Reference10_40;
005import org.hl7.fhir.convertors.conv10_40.datatypes10_40.complextypes10_40.Annotation10_40;
006import org.hl7.fhir.convertors.conv10_40.datatypes10_40.complextypes10_40.CodeableConcept10_40;
007import org.hl7.fhir.convertors.conv10_40.datatypes10_40.complextypes10_40.Identifier10_40;
008import org.hl7.fhir.convertors.conv10_40.datatypes10_40.complextypes10_40.Period10_40;
009import org.hl7.fhir.convertors.conv10_40.datatypes10_40.complextypes10_40.SimpleQuantity10_40;
010import org.hl7.fhir.convertors.conv10_40.datatypes10_40.primitivetypes10_40.Boolean10_40;
011import org.hl7.fhir.convertors.conv10_40.datatypes10_40.primitivetypes10_40.String10_40;
012import org.hl7.fhir.exceptions.FHIRException;
013
014public class CarePlan10_40 {
015
016  public static org.hl7.fhir.r4.model.CarePlan convertCarePlan(org.hl7.fhir.dstu2.model.CarePlan src) throws FHIRException {
017    if (src == null || src.isEmpty())
018      return null;
019    org.hl7.fhir.r4.model.CarePlan tgt = new org.hl7.fhir.r4.model.CarePlan();
020    ConversionContext10_40.INSTANCE.getVersionConvertor_10_40().copyDomainResource(src, tgt);
021    for (org.hl7.fhir.dstu2.model.Identifier t : src.getIdentifier())
022      tgt.addIdentifier(Identifier10_40.convertIdentifier(t));
023    if (src.hasSubject())
024      tgt.setSubject(Reference10_40.convertReference(src.getSubject()));
025    if (src.hasStatus())
026      tgt.setStatusElement(convertCarePlanStatus(src.getStatusElement()));
027    if (src.hasContext())
028      tgt.setEncounter(Reference10_40.convertReference(src.getContext()));
029    if (src.hasPeriod())
030      tgt.setPeriod(Period10_40.convertPeriod(src.getPeriod()));
031    for (org.hl7.fhir.dstu2.model.Reference t : src.getAuthor())
032      if (!tgt.hasAuthor())
033        tgt.setAuthor(Reference10_40.convertReference(t));
034      else
035        tgt.addContributor(Reference10_40.convertReference(t));
036    for (org.hl7.fhir.dstu2.model.CodeableConcept t : src.getCategory())
037      tgt.addCategory(CodeableConcept10_40.convertCodeableConcept(t));
038    if (src.hasDescriptionElement())
039      tgt.setDescriptionElement(String10_40.convertString(src.getDescriptionElement()));
040    for (org.hl7.fhir.dstu2.model.Reference t : src.getAddresses())
041      tgt.addAddresses(Reference10_40.convertReference(t));
042    for (org.hl7.fhir.dstu2.model.Reference t : src.getGoal()) tgt.addGoal(Reference10_40.convertReference(t));
043    for (org.hl7.fhir.dstu2.model.CarePlan.CarePlanActivityComponent t : src.getActivity())
044      tgt.addActivity(convertCarePlanActivityComponent(t));
045    return tgt;
046  }
047
048  public static org.hl7.fhir.dstu2.model.CarePlan convertCarePlan(org.hl7.fhir.r4.model.CarePlan src) throws FHIRException {
049    if (src == null || src.isEmpty())
050      return null;
051    org.hl7.fhir.dstu2.model.CarePlan tgt = new org.hl7.fhir.dstu2.model.CarePlan();
052    ConversionContext10_40.INSTANCE.getVersionConvertor_10_40().copyDomainResource(src, tgt);
053    for (org.hl7.fhir.r4.model.Identifier t : src.getIdentifier())
054      tgt.addIdentifier(Identifier10_40.convertIdentifier(t));
055    if (src.hasSubject())
056      tgt.setSubject(Reference10_40.convertReference(src.getSubject()));
057    if (src.hasStatus())
058      tgt.setStatusElement(convertCarePlanStatus(src.getStatusElement()));
059    if (src.hasEncounter())
060      tgt.setContext(Reference10_40.convertReference(src.getEncounter()));
061    if (src.hasPeriod())
062      tgt.setPeriod(Period10_40.convertPeriod(src.getPeriod()));
063    if (src.hasAuthor())
064      tgt.addAuthor(Reference10_40.convertReference(src.getAuthor()));
065    for (org.hl7.fhir.r4.model.Reference t : src.getContributor()) tgt.addAuthor(Reference10_40.convertReference(t));
066    for (org.hl7.fhir.r4.model.CodeableConcept t : src.getCategory())
067      tgt.addCategory(CodeableConcept10_40.convertCodeableConcept(t));
068    if (src.hasDescriptionElement())
069      tgt.setDescriptionElement(String10_40.convertString(src.getDescriptionElement()));
070    for (org.hl7.fhir.r4.model.Reference t : src.getAddresses()) tgt.addAddresses(Reference10_40.convertReference(t));
071    for (org.hl7.fhir.r4.model.Reference t : src.getGoal()) tgt.addGoal(Reference10_40.convertReference(t));
072    for (org.hl7.fhir.r4.model.CarePlan.CarePlanActivityComponent t : src.getActivity())
073      tgt.addActivity(convertCarePlanActivityComponent(t));
074    return tgt;
075  }
076
077  public static org.hl7.fhir.r4.model.CarePlan.CarePlanActivityComponent convertCarePlanActivityComponent(org.hl7.fhir.dstu2.model.CarePlan.CarePlanActivityComponent src) throws FHIRException {
078    if (src == null || src.isEmpty())
079      return null;
080    org.hl7.fhir.r4.model.CarePlan.CarePlanActivityComponent tgt = new org.hl7.fhir.r4.model.CarePlan.CarePlanActivityComponent();
081    ConversionContext10_40.INSTANCE.getVersionConvertor_10_40().copyBackboneElement(src,tgt);
082    for (org.hl7.fhir.dstu2.model.Annotation t : src.getProgress())
083      tgt.addProgress(Annotation10_40.convertAnnotation(t));
084    if (src.hasReference())
085      tgt.setReference(Reference10_40.convertReference(src.getReference()));
086    if (src.hasDetail())
087      tgt.setDetail(convertCarePlanActivityDetailComponent(src.getDetail()));
088    return tgt;
089  }
090
091  public static org.hl7.fhir.dstu2.model.CarePlan.CarePlanActivityComponent convertCarePlanActivityComponent(org.hl7.fhir.r4.model.CarePlan.CarePlanActivityComponent src) throws FHIRException {
092    if (src == null || src.isEmpty())
093      return null;
094    org.hl7.fhir.dstu2.model.CarePlan.CarePlanActivityComponent tgt = new org.hl7.fhir.dstu2.model.CarePlan.CarePlanActivityComponent();
095    ConversionContext10_40.INSTANCE.getVersionConvertor_10_40().copyBackboneElement(src,tgt);
096    for (org.hl7.fhir.r4.model.Annotation t : src.getProgress()) tgt.addProgress(Annotation10_40.convertAnnotation(t));
097    if (src.hasReference())
098      tgt.setReference(Reference10_40.convertReference(src.getReference()));
099    if (src.hasDetail())
100      tgt.setDetail(convertCarePlanActivityDetailComponent(src.getDetail()));
101    return tgt;
102  }
103
104  public static org.hl7.fhir.dstu2.model.CarePlan.CarePlanActivityDetailComponent convertCarePlanActivityDetailComponent(org.hl7.fhir.r4.model.CarePlan.CarePlanActivityDetailComponent src) throws FHIRException {
105    if (src == null || src.isEmpty())
106      return null;
107    org.hl7.fhir.dstu2.model.CarePlan.CarePlanActivityDetailComponent tgt = new org.hl7.fhir.dstu2.model.CarePlan.CarePlanActivityDetailComponent();
108    ConversionContext10_40.INSTANCE.getVersionConvertor_10_40().copyBackboneElement(src,tgt);
109    if (src.hasCode())
110      tgt.setCode(CodeableConcept10_40.convertCodeableConcept(src.getCode()));
111    for (org.hl7.fhir.r4.model.CodeableConcept t : src.getReasonCode())
112      tgt.addReasonCode(CodeableConcept10_40.convertCodeableConcept(t));
113    for (org.hl7.fhir.r4.model.Reference t : src.getReasonReference())
114      tgt.addReasonReference(Reference10_40.convertReference(t));
115    for (org.hl7.fhir.r4.model.Reference t : src.getGoal()) tgt.addGoal(Reference10_40.convertReference(t));
116    if (src.hasStatus())
117      tgt.setStatusElement(convertCarePlanActivityStatus(src.getStatusElement()));
118    if (src.hasDoNotPerformElement())
119      tgt.setProhibitedElement(Boolean10_40.convertBoolean(src.getDoNotPerformElement()));
120    if (src.hasScheduled())
121      tgt.setScheduled(ConversionContext10_40.INSTANCE.getVersionConvertor_10_40().convertType(src.getScheduled()));
122    if (src.hasLocation())
123      tgt.setLocation(Reference10_40.convertReference(src.getLocation()));
124    for (org.hl7.fhir.r4.model.Reference t : src.getPerformer()) tgt.addPerformer(Reference10_40.convertReference(t));
125    if (src.hasProduct())
126      tgt.setProduct(ConversionContext10_40.INSTANCE.getVersionConvertor_10_40().convertType(src.getProduct()));
127    if (src.hasDailyAmount())
128      tgt.setDailyAmount(SimpleQuantity10_40.convertSimpleQuantity(src.getDailyAmount()));
129    if (src.hasQuantity())
130      tgt.setQuantity(SimpleQuantity10_40.convertSimpleQuantity(src.getQuantity()));
131    if (src.hasDescriptionElement())
132      tgt.setDescriptionElement(String10_40.convertString(src.getDescriptionElement()));
133    return tgt;
134  }
135
136  public static org.hl7.fhir.r4.model.CarePlan.CarePlanActivityDetailComponent convertCarePlanActivityDetailComponent(org.hl7.fhir.dstu2.model.CarePlan.CarePlanActivityDetailComponent src) throws FHIRException {
137    if (src == null || src.isEmpty())
138      return null;
139    org.hl7.fhir.r4.model.CarePlan.CarePlanActivityDetailComponent tgt = new org.hl7.fhir.r4.model.CarePlan.CarePlanActivityDetailComponent();
140    ConversionContext10_40.INSTANCE.getVersionConvertor_10_40().copyBackboneElement(src,tgt);
141    if (src.hasCode())
142      tgt.setCode(CodeableConcept10_40.convertCodeableConcept(src.getCode()));
143    for (org.hl7.fhir.dstu2.model.CodeableConcept t : src.getReasonCode())
144      tgt.addReasonCode(CodeableConcept10_40.convertCodeableConcept(t));
145    for (org.hl7.fhir.dstu2.model.Reference t : src.getReasonReference())
146      tgt.addReasonReference(Reference10_40.convertReference(t));
147    for (org.hl7.fhir.dstu2.model.Reference t : src.getGoal()) tgt.addGoal(Reference10_40.convertReference(t));
148    if (src.hasStatus())
149      tgt.setStatusElement(convertCarePlanActivityStatus(src.getStatusElement()));
150    if (src.hasProhibitedElement())
151      tgt.setDoNotPerformElement(Boolean10_40.convertBoolean(src.getProhibitedElement()));
152    if (src.hasScheduled())
153      tgt.setScheduled(ConversionContext10_40.INSTANCE.getVersionConvertor_10_40().convertType(src.getScheduled()));
154    if (src.hasLocation())
155      tgt.setLocation(Reference10_40.convertReference(src.getLocation()));
156    for (org.hl7.fhir.dstu2.model.Reference t : src.getPerformer())
157      tgt.addPerformer(Reference10_40.convertReference(t));
158    if (src.hasProduct())
159      tgt.setProduct(ConversionContext10_40.INSTANCE.getVersionConvertor_10_40().convertType(src.getProduct()));
160    if (src.hasDailyAmount())
161      tgt.setDailyAmount(SimpleQuantity10_40.convertSimpleQuantity(src.getDailyAmount()));
162    if (src.hasQuantity())
163      tgt.setQuantity(SimpleQuantity10_40.convertSimpleQuantity(src.getQuantity()));
164    if (src.hasDescriptionElement())
165      tgt.setDescriptionElement(String10_40.convertString(src.getDescriptionElement()));
166    return tgt;
167  }
168
169  static public org.hl7.fhir.r4.model.Enumeration<org.hl7.fhir.r4.model.CarePlan.CarePlanActivityStatus> convertCarePlanActivityStatus(org.hl7.fhir.dstu2.model.Enumeration<org.hl7.fhir.dstu2.model.CarePlan.CarePlanActivityStatus> src) throws FHIRException {
170    if (src == null || src.isEmpty())
171      return null;
172    org.hl7.fhir.r4.model.Enumeration<org.hl7.fhir.r4.model.CarePlan.CarePlanActivityStatus> tgt = new org.hl7.fhir.r4.model.Enumeration<>(new org.hl7.fhir.r4.model.CarePlan.CarePlanActivityStatusEnumFactory());
173    ConversionContext10_40.INSTANCE.getVersionConvertor_10_40().copyElement(src, tgt);
174    switch (src.getValue()) {
175      case NOTSTARTED:
176        tgt.setValue(org.hl7.fhir.r4.model.CarePlan.CarePlanActivityStatus.NOTSTARTED);
177        break;
178      case SCHEDULED:
179        tgt.setValue(org.hl7.fhir.r4.model.CarePlan.CarePlanActivityStatus.SCHEDULED);
180        break;
181      case INPROGRESS:
182        tgt.setValue(org.hl7.fhir.r4.model.CarePlan.CarePlanActivityStatus.INPROGRESS);
183        break;
184      case ONHOLD:
185        tgt.setValue(org.hl7.fhir.r4.model.CarePlan.CarePlanActivityStatus.ONHOLD);
186        break;
187      case COMPLETED:
188        tgt.setValue(org.hl7.fhir.r4.model.CarePlan.CarePlanActivityStatus.COMPLETED);
189        break;
190      case CANCELLED:
191        tgt.setValue(org.hl7.fhir.r4.model.CarePlan.CarePlanActivityStatus.CANCELLED);
192        break;
193      default:
194        tgt.setValue(org.hl7.fhir.r4.model.CarePlan.CarePlanActivityStatus.NULL);
195        break;
196    }
197    return tgt;
198  }
199
200  static public org.hl7.fhir.dstu2.model.Enumeration<org.hl7.fhir.dstu2.model.CarePlan.CarePlanActivityStatus> convertCarePlanActivityStatus(org.hl7.fhir.r4.model.Enumeration<org.hl7.fhir.r4.model.CarePlan.CarePlanActivityStatus> src) throws FHIRException {
201    if (src == null || src.isEmpty())
202      return null;
203    org.hl7.fhir.dstu2.model.Enumeration<org.hl7.fhir.dstu2.model.CarePlan.CarePlanActivityStatus> tgt = new org.hl7.fhir.dstu2.model.Enumeration<>(new org.hl7.fhir.dstu2.model.CarePlan.CarePlanActivityStatusEnumFactory());
204    ConversionContext10_40.INSTANCE.getVersionConvertor_10_40().copyElement(src, tgt);
205    switch (src.getValue()) {
206      case NOTSTARTED:
207        tgt.setValue(org.hl7.fhir.dstu2.model.CarePlan.CarePlanActivityStatus.NOTSTARTED);
208        break;
209      case SCHEDULED:
210        tgt.setValue(org.hl7.fhir.dstu2.model.CarePlan.CarePlanActivityStatus.SCHEDULED);
211        break;
212      case INPROGRESS:
213        tgt.setValue(org.hl7.fhir.dstu2.model.CarePlan.CarePlanActivityStatus.INPROGRESS);
214        break;
215      case ONHOLD:
216        tgt.setValue(org.hl7.fhir.dstu2.model.CarePlan.CarePlanActivityStatus.ONHOLD);
217        break;
218      case COMPLETED:
219        tgt.setValue(org.hl7.fhir.dstu2.model.CarePlan.CarePlanActivityStatus.COMPLETED);
220        break;
221      case CANCELLED:
222        tgt.setValue(org.hl7.fhir.dstu2.model.CarePlan.CarePlanActivityStatus.CANCELLED);
223        break;
224      default:
225        tgt.setValue(org.hl7.fhir.dstu2.model.CarePlan.CarePlanActivityStatus.NULL);
226        break;
227    }
228    return tgt;
229  }
230
231  static public org.hl7.fhir.r4.model.Enumeration<org.hl7.fhir.r4.model.CarePlan.CarePlanStatus> convertCarePlanStatus(org.hl7.fhir.dstu2.model.Enumeration<org.hl7.fhir.dstu2.model.CarePlan.CarePlanStatus> src) throws FHIRException {
232    if (src == null || src.isEmpty())
233      return null;
234    org.hl7.fhir.r4.model.Enumeration<org.hl7.fhir.r4.model.CarePlan.CarePlanStatus> tgt = new org.hl7.fhir.r4.model.Enumeration<>(new org.hl7.fhir.r4.model.CarePlan.CarePlanStatusEnumFactory());
235    ConversionContext10_40.INSTANCE.getVersionConvertor_10_40().copyElement(src, tgt);
236    switch (src.getValue()) {
237      case PROPOSED:
238        tgt.setValue(org.hl7.fhir.r4.model.CarePlan.CarePlanStatus.DRAFT);
239        break;
240      case DRAFT:
241        tgt.setValue(org.hl7.fhir.r4.model.CarePlan.CarePlanStatus.DRAFT);
242        break;
243      case ACTIVE:
244        tgt.setValue(org.hl7.fhir.r4.model.CarePlan.CarePlanStatus.ACTIVE);
245        break;
246      case COMPLETED:
247        tgt.setValue(org.hl7.fhir.r4.model.CarePlan.CarePlanStatus.COMPLETED);
248        break;
249      case CANCELLED:
250        tgt.setValue(org.hl7.fhir.r4.model.CarePlan.CarePlanStatus.REVOKED);
251        break;
252      default:
253        tgt.setValue(org.hl7.fhir.r4.model.CarePlan.CarePlanStatus.NULL);
254        break;
255    }
256    return tgt;
257  }
258
259  static public org.hl7.fhir.dstu2.model.Enumeration<org.hl7.fhir.dstu2.model.CarePlan.CarePlanStatus> convertCarePlanStatus(org.hl7.fhir.r4.model.Enumeration<org.hl7.fhir.r4.model.CarePlan.CarePlanStatus> src) throws FHIRException {
260    if (src == null || src.isEmpty())
261      return null;
262    org.hl7.fhir.dstu2.model.Enumeration<org.hl7.fhir.dstu2.model.CarePlan.CarePlanStatus> tgt = new org.hl7.fhir.dstu2.model.Enumeration<>(new org.hl7.fhir.dstu2.model.CarePlan.CarePlanStatusEnumFactory());
263    ConversionContext10_40.INSTANCE.getVersionConvertor_10_40().copyElement(src, tgt);
264    switch (src.getValue()) {
265      case DRAFT:
266        tgt.setValue(org.hl7.fhir.dstu2.model.CarePlan.CarePlanStatus.DRAFT);
267        break;
268      case ACTIVE:
269        tgt.setValue(org.hl7.fhir.dstu2.model.CarePlan.CarePlanStatus.ACTIVE);
270        break;
271      case COMPLETED:
272        tgt.setValue(org.hl7.fhir.dstu2.model.CarePlan.CarePlanStatus.COMPLETED);
273        break;
274      case REVOKED:
275        tgt.setValue(org.hl7.fhir.dstu2.model.CarePlan.CarePlanStatus.CANCELLED);
276        break;
277      default:
278        tgt.setValue(org.hl7.fhir.dstu2.model.CarePlan.CarePlanStatus.NULL);
279        break;
280    }
281    return tgt;
282  }
283}