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.*;
006import org.hl7.fhir.convertors.conv30_50.datatypes30_50.primitivetypes30_50.String30_50;
007import org.hl7.fhir.exceptions.FHIRException;
008import org.hl7.fhir.r5.model.DocumentReference.DocumentAttestationMode;
009import org.hl7.fhir.r5.model.DocumentReference.DocumentReferenceAttesterComponent;
010
011public class DocumentReference30_50 {
012
013  public static org.hl7.fhir.r5.model.DocumentReference convertDocumentReference(org.hl7.fhir.dstu3.model.DocumentReference src) throws FHIRException {
014    if (src == null)
015      return null;
016    org.hl7.fhir.r5.model.DocumentReference tgt = new org.hl7.fhir.r5.model.DocumentReference();
017    ConversionContext30_50.INSTANCE.getVersionConvertor_30_50().copyDomainResource(src, tgt);
018    if (src.hasMasterIdentifier())
019      tgt.addIdentifier(Identifier30_50.convertIdentifier(src.getMasterIdentifier()));
020    for (org.hl7.fhir.dstu3.model.Identifier t : src.getIdentifier())
021      tgt.addIdentifier(Identifier30_50.convertIdentifier(t));
022    if (src.hasStatus())
023      tgt.setStatusElement(convertDocumentReferenceStatus(src.getStatusElement()));
024    if (src.hasDocStatus())
025      tgt.setDocStatusElement(convertReferredDocumentStatus(src.getDocStatusElement()));
026    if (src.hasType())
027      tgt.setType(CodeableConcept30_50.convertCodeableConcept(src.getType()));
028    if (src.hasClass_())
029      tgt.addCategory(CodeableConcept30_50.convertCodeableConcept(src.getClass_()));
030    if (src.hasSubject())
031      tgt.setSubject(Reference30_50.convertReference(src.getSubject()));
032    if (src.hasCreated())
033      tgt.setDate(src.getCreated());
034    if (src.hasAuthenticator())
035      tgt.addAttester().setMode(DocumentAttestationMode.OFFICIAL).setParty(Reference30_50.convertReference(src.getAuthenticator()));
036    if (src.hasCustodian())
037      tgt.setCustodian(Reference30_50.convertReference(src.getCustodian()));
038    for (org.hl7.fhir.dstu3.model.DocumentReference.DocumentReferenceRelatesToComponent t : src.getRelatesTo())
039      tgt.addRelatesTo(convertDocumentReferenceRelatesToComponent(t));
040    if (src.hasDescription())
041      tgt.setDescriptionElement(String30_50.convertStringToMarkdown(src.getDescriptionElement()));
042    for (org.hl7.fhir.dstu3.model.CodeableConcept t : src.getSecurityLabel())
043      tgt.addSecurityLabel(CodeableConcept30_50.convertCodeableConcept(t));
044    for (org.hl7.fhir.dstu3.model.DocumentReference.DocumentReferenceContentComponent t : src.getContent())
045      tgt.addContent(convertDocumentReferenceContentComponent(t));
046    if (src.hasContext())
047      convertDocumentReferenceContextComponent(src.getContext(), tgt);
048    return tgt;
049  }
050
051  public static org.hl7.fhir.dstu3.model.DocumentReference convertDocumentReference(org.hl7.fhir.r5.model.DocumentReference src) throws FHIRException {
052    if (src == null)
053      return null;
054    org.hl7.fhir.dstu3.model.DocumentReference tgt = new org.hl7.fhir.dstu3.model.DocumentReference();
055    ConversionContext30_50.INSTANCE.getVersionConvertor_30_50().copyDomainResource(src, tgt);
056    //        if (src.hasMasterIdentifier())
057    //            tgt.setMasterIdentifier(VersionConvertor_30_50.convertIdentifier(src.getMasterIdentifier()));
058    for (org.hl7.fhir.r5.model.Identifier t : src.getIdentifier())
059      tgt.addIdentifier(Identifier30_50.convertIdentifier(t));
060    if (src.hasStatus())
061      tgt.setStatusElement(convertDocumentReferenceStatus(src.getStatusElement()));
062    if (src.hasDocStatus())
063      tgt.setDocStatusElement(convertReferredDocumentStatus(src.getDocStatusElement()));
064    if (src.hasType())
065      tgt.setType(CodeableConcept30_50.convertCodeableConcept(src.getType()));
066    if (src.hasCategory())
067      tgt.setClass_(CodeableConcept30_50.convertCodeableConcept(src.getCategoryFirstRep()));
068    if (src.hasSubject())
069      tgt.setSubject(Reference30_50.convertReference(src.getSubject()));
070    if (src.hasDate())
071      tgt.setCreated(src.getDate());
072    for (DocumentReferenceAttesterComponent t : src.getAttester()) {
073      if (t.getMode() == DocumentAttestationMode.OFFICIAL)
074        tgt.setAuthenticator(Reference30_50.convertReference(t.getParty()));
075    }
076    if (src.hasCustodian())
077      tgt.setCustodian(Reference30_50.convertReference(src.getCustodian()));
078    for (org.hl7.fhir.r5.model.DocumentReference.DocumentReferenceRelatesToComponent t : src.getRelatesTo())
079      tgt.addRelatesTo(convertDocumentReferenceRelatesToComponent(t));
080    if (src.hasDescription())
081      tgt.setDescriptionElement(String30_50.convertString(src.getDescriptionElement()));
082    for (org.hl7.fhir.r5.model.CodeableConcept t : src.getSecurityLabel())
083      tgt.addSecurityLabel(CodeableConcept30_50.convertCodeableConcept(t));
084    for (org.hl7.fhir.r5.model.DocumentReference.DocumentReferenceContentComponent t : src.getContent())
085      tgt.addContent(convertDocumentReferenceContentComponent(t));
086    convertDocumentReferenceContextComponent(src, tgt.getContext());
087    return tgt;
088  }
089
090  public static org.hl7.fhir.dstu3.model.DocumentReference.DocumentReferenceContentComponent convertDocumentReferenceContentComponent(org.hl7.fhir.r5.model.DocumentReference.DocumentReferenceContentComponent src) throws FHIRException {
091    if (src == null)
092      return null;
093    org.hl7.fhir.dstu3.model.DocumentReference.DocumentReferenceContentComponent tgt = new org.hl7.fhir.dstu3.model.DocumentReference.DocumentReferenceContentComponent();
094    ConversionContext30_50.INSTANCE.getVersionConvertor_30_50().copyElement(src, tgt);
095    if (src.hasAttachment())
096      tgt.setAttachment(Attachment30_50.convertAttachment(src.getAttachment()));
097    if (src.hasFormat())
098      tgt.setFormat(Coding30_50.convertCoding(src.getFormat()));
099    return tgt;
100  }
101
102  public static org.hl7.fhir.r5.model.DocumentReference.DocumentReferenceContentComponent convertDocumentReferenceContentComponent(org.hl7.fhir.dstu3.model.DocumentReference.DocumentReferenceContentComponent src) throws FHIRException {
103    if (src == null)
104      return null;
105    org.hl7.fhir.r5.model.DocumentReference.DocumentReferenceContentComponent tgt = new org.hl7.fhir.r5.model.DocumentReference.DocumentReferenceContentComponent();
106    ConversionContext30_50.INSTANCE.getVersionConvertor_30_50().copyElement(src, tgt);
107    if (src.hasAttachment())
108      tgt.setAttachment(Attachment30_50.convertAttachment(src.getAttachment()));
109    if (src.hasFormat())
110      tgt.setFormat(Coding30_50.convertCoding(src.getFormat()));
111    return tgt;
112  }
113
114  public static void convertDocumentReferenceContextComponent(org.hl7.fhir.r5.model.DocumentReference src, org.hl7.fhir.dstu3.model.DocumentReference.DocumentReferenceContextComponent tgt) throws FHIRException {
115    if (src.hasEncounter())
116      tgt.setEncounter(Reference30_50.convertReference(src.getEncounterFirstRep()));
117    for (org.hl7.fhir.r5.model.CodeableConcept t : src.getEvent())
118      tgt.addEvent(CodeableConcept30_50.convertCodeableConcept(t));
119    if (src.hasPeriod())
120      tgt.setPeriod(Period30_50.convertPeriod(src.getPeriod()));
121    if (src.hasFacilityType())
122      tgt.setFacilityType(CodeableConcept30_50.convertCodeableConcept(src.getFacilityType()));
123    if (src.hasPracticeSetting())
124      tgt.setPracticeSetting(CodeableConcept30_50.convertCodeableConcept(src.getPracticeSetting()));
125    if (src.hasSourcePatientInfo())
126      tgt.setSourcePatientInfo(Reference30_50.convertReference(src.getSourcePatientInfo()));
127    for (org.hl7.fhir.r5.model.Reference t : src.getRelated())
128      tgt.addRelated(convertDocumentReferenceContextRelatedComponent(t));
129  }
130
131  public static void convertDocumentReferenceContextComponent(org.hl7.fhir.dstu3.model.DocumentReference.DocumentReferenceContextComponent src, org.hl7.fhir.r5.model.DocumentReference tgt) throws FHIRException {
132    if (src.hasEncounter())
133      tgt.addEncounter(Reference30_50.convertReference(src.getEncounter()));
134    for (org.hl7.fhir.dstu3.model.CodeableConcept t : src.getEvent())
135      tgt.addEvent(CodeableConcept30_50.convertCodeableConcept(t));
136    if (src.hasPeriod())
137      tgt.setPeriod(Period30_50.convertPeriod(src.getPeriod()));
138    if (src.hasFacilityType())
139      tgt.setFacilityType(CodeableConcept30_50.convertCodeableConcept(src.getFacilityType()));
140    if (src.hasPracticeSetting())
141      tgt.setPracticeSetting(CodeableConcept30_50.convertCodeableConcept(src.getPracticeSetting()));
142    if (src.hasSourcePatientInfo())
143      tgt.setSourcePatientInfo(Reference30_50.convertReference(src.getSourcePatientInfo()));
144    for (org.hl7.fhir.dstu3.model.DocumentReference.DocumentReferenceContextRelatedComponent t : src.getRelated())
145      tgt.addRelated(convertDocumentReferenceContextRelatedComponent(t));
146  }
147
148  public static org.hl7.fhir.r5.model.Reference convertDocumentReferenceContextRelatedComponent(org.hl7.fhir.dstu3.model.DocumentReference.DocumentReferenceContextRelatedComponent src) throws FHIRException {
149    if (src == null)
150      return null;
151    org.hl7.fhir.r5.model.Reference tgt = Reference30_50.convertReference(src.getRef());
152    ConversionContext30_50.INSTANCE.getVersionConvertor_30_50().copyElement(src, tgt);
153    if (src.hasIdentifier())
154      tgt.setIdentifier(Identifier30_50.convertIdentifier(src.getIdentifier()));
155    return tgt;
156  }
157
158  public static org.hl7.fhir.dstu3.model.DocumentReference.DocumentReferenceContextRelatedComponent convertDocumentReferenceContextRelatedComponent(org.hl7.fhir.r5.model.Reference src) throws FHIRException {
159    if (src == null)
160      return null;
161    org.hl7.fhir.dstu3.model.DocumentReference.DocumentReferenceContextRelatedComponent tgt = new org.hl7.fhir.dstu3.model.DocumentReference.DocumentReferenceContextRelatedComponent();
162    ConversionContext30_50.INSTANCE.getVersionConvertor_30_50().copyElement(src, tgt);
163    if (src.hasIdentifier())
164      tgt.setIdentifier(Identifier30_50.convertIdentifier(src.getIdentifier()));
165    tgt.setRef(Reference30_50.convertReference(src));
166    return tgt;
167  }
168
169  public static org.hl7.fhir.r5.model.DocumentReference.DocumentReferenceRelatesToComponent convertDocumentReferenceRelatesToComponent(org.hl7.fhir.dstu3.model.DocumentReference.DocumentReferenceRelatesToComponent src) throws FHIRException {
170    if (src == null)
171      return null;
172    org.hl7.fhir.r5.model.DocumentReference.DocumentReferenceRelatesToComponent tgt = new org.hl7.fhir.r5.model.DocumentReference.DocumentReferenceRelatesToComponent();
173    ConversionContext30_50.INSTANCE.getVersionConvertor_30_50().copyElement(src, tgt);
174    if (src.hasCode())
175      tgt.setCode(convertDocumentRelationshipType(src.getCodeElement()));
176    if (src.hasTarget())
177      tgt.setTarget(Reference30_50.convertReference(src.getTarget()));
178    return tgt;
179  }
180
181  public static org.hl7.fhir.dstu3.model.DocumentReference.DocumentReferenceRelatesToComponent convertDocumentReferenceRelatesToComponent(org.hl7.fhir.r5.model.DocumentReference.DocumentReferenceRelatesToComponent src) throws FHIRException {
182    if (src == null)
183      return null;
184    org.hl7.fhir.dstu3.model.DocumentReference.DocumentReferenceRelatesToComponent tgt = new org.hl7.fhir.dstu3.model.DocumentReference.DocumentReferenceRelatesToComponent();
185    ConversionContext30_50.INSTANCE.getVersionConvertor_30_50().copyElement(src, tgt);
186    if (src.hasCode())
187      tgt.setCodeElement(convertDocumentRelationshipType2(src.getCode()));
188    if (src.hasTarget())
189      tgt.setTarget(Reference30_50.convertReference(src.getTarget()));
190    return tgt;
191  }
192
193  static public org.hl7.fhir.dstu3.model.Enumeration<org.hl7.fhir.dstu3.model.Enumerations.DocumentReferenceStatus> convertDocumentReferenceStatus(org.hl7.fhir.r5.model.Enumeration<org.hl7.fhir.r5.model.Enumerations.DocumentReferenceStatus> src) throws FHIRException {
194    if (src == null || src.isEmpty())
195      return null;
196    org.hl7.fhir.dstu3.model.Enumeration<org.hl7.fhir.dstu3.model.Enumerations.DocumentReferenceStatus> tgt = new org.hl7.fhir.dstu3.model.Enumeration<>(new org.hl7.fhir.dstu3.model.Enumerations.DocumentReferenceStatusEnumFactory());
197    ConversionContext30_50.INSTANCE.getVersionConvertor_30_50().copyElement(src, tgt);
198    switch (src.getValue()) {
199    case CURRENT:
200      tgt.setValue(org.hl7.fhir.dstu3.model.Enumerations.DocumentReferenceStatus.CURRENT);
201      break;
202    case SUPERSEDED:
203      tgt.setValue(org.hl7.fhir.dstu3.model.Enumerations.DocumentReferenceStatus.SUPERSEDED);
204      break;
205    case ENTEREDINERROR:
206      tgt.setValue(org.hl7.fhir.dstu3.model.Enumerations.DocumentReferenceStatus.ENTEREDINERROR);
207      break;
208    default:
209      tgt.setValue(org.hl7.fhir.dstu3.model.Enumerations.DocumentReferenceStatus.NULL);
210      break;
211    }
212    return tgt;
213  }
214
215  static public org.hl7.fhir.r5.model.Enumeration<org.hl7.fhir.r5.model.Enumerations.DocumentReferenceStatus> convertDocumentReferenceStatus(org.hl7.fhir.dstu3.model.Enumeration<org.hl7.fhir.dstu3.model.Enumerations.DocumentReferenceStatus> src) throws FHIRException {
216    if (src == null || src.isEmpty())
217      return null;
218    org.hl7.fhir.r5.model.Enumeration<org.hl7.fhir.r5.model.Enumerations.DocumentReferenceStatus> tgt = new org.hl7.fhir.r5.model.Enumeration<>(new org.hl7.fhir.r5.model.Enumerations.DocumentReferenceStatusEnumFactory());
219    ConversionContext30_50.INSTANCE.getVersionConvertor_30_50().copyElement(src, tgt);
220    switch (src.getValue()) {
221    case CURRENT:
222      tgt.setValue(org.hl7.fhir.r5.model.Enumerations.DocumentReferenceStatus.CURRENT);
223      break;
224    case SUPERSEDED:
225      tgt.setValue(org.hl7.fhir.r5.model.Enumerations.DocumentReferenceStatus.SUPERSEDED);
226      break;
227    case ENTEREDINERROR:
228      tgt.setValue(org.hl7.fhir.r5.model.Enumerations.DocumentReferenceStatus.ENTEREDINERROR);
229      break;
230    default:
231      tgt.setValue(org.hl7.fhir.r5.model.Enumerations.DocumentReferenceStatus.NULL);
232      break;
233    }
234    return tgt;
235  }
236
237  static public org.hl7.fhir.dstu3.model.Enumeration<org.hl7.fhir.dstu3.model.DocumentReference.DocumentRelationshipType> convertDocumentRelationshipType2(org.hl7.fhir.r5.model.CodeableConcept src) throws FHIRException {
238    if (src == null || src.isEmpty())
239      return null;
240    org.hl7.fhir.dstu3.model.Enumeration<org.hl7.fhir.dstu3.model.DocumentReference.DocumentRelationshipType> tgt = new org.hl7.fhir.dstu3.model.Enumeration<>(new org.hl7.fhir.dstu3.model.DocumentReference.DocumentRelationshipTypeEnumFactory());
241    ConversionContext30_50.INSTANCE.getVersionConvertor_30_50().copyElement(src, tgt);
242    switch (src.getCode("http://hl7.org/fhir/document-relationship-type")) {
243    case "replaces":
244      tgt.setValue(org.hl7.fhir.dstu3.model.DocumentReference.DocumentRelationshipType.REPLACES);
245      break;
246    case "transforms":
247      tgt.setValue(org.hl7.fhir.dstu3.model.DocumentReference.DocumentRelationshipType.TRANSFORMS);
248      break;
249    case "signs":
250      tgt.setValue(org.hl7.fhir.dstu3.model.DocumentReference.DocumentRelationshipType.SIGNS);
251      break;
252    case "appends":
253      tgt.setValue(org.hl7.fhir.dstu3.model.DocumentReference.DocumentRelationshipType.APPENDS);
254      break;
255    default:
256      tgt.setValue(org.hl7.fhir.dstu3.model.DocumentReference.DocumentRelationshipType.NULL);
257      break;
258    }
259
260    return tgt;
261  }
262
263  static public org.hl7.fhir.dstu3.model.Enumeration<org.hl7.fhir.dstu3.model.DocumentReference.ReferredDocumentStatus> convertReferredDocumentStatus(org.hl7.fhir.r5.model.Enumeration<org.hl7.fhir.r5.model.Enumerations.CompositionStatus> src) throws FHIRException {
264    if (src == null || src.isEmpty())
265      return null;
266    org.hl7.fhir.dstu3.model.Enumeration<org.hl7.fhir.dstu3.model.DocumentReference.ReferredDocumentStatus> tgt = new org.hl7.fhir.dstu3.model.Enumeration<>(new org.hl7.fhir.dstu3.model.DocumentReference.ReferredDocumentStatusEnumFactory());
267    ConversionContext30_50.INSTANCE.getVersionConvertor_30_50().copyElement(src, tgt);
268    switch (src.getValue()) {
269    case PRELIMINARY:
270      tgt.setValue(org.hl7.fhir.dstu3.model.DocumentReference.ReferredDocumentStatus.PRELIMINARY);
271      break;
272    case FINAL:
273      tgt.setValue(org.hl7.fhir.dstu3.model.DocumentReference.ReferredDocumentStatus.FINAL);
274      break;
275    case AMENDED:
276      tgt.setValue(org.hl7.fhir.dstu3.model.DocumentReference.ReferredDocumentStatus.AMENDED);
277      break;
278    case ENTEREDINERROR:
279      tgt.setValue(org.hl7.fhir.dstu3.model.DocumentReference.ReferredDocumentStatus.ENTEREDINERROR);
280      break;
281    default:
282      tgt.setValue(org.hl7.fhir.dstu3.model.DocumentReference.ReferredDocumentStatus.NULL);
283      break;
284    }
285    return tgt;
286  }
287
288  static public org.hl7.fhir.r5.model.Enumeration<org.hl7.fhir.r5.model.Enumerations.CompositionStatus> convertReferredDocumentStatus(org.hl7.fhir.dstu3.model.Enumeration<org.hl7.fhir.dstu3.model.DocumentReference.ReferredDocumentStatus> src) throws FHIRException {
289    if (src == null || src.isEmpty())
290      return null;
291    org.hl7.fhir.r5.model.Enumeration<org.hl7.fhir.r5.model.Enumerations.CompositionStatus> tgt = new org.hl7.fhir.r5.model.Enumeration<>(new org.hl7.fhir.r5.model.Enumerations.CompositionStatusEnumFactory());
292    ConversionContext30_50.INSTANCE.getVersionConvertor_30_50().copyElement(src, tgt);
293    switch (src.getValue()) {
294    case PRELIMINARY:
295      tgt.setValue(org.hl7.fhir.r5.model.Enumerations.CompositionStatus.PRELIMINARY);
296      break;
297    case FINAL:
298      tgt.setValue(org.hl7.fhir.r5.model.Enumerations.CompositionStatus.FINAL);
299      break;
300    case AMENDED:
301      tgt.setValue(org.hl7.fhir.r5.model.Enumerations.CompositionStatus.AMENDED);
302      break;
303    case ENTEREDINERROR:
304      tgt.setValue(org.hl7.fhir.r5.model.Enumerations.CompositionStatus.ENTEREDINERROR);
305      break;
306    default:
307      tgt.setValue(org.hl7.fhir.r5.model.Enumerations.CompositionStatus.NULL);
308      break;
309    }
310    return tgt;
311  }
312
313  static public org.hl7.fhir.r5.model.CodeableConcept convertDocumentRelationshipType(org.hl7.fhir.dstu3.model.Enumeration<org.hl7.fhir.dstu3.model.DocumentReference.DocumentRelationshipType> src) throws FHIRException {
314    if (src == null || src.isEmpty()) return null;
315    org.hl7.fhir.r5.model.CodeableConcept tgt = new org.hl7.fhir.r5.model.CodeableConcept();
316    ConversionContext30_50.INSTANCE.getVersionConvertor_30_50().copyElement(src, tgt);
317    if (src.getValue() == null) {
318    } else {
319      switch (src.getValue()) {
320      case REPLACES:
321        tgt.addCoding().setSystem("http://hl7.org/fhir/document-relationship-type").setCode("replaces");
322        break;
323      case TRANSFORMS:
324        tgt.addCoding().setSystem("http://hl7.org/fhir/document-relationship-type").setCode("transforms");
325        break;
326      case SIGNS:
327        tgt.addCoding().setSystem("http://hl7.org/fhir/document-relationship-type").setCode("signs");
328        break;
329      case APPENDS:
330        tgt.addCoding().setSystem("http://hl7.org/fhir/document-relationship-type").setCode("appends");
331        break;
332      default:
333        break;
334      }
335
336    }
337    return tgt;
338  }
339}