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.Reference30_50; 005import org.hl7.fhir.convertors.conv30_50.datatypes30_50.complextypes30_50.Attachment30_50; 006import org.hl7.fhir.convertors.conv30_50.datatypes30_50.complextypes30_50.CodeableConcept30_50; 007import org.hl7.fhir.convertors.conv30_50.datatypes30_50.complextypes30_50.Identifier30_50; 008import org.hl7.fhir.convertors.conv30_50.datatypes30_50.complextypes30_50.Period30_50; 009import org.hl7.fhir.convertors.conv30_50.datatypes30_50.primitivetypes30_50.String30_50; 010import org.hl7.fhir.exceptions.FHIRException; 011import org.hl7.fhir.r5.model.CodeableReference; 012import org.hl7.fhir.r5.model.DocumentReference.DocumentReferenceAttesterComponent; 013 014public class DocumentReference30_50 { 015 016 public static org.hl7.fhir.r5.model.DocumentReference convertDocumentReference(org.hl7.fhir.dstu3.model.DocumentReference src) throws FHIRException { 017 if (src == null) 018 return null; 019 org.hl7.fhir.r5.model.DocumentReference tgt = new org.hl7.fhir.r5.model.DocumentReference(); 020 ConversionContext30_50.INSTANCE.getVersionConvertor_30_50().copyDomainResource(src, tgt); 021 if (src.hasMasterIdentifier()) 022 tgt.addIdentifier(Identifier30_50.convertIdentifier(src.getMasterIdentifier())); 023 for (org.hl7.fhir.dstu3.model.Identifier t : src.getIdentifier()) 024 tgt.addIdentifier(Identifier30_50.convertIdentifier(t)); 025 if (src.hasStatus()) 026 tgt.setStatusElement(convertDocumentReferenceStatus(src.getStatusElement())); 027 if (src.hasDocStatus()) 028 tgt.setDocStatusElement(convertReferredDocumentStatus(src.getDocStatusElement())); 029 if (src.hasType()) 030 tgt.setType(CodeableConcept30_50.convertCodeableConcept(src.getType())); 031 if (src.hasClass_()) 032 tgt.addCategory(CodeableConcept30_50.convertCodeableConcept(src.getClass_())); 033 if (src.hasSubject()) 034 tgt.setSubject(Reference30_50.convertReference(src.getSubject())); 035 if (src.hasCreated()) 036 tgt.setDate(src.getCreated()); 037 if (src.hasAuthenticator()) 038 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"))) 039 .setParty(Reference30_50.convertReference(src.getAuthenticator())); 040 if (src.hasCustodian()) 041 tgt.setCustodian(Reference30_50.convertReference(src.getCustodian())); 042 for (org.hl7.fhir.dstu3.model.DocumentReference.DocumentReferenceRelatesToComponent t : src.getRelatesTo()) 043 tgt.addRelatesTo(convertDocumentReferenceRelatesToComponent(t)); 044 if (src.hasDescription()) 045 tgt.setDescriptionElement(String30_50.convertStringToMarkdown(src.getDescriptionElement())); 046 for (org.hl7.fhir.dstu3.model.CodeableConcept t : src.getSecurityLabel()) 047 tgt.addSecurityLabel(CodeableConcept30_50.convertCodeableConcept(t)); 048 for (org.hl7.fhir.dstu3.model.DocumentReference.DocumentReferenceContentComponent t : src.getContent()) 049 tgt.addContent(convertDocumentReferenceContentComponent(t)); 050 if (src.hasContext()) 051 convertDocumentReferenceContextComponent(src.getContext(), tgt); 052 for (org.hl7.fhir.dstu3.model.Reference t : src.getAuthor()) 053 tgt.addAuthor(Reference30_50.convertReference(t)); 054 return tgt; 055 } 056 057 public static org.hl7.fhir.dstu3.model.DocumentReference convertDocumentReference(org.hl7.fhir.r5.model.DocumentReference src) throws FHIRException { 058 if (src == null) 059 return null; 060 org.hl7.fhir.dstu3.model.DocumentReference tgt = new org.hl7.fhir.dstu3.model.DocumentReference(); 061 ConversionContext30_50.INSTANCE.getVersionConvertor_30_50().copyDomainResource(src, tgt); 062 // if (src.hasMasterIdentifier()) 063 // tgt.setMasterIdentifier(VersionConvertor_30_50.convertIdentifier(src.getMasterIdentifier())); 064 for (org.hl7.fhir.r5.model.Identifier t : src.getIdentifier()) 065 tgt.addIdentifier(Identifier30_50.convertIdentifier(t)); 066 if (src.hasStatus()) 067 tgt.setStatusElement(convertDocumentReferenceStatus(src.getStatusElement())); 068 if (src.hasDocStatus()) 069 tgt.setDocStatusElement(convertReferredDocumentStatus(src.getDocStatusElement())); 070 if (src.hasType()) 071 tgt.setType(CodeableConcept30_50.convertCodeableConcept(src.getType())); 072 if (src.hasCategory()) 073 tgt.setClass_(CodeableConcept30_50.convertCodeableConcept(src.getCategoryFirstRep())); 074 if (src.hasSubject()) 075 tgt.setSubject(Reference30_50.convertReference(src.getSubject())); 076 if (src.hasDate()) 077 tgt.setCreated(src.getDate()); 078 for (DocumentReferenceAttesterComponent t : src.getAttester()) { 079 if (t.getMode().hasCoding("http://hl7.org/fhir/composition-attestation-mode", "official")) 080 tgt.setAuthenticator(Reference30_50.convertReference(t.getParty())); 081 } 082 if (src.hasCustodian()) 083 tgt.setCustodian(Reference30_50.convertReference(src.getCustodian())); 084 for (org.hl7.fhir.r5.model.DocumentReference.DocumentReferenceRelatesToComponent t : src.getRelatesTo()) 085 tgt.addRelatesTo(convertDocumentReferenceRelatesToComponent(t)); 086 if (src.hasDescription()) 087 tgt.setDescriptionElement(String30_50.convertString(src.getDescriptionElement())); 088 for (org.hl7.fhir.r5.model.CodeableConcept t : src.getSecurityLabel()) 089 tgt.addSecurityLabel(CodeableConcept30_50.convertCodeableConcept(t)); 090 for (org.hl7.fhir.r5.model.DocumentReference.DocumentReferenceContentComponent t : src.getContent()) 091 tgt.addContent(convertDocumentReferenceContentComponent(t)); 092 convertDocumentReferenceContextComponent(src, tgt.getContext()); 093 for (org.hl7.fhir.r5.model.Reference t : src.getAuthor()) 094 tgt.addAuthor(Reference30_50.convertReference(t)); 095 return tgt; 096 } 097 098 public static org.hl7.fhir.dstu3.model.DocumentReference.DocumentReferenceContentComponent convertDocumentReferenceContentComponent(org.hl7.fhir.r5.model.DocumentReference.DocumentReferenceContentComponent src) throws FHIRException { 099 if (src == null) 100 return null; 101 org.hl7.fhir.dstu3.model.DocumentReference.DocumentReferenceContentComponent tgt = new org.hl7.fhir.dstu3.model.DocumentReference.DocumentReferenceContentComponent(); 102 ConversionContext30_50.INSTANCE.getVersionConvertor_30_50().copyBackboneElement(src,tgt); 103 if (src.hasAttachment()) 104 tgt.setAttachment(Attachment30_50.convertAttachment(src.getAttachment())); 105 return tgt; 106 } 107 108 public static org.hl7.fhir.r5.model.DocumentReference.DocumentReferenceContentComponent convertDocumentReferenceContentComponent(org.hl7.fhir.dstu3.model.DocumentReference.DocumentReferenceContentComponent src) throws FHIRException { 109 if (src == null) 110 return null; 111 org.hl7.fhir.r5.model.DocumentReference.DocumentReferenceContentComponent tgt = new org.hl7.fhir.r5.model.DocumentReference.DocumentReferenceContentComponent(); 112 ConversionContext30_50.INSTANCE.getVersionConvertor_30_50().copyBackboneElement(src,tgt); 113 if (src.hasAttachment()) 114 tgt.setAttachment(Attachment30_50.convertAttachment(src.getAttachment())); 115 return tgt; 116 } 117 118 public static void convertDocumentReferenceContextComponent(org.hl7.fhir.r5.model.DocumentReference src, org.hl7.fhir.dstu3.model.DocumentReference.DocumentReferenceContextComponent tgt) throws FHIRException { 119 if (src.hasContext()) 120 tgt.setEncounter(Reference30_50.convertReference(src.getContextFirstRep())); 121 for (CodeableReference t : src.getEvent()) 122 if (t.hasConcept()) 123 tgt.addEvent(CodeableConcept30_50.convertCodeableConcept(t.getConcept())); 124 if (src.hasPeriod()) 125 tgt.setPeriod(Period30_50.convertPeriod(src.getPeriod())); 126 if (src.hasFacilityType()) 127 tgt.setFacilityType(CodeableConcept30_50.convertCodeableConcept(src.getFacilityType())); 128 if (src.hasPracticeSetting()) 129 tgt.setPracticeSetting(CodeableConcept30_50.convertCodeableConcept(src.getPracticeSetting())); 130// if (src.hasSourcePatientInfo()) 131// tgt.setSourcePatientInfo(Reference30_50.convertReference(src.getSourcePatientInfo())); 132// for (org.hl7.fhir.r5.model.Reference t : src.getRelated()) 133// tgt.addRelated(convertDocumentReferenceContextRelatedComponent(t)); 134 } 135 136 public static void convertDocumentReferenceContextComponent(org.hl7.fhir.dstu3.model.DocumentReference.DocumentReferenceContextComponent src, org.hl7.fhir.r5.model.DocumentReference tgt) throws FHIRException { 137 if (src.hasEncounter()) 138 tgt.addContext(Reference30_50.convertReference(src.getEncounter())); 139 for (org.hl7.fhir.dstu3.model.CodeableConcept t : src.getEvent()) 140 tgt.addEvent(new CodeableReference().setConcept(CodeableConcept30_50.convertCodeableConcept(t))); 141 if (src.hasPeriod()) 142 tgt.setPeriod(Period30_50.convertPeriod(src.getPeriod())); 143 if (src.hasFacilityType()) 144 tgt.setFacilityType(CodeableConcept30_50.convertCodeableConcept(src.getFacilityType())); 145 if (src.hasPracticeSetting()) 146 tgt.setPracticeSetting(CodeableConcept30_50.convertCodeableConcept(src.getPracticeSetting())); 147// if (src.hasSourcePatientInfo()) 148// tgt.setSourcePatientInfo(Reference30_50.convertReference(src.getSourcePatientInfo())); 149// for (org.hl7.fhir.dstu3.model.DocumentReference.DocumentReferenceContextRelatedComponent t : src.getRelated()) 150// tgt.addRelated(convertDocumentReferenceContextRelatedComponent(t)); 151 } 152 153 public static org.hl7.fhir.r5.model.Reference convertDocumentReferenceContextRelatedComponent(org.hl7.fhir.dstu3.model.DocumentReference.DocumentReferenceContextRelatedComponent src) throws FHIRException { 154 if (src == null) 155 return null; 156 org.hl7.fhir.r5.model.Reference tgt = Reference30_50.convertReference(src.getRef()); 157 ConversionContext30_50.INSTANCE.getVersionConvertor_30_50().copyElement(src, tgt); 158 if (src.hasIdentifier()) 159 tgt.setIdentifier(Identifier30_50.convertIdentifier(src.getIdentifier())); 160 return tgt; 161 } 162 163 public static org.hl7.fhir.dstu3.model.DocumentReference.DocumentReferenceContextRelatedComponent convertDocumentReferenceContextRelatedComponent(org.hl7.fhir.r5.model.Reference src) throws FHIRException { 164 if (src == null) 165 return null; 166 org.hl7.fhir.dstu3.model.DocumentReference.DocumentReferenceContextRelatedComponent tgt = new org.hl7.fhir.dstu3.model.DocumentReference.DocumentReferenceContextRelatedComponent(); 167 ConversionContext30_50.INSTANCE.getVersionConvertor_30_50().copyElement(src, tgt); 168 if (src.hasIdentifier()) 169 tgt.setIdentifier(Identifier30_50.convertIdentifier(src.getIdentifier())); 170 tgt.setRef(Reference30_50.convertReference(src)); 171 return tgt; 172 } 173 174 public static org.hl7.fhir.r5.model.DocumentReference.DocumentReferenceRelatesToComponent convertDocumentReferenceRelatesToComponent(org.hl7.fhir.dstu3.model.DocumentReference.DocumentReferenceRelatesToComponent src) throws FHIRException { 175 if (src == null) 176 return null; 177 org.hl7.fhir.r5.model.DocumentReference.DocumentReferenceRelatesToComponent tgt = new org.hl7.fhir.r5.model.DocumentReference.DocumentReferenceRelatesToComponent(); 178 ConversionContext30_50.INSTANCE.getVersionConvertor_30_50().copyBackboneElement(src,tgt); 179 if (src.hasCode()) 180 tgt.setCode(convertDocumentRelationshipType(src.getCodeElement())); 181 if (src.hasTarget()) 182 tgt.setTarget(Reference30_50.convertReference(src.getTarget())); 183 return tgt; 184 } 185 186 public static org.hl7.fhir.dstu3.model.DocumentReference.DocumentReferenceRelatesToComponent convertDocumentReferenceRelatesToComponent(org.hl7.fhir.r5.model.DocumentReference.DocumentReferenceRelatesToComponent src) throws FHIRException { 187 if (src == null) 188 return null; 189 org.hl7.fhir.dstu3.model.DocumentReference.DocumentReferenceRelatesToComponent tgt = new org.hl7.fhir.dstu3.model.DocumentReference.DocumentReferenceRelatesToComponent(); 190 ConversionContext30_50.INSTANCE.getVersionConvertor_30_50().copyBackboneElement(src,tgt); 191 if (src.hasCode()) 192 tgt.setCodeElement(convertDocumentRelationshipType2(src.getCode())); 193 if (src.hasTarget()) 194 tgt.setTarget(Reference30_50.convertReference(src.getTarget())); 195 return tgt; 196 } 197 198 static public org.hl7.fhir.dstu3.model.Enumeration<org.hl7.fhir.dstu3.model.Enumerations.DocumentReferenceStatus> convertDocumentReferenceStatus(org.hl7.fhir.r5.model.Enumeration<org.hl7.fhir.r5.model.DocumentReference.DocumentReferenceStatus> src) throws FHIRException { 199 if (src == null || src.isEmpty()) 200 return null; 201 org.hl7.fhir.dstu3.model.Enumeration<org.hl7.fhir.dstu3.model.Enumerations.DocumentReferenceStatus> tgt = new org.hl7.fhir.dstu3.model.Enumeration<>(new org.hl7.fhir.dstu3.model.Enumerations.DocumentReferenceStatusEnumFactory()); 202 ConversionContext30_50.INSTANCE.getVersionConvertor_30_50().copyElement(src, tgt); 203 switch (src.getValue()) { 204 case CURRENT: 205 tgt.setValue(org.hl7.fhir.dstu3.model.Enumerations.DocumentReferenceStatus.CURRENT); 206 break; 207 case SUPERSEDED: 208 tgt.setValue(org.hl7.fhir.dstu3.model.Enumerations.DocumentReferenceStatus.SUPERSEDED); 209 break; 210 case ENTEREDINERROR: 211 tgt.setValue(org.hl7.fhir.dstu3.model.Enumerations.DocumentReferenceStatus.ENTEREDINERROR); 212 break; 213 default: 214 tgt.setValue(org.hl7.fhir.dstu3.model.Enumerations.DocumentReferenceStatus.NULL); 215 break; 216 } 217 return tgt; 218 } 219 220 static public org.hl7.fhir.r5.model.Enumeration<org.hl7.fhir.r5.model.DocumentReference.DocumentReferenceStatus> convertDocumentReferenceStatus(org.hl7.fhir.dstu3.model.Enumeration<org.hl7.fhir.dstu3.model.Enumerations.DocumentReferenceStatus> src) throws FHIRException { 221 if (src == null || src.isEmpty()) 222 return null; 223 org.hl7.fhir.r5.model.Enumeration<org.hl7.fhir.r5.model.DocumentReference.DocumentReferenceStatus> tgt = new org.hl7.fhir.r5.model.Enumeration<>(new org.hl7.fhir.r5.model.DocumentReference.DocumentReferenceStatusEnumFactory()); 224 ConversionContext30_50.INSTANCE.getVersionConvertor_30_50().copyElement(src, tgt); 225 switch (src.getValue()) { 226 case CURRENT: 227 tgt.setValue(org.hl7.fhir.r5.model.DocumentReference.DocumentReferenceStatus.CURRENT); 228 break; 229 case SUPERSEDED: 230 tgt.setValue(org.hl7.fhir.r5.model.DocumentReference.DocumentReferenceStatus.SUPERSEDED); 231 break; 232 case ENTEREDINERROR: 233 tgt.setValue(org.hl7.fhir.r5.model.DocumentReference.DocumentReferenceStatus.ENTEREDINERROR); 234 break; 235 default: 236 tgt.setValue(org.hl7.fhir.r5.model.DocumentReference.DocumentReferenceStatus.NULL); 237 break; 238 } 239 return tgt; 240 } 241 242 static public org.hl7.fhir.dstu3.model.Enumeration<org.hl7.fhir.dstu3.model.DocumentReference.DocumentRelationshipType> convertDocumentRelationshipType2(org.hl7.fhir.r5.model.CodeableConcept src) throws FHIRException { 243 if (src == null || src.isEmpty()) 244 return null; 245 org.hl7.fhir.dstu3.model.Enumeration<org.hl7.fhir.dstu3.model.DocumentReference.DocumentRelationshipType> tgt = new org.hl7.fhir.dstu3.model.Enumeration<>(new org.hl7.fhir.dstu3.model.DocumentReference.DocumentRelationshipTypeEnumFactory()); 246 ConversionContext30_50.INSTANCE.getVersionConvertor_30_50().copyElement(src, tgt); 247 switch (src.getCode("http://hl7.org/fhir/document-relationship-type")) { 248 case "replaces": 249 tgt.setValue(org.hl7.fhir.dstu3.model.DocumentReference.DocumentRelationshipType.REPLACES); 250 break; 251 case "transforms": 252 tgt.setValue(org.hl7.fhir.dstu3.model.DocumentReference.DocumentRelationshipType.TRANSFORMS); 253 break; 254 case "signs": 255 tgt.setValue(org.hl7.fhir.dstu3.model.DocumentReference.DocumentRelationshipType.SIGNS); 256 break; 257 case "appends": 258 tgt.setValue(org.hl7.fhir.dstu3.model.DocumentReference.DocumentRelationshipType.APPENDS); 259 break; 260 default: 261 tgt.setValue(org.hl7.fhir.dstu3.model.DocumentReference.DocumentRelationshipType.NULL); 262 break; 263 } 264 265 return tgt; 266 } 267 268 static public org.hl7.fhir.dstu3.model.Enumeration<org.hl7.fhir.dstu3.model.DocumentReference.ReferredDocumentStatus> convertReferredDocumentStatus(org.hl7.fhir.r5.model.Enumeration<org.hl7.fhir.r5.model.Enumerations.CompositionStatus> src) throws FHIRException { 269 if (src == null || src.isEmpty()) 270 return null; 271 org.hl7.fhir.dstu3.model.Enumeration<org.hl7.fhir.dstu3.model.DocumentReference.ReferredDocumentStatus> tgt = new org.hl7.fhir.dstu3.model.Enumeration<>(new org.hl7.fhir.dstu3.model.DocumentReference.ReferredDocumentStatusEnumFactory()); 272 ConversionContext30_50.INSTANCE.getVersionConvertor_30_50().copyElement(src, tgt); 273 switch (src.getValue()) { 274 case PRELIMINARY: 275 tgt.setValue(org.hl7.fhir.dstu3.model.DocumentReference.ReferredDocumentStatus.PRELIMINARY); 276 break; 277 case FINAL: 278 tgt.setValue(org.hl7.fhir.dstu3.model.DocumentReference.ReferredDocumentStatus.FINAL); 279 break; 280 case AMENDED: 281 tgt.setValue(org.hl7.fhir.dstu3.model.DocumentReference.ReferredDocumentStatus.AMENDED); 282 break; 283 case ENTEREDINERROR: 284 tgt.setValue(org.hl7.fhir.dstu3.model.DocumentReference.ReferredDocumentStatus.ENTEREDINERROR); 285 break; 286 default: 287 tgt.setValue(org.hl7.fhir.dstu3.model.DocumentReference.ReferredDocumentStatus.NULL); 288 break; 289 } 290 return tgt; 291 } 292 293 static public org.hl7.fhir.r5.model.Enumeration<org.hl7.fhir.r5.model.Enumerations.CompositionStatus> convertReferredDocumentStatus(org.hl7.fhir.dstu3.model.Enumeration<org.hl7.fhir.dstu3.model.DocumentReference.ReferredDocumentStatus> src) throws FHIRException { 294 if (src == null || src.isEmpty()) 295 return null; 296 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()); 297 ConversionContext30_50.INSTANCE.getVersionConvertor_30_50().copyElement(src, tgt); 298 switch (src.getValue()) { 299 case PRELIMINARY: 300 tgt.setValue(org.hl7.fhir.r5.model.Enumerations.CompositionStatus.PRELIMINARY); 301 break; 302 case FINAL: 303 tgt.setValue(org.hl7.fhir.r5.model.Enumerations.CompositionStatus.FINAL); 304 break; 305 case AMENDED: 306 tgt.setValue(org.hl7.fhir.r5.model.Enumerations.CompositionStatus.AMENDED); 307 break; 308 case ENTEREDINERROR: 309 tgt.setValue(org.hl7.fhir.r5.model.Enumerations.CompositionStatus.ENTEREDINERROR); 310 break; 311 default: 312 tgt.setValue(org.hl7.fhir.r5.model.Enumerations.CompositionStatus.NULL); 313 break; 314 } 315 return tgt; 316 } 317 318 static public org.hl7.fhir.r5.model.CodeableConcept convertDocumentRelationshipType(org.hl7.fhir.dstu3.model.Enumeration<org.hl7.fhir.dstu3.model.DocumentReference.DocumentRelationshipType> src) throws FHIRException { 319 if (src == null || src.isEmpty()) return null; 320 org.hl7.fhir.r5.model.CodeableConcept tgt = new org.hl7.fhir.r5.model.CodeableConcept(); 321 ConversionContext30_50.INSTANCE.getVersionConvertor_30_50().copyElement(src, tgt); 322 if (src.getValue() == null) { 323 } else { 324 switch (src.getValue()) { 325 case REPLACES: 326 tgt.addCoding().setSystem("http://hl7.org/fhir/document-relationship-type").setCode("replaces"); 327 break; 328 case TRANSFORMS: 329 tgt.addCoding().setSystem("http://hl7.org/fhir/document-relationship-type").setCode("transforms"); 330 break; 331 case SIGNS: 332 tgt.addCoding().setSystem("http://hl7.org/fhir/document-relationship-type").setCode("signs"); 333 break; 334 case APPENDS: 335 tgt.addCoding().setSystem("http://hl7.org/fhir/document-relationship-type").setCode("appends"); 336 break; 337 default: 338 break; 339 } 340 341 } 342 return tgt; 343 } 344}