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.Reference30_50;
005import org.hl7.fhir.convertors.conv30_50.datatypes30_50.complextypes30_50.CodeableConcept30_50;
006import org.hl7.fhir.convertors.conv30_50.datatypes30_50.complextypes30_50.Ratio30_50;
007import org.hl7.fhir.convertors.conv30_50.datatypes30_50.primitivetypes30_50.Boolean30_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;
011
012public class Medication30_50 {
013
014  public static org.hl7.fhir.r5.model.Medication convertMedication(org.hl7.fhir.dstu3.model.Medication src) throws FHIRException {
015    if (src == null)
016      return null;
017    org.hl7.fhir.r5.model.Medication tgt = new org.hl7.fhir.r5.model.Medication();
018    ConversionContext30_50.INSTANCE.getVersionConvertor_30_50().copyDomainResource(src, tgt);
019    if (src.hasCode())
020      tgt.setCode(CodeableConcept30_50.convertCodeableConcept(src.getCode()));
021    if (src.hasStatus())
022      tgt.setStatusElement(convertMedicationStatus(src.getStatusElement()));
023    if (src.hasManufacturer())
024      tgt.setMarketingAuthorizationHolder(Reference30_50.convertReference(src.getManufacturer()));
025    if (src.hasForm())
026      tgt.setDoseForm(CodeableConcept30_50.convertCodeableConcept(src.getForm()));
027    for (org.hl7.fhir.dstu3.model.Medication.MedicationIngredientComponent t : src.getIngredient())
028      tgt.addIngredient(convertMedicationIngredientComponent(t));
029    if (src.hasPackage())
030      tgt.setBatch(convertMedicationPackageBatchComponent(src.getPackage().getBatchFirstRep()));
031    return tgt;
032  }
033
034  public static org.hl7.fhir.dstu3.model.Medication convertMedication(org.hl7.fhir.r5.model.Medication src) throws FHIRException {
035    if (src == null)
036      return null;
037    org.hl7.fhir.dstu3.model.Medication tgt = new org.hl7.fhir.dstu3.model.Medication();
038    ConversionContext30_50.INSTANCE.getVersionConvertor_30_50().copyDomainResource(src, tgt);
039    if (src.hasCode())
040      tgt.setCode(CodeableConcept30_50.convertCodeableConcept(src.getCode()));
041    if (src.hasStatus())
042      tgt.setStatusElement(convertMedicationStatus(src.getStatusElement()));
043    if (src.hasMarketingAuthorizationHolder())
044      tgt.setManufacturer(Reference30_50.convertReference(src.getMarketingAuthorizationHolder()));
045    if (src.hasDoseForm())
046      tgt.setForm(CodeableConcept30_50.convertCodeableConcept(src.getDoseForm()));
047    for (org.hl7.fhir.r5.model.Medication.MedicationIngredientComponent t : src.getIngredient())
048      tgt.addIngredient(convertMedicationIngredientComponent(t));
049    if (src.hasBatch())
050      tgt.getPackage().addBatch(convertMedicationPackageBatchComponent(src.getBatch()));
051    return tgt;
052  }
053
054  public static org.hl7.fhir.dstu3.model.Medication.MedicationIngredientComponent convertMedicationIngredientComponent(org.hl7.fhir.r5.model.Medication.MedicationIngredientComponent src) throws FHIRException {
055    if (src == null)
056      return null;
057    org.hl7.fhir.dstu3.model.Medication.MedicationIngredientComponent tgt = new org.hl7.fhir.dstu3.model.Medication.MedicationIngredientComponent();
058    ConversionContext30_50.INSTANCE.getVersionConvertor_30_50().copyElement(src, tgt);
059    if (src.getItem().hasConcept())
060      tgt.setItem(ConversionContext30_50.INSTANCE.getVersionConvertor_30_50().convertType(src.getItem().getConcept()));
061    if (src.getItem().hasReference())
062      tgt.setItem(ConversionContext30_50.INSTANCE.getVersionConvertor_30_50().convertType(src.getItem().getReference()));
063    if (src.hasIsActive())
064      tgt.setIsActiveElement(Boolean30_50.convertBoolean(src.getIsActiveElement()));
065    if (src.hasStrengthRatio())
066      tgt.setAmount(Ratio30_50.convertRatio(src.getStrengthRatio()));
067    return tgt;
068  }
069
070  public static org.hl7.fhir.r5.model.Medication.MedicationIngredientComponent convertMedicationIngredientComponent(org.hl7.fhir.dstu3.model.Medication.MedicationIngredientComponent src) throws FHIRException {
071    if (src == null)
072      return null;
073    org.hl7.fhir.r5.model.Medication.MedicationIngredientComponent tgt = new org.hl7.fhir.r5.model.Medication.MedicationIngredientComponent();
074    ConversionContext30_50.INSTANCE.getVersionConvertor_30_50().copyElement(src, tgt);
075    if (src.hasItemCodeableConcept())
076      tgt.getItem().setConcept(CodeableConcept30_50.convertCodeableConcept(src.getItemCodeableConcept()));
077    if (src.hasItemReference())
078      tgt.getItem().setReference(Reference30_50.convertReference(src.getItemReference()));
079    if (src.hasIsActive())
080      tgt.setIsActiveElement(Boolean30_50.convertBoolean(src.getIsActiveElement()));
081    if (src.hasAmount())
082      tgt.setStrength(Ratio30_50.convertRatio(src.getAmount()));
083    return tgt;
084  }
085
086  public static org.hl7.fhir.dstu3.model.Medication.MedicationPackageBatchComponent convertMedicationPackageBatchComponent(org.hl7.fhir.r5.model.Medication.MedicationBatchComponent src) throws FHIRException {
087    if (src == null)
088      return null;
089    org.hl7.fhir.dstu3.model.Medication.MedicationPackageBatchComponent tgt = new org.hl7.fhir.dstu3.model.Medication.MedicationPackageBatchComponent();
090    ConversionContext30_50.INSTANCE.getVersionConvertor_30_50().copyElement(src, tgt);
091    if (src.hasLotNumber())
092      tgt.setLotNumberElement(String30_50.convertString(src.getLotNumberElement()));
093    if (src.hasExpirationDate())
094      tgt.setExpirationDateElement(DateTime30_50.convertDateTime(src.getExpirationDateElement()));
095    return tgt;
096  }
097
098  public static org.hl7.fhir.r5.model.Medication.MedicationBatchComponent convertMedicationPackageBatchComponent(org.hl7.fhir.dstu3.model.Medication.MedicationPackageBatchComponent src) throws FHIRException {
099    if (src == null)
100      return null;
101    org.hl7.fhir.r5.model.Medication.MedicationBatchComponent tgt = new org.hl7.fhir.r5.model.Medication.MedicationBatchComponent();
102    ConversionContext30_50.INSTANCE.getVersionConvertor_30_50().copyElement(src, tgt);
103    if (src.hasLotNumber())
104      tgt.setLotNumberElement(String30_50.convertString(src.getLotNumberElement()));
105    if (src.hasExpirationDate())
106      tgt.setExpirationDateElement(DateTime30_50.convertDateTime(src.getExpirationDateElement()));
107    return tgt;
108  }
109
110  static public org.hl7.fhir.r5.model.Enumeration<org.hl7.fhir.r5.model.Medication.MedicationStatusCodes> convertMedicationStatus(org.hl7.fhir.dstu3.model.Enumeration<org.hl7.fhir.dstu3.model.Medication.MedicationStatus> src) throws FHIRException {
111    if (src == null || src.isEmpty())
112      return null;
113    org.hl7.fhir.r5.model.Enumeration<org.hl7.fhir.r5.model.Medication.MedicationStatusCodes> tgt = new org.hl7.fhir.r5.model.Enumeration<>(new org.hl7.fhir.r5.model.Medication.MedicationStatusCodesEnumFactory());
114    ConversionContext30_50.INSTANCE.getVersionConvertor_30_50().copyElement(src, tgt);
115    switch (src.getValue()) {
116      case ACTIVE:
117        tgt.setValue(org.hl7.fhir.r5.model.Medication.MedicationStatusCodes.ACTIVE);
118        break;
119      case INACTIVE:
120        tgt.setValue(org.hl7.fhir.r5.model.Medication.MedicationStatusCodes.INACTIVE);
121        break;
122      case ENTEREDINERROR:
123        tgt.setValue(org.hl7.fhir.r5.model.Medication.MedicationStatusCodes.ENTEREDINERROR);
124        break;
125      default:
126        tgt.setValue(org.hl7.fhir.r5.model.Medication.MedicationStatusCodes.NULL);
127        break;
128    }
129    return tgt;
130  }
131
132  static public org.hl7.fhir.dstu3.model.Enumeration<org.hl7.fhir.dstu3.model.Medication.MedicationStatus> convertMedicationStatus(org.hl7.fhir.r5.model.Enumeration<org.hl7.fhir.r5.model.Medication.MedicationStatusCodes> src) throws FHIRException {
133    if (src == null || src.isEmpty())
134      return null;
135    org.hl7.fhir.dstu3.model.Enumeration<org.hl7.fhir.dstu3.model.Medication.MedicationStatus> tgt = new org.hl7.fhir.dstu3.model.Enumeration<>(new org.hl7.fhir.dstu3.model.Medication.MedicationStatusEnumFactory());
136    ConversionContext30_50.INSTANCE.getVersionConvertor_30_50().copyElement(src, tgt);
137    switch (src.getValue()) {
138      case ACTIVE:
139        tgt.setValue(org.hl7.fhir.dstu3.model.Medication.MedicationStatus.ACTIVE);
140        break;
141      case INACTIVE:
142        tgt.setValue(org.hl7.fhir.dstu3.model.Medication.MedicationStatus.INACTIVE);
143        break;
144      case ENTEREDINERROR:
145        tgt.setValue(org.hl7.fhir.dstu3.model.Medication.MedicationStatus.ENTEREDINERROR);
146        break;
147      default:
148        tgt.setValue(org.hl7.fhir.dstu3.model.Medication.MedicationStatus.NULL);
149        break;
150    }
151    return tgt;
152  }
153}