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.Extension10_40;
005import org.hl7.fhir.convertors.conv10_40.datatypes10_40.Reference10_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.Identifier10_40;
008import org.hl7.fhir.convertors.conv10_40.datatypes10_40.primitivetypes10_40.Boolean10_40;
009import org.hl7.fhir.convertors.conv10_40.datatypes10_40.primitivetypes10_40.DateTime10_40;
010import org.hl7.fhir.convertors.conv10_40.datatypes10_40.primitivetypes10_40.String10_40;
011import org.hl7.fhir.exceptions.FHIRException;
012
013public class List10_40 {
014
015  public static org.hl7.fhir.r4.model.ListResource convertList(org.hl7.fhir.dstu2.model.List_ src) throws FHIRException {
016    if (src == null || src.isEmpty())
017      return null;
018    org.hl7.fhir.r4.model.ListResource tgt = new org.hl7.fhir.r4.model.ListResource();
019    ConversionContext10_40.INSTANCE.getVersionConvertor_10_40().copyDomainResource(src, tgt);
020    for (org.hl7.fhir.dstu2.model.Identifier t : src.getIdentifier())
021      tgt.addIdentifier(Identifier10_40.convertIdentifier(t));
022    if (src.hasTitleElement())
023      tgt.setTitleElement(String10_40.convertString(src.getTitleElement()));
024    if (src.hasCode())
025      tgt.setCode(CodeableConcept10_40.convertCodeableConcept(src.getCode()));
026    if (src.hasSubject())
027      tgt.setSubject(Reference10_40.convertReference(src.getSubject()));
028    if (src.hasSource())
029      tgt.setSource(Reference10_40.convertReference(src.getSource()));
030    if (src.hasEncounter())
031      tgt.setEncounter(Reference10_40.convertReference(src.getEncounter()));
032    if (src.hasStatus())
033      tgt.setStatusElement(convertListStatus(src.getStatusElement()));
034    if (src.hasDate())
035      tgt.setDateElement(DateTime10_40.convertDateTime(src.getDateElement()));
036    if (src.hasOrderedBy())
037      tgt.setOrderedBy(CodeableConcept10_40.convertCodeableConcept(src.getOrderedBy()));
038    if (src.hasMode())
039      tgt.setModeElement(convertListMode(src.getModeElement()));
040    if (src.hasNote())
041      tgt.addNote(new org.hl7.fhir.r4.model.Annotation().setText(src.getNote()));
042    for (org.hl7.fhir.dstu2.model.List_.ListEntryComponent t : src.getEntry()) tgt.addEntry(convertListEntry(t));
043    return tgt;
044  }
045
046  public static org.hl7.fhir.dstu2.model.List_ convertList(org.hl7.fhir.r4.model.ListResource src) throws FHIRException {
047    if (src == null || src.isEmpty())
048      return null;
049    org.hl7.fhir.dstu2.model.List_ tgt = new org.hl7.fhir.dstu2.model.List_();
050    ConversionContext10_40.INSTANCE.getVersionConvertor_10_40().copyDomainResource(src, tgt);
051    for (org.hl7.fhir.r4.model.Identifier t : src.getIdentifier())
052      tgt.addIdentifier(Identifier10_40.convertIdentifier(t));
053    if (src.hasTitleElement())
054      tgt.setTitleElement(String10_40.convertString(src.getTitleElement()));
055    if (src.hasCode())
056      tgt.setCode(CodeableConcept10_40.convertCodeableConcept(src.getCode()));
057    if (src.hasSubject())
058      tgt.setSubject(Reference10_40.convertReference(src.getSubject()));
059    if (src.hasSource())
060      tgt.setSource(Reference10_40.convertReference(src.getSource()));
061    if (src.hasEncounter())
062      tgt.setEncounter(Reference10_40.convertReference(src.getEncounter()));
063    if (src.hasStatus())
064      tgt.setStatusElement(convertListStatus(src.getStatusElement()));
065    if (src.hasDate())
066      tgt.setDateElement(DateTime10_40.convertDateTime(src.getDateElement()));
067    if (src.hasOrderedBy())
068      tgt.setOrderedBy(CodeableConcept10_40.convertCodeableConcept(src.getOrderedBy()));
069    if (src.hasMode())
070      tgt.setModeElement(convertListMode(src.getModeElement()));
071    for (org.hl7.fhir.r4.model.Annotation t : src.getNote()) tgt.setNote(t.getText());
072    for (org.hl7.fhir.r4.model.ListResource.ListEntryComponent t : src.getEntry()) tgt.addEntry(convertListEntry(t));
073    return tgt;
074  }
075
076  public static org.hl7.fhir.r4.model.ListResource.ListEntryComponent convertListEntry(org.hl7.fhir.dstu2.model.List_.ListEntryComponent src) throws FHIRException {
077    if (src == null || src.isEmpty())
078      return null;
079    org.hl7.fhir.r4.model.ListResource.ListEntryComponent tgt = new org.hl7.fhir.r4.model.ListResource.ListEntryComponent();
080    copyBackboneElement(src, tgt);
081    if (src.hasFlag())
082      tgt.setFlag(CodeableConcept10_40.convertCodeableConcept(src.getFlag()));
083    if (src.hasDeletedElement())
084      tgt.setDeletedElement(Boolean10_40.convertBoolean(src.getDeletedElement()));
085    if (src.hasDate())
086      tgt.setDateElement(DateTime10_40.convertDateTime(src.getDateElement()));
087    if (src.hasItem())
088      tgt.setItem(Reference10_40.convertReference(src.getItem()));
089    return tgt;
090  }
091
092  public static org.hl7.fhir.dstu2.model.List_.ListEntryComponent convertListEntry(org.hl7.fhir.r4.model.ListResource.ListEntryComponent src) throws FHIRException {
093    if (src == null || src.isEmpty())
094      return null;
095    org.hl7.fhir.dstu2.model.List_.ListEntryComponent tgt = new org.hl7.fhir.dstu2.model.List_.ListEntryComponent();
096    copyBackboneElement(src, tgt);
097    if (src.hasFlag())
098      tgt.setFlag(CodeableConcept10_40.convertCodeableConcept(src.getFlag()));
099    if (src.hasDeletedElement())
100      tgt.setDeletedElement(Boolean10_40.convertBoolean(src.getDeletedElement()));
101    if (src.hasDate())
102      tgt.setDateElement(DateTime10_40.convertDateTime(src.getDateElement()));
103    if (src.hasItem())
104      tgt.setItem(Reference10_40.convertReference(src.getItem()));
105    return tgt;
106  }
107
108  static public org.hl7.fhir.dstu2.model.Enumeration<org.hl7.fhir.dstu2.model.List_.ListMode> convertListMode(org.hl7.fhir.r4.model.Enumeration<org.hl7.fhir.r4.model.ListResource.ListMode> src) throws FHIRException {
109    if (src == null || src.isEmpty())
110      return null;
111    org.hl7.fhir.dstu2.model.Enumeration<org.hl7.fhir.dstu2.model.List_.ListMode> tgt = new org.hl7.fhir.dstu2.model.Enumeration<>(new org.hl7.fhir.dstu2.model.List_.ListModeEnumFactory());
112    ConversionContext10_40.INSTANCE.getVersionConvertor_10_40().copyElement(src, tgt);
113    switch (src.getValue()) {
114      case WORKING:
115        tgt.setValue(org.hl7.fhir.dstu2.model.List_.ListMode.WORKING);
116        break;
117      case SNAPSHOT:
118        tgt.setValue(org.hl7.fhir.dstu2.model.List_.ListMode.SNAPSHOT);
119        break;
120      case CHANGES:
121        tgt.setValue(org.hl7.fhir.dstu2.model.List_.ListMode.CHANGES);
122        break;
123      default:
124        tgt.setValue(org.hl7.fhir.dstu2.model.List_.ListMode.NULL);
125        break;
126    }
127    return tgt;
128  }
129
130  static public org.hl7.fhir.r4.model.Enumeration<org.hl7.fhir.r4.model.ListResource.ListMode> convertListMode(org.hl7.fhir.dstu2.model.Enumeration<org.hl7.fhir.dstu2.model.List_.ListMode> src) throws FHIRException {
131    if (src == null || src.isEmpty())
132      return null;
133    org.hl7.fhir.r4.model.Enumeration<org.hl7.fhir.r4.model.ListResource.ListMode> tgt = new org.hl7.fhir.r4.model.Enumeration<>(new org.hl7.fhir.r4.model.ListResource.ListModeEnumFactory());
134    ConversionContext10_40.INSTANCE.getVersionConvertor_10_40().copyElement(src, tgt);
135    switch (src.getValue()) {
136      case WORKING:
137        tgt.setValue(org.hl7.fhir.r4.model.ListResource.ListMode.WORKING);
138        break;
139      case SNAPSHOT:
140        tgt.setValue(org.hl7.fhir.r4.model.ListResource.ListMode.SNAPSHOT);
141        break;
142      case CHANGES:
143        tgt.setValue(org.hl7.fhir.r4.model.ListResource.ListMode.CHANGES);
144        break;
145      default:
146        tgt.setValue(org.hl7.fhir.r4.model.ListResource.ListMode.NULL);
147        break;
148    }
149    return tgt;
150  }
151
152  static public org.hl7.fhir.r4.model.Enumeration<org.hl7.fhir.r4.model.ListResource.ListStatus> convertListStatus(org.hl7.fhir.dstu2.model.Enumeration<org.hl7.fhir.dstu2.model.List_.ListStatus> src) throws FHIRException {
153    if (src == null || src.isEmpty())
154      return null;
155    org.hl7.fhir.r4.model.Enumeration<org.hl7.fhir.r4.model.ListResource.ListStatus> tgt = new org.hl7.fhir.r4.model.Enumeration<>(new org.hl7.fhir.r4.model.ListResource.ListStatusEnumFactory());
156    ConversionContext10_40.INSTANCE.getVersionConvertor_10_40().copyElement(src, tgt);
157    switch (src.getValue()) {
158      case CURRENT:
159        tgt.setValue(org.hl7.fhir.r4.model.ListResource.ListStatus.CURRENT);
160        break;
161      case RETIRED:
162        tgt.setValue(org.hl7.fhir.r4.model.ListResource.ListStatus.RETIRED);
163        break;
164      case ENTEREDINERROR:
165        tgt.setValue(org.hl7.fhir.r4.model.ListResource.ListStatus.ENTEREDINERROR);
166        break;
167      default:
168        tgt.setValue(org.hl7.fhir.r4.model.ListResource.ListStatus.NULL);
169        break;
170    }
171    return tgt;
172  }
173
174  static public org.hl7.fhir.dstu2.model.Enumeration<org.hl7.fhir.dstu2.model.List_.ListStatus> convertListStatus(org.hl7.fhir.r4.model.Enumeration<org.hl7.fhir.r4.model.ListResource.ListStatus> src) throws FHIRException {
175    if (src == null || src.isEmpty())
176      return null;
177    org.hl7.fhir.dstu2.model.Enumeration<org.hl7.fhir.dstu2.model.List_.ListStatus> tgt = new org.hl7.fhir.dstu2.model.Enumeration<>(new org.hl7.fhir.dstu2.model.List_.ListStatusEnumFactory());
178    ConversionContext10_40.INSTANCE.getVersionConvertor_10_40().copyElement(src, tgt);
179    switch (src.getValue()) {
180      case CURRENT:
181        tgt.setValue(org.hl7.fhir.dstu2.model.List_.ListStatus.CURRENT);
182        break;
183      case RETIRED:
184        tgt.setValue(org.hl7.fhir.dstu2.model.List_.ListStatus.RETIRED);
185        break;
186      case ENTEREDINERROR:
187        tgt.setValue(org.hl7.fhir.dstu2.model.List_.ListStatus.ENTEREDINERROR);
188        break;
189      default:
190        tgt.setValue(org.hl7.fhir.dstu2.model.List_.ListStatus.NULL);
191        break;
192    }
193    return tgt;
194  }
195
196  public static void copyBackboneElement(org.hl7.fhir.r4.model.BackboneElement src, org.hl7.fhir.dstu2.model.BackboneElement tgt) throws FHIRException {
197    ConversionContext10_40.INSTANCE.getVersionConvertor_10_40().copyBackboneElement(src,tgt);
198    for (org.hl7.fhir.r4.model.Extension e : src.getModifierExtension()) {
199      tgt.addModifierExtension(Extension10_40.convertExtension(e));
200    }
201  }
202
203  public static void copyBackboneElement(org.hl7.fhir.dstu2.model.BackboneElement src, org.hl7.fhir.r4.model.BackboneElement tgt) throws FHIRException {
204    ConversionContext10_40.INSTANCE.getVersionConvertor_10_40().copyBackboneElement(src,tgt);
205    for (org.hl7.fhir.dstu2.model.Extension e : src.getModifierExtension()) {
206      tgt.addModifierExtension(Extension10_40.convertExtension(e));
207    }
208  }
209}