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