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.complextypes10_50.ContactPoint10_50;
005import org.hl7.fhir.convertors.conv10_50.datatypes10_50.primitivetypes10_50.Boolean10_50;
006import org.hl7.fhir.convertors.conv10_50.datatypes10_50.primitivetypes10_50.Code10_50;
007import org.hl7.fhir.convertors.conv10_50.datatypes10_50.primitivetypes10_50.DateTime10_50;
008import org.hl7.fhir.convertors.conv10_50.datatypes10_50.primitivetypes10_50.String10_50;
009import org.hl7.fhir.convertors.conv10_50.datatypes10_50.primitivetypes10_50.Uri10_50;
010import org.hl7.fhir.dstu2.utils.ToolingExtensions;
011import org.hl7.fhir.exceptions.FHIRException;
012import org.hl7.fhir.r5.model.Enumeration;
013import org.hl7.fhir.r5.model.Enumerations.VersionIndependentResourceTypesAll;
014import org.hl7.fhir.r5.model.Enumerations.VersionIndependentResourceTypesAllEnumFactory;
015
016public class SearchParameter10_50 {
017
018  public static org.hl7.fhir.dstu2.model.SearchParameter convertSearchParameter(org.hl7.fhir.r5.model.SearchParameter src) throws FHIRException {
019    if (src == null || src.isEmpty())
020      return null;
021    org.hl7.fhir.dstu2.model.SearchParameter tgt = new org.hl7.fhir.dstu2.model.SearchParameter();
022    ConversionContext10_50.INSTANCE.getVersionConvertor_10_50().copyDomainResource(src, tgt);
023    if (src.hasUrlElement())
024      tgt.setUrlElement(Uri10_50.convertUri(src.getUrlElement()));
025    if (src.hasNameElement())
026      tgt.setNameElement(String10_50.convertString(src.getNameElement()));
027    if (src.hasStatus())
028      tgt.setStatusElement(Enumerations10_50.convertConformanceResourceStatus(src.getStatusElement()));
029    if (src.hasExperimental())
030      tgt.setExperimentalElement(Boolean10_50.convertBoolean(src.getExperimentalElement()));
031    if (src.hasDate())
032      tgt.setDateElement(DateTime10_50.convertDateTime(src.getDateElement()));
033    if (src.hasPublisherElement())
034      tgt.setPublisherElement(String10_50.convertString(src.getPublisherElement()));
035    for (org.hl7.fhir.r5.model.ContactDetail t : src.getContact())
036      tgt.addContact(convertSearchParameterContactComponent(t));
037    if (src.hasPurpose())
038      tgt.setRequirements(src.getPurpose());
039    if (src.hasCodeElement())
040      tgt.setCodeElement(Code10_50.convertCode(src.getCodeElement()));
041    for (Enumeration<VersionIndependentResourceTypesAll> t : src.getBase()) tgt.setBaseElement(Code10_50.convertCode(t.getCodeType()));
042    if (src.hasType())
043      tgt.setTypeElement(Enumerations10_50.convertSearchParamType(src.getTypeElement()));
044    if (src.hasDescription())
045      tgt.setDescription(src.getDescription());
046    org.hl7.fhir.dstu2.utils.ToolingExtensions.setStringExtension(tgt, ToolingExtensions.EXT_EXPRESSION, src.getExpression());
047//    if (src.hasXpathElement())
048//      tgt.setXpathElement(String10_50.convertString(src.getXpathElement()));
049    if (src.hasProcessingMode())
050      tgt.setXpathUsageElement(convertXPathUsageType(src.getProcessingModeElement()));
051    for (Enumeration<VersionIndependentResourceTypesAll> t : src.getTarget()) tgt.getTarget().add(Code10_50.convertCode(t.getCodeType()));
052    return tgt;
053  }
054
055  public static org.hl7.fhir.r5.model.SearchParameter convertSearchParameter(org.hl7.fhir.dstu2.model.SearchParameter src) throws FHIRException {
056    if (src == null || src.isEmpty())
057      return null;
058    org.hl7.fhir.r5.model.SearchParameter tgt = new org.hl7.fhir.r5.model.SearchParameter();
059    ConversionContext10_50.INSTANCE.getVersionConvertor_10_50().copyDomainResource(src, tgt);
060    if (src.hasUrlElement())
061      tgt.setUrlElement(Uri10_50.convertUri(src.getUrlElement()));
062    if (src.hasNameElement())
063      tgt.setNameElement(String10_50.convertString(src.getNameElement()));
064    if (src.hasStatus())
065      tgt.setStatusElement(Enumerations10_50.convertConformanceResourceStatus(src.getStatusElement()));
066    if (src.hasExperimental())
067      tgt.setExperimentalElement(Boolean10_50.convertBoolean(src.getExperimentalElement()));
068    if (src.hasDate())
069      tgt.setDateElement(DateTime10_50.convertDateTime(src.getDateElement()));
070    if (src.hasPublisherElement())
071      tgt.setPublisherElement(String10_50.convertString(src.getPublisherElement()));
072    for (org.hl7.fhir.dstu2.model.SearchParameter.SearchParameterContactComponent t : src.getContact())
073      tgt.addContact(convertSearchParameterContactComponent(t));
074    if (src.hasRequirements())
075      tgt.setPurpose(src.getRequirements());
076    if (src.hasCodeElement())
077      tgt.setCodeElement(Code10_50.convertCode(src.getCodeElement()));
078    tgt.getBase().add(new Enumeration<VersionIndependentResourceTypesAll>(new VersionIndependentResourceTypesAllEnumFactory(), Code10_50.convertCode(src.getBaseElement())));
079    if (src.hasType())
080      tgt.setTypeElement(Enumerations10_50.convertSearchParamType(src.getTypeElement()));
081    if (src.hasDescription())
082      tgt.setDescription(src.getDescription());
083    tgt.setExpression(ToolingExtensions.readStringExtension(src, ToolingExtensions.EXT_EXPRESSION));
084//    if (src.hasXpathElement())
085//      tgt.setXpathElement(String10_50.convertString(src.getXpathElement()));
086    if (src.hasXpathUsage())
087      tgt.setProcessingModeElement(convertXPathUsageType(src.getXpathUsageElement()));
088    for (org.hl7.fhir.dstu2.model.CodeType t : src.getTarget()) tgt.getTarget().add(new Enumeration<VersionIndependentResourceTypesAll>(new VersionIndependentResourceTypesAllEnumFactory(), t.getValue()));
089    return tgt;
090  }
091
092  public static org.hl7.fhir.dstu2.model.SearchParameter.SearchParameterContactComponent convertSearchParameterContactComponent(org.hl7.fhir.r5.model.ContactDetail src) throws FHIRException {
093    if (src == null || src.isEmpty())
094      return null;
095    org.hl7.fhir.dstu2.model.SearchParameter.SearchParameterContactComponent tgt = new org.hl7.fhir.dstu2.model.SearchParameter.SearchParameterContactComponent();
096    ConversionContext10_50.INSTANCE.getVersionConvertor_10_50().copyElement(src, tgt);
097    if (src.hasNameElement())
098      tgt.setNameElement(String10_50.convertString(src.getNameElement()));
099    for (org.hl7.fhir.r5.model.ContactPoint t : src.getTelecom())
100      tgt.addTelecom(ContactPoint10_50.convertContactPoint(t));
101    return tgt;
102  }
103
104  public static org.hl7.fhir.r5.model.ContactDetail convertSearchParameterContactComponent(org.hl7.fhir.dstu2.model.SearchParameter.SearchParameterContactComponent src) throws FHIRException {
105    if (src == null || src.isEmpty())
106      return null;
107    org.hl7.fhir.r5.model.ContactDetail tgt = new org.hl7.fhir.r5.model.ContactDetail();
108    ConversionContext10_50.INSTANCE.getVersionConvertor_10_50().copyElement(src, tgt);
109    if (src.hasNameElement())
110      tgt.setNameElement(String10_50.convertString(src.getNameElement()));
111    for (org.hl7.fhir.dstu2.model.ContactPoint t : src.getTelecom())
112      tgt.addTelecom(ContactPoint10_50.convertContactPoint(t));
113    return tgt;
114  }
115
116  static public org.hl7.fhir.r5.model.Enumeration<org.hl7.fhir.r5.model.SearchParameter.SearchProcessingModeType> convertXPathUsageType(org.hl7.fhir.dstu2.model.Enumeration<org.hl7.fhir.dstu2.model.SearchParameter.XPathUsageType> src) throws FHIRException {
117    if (src == null || src.isEmpty())
118      return null;
119    org.hl7.fhir.r5.model.Enumeration<org.hl7.fhir.r5.model.SearchParameter.SearchProcessingModeType> tgt = new org.hl7.fhir.r5.model.Enumeration<>(new org.hl7.fhir.r5.model.SearchParameter.SearchProcessingModeTypeEnumFactory());
120    ConversionContext10_50.INSTANCE.getVersionConvertor_10_50().copyElement(src, tgt);
121    switch (src.getValue()) {
122      case NORMAL:
123        tgt.setValue(org.hl7.fhir.r5.model.SearchParameter.SearchProcessingModeType.NORMAL);
124        break;
125      case PHONETIC:
126        tgt.setValue(org.hl7.fhir.r5.model.SearchParameter.SearchProcessingModeType.PHONETIC);
127        break;
128      case NEARBY:
129        tgt.setValue(org.hl7.fhir.r5.model.SearchParameter.SearchProcessingModeType.OTHER);
130        break;
131      case DISTANCE:
132        tgt.setValue(org.hl7.fhir.r5.model.SearchParameter.SearchProcessingModeType.OTHER);
133        break;
134      case OTHER:
135        tgt.setValue(org.hl7.fhir.r5.model.SearchParameter.SearchProcessingModeType.OTHER);
136        break;
137      default:
138        tgt.setValue(org.hl7.fhir.r5.model.SearchParameter.SearchProcessingModeType.NULL);
139        break;
140    }
141    return tgt;
142  }
143
144  static public org.hl7.fhir.dstu2.model.Enumeration<org.hl7.fhir.dstu2.model.SearchParameter.XPathUsageType> convertXPathUsageType(org.hl7.fhir.r5.model.Enumeration<org.hl7.fhir.r5.model.SearchParameter.SearchProcessingModeType> src) throws FHIRException {
145    if (src == null || src.isEmpty())
146      return null;
147    org.hl7.fhir.dstu2.model.Enumeration<org.hl7.fhir.dstu2.model.SearchParameter.XPathUsageType> tgt = new org.hl7.fhir.dstu2.model.Enumeration<>(new org.hl7.fhir.dstu2.model.SearchParameter.XPathUsageTypeEnumFactory());
148    ConversionContext10_50.INSTANCE.getVersionConvertor_10_50().copyElement(src, tgt);
149    switch (src.getValue()) {
150      case NORMAL:
151        tgt.setValue(org.hl7.fhir.dstu2.model.SearchParameter.XPathUsageType.NORMAL);
152        break;
153      case PHONETIC:
154        tgt.setValue(org.hl7.fhir.dstu2.model.SearchParameter.XPathUsageType.PHONETIC);
155        break;
156      case OTHER:
157        tgt.setValue(org.hl7.fhir.dstu2.model.SearchParameter.XPathUsageType.OTHER);
158        break;
159      default:
160        tgt.setValue(org.hl7.fhir.dstu2.model.SearchParameter.XPathUsageType.NULL);
161        break;
162    }
163    return tgt;
164  }
165}