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.Timing10_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.Dosage.DosageDoseAndRateComponent; 013 014public class MedicationStatement10_50 { 015 016 public static org.hl7.fhir.dstu2.model.MedicationStatement convertMedicationStatement(org.hl7.fhir.r5.model.MedicationUsage 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_50.INSTANCE.getVersionConvertor_10_50().copyDomainResource(src, tgt); 021 for (org.hl7.fhir.r5.model.Identifier t : src.getIdentifier()) 022 tgt.addIdentifier(Identifier10_50.convertIdentifier(t)); 023 if (src.hasStatus()) 024 tgt.setStatusElement(convertMedicationStatementStatus(src.getStatusElement())); 025 if (src.getMedication().hasConcept()) { 026 tgt.setMedication(ConversionContext10_50.INSTANCE.getVersionConvertor_10_50().convertType(src.getMedication().getConcept())); 027 } 028 if (src.getMedication().hasReference()) { 029 tgt.setMedication(ConversionContext10_50.INSTANCE.getVersionConvertor_10_50().convertType(src.getMedication().getReference())); 030 } 031 if (src.hasSubject()) 032 tgt.setPatient(Reference10_50.convertReference(src.getSubject())); 033 if (src.hasEffective()) 034 tgt.setEffective(ConversionContext10_50.INSTANCE.getVersionConvertor_10_50().convertType(src.getEffective())); 035 if (src.hasInformationSource()) 036 tgt.setInformationSource(Reference10_50.convertReference(src.getInformationSource())); 037 for (org.hl7.fhir.r5.model.Reference t : src.getDerivedFrom()) 038 tgt.addSupportingInformation(Reference10_50.convertReference(t)); 039 if (src.hasDateAsserted()) 040 tgt.setDateAssertedElement(DateTime10_50.convertDateTime(src.getDateAssertedElement())); 041 for (org.hl7.fhir.r5.model.Annotation t : src.getNote()) tgt.setNote(t.getText()); 042 for (org.hl7.fhir.r5.model.Dosage t : src.getDosage()) tgt.addDosage(convertMedicationStatementDosageComponent(t)); 043 return tgt; 044 } 045 046 public static org.hl7.fhir.r5.model.MedicationUsage convertMedicationStatement(org.hl7.fhir.dstu2.model.MedicationStatement src) throws FHIRException { 047 if (src == null || src.isEmpty()) 048 return null; 049 org.hl7.fhir.r5.model.MedicationUsage tgt = new org.hl7.fhir.r5.model.MedicationUsage(); 050 ConversionContext10_50.INSTANCE.getVersionConvertor_10_50().copyDomainResource(src, tgt); 051 for (org.hl7.fhir.dstu2.model.Identifier t : src.getIdentifier()) 052 tgt.addIdentifier(Identifier10_50.convertIdentifier(t)); 053 if (src.hasStatus()) 054 tgt.setStatusElement(convertMedicationStatementStatus(src.getStatusElement())); 055 if (src.hasMedicationCodeableConcept()) { 056 tgt.getMedication().setConcept(CodeableConcept10_50.convertCodeableConcept(src.getMedicationCodeableConcept())); 057 } 058 if (src.hasMedicationReference()) { 059 tgt.getMedication().setReference(Reference10_50.convertReference(src.getMedicationReference())); 060 } 061 if (src.hasPatient()) 062 tgt.setSubject(Reference10_50.convertReference(src.getPatient())); 063 if (src.hasEffective()) 064 tgt.setEffective(ConversionContext10_50.INSTANCE.getVersionConvertor_10_50().convertType(src.getEffective())); 065 if (src.hasInformationSource()) 066 tgt.setInformationSource(Reference10_50.convertReference(src.getInformationSource())); 067 for (org.hl7.fhir.dstu2.model.Reference t : src.getSupportingInformation()) 068 tgt.addDerivedFrom(Reference10_50.convertReference(t)); 069 if (src.hasDateAsserted()) 070 tgt.setDateAssertedElement(DateTime10_50.convertDateTime(src.getDateAssertedElement())); 071 if (src.hasNote()) 072 tgt.addNote().setText(src.getNote()); 073 for (org.hl7.fhir.dstu2.model.MedicationStatement.MedicationStatementDosageComponent t : src.getDosage()) 074 tgt.addDosage(convertMedicationStatementDosageComponent(t)); 075 return tgt; 076 } 077 078 public static org.hl7.fhir.r5.model.Dosage convertMedicationStatementDosageComponent(org.hl7.fhir.dstu2.model.MedicationStatement.MedicationStatementDosageComponent src) throws FHIRException { 079 if (src == null || src.isEmpty()) 080 return null; 081 org.hl7.fhir.r5.model.Dosage tgt = new org.hl7.fhir.r5.model.Dosage(); 082 ConversionContext10_50.INSTANCE.getVersionConvertor_10_50().copyElement(src, tgt); 083 if (src.hasTextElement()) 084 tgt.setTextElement(String10_50.convertString(src.getTextElement())); 085 if (src.hasTiming()) 086 tgt.setTiming(Timing10_50.convertTiming(src.getTiming())); 087 if (src.hasAsNeeded()) 088 tgt.setAsNeeded(ConversionContext10_50.INSTANCE.getVersionConvertor_10_50().convertType(src.getAsNeeded())); 089 if (src.hasSiteCodeableConcept()) 090 tgt.setSite(CodeableConcept10_50.convertCodeableConcept(src.getSiteCodeableConcept())); 091 if (src.hasRoute()) 092 tgt.setRoute(CodeableConcept10_50.convertCodeableConcept(src.getRoute())); 093 if (src.hasMethod()) 094 tgt.setMethod(CodeableConcept10_50.convertCodeableConcept(src.getMethod())); 095 if (src.hasRate()) { 096 DosageDoseAndRateComponent dr = tgt.addDoseAndRate(); 097 if (src.hasRate()) 098 dr.setRate(ConversionContext10_50.INSTANCE.getVersionConvertor_10_50().convertType(src.getRate())); 099 } 100 if (src.hasMaxDosePerPeriod()) 101 tgt.setMaxDosePerPeriod(Ratio10_50.convertRatio(src.getMaxDosePerPeriod())); 102 return tgt; 103 } 104 105 public static org.hl7.fhir.dstu2.model.MedicationStatement.MedicationStatementDosageComponent convertMedicationStatementDosageComponent(org.hl7.fhir.r5.model.Dosage src) throws FHIRException { 106 if (src == null || src.isEmpty()) 107 return null; 108 org.hl7.fhir.dstu2.model.MedicationStatement.MedicationStatementDosageComponent tgt = new org.hl7.fhir.dstu2.model.MedicationStatement.MedicationStatementDosageComponent(); 109 ConversionContext10_50.INSTANCE.getVersionConvertor_10_50().copyElement(src, tgt); 110 if (src.hasTextElement()) 111 tgt.setTextElement(String10_50.convertString(src.getTextElement())); 112 if (src.hasTiming()) 113 tgt.setTiming(Timing10_50.convertTiming(src.getTiming())); 114 if (src.hasAsNeeded()) 115 tgt.setAsNeeded(ConversionContext10_50.INSTANCE.getVersionConvertor_10_50().convertType(src.getAsNeeded())); 116 if (src.hasSite()) 117 tgt.setSite(ConversionContext10_50.INSTANCE.getVersionConvertor_10_50().convertType(src.getSite())); 118 if (src.hasRoute()) 119 tgt.setRoute(CodeableConcept10_50.convertCodeableConcept(src.getRoute())); 120 if (src.hasMethod()) 121 tgt.setMethod(CodeableConcept10_50.convertCodeableConcept(src.getMethod())); 122 if (src.hasDoseAndRate() && src.getDoseAndRate().get(0).hasRate()) 123 tgt.setRate(ConversionContext10_50.INSTANCE.getVersionConvertor_10_50().convertType(src.getDoseAndRate().get(0).getRate())); 124 if (src.hasMaxDosePerPeriod()) 125 tgt.setMaxDosePerPeriod(Ratio10_50.convertRatio(src.getMaxDosePerPeriod())); 126 return tgt; 127 } 128 129 static public org.hl7.fhir.r5.model.Enumeration<org.hl7.fhir.r5.model.MedicationUsage.MedicationUsageStatusCodes> convertMedicationStatementStatus(org.hl7.fhir.dstu2.model.Enumeration<org.hl7.fhir.dstu2.model.MedicationStatement.MedicationStatementStatus> src) throws FHIRException { 130 if (src == null || src.isEmpty()) 131 return null; 132 org.hl7.fhir.r5.model.Enumeration<org.hl7.fhir.r5.model.MedicationUsage.MedicationUsageStatusCodes> tgt = new org.hl7.fhir.r5.model.Enumeration<>(new org.hl7.fhir.r5.model.MedicationUsage.MedicationUsageStatusCodesEnumFactory()); 133 ConversionContext10_50.INSTANCE.getVersionConvertor_10_50().copyElement(src, tgt); 134 switch (src.getValue()) { 135 case ACTIVE: 136 tgt.setValue(org.hl7.fhir.r5.model.MedicationUsage.MedicationUsageStatusCodes.RECORDED); 137 break; 138 case COMPLETED: 139 tgt.setValue(org.hl7.fhir.r5.model.MedicationUsage.MedicationUsageStatusCodes.RECORDED); 140 break; 141 case ENTEREDINERROR: 142 tgt.setValue(org.hl7.fhir.r5.model.MedicationUsage.MedicationUsageStatusCodes.ENTEREDINERROR); 143 break; 144 case INTENDED: 145 tgt.setValue(org.hl7.fhir.r5.model.MedicationUsage.MedicationUsageStatusCodes.RECORDED); 146 break; 147 default: 148 tgt.setValue(org.hl7.fhir.r5.model.MedicationUsage.MedicationUsageStatusCodes.NULL); 149 break; 150 } 151 return tgt; 152 } 153 154 static public org.hl7.fhir.dstu2.model.Enumeration<org.hl7.fhir.dstu2.model.MedicationStatement.MedicationStatementStatus> convertMedicationStatementStatus(org.hl7.fhir.r5.model.Enumeration<org.hl7.fhir.r5.model.MedicationUsage.MedicationUsageStatusCodes> src) throws FHIRException { 155 if (src == null || src.isEmpty()) 156 return null; 157 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()); 158 ConversionContext10_50.INSTANCE.getVersionConvertor_10_50().copyElement(src, tgt); 159 switch (src.getValue()) { 160// case ACTIVE: 161// tgt.setValue(org.hl7.fhir.dstu2.model.MedicationStatement.MedicationStatementStatus.ACTIVE); 162// break; 163 case RECORDED: 164 tgt.setValue(org.hl7.fhir.dstu2.model.MedicationStatement.MedicationStatementStatus.COMPLETED); 165 break; 166 case ENTEREDINERROR: 167 tgt.setValue(org.hl7.fhir.dstu2.model.MedicationStatement.MedicationStatementStatus.ENTEREDINERROR); 168 break; 169 case DRAFT: 170 tgt.setValue(org.hl7.fhir.dstu2.model.MedicationStatement.MedicationStatementStatus.ACTIVE); 171 break; 172 default: 173 tgt.setValue(org.hl7.fhir.dstu2.model.MedicationStatement.MedicationStatementStatus.NULL); 174 break; 175 } 176 return tgt; 177 } 178}