001package org.hl7.fhir.convertors.conv14_50.resources14_50; 002 003import java.util.Arrays; 004 005import org.hl7.fhir.convertors.advisors.impl.BaseAdvisor_14_50; 006import org.hl7.fhir.convertors.context.ConversionContext14_50; 007import org.hl7.fhir.convertors.conv14_50.datatypes14_50.Extension14_50; 008import org.hl7.fhir.convertors.conv14_50.datatypes14_50.Meta14_50; 009import org.hl7.fhir.convertors.conv14_50.datatypes14_50.Narrative14_50; 010import org.hl7.fhir.exceptions.FHIRException; 011 012public class Resource14_50 { 013 014 public final BaseAdvisor_14_50 advisor; 015 016 public Resource14_50(BaseAdvisor_14_50 advisor) { 017 this.advisor = advisor; 018 } 019 020 public void copyResource(org.hl7.fhir.dstu2016may.model.Resource src, org.hl7.fhir.r5.model.Resource tgt) throws FHIRException { 021 if (src.hasId()) tgt.setId(src.getId()); 022 if (src.hasMeta()) tgt.setMeta(Meta14_50.convertMeta(src.getMeta())); 023 if (src.hasImplicitRules()) tgt.setImplicitRules(src.getImplicitRules()); 024 if (src.hasLanguage()) tgt.setLanguage(src.getLanguage()); 025 } 026 027 public void copyResource(org.hl7.fhir.r5.model.Resource src, org.hl7.fhir.dstu2016may.model.Resource tgt) throws FHIRException { 028 if (src.hasId()) tgt.setId(src.getId()); 029 if (src.hasMeta()) tgt.setMeta(Meta14_50.convertMeta(src.getMeta())); 030 if (src.hasImplicitRules()) tgt.setImplicitRules(src.getImplicitRules()); 031 if (src.hasLanguage()) tgt.setLanguage(src.getLanguage()); 032 } 033 034 public org.hl7.fhir.r5.model.Resource convertResource(org.hl7.fhir.dstu2016may.model.Resource src) throws FHIRException { 035 if (src == null || src.isEmpty()) return null; 036 if (src instanceof org.hl7.fhir.dstu2016may.model.Parameters) 037 return Parameters14_50.convertParameters((org.hl7.fhir.dstu2016may.model.Parameters) src); 038 if (src instanceof org.hl7.fhir.dstu2016may.model.Bundle) 039 return Bundle14_50.convertBundle((org.hl7.fhir.dstu2016may.model.Bundle) src); 040 if (src instanceof org.hl7.fhir.dstu2016may.model.CodeSystem) 041 return CodeSystem14_50.convertCodeSystem((org.hl7.fhir.dstu2016may.model.CodeSystem) src); 042 if (src instanceof org.hl7.fhir.dstu2016may.model.CompartmentDefinition) 043 return CompartmentDefinition14_50.convertCompartmentDefinition((org.hl7.fhir.dstu2016may.model.CompartmentDefinition) src); 044 if (src instanceof org.hl7.fhir.dstu2016may.model.ConceptMap) 045 return ConceptMap14_50.convertConceptMap((org.hl7.fhir.dstu2016may.model.ConceptMap) src); 046 if (src instanceof org.hl7.fhir.dstu2016may.model.Conformance) 047 return Conformance14_50.convertConformance((org.hl7.fhir.dstu2016may.model.Conformance) src); 048 if (src instanceof org.hl7.fhir.dstu2016may.model.DataElement) 049 return DataElement14_50.convertDataElement((org.hl7.fhir.dstu2016may.model.DataElement) src); 050 if (src instanceof org.hl7.fhir.dstu2016may.model.ImplementationGuide) 051 return ImplementationGuide14_50.convertImplementationGuide((org.hl7.fhir.dstu2016may.model.ImplementationGuide) src); 052 if (src instanceof org.hl7.fhir.dstu2016may.model.NamingSystem) 053 return NamingSystem14_50.convertNamingSystem((org.hl7.fhir.dstu2016may.model.NamingSystem) src); 054 if (src instanceof org.hl7.fhir.dstu2016may.model.OperationDefinition) 055 return OperationDefinition14_50.convertOperationDefinition((org.hl7.fhir.dstu2016may.model.OperationDefinition) src); 056 if (src instanceof org.hl7.fhir.dstu2016may.model.OperationOutcome) 057 return OperationOutcome14_50.convertOperationOutcome((org.hl7.fhir.dstu2016may.model.OperationOutcome) src); 058 if (src instanceof org.hl7.fhir.dstu2016may.model.Questionnaire) 059 return Questionnaire14_50.convertQuestionnaire((org.hl7.fhir.dstu2016may.model.Questionnaire) src); 060 if (src instanceof org.hl7.fhir.dstu2016may.model.QuestionnaireResponse) 061 return QuestionnaireResponse14_50.convertQuestionnaireResponse((org.hl7.fhir.dstu2016may.model.QuestionnaireResponse) src); 062 if (src instanceof org.hl7.fhir.dstu2016may.model.SearchParameter) 063 return SearchParameter14_50.convertSearchParameter((org.hl7.fhir.dstu2016may.model.SearchParameter) src); 064 if (src instanceof org.hl7.fhir.dstu2016may.model.StructureDefinition) 065 return StructureDefinition14_50.convertStructureDefinition((org.hl7.fhir.dstu2016may.model.StructureDefinition) src); 066 if (src instanceof org.hl7.fhir.dstu2016may.model.StructureMap) 067 return StructureMap14_50.convertStructureMap((org.hl7.fhir.dstu2016may.model.StructureMap) src); 068 if (src instanceof org.hl7.fhir.dstu2016may.model.ValueSet) 069 return ValueSet14_50.convertValueSet((org.hl7.fhir.dstu2016may.model.ValueSet) src); 070 if (advisor.failFastOnNullOrUnknownEntry()) { 071 throw new FHIRException("The resource " + src.fhirType()+" cannot be converted from R2B to R5"); 072 } else { 073 return null; 074 } 075 } 076 077 public org.hl7.fhir.dstu2016may.model.Resource convertResource(org.hl7.fhir.r5.model.Resource src) throws FHIRException { 078 if (src == null || src.isEmpty()) return null; 079 if (src instanceof org.hl7.fhir.r5.model.Parameters) 080 return Parameters14_50.convertParameters((org.hl7.fhir.r5.model.Parameters) src); 081 if (src instanceof org.hl7.fhir.r5.model.Bundle) 082 return Bundle14_50.convertBundle((org.hl7.fhir.r5.model.Bundle) src); 083 if (src instanceof org.hl7.fhir.r5.model.CodeSystem) 084 return CodeSystem14_50.convertCodeSystem((org.hl7.fhir.r5.model.CodeSystem) src); 085 if (src instanceof org.hl7.fhir.r5.model.CompartmentDefinition) 086 return CompartmentDefinition14_50.convertCompartmentDefinition((org.hl7.fhir.r5.model.CompartmentDefinition) src); 087 if (src instanceof org.hl7.fhir.r5.model.ConceptMap) 088 return ConceptMap14_50.convertConceptMap((org.hl7.fhir.r5.model.ConceptMap) src); 089 if (src instanceof org.hl7.fhir.r5.model.CapabilityStatement) 090 return Conformance14_50.convertConformance((org.hl7.fhir.r5.model.CapabilityStatement) src); 091 if (src instanceof org.hl7.fhir.r5.model.ImplementationGuide) 092 return ImplementationGuide14_50.convertImplementationGuide((org.hl7.fhir.r5.model.ImplementationGuide) src); 093 if (src instanceof org.hl7.fhir.r5.model.NamingSystem) 094 return NamingSystem14_50.convertNamingSystem((org.hl7.fhir.r5.model.NamingSystem) src); 095 if (src instanceof org.hl7.fhir.r5.model.OperationDefinition) 096 return OperationDefinition14_50.convertOperationDefinition((org.hl7.fhir.r5.model.OperationDefinition) src); 097 if (src instanceof org.hl7.fhir.r5.model.OperationOutcome) 098 return OperationOutcome14_50.convertOperationOutcome((org.hl7.fhir.r5.model.OperationOutcome) src); 099 if (src instanceof org.hl7.fhir.r5.model.Questionnaire) 100 return Questionnaire14_50.convertQuestionnaire((org.hl7.fhir.r5.model.Questionnaire) src); 101 if (src instanceof org.hl7.fhir.r5.model.QuestionnaireResponse) 102 return QuestionnaireResponse14_50.convertQuestionnaireResponse((org.hl7.fhir.r5.model.QuestionnaireResponse) src); 103 if (src instanceof org.hl7.fhir.r5.model.SearchParameter) 104 return SearchParameter14_50.convertSearchParameter((org.hl7.fhir.r5.model.SearchParameter) src); 105 if (src instanceof org.hl7.fhir.r5.model.StructureDefinition) 106 return StructureDefinition14_50.convertStructureDefinition((org.hl7.fhir.r5.model.StructureDefinition) src); 107 if (src instanceof org.hl7.fhir.r5.model.StructureMap) 108 return StructureMap14_50.convertStructureMap((org.hl7.fhir.r5.model.StructureMap) src); 109 if (src instanceof org.hl7.fhir.r5.model.ValueSet) 110 return ValueSet14_50.convertValueSet((org.hl7.fhir.r5.model.ValueSet) src); 111 if (advisor.failFastOnNullOrUnknownEntry()) { 112 throw new FHIRException("The resource " + src.fhirType()+" cannot be converted from R5 to R2B"); 113 } else { 114 return null; 115 } 116 } 117 118 public void copyDomainResource( 119 org.hl7.fhir.dstu2016may.model.DomainResource src, 120 org.hl7.fhir.r5.model.DomainResource tgt, 121 String... extensionUrlsToIgnore) throws FHIRException { 122 copyResource(src, tgt); 123 if (src.hasText()) tgt.setText(Narrative14_50.convertNarrative(src.getText())); 124 src.getContained().stream() 125 .map(this::convertResource) 126 .forEach(tgt::addContained); 127 src.getExtension().forEach(extension -> { 128 if (advisor.useAdvisorForExtension(ConversionContext14_50.INSTANCE.path(), extension)) { 129 org.hl7.fhir.r5.model.Extension convertExtension = new org.hl7.fhir.r5.model.Extension(); 130 advisor.handleExtension(ConversionContext14_50.INSTANCE.path(), extension, convertExtension); 131 tgt.addExtension(convertExtension); 132 } else if (!advisor.ignoreExtension(ConversionContext14_50.INSTANCE.path(), extension) && !Arrays.asList(extensionUrlsToIgnore).contains(extension.getUrl())) { 133 tgt.addExtension(Extension14_50.convertExtension(extension)); 134 } 135 }); 136 src.getModifierExtension().stream() 137 .filter(extension -> !advisor.ignoreExtension(ConversionContext14_50.INSTANCE.path(), extension)) 138 .map(Extension14_50::convertExtension) 139 .forEach(tgt::addModifierExtension); 140 } 141 142 public void copyDomainResource( 143 org.hl7.fhir.r5.model.DomainResource src, 144 org.hl7.fhir.dstu2016may.model.DomainResource tgt, 145 String... extensionUrlsToIgnore) throws FHIRException { 146 copyResource(src, tgt); 147 if (src.hasText()) tgt.setText(Narrative14_50.convertNarrative(src.getText())); 148 src.getContained().stream() 149 .map(this::convertResource) 150 .forEach(tgt::addContained); 151 src.getExtension().forEach(extension -> { 152 if (advisor.useAdvisorForExtension(ConversionContext14_50.INSTANCE.path(), extension)) { 153 org.hl7.fhir.dstu2016may.model.Extension convertExtension = new org.hl7.fhir.dstu2016may.model.Extension(); 154 advisor.handleExtension(ConversionContext14_50.INSTANCE.path(), extension, convertExtension); 155 tgt.addExtension(convertExtension); 156 } else if (!advisor.ignoreExtension(ConversionContext14_50.INSTANCE.path(), extension) && !Arrays.asList(extensionUrlsToIgnore).contains(extension.getUrl())) { 157 tgt.addExtension(Extension14_50.convertExtension(extension)); 158 } 159 }); 160 src.getModifierExtension().stream() 161 .filter(extension -> !advisor.ignoreExtension(ConversionContext14_50.INSTANCE.path(), extension)) 162 .map(Extension14_50::convertExtension) 163 .forEach(tgt::addModifierExtension); 164 } 165}