001package org.hl7.fhir.convertors.conv30_40.resources30_40;
002
003import java.util.List;
004
005import org.hl7.fhir.convertors.context.ConversionContext30_40;
006import org.hl7.fhir.convertors.conv30_40.VersionConvertor_30_40;
007import org.hl7.fhir.convertors.conv30_40.datatypes30_40.Reference30_40;
008import org.hl7.fhir.convertors.conv30_40.datatypes30_40.complextypes30_40.CodeableConcept30_40;
009import org.hl7.fhir.convertors.conv30_40.datatypes30_40.complextypes30_40.Coding30_40;
010import org.hl7.fhir.convertors.conv30_40.datatypes30_40.complextypes30_40.Identifier30_40;
011import org.hl7.fhir.convertors.conv30_40.datatypes30_40.primitivetypes30_40.DateTime30_40;
012import org.hl7.fhir.convertors.conv30_40.datatypes30_40.primitivetypes30_40.String30_40;
013import org.hl7.fhir.convertors.conv30_40.datatypes30_40.primitivetypes30_40.UnsignedInt30_40;
014import org.hl7.fhir.dstu3.model.Reference;
015import org.hl7.fhir.exceptions.FHIRException;
016import org.hl7.fhir.r4.model.CodeableConcept;
017
018public class ImagingStudy30_40 {
019
020  private static final String URN_DICOM_UID = "urn:dicom:uid";
021
022  public static org.hl7.fhir.dstu3.model.ImagingStudy convertImagingStudy(org.hl7.fhir.r4.model.ImagingStudy src) throws FHIRException {
023    if (src == null)
024      return null;
025    org.hl7.fhir.dstu3.model.ImagingStudy tgt = new org.hl7.fhir.dstu3.model.ImagingStudy();
026    ConversionContext30_40.INSTANCE.getVersionConvertor_30_40().copyDomainResource(src, tgt);
027    for (org.hl7.fhir.r4.model.Identifier t : src.getIdentifier()) {
028      if (URN_DICOM_UID.equals(t.getSystem())) {
029        tgt.setUid(t.getValue());
030      } else {
031        tgt.addIdentifier(Identifier30_40.convertIdentifier(t));
032      }
033    }
034    if (src.hasStatus()) {
035      org.hl7.fhir.r4.model.ImagingStudy.ImagingStudyStatus s = src.getStatus();
036      switch (s) {
037        case REGISTERED:
038          tgt.setAvailability(org.hl7.fhir.dstu3.model.ImagingStudy.InstanceAvailability.OFFLINE);
039          break;
040        case AVAILABLE:
041          tgt.setAvailability(org.hl7.fhir.dstu3.model.ImagingStudy.InstanceAvailability.ONLINE);
042          break;
043        case CANCELLED:
044          tgt.setAvailability(org.hl7.fhir.dstu3.model.ImagingStudy.InstanceAvailability.UNAVAILABLE);
045          break;
046        default:
047          break;
048      }
049    }
050    for (org.hl7.fhir.r4.model.Coding t : src.getModality()) {
051      tgt.addModalityList(Coding30_40.convertCoding(t));
052    }
053    if (src.hasSubject()) {
054      if (src.hasSubject())
055        tgt.setPatient(Reference30_40.convertReference(src.getSubject()));
056    }
057    if (src.hasEncounter()) {
058      if (src.hasEncounter())
059        tgt.setContext(Reference30_40.convertReference(src.getEncounter()));
060    }
061    if (src.hasStarted()) {
062      if (src.hasStartedElement())
063        tgt.setStartedElement(DateTime30_40.convertDateTime(src.getStartedElement()));
064    }
065    for (org.hl7.fhir.r4.model.Reference t : src.getBasedOn()) {
066      tgt.addBasedOn(Reference30_40.convertReference(t));
067    }
068    if (src.hasReferrer()) {
069      if (src.hasReferrer())
070        tgt.setReferrer(Reference30_40.convertReference(src.getReferrer()));
071    }
072    for (org.hl7.fhir.r4.model.Reference t : src.getInterpreter()) {
073      tgt.addInterpreter(Reference30_40.convertReference(t));
074    }
075    for (org.hl7.fhir.r4.model.Reference t : src.getEndpoint()) {
076      tgt.addEndpoint(Reference30_40.convertReference(t));
077    }
078    if (src.hasNumberOfSeries()) {
079      if (src.hasNumberOfSeriesElement())
080        tgt.setNumberOfSeriesElement(UnsignedInt30_40.convertUnsignedInt(src.getNumberOfSeriesElement()));
081    }
082    if (src.hasNumberOfInstances()) {
083      if (src.hasNumberOfInstancesElement())
084        tgt.setNumberOfInstancesElement(UnsignedInt30_40.convertUnsignedInt(src.getNumberOfInstancesElement()));
085    }
086    if (src.hasProcedureReference()) {
087      if (src.hasProcedureReference())
088        tgt.addProcedureReference(Reference30_40.convertReference(src.getProcedureReference()));
089    }
090    for (org.hl7.fhir.r4.model.CodeableConcept t : src.getProcedureCode()) {
091      tgt.addProcedureCode(CodeableConcept30_40.convertCodeableConcept(t));
092    }
093    List<CodeableConcept> reasonCodes = src.getReasonCode();
094    if (reasonCodes.size() > 0) {
095      tgt.setReason(CodeableConcept30_40.convertCodeableConcept(reasonCodes.get(0)));
096      if (reasonCodes.size() > 1) {
097      }
098    }
099    if (src.hasDescription()) {
100      if (src.hasDescriptionElement())
101        tgt.setDescriptionElement(String30_40.convertString(src.getDescriptionElement()));
102    }
103    for (org.hl7.fhir.r4.model.ImagingStudy.ImagingStudySeriesComponent t : src.getSeries()) {
104      tgt.addSeries(convertImagingStudySeriesComponent(t));
105    }
106    return tgt;
107  }
108
109  public static org.hl7.fhir.r4.model.ImagingStudy convertImagingStudy(org.hl7.fhir.dstu3.model.ImagingStudy src) throws FHIRException {
110    if (src == null)
111      return null;
112    org.hl7.fhir.r4.model.ImagingStudy tgt = new org.hl7.fhir.r4.model.ImagingStudy();
113    ConversionContext30_40.INSTANCE.getVersionConvertor_30_40().copyDomainResource(src, tgt);
114    if (src.hasUid()) {
115      org.hl7.fhir.r4.model.Identifier i = new org.hl7.fhir.r4.model.Identifier();
116      i.setSystem(URN_DICOM_UID);
117      i.setValue(src.getUid());
118      tgt.addIdentifier(i);
119    }
120    for (org.hl7.fhir.dstu3.model.Identifier t : src.getIdentifier()) {
121      tgt.addIdentifier(Identifier30_40.convertIdentifier(t));
122    }
123    if (src.hasAccession())
124      tgt.addIdentifier(Identifier30_40.convertIdentifier(src.getAccession()));
125    if (src.hasAvailability()) {
126      org.hl7.fhir.dstu3.model.ImagingStudy.InstanceAvailability availability = src.getAvailability();
127      switch (availability) {
128        case OFFLINE:
129          tgt.setStatus(org.hl7.fhir.r4.model.ImagingStudy.ImagingStudyStatus.REGISTERED);
130          break;
131        case UNAVAILABLE:
132          tgt.setStatus(org.hl7.fhir.r4.model.ImagingStudy.ImagingStudyStatus.CANCELLED);
133          break;
134        case ONLINE:
135        case NEARLINE:
136          tgt.setStatus(org.hl7.fhir.r4.model.ImagingStudy.ImagingStudyStatus.AVAILABLE);
137          break;
138        default:
139          break;
140      }
141    } else {
142      tgt.setStatus(org.hl7.fhir.r4.model.ImagingStudy.ImagingStudyStatus.UNKNOWN);
143    }
144    for (org.hl7.fhir.dstu3.model.Coding t : src.getModalityList()) {
145      tgt.addModality(Coding30_40.convertCoding(t));
146    }
147    if (src.hasPatient())
148      tgt.setSubject(Reference30_40.convertReference(src.getPatient()));
149    if (src.hasContext()) {
150      if (src.hasContext())
151        tgt.setEncounter(Reference30_40.convertReference(src.getContext()));
152    }
153    if (src.hasStarted()) {
154      if (src.hasStartedElement())
155        tgt.setStartedElement(DateTime30_40.convertDateTime(src.getStartedElement()));
156    }
157    for (org.hl7.fhir.dstu3.model.Reference t : src.getBasedOn()) {
158      tgt.addBasedOn(Reference30_40.convertReference(t));
159    }
160    if (src.hasReferrer()) {
161      if (src.hasReferrer())
162        tgt.setReferrer(Reference30_40.convertReference(src.getReferrer()));
163    }
164    for (org.hl7.fhir.dstu3.model.Reference t : src.getInterpreter()) {
165      tgt.addInterpreter(Reference30_40.convertReference(t));
166    }
167    for (org.hl7.fhir.dstu3.model.Reference t : src.getEndpoint()) {
168      tgt.addEndpoint(Reference30_40.convertReference(t));
169    }
170    if (src.hasNumberOfSeries()) {
171      if (src.hasNumberOfSeriesElement())
172        tgt.setNumberOfSeriesElement(UnsignedInt30_40.convertUnsignedInt(src.getNumberOfSeriesElement()));
173    }
174    if (src.hasNumberOfInstances()) {
175      if (src.hasNumberOfInstancesElement())
176        tgt.setNumberOfInstancesElement(UnsignedInt30_40.convertUnsignedInt(src.getNumberOfInstancesElement()));
177    }
178    List<Reference> procedureReferences = src.getProcedureReference();
179    if (procedureReferences.size() > 0) {
180      tgt.setProcedureReference(Reference30_40.convertReference(procedureReferences.get(0)));
181      if (procedureReferences.size() > 1) {
182      }
183    }
184    for (org.hl7.fhir.dstu3.model.CodeableConcept t : src.getProcedureCode()) {
185      tgt.addProcedureCode(CodeableConcept30_40.convertCodeableConcept(t));
186    }
187    if (src.hasReason()) {
188      if (src.hasReason())
189        tgt.addReasonCode(CodeableConcept30_40.convertCodeableConcept(src.getReason()));
190    }
191    if (src.hasDescription()) {
192      if (src.hasDescriptionElement())
193        tgt.setDescriptionElement(String30_40.convertString(src.getDescriptionElement()));
194    }
195    for (org.hl7.fhir.dstu3.model.ImagingStudy.ImagingStudySeriesComponent t : src.getSeries()) {
196      tgt.addSeries(convertImagingStudySeriesComponent(t));
197    }
198    return tgt;
199  }
200
201  public static org.hl7.fhir.r4.model.ImagingStudy.ImagingStudySeriesComponent convertImagingStudySeriesComponent(org.hl7.fhir.dstu3.model.ImagingStudy.ImagingStudySeriesComponent src) throws FHIRException {
202    if (src == null)
203      return null;
204    org.hl7.fhir.r4.model.ImagingStudy.ImagingStudySeriesComponent tgt = new org.hl7.fhir.r4.model.ImagingStudy.ImagingStudySeriesComponent();
205    ConversionContext30_40.INSTANCE.getVersionConvertor_30_40().copyBackboneElement(src,tgt);
206    if (src.hasUid()) {
207      if (src.hasUid())
208        tgt.setUid(src.getUid());
209    }
210    if (src.hasNumber()) {
211      if (src.hasNumberElement())
212        tgt.setNumberElement(UnsignedInt30_40.convertUnsignedInt(src.getNumberElement()));
213    }
214    if (src.hasModality()) {
215      if (src.hasModality())
216        tgt.setModality(Coding30_40.convertCoding(src.getModality()));
217    }
218    if (src.hasDescription()) {
219      if (src.hasDescriptionElement())
220        tgt.setDescriptionElement(String30_40.convertString(src.getDescriptionElement()));
221    }
222    if (src.hasNumberOfInstances()) {
223      if (src.hasNumberOfInstancesElement())
224        tgt.setNumberOfInstancesElement(UnsignedInt30_40.convertUnsignedInt(src.getNumberOfInstancesElement()));
225    }
226    for (org.hl7.fhir.dstu3.model.Reference t : src.getEndpoint()) {
227      tgt.addEndpoint(Reference30_40.convertReference(t));
228    }
229    if (src.hasBodySite()) {
230      if (src.hasBodySite())
231        tgt.setBodySite(Coding30_40.convertCoding(src.getBodySite()));
232    }
233    if (src.hasLaterality()) {
234      if (src.hasLaterality())
235        tgt.setLaterality(Coding30_40.convertCoding(src.getLaterality()));
236    }
237    if (src.hasStarted()) {
238      if (src.hasStartedElement())
239        tgt.setStartedElement(DateTime30_40.convertDateTime(src.getStartedElement()));
240    }
241    for (org.hl7.fhir.dstu3.model.ImagingStudy.ImagingStudySeriesInstanceComponent t : src.getInstance()) {
242      tgt.addInstance(convertImagingStudySeriesInstanceComponent(t));
243    }
244    return tgt;
245  }
246
247  public static org.hl7.fhir.dstu3.model.ImagingStudy.ImagingStudySeriesComponent convertImagingStudySeriesComponent(org.hl7.fhir.r4.model.ImagingStudy.ImagingStudySeriesComponent src) throws FHIRException {
248    if (src == null)
249      return null;
250    org.hl7.fhir.dstu3.model.ImagingStudy.ImagingStudySeriesComponent tgt = new org.hl7.fhir.dstu3.model.ImagingStudy.ImagingStudySeriesComponent();
251    ConversionContext30_40.INSTANCE.getVersionConvertor_30_40().copyBackboneElement(src,tgt);
252    if (src.hasUid()) {
253      if (src.hasUid())
254        tgt.setUid(src.getUid());
255    }
256    if (src.hasNumber()) {
257      if (src.hasNumberElement())
258        tgt.setNumberElement(UnsignedInt30_40.convertUnsignedInt(src.getNumberElement()));
259    }
260    if (src.hasModality()) {
261      if (src.hasModality())
262        tgt.setModality(Coding30_40.convertCoding(src.getModality()));
263    }
264    if (src.hasDescription()) {
265      if (src.hasDescriptionElement())
266        tgt.setDescriptionElement(String30_40.convertString(src.getDescriptionElement()));
267    }
268    if (src.hasNumberOfInstances()) {
269      if (src.hasNumberOfInstancesElement())
270        tgt.setNumberOfInstancesElement(UnsignedInt30_40.convertUnsignedInt(src.getNumberOfInstancesElement()));
271    }
272    for (org.hl7.fhir.r4.model.Reference t : src.getEndpoint()) {
273      tgt.addEndpoint(Reference30_40.convertReference(t));
274    }
275    if (src.hasBodySite()) {
276      if (src.hasBodySite())
277        tgt.setBodySite(Coding30_40.convertCoding(src.getBodySite()));
278    }
279    if (src.hasLaterality()) {
280      if (src.hasLaterality())
281        tgt.setLaterality(Coding30_40.convertCoding(src.getLaterality()));
282    }
283    if (src.hasStarted()) {
284      if (src.hasStartedElement())
285        tgt.setStartedElement(DateTime30_40.convertDateTime(src.getStartedElement()));
286    }
287    for (org.hl7.fhir.r4.model.ImagingStudy.ImagingStudySeriesInstanceComponent t : src.getInstance()) {
288      tgt.addInstance(convertImagingStudySeriesInstanceComponent(t));
289    }
290    return tgt;
291  }
292
293  static public org.hl7.fhir.r4.model.ImagingStudy.ImagingStudySeriesInstanceComponent convertImagingStudySeriesInstanceComponent(org.hl7.fhir.dstu3.model.ImagingStudy.ImagingStudySeriesInstanceComponent src) throws FHIRException {
294    if (src == null)
295      return null;
296    org.hl7.fhir.r4.model.ImagingStudy.ImagingStudySeriesInstanceComponent tgt = new org.hl7.fhir.r4.model.ImagingStudy.ImagingStudySeriesInstanceComponent();
297    ConversionContext30_40.INSTANCE.getVersionConvertor_30_40().copyBackboneElement(src,tgt);
298    if (src.hasUid()) {
299      if (src.hasUid())
300        tgt.setUid(src.getUid());
301    }
302    if (src.hasSopClass()) {
303      org.hl7.fhir.r4.model.Coding c = new org.hl7.fhir.r4.model.Coding();
304      c.setSystem(VersionConvertor_30_40.URN_IETF_RFC_3986);
305      c.setCode(src.getSopClass());
306      tgt.setSopClass(c);
307    }
308    if (src.hasNumber()) {
309      if (src.hasNumberElement())
310        tgt.setNumberElement(UnsignedInt30_40.convertUnsignedInt(src.getNumberElement()));
311    }
312    if (src.hasTitle()) {
313      if (src.hasTitleElement())
314        tgt.setTitleElement(String30_40.convertString(src.getTitleElement()));
315    }
316    return tgt;
317  }
318
319  static public org.hl7.fhir.dstu3.model.ImagingStudy.ImagingStudySeriesInstanceComponent convertImagingStudySeriesInstanceComponent(org.hl7.fhir.r4.model.ImagingStudy.ImagingStudySeriesInstanceComponent src) throws FHIRException {
320    if (src == null)
321      return null;
322    org.hl7.fhir.dstu3.model.ImagingStudy.ImagingStudySeriesInstanceComponent tgt = new org.hl7.fhir.dstu3.model.ImagingStudy.ImagingStudySeriesInstanceComponent();
323    ConversionContext30_40.INSTANCE.getVersionConvertor_30_40().copyBackboneElement(src,tgt);
324    if (src.hasUid()) {
325      if (src.hasUid())
326        tgt.setUid(src.getUid());
327    }
328    org.hl7.fhir.r4.model.Coding sop = src.getSopClass();
329    if (VersionConvertor_30_40.URN_IETF_RFC_3986.equals(sop.getSystem())) {
330      tgt.setSopClass(sop.getCode());
331    }
332    if (src.hasNumber()) {
333      if (src.hasNumberElement())
334        tgt.setNumberElement(UnsignedInt30_40.convertUnsignedInt(src.getNumberElement()));
335    }
336    if (src.hasTitle()) {
337      if (src.hasTitleElement())
338        tgt.setTitleElement(String30_40.convertString(src.getTitleElement()));
339    }
340    return tgt;
341  }
342}