
001package org.hl7.fhir.convertors.conv43_50.resources43_50; 002 003import org.hl7.fhir.convertors.VersionConvertorConstants; 004import org.hl7.fhir.convertors.context.ConversionContext43_50; 005import org.hl7.fhir.convertors.conv43_50.datatypes43_50.general43_50.Annotation43_50; 006import org.hl7.fhir.convertors.conv43_50.datatypes43_50.general43_50.CodeableConcept43_50; 007import org.hl7.fhir.convertors.conv43_50.datatypes43_50.general43_50.Identifier43_50; 008import org.hl7.fhir.convertors.conv43_50.datatypes43_50.primitive43_50.DateTime43_50; 009import org.hl7.fhir.convertors.conv43_50.datatypes43_50.special43_50.Dosage43_50; 010import org.hl7.fhir.convertors.conv43_50.datatypes43_50.special43_50.Reference43_50; 011import org.hl7.fhir.exceptions.FHIRException; 012import org.hl7.fhir.r5.model.CodeableReference; 013import org.hl7.fhir.r5.model.Enumeration; 014import org.hl7.fhir.r5.model.MedicationStatement; 015 016/* 017 Copyright (c) 2011+, HL7, Inc. 018 All rights reserved. 019 020 Redistribution and use in source and binary forms, with or without modification, 021 are permitted provided that the following conditions are met: 022 023 * Redistributions of source code must retain the above copyright notice, this 024 list of conditions and the following disclaimer. 025 * Redistributions in binary form must reproduce the above copyright notice, 026 this list of conditions and the following disclaimer in the documentation 027 and/or other materials provided with the distribution. 028 * Neither the name of HL7 nor the names of its contributors may be used to 029 endorse or promote products derived from this software without specific 030 prior written permission. 031 032 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 033 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 034 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 035 IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 036 INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 037 NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 038 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 039 WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 040 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 041 POSSIBILITY OF SUCH DAMAGE. 042 043*/ 044// Generated on Sun, Feb 24, 2019 11:37+1100 for FHIR v4.0.0 045public class MedicationStatement43_50 { 046 047 public static org.hl7.fhir.r5.model.MedicationStatement convertMedicationStatement(org.hl7.fhir.r4b.model.MedicationStatement src) throws FHIRException { 048 if (src == null) 049 return null; 050 org.hl7.fhir.r5.model.MedicationStatement tgt = new org.hl7.fhir.r5.model.MedicationStatement(); 051 ConversionContext43_50.INSTANCE.getVersionConvertor_43_50().copyDomainResource(src, tgt); 052 for (org.hl7.fhir.r4b.model.Identifier t : src.getIdentifier()) 053 tgt.addIdentifier(Identifier43_50.convertIdentifier(t)); 054// for (org.hl7.fhir.r4b.model.Reference t : src.getBasedOn()) tgt.addBasedOn(Reference43_50.convertReference(t)); 055// for (org.hl7.fhir.r4b.model.Reference t : src.getPartOf()) tgt.addPartOf(Reference43_50.convertReference(t)); 056 if (src.hasPrimitiveExtension(VersionConvertorConstants.EXT_MED_STAT_STATUS_5)) { 057 tgt.setStatus(org.hl7.fhir.r5.model.MedicationStatement.MedicationStatementStatusCodes.fromCode(src.getExtensionString(VersionConvertorConstants.EXT_MED_STAT_STATUS_5))); 058 } else if (src.hasStatus()) { 059 tgt.addExtension(new org.hl7.fhir.r5.model.Extension(VersionConvertorConstants.EXT_MED_STAT_STATUS_4, new org.hl7.fhir.r5.model.CodeType(src.getStatus().toCode()))); 060 tgt.setStatusElement(convertMedicationStatementStatus(src.getStatusElement())); 061 } 062// for (org.hl7.fhir.r4b.model.CodeableConcept t : src.getStatusReason()) 063// tgt.addStatusReason(CodeableConcept43_50.convertCodeableConcept(t)); 064 if (src.hasCategory()) 065 tgt.addCategory(CodeableConcept43_50.convertCodeableConcept(src.getCategory())); 066 if (src.hasMedicationCodeableConcept()) { 067 tgt.getMedication().setConcept(CodeableConcept43_50.convertCodeableConcept(src.getMedicationCodeableConcept())); 068 } 069 if (src.hasMedicationReference()) { 070 tgt.getMedication().setReference(Reference43_50.convertReference(src.getMedicationReference())); 071 } 072 if (src.hasSubject()) 073 tgt.setSubject(Reference43_50.convertReference(src.getSubject())); 074 if (src.hasContext()) 075 tgt.setEncounter(Reference43_50.convertReference(src.getContext())); 076 if (src.hasEffective()) 077 tgt.setEffective(ConversionContext43_50.INSTANCE.getVersionConvertor_43_50().convertType(src.getEffective())); 078 if (src.hasDateAsserted()) 079 tgt.setDateAssertedElement(DateTime43_50.convertDateTime(src.getDateAssertedElement())); 080 if (src.hasInformationSource()) 081 tgt.addInformationSource(Reference43_50.convertReference(src.getInformationSource())); 082 for (org.hl7.fhir.r4b.model.Reference t : src.getDerivedFrom()) 083 tgt.addDerivedFrom(Reference43_50.convertReference(t)); 084 for (org.hl7.fhir.r4b.model.CodeableConcept t : src.getReasonCode()) 085 tgt.addReason(CodeableConcept43_50.convertCodeableConceptToCodeableReference(t)); 086 for (org.hl7.fhir.r4b.model.Reference t : src.getReasonReference()) 087 tgt.addReason(Reference43_50.convertReferenceToCodeableReference(t)); 088 for (org.hl7.fhir.r4b.model.Annotation t : src.getNote()) tgt.addNote(Annotation43_50.convertAnnotation(t)); 089 for (org.hl7.fhir.r4b.model.Dosage t : src.getDosage()) tgt.addDosage(Dosage43_50.convertDosage(t)); 090 return tgt; 091 } 092 093 public static org.hl7.fhir.r4b.model.MedicationStatement convertMedicationStatement(org.hl7.fhir.r5.model.MedicationStatement src) throws FHIRException { 094 if (src == null) 095 return null; 096 org.hl7.fhir.r4b.model.MedicationStatement tgt = new org.hl7.fhir.r4b.model.MedicationStatement(); 097 ConversionContext43_50.INSTANCE.getVersionConvertor_43_50().copyDomainResource(src, tgt); 098 for (org.hl7.fhir.r5.model.Identifier t : src.getIdentifier()) 099 tgt.addIdentifier(Identifier43_50.convertIdentifier(t)); 100// for (org.hl7.fhir.r5.model.Reference t : src.getBasedOn()) tgt.addBasedOn(Reference43_50.convertReference(t)); 101// for (org.hl7.fhir.r5.model.Reference t : src.getPartOf()) tgt.addPartOf(Reference43_50.convertReference(t)); 102 if (src.hasPrimitiveExtension(VersionConvertorConstants.EXT_MED_STAT_STATUS_4)) { 103 tgt.setStatus(org.hl7.fhir.r4b.model.MedicationStatement.MedicationStatusCodes.fromCode(src.getExtensionString(VersionConvertorConstants.EXT_MED_STAT_STATUS_4))); 104 } else if (src.hasStatus()) { 105 tgt.addExtension(new org.hl7.fhir.r4b.model.Extension(VersionConvertorConstants.EXT_MED_STAT_STATUS_5, new org.hl7.fhir.r4b.model.CodeType(src.getStatus().toCode()))); 106 tgt.setStatusElement(convertMedicationStatementStatus(src.getStatusElement())); 107 } 108// for (org.hl7.fhir.r5.model.CodeableConcept t : src.getStatusReason()) 109// tgt.addStatusReason(CodeableConcept43_50.convertCodeableConcept(t)); 110 if (src.hasCategory()) 111 tgt.setCategory(CodeableConcept43_50.convertCodeableConcept(src.getCategoryFirstRep())); 112 if (src.getMedication().hasConcept()) { 113 tgt.setMedication(ConversionContext43_50.INSTANCE.getVersionConvertor_43_50().convertType(src.getMedication().getConcept())); 114 } 115 if (src.getMedication().hasReference()) { 116 tgt.setMedication(ConversionContext43_50.INSTANCE.getVersionConvertor_43_50().convertType(src.getMedication().getReference())); 117 } 118 if (src.hasSubject()) 119 tgt.setSubject(Reference43_50.convertReference(src.getSubject())); 120 if (src.hasEncounter()) 121 tgt.setContext(Reference43_50.convertReference(src.getEncounter())); 122 if (src.hasEffective()) 123 tgt.setEffective(ConversionContext43_50.INSTANCE.getVersionConvertor_43_50().convertType(src.getEffective())); 124 if (src.hasDateAsserted()) 125 tgt.setDateAssertedElement(DateTime43_50.convertDateTime(src.getDateAssertedElement())); 126 if (src.hasInformationSource()) 127 tgt.setInformationSource(Reference43_50.convertReference(src.getInformationSourceFirstRep())); 128 for (org.hl7.fhir.r5.model.Reference t : src.getDerivedFrom()) 129 tgt.addDerivedFrom(Reference43_50.convertReference(t)); 130 for (CodeableReference t : src.getReason()) 131 if (t.hasConcept()) 132 tgt.addReasonCode(CodeableConcept43_50.convertCodeableConcept(t.getConcept())); 133 for (CodeableReference t : src.getReason()) 134 if (t.hasReference()) 135 tgt.addReasonReference(Reference43_50.convertReference(t.getReference())); 136 for (org.hl7.fhir.r5.model.Annotation t : src.getNote()) tgt.addNote(Annotation43_50.convertAnnotation(t)); 137 for (org.hl7.fhir.r5.model.Dosage t : src.getDosage()) tgt.addDosage(Dosage43_50.convertDosage(t)); 138 return tgt; 139 } 140 141 static public org.hl7.fhir.r5.model.Enumeration<org.hl7.fhir.r5.model.MedicationStatement.MedicationStatementStatusCodes> convertMedicationStatementStatus(org.hl7.fhir.r4b.model.Enumeration<org.hl7.fhir.r4b.model.MedicationStatement.MedicationStatusCodes> src) throws FHIRException { 142 if (src == null || src.isEmpty()) 143 return null; 144 Enumeration<MedicationStatement.MedicationStatementStatusCodes> tgt = new Enumeration<>(new MedicationStatement.MedicationStatementStatusCodesEnumFactory()); 145 ConversionContext43_50.INSTANCE.getVersionConvertor_43_50().copyElement(src, tgt); 146 if (src.getValue() == null) { 147 tgt.setValue(null); 148 } else { 149 switch (src.getValue()) { 150 case ACTIVE: 151 tgt.setValue(MedicationStatement.MedicationStatementStatusCodes.RECORDED); 152 break; 153 case COMPLETED: 154 tgt.setValue(MedicationStatement.MedicationStatementStatusCodes.RECORDED); 155 break; 156 case ENTEREDINERROR: 157 tgt.setValue(MedicationStatement.MedicationStatementStatusCodes.ENTEREDINERROR); 158 break; 159 case INTENDED: 160 tgt.setValue(MedicationStatement.MedicationStatementStatusCodes.RECORDED); 161 break; 162 case STOPPED: 163 tgt.setValue(MedicationStatement.MedicationStatementStatusCodes.RECORDED); 164 break; 165 case ONHOLD: 166 tgt.setValue(MedicationStatement.MedicationStatementStatusCodes.RECORDED); 167 break; 168 case UNKNOWN: 169 tgt.setValue(MedicationStatement.MedicationStatementStatusCodes.RECORDED); 170 break; 171 case NOTTAKEN: 172 tgt.setValue(MedicationStatement.MedicationStatementStatusCodes.RECORDED); 173 break; 174 default: 175 tgt.setValue(MedicationStatement.MedicationStatementStatusCodes.NULL); 176 break; 177 } 178 } 179 return tgt; 180 } 181 182 static public org.hl7.fhir.r4b.model.Enumeration<org.hl7.fhir.r4b.model.MedicationStatement.MedicationStatusCodes> convertMedicationStatementStatus(org.hl7.fhir.r5.model.Enumeration<org.hl7.fhir.r5.model.MedicationStatement.MedicationStatementStatusCodes> src) throws FHIRException { 183 if (src == null || src.isEmpty()) 184 return null; 185 org.hl7.fhir.r4b.model.Enumeration<org.hl7.fhir.r4b.model.MedicationStatement.MedicationStatusCodes> tgt = new org.hl7.fhir.r4b.model.Enumeration<>(new org.hl7.fhir.r4b.model.MedicationStatement.MedicationStatusCodesEnumFactory()); 186 ConversionContext43_50.INSTANCE.getVersionConvertor_43_50().copyElement(src, tgt); 187 if (src.getValue() == null) { 188 tgt.setValue(null); 189 } else { 190 switch (src.getValue()) { 191 // case ACTIVE: 192// tgt.setValue(org.hl7.fhir.r4b.model.MedicationStatement.MedicationStatusCodes.ACTIVE); 193// break; 194 case RECORDED: 195 tgt.setValue(org.hl7.fhir.r4b.model.MedicationStatement.MedicationStatusCodes.COMPLETED); 196 break; 197 case ENTEREDINERROR: 198 tgt.setValue(org.hl7.fhir.r4b.model.MedicationStatement.MedicationStatusCodes.ENTEREDINERROR); 199 break; 200// case UNKNOWN: 201// tgt.setValue(org.hl7.fhir.r4b.model.MedicationStatement.MedicationStatusCodes.INTENDED); 202// break; 203// case STOPPED: 204// tgt.setValue(org.hl7.fhir.r4b.model.MedicationStatement.MedicationStatusCodes.STOPPED); 205// break; 206// case ONHOLD: 207// tgt.setValue(org.hl7.fhir.r4b.model.MedicationStatement.MedicationStatusCodes.ONHOLD); 208// break; 209 case DRAFT: 210 tgt.setValue(org.hl7.fhir.r4b.model.MedicationStatement.MedicationStatusCodes.UNKNOWN); 211 break; 212// case NOTTAKEN: 213// tgt.setValue(org.hl7.fhir.r4b.model.MedicationStatement.MedicationStatusCodes.NOTTAKEN); 214// break; 215 default: 216 tgt.setValue(org.hl7.fhir.r4b.model.MedicationStatement.MedicationStatusCodes.NULL); 217 break; 218 } 219 } 220 return tgt; 221 } 222}