001package org.hl7.fhir.convertors.conv10_40.resources10_40; 002 003import org.hl7.fhir.convertors.context.ConversionContext10_40; 004import org.hl7.fhir.convertors.conv10_40.datatypes10_40.Reference10_40; 005import org.hl7.fhir.convertors.conv10_40.datatypes10_40.complextypes10_40.CodeableConcept10_40; 006import org.hl7.fhir.convertors.conv10_40.datatypes10_40.complextypes10_40.Identifier10_40; 007import org.hl7.fhir.convertors.conv10_40.datatypes10_40.complextypes10_40.Ratio10_40; 008import org.hl7.fhir.convertors.conv10_40.datatypes10_40.complextypes10_40.Timing10_40; 009import org.hl7.fhir.convertors.conv10_40.datatypes10_40.primitivetypes10_40.DateTime10_40; 010import org.hl7.fhir.convertors.conv10_40.datatypes10_40.primitivetypes10_40.String10_40; 011import org.hl7.fhir.exceptions.FHIRException; 012import org.hl7.fhir.r4.model.Dosage.DosageDoseAndRateComponent; 013 014public class MedicationStatement10_40 { 015 016 public static org.hl7.fhir.dstu2.model.MedicationStatement convertMedicationStatement(org.hl7.fhir.r4.model.MedicationStatement src) throws FHIRException { 017 if (src == null || src.isEmpty()) 018 return null; 019 org.hl7.fhir.dstu2.model.MedicationStatement tgt = new org.hl7.fhir.dstu2.model.MedicationStatement(); 020 ConversionContext10_40.INSTANCE.getVersionConvertor_10_40().copyDomainResource(src, tgt); 021 for (org.hl7.fhir.r4.model.Identifier t : src.getIdentifier()) 022 tgt.addIdentifier(Identifier10_40.convertIdentifier(t)); 023 if (src.hasStatus()) 024 tgt.setStatusElement(convertMedicationStatementStatus(src.getStatusElement())); 025 if (src.hasMedication()) 026 tgt.setMedication(ConversionContext10_40.INSTANCE.getVersionConvertor_10_40().convertType(src.getMedication())); 027 if (src.hasSubject()) 028 tgt.setPatient(Reference10_40.convertReference(src.getSubject())); 029 if (src.hasEffective()) 030 tgt.setEffective(ConversionContext10_40.INSTANCE.getVersionConvertor_10_40().convertType(src.getEffective())); 031 if (src.hasInformationSource()) 032 tgt.setInformationSource(Reference10_40.convertReference(src.getInformationSource())); 033 for (org.hl7.fhir.r4.model.Reference t : src.getDerivedFrom()) 034 tgt.addSupportingInformation(Reference10_40.convertReference(t)); 035 if (src.hasDateAsserted()) 036 tgt.setDateAssertedElement(DateTime10_40.convertDateTime(src.getDateAssertedElement())); 037 for (org.hl7.fhir.r4.model.Annotation t : src.getNote()) tgt.setNote(t.getText()); 038 for (org.hl7.fhir.r4.model.Dosage t : src.getDosage()) tgt.addDosage(convertMedicationStatementDosageComponent(t)); 039 return tgt; 040 } 041 042 public static org.hl7.fhir.r4.model.MedicationStatement convertMedicationStatement(org.hl7.fhir.dstu2.model.MedicationStatement src) throws FHIRException { 043 if (src == null || src.isEmpty()) 044 return null; 045 org.hl7.fhir.r4.model.MedicationStatement tgt = new org.hl7.fhir.r4.model.MedicationStatement(); 046 ConversionContext10_40.INSTANCE.getVersionConvertor_10_40().copyDomainResource(src, tgt); 047 for (org.hl7.fhir.dstu2.model.Identifier t : src.getIdentifier()) 048 tgt.addIdentifier(Identifier10_40.convertIdentifier(t)); 049 if (src.hasStatus()) 050 tgt.setStatusElement(convertMedicationStatementStatus(src.getStatusElement())); 051 if (src.hasMedication()) 052 tgt.setMedication(ConversionContext10_40.INSTANCE.getVersionConvertor_10_40().convertType(src.getMedication())); 053 if (src.hasPatient()) 054 tgt.setSubject(Reference10_40.convertReference(src.getPatient())); 055 if (src.hasEffective()) 056 tgt.setEffective(ConversionContext10_40.INSTANCE.getVersionConvertor_10_40().convertType(src.getEffective())); 057 if (src.hasInformationSource()) 058 tgt.setInformationSource(Reference10_40.convertReference(src.getInformationSource())); 059 for (org.hl7.fhir.dstu2.model.Reference t : src.getSupportingInformation()) 060 tgt.addDerivedFrom(Reference10_40.convertReference(t)); 061 if (src.hasDateAsserted()) 062 tgt.setDateAssertedElement(DateTime10_40.convertDateTime(src.getDateAssertedElement())); 063 if (src.hasNote()) 064 tgt.addNote().setText(src.getNote()); 065 for (org.hl7.fhir.dstu2.model.MedicationStatement.MedicationStatementDosageComponent t : src.getDosage()) 066 tgt.addDosage(convertMedicationStatementDosageComponent(t)); 067 return tgt; 068 } 069 070 public static org.hl7.fhir.r4.model.Dosage convertMedicationStatementDosageComponent(org.hl7.fhir.dstu2.model.MedicationStatement.MedicationStatementDosageComponent src) throws FHIRException { 071 if (src == null || src.isEmpty()) 072 return null; 073 org.hl7.fhir.r4.model.Dosage tgt = new org.hl7.fhir.r4.model.Dosage(); 074 ConversionContext10_40.INSTANCE.getVersionConvertor_10_40().copyElement(src, tgt); 075 if (src.hasTextElement()) 076 tgt.setTextElement(String10_40.convertString(src.getTextElement())); 077 if (src.hasTiming()) 078 tgt.setTiming(Timing10_40.convertTiming(src.getTiming())); 079 if (src.hasAsNeeded()) 080 tgt.setAsNeeded(ConversionContext10_40.INSTANCE.getVersionConvertor_10_40().convertType(src.getAsNeeded())); 081 if (src.hasSiteCodeableConcept()) 082 tgt.setSite(CodeableConcept10_40.convertCodeableConcept(src.getSiteCodeableConcept())); 083 if (src.hasRoute()) 084 tgt.setRoute(CodeableConcept10_40.convertCodeableConcept(src.getRoute())); 085 if (src.hasMethod()) 086 tgt.setMethod(CodeableConcept10_40.convertCodeableConcept(src.getMethod())); 087 if (src.hasRate()) { 088 DosageDoseAndRateComponent dr = tgt.addDoseAndRate(); 089 if (src.hasRate()) 090 dr.setRate(ConversionContext10_40.INSTANCE.getVersionConvertor_10_40().convertType(src.getRate())); 091 } 092 if (src.hasMaxDosePerPeriod()) 093 tgt.setMaxDosePerPeriod(Ratio10_40.convertRatio(src.getMaxDosePerPeriod())); 094 return tgt; 095 } 096 097 public static org.hl7.fhir.dstu2.model.MedicationStatement.MedicationStatementDosageComponent convertMedicationStatementDosageComponent(org.hl7.fhir.r4.model.Dosage src) throws FHIRException { 098 if (src == null || src.isEmpty()) 099 return null; 100 org.hl7.fhir.dstu2.model.MedicationStatement.MedicationStatementDosageComponent tgt = new org.hl7.fhir.dstu2.model.MedicationStatement.MedicationStatementDosageComponent(); 101 ConversionContext10_40.INSTANCE.getVersionConvertor_10_40().copyElement(src, tgt); 102 if (src.hasTextElement()) 103 tgt.setTextElement(String10_40.convertString(src.getTextElement())); 104 if (src.hasTiming()) 105 tgt.setTiming(Timing10_40.convertTiming(src.getTiming())); 106 if (src.hasAsNeeded()) 107 tgt.setAsNeeded(ConversionContext10_40.INSTANCE.getVersionConvertor_10_40().convertType(src.getAsNeeded())); 108 if (src.hasSite()) 109 tgt.setSite(ConversionContext10_40.INSTANCE.getVersionConvertor_10_40().convertType(src.getSite())); 110 if (src.hasRoute()) 111 tgt.setRoute(CodeableConcept10_40.convertCodeableConcept(src.getRoute())); 112 if (src.hasMethod()) 113 tgt.setMethod(CodeableConcept10_40.convertCodeableConcept(src.getMethod())); 114 if (src.hasDoseAndRate() && src.getDoseAndRate().get(0).hasRate()) 115 tgt.setRate(ConversionContext10_40.INSTANCE.getVersionConvertor_10_40().convertType(src.getDoseAndRate().get(0).getRate())); 116 if (src.hasMaxDosePerPeriod()) 117 tgt.setMaxDosePerPeriod(Ratio10_40.convertRatio(src.getMaxDosePerPeriod())); 118 return tgt; 119 } 120 121 static public org.hl7.fhir.r4.model.Enumeration<org.hl7.fhir.r4.model.MedicationStatement.MedicationStatementStatus> convertMedicationStatementStatus(org.hl7.fhir.dstu2.model.Enumeration<org.hl7.fhir.dstu2.model.MedicationStatement.MedicationStatementStatus> src) throws FHIRException { 122 if (src == null || src.isEmpty()) 123 return null; 124 org.hl7.fhir.r4.model.Enumeration<org.hl7.fhir.r4.model.MedicationStatement.MedicationStatementStatus> tgt = new org.hl7.fhir.r4.model.Enumeration<>(new org.hl7.fhir.r4.model.MedicationStatement.MedicationStatementStatusEnumFactory()); 125 ConversionContext10_40.INSTANCE.getVersionConvertor_10_40().copyElement(src, tgt); 126 switch (src.getValue()) { 127 case ACTIVE: 128 tgt.setValue(org.hl7.fhir.r4.model.MedicationStatement.MedicationStatementStatus.ACTIVE); 129 break; 130 case COMPLETED: 131 tgt.setValue(org.hl7.fhir.r4.model.MedicationStatement.MedicationStatementStatus.COMPLETED); 132 break; 133 case ENTEREDINERROR: 134 tgt.setValue(org.hl7.fhir.r4.model.MedicationStatement.MedicationStatementStatus.ENTEREDINERROR); 135 break; 136 case INTENDED: 137 tgt.setValue(org.hl7.fhir.r4.model.MedicationStatement.MedicationStatementStatus.INTENDED); 138 break; 139 default: 140 tgt.setValue(org.hl7.fhir.r4.model.MedicationStatement.MedicationStatementStatus.NULL); 141 break; 142 } 143 return tgt; 144 } 145 146 static public org.hl7.fhir.dstu2.model.Enumeration<org.hl7.fhir.dstu2.model.MedicationStatement.MedicationStatementStatus> convertMedicationStatementStatus(org.hl7.fhir.r4.model.Enumeration<org.hl7.fhir.r4.model.MedicationStatement.MedicationStatementStatus> src) throws FHIRException { 147 if (src == null || src.isEmpty()) 148 return null; 149 org.hl7.fhir.dstu2.model.Enumeration<org.hl7.fhir.dstu2.model.MedicationStatement.MedicationStatementStatus> tgt = new org.hl7.fhir.dstu2.model.Enumeration<>(new org.hl7.fhir.dstu2.model.MedicationStatement.MedicationStatementStatusEnumFactory()); 150 ConversionContext10_40.INSTANCE.getVersionConvertor_10_40().copyElement(src, tgt); 151 switch (src.getValue()) { 152 case ACTIVE: 153 tgt.setValue(org.hl7.fhir.dstu2.model.MedicationStatement.MedicationStatementStatus.ACTIVE); 154 break; 155 case COMPLETED: 156 tgt.setValue(org.hl7.fhir.dstu2.model.MedicationStatement.MedicationStatementStatus.COMPLETED); 157 break; 158 case ENTEREDINERROR: 159 tgt.setValue(org.hl7.fhir.dstu2.model.MedicationStatement.MedicationStatementStatus.ENTEREDINERROR); 160 break; 161 case INTENDED: 162 tgt.setValue(org.hl7.fhir.dstu2.model.MedicationStatement.MedicationStatementStatus.INTENDED); 163 break; 164 default: 165 tgt.setValue(org.hl7.fhir.dstu2.model.MedicationStatement.MedicationStatementStatus.NULL); 166 break; 167 } 168 return tgt; 169 } 170}