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.Reference30_40; 005import org.hl7.fhir.convertors.conv30_40.datatypes30_40.complextypes30_40.CodeableConcept30_40; 006import org.hl7.fhir.convertors.conv30_40.datatypes30_40.complextypes30_40.Ratio30_40; 007import org.hl7.fhir.convertors.conv30_40.datatypes30_40.primitivetypes30_40.Boolean30_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; 011 012public class Medication30_40 { 013 014 public static org.hl7.fhir.r4.model.Medication convertMedication(org.hl7.fhir.dstu3.model.Medication src) throws FHIRException { 015 if (src == null) 016 return null; 017 org.hl7.fhir.r4.model.Medication tgt = new org.hl7.fhir.r4.model.Medication(); 018 ConversionContext30_40.INSTANCE.getVersionConvertor_30_40().copyDomainResource(src, tgt); 019 if (src.hasCode()) 020 tgt.setCode(CodeableConcept30_40.convertCodeableConcept(src.getCode())); 021 if (src.hasStatus()) 022 tgt.setStatusElement(convertMedicationStatus(src.getStatusElement())); 023 if (src.hasManufacturer()) 024 tgt.setManufacturer(Reference30_40.convertReference(src.getManufacturer())); 025 if (src.hasForm()) 026 tgt.setForm(CodeableConcept30_40.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.r4.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_40.INSTANCE.getVersionConvertor_30_40().copyDomainResource(src, tgt); 039 if (src.hasCode()) 040 tgt.setCode(CodeableConcept30_40.convertCodeableConcept(src.getCode())); 041 if (src.hasStatus()) 042 tgt.setStatusElement(convertMedicationStatus(src.getStatusElement())); 043 if (src.hasManufacturer()) 044 tgt.setManufacturer(Reference30_40.convertReference(src.getManufacturer())); 045 if (src.hasForm()) 046 tgt.setForm(CodeableConcept30_40.convertCodeableConcept(src.getForm())); 047 for (org.hl7.fhir.r4.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.r4.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_40.INSTANCE.getVersionConvertor_30_40().copyBackboneElement(src,tgt); 059 if (src.hasItem()) 060 tgt.setItem(ConversionContext30_40.INSTANCE.getVersionConvertor_30_40().convertType(src.getItem())); 061 if (src.hasIsActive()) 062 tgt.setIsActiveElement(Boolean30_40.convertBoolean(src.getIsActiveElement())); 063 if (src.hasStrength()) 064 tgt.setAmount(Ratio30_40.convertRatio(src.getStrength())); 065 return tgt; 066 } 067 068 public static org.hl7.fhir.r4.model.Medication.MedicationIngredientComponent convertMedicationIngredientComponent(org.hl7.fhir.dstu3.model.Medication.MedicationIngredientComponent src) throws FHIRException { 069 if (src == null) 070 return null; 071 org.hl7.fhir.r4.model.Medication.MedicationIngredientComponent tgt = new org.hl7.fhir.r4.model.Medication.MedicationIngredientComponent(); 072 ConversionContext30_40.INSTANCE.getVersionConvertor_30_40().copyBackboneElement(src,tgt); 073 if (src.hasItem()) 074 tgt.setItem(ConversionContext30_40.INSTANCE.getVersionConvertor_30_40().convertType(src.getItem())); 075 if (src.hasIsActive()) 076 tgt.setIsActiveElement(Boolean30_40.convertBoolean(src.getIsActiveElement())); 077 if (src.hasAmount()) 078 tgt.setStrength(Ratio30_40.convertRatio(src.getAmount())); 079 return tgt; 080 } 081 082 public static org.hl7.fhir.dstu3.model.Medication.MedicationPackageBatchComponent convertMedicationPackageBatchComponent(org.hl7.fhir.r4.model.Medication.MedicationBatchComponent src) throws FHIRException { 083 if (src == null) 084 return null; 085 org.hl7.fhir.dstu3.model.Medication.MedicationPackageBatchComponent tgt = new org.hl7.fhir.dstu3.model.Medication.MedicationPackageBatchComponent(); 086 ConversionContext30_40.INSTANCE.getVersionConvertor_30_40().copyBackboneElement(src,tgt); 087 if (src.hasLotNumber()) 088 tgt.setLotNumberElement(String30_40.convertString(src.getLotNumberElement())); 089 if (src.hasExpirationDate()) 090 tgt.setExpirationDateElement(DateTime30_40.convertDateTime(src.getExpirationDateElement())); 091 return tgt; 092 } 093 094 public static org.hl7.fhir.r4.model.Medication.MedicationBatchComponent convertMedicationPackageBatchComponent(org.hl7.fhir.dstu3.model.Medication.MedicationPackageBatchComponent src) throws FHIRException { 095 if (src == null) 096 return null; 097 org.hl7.fhir.r4.model.Medication.MedicationBatchComponent tgt = new org.hl7.fhir.r4.model.Medication.MedicationBatchComponent(); 098 ConversionContext30_40.INSTANCE.getVersionConvertor_30_40().copyBackboneElement(src,tgt); 099 if (src.hasLotNumber()) 100 tgt.setLotNumberElement(String30_40.convertString(src.getLotNumberElement())); 101 if (src.hasExpirationDate()) 102 tgt.setExpirationDateElement(DateTime30_40.convertDateTime(src.getExpirationDateElement())); 103 return tgt; 104 } 105 106 static public org.hl7.fhir.dstu3.model.Enumeration<org.hl7.fhir.dstu3.model.Medication.MedicationStatus> convertMedicationStatus(org.hl7.fhir.r4.model.Enumeration<org.hl7.fhir.r4.model.Medication.MedicationStatus> src) throws FHIRException { 107 if (src == null || src.isEmpty()) 108 return null; 109 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()); 110 ConversionContext30_40.INSTANCE.getVersionConvertor_30_40().copyElement(src, tgt); 111 switch (src.getValue()) { 112 case ACTIVE: 113 tgt.setValue(org.hl7.fhir.dstu3.model.Medication.MedicationStatus.ACTIVE); 114 break; 115 case INACTIVE: 116 tgt.setValue(org.hl7.fhir.dstu3.model.Medication.MedicationStatus.INACTIVE); 117 break; 118 case ENTEREDINERROR: 119 tgt.setValue(org.hl7.fhir.dstu3.model.Medication.MedicationStatus.ENTEREDINERROR); 120 break; 121 default: 122 tgt.setValue(org.hl7.fhir.dstu3.model.Medication.MedicationStatus.NULL); 123 break; 124 } 125 return tgt; 126 } 127 128 static public org.hl7.fhir.r4.model.Enumeration<org.hl7.fhir.r4.model.Medication.MedicationStatus> convertMedicationStatus(org.hl7.fhir.dstu3.model.Enumeration<org.hl7.fhir.dstu3.model.Medication.MedicationStatus> src) throws FHIRException { 129 if (src == null || src.isEmpty()) 130 return null; 131 org.hl7.fhir.r4.model.Enumeration<org.hl7.fhir.r4.model.Medication.MedicationStatus> tgt = new org.hl7.fhir.r4.model.Enumeration<>(new org.hl7.fhir.r4.model.Medication.MedicationStatusEnumFactory()); 132 ConversionContext30_40.INSTANCE.getVersionConvertor_30_40().copyElement(src, tgt); 133 switch (src.getValue()) { 134 case ACTIVE: 135 tgt.setValue(org.hl7.fhir.r4.model.Medication.MedicationStatus.ACTIVE); 136 break; 137 case INACTIVE: 138 tgt.setValue(org.hl7.fhir.r4.model.Medication.MedicationStatus.INACTIVE); 139 break; 140 case ENTEREDINERROR: 141 tgt.setValue(org.hl7.fhir.r4.model.Medication.MedicationStatus.ENTEREDINERROR); 142 break; 143 default: 144 tgt.setValue(org.hl7.fhir.r4.model.Medication.MedicationStatus.NULL); 145 break; 146 } 147 return tgt; 148 } 149}