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.CodeableConcept10_50;
006import org.hl7.fhir.convertors.conv10_50.datatypes10_50.complextypes10_50.Identifier10_50;
007import org.hl7.fhir.convertors.conv10_50.datatypes10_50.primitivetypes10_50.Instant10_50;
008import org.hl7.fhir.convertors.conv10_50.datatypes10_50.primitivetypes10_50.MarkDown10_50;
009import org.hl7.fhir.convertors.conv10_50.datatypes10_50.primitivetypes10_50.PositiveInt10_50;
010import org.hl7.fhir.convertors.conv10_50.datatypes10_50.primitivetypes10_50.String10_50;
011import org.hl7.fhir.dstu2.model.UnsignedIntType;
012import org.hl7.fhir.exceptions.FHIRException;
013import org.hl7.fhir.r5.model.CodeableConcept;
014
015public class Appointment10_50 {
016
017  public static org.hl7.fhir.dstu2.model.Appointment convertAppointment(org.hl7.fhir.r5.model.Appointment src) throws FHIRException {
018    if (src == null || src.isEmpty())
019      return null;
020    org.hl7.fhir.dstu2.model.Appointment tgt = new org.hl7.fhir.dstu2.model.Appointment();
021    ConversionContext10_50.INSTANCE.getVersionConvertor_10_50().copyDomainResource(src, tgt);
022    for (org.hl7.fhir.r5.model.Identifier t : src.getIdentifier())
023      tgt.addIdentifier(Identifier10_50.convertIdentifier(t));
024    if (src.hasStatus())
025      tgt.setStatusElement(convertAppointmentStatus(src.getStatusElement()));
026    for (org.hl7.fhir.r5.model.CodeableReference t : src.getServiceType())
027      tgt.setType(CodeableConcept10_50.convertCodeableConcept(t.getConcept()));
028    if (src.hasPriority())
029      tgt.setPriorityElement(convertAppointmentPriority(src.getPriority()));
030    if (src.hasDescriptionElement())
031      tgt.setDescriptionElement(String10_50.convertString(src.getDescriptionElement()));
032    if (src.hasStartElement())
033      tgt.setStartElement(Instant10_50.convertInstant(src.getStartElement()));
034    if (src.hasEndElement())
035      tgt.setEndElement(Instant10_50.convertInstant(src.getEndElement()));
036    if (src.hasMinutesDurationElement())
037      tgt.setMinutesDurationElement(PositiveInt10_50.convertPositiveInt(src.getMinutesDurationElement()));
038    for (org.hl7.fhir.r5.model.Reference t : src.getSlot()) tgt.addSlot(Reference10_50.convertReference(t));
039    if (src.hasNote())
040      tgt.setCommentElement(String10_50.convertString(src.getNoteFirstRep().getTextElement()));
041    for (org.hl7.fhir.r5.model.Appointment.AppointmentParticipantComponent t : src.getParticipant())
042      tgt.addParticipant(convertAppointmentParticipantComponent(t));
043    return tgt;
044  }
045
046  private static UnsignedIntType convertAppointmentPriority(CodeableConcept src) {
047    UnsignedIntType tgt = new UnsignedIntType(convertAppointmentPriorityFromR5(src));
048    ConversionContext10_50.INSTANCE.getVersionConvertor_10_50().copyElement(src, tgt);
049    return tgt;
050  }
051
052  private static CodeableConcept convertAppointmentPriority(UnsignedIntType src) {
053    CodeableConcept tgt = src.hasValue() ? convertAppointmentPriorityToR5(src.getValue()) : new CodeableConcept();
054    ConversionContext10_50.INSTANCE.getVersionConvertor_10_50().copyElement(src, tgt);
055    return tgt;
056  }
057
058  public static org.hl7.fhir.r5.model.CodeableConcept convertAppointmentPriorityToR5(int priority) {
059    return null;
060  }
061
062  public static int convertAppointmentPriorityFromR5(org.hl7.fhir.r5.model.CodeableConcept priority) {
063    return 0;
064  }
065
066  public static org.hl7.fhir.r5.model.Appointment convertAppointment(org.hl7.fhir.dstu2.model.Appointment src) throws FHIRException {
067    if (src == null || src.isEmpty())
068      return null;
069    org.hl7.fhir.r5.model.Appointment tgt = new org.hl7.fhir.r5.model.Appointment();
070    ConversionContext10_50.INSTANCE.getVersionConvertor_10_50().copyDomainResource(src, tgt);
071    for (org.hl7.fhir.dstu2.model.Identifier t : src.getIdentifier())
072      tgt.addIdentifier(Identifier10_50.convertIdentifier(t));
073    if (src.hasStatus())
074      tgt.setStatusElement(convertAppointmentStatus(src.getStatusElement()));
075    if (src.hasType())
076      tgt.addServiceType().setConcept(CodeableConcept10_50.convertCodeableConcept(src.getType()));
077    if (src.hasPriorityElement())
078      tgt.setPriority(convertAppointmentPriority(src.getPriorityElement()));
079    if (src.hasDescriptionElement())
080      tgt.setDescriptionElement(String10_50.convertString(src.getDescriptionElement()));
081    if (src.hasStartElement())
082      tgt.setStartElement(Instant10_50.convertInstant(src.getStartElement()));
083    if (src.hasEndElement())
084      tgt.setEndElement(Instant10_50.convertInstant(src.getEndElement()));
085    if (src.hasMinutesDurationElement())
086      tgt.setMinutesDurationElement(PositiveInt10_50.convertPositiveInt(src.getMinutesDurationElement()));
087    for (org.hl7.fhir.dstu2.model.Reference t : src.getSlot()) tgt.addSlot(Reference10_50.convertReference(t));
088    if (src.hasCommentElement())
089      tgt.getNoteFirstRep().setTextElement(MarkDown10_50.convertStringToMarkdown(src.getCommentElement()));
090    for (org.hl7.fhir.dstu2.model.Appointment.AppointmentParticipantComponent t : src.getParticipant())
091      tgt.addParticipant(convertAppointmentParticipantComponent(t));
092    return tgt;
093  }
094
095
096  public static org.hl7.fhir.dstu2.model.Appointment.AppointmentParticipantComponent convertAppointmentParticipantComponent(org.hl7.fhir.r5.model.Appointment.AppointmentParticipantComponent src) throws FHIRException {
097    if (src == null || src.isEmpty())
098      return null;
099    org.hl7.fhir.dstu2.model.Appointment.AppointmentParticipantComponent tgt = new org.hl7.fhir.dstu2.model.Appointment.AppointmentParticipantComponent();
100    ConversionContext10_50.INSTANCE.getVersionConvertor_10_50().copyBackboneElement(src,tgt);
101    for (org.hl7.fhir.r5.model.CodeableConcept t : src.getType())
102      tgt.addType(CodeableConcept10_50.convertCodeableConcept(t));
103    if (src.hasActor())
104      tgt.setActor(Reference10_50.convertReference(src.getActor()));
105    if (src.hasRequired())
106      tgt.setRequiredElement(convertParticipantRequired(src.getRequiredElement()));
107    if (src.hasStatus())
108      tgt.setStatusElement(convertParticipationStatus(src.getStatusElement()));
109    return tgt;
110  }
111
112  public static org.hl7.fhir.r5.model.Appointment.AppointmentParticipantComponent convertAppointmentParticipantComponent(org.hl7.fhir.dstu2.model.Appointment.AppointmentParticipantComponent src) throws FHIRException {
113    if (src == null || src.isEmpty())
114      return null;
115    org.hl7.fhir.r5.model.Appointment.AppointmentParticipantComponent tgt = new org.hl7.fhir.r5.model.Appointment.AppointmentParticipantComponent();
116    ConversionContext10_50.INSTANCE.getVersionConvertor_10_50().copyBackboneElement(src,tgt);
117    for (org.hl7.fhir.dstu2.model.CodeableConcept t : src.getType())
118      tgt.addType(CodeableConcept10_50.convertCodeableConcept(t));
119    if (src.hasActor())
120      tgt.setActor(Reference10_50.convertReference(src.getActor()));
121    if (src.hasRequired())
122      tgt.setRequiredElement(convertParticipantRequired(src.getRequiredElement()));
123    if (src.hasStatus())
124      tgt.setStatusElement(convertParticipationStatus(src.getStatusElement()));
125    return tgt;
126  }
127
128  static public org.hl7.fhir.r5.model.Enumeration<org.hl7.fhir.r5.model.Appointment.AppointmentStatus> convertAppointmentStatus(org.hl7.fhir.dstu2.model.Enumeration<org.hl7.fhir.dstu2.model.Appointment.AppointmentStatus> src) throws FHIRException {
129    if (src == null || src.isEmpty())
130      return null;
131    org.hl7.fhir.r5.model.Enumeration<org.hl7.fhir.r5.model.Appointment.AppointmentStatus> tgt = new org.hl7.fhir.r5.model.Enumeration<>(new org.hl7.fhir.r5.model.Appointment.AppointmentStatusEnumFactory());
132    ConversionContext10_50.INSTANCE.getVersionConvertor_10_50().copyElement(src, tgt);
133    switch (src.getValue()) {
134      case PROPOSED:
135        tgt.setValue(org.hl7.fhir.r5.model.Appointment.AppointmentStatus.PROPOSED);
136        break;
137      case PENDING:
138        tgt.setValue(org.hl7.fhir.r5.model.Appointment.AppointmentStatus.PENDING);
139        break;
140      case BOOKED:
141        tgt.setValue(org.hl7.fhir.r5.model.Appointment.AppointmentStatus.BOOKED);
142        break;
143      case ARRIVED:
144        tgt.setValue(org.hl7.fhir.r5.model.Appointment.AppointmentStatus.ARRIVED);
145        break;
146      case FULFILLED:
147        tgt.setValue(org.hl7.fhir.r5.model.Appointment.AppointmentStatus.FULFILLED);
148        break;
149      case CANCELLED:
150        tgt.setValue(org.hl7.fhir.r5.model.Appointment.AppointmentStatus.CANCELLED);
151        break;
152      case NOSHOW:
153        tgt.setValue(org.hl7.fhir.r5.model.Appointment.AppointmentStatus.NOSHOW);
154        break;
155      default:
156        tgt.setValue(org.hl7.fhir.r5.model.Appointment.AppointmentStatus.NULL);
157        break;
158    }
159    return tgt;
160  }
161
162  static public org.hl7.fhir.dstu2.model.Enumeration<org.hl7.fhir.dstu2.model.Appointment.AppointmentStatus> convertAppointmentStatus(org.hl7.fhir.r5.model.Enumeration<org.hl7.fhir.r5.model.Appointment.AppointmentStatus> src) throws FHIRException {
163    if (src == null || src.isEmpty())
164      return null;
165    org.hl7.fhir.dstu2.model.Enumeration<org.hl7.fhir.dstu2.model.Appointment.AppointmentStatus> tgt = new org.hl7.fhir.dstu2.model.Enumeration<>(new org.hl7.fhir.dstu2.model.Appointment.AppointmentStatusEnumFactory());
166    ConversionContext10_50.INSTANCE.getVersionConvertor_10_50().copyElement(src, tgt);
167    switch (src.getValue()) {
168      case PROPOSED:
169        tgt.setValue(org.hl7.fhir.dstu2.model.Appointment.AppointmentStatus.PROPOSED);
170        break;
171      case PENDING:
172        tgt.setValue(org.hl7.fhir.dstu2.model.Appointment.AppointmentStatus.PENDING);
173        break;
174      case BOOKED:
175        tgt.setValue(org.hl7.fhir.dstu2.model.Appointment.AppointmentStatus.BOOKED);
176        break;
177      case ARRIVED:
178        tgt.setValue(org.hl7.fhir.dstu2.model.Appointment.AppointmentStatus.ARRIVED);
179        break;
180      case FULFILLED:
181        tgt.setValue(org.hl7.fhir.dstu2.model.Appointment.AppointmentStatus.FULFILLED);
182        break;
183      case CANCELLED:
184        tgt.setValue(org.hl7.fhir.dstu2.model.Appointment.AppointmentStatus.CANCELLED);
185        break;
186      case NOSHOW:
187        tgt.setValue(org.hl7.fhir.dstu2.model.Appointment.AppointmentStatus.NOSHOW);
188        break;
189      default:
190        tgt.setValue(org.hl7.fhir.dstu2.model.Appointment.AppointmentStatus.NULL);
191        break;
192    }
193    return tgt;
194  }
195
196  static public org.hl7.fhir.dstu2.model.Enumeration<org.hl7.fhir.dstu2.model.Appointment.ParticipantRequired> convertParticipantRequired(org.hl7.fhir.r5.model.BooleanType src) throws FHIRException {
197    if (src == null || src.isEmpty())
198      return null;
199    org.hl7.fhir.dstu2.model.Enumeration<org.hl7.fhir.dstu2.model.Appointment.ParticipantRequired> tgt = new org.hl7.fhir.dstu2.model.Enumeration<>(new org.hl7.fhir.dstu2.model.Appointment.ParticipantRequiredEnumFactory());
200    ConversionContext10_50.INSTANCE.getVersionConvertor_10_50().copyElement(src, tgt);
201    if (src.getValue()) {
202        tgt.setValue(org.hl7.fhir.dstu2.model.Appointment.ParticipantRequired.REQUIRED);
203    } else { //  case OPTIONAL:
204        tgt.setValue(org.hl7.fhir.dstu2.model.Appointment.ParticipantRequired.OPTIONAL);
205    }
206    return tgt;
207  }
208
209  static public org.hl7.fhir.r5.model.BooleanType convertParticipantRequired(org.hl7.fhir.dstu2.model.Enumeration<org.hl7.fhir.dstu2.model.Appointment.ParticipantRequired> src) throws FHIRException {
210    if (src == null || src.isEmpty())
211      return null;
212    org.hl7.fhir.r5.model.BooleanType tgt = new org.hl7.fhir.r5.model.BooleanType();
213    ConversionContext10_50.INSTANCE.getVersionConvertor_10_50().copyElement(src, tgt);
214    switch (src.getValue()) {
215      case REQUIRED:
216        tgt.setValue(true);
217        break;
218      case OPTIONAL:
219        tgt.setValue(false);
220        break;
221      case INFORMATIONONLY:
222        tgt.setValue(false);
223        break;
224      default:
225        break;
226    }
227    return tgt;
228  }
229
230  static public org.hl7.fhir.r5.model.Enumeration<org.hl7.fhir.r5.model.Appointment.ParticipationStatus> convertParticipationStatus(org.hl7.fhir.dstu2.model.Enumeration<org.hl7.fhir.dstu2.model.Appointment.ParticipationStatus> src) throws FHIRException {
231    if (src == null || src.isEmpty())
232      return null;
233    org.hl7.fhir.r5.model.Enumeration<org.hl7.fhir.r5.model.Appointment.ParticipationStatus> tgt = new org.hl7.fhir.r5.model.Enumeration<>(new org.hl7.fhir.r5.model.Appointment.ParticipationStatusEnumFactory());
234    ConversionContext10_50.INSTANCE.getVersionConvertor_10_50().copyElement(src, tgt);
235    switch (src.getValue()) {
236      case ACCEPTED:
237        tgt.setValue(org.hl7.fhir.r5.model.Appointment.ParticipationStatus.ACCEPTED);
238        break;
239      case DECLINED:
240        tgt.setValue(org.hl7.fhir.r5.model.Appointment.ParticipationStatus.DECLINED);
241        break;
242      case TENTATIVE:
243        tgt.setValue(org.hl7.fhir.r5.model.Appointment.ParticipationStatus.TENTATIVE);
244        break;
245      case NEEDSACTION:
246        tgt.setValue(org.hl7.fhir.r5.model.Appointment.ParticipationStatus.NEEDSACTION);
247        break;
248      default:
249        tgt.setValue(org.hl7.fhir.r5.model.Appointment.ParticipationStatus.NULL);
250        break;
251    }
252    return tgt;
253  }
254
255  static public org.hl7.fhir.dstu2.model.Enumeration<org.hl7.fhir.dstu2.model.Appointment.ParticipationStatus> convertParticipationStatus(org.hl7.fhir.r5.model.Enumeration<org.hl7.fhir.r5.model.Appointment.ParticipationStatus> src) throws FHIRException {
256    if (src == null || src.isEmpty())
257      return null;
258    org.hl7.fhir.dstu2.model.Enumeration<org.hl7.fhir.dstu2.model.Appointment.ParticipationStatus> tgt = new org.hl7.fhir.dstu2.model.Enumeration<>(new org.hl7.fhir.dstu2.model.Appointment.ParticipationStatusEnumFactory());
259    ConversionContext10_50.INSTANCE.getVersionConvertor_10_50().copyElement(src, tgt);
260    switch (src.getValue()) {
261      case ACCEPTED:
262        tgt.setValue(org.hl7.fhir.dstu2.model.Appointment.ParticipationStatus.ACCEPTED);
263        break;
264      case DECLINED:
265        tgt.setValue(org.hl7.fhir.dstu2.model.Appointment.ParticipationStatus.DECLINED);
266        break;
267      case TENTATIVE:
268        tgt.setValue(org.hl7.fhir.dstu2.model.Appointment.ParticipationStatus.TENTATIVE);
269        break;
270      case NEEDSACTION:
271        tgt.setValue(org.hl7.fhir.dstu2.model.Appointment.ParticipationStatus.NEEDSACTION);
272        break;
273      default:
274        tgt.setValue(org.hl7.fhir.dstu2.model.Appointment.ParticipationStatus.NULL);
275        break;
276    }
277    return tgt;
278  }
279}