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