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