
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.Dosage30_50; 005import org.hl7.fhir.convertors.conv30_50.datatypes30_50.Reference30_50; 006import org.hl7.fhir.convertors.conv30_50.datatypes30_50.complextypes30_50.Annotation30_50; 007import org.hl7.fhir.convertors.conv30_50.datatypes30_50.complextypes30_50.CodeableConcept30_50; 008import org.hl7.fhir.convertors.conv30_50.datatypes30_50.complextypes30_50.Identifier30_50; 009import org.hl7.fhir.convertors.conv30_50.datatypes30_50.primitivetypes30_50.DateTime30_50; 010import org.hl7.fhir.dstu3.model.Enumeration; 011import org.hl7.fhir.dstu3.model.MedicationStatement; 012import org.hl7.fhir.exceptions.FHIRException; 013import org.hl7.fhir.r5.model.CodeableReference; 014 015public class MedicationStatement30_50 { 016 017 public static org.hl7.fhir.r5.model.MedicationStatement convertMedicationStatement(org.hl7.fhir.dstu3.model.MedicationStatement src) throws FHIRException { 018 if (src == null) 019 return null; 020 org.hl7.fhir.r5.model.MedicationStatement tgt = new org.hl7.fhir.r5.model.MedicationStatement(); 021 ConversionContext30_50.INSTANCE.getVersionConvertor_30_50().copyDomainResource(src, tgt); 022 for (org.hl7.fhir.dstu3.model.Identifier t : src.getIdentifier()) 023 tgt.addIdentifier(Identifier30_50.convertIdentifier(t)); 024// for (org.hl7.fhir.dstu3.model.Reference t : src.getBasedOn()) tgt.addBasedOn(Reference30_50.convertReference(t)); 025// for (org.hl7.fhir.dstu3.model.Reference t : src.getPartOf()) tgt.addPartOf(Reference30_50.convertReference(t)); 026 if (src.hasContext()) 027 tgt.setEncounter(Reference30_50.convertReference(src.getContext())); 028 if (src.hasStatus()) 029 tgt.setStatusElement(convertMedicationStatementStatus(src.getStatusElement())); 030 if (src.hasCategory()) 031 tgt.addCategory(CodeableConcept30_50.convertCodeableConcept(src.getCategory())); 032 if (src.hasMedicationCodeableConcept()) { 033 tgt.getMedication().setConcept(CodeableConcept30_50.convertCodeableConcept(src.getMedicationCodeableConcept())); 034 } 035 if (src.hasMedicationReference()) { 036 tgt.getMedication().setReference(Reference30_50.convertReference(src.getMedicationReference())); 037 } 038 if (src.hasEffective()) 039 tgt.setEffective(ConversionContext30_50.INSTANCE.getVersionConvertor_30_50().convertType(src.getEffective())); 040 if (src.hasDateAsserted()) 041 tgt.setDateAssertedElement(DateTime30_50.convertDateTime(src.getDateAssertedElement())); 042 if (src.hasInformationSource()) 043 tgt.addInformationSource(Reference30_50.convertReference(src.getInformationSource())); 044 if (src.hasSubject()) 045 tgt.setSubject(Reference30_50.convertReference(src.getSubject())); 046 for (org.hl7.fhir.dstu3.model.Reference t : src.getDerivedFrom()) 047 tgt.addDerivedFrom(Reference30_50.convertReference(t)); 048 for (org.hl7.fhir.dstu3.model.CodeableConcept t : src.getReasonCode()) 049 tgt.addReason(Reference30_50.convertCodeableConceptToCodableReference(t)); 050 for (org.hl7.fhir.dstu3.model.Reference t : src.getReasonReference()) 051 tgt.addReason(Reference30_50.convertReferenceToCodableReference(t)); 052 for (org.hl7.fhir.dstu3.model.Annotation t : src.getNote()) tgt.addNote(Annotation30_50.convertAnnotation(t)); 053 for (org.hl7.fhir.dstu3.model.Dosage t : src.getDosage()) tgt.addDosage(Dosage30_50.convertDosage(t)); 054 return tgt; 055 } 056 057 public static org.hl7.fhir.dstu3.model.MedicationStatement convertMedicationStatement(org.hl7.fhir.r5.model.MedicationStatement src) throws FHIRException { 058 if (src == null) 059 return null; 060 org.hl7.fhir.dstu3.model.MedicationStatement tgt = new org.hl7.fhir.dstu3.model.MedicationStatement(); 061 ConversionContext30_50.INSTANCE.getVersionConvertor_30_50().copyDomainResource(src, tgt); 062 for (org.hl7.fhir.r5.model.Identifier t : src.getIdentifier()) 063 tgt.addIdentifier(Identifier30_50.convertIdentifier(t)); 064// for (org.hl7.fhir.r5.model.Reference t : src.getBasedOn()) tgt.addBasedOn(Reference30_50.convertReference(t)); 065// for (org.hl7.fhir.r5.model.Reference t : src.getPartOf()) tgt.addPartOf(Reference30_50.convertReference(t)); 066 if (src.hasEncounter()) 067 tgt.setContext(Reference30_50.convertReference(src.getEncounter())); 068 if (src.hasStatus()) 069 tgt.setStatusElement(convertMedicationStatementStatus(src.getStatusElement())); 070 if (src.hasCategory()) 071 tgt.setCategory(CodeableConcept30_50.convertCodeableConcept(src.getCategoryFirstRep())); 072 if (src.getMedication().hasConcept()) { 073 tgt.setMedication(ConversionContext30_50.INSTANCE.getVersionConvertor_30_50().convertType(src.getMedication().getConcept())); 074 } 075 if (src.getMedication().hasReference()) { 076 tgt.setMedication(ConversionContext30_50.INSTANCE.getVersionConvertor_30_50().convertType(src.getMedication().getReference())); 077 } 078 if (src.hasEffective()) 079 tgt.setEffective(ConversionContext30_50.INSTANCE.getVersionConvertor_30_50().convertType(src.getEffective())); 080 if (src.hasDateAsserted()) 081 tgt.setDateAssertedElement(DateTime30_50.convertDateTime(src.getDateAssertedElement())); 082 if (src.hasInformationSource()) 083 tgt.setInformationSource(Reference30_50.convertReference(src.getInformationSourceFirstRep())); 084 if (src.hasSubject()) 085 tgt.setSubject(Reference30_50.convertReference(src.getSubject())); 086 for (org.hl7.fhir.r5.model.Reference t : src.getDerivedFrom()) 087 tgt.addDerivedFrom(Reference30_50.convertReference(t)); 088 for (CodeableReference t : src.getReason()) 089 if (t.hasConcept()) 090 tgt.addReasonCode(CodeableConcept30_50.convertCodeableConcept(t.getConcept())); 091 for (CodeableReference t : src.getReason()) 092 if (t.hasReference()) 093 tgt.addReasonReference(Reference30_50.convertReference(t.getReference())); 094 for (org.hl7.fhir.r5.model.Annotation t : src.getNote()) tgt.addNote(Annotation30_50.convertAnnotation(t)); 095 for (org.hl7.fhir.r5.model.Dosage t : src.getDosage()) tgt.addDosage(Dosage30_50.convertDosage(t)); 096 return tgt; 097 } 098 099 static public org.hl7.fhir.dstu3.model.Enumeration<org.hl7.fhir.dstu3.model.MedicationStatement.MedicationStatementStatus> convertMedicationStatementStatus(org.hl7.fhir.r5.model.Enumeration<org.hl7.fhir.r5.model.MedicationStatement.MedicationStatementStatusCodes> src) throws FHIRException { 100 if (src == null || src.isEmpty()) 101 return null; 102 Enumeration<MedicationStatement.MedicationStatementStatus> tgt = new Enumeration<>(new MedicationStatement.MedicationStatementStatusEnumFactory()); 103 ConversionContext30_50.INSTANCE.getVersionConvertor_30_50().copyElement(src, tgt); 104 if (src.getValue() == null) { 105 tgt.setValue(null); 106 } else { 107 switch (src.getValue()) { 108 // case ACTIVE: 109// tgt.setValue(org.hl7.fhir.dstu3.model.MedicationStatement.MedicationStatementStatus.ACTIVE); 110// break; 111 case RECORDED: 112 tgt.setValue(MedicationStatement.MedicationStatementStatus.COMPLETED); 113 break; 114 case ENTEREDINERROR: 115 tgt.setValue(MedicationStatement.MedicationStatementStatus.ENTEREDINERROR); 116 break; 117 case DRAFT: 118 tgt.setValue(MedicationStatement.MedicationStatementStatus.COMPLETED); 119 break; 120// case STOPPED: 121// tgt.setValue(org.hl7.fhir.dstu3.model.MedicationStatement.MedicationStatementStatus.STOPPED); 122// break; 123// case ONHOLD: 124// tgt.setValue(org.hl7.fhir.dstu3.model.MedicationStatement.MedicationStatementStatus.ONHOLD); 125// break; 126 default: 127 tgt.setValue(MedicationStatement.MedicationStatementStatus.NULL); 128 break; 129 } 130 } 131 return tgt; 132 } 133 134 static public org.hl7.fhir.r5.model.Enumeration<org.hl7.fhir.r5.model.MedicationStatement.MedicationStatementStatusCodes> convertMedicationStatementStatus(org.hl7.fhir.dstu3.model.Enumeration<org.hl7.fhir.dstu3.model.MedicationStatement.MedicationStatementStatus> src) throws FHIRException { 135 if (src == null || src.isEmpty()) 136 return null; 137 org.hl7.fhir.r5.model.Enumeration<org.hl7.fhir.r5.model.MedicationStatement.MedicationStatementStatusCodes> tgt = new org.hl7.fhir.r5.model.Enumeration<>(new org.hl7.fhir.r5.model.MedicationStatement.MedicationStatementStatusCodesEnumFactory()); 138 ConversionContext30_50.INSTANCE.getVersionConvertor_30_50().copyElement(src, tgt); 139 if (src.getValue() == null) { 140 tgt.setValue(null); 141 } else { 142 switch (src.getValue()) { 143 case ACTIVE: 144 tgt.setValue(org.hl7.fhir.r5.model.MedicationStatement.MedicationStatementStatusCodes.RECORDED); 145 break; 146 case COMPLETED: 147 tgt.setValue(org.hl7.fhir.r5.model.MedicationStatement.MedicationStatementStatusCodes.RECORDED); 148 break; 149 case ENTEREDINERROR: 150 tgt.setValue(org.hl7.fhir.r5.model.MedicationStatement.MedicationStatementStatusCodes.ENTEREDINERROR); 151 break; 152 case INTENDED: 153 tgt.setValue(org.hl7.fhir.r5.model.MedicationStatement.MedicationStatementStatusCodes.RECORDED); 154 break; 155 case STOPPED: 156 tgt.setValue(org.hl7.fhir.r5.model.MedicationStatement.MedicationStatementStatusCodes.RECORDED); 157 break; 158 case ONHOLD: 159 tgt.setValue(org.hl7.fhir.r5.model.MedicationStatement.MedicationStatementStatusCodes.RECORDED); 160 break; 161 default: 162 tgt.setValue(org.hl7.fhir.r5.model.MedicationStatement.MedicationStatementStatusCodes.NULL); 163 break; 164 } 165 } 166 return tgt; 167 } 168}