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.CodeableConcept10_40;
006import org.hl7.fhir.convertors.conv10_40.datatypes10_40.complextypes10_40.Duration10_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.exceptions.FHIRException;
010
011public class Encounter10_40 {
012
013  public static org.hl7.fhir.dstu2.model.Encounter convertEncounter(org.hl7.fhir.r4.model.Encounter src) throws FHIRException {
014    if (src == null || src.isEmpty())
015      return null;
016    org.hl7.fhir.dstu2.model.Encounter tgt = new org.hl7.fhir.dstu2.model.Encounter();
017    ConversionContext10_40.INSTANCE.getVersionConvertor_10_40().copyDomainResource(src, tgt);
018    for (org.hl7.fhir.r4.model.Identifier t : src.getIdentifier())
019      tgt.addIdentifier(Identifier10_40.convertIdentifier(t));
020    if (src.hasStatus())
021      tgt.setStatusElement(convertEncounterState(src.getStatusElement()));
022    if (src.hasClass_())
023      tgt.setClass_(convertEncounterClass(src.getClass_()));
024    for (org.hl7.fhir.r4.model.CodeableConcept t : src.getType())
025      tgt.addType(CodeableConcept10_40.convertCodeableConcept(t));
026    if (src.hasPriority())
027      tgt.setPriority(CodeableConcept10_40.convertCodeableConcept(src.getPriority()));
028    if (src.hasSubject())
029      tgt.setPatient(Reference10_40.convertReference(src.getSubject()));
030    for (org.hl7.fhir.r4.model.Reference t : src.getEpisodeOfCare())
031      tgt.addEpisodeOfCare(Reference10_40.convertReference(t));
032    for (org.hl7.fhir.r4.model.Reference t : src.getBasedOn())
033      tgt.addIncomingReferral(Reference10_40.convertReference(t));
034    for (org.hl7.fhir.r4.model.Encounter.EncounterParticipantComponent t : src.getParticipant())
035      tgt.addParticipant(convertEncounterParticipantComponent(t));
036    if (src.hasAppointment())
037      tgt.setAppointment(Reference10_40.convertReference(src.getAppointmentFirstRep()));
038    if (src.hasPeriod())
039      tgt.setPeriod(Period10_40.convertPeriod(src.getPeriod()));
040    if (src.hasLength())
041      tgt.setLength(Duration10_40.convertDuration(src.getLength()));
042    for (org.hl7.fhir.r4.model.CodeableConcept t : src.getReasonCode())
043      tgt.addReason(CodeableConcept10_40.convertCodeableConcept(t));
044    if (src.hasHospitalization())
045      tgt.setHospitalization(convertEncounterHospitalizationComponent(src.getHospitalization()));
046    for (org.hl7.fhir.r4.model.Encounter.EncounterLocationComponent t : src.getLocation())
047      tgt.addLocation(convertEncounterLocationComponent(t));
048    if (src.hasServiceProvider())
049      tgt.setServiceProvider(Reference10_40.convertReference(src.getServiceProvider()));
050    if (src.hasPartOf())
051      tgt.setPartOf(Reference10_40.convertReference(src.getPartOf()));
052    return tgt;
053  }
054
055  public static org.hl7.fhir.r4.model.Encounter convertEncounter(org.hl7.fhir.dstu2.model.Encounter src) throws FHIRException {
056    if (src == null || src.isEmpty())
057      return null;
058    org.hl7.fhir.r4.model.Encounter tgt = new org.hl7.fhir.r4.model.Encounter();
059    ConversionContext10_40.INSTANCE.getVersionConvertor_10_40().copyDomainResource(src, tgt);
060    for (org.hl7.fhir.dstu2.model.Identifier t : src.getIdentifier())
061      tgt.addIdentifier(Identifier10_40.convertIdentifier(t));
062    if (src.hasStatus())
063      tgt.setStatusElement(convertEncounterState(src.getStatusElement()));
064    if (src.hasClass_())
065      tgt.setClass_(convertEncounterClass(src.getClass_()));
066    for (org.hl7.fhir.dstu2.model.CodeableConcept t : src.getType())
067      tgt.addType(CodeableConcept10_40.convertCodeableConcept(t));
068    if (src.hasPriority())
069      tgt.setPriority(CodeableConcept10_40.convertCodeableConcept(src.getPriority()));
070    if (src.hasPatient())
071      tgt.setSubject(Reference10_40.convertReference(src.getPatient()));
072    for (org.hl7.fhir.dstu2.model.Reference t : src.getEpisodeOfCare())
073      tgt.addEpisodeOfCare(Reference10_40.convertReference(t));
074    for (org.hl7.fhir.dstu2.model.Reference t : src.getIncomingReferral())
075      tgt.addBasedOn(Reference10_40.convertReference(t));
076    for (org.hl7.fhir.dstu2.model.Encounter.EncounterParticipantComponent t : src.getParticipant())
077      tgt.addParticipant(convertEncounterParticipantComponent(t));
078    if (src.hasAppointment())
079      tgt.addAppointment(Reference10_40.convertReference(src.getAppointment()));
080    if (src.hasPeriod())
081      tgt.setPeriod(Period10_40.convertPeriod(src.getPeriod()));
082    if (src.hasLength())
083      tgt.setLength(Duration10_40.convertDuration(src.getLength()));
084    for (org.hl7.fhir.dstu2.model.CodeableConcept t : src.getReason())
085      tgt.addReasonCode(CodeableConcept10_40.convertCodeableConcept(t));
086    if (src.hasHospitalization())
087      tgt.setHospitalization(convertEncounterHospitalizationComponent(src.getHospitalization()));
088    for (org.hl7.fhir.dstu2.model.Encounter.EncounterLocationComponent t : src.getLocation())
089      tgt.addLocation(convertEncounterLocationComponent(t));
090    if (src.hasServiceProvider())
091      tgt.setServiceProvider(Reference10_40.convertReference(src.getServiceProvider()));
092    if (src.hasPartOf())
093      tgt.setPartOf(Reference10_40.convertReference(src.getPartOf()));
094    return tgt;
095  }
096
097  public static org.hl7.fhir.r4.model.Coding convertEncounterClass(org.hl7.fhir.dstu2.model.Encounter.EncounterClass src) throws FHIRException {
098    if (src == null)
099      return null;
100    switch (src) {
101      case INPATIENT:
102        return new org.hl7.fhir.r4.model.Coding().setSystem("http://terminology.hl7.org/v3/ActCode").setCode("IMP");
103      case OUTPATIENT:
104        return new org.hl7.fhir.r4.model.Coding().setSystem("http://terminology.hl7.org/v3/ActCode").setCode("AMB");
105      case AMBULATORY:
106        return new org.hl7.fhir.r4.model.Coding().setSystem("http://terminology.hl7.org/v3/ActCode").setCode("AMB");
107      case EMERGENCY:
108        return new org.hl7.fhir.r4.model.Coding().setSystem("http://terminology.hl7.org/v3/ActCode").setCode("EMER");
109      case HOME:
110        return new org.hl7.fhir.r4.model.Coding().setSystem("http://terminology.hl7.org/v3/ActCode").setCode("HH");
111      case FIELD:
112        return new org.hl7.fhir.r4.model.Coding().setSystem("http://terminology.hl7.org/v3/ActCode").setCode("FLD");
113      case DAYTIME:
114        return new org.hl7.fhir.r4.model.Coding().setSystem("http://terminology.hl7.org/v3/ActCode").setCode("SS");
115      case VIRTUAL:
116        return new org.hl7.fhir.r4.model.Coding().setSystem("http://terminology.hl7.org/v3/ActCode").setCode("VR");
117      default:
118        return null;
119    }
120  }
121
122  public static org.hl7.fhir.dstu2.model.Encounter.EncounterClass convertEncounterClass(org.hl7.fhir.r4.model.Coding src) throws FHIRException {
123    if (src == null || src.isEmpty())
124      return null;
125    if (src.getSystem().equals("http://terminology.hl7.org/v3/ActCode")) {
126      if (src.getCode().equals("IMP"))
127        return org.hl7.fhir.dstu2.model.Encounter.EncounterClass.INPATIENT;
128      if (src.getCode().equals("AMB"))
129        return org.hl7.fhir.dstu2.model.Encounter.EncounterClass.AMBULATORY;
130      if (src.getCode().equals("EMER"))
131        return org.hl7.fhir.dstu2.model.Encounter.EncounterClass.EMERGENCY;
132      if (src.getCode().equals("HH"))
133        return org.hl7.fhir.dstu2.model.Encounter.EncounterClass.HOME;
134      if (src.getCode().equals("FLD"))
135        return org.hl7.fhir.dstu2.model.Encounter.EncounterClass.FIELD;
136      if (src.getCode().equals(""))
137        return org.hl7.fhir.dstu2.model.Encounter.EncounterClass.DAYTIME;
138      if (src.getCode().equals("VR"))
139        return org.hl7.fhir.dstu2.model.Encounter.EncounterClass.VIRTUAL;
140    }
141    return org.hl7.fhir.dstu2.model.Encounter.EncounterClass.NULL;
142  }
143
144  public static org.hl7.fhir.r4.model.Encounter.EncounterHospitalizationComponent convertEncounterHospitalizationComponent(org.hl7.fhir.dstu2.model.Encounter.EncounterHospitalizationComponent src) throws FHIRException {
145    if (src == null || src.isEmpty())
146      return null;
147    org.hl7.fhir.r4.model.Encounter.EncounterHospitalizationComponent tgt = new org.hl7.fhir.r4.model.Encounter.EncounterHospitalizationComponent();
148    ConversionContext10_40.INSTANCE.getVersionConvertor_10_40().copyBackboneElement(src,tgt);
149    if (src.hasPreAdmissionIdentifier())
150      tgt.setPreAdmissionIdentifier(Identifier10_40.convertIdentifier(src.getPreAdmissionIdentifier()));
151    if (src.hasOrigin())
152      tgt.setOrigin(Reference10_40.convertReference(src.getOrigin()));
153    if (src.hasAdmitSource())
154      tgt.setAdmitSource(CodeableConcept10_40.convertCodeableConcept(src.getAdmitSource()));
155    if (src.hasReAdmission())
156      tgt.setReAdmission(CodeableConcept10_40.convertCodeableConcept(src.getReAdmission()));
157    for (org.hl7.fhir.dstu2.model.CodeableConcept t : src.getDietPreference())
158      tgt.addDietPreference(CodeableConcept10_40.convertCodeableConcept(t));
159    for (org.hl7.fhir.dstu2.model.CodeableConcept t : src.getSpecialCourtesy())
160      tgt.addSpecialCourtesy(CodeableConcept10_40.convertCodeableConcept(t));
161    for (org.hl7.fhir.dstu2.model.CodeableConcept t : src.getSpecialArrangement())
162      tgt.addSpecialArrangement(CodeableConcept10_40.convertCodeableConcept(t));
163    if (src.hasDestination())
164      tgt.setDestination(Reference10_40.convertReference(src.getDestination()));
165    if (src.hasDischargeDisposition())
166      tgt.setDischargeDisposition(CodeableConcept10_40.convertCodeableConcept(src.getDischargeDisposition()));
167    return tgt;
168  }
169
170  public static org.hl7.fhir.dstu2.model.Encounter.EncounterHospitalizationComponent convertEncounterHospitalizationComponent(org.hl7.fhir.r4.model.Encounter.EncounterHospitalizationComponent src) throws FHIRException {
171    if (src == null || src.isEmpty())
172      return null;
173    org.hl7.fhir.dstu2.model.Encounter.EncounterHospitalizationComponent tgt = new org.hl7.fhir.dstu2.model.Encounter.EncounterHospitalizationComponent();
174    ConversionContext10_40.INSTANCE.getVersionConvertor_10_40().copyBackboneElement(src,tgt);
175    if (src.hasPreAdmissionIdentifier())
176      tgt.setPreAdmissionIdentifier(Identifier10_40.convertIdentifier(src.getPreAdmissionIdentifier()));
177    if (src.hasOrigin())
178      tgt.setOrigin(Reference10_40.convertReference(src.getOrigin()));
179    if (src.hasAdmitSource())
180      tgt.setAdmitSource(CodeableConcept10_40.convertCodeableConcept(src.getAdmitSource()));
181    if (src.hasReAdmission())
182      tgt.setReAdmission(CodeableConcept10_40.convertCodeableConcept(src.getReAdmission()));
183    for (org.hl7.fhir.r4.model.CodeableConcept t : src.getDietPreference())
184      tgt.addDietPreference(CodeableConcept10_40.convertCodeableConcept(t));
185    for (org.hl7.fhir.r4.model.CodeableConcept t : src.getSpecialCourtesy())
186      tgt.addSpecialCourtesy(CodeableConcept10_40.convertCodeableConcept(t));
187    for (org.hl7.fhir.r4.model.CodeableConcept t : src.getSpecialArrangement())
188      tgt.addSpecialArrangement(CodeableConcept10_40.convertCodeableConcept(t));
189    if (src.hasDestination())
190      tgt.setDestination(Reference10_40.convertReference(src.getDestination()));
191    if (src.hasDischargeDisposition())
192      tgt.setDischargeDisposition(CodeableConcept10_40.convertCodeableConcept(src.getDischargeDisposition()));
193    return tgt;
194  }
195
196  public static org.hl7.fhir.r4.model.Encounter.EncounterLocationComponent convertEncounterLocationComponent(org.hl7.fhir.dstu2.model.Encounter.EncounterLocationComponent src) throws FHIRException {
197    if (src == null || src.isEmpty())
198      return null;
199    org.hl7.fhir.r4.model.Encounter.EncounterLocationComponent tgt = new org.hl7.fhir.r4.model.Encounter.EncounterLocationComponent();
200    ConversionContext10_40.INSTANCE.getVersionConvertor_10_40().copyBackboneElement(src,tgt);
201    if (src.hasLocation())
202      tgt.setLocation(Reference10_40.convertReference(src.getLocation()));
203    if (src.hasStatus())
204      tgt.setStatusElement(convertEncounterLocationStatus(src.getStatusElement()));
205    if (src.hasPeriod())
206      tgt.setPeriod(Period10_40.convertPeriod(src.getPeriod()));
207    return tgt;
208  }
209
210  public static org.hl7.fhir.dstu2.model.Encounter.EncounterLocationComponent convertEncounterLocationComponent(org.hl7.fhir.r4.model.Encounter.EncounterLocationComponent src) throws FHIRException {
211    if (src == null || src.isEmpty())
212      return null;
213    org.hl7.fhir.dstu2.model.Encounter.EncounterLocationComponent tgt = new org.hl7.fhir.dstu2.model.Encounter.EncounterLocationComponent();
214    ConversionContext10_40.INSTANCE.getVersionConvertor_10_40().copyBackboneElement(src,tgt);
215    if (src.hasLocation())
216      tgt.setLocation(Reference10_40.convertReference(src.getLocation()));
217    if (src.hasStatus())
218      tgt.setStatusElement(convertEncounterLocationStatus(src.getStatusElement()));
219    if (src.hasPeriod())
220      tgt.setPeriod(Period10_40.convertPeriod(src.getPeriod()));
221    return tgt;
222  }
223
224  static public org.hl7.fhir.dstu2.model.Enumeration<org.hl7.fhir.dstu2.model.Encounter.EncounterLocationStatus> convertEncounterLocationStatus(org.hl7.fhir.r4.model.Enumeration<org.hl7.fhir.r4.model.Encounter.EncounterLocationStatus> src) throws FHIRException {
225    if (src == null || src.isEmpty())
226      return null;
227    org.hl7.fhir.dstu2.model.Enumeration<org.hl7.fhir.dstu2.model.Encounter.EncounterLocationStatus> tgt = new org.hl7.fhir.dstu2.model.Enumeration<>(new org.hl7.fhir.dstu2.model.Encounter.EncounterLocationStatusEnumFactory());
228    ConversionContext10_40.INSTANCE.getVersionConvertor_10_40().copyElement(src, tgt);
229    switch (src.getValue()) {
230      case PLANNED:
231        tgt.setValue(org.hl7.fhir.dstu2.model.Encounter.EncounterLocationStatus.PLANNED);
232        break;
233      case ACTIVE:
234        tgt.setValue(org.hl7.fhir.dstu2.model.Encounter.EncounterLocationStatus.ACTIVE);
235        break;
236      case RESERVED:
237        tgt.setValue(org.hl7.fhir.dstu2.model.Encounter.EncounterLocationStatus.RESERVED);
238        break;
239      case COMPLETED:
240        tgt.setValue(org.hl7.fhir.dstu2.model.Encounter.EncounterLocationStatus.COMPLETED);
241        break;
242      default:
243        tgt.setValue(org.hl7.fhir.dstu2.model.Encounter.EncounterLocationStatus.NULL);
244        break;
245    }
246    return tgt;
247  }
248
249  static public org.hl7.fhir.r4.model.Enumeration<org.hl7.fhir.r4.model.Encounter.EncounterLocationStatus> convertEncounterLocationStatus(org.hl7.fhir.dstu2.model.Enumeration<org.hl7.fhir.dstu2.model.Encounter.EncounterLocationStatus> src) throws FHIRException {
250    if (src == null || src.isEmpty())
251      return null;
252    org.hl7.fhir.r4.model.Enumeration<org.hl7.fhir.r4.model.Encounter.EncounterLocationStatus> tgt = new org.hl7.fhir.r4.model.Enumeration<>(new org.hl7.fhir.r4.model.Encounter.EncounterLocationStatusEnumFactory());
253    ConversionContext10_40.INSTANCE.getVersionConvertor_10_40().copyElement(src, tgt);
254    switch (src.getValue()) {
255      case PLANNED:
256        tgt.setValue(org.hl7.fhir.r4.model.Encounter.EncounterLocationStatus.PLANNED);
257        break;
258      case ACTIVE:
259        tgt.setValue(org.hl7.fhir.r4.model.Encounter.EncounterLocationStatus.ACTIVE);
260        break;
261      case RESERVED:
262        tgt.setValue(org.hl7.fhir.r4.model.Encounter.EncounterLocationStatus.RESERVED);
263        break;
264      case COMPLETED:
265        tgt.setValue(org.hl7.fhir.r4.model.Encounter.EncounterLocationStatus.COMPLETED);
266        break;
267      default:
268        tgt.setValue(org.hl7.fhir.r4.model.Encounter.EncounterLocationStatus.NULL);
269        break;
270    }
271    return tgt;
272  }
273
274  public static org.hl7.fhir.r4.model.Encounter.EncounterParticipantComponent convertEncounterParticipantComponent(org.hl7.fhir.dstu2.model.Encounter.EncounterParticipantComponent src) throws FHIRException {
275    if (src == null || src.isEmpty())
276      return null;
277    org.hl7.fhir.r4.model.Encounter.EncounterParticipantComponent tgt = new org.hl7.fhir.r4.model.Encounter.EncounterParticipantComponent();
278    ConversionContext10_40.INSTANCE.getVersionConvertor_10_40().copyBackboneElement(src,tgt);
279    for (org.hl7.fhir.dstu2.model.CodeableConcept t : src.getType())
280      tgt.addType(CodeableConcept10_40.convertCodeableConcept(t));
281    if (src.hasPeriod())
282      tgt.setPeriod(Period10_40.convertPeriod(src.getPeriod()));
283    if (src.hasIndividual())
284      tgt.setIndividual(Reference10_40.convertReference(src.getIndividual()));
285    return tgt;
286  }
287
288  public static org.hl7.fhir.dstu2.model.Encounter.EncounterParticipantComponent convertEncounterParticipantComponent(org.hl7.fhir.r4.model.Encounter.EncounterParticipantComponent src) throws FHIRException {
289    if (src == null || src.isEmpty())
290      return null;
291    org.hl7.fhir.dstu2.model.Encounter.EncounterParticipantComponent tgt = new org.hl7.fhir.dstu2.model.Encounter.EncounterParticipantComponent();
292    ConversionContext10_40.INSTANCE.getVersionConvertor_10_40().copyBackboneElement(src,tgt);
293    for (org.hl7.fhir.r4.model.CodeableConcept t : src.getType())
294      tgt.addType(CodeableConcept10_40.convertCodeableConcept(t));
295    if (src.hasPeriod())
296      tgt.setPeriod(Period10_40.convertPeriod(src.getPeriod()));
297    if (src.hasIndividual())
298      tgt.setIndividual(Reference10_40.convertReference(src.getIndividual()));
299    return tgt;
300  }
301
302  static public org.hl7.fhir.dstu2.model.Enumeration<org.hl7.fhir.dstu2.model.Encounter.EncounterState> convertEncounterState(org.hl7.fhir.r4.model.Enumeration<org.hl7.fhir.r4.model.Encounter.EncounterStatus> src) throws FHIRException {
303    if (src == null || src.isEmpty())
304      return null;
305    org.hl7.fhir.dstu2.model.Enumeration<org.hl7.fhir.dstu2.model.Encounter.EncounterState> tgt = new org.hl7.fhir.dstu2.model.Enumeration<>(new org.hl7.fhir.dstu2.model.Encounter.EncounterStateEnumFactory());
306    ConversionContext10_40.INSTANCE.getVersionConvertor_10_40().copyElement(src, tgt);
307    switch (src.getValue()) {
308      case PLANNED:
309        tgt.setValue(org.hl7.fhir.dstu2.model.Encounter.EncounterState.PLANNED);
310        break;
311      case ARRIVED:
312        tgt.setValue(org.hl7.fhir.dstu2.model.Encounter.EncounterState.ARRIVED);
313        break;
314      case INPROGRESS:
315        tgt.setValue(org.hl7.fhir.dstu2.model.Encounter.EncounterState.INPROGRESS);
316        break;
317      case ONLEAVE:
318        tgt.setValue(org.hl7.fhir.dstu2.model.Encounter.EncounterState.ONLEAVE);
319        break;
320      case FINISHED:
321        tgt.setValue(org.hl7.fhir.dstu2.model.Encounter.EncounterState.FINISHED);
322        break;
323      case CANCELLED:
324        tgt.setValue(org.hl7.fhir.dstu2.model.Encounter.EncounterState.CANCELLED);
325        break;
326      default:
327        tgt.setValue(org.hl7.fhir.dstu2.model.Encounter.EncounterState.NULL);
328        break;
329    }
330    return tgt;
331  }
332
333  static public org.hl7.fhir.r4.model.Enumeration<org.hl7.fhir.r4.model.Encounter.EncounterStatus> convertEncounterState(org.hl7.fhir.dstu2.model.Enumeration<org.hl7.fhir.dstu2.model.Encounter.EncounterState> src) throws FHIRException {
334    if (src == null || src.isEmpty())
335      return null;
336    org.hl7.fhir.r4.model.Enumeration<org.hl7.fhir.r4.model.Encounter.EncounterStatus> tgt = new org.hl7.fhir.r4.model.Enumeration<>(new org.hl7.fhir.r4.model.Encounter.EncounterStatusEnumFactory());
337    ConversionContext10_40.INSTANCE.getVersionConvertor_10_40().copyElement(src, tgt);
338    switch (src.getValue()) {
339      case PLANNED:
340        tgt.setValue(org.hl7.fhir.r4.model.Encounter.EncounterStatus.PLANNED);
341        break;
342      case ARRIVED:
343        tgt.setValue(org.hl7.fhir.r4.model.Encounter.EncounterStatus.ARRIVED);
344        break;
345      case INPROGRESS:
346        tgt.setValue(org.hl7.fhir.r4.model.Encounter.EncounterStatus.INPROGRESS);
347        break;
348      case ONLEAVE:
349        tgt.setValue(org.hl7.fhir.r4.model.Encounter.EncounterStatus.ONLEAVE);
350        break;
351      case FINISHED:
352        tgt.setValue(org.hl7.fhir.r4.model.Encounter.EncounterStatus.FINISHED);
353        break;
354      case CANCELLED:
355        tgt.setValue(org.hl7.fhir.r4.model.Encounter.EncounterStatus.CANCELLED);
356        break;
357      default:
358        tgt.setValue(org.hl7.fhir.r4.model.Encounter.EncounterStatus.NULL);
359        break;
360    }
361    return tgt;
362  }
363}