From 2b1ed16f68d479421cdbfa495c99a5e360c299a1 Mon Sep 17 00:00:00 2001 From: Ken Stevens Date: Thu, 4 Jul 2019 13:58:20 -0400 Subject: [PATCH] Apply the same fix we used for Dstu3 --- .../ca/uhn/fhir/jpa/model/any/AnyBundle.java | 90 +++++++++++++++++++ .../config/SearchParamR4Config.java | 6 -- .../module/config/SubscriptionR4Config.java | 11 +++ 3 files changed, 101 insertions(+), 6 deletions(-) create mode 100644 hapi-fhir-jpaserver-model/src/main/java/ca/uhn/fhir/jpa/model/any/AnyBundle.java diff --git a/hapi-fhir-jpaserver-model/src/main/java/ca/uhn/fhir/jpa/model/any/AnyBundle.java b/hapi-fhir-jpaserver-model/src/main/java/ca/uhn/fhir/jpa/model/any/AnyBundle.java new file mode 100644 index 00000000000..c383d8cc1ac --- /dev/null +++ b/hapi-fhir-jpaserver-model/src/main/java/ca/uhn/fhir/jpa/model/any/AnyBundle.java @@ -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"); + } + + } +} diff --git a/hapi-fhir-jpaserver-searchparam/src/main/java/ca/uhn/fhir/jpa/searchparam/config/SearchParamR4Config.java b/hapi-fhir-jpaserver-searchparam/src/main/java/ca/uhn/fhir/jpa/searchparam/config/SearchParamR4Config.java index 9b1e9897bae..97b33256e8e 100644 --- a/hapi-fhir-jpaserver-searchparam/src/main/java/ca/uhn/fhir/jpa/searchparam/config/SearchParamR4Config.java +++ b/hapi-fhir-jpaserver-searchparam/src/main/java/ca/uhn/fhir/jpa/searchparam/config/SearchParamR4Config.java @@ -53,10 +53,4 @@ public class SearchParamR4Config extends BaseSearchParamConfig { public SearchParamExtractorR4 searchParamExtractor() { return new SearchParamExtractorR4(); } - - @Primary - @Bean(autowire = Autowire.BY_NAME, name = "myJpaValidationSupportChainR4") - public IValidationSupport validationSupportChainR4() { - return new DefaultProfileValidationSupport(); - } } diff --git a/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/module/config/SubscriptionR4Config.java b/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/module/config/SubscriptionR4Config.java index 5c758a15fd6..9176dd3bac5 100644 --- a/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/module/config/SubscriptionR4Config.java +++ b/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/module/config/SubscriptionR4Config.java @@ -21,8 +21,19 @@ package ca.uhn.fhir.jpa.subscription.module.config; */ 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.Primary; @Import({SearchParamR4Config.class}) public class SubscriptionR4Config extends BaseSubscriptionConfig { + + @Primary + @Bean(autowire = Autowire.BY_NAME, name = "myJpaValidationSupportChainR4") + public IValidationSupport validationSupportChainR4() { + return new DefaultProfileValidationSupport(); + } }