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.Reference10_50;
005import org.hl7.fhir.convertors.conv10_50.datatypes10_50.complextypes10_50.CodeableConcept10_50;
006import org.hl7.fhir.convertors.conv10_50.datatypes10_50.complextypes10_50.Identifier10_50;
007import org.hl7.fhir.convertors.conv10_50.datatypes10_50.complextypes10_50.Ratio10_50;
008import org.hl7.fhir.convertors.conv10_50.datatypes10_50.complextypes10_50.SimpleQuantity10_50;
009import org.hl7.fhir.convertors.conv10_50.datatypes10_50.primitivetypes10_50.DateTime10_50;
010import org.hl7.fhir.convertors.conv10_50.datatypes10_50.primitivetypes10_50.String10_50;
011import org.hl7.fhir.exceptions.FHIRException;
012import org.hl7.fhir.r5.model.Identifier;
013
014public class Substance10_50 {
015
016  public static org.hl7.fhir.r5.model.Substance convertSubstance(org.hl7.fhir.dstu2.model.Substance src) throws FHIRException {
017    if (src == null || src.isEmpty())
018      return null;
019    org.hl7.fhir.r5.model.Substance tgt = new org.hl7.fhir.r5.model.Substance();
020    ConversionContext10_50.INSTANCE.getVersionConvertor_10_50().copyDomainResource(src, tgt);
021    for (org.hl7.fhir.dstu2.model.Identifier t : src.getIdentifier())
022      tgt.addIdentifier(Identifier10_50.convertIdentifier(t));
023    for (org.hl7.fhir.dstu2.model.CodeableConcept t : src.getCategory())
024      tgt.addCategory(CodeableConcept10_50.convertCodeableConcept(t));
025    if (src.hasCode())
026      tgt.getCode().setConcept(CodeableConcept10_50.convertCodeableConcept(src.getCode()));
027    if (src.hasDescriptionElement())
028      tgt.setDescriptionElement(String10_50.convertStringToMarkdown(src.getDescriptionElement()));
029    for (org.hl7.fhir.dstu2.model.Substance.SubstanceInstanceComponent t : src.getInstance())
030      convertSubstanceInstanceComponent(t, tgt);
031    for (org.hl7.fhir.dstu2.model.Substance.SubstanceIngredientComponent t : src.getIngredient())
032      tgt.addIngredient(convertSubstanceIngredientComponent(t));
033    return tgt;
034  }
035
036  public static org.hl7.fhir.dstu2.model.Substance convertSubstance(org.hl7.fhir.r5.model.Substance src) throws FHIRException {
037    if (src == null || src.isEmpty())
038      return null;
039    org.hl7.fhir.dstu2.model.Substance tgt = new org.hl7.fhir.dstu2.model.Substance();
040    ConversionContext10_50.INSTANCE.getVersionConvertor_10_50().copyDomainResource(src, tgt);
041    for (org.hl7.fhir.r5.model.Identifier t : src.getIdentifier())
042      tgt.addIdentifier(Identifier10_50.convertIdentifier(t));
043    for (org.hl7.fhir.r5.model.CodeableConcept t : src.getCategory())
044      tgt.addCategory(CodeableConcept10_50.convertCodeableConcept(t));
045    if (src.hasCode())
046      tgt.setCode(CodeableConcept10_50.convertCodeableConcept(src.getCode().getConcept()));
047    if (src.hasDescriptionElement())
048      tgt.setDescriptionElement(String10_50.convertString(src.getDescriptionElement()));
049    if (src.getInstance()) {
050      tgt.addInstance(convertSubstanceInstanceComponent(src));
051    }
052    for (org.hl7.fhir.r5.model.Substance.SubstanceIngredientComponent t : src.getIngredient())
053      tgt.addIngredient(convertSubstanceIngredientComponent(t));
054    return tgt;
055  }
056
057  public static org.hl7.fhir.dstu2.model.Substance.SubstanceIngredientComponent convertSubstanceIngredientComponent(org.hl7.fhir.r5.model.Substance.SubstanceIngredientComponent src) throws FHIRException {
058    if (src == null || src.isEmpty())
059      return null;
060    org.hl7.fhir.dstu2.model.Substance.SubstanceIngredientComponent tgt = new org.hl7.fhir.dstu2.model.Substance.SubstanceIngredientComponent();
061    ConversionContext10_50.INSTANCE.getVersionConvertor_10_50().copyBackboneElement(src,tgt);
062    if (src.hasQuantity())
063      tgt.setQuantity(Ratio10_50.convertRatio(src.getQuantity()));
064    return tgt;
065  }
066
067  public static org.hl7.fhir.r5.model.Substance.SubstanceIngredientComponent convertSubstanceIngredientComponent(org.hl7.fhir.dstu2.model.Substance.SubstanceIngredientComponent src) throws FHIRException {
068    if (src == null || src.isEmpty())
069      return null;
070    org.hl7.fhir.r5.model.Substance.SubstanceIngredientComponent tgt = new org.hl7.fhir.r5.model.Substance.SubstanceIngredientComponent();
071    ConversionContext10_50.INSTANCE.getVersionConvertor_10_50().copyBackboneElement(src,tgt);
072    if (src.hasQuantity())
073      tgt.setQuantity(Ratio10_50.convertRatio(src.getQuantity()));
074    if (src.hasSubstance())
075      tgt.setSubstance(Reference10_50.convertReference(src.getSubstance()));
076    return tgt;
077  }
078
079  public static org.hl7.fhir.dstu2.model.Substance.SubstanceInstanceComponent convertSubstanceInstanceComponent(org.hl7.fhir.r5.model.Substance src) throws FHIRException {
080    org.hl7.fhir.dstu2.model.Substance.SubstanceInstanceComponent tgt = new org.hl7.fhir.dstu2.model.Substance.SubstanceInstanceComponent();
081    for (Identifier t : src.getIdentifier()) {
082      tgt.setIdentifier(Identifier10_50.convertIdentifier(t));
083    }
084    if (src.hasExpiry())
085      tgt.setExpiryElement(DateTime10_50.convertDateTime(src.getExpiryElement()));
086    if (src.hasQuantity())
087      tgt.setQuantity(SimpleQuantity10_50.convertSimpleQuantity(src.getQuantity()));
088    return tgt;
089  }
090
091
092  public static void convertSubstanceInstanceComponent(org.hl7.fhir.dstu2.model.Substance.SubstanceInstanceComponent src, org.hl7.fhir.r5.model.Substance tgt) throws FHIRException {
093    tgt.setInstance(true);
094    if (src.hasIdentifier())
095      tgt.addIdentifier(Identifier10_50.convertIdentifier(src.getIdentifier()));
096    if (src.hasExpiryElement())
097      tgt.setExpiryElement(DateTime10_50.convertDateTime(src.getExpiryElement()));
098    if (src.hasQuantity())
099      tgt.setQuantity(SimpleQuantity10_50.convertSimpleQuantity(src.getQuantity()));
100  }
101}