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