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