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.ElementDefinition10_30;
005import org.hl7.fhir.convertors.conv10_30.datatypes10_30.Reference10_30;
006import org.hl7.fhir.convertors.conv10_30.datatypes10_30.complextypes10_30.ContactPoint10_30;
007import org.hl7.fhir.convertors.conv10_30.datatypes10_30.primitivetypes10_30.Boolean10_30;
008import org.hl7.fhir.convertors.conv10_30.datatypes10_30.primitivetypes10_30.Code10_30;
009import org.hl7.fhir.convertors.conv10_30.datatypes10_30.primitivetypes10_30.DateTime10_30;
010import org.hl7.fhir.convertors.conv10_30.datatypes10_30.primitivetypes10_30.Integer10_30;
011import org.hl7.fhir.convertors.conv10_30.datatypes10_30.primitivetypes10_30.String10_30;
012import org.hl7.fhir.convertors.conv10_30.datatypes10_30.primitivetypes10_30.Uri10_30;
013import org.hl7.fhir.dstu3.model.Enumerations.SearchParamType;
014import org.hl7.fhir.exceptions.FHIRException;
015import org.hl7.fhir.utilities.Utilities;
016
017public class OperationDefinition10_30 {
018
019  public static org.hl7.fhir.dstu2.model.OperationDefinition convertOperationDefinition(org.hl7.fhir.dstu3.model.OperationDefinition src) throws FHIRException {
020    if (src == null || src.isEmpty())
021      return null;
022    org.hl7.fhir.dstu2.model.OperationDefinition tgt = new org.hl7.fhir.dstu2.model.OperationDefinition();
023    ConversionContext10_30.INSTANCE.getVersionConvertor_10_30().copyDomainResource(src, tgt);
024    if (src.hasUrlElement())
025      tgt.setUrlElement(Uri10_30.convertUri(src.getUrlElement()));
026    if (src.hasVersionElement())
027      tgt.setVersionElement(String10_30.convertString(src.getVersionElement()));
028    if (src.hasNameElement())
029      tgt.setNameElement(String10_30.convertString(src.getNameElement()));
030    if (src.hasStatus())
031      tgt.setStatusElement(Enumerations10_30.convertConformanceResourceStatus(src.getStatusElement()));
032    if (src.hasKind())
033      tgt.setKindElement(convertOperationKind(src.getKindElement()));
034    if (src.hasExperimental())
035      tgt.setExperimentalElement(Boolean10_30.convertBoolean(src.getExperimentalElement()));
036    if (src.hasDate())
037      tgt.setDateElement(DateTime10_30.convertDateTime(src.getDateElement()));
038    if (src.hasPublisherElement())
039      tgt.setPublisherElement(String10_30.convertString(src.getPublisherElement()));
040    for (org.hl7.fhir.dstu3.model.ContactDetail t : src.getContact())
041      tgt.addContact(convertOperationDefinitionContactComponent(t));
042    if (src.hasDescription())
043      tgt.setDescription(src.getDescription());
044    if (src.hasPurpose())
045      tgt.setRequirements(src.getPurpose());
046    if (src.hasIdempotentElement())
047      tgt.setIdempotentElement(Boolean10_30.convertBoolean(src.getIdempotentElement()));
048    if (src.hasCodeElement())
049      tgt.setCodeElement(Code10_30.convertCode(src.getCodeElement()));
050    if (src.hasCommentElement())
051      tgt.setNotesElement(String10_30.convertString(src.getCommentElement()));
052    if (src.hasBase())
053      tgt.setBase(Reference10_30.convertReference(src.getBase()));
054    if (src.hasSystemElement())
055      tgt.setSystemElement(Boolean10_30.convertBoolean(src.getSystemElement()));
056    if (src.getType())
057      for (org.hl7.fhir.dstu3.model.CodeType t : src.getResource()) tgt.addType(t.getValue());
058    if (src.hasInstanceElement())
059      tgt.setInstanceElement(Boolean10_30.convertBoolean(src.getInstanceElement()));
060    for (org.hl7.fhir.dstu3.model.OperationDefinition.OperationDefinitionParameterComponent t : src.getParameter())
061      tgt.addParameter(convertOperationDefinitionParameterComponent(t));
062    return tgt;
063  }
064
065  public static org.hl7.fhir.dstu3.model.OperationDefinition convertOperationDefinition(org.hl7.fhir.dstu2.model.OperationDefinition src) throws FHIRException {
066    if (src == null || src.isEmpty())
067      return null;
068    org.hl7.fhir.dstu3.model.OperationDefinition tgt = new org.hl7.fhir.dstu3.model.OperationDefinition();
069    ConversionContext10_30.INSTANCE.getVersionConvertor_10_30().copyDomainResource(src, tgt);
070    if (src.hasUrlElement())
071      tgt.setUrlElement(Uri10_30.convertUri(src.getUrlElement()));
072    if (src.hasVersionElement())
073      tgt.setVersionElement(String10_30.convertString(src.getVersionElement()));
074    if (src.hasNameElement())
075      tgt.setNameElement(String10_30.convertString(src.getNameElement()));
076    if (src.hasStatus())
077      tgt.setStatusElement(Enumerations10_30.convertConformanceResourceStatus(src.getStatusElement()));
078    if (src.hasKind())
079      tgt.setKindElement(convertOperationKind(src.getKindElement()));
080    if (src.hasExperimental())
081      tgt.setExperimentalElement(Boolean10_30.convertBoolean(src.getExperimentalElement()));
082    if (src.hasDate())
083      tgt.setDateElement(DateTime10_30.convertDateTime(src.getDateElement()));
084    if (src.hasPublisherElement())
085      tgt.setPublisherElement(String10_30.convertString(src.getPublisherElement()));
086    for (org.hl7.fhir.dstu2.model.OperationDefinition.OperationDefinitionContactComponent t : src.getContact())
087      tgt.addContact(convertOperationDefinitionContactComponent(t));
088    if (src.hasDescription())
089      tgt.setDescription(src.getDescription());
090    if (src.hasRequirements())
091      tgt.setPurpose(src.getRequirements());
092    if (src.hasIdempotent())
093      tgt.setIdempotentElement(Boolean10_30.convertBoolean(src.getIdempotentElement()));
094    if (src.hasCodeElement())
095      tgt.setCodeElement(Code10_30.convertCode(src.getCodeElement()));
096    if (src.hasNotesElement())
097      tgt.setCommentElement(String10_30.convertString(src.getNotesElement()));
098    if (src.hasBase())
099      tgt.setBase(Reference10_30.convertReference(src.getBase()));
100    if (src.hasSystemElement())
101      tgt.setSystemElement(Boolean10_30.convertBoolean(src.getSystemElement()));
102    for (org.hl7.fhir.dstu2.model.CodeType t : src.getType()) tgt.addResource(t.getValue());
103    tgt.setType(tgt.hasResource());
104    if (src.hasInstanceElement())
105      tgt.setInstanceElement(Boolean10_30.convertBoolean(src.getInstanceElement()));
106    for (org.hl7.fhir.dstu2.model.OperationDefinition.OperationDefinitionParameterComponent t : src.getParameter())
107      tgt.addParameter(convertOperationDefinitionParameterComponent(t));
108    return tgt;
109  }
110
111  public static org.hl7.fhir.dstu2.model.OperationDefinition.OperationDefinitionContactComponent convertOperationDefinitionContactComponent(org.hl7.fhir.dstu3.model.ContactDetail src) throws FHIRException {
112    if (src == null || src.isEmpty())
113      return null;
114    org.hl7.fhir.dstu2.model.OperationDefinition.OperationDefinitionContactComponent tgt = new org.hl7.fhir.dstu2.model.OperationDefinition.OperationDefinitionContactComponent();
115    ConversionContext10_30.INSTANCE.getVersionConvertor_10_30().copyElement(src, tgt);
116    if (src.hasNameElement())
117      tgt.setNameElement(String10_30.convertString(src.getNameElement()));
118    for (org.hl7.fhir.dstu3.model.ContactPoint t : src.getTelecom())
119      tgt.addTelecom(ContactPoint10_30.convertContactPoint(t));
120    return tgt;
121  }
122
123  public static org.hl7.fhir.dstu3.model.ContactDetail convertOperationDefinitionContactComponent(org.hl7.fhir.dstu2.model.OperationDefinition.OperationDefinitionContactComponent src) throws FHIRException {
124    if (src == null || src.isEmpty())
125      return null;
126    org.hl7.fhir.dstu3.model.ContactDetail tgt = new org.hl7.fhir.dstu3.model.ContactDetail();
127    ConversionContext10_30.INSTANCE.getVersionConvertor_10_30().copyElement(src, tgt);
128    if (src.hasNameElement())
129      tgt.setNameElement(String10_30.convertString(src.getNameElement()));
130    for (org.hl7.fhir.dstu2.model.ContactPoint t : src.getTelecom())
131      tgt.addTelecom(ContactPoint10_30.convertContactPoint(t));
132    return tgt;
133  }
134
135  public static org.hl7.fhir.dstu3.model.OperationDefinition.OperationDefinitionParameterBindingComponent convertOperationDefinitionParameterBindingComponent(org.hl7.fhir.dstu2.model.OperationDefinition.OperationDefinitionParameterBindingComponent src) throws FHIRException {
136    if (src == null || src.isEmpty())
137      return null;
138    org.hl7.fhir.dstu3.model.OperationDefinition.OperationDefinitionParameterBindingComponent tgt = new org.hl7.fhir.dstu3.model.OperationDefinition.OperationDefinitionParameterBindingComponent();
139    ConversionContext10_30.INSTANCE.getVersionConvertor_10_30().copyBackboneElement(src,tgt);
140    if (src.hasStrength())
141      tgt.setStrengthElement(ElementDefinition10_30.convertBindingStrength(src.getStrengthElement()));
142    if (src.hasValueSet())
143      tgt.setValueSet(ConversionContext10_30.INSTANCE.getVersionConvertor_10_30().convertType(src.getValueSet()));
144    return tgt;
145  }
146
147  public static org.hl7.fhir.dstu2.model.OperationDefinition.OperationDefinitionParameterBindingComponent convertOperationDefinitionParameterBindingComponent(org.hl7.fhir.dstu3.model.OperationDefinition.OperationDefinitionParameterBindingComponent src) throws FHIRException {
148    if (src == null || src.isEmpty())
149      return null;
150    org.hl7.fhir.dstu2.model.OperationDefinition.OperationDefinitionParameterBindingComponent tgt = new org.hl7.fhir.dstu2.model.OperationDefinition.OperationDefinitionParameterBindingComponent();
151    ConversionContext10_30.INSTANCE.getVersionConvertor_10_30().copyBackboneElement(src,tgt);
152    if (src.hasStrength())
153      tgt.setStrengthElement(ElementDefinition10_30.convertBindingStrength(src.getStrengthElement()));
154    if (src.hasValueSet())
155      tgt.setValueSet(ConversionContext10_30.INSTANCE.getVersionConvertor_10_30().convertType(src.getValueSet()));
156    return tgt;
157  }
158
159  public static org.hl7.fhir.dstu2.model.OperationDefinition.OperationDefinitionParameterComponent convertOperationDefinitionParameterComponent(org.hl7.fhir.dstu3.model.OperationDefinition.OperationDefinitionParameterComponent src) throws FHIRException {
160    if (src == null || src.isEmpty())
161      return null;
162    org.hl7.fhir.dstu2.model.OperationDefinition.OperationDefinitionParameterComponent tgt = new org.hl7.fhir.dstu2.model.OperationDefinition.OperationDefinitionParameterComponent();
163    ConversionContext10_30.INSTANCE.getVersionConvertor_10_30().copyBackboneElement(src,tgt);
164    if (src.hasNameElement())
165      tgt.setNameElement(Code10_30.convertCode(src.getNameElement()));
166    if (src.hasUse())
167      tgt.setUseElement(convertOperationParameterUse(src.getUseElement()));
168    if (src.hasMinElement())
169      tgt.setMinElement(Integer10_30.convertInteger(src.getMinElement()));
170    if (src.hasMaxElement())
171      tgt.setMaxElement(String10_30.convertString(src.getMaxElement()));
172    if (src.hasDocumentationElement())
173      tgt.setDocumentationElement(String10_30.convertString(src.getDocumentationElement()));
174    if (src.hasSearchType()) {
175      tgt.setType(src.getSearchType().toCode());
176    } else
177      tgt.setTypeElement(Code10_30.convertCode(src.getTypeElement()));
178    if (src.hasProfile())
179      tgt.setProfile(Reference10_30.convertReference(src.getProfile()));
180    if (src.hasBinding())
181      tgt.setBinding(convertOperationDefinitionParameterBindingComponent(src.getBinding()));
182    for (org.hl7.fhir.dstu3.model.OperationDefinition.OperationDefinitionParameterComponent t : src.getPart())
183      tgt.addPart(convertOperationDefinitionParameterComponent(t));
184    return tgt;
185  }
186
187  public static org.hl7.fhir.dstu3.model.OperationDefinition.OperationDefinitionParameterComponent convertOperationDefinitionParameterComponent(org.hl7.fhir.dstu2.model.OperationDefinition.OperationDefinitionParameterComponent src) throws FHIRException {
188    if (src == null || src.isEmpty())
189      return null;
190    org.hl7.fhir.dstu3.model.OperationDefinition.OperationDefinitionParameterComponent tgt = new org.hl7.fhir.dstu3.model.OperationDefinition.OperationDefinitionParameterComponent();
191    ConversionContext10_30.INSTANCE.getVersionConvertor_10_30().copyBackboneElement(src,tgt);
192    if (src.hasNameElement())
193      tgt.setNameElement(Code10_30.convertCode(src.getNameElement()));
194    if (src.hasUse())
195      tgt.setUseElement(convertOperationParameterUse(src.getUseElement()));
196    if (src.hasMinElement())
197      tgt.setMinElement(Integer10_30.convertInteger(src.getMinElement()));
198    if (src.hasMaxElement())
199      tgt.setMaxElement(String10_30.convertString(src.getMaxElement()));
200    if (src.hasDocumentationElement())
201      tgt.setDocumentationElement(String10_30.convertString(src.getDocumentationElement()));
202    if (Utilities.existsInList(src.getType(), "token", "reference", "composite", "number", "date", "quantity", "uri")) {
203      tgt.setType("string");
204      if (src.hasType())
205        tgt.setSearchType(SearchParamType.fromCode(src.getType()));
206    } else {
207      if (src.hasTypeElement())
208        tgt.setTypeElement(Code10_30.convertCode(src.getTypeElement()));
209    }
210    if (src.hasProfile())
211      tgt.setProfile(Reference10_30.convertReference(src.getProfile()));
212    if (src.hasBinding())
213      tgt.setBinding(convertOperationDefinitionParameterBindingComponent(src.getBinding()));
214    for (org.hl7.fhir.dstu2.model.OperationDefinition.OperationDefinitionParameterComponent t : src.getPart())
215      tgt.addPart(convertOperationDefinitionParameterComponent(t));
216    return tgt;
217  }
218
219  static public org.hl7.fhir.dstu2.model.Enumeration<org.hl7.fhir.dstu2.model.OperationDefinition.OperationKind> convertOperationKind(org.hl7.fhir.dstu3.model.Enumeration<org.hl7.fhir.dstu3.model.OperationDefinition.OperationKind> src) throws FHIRException {
220    if (src == null || src.isEmpty())
221      return null;
222    org.hl7.fhir.dstu2.model.Enumeration<org.hl7.fhir.dstu2.model.OperationDefinition.OperationKind> tgt = new org.hl7.fhir.dstu2.model.Enumeration<>(new org.hl7.fhir.dstu2.model.OperationDefinition.OperationKindEnumFactory());
223    ConversionContext10_30.INSTANCE.getVersionConvertor_10_30().copyElement(src, tgt);
224    switch (src.getValue()) {
225      case OPERATION:
226        tgt.setValue(org.hl7.fhir.dstu2.model.OperationDefinition.OperationKind.OPERATION);
227        break;
228      case QUERY:
229        tgt.setValue(org.hl7.fhir.dstu2.model.OperationDefinition.OperationKind.QUERY);
230        break;
231      default:
232        tgt.setValue(org.hl7.fhir.dstu2.model.OperationDefinition.OperationKind.NULL);
233        break;
234    }
235    return tgt;
236  }
237
238  static public org.hl7.fhir.dstu3.model.Enumeration<org.hl7.fhir.dstu3.model.OperationDefinition.OperationKind> convertOperationKind(org.hl7.fhir.dstu2.model.Enumeration<org.hl7.fhir.dstu2.model.OperationDefinition.OperationKind> src) throws FHIRException {
239    if (src == null || src.isEmpty())
240      return null;
241    org.hl7.fhir.dstu3.model.Enumeration<org.hl7.fhir.dstu3.model.OperationDefinition.OperationKind> tgt = new org.hl7.fhir.dstu3.model.Enumeration<>(new org.hl7.fhir.dstu3.model.OperationDefinition.OperationKindEnumFactory());
242    ConversionContext10_30.INSTANCE.getVersionConvertor_10_30().copyElement(src, tgt);
243    switch (src.getValue()) {
244      case OPERATION:
245        tgt.setValue(org.hl7.fhir.dstu3.model.OperationDefinition.OperationKind.OPERATION);
246        break;
247      case QUERY:
248        tgt.setValue(org.hl7.fhir.dstu3.model.OperationDefinition.OperationKind.QUERY);
249        break;
250      default:
251        tgt.setValue(org.hl7.fhir.dstu3.model.OperationDefinition.OperationKind.NULL);
252        break;
253    }
254    return tgt;
255  }
256
257  static public org.hl7.fhir.dstu2.model.Enumeration<org.hl7.fhir.dstu2.model.OperationDefinition.OperationParameterUse> convertOperationParameterUse(org.hl7.fhir.dstu3.model.Enumeration<org.hl7.fhir.dstu3.model.OperationDefinition.OperationParameterUse> src) throws FHIRException {
258    if (src == null || src.isEmpty())
259      return null;
260    org.hl7.fhir.dstu2.model.Enumeration<org.hl7.fhir.dstu2.model.OperationDefinition.OperationParameterUse> tgt = new org.hl7.fhir.dstu2.model.Enumeration<>(new org.hl7.fhir.dstu2.model.OperationDefinition.OperationParameterUseEnumFactory());
261    ConversionContext10_30.INSTANCE.getVersionConvertor_10_30().copyElement(src, tgt);
262    switch (src.getValue()) {
263      case IN:
264        tgt.setValue(org.hl7.fhir.dstu2.model.OperationDefinition.OperationParameterUse.IN);
265        break;
266      case OUT:
267        tgt.setValue(org.hl7.fhir.dstu2.model.OperationDefinition.OperationParameterUse.OUT);
268        break;
269      default:
270        tgt.setValue(org.hl7.fhir.dstu2.model.OperationDefinition.OperationParameterUse.NULL);
271        break;
272    }
273    return tgt;
274  }
275
276  static public org.hl7.fhir.dstu3.model.Enumeration<org.hl7.fhir.dstu3.model.OperationDefinition.OperationParameterUse> convertOperationParameterUse(org.hl7.fhir.dstu2.model.Enumeration<org.hl7.fhir.dstu2.model.OperationDefinition.OperationParameterUse> src) throws FHIRException {
277    if (src == null || src.isEmpty())
278      return null;
279    org.hl7.fhir.dstu3.model.Enumeration<org.hl7.fhir.dstu3.model.OperationDefinition.OperationParameterUse> tgt = new org.hl7.fhir.dstu3.model.Enumeration<>(new org.hl7.fhir.dstu3.model.OperationDefinition.OperationParameterUseEnumFactory());
280    ConversionContext10_30.INSTANCE.getVersionConvertor_10_30().copyElement(src, tgt);
281    switch (src.getValue()) {
282      case IN:
283        tgt.setValue(org.hl7.fhir.dstu3.model.OperationDefinition.OperationParameterUse.IN);
284        break;
285      case OUT:
286        tgt.setValue(org.hl7.fhir.dstu3.model.OperationDefinition.OperationParameterUse.OUT);
287        break;
288      default:
289        tgt.setValue(org.hl7.fhir.dstu3.model.OperationDefinition.OperationParameterUse.NULL);
290        break;
291    }
292    return tgt;
293  }
294}