001package org.hl7.fhir.convertors.conv30_40.resources30_40;
002
003import org.hl7.fhir.convertors.context.ConversionContext30_40;
004import org.hl7.fhir.convertors.conv30_40.datatypes30_40.complextypes30_40.CodeableConcept30_40;
005import org.hl7.fhir.convertors.conv30_40.datatypes30_40.complextypes30_40.Identifier30_40;
006import org.hl7.fhir.convertors.conv30_40.datatypes30_40.complextypes30_40.Ratio30_40;
007import org.hl7.fhir.convertors.conv30_40.datatypes30_40.complextypes30_40.SimpleQuantity30_40;
008import org.hl7.fhir.convertors.conv30_40.datatypes30_40.primitivetypes30_40.DateTime30_40;
009import org.hl7.fhir.convertors.conv30_40.datatypes30_40.primitivetypes30_40.String30_40;
010import org.hl7.fhir.exceptions.FHIRException;
011import org.hl7.fhir.r4.model.Enumeration;
012import org.hl7.fhir.r4.model.Substance;
013
014public class Substance30_40 {
015
016  static public org.hl7.fhir.r4.model.Enumeration<org.hl7.fhir.r4.model.Substance.FHIRSubstanceStatus> convertFHIRSubstanceStatus(org.hl7.fhir.dstu3.model.Enumeration<org.hl7.fhir.dstu3.model.Substance.FHIRSubstanceStatus> src) throws FHIRException {
017      if (src == null || src.isEmpty())
018          return null;
019      Enumeration<Substance.FHIRSubstanceStatus> tgt = new Enumeration<>(new Substance.FHIRSubstanceStatusEnumFactory());
020      ConversionContext30_40.INSTANCE.getVersionConvertor_30_40().copyElement(src, tgt);
021      if (src.getValue() == null) {
022          tgt.setValue(null);
023      } else {
024          switch (src.getValue()) {
025              case ACTIVE:
026                  tgt.setValue(Substance.FHIRSubstanceStatus.ACTIVE);
027                  break;
028              case INACTIVE:
029                  tgt.setValue(Substance.FHIRSubstanceStatus.INACTIVE);
030                  break;
031              case ENTEREDINERROR:
032                  tgt.setValue(Substance.FHIRSubstanceStatus.ENTEREDINERROR);
033                  break;
034              default:
035                  tgt.setValue(Substance.FHIRSubstanceStatus.NULL);
036                  break;
037          }
038      }
039      return tgt;
040  }
041
042  static public org.hl7.fhir.dstu3.model.Enumeration<org.hl7.fhir.dstu3.model.Substance.FHIRSubstanceStatus> convertFHIRSubstanceStatus(org.hl7.fhir.r4.model.Enumeration<org.hl7.fhir.r4.model.Substance.FHIRSubstanceStatus> src) throws FHIRException {
043      if (src == null || src.isEmpty())
044          return null;
045      org.hl7.fhir.dstu3.model.Enumeration<org.hl7.fhir.dstu3.model.Substance.FHIRSubstanceStatus> tgt = new org.hl7.fhir.dstu3.model.Enumeration<>(new org.hl7.fhir.dstu3.model.Substance.FHIRSubstanceStatusEnumFactory());
046      ConversionContext30_40.INSTANCE.getVersionConvertor_30_40().copyElement(src, tgt);
047      if (src.getValue() == null) {
048          tgt.setValue(null);
049      } else {
050          switch (src.getValue()) {
051              case ACTIVE:
052                  tgt.setValue(org.hl7.fhir.dstu3.model.Substance.FHIRSubstanceStatus.ACTIVE);
053                  break;
054              case INACTIVE:
055                  tgt.setValue(org.hl7.fhir.dstu3.model.Substance.FHIRSubstanceStatus.INACTIVE);
056                  break;
057              case ENTEREDINERROR:
058                  tgt.setValue(org.hl7.fhir.dstu3.model.Substance.FHIRSubstanceStatus.ENTEREDINERROR);
059                  break;
060              default:
061                  tgt.setValue(org.hl7.fhir.dstu3.model.Substance.FHIRSubstanceStatus.NULL);
062                  break;
063          }
064      }
065      return tgt;
066  }
067
068  public static org.hl7.fhir.r4.model.Substance convertSubstance(org.hl7.fhir.dstu3.model.Substance src) throws FHIRException {
069    if (src == null)
070      return null;
071    org.hl7.fhir.r4.model.Substance tgt = new org.hl7.fhir.r4.model.Substance();
072    ConversionContext30_40.INSTANCE.getVersionConvertor_30_40().copyDomainResource(src, tgt);
073    for (org.hl7.fhir.dstu3.model.Identifier t : src.getIdentifier())
074      tgt.addIdentifier(Identifier30_40.convertIdentifier(t));
075    if (src.hasStatus())
076      tgt.setStatusElement(convertFHIRSubstanceStatus(src.getStatusElement()));
077    for (org.hl7.fhir.dstu3.model.CodeableConcept t : src.getCategory())
078      tgt.addCategory(CodeableConcept30_40.convertCodeableConcept(t));
079    if (src.hasCode())
080      tgt.setCode(CodeableConcept30_40.convertCodeableConcept(src.getCode()));
081    if (src.hasDescription())
082      tgt.setDescriptionElement(String30_40.convertString(src.getDescriptionElement()));
083    for (org.hl7.fhir.dstu3.model.Substance.SubstanceInstanceComponent t : src.getInstance())
084      tgt.addInstance(convertSubstanceInstanceComponent(t));
085    for (org.hl7.fhir.dstu3.model.Substance.SubstanceIngredientComponent t : src.getIngredient())
086      tgt.addIngredient(convertSubstanceIngredientComponent(t));
087    return tgt;
088  }
089
090  public static org.hl7.fhir.dstu3.model.Substance convertSubstance(org.hl7.fhir.r4.model.Substance src) throws FHIRException {
091    if (src == null)
092      return null;
093    org.hl7.fhir.dstu3.model.Substance tgt = new org.hl7.fhir.dstu3.model.Substance();
094    ConversionContext30_40.INSTANCE.getVersionConvertor_30_40().copyDomainResource(src, tgt);
095    for (org.hl7.fhir.r4.model.Identifier t : src.getIdentifier())
096      tgt.addIdentifier(Identifier30_40.convertIdentifier(t));
097    if (src.hasStatus())
098      tgt.setStatusElement(convertFHIRSubstanceStatus(src.getStatusElement()));
099    for (org.hl7.fhir.r4.model.CodeableConcept t : src.getCategory())
100      tgt.addCategory(CodeableConcept30_40.convertCodeableConcept(t));
101    if (src.hasCode())
102      tgt.setCode(CodeableConcept30_40.convertCodeableConcept(src.getCode()));
103    if (src.hasDescription())
104      tgt.setDescriptionElement(String30_40.convertString(src.getDescriptionElement()));
105    for (org.hl7.fhir.r4.model.Substance.SubstanceInstanceComponent t : src.getInstance())
106      tgt.addInstance(convertSubstanceInstanceComponent(t));
107    for (org.hl7.fhir.r4.model.Substance.SubstanceIngredientComponent t : src.getIngredient())
108      tgt.addIngredient(convertSubstanceIngredientComponent(t));
109    return tgt;
110  }
111
112  public static org.hl7.fhir.dstu3.model.Substance.SubstanceIngredientComponent convertSubstanceIngredientComponent(org.hl7.fhir.r4.model.Substance.SubstanceIngredientComponent src) throws FHIRException {
113    if (src == null)
114      return null;
115    org.hl7.fhir.dstu3.model.Substance.SubstanceIngredientComponent tgt = new org.hl7.fhir.dstu3.model.Substance.SubstanceIngredientComponent();
116    ConversionContext30_40.INSTANCE.getVersionConvertor_30_40().copyBackboneElement(src,tgt);
117    if (src.hasQuantity())
118      tgt.setQuantity(Ratio30_40.convertRatio(src.getQuantity()));
119    if (src.hasSubstance())
120      tgt.setSubstance(ConversionContext30_40.INSTANCE.getVersionConvertor_30_40().convertType(src.getSubstance()));
121    return tgt;
122  }
123
124  public static org.hl7.fhir.r4.model.Substance.SubstanceIngredientComponent convertSubstanceIngredientComponent(org.hl7.fhir.dstu3.model.Substance.SubstanceIngredientComponent src) throws FHIRException {
125    if (src == null)
126      return null;
127    org.hl7.fhir.r4.model.Substance.SubstanceIngredientComponent tgt = new org.hl7.fhir.r4.model.Substance.SubstanceIngredientComponent();
128    ConversionContext30_40.INSTANCE.getVersionConvertor_30_40().copyBackboneElement(src,tgt);
129    if (src.hasQuantity())
130      tgt.setQuantity(Ratio30_40.convertRatio(src.getQuantity()));
131    if (src.hasSubstance())
132      tgt.setSubstance(ConversionContext30_40.INSTANCE.getVersionConvertor_30_40().convertType(src.getSubstance()));
133    return tgt;
134  }
135
136  public static org.hl7.fhir.dstu3.model.Substance.SubstanceInstanceComponent convertSubstanceInstanceComponent(org.hl7.fhir.r4.model.Substance.SubstanceInstanceComponent src) throws FHIRException {
137    if (src == null)
138      return null;
139    org.hl7.fhir.dstu3.model.Substance.SubstanceInstanceComponent tgt = new org.hl7.fhir.dstu3.model.Substance.SubstanceInstanceComponent();
140    ConversionContext30_40.INSTANCE.getVersionConvertor_30_40().copyBackboneElement(src,tgt);
141    if (src.hasIdentifier())
142      tgt.setIdentifier(Identifier30_40.convertIdentifier(src.getIdentifier()));
143    if (src.hasExpiry())
144      tgt.setExpiryElement(DateTime30_40.convertDateTime(src.getExpiryElement()));
145    if (src.hasQuantity())
146      tgt.setQuantity(SimpleQuantity30_40.convertSimpleQuantity(src.getQuantity()));
147    return tgt;
148  }
149
150  public static org.hl7.fhir.r4.model.Substance.SubstanceInstanceComponent convertSubstanceInstanceComponent(org.hl7.fhir.dstu3.model.Substance.SubstanceInstanceComponent src) throws FHIRException {
151    if (src == null)
152      return null;
153    org.hl7.fhir.r4.model.Substance.SubstanceInstanceComponent tgt = new org.hl7.fhir.r4.model.Substance.SubstanceInstanceComponent();
154    ConversionContext30_40.INSTANCE.getVersionConvertor_30_40().copyBackboneElement(src,tgt);
155    if (src.hasIdentifier())
156      tgt.setIdentifier(Identifier30_40.convertIdentifier(src.getIdentifier()));
157    if (src.hasExpiry())
158      tgt.setExpiryElement(DateTime30_40.convertDateTime(src.getExpiryElement()));
159    if (src.hasQuantity())
160      tgt.setQuantity(SimpleQuantity30_40.convertSimpleQuantity(src.getQuantity()));
161    return tgt;
162  }
163}