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.*; 005import org.hl7.fhir.convertors.conv40_50.datatypes40_50.primitive40_50.Instant40_50; 006import org.hl7.fhir.convertors.conv40_50.datatypes40_50.primitive40_50.MarkDown40_50; 007import org.hl7.fhir.convertors.conv40_50.datatypes40_50.primitive40_50.String40_50; 008import org.hl7.fhir.convertors.conv40_50.datatypes40_50.special40_50.Reference40_50; 009import org.hl7.fhir.exceptions.FHIRException; 010import org.hl7.fhir.r5.model.DocumentReference.DocumentAttestationMode; 011import org.hl7.fhir.r5.model.DocumentReference.DocumentReferenceAttesterComponent; 012 013/* 014 Copyright (c) 2011+, HL7, Inc. 015 All rights reserved. 016 017 Redistribution and use in source and binary forms, with or without modification, 018 are permitted provided that the following conditions are met: 019 020 * Redistributions of source code must retain the above copyright notice, this 021 list of conditions and the following disclaimer. 022 * Redistributions in binary form must reproduce the above copyright notice, 023 this list of conditions and the following disclaimer in the documentation 024 and/or other materials provided with the distribution. 025 * Neither the name of HL7 nor the names of its contributors may be used to 026 endorse or promote products derived from this software without specific 027 prior written permission. 028 029 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 030 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 031 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 032 IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 033 INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 034 NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 035 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 036 WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 037 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 038 POSSIBILITY OF SUCH DAMAGE. 039 040*/ 041// Generated on Sun, Feb 24, 2019 11:37+1100 for FHIR v4.0.0 042public class DocumentReference40_50 { 043 044 public static org.hl7.fhir.r5.model.DocumentReference convertDocumentReference(org.hl7.fhir.r4.model.DocumentReference src) throws FHIRException { 045 if (src == null) 046 return null; 047 org.hl7.fhir.r5.model.DocumentReference tgt = new org.hl7.fhir.r5.model.DocumentReference(); 048 ConversionContext40_50.INSTANCE.getVersionConvertor_40_50().copyDomainResource(src, tgt); 049 if (src.hasMasterIdentifier()) 050 tgt.addIdentifier(Identifier40_50.convertIdentifier(src.getMasterIdentifier())); 051 for (org.hl7.fhir.r4.model.Identifier t : src.getIdentifier()) 052 tgt.addIdentifier(Identifier40_50.convertIdentifier(t)); 053 if (src.hasStatus()) 054 tgt.setStatusElement(Enumerations40_50.convertDocumentReferenceStatus(src.getStatusElement())); 055 if (src.hasDocStatus()) 056 tgt.setDocStatusElement(convertReferredDocumentStatus(src.getDocStatusElement())); 057 if (src.hasType()) 058 tgt.setType(CodeableConcept40_50.convertCodeableConcept(src.getType())); 059 for (org.hl7.fhir.r4.model.CodeableConcept t : src.getCategory()) 060 tgt.addCategory(CodeableConcept40_50.convertCodeableConcept(t)); 061 if (src.hasSubject()) 062 tgt.setSubject(Reference40_50.convertReference(src.getSubject())); 063 if (src.hasDate()) 064 tgt.setDateElement(Instant40_50.convertInstant(src.getDateElement())); 065 for (org.hl7.fhir.r4.model.Reference t : src.getAuthor()) tgt.addAuthor(Reference40_50.convertReference(t)); 066 if (src.hasAuthenticator()) 067 tgt.addAttester().setMode(DocumentAttestationMode.OFFICIAL).setParty(Reference40_50.convertReference(src.getAuthenticator())); 068 if (src.hasCustodian()) 069 tgt.setCustodian(Reference40_50.convertReference(src.getCustodian())); 070 for (org.hl7.fhir.r4.model.DocumentReference.DocumentReferenceRelatesToComponent t : src.getRelatesTo()) 071 tgt.addRelatesTo(convertDocumentReferenceRelatesToComponent(t)); 072 if (src.hasDescription()) 073 tgt.setDescriptionElement(MarkDown40_50.convertStringToMarkdown(src.getDescriptionElement())); 074 for (org.hl7.fhir.r4.model.CodeableConcept t : src.getSecurityLabel()) 075 tgt.addSecurityLabel(CodeableConcept40_50.convertCodeableConcept(t)); 076 for (org.hl7.fhir.r4.model.DocumentReference.DocumentReferenceContentComponent t : src.getContent()) 077 tgt.addContent(convertDocumentReferenceContentComponent(t)); 078 if (src.hasContext()) 079 convertDocumentReferenceContextComponent(src.getContext(), tgt); 080 return tgt; 081 } 082 083 public static org.hl7.fhir.r4.model.DocumentReference convertDocumentReference(org.hl7.fhir.r5.model.DocumentReference src) throws FHIRException { 084 if (src == null) 085 return null; 086 org.hl7.fhir.r4.model.DocumentReference tgt = new org.hl7.fhir.r4.model.DocumentReference(); 087 ConversionContext40_50.INSTANCE.getVersionConvertor_40_50().copyDomainResource(src, tgt); 088// if (src.hasMasterIdentifier()) 089// tgt.setMasterIdentifier(convertIdentifier(src.getMasterIdentifier())); 090 for (org.hl7.fhir.r5.model.Identifier t : src.getIdentifier()) 091 tgt.addIdentifier(Identifier40_50.convertIdentifier(t)); 092 if (src.hasStatus()) 093 tgt.setStatusElement(Enumerations40_50.convertDocumentReferenceStatus(src.getStatusElement())); 094 if (src.hasDocStatus()) 095 tgt.setDocStatusElement(convertReferredDocumentStatus(src.getDocStatusElement())); 096 if (src.hasType()) 097 tgt.setType(CodeableConcept40_50.convertCodeableConcept(src.getType())); 098 for (org.hl7.fhir.r5.model.CodeableConcept t : src.getCategory()) 099 tgt.addCategory(CodeableConcept40_50.convertCodeableConcept(t)); 100 if (src.hasSubject()) 101 tgt.setSubject(Reference40_50.convertReference(src.getSubject())); 102 if (src.hasDate()) 103 tgt.setDateElement(Instant40_50.convertInstant(src.getDateElement())); 104 for (org.hl7.fhir.r5.model.Reference t : src.getAuthor()) tgt.addAuthor(Reference40_50.convertReference(t)); 105 for (DocumentReferenceAttesterComponent t : src.getAttester()) { 106 if (t.getMode() == DocumentAttestationMode.OFFICIAL) 107 tgt.setAuthenticator(Reference40_50.convertReference(t.getParty())); 108 } 109 if (src.hasCustodian()) 110 tgt.setCustodian(Reference40_50.convertReference(src.getCustodian())); 111 for (org.hl7.fhir.r5.model.DocumentReference.DocumentReferenceRelatesToComponent t : src.getRelatesTo()) 112 tgt.addRelatesTo(convertDocumentReferenceRelatesToComponent(t)); 113 if (src.hasDescription()) 114 tgt.setDescriptionElement(String40_50.convertString(src.getDescriptionElement())); 115 for (org.hl7.fhir.r5.model.CodeableConcept t : src.getSecurityLabel()) 116 tgt.addSecurityLabel(CodeableConcept40_50.convertCodeableConcept(t)); 117 for (org.hl7.fhir.r5.model.DocumentReference.DocumentReferenceContentComponent t : src.getContent()) 118 tgt.addContent(convertDocumentReferenceContentComponent(t)); 119 convertDocumentReferenceContextComponent(src, tgt.getContext()); 120 return tgt; 121 } 122 123 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 { 124 if (src == null || src.isEmpty()) 125 return null; 126 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()); 127 ConversionContext40_50.INSTANCE.getVersionConvertor_40_50().copyElement(src, tgt); 128 switch (src.getValue()) { 129 case PRELIMINARY: 130 tgt.setValue(org.hl7.fhir.r5.model.Enumerations.CompositionStatus.PRELIMINARY); 131 break; 132 case FINAL: 133 tgt.setValue(org.hl7.fhir.r5.model.Enumerations.CompositionStatus.FINAL); 134 break; 135 case AMENDED: 136 tgt.setValue(org.hl7.fhir.r5.model.Enumerations.CompositionStatus.AMENDED); 137 break; 138 case ENTEREDINERROR: 139 tgt.setValue(org.hl7.fhir.r5.model.Enumerations.CompositionStatus.ENTEREDINERROR); 140 break; 141 default: 142 tgt.setValue(org.hl7.fhir.r5.model.Enumerations.CompositionStatus.NULL); 143 break; 144 } 145 return tgt; 146 } 147 148 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 { 149 if (src == null || src.isEmpty()) 150 return null; 151 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()); 152 ConversionContext40_50.INSTANCE.getVersionConvertor_40_50().copyElement(src, tgt); 153 switch (src.getValue()) { 154 case PRELIMINARY: 155 tgt.setValue(org.hl7.fhir.r4.model.DocumentReference.ReferredDocumentStatus.PRELIMINARY); 156 break; 157 case FINAL: 158 tgt.setValue(org.hl7.fhir.r4.model.DocumentReference.ReferredDocumentStatus.FINAL); 159 break; 160 case AMENDED: 161 tgt.setValue(org.hl7.fhir.r4.model.DocumentReference.ReferredDocumentStatus.AMENDED); 162 break; 163 case ENTEREDINERROR: 164 tgt.setValue(org.hl7.fhir.r4.model.DocumentReference.ReferredDocumentStatus.ENTEREDINERROR); 165 break; 166 default: 167 tgt.setValue(org.hl7.fhir.r4.model.DocumentReference.ReferredDocumentStatus.NULL); 168 break; 169 } 170 return tgt; 171 } 172 173 public static org.hl7.fhir.r5.model.DocumentReference.DocumentReferenceRelatesToComponent convertDocumentReferenceRelatesToComponent(org.hl7.fhir.r4.model.DocumentReference.DocumentReferenceRelatesToComponent src) throws FHIRException { 174 if (src == null) 175 return null; 176 org.hl7.fhir.r5.model.DocumentReference.DocumentReferenceRelatesToComponent tgt = new org.hl7.fhir.r5.model.DocumentReference.DocumentReferenceRelatesToComponent(); 177 ConversionContext40_50.INSTANCE.getVersionConvertor_40_50().copyElement(src, tgt); 178 if (src.hasCode()) 179 tgt.setCode(convertDocumentRelationshipType(src.getCodeElement())); 180 if (src.hasTarget()) 181 tgt.setTarget(Reference40_50.convertReference(src.getTarget())); 182 return tgt; 183 } 184 185 public static org.hl7.fhir.r4.model.DocumentReference.DocumentReferenceRelatesToComponent convertDocumentReferenceRelatesToComponent(org.hl7.fhir.r5.model.DocumentReference.DocumentReferenceRelatesToComponent src) throws FHIRException { 186 if (src == null) 187 return null; 188 org.hl7.fhir.r4.model.DocumentReference.DocumentReferenceRelatesToComponent tgt = new org.hl7.fhir.r4.model.DocumentReference.DocumentReferenceRelatesToComponent(); 189 ConversionContext40_50.INSTANCE.getVersionConvertor_40_50().copyElement(src, tgt); 190 if (src.hasCode()) 191 tgt.setCodeElement(convertDocumentRelationshipType(src.getCode())); 192 if (src.hasTarget()) 193 tgt.setTarget(Reference40_50.convertReference(src.getTarget())); 194 return tgt; 195 } 196 197 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 { 198 if (src == null || src.isEmpty()) 199 return null; 200 org.hl7.fhir.r5.model.CodeableConcept tgt = new org.hl7.fhir.r5.model.CodeableConcept(); 201 ConversionContext40_50.INSTANCE.getVersionConvertor_40_50().copyElement(src, tgt); 202 switch (src.getValue()) { 203 case REPLACES: 204 tgt.addCoding().setSystem("http://hl7.org/fhir/document-relationship-type").setCode("replaces"); 205 break; 206 case TRANSFORMS: 207 tgt.addCoding().setSystem("http://hl7.org/fhir/document-relationship-type").setCode("transforms"); 208 break; 209 case SIGNS: 210 tgt.addCoding().setSystem("http://hl7.org/fhir/document-relationship-type").setCode("signs"); 211 break; 212 case APPENDS: 213 tgt.addCoding().setSystem("http://hl7.org/fhir/document-relationship-type").setCode("appends"); 214 break; 215 default: 216 break; 217 } 218 return tgt; 219 } 220 221 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 { 222 if (src == null || src.isEmpty()) 223 return null; 224 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()); 225 ConversionContext40_50.INSTANCE.getVersionConvertor_40_50().copyElement(src, tgt); 226 switch (src.getCode("http://hl7.org/fhir/document-relationship-type")) { 227 case "replaces": 228 tgt.setValue(org.hl7.fhir.r4.model.DocumentReference.DocumentRelationshipType.REPLACES); 229 break; 230 case "transforms": 231 tgt.setValue(org.hl7.fhir.r4.model.DocumentReference.DocumentRelationshipType.TRANSFORMS); 232 break; 233 case "signs": 234 tgt.setValue(org.hl7.fhir.r4.model.DocumentReference.DocumentRelationshipType.SIGNS); 235 break; 236 case "appends": 237 tgt.setValue(org.hl7.fhir.r4.model.DocumentReference.DocumentRelationshipType.APPENDS); 238 break; 239 default: 240 tgt.setValue(org.hl7.fhir.r4.model.DocumentReference.DocumentRelationshipType.NULL); 241 break; 242 } 243 return tgt; 244 } 245 246 public static org.hl7.fhir.r5.model.DocumentReference.DocumentReferenceContentComponent convertDocumentReferenceContentComponent(org.hl7.fhir.r4.model.DocumentReference.DocumentReferenceContentComponent src) throws FHIRException { 247 if (src == null) 248 return null; 249 org.hl7.fhir.r5.model.DocumentReference.DocumentReferenceContentComponent tgt = new org.hl7.fhir.r5.model.DocumentReference.DocumentReferenceContentComponent(); 250 ConversionContext40_50.INSTANCE.getVersionConvertor_40_50().copyElement(src, tgt); 251 if (src.hasAttachment()) 252 tgt.setAttachment(Attachment40_50.convertAttachment(src.getAttachment())); 253 if (src.hasFormat()) 254 tgt.setFormat(Coding40_50.convertCoding(src.getFormat())); 255 return tgt; 256 } 257 258 public static org.hl7.fhir.r4.model.DocumentReference.DocumentReferenceContentComponent convertDocumentReferenceContentComponent(org.hl7.fhir.r5.model.DocumentReference.DocumentReferenceContentComponent src) throws FHIRException { 259 if (src == null) 260 return null; 261 org.hl7.fhir.r4.model.DocumentReference.DocumentReferenceContentComponent tgt = new org.hl7.fhir.r4.model.DocumentReference.DocumentReferenceContentComponent(); 262 ConversionContext40_50.INSTANCE.getVersionConvertor_40_50().copyElement(src, tgt); 263 if (src.hasAttachment()) 264 tgt.setAttachment(Attachment40_50.convertAttachment(src.getAttachment())); 265 if (src.hasFormat()) 266 tgt.setFormat(Coding40_50.convertCoding(src.getFormat())); 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.addEncounter(Reference40_50.convertReference(t)); 272 for (org.hl7.fhir.r4.model.CodeableConcept t : src.getEvent()) 273 tgt.addEvent(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.getEncounter()) tgt.addEncounter(Reference40_50.convertReference(t)); 287 for (org.hl7.fhir.r5.model.CodeableConcept t : src.getEvent()) 288 tgt.addEvent(CodeableConcept40_50.convertCodeableConcept(t)); 289 if (src.hasPeriod()) 290 tgt.setPeriod(Period40_50.convertPeriod(src.getPeriod())); 291 if (src.hasFacilityType()) 292 tgt.setFacilityType(CodeableConcept40_50.convertCodeableConcept(src.getFacilityType())); 293 if (src.hasPracticeSetting()) 294 tgt.setPracticeSetting(CodeableConcept40_50.convertCodeableConcept(src.getPracticeSetting())); 295 if (src.hasSourcePatientInfo()) 296 tgt.setSourcePatientInfo(Reference40_50.convertReference(src.getSourcePatientInfo())); 297 for (org.hl7.fhir.r5.model.Reference t : src.getRelated()) tgt.addRelated(Reference40_50.convertReference(t)); 298 } 299}