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