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