001package org.hl7.fhir.convertors.conv40_50.resources40_50; 002 003import org.hl7.fhir.convertors.context.ConversionContext40_50; 004import org.hl7.fhir.convertors.conv40_50.datatypes40_50.general40_50.Attachment40_50; 005import org.hl7.fhir.convertors.conv40_50.datatypes40_50.general40_50.CodeableConcept40_50; 006import org.hl7.fhir.convertors.conv40_50.datatypes40_50.general40_50.Identifier40_50; 007import org.hl7.fhir.convertors.conv40_50.datatypes40_50.general40_50.Period40_50; 008import org.hl7.fhir.convertors.conv40_50.datatypes40_50.primitive40_50.Instant40_50; 009import org.hl7.fhir.convertors.conv40_50.datatypes40_50.primitive40_50.MarkDown40_50; 010import org.hl7.fhir.convertors.conv40_50.datatypes40_50.primitive40_50.String40_50; 011import org.hl7.fhir.convertors.conv40_50.datatypes40_50.special40_50.Reference40_50; 012import org.hl7.fhir.exceptions.FHIRException; 013import org.hl7.fhir.r5.model.CodeableReference; 014import org.hl7.fhir.r5.model.DocumentReference.DocumentReferenceAttesterComponent; 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 DocumentReference40_50 { 046 047 public static org.hl7.fhir.r5.model.DocumentReference convertDocumentReference(org.hl7.fhir.r4.model.DocumentReference src) throws FHIRException { 048 if (src == null) 049 return null; 050 org.hl7.fhir.r5.model.DocumentReference tgt = new org.hl7.fhir.r5.model.DocumentReference(); 051 ConversionContext40_50.INSTANCE.getVersionConvertor_40_50().copyDomainResource(src, tgt); 052 if (src.hasMasterIdentifier()) 053 tgt.addIdentifier(Identifier40_50.convertIdentifier(src.getMasterIdentifier())); 054 for (org.hl7.fhir.r4.model.Identifier t : src.getIdentifier()) 055 tgt.addIdentifier(Identifier40_50.convertIdentifier(t)); 056 if (src.hasStatus()) 057 tgt.setStatusElement(Enumerations40_50.convertDocumentReferenceStatus(src.getStatusElement())); 058 if (src.hasDocStatus()) 059 tgt.setDocStatusElement(convertReferredDocumentStatus(src.getDocStatusElement())); 060 if (src.hasType()) 061 tgt.setType(CodeableConcept40_50.convertCodeableConcept(src.getType())); 062 for (org.hl7.fhir.r4.model.CodeableConcept t : src.getCategory()) 063 tgt.addCategory(CodeableConcept40_50.convertCodeableConcept(t)); 064 if (src.hasSubject()) 065 tgt.setSubject(Reference40_50.convertReference(src.getSubject())); 066 if (src.hasDate()) 067 tgt.setDateElement(Instant40_50.convertInstant(src.getDateElement())); 068 for (org.hl7.fhir.r4.model.Reference t : src.getAuthor()) tgt.addAuthor(Reference40_50.convertReference(t)); 069 if (src.hasAuthenticator()) 070 tgt.addAttester().setMode(new org.hl7.fhir.r5.model.CodeableConcept().addCoding(new org.hl7.fhir.r5.model.Coding("http://hl7.org/fhir/composition-attestation-mode","official", "Official"))) 071 .setParty(Reference40_50.convertReference(src.getAuthenticator())); 072 if (src.hasCustodian()) 073 tgt.setCustodian(Reference40_50.convertReference(src.getCustodian())); 074 for (org.hl7.fhir.r4.model.DocumentReference.DocumentReferenceRelatesToComponent t : src.getRelatesTo()) 075 tgt.addRelatesTo(convertDocumentReferenceRelatesToComponent(t)); 076 if (src.hasDescription()) 077 tgt.setDescriptionElement(MarkDown40_50.convertStringToMarkdown(src.getDescriptionElement())); 078 for (org.hl7.fhir.r4.model.CodeableConcept t : src.getSecurityLabel()) 079 tgt.addSecurityLabel(CodeableConcept40_50.convertCodeableConcept(t)); 080 for (org.hl7.fhir.r4.model.DocumentReference.DocumentReferenceContentComponent t : src.getContent()) 081 tgt.addContent(convertDocumentReferenceContentComponent(t)); 082 if (src.hasContext()) 083 convertDocumentReferenceContextComponent(src.getContext(), tgt); 084 return tgt; 085 } 086 087 public static org.hl7.fhir.r4.model.DocumentReference convertDocumentReference(org.hl7.fhir.r5.model.DocumentReference src) throws FHIRException { 088 if (src == null) 089 return null; 090 org.hl7.fhir.r4.model.DocumentReference tgt = new org.hl7.fhir.r4.model.DocumentReference(); 091 ConversionContext40_50.INSTANCE.getVersionConvertor_40_50().copyDomainResource(src, tgt); 092// if (src.hasMasterIdentifier()) 093// tgt.setMasterIdentifier(convertIdentifier(src.getMasterIdentifier())); 094 for (org.hl7.fhir.r5.model.Identifier t : src.getIdentifier()) 095 tgt.addIdentifier(Identifier40_50.convertIdentifier(t)); 096 if (src.hasStatus()) 097 tgt.setStatusElement(Enumerations40_50.convertDocumentReferenceStatus(src.getStatusElement())); 098 if (src.hasDocStatus()) 099 tgt.setDocStatusElement(convertReferredDocumentStatus(src.getDocStatusElement())); 100 if (src.hasType()) 101 tgt.setType(CodeableConcept40_50.convertCodeableConcept(src.getType())); 102 for (org.hl7.fhir.r5.model.CodeableConcept t : src.getCategory()) 103 tgt.addCategory(CodeableConcept40_50.convertCodeableConcept(t)); 104 if (src.hasSubject()) 105 tgt.setSubject(Reference40_50.convertReference(src.getSubject())); 106 if (src.hasDate()) 107 tgt.setDateElement(Instant40_50.convertInstant(src.getDateElement())); 108 for (org.hl7.fhir.r5.model.Reference t : src.getAuthor()) tgt.addAuthor(Reference40_50.convertReference(t)); 109 for (DocumentReferenceAttesterComponent t : src.getAttester()) { 110 if (t.getMode().hasCoding("http://hl7.org/fhir/composition-attestation-mode", "official")) 111 tgt.setAuthenticator(Reference40_50.convertReference(t.getParty())); 112 } 113 if (src.hasCustodian()) 114 tgt.setCustodian(Reference40_50.convertReference(src.getCustodian())); 115 for (org.hl7.fhir.r5.model.DocumentReference.DocumentReferenceRelatesToComponent t : src.getRelatesTo()) 116 tgt.addRelatesTo(convertDocumentReferenceRelatesToComponent(t)); 117 if (src.hasDescription()) 118 tgt.setDescriptionElement(String40_50.convertString(src.getDescriptionElement())); 119 for (org.hl7.fhir.r5.model.CodeableConcept t : src.getSecurityLabel()) 120 tgt.addSecurityLabel(CodeableConcept40_50.convertCodeableConcept(t)); 121 for (org.hl7.fhir.r5.model.DocumentReference.DocumentReferenceContentComponent t : src.getContent()) 122 tgt.addContent(convertDocumentReferenceContentComponent(t)); 123 convertDocumentReferenceContextComponent(src, tgt.getContext()); 124 return tgt; 125 } 126 127 static public org.hl7.fhir.r5.model.Enumeration<org.hl7.fhir.r5.model.Enumerations.CompositionStatus> convertReferredDocumentStatus(org.hl7.fhir.r4.model.Enumeration<org.hl7.fhir.r4.model.DocumentReference.ReferredDocumentStatus> src) throws FHIRException { 128 if (src == null || src.isEmpty()) 129 return null; 130 org.hl7.fhir.r5.model.Enumeration<org.hl7.fhir.r5.model.Enumerations.CompositionStatus> tgt = new org.hl7.fhir.r5.model.Enumeration<>(new org.hl7.fhir.r5.model.Enumerations.CompositionStatusEnumFactory()); 131 ConversionContext40_50.INSTANCE.getVersionConvertor_40_50().copyElement(src, tgt); 132 switch (src.getValue()) { 133 case PRELIMINARY: 134 tgt.setValue(org.hl7.fhir.r5.model.Enumerations.CompositionStatus.PRELIMINARY); 135 break; 136 case FINAL: 137 tgt.setValue(org.hl7.fhir.r5.model.Enumerations.CompositionStatus.FINAL); 138 break; 139 case AMENDED: 140 tgt.setValue(org.hl7.fhir.r5.model.Enumerations.CompositionStatus.AMENDED); 141 break; 142 case ENTEREDINERROR: 143 tgt.setValue(org.hl7.fhir.r5.model.Enumerations.CompositionStatus.ENTEREDINERROR); 144 break; 145 default: 146 tgt.setValue(org.hl7.fhir.r5.model.Enumerations.CompositionStatus.NULL); 147 break; 148 } 149 return tgt; 150 } 151 152 static public org.hl7.fhir.r4.model.Enumeration<org.hl7.fhir.r4.model.DocumentReference.ReferredDocumentStatus> convertReferredDocumentStatus(org.hl7.fhir.r5.model.Enumeration<org.hl7.fhir.r5.model.Enumerations.CompositionStatus> src) throws FHIRException { 153 if (src == null || src.isEmpty()) 154 return null; 155 org.hl7.fhir.r4.model.Enumeration<org.hl7.fhir.r4.model.DocumentReference.ReferredDocumentStatus> tgt = new org.hl7.fhir.r4.model.Enumeration<>(new org.hl7.fhir.r4.model.DocumentReference.ReferredDocumentStatusEnumFactory()); 156 ConversionContext40_50.INSTANCE.getVersionConvertor_40_50().copyElement(src, tgt); 157 switch (src.getValue()) { 158 case PRELIMINARY: 159 tgt.setValue(org.hl7.fhir.r4.model.DocumentReference.ReferredDocumentStatus.PRELIMINARY); 160 break; 161 case FINAL: 162 tgt.setValue(org.hl7.fhir.r4.model.DocumentReference.ReferredDocumentStatus.FINAL); 163 break; 164 case AMENDED: 165 tgt.setValue(org.hl7.fhir.r4.model.DocumentReference.ReferredDocumentStatus.AMENDED); 166 break; 167 case ENTEREDINERROR: 168 tgt.setValue(org.hl7.fhir.r4.model.DocumentReference.ReferredDocumentStatus.ENTEREDINERROR); 169 break; 170 default: 171 tgt.setValue(org.hl7.fhir.r4.model.DocumentReference.ReferredDocumentStatus.NULL); 172 break; 173 } 174 return tgt; 175 } 176 177 public static org.hl7.fhir.r5.model.DocumentReference.DocumentReferenceRelatesToComponent convertDocumentReferenceRelatesToComponent(org.hl7.fhir.r4.model.DocumentReference.DocumentReferenceRelatesToComponent src) throws FHIRException { 178 if (src == null) 179 return null; 180 org.hl7.fhir.r5.model.DocumentReference.DocumentReferenceRelatesToComponent tgt = new org.hl7.fhir.r5.model.DocumentReference.DocumentReferenceRelatesToComponent(); 181 ConversionContext40_50.INSTANCE.getVersionConvertor_40_50().copyBackboneElement(src, tgt); 182 if (src.hasCode()) 183 tgt.setCode(convertDocumentRelationshipType(src.getCodeElement())); 184 if (src.hasTarget()) 185 tgt.setTarget(Reference40_50.convertReference(src.getTarget())); 186 return tgt; 187 } 188 189 public static org.hl7.fhir.r4.model.DocumentReference.DocumentReferenceRelatesToComponent convertDocumentReferenceRelatesToComponent(org.hl7.fhir.r5.model.DocumentReference.DocumentReferenceRelatesToComponent src) throws FHIRException { 190 if (src == null) 191 return null; 192 org.hl7.fhir.r4.model.DocumentReference.DocumentReferenceRelatesToComponent tgt = new org.hl7.fhir.r4.model.DocumentReference.DocumentReferenceRelatesToComponent(); 193 ConversionContext40_50.INSTANCE.getVersionConvertor_40_50().copyBackboneElement(src, tgt); 194 if (src.hasCode()) 195 tgt.setCodeElement(convertDocumentRelationshipType(src.getCode())); 196 if (src.hasTarget()) 197 tgt.setTarget(Reference40_50.convertReference(src.getTarget())); 198 return tgt; 199 } 200 201 static public org.hl7.fhir.r5.model.CodeableConcept convertDocumentRelationshipType(org.hl7.fhir.r4.model.Enumeration<org.hl7.fhir.r4.model.DocumentReference.DocumentRelationshipType> src) throws FHIRException { 202 if (src == null || src.isEmpty()) 203 return null; 204 org.hl7.fhir.r5.model.CodeableConcept tgt = new org.hl7.fhir.r5.model.CodeableConcept(); 205 ConversionContext40_50.INSTANCE.getVersionConvertor_40_50().copyElement(src, tgt); 206 switch (src.getValue()) { 207 case REPLACES: 208 tgt.addCoding().setSystem("http://hl7.org/fhir/document-relationship-type").setCode("replaces"); 209 break; 210 case TRANSFORMS: 211 tgt.addCoding().setSystem("http://hl7.org/fhir/document-relationship-type").setCode("transforms"); 212 break; 213 case SIGNS: 214 tgt.addCoding().setSystem("http://hl7.org/fhir/document-relationship-type").setCode("signs"); 215 break; 216 case APPENDS: 217 tgt.addCoding().setSystem("http://hl7.org/fhir/document-relationship-type").setCode("appends"); 218 break; 219 default: 220 break; 221 } 222 return tgt; 223 } 224 225 static public org.hl7.fhir.r4.model.Enumeration<org.hl7.fhir.r4.model.DocumentReference.DocumentRelationshipType> convertDocumentRelationshipType(org.hl7.fhir.r5.model.CodeableConcept src) throws FHIRException { 226 if (src == null || src.isEmpty()) 227 return null; 228 org.hl7.fhir.r4.model.Enumeration<org.hl7.fhir.r4.model.DocumentReference.DocumentRelationshipType> tgt = new org.hl7.fhir.r4.model.Enumeration<>(new org.hl7.fhir.r4.model.DocumentReference.DocumentRelationshipTypeEnumFactory()); 229 ConversionContext40_50.INSTANCE.getVersionConvertor_40_50().copyElement(src, tgt); 230 switch (src.getCode("http://hl7.org/fhir/document-relationship-type")) { 231 case "replaces": 232 tgt.setValue(org.hl7.fhir.r4.model.DocumentReference.DocumentRelationshipType.REPLACES); 233 break; 234 case "transforms": 235 tgt.setValue(org.hl7.fhir.r4.model.DocumentReference.DocumentRelationshipType.TRANSFORMS); 236 break; 237 case "signs": 238 tgt.setValue(org.hl7.fhir.r4.model.DocumentReference.DocumentRelationshipType.SIGNS); 239 break; 240 case "appends": 241 tgt.setValue(org.hl7.fhir.r4.model.DocumentReference.DocumentRelationshipType.APPENDS); 242 break; 243 default: 244 tgt.setValue(org.hl7.fhir.r4.model.DocumentReference.DocumentRelationshipType.NULL); 245 break; 246 } 247 return tgt; 248 } 249 250 public static org.hl7.fhir.r5.model.DocumentReference.DocumentReferenceContentComponent convertDocumentReferenceContentComponent(org.hl7.fhir.r4.model.DocumentReference.DocumentReferenceContentComponent src) throws FHIRException { 251 if (src == null) 252 return null; 253 org.hl7.fhir.r5.model.DocumentReference.DocumentReferenceContentComponent tgt = new org.hl7.fhir.r5.model.DocumentReference.DocumentReferenceContentComponent(); 254 ConversionContext40_50.INSTANCE.getVersionConvertor_40_50().copyBackboneElement(src, tgt); 255 if (src.hasAttachment()) 256 tgt.setAttachment(Attachment40_50.convertAttachment(src.getAttachment())); 257 return tgt; 258 } 259 260 public static org.hl7.fhir.r4.model.DocumentReference.DocumentReferenceContentComponent convertDocumentReferenceContentComponent(org.hl7.fhir.r5.model.DocumentReference.DocumentReferenceContentComponent src) throws FHIRException { 261 if (src == null) 262 return null; 263 org.hl7.fhir.r4.model.DocumentReference.DocumentReferenceContentComponent tgt = new org.hl7.fhir.r4.model.DocumentReference.DocumentReferenceContentComponent(); 264 ConversionContext40_50.INSTANCE.getVersionConvertor_40_50().copyBackboneElement(src, tgt); 265 if (src.hasAttachment()) 266 tgt.setAttachment(Attachment40_50.convertAttachment(src.getAttachment())); 267 return tgt; 268 } 269 270 public static void convertDocumentReferenceContextComponent(org.hl7.fhir.r4.model.DocumentReference.DocumentReferenceContextComponent src, org.hl7.fhir.r5.model.DocumentReference tgt) throws FHIRException { 271 for (org.hl7.fhir.r4.model.Reference t : src.getEncounter()) tgt.addContext(Reference40_50.convertReference(t)); 272 for (org.hl7.fhir.r4.model.CodeableConcept t : src.getEvent()) 273 tgt.addEvent(new CodeableReference().setConcept(CodeableConcept40_50.convertCodeableConcept(t))); 274 if (src.hasPeriod()) 275 tgt.setPeriod(Period40_50.convertPeriod(src.getPeriod())); 276 if (src.hasFacilityType()) 277 tgt.setFacilityType(CodeableConcept40_50.convertCodeableConcept(src.getFacilityType())); 278 if (src.hasPracticeSetting()) 279 tgt.setPracticeSetting(CodeableConcept40_50.convertCodeableConcept(src.getPracticeSetting())); 280// if (src.hasSourcePatientInfo()) 281// tgt.setSourcePatientInfo(Reference40_50.convertReference(src.getSourcePatientInfo())); 282// for (org.hl7.fhir.r4.model.Reference t : src.getRelated()) tgt.addRelated(Reference40_50.convertReference(t)); 283 } 284 285 public static void convertDocumentReferenceContextComponent(org.hl7.fhir.r5.model.DocumentReference src, org.hl7.fhir.r4.model.DocumentReference.DocumentReferenceContextComponent tgt) throws FHIRException { 286 for (org.hl7.fhir.r5.model.Reference t : src.getContext()) tgt.addEncounter(Reference40_50.convertReference(t)); 287 for (CodeableReference t : src.getEvent()) 288 if (t.hasConcept()) 289 tgt.addEvent(CodeableConcept40_50.convertCodeableConcept(t.getConcept())); 290 if (src.hasPeriod()) 291 tgt.setPeriod(Period40_50.convertPeriod(src.getPeriod())); 292 if (src.hasFacilityType()) 293 tgt.setFacilityType(CodeableConcept40_50.convertCodeableConcept(src.getFacilityType())); 294 if (src.hasPracticeSetting()) 295 tgt.setPracticeSetting(CodeableConcept40_50.convertCodeableConcept(src.getPracticeSetting())); 296// if (src.hasSourcePatientInfo()) 297// tgt.setSourcePatientInfo(Reference40_50.convertReference(src.getSourcePatientInfo())); 298// for (org.hl7.fhir.r5.model.Reference t : src.getRelated()) tgt.addRelated(Reference40_50.convertReference(t)); 299 } 300}