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