Apply the same fix we used for Dstu3 (#1367)

This commit is contained in:
Ken Stevens 2019-07-04 17:16:39 -04:00 committed by GitHub
commit 5b58cbec76
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 101 additions and 6 deletions

View File

@ -0,0 +1,90 @@
package ca.uhn.fhir.jpa.model.any;
import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.context.FhirVersionEnum;
import org.apache.commons.lang3.Validate;
import org.hl7.fhir.instance.model.api.IBaseBundle;
import org.hl7.fhir.instance.model.api.IBaseResource;
public class AnyBundle {
private final FhirVersionEnum myFhirVersion;
private final IBaseBundle myBundle;
public static AnyBundle fromFhirContext(FhirContext theFhirContext) {
FhirVersionEnum version = theFhirContext.getVersion().getVersion();
switch (version) {
case DSTU2:
return new AnyBundle(new ca.uhn.fhir.model.dstu2.resource.Bundle());
case DSTU3:
return new AnyBundle(new org.hl7.fhir.dstu3.model.Bundle());
case R4:
return new AnyBundle(new org.hl7.fhir.r4.model.Bundle());
default:
throw new UnsupportedOperationException(version + " not supported");
}
}
public AnyBundle(ca.uhn.fhir.model.dstu2.resource.Bundle theBundleR2) {
myFhirVersion = FhirVersionEnum.DSTU2;
myBundle = theBundleR2;
}
public AnyBundle(org.hl7.fhir.dstu3.model.Bundle theBundleR3) {
myFhirVersion = FhirVersionEnum.DSTU3;
myBundle = theBundleR3;
}
public AnyBundle(org.hl7.fhir.r4.model.Bundle theBundleR4) {
myFhirVersion = FhirVersionEnum.R4;
myBundle = theBundleR4;
}
public static AnyBundle fromResource(IBaseResource theBundle) {
if (theBundle instanceof ca.uhn.fhir.model.dstu2.resource.Bundle) {
return new AnyBundle((ca.uhn.fhir.model.dstu2.resource.Bundle) theBundle);
} else if (theBundle instanceof org.hl7.fhir.dstu3.model.Bundle) {
return new AnyBundle((org.hl7.fhir.dstu3.model.Bundle) theBundle);
} else if (theBundle instanceof org.hl7.fhir.r4.model.Bundle) {
return new AnyBundle((org.hl7.fhir.r4.model.Bundle) theBundle);
} else {
throw new UnsupportedOperationException("Cannot convert " + theBundle.getClass().getName() + " to AnyBundle");
}
}
public IBaseBundle get() {
return myBundle;
}
public ca.uhn.fhir.model.dstu2.resource.Bundle getDstu2() {
Validate.isTrue(myFhirVersion == FhirVersionEnum.DSTU2);
return (ca.uhn.fhir.model.dstu2.resource.Bundle) get();
}
public org.hl7.fhir.dstu3.model.Bundle getDstu3() {
Validate.isTrue(myFhirVersion == FhirVersionEnum.DSTU3);
return (org.hl7.fhir.dstu3.model.Bundle) get();
}
public org.hl7.fhir.r4.model.Bundle getR4() {
Validate.isTrue(myFhirVersion == FhirVersionEnum.R4);
return (org.hl7.fhir.r4.model.Bundle) get();
}
public void addResource(IBaseResource theResource) {
switch (myFhirVersion) {
case DSTU3:
org.hl7.fhir.dstu3.model.Bundle.BundleEntryComponent entry = new org.hl7.fhir.dstu3.model.Bundle.BundleEntryComponent();
entry.setResource((org.hl7.fhir.dstu3.model.Resource) theResource);
getDstu3().getEntry().add(entry);
break;
case R4:
org.hl7.fhir.r4.model.Bundle.BundleEntryComponent entryr4 = new org.hl7.fhir.r4.model.Bundle.BundleEntryComponent();
entryr4.setResource((org.hl7.fhir.r4.model.Resource) theResource);
getR4().getEntry().add(entryr4);
break;
default:
throw new UnsupportedOperationException(myFhirVersion + " not supported");
}
}
}

View File

@ -53,10 +53,4 @@ public class SearchParamR4Config extends BaseSearchParamConfig {
public SearchParamExtractorR4 searchParamExtractor() { public SearchParamExtractorR4 searchParamExtractor() {
return new SearchParamExtractorR4(); return new SearchParamExtractorR4();
} }
@Primary
@Bean(autowire = Autowire.BY_NAME, name = "myJpaValidationSupportChainR4")
public IValidationSupport validationSupportChainR4() {
return new DefaultProfileValidationSupport();
}
} }

View File

@ -21,8 +21,19 @@ package ca.uhn.fhir.jpa.subscription.module.config;
*/ */
import ca.uhn.fhir.jpa.searchparam.config.SearchParamR4Config; import ca.uhn.fhir.jpa.searchparam.config.SearchParamR4Config;
import org.hl7.fhir.r4.hapi.ctx.DefaultProfileValidationSupport;
import org.hl7.fhir.r4.hapi.ctx.IValidationSupport;
import org.springframework.beans.factory.annotation.Autowire;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Import; import org.springframework.context.annotation.Import;
import org.springframework.context.annotation.Primary;
@Import({SearchParamR4Config.class}) @Import({SearchParamR4Config.class})
public class SubscriptionR4Config extends BaseSubscriptionConfig { public class SubscriptionR4Config extends BaseSubscriptionConfig {
@Primary
@Bean(autowire = Autowire.BY_NAME, name = "myJpaValidationSupportChainR4")
public IValidationSupport validationSupportChainR4() {
return new DefaultProfileValidationSupport();
}
} }