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