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 deleted file mode 100644 index 63805b90fb0..00000000000 --- a/hapi-fhir-jpaserver-model/src/main/java/ca/uhn/fhir/jpa/model/any/AnyBundle.java +++ /dev/null @@ -1,110 +0,0 @@ -package ca.uhn.fhir.jpa.model.any; - -/*- - * #%L - * HAPI FHIR Model - * %% - * Copyright (C) 2014 - 2020 University Health Network - * %% - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * #L% - */ - -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-model/src/main/java/ca/uhn/fhir/jpa/model/any/AnyComposition.java b/hapi-fhir-jpaserver-model/src/main/java/ca/uhn/fhir/jpa/model/any/AnyComposition.java deleted file mode 100644 index 702f63a05f5..00000000000 --- a/hapi-fhir-jpaserver-model/src/main/java/ca/uhn/fhir/jpa/model/any/AnyComposition.java +++ /dev/null @@ -1,235 +0,0 @@ -package ca.uhn.fhir.jpa.model.any; - -/*- - * #%L - * HAPI FHIR Model - * %% - * Copyright (C) 2014 - 2020 University Health Network - * %% - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * #L% - */ - -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.IBaseResource; - -import java.util.List; - -public class AnyComposition { - private final FhirVersionEnum myFhirVersion; - private final IBaseResource myComposition; - - public static AnyComposition fromFhirContext(FhirContext theFhirContext) { - FhirVersionEnum version = theFhirContext.getVersion().getVersion(); - switch (version) { - case DSTU3: - return new AnyComposition(new org.hl7.fhir.dstu3.model.Composition()); - case R4: - return new AnyComposition(new org.hl7.fhir.r4.model.Composition()); - default: - throw new UnsupportedOperationException(version + " not supported"); - } - } - - public AnyComposition(org.hl7.fhir.dstu3.model.Composition theCompositionR3) { - myFhirVersion = FhirVersionEnum.DSTU3; - myComposition = theCompositionR3; - } - - public AnyComposition(org.hl7.fhir.r4.model.Composition theCompositionR4) { - myFhirVersion = FhirVersionEnum.R4; - myComposition = theCompositionR4; - } - - public static AnyComposition fromResource(IBaseResource theComposition) { - if (theComposition instanceof org.hl7.fhir.dstu3.model.Composition) { - return new AnyComposition((org.hl7.fhir.dstu3.model.Composition) theComposition); - } else if (theComposition instanceof org.hl7.fhir.r4.model.Composition) { - return new AnyComposition((org.hl7.fhir.r4.model.Composition) theComposition); - } else { - throw new UnsupportedOperationException("Cannot convert " + theComposition.getClass().getName() + " to AnyList"); - } - } - - public IBaseResource get() { - return myComposition; - } - - public org.hl7.fhir.dstu3.model.Composition getDstu3() { - Validate.isTrue(myFhirVersion == FhirVersionEnum.DSTU3); - return (org.hl7.fhir.dstu3.model.Composition) get(); - } - - public org.hl7.fhir.r4.model.Composition getR4() { - Validate.isTrue(myFhirVersion == FhirVersionEnum.R4); - return (org.hl7.fhir.r4.model.Composition) get(); - } - - public void setIdentifier(String theSystem, String theValue) { - switch (myFhirVersion) { - case DSTU3: - getDstu3().setIdentifier(new org.hl7.fhir.dstu3.model.Identifier().setSystem(theSystem).setValue(theValue)); - break; - case R4: - getR4().setIdentifier(new org.hl7.fhir.r4.model.Identifier().setSystem(theSystem).setValue(theValue)); - break; - default: - throw new UnsupportedOperationException(myFhirVersion + " not supported"); - } - } - - public String getIdentifier() { - switch (myFhirVersion) { - case DSTU3: - return getDstu3().getIdentifier().getValue(); - case R4: - return getR4().getIdentifier().getValue(); - default: - throw new UnsupportedOperationException(myFhirVersion + " not supported"); - } - } - - public void setClass(String theSystem, String theCode) { - switch (myFhirVersion) { - case DSTU3: - setClassDstu3(theSystem, theCode); - break; - case R4: - setClassR4(theSystem, theCode); - break; - default: - throw new UnsupportedOperationException(myFhirVersion + " not supported"); - } - } - - private void setClassDstu3(String theSystem, String theCode) { - org.hl7.fhir.dstu3.model.CodeableConcept codeableConcept = new org.hl7.fhir.dstu3.model.CodeableConcept(); - codeableConcept.addCoding().setSystem(theSystem).setCode(theCode); - getDstu3().setClass_(codeableConcept); - } - - private void setClassR4(String theSystem, String theCode) { - org.hl7.fhir.r4.model.CodeableConcept codeableConcept = new org.hl7.fhir.r4.model.CodeableConcept(); - codeableConcept.addCoding().setSystem(theSystem).setCode(theCode); - getR4().addCategory(codeableConcept); - } - - public void addStringExtension(String theUrl, String theValue) { - switch (myFhirVersion) { - case DSTU3: - getDstu3().addExtension().setUrl(theUrl).setValue(new org.hl7.fhir.dstu3.model.StringType(theValue)); - break; - case R4: - getR4().addExtension().setUrl(theUrl).setValue(new org.hl7.fhir.r4.model.StringType(theValue)); - break; - default: - throw new UnsupportedOperationException(myFhirVersion + " not supported"); - } - } - - // TODO KHS Consolidate with other classes in this package - public String getStringExtensionValueOrNull(String theUrl) { - switch (myFhirVersion) { - case DSTU3: - return getStringExtensionValueOrNullDstu3(theUrl); - case R4: - return getStringExtensionValueOrNullR4(theUrl); - default: - throw new UnsupportedOperationException(myFhirVersion + " not supported"); - } - } - - private String getStringExtensionValueOrNullDstu3(String theUrl) { - List targetTypes = getDstu3().getExtensionsByUrl(theUrl); - if (targetTypes.size() < 1) { - return null; - } - org.hl7.fhir.dstu3.model.StringType targetType = (org.hl7.fhir.dstu3.model.StringType) targetTypes.get(0).getValue(); - return targetType.getValue(); - } - - private String getStringExtensionValueOrNullR4(String theUrl) { - List targetTypes = getR4().getExtensionsByUrl(theUrl); - if (targetTypes.size() < 1) { - return null; - } - org.hl7.fhir.r4.model.StringType targetType = (org.hl7.fhir.r4.model.StringType) targetTypes.get(0).getValue(); - return targetType.getValue(); - } - - public void setSubject(String theReferenceId) { - switch (myFhirVersion) { - case DSTU3: - getDstu3().setSubject(new org.hl7.fhir.dstu3.model.Reference(theReferenceId)); - break; - case R4: - getR4().setSubject(new org.hl7.fhir.r4.model.Reference(theReferenceId)); - break; - default: - throw new UnsupportedOperationException(myFhirVersion + " not supported"); - } - } - - public void setTitle(String theTitle) { - switch (myFhirVersion) { - case DSTU3: - getDstu3().setTitle(theTitle); - break; - case R4: - getR4().setTitle(theTitle); - break; - default: - throw new UnsupportedOperationException(myFhirVersion + " not supported"); - } - } - - public String getTitle() { - switch (myFhirVersion) { - case DSTU3: - return getDstu3().getTitle(); - case R4: - return getR4().getTitle(); - default: - throw new UnsupportedOperationException(myFhirVersion + " not supported"); - } - } - - public void addEntry(String theReferenceId) { - switch (myFhirVersion) { - case DSTU3: - getDstu3().getSectionFirstRep().addEntry(new org.hl7.fhir.dstu3.model.Reference(theReferenceId)); - break; - case R4: - getR4().getSectionFirstRep().addEntry(new org.hl7.fhir.r4.model.Reference(theReferenceId)); - break; - default: - throw new UnsupportedOperationException(myFhirVersion + " not supported"); - } - } - - public void setRandomUuid() { - switch (myFhirVersion) { - case DSTU3: - getDstu3().setId(org.hl7.fhir.dstu3.model.IdType.newRandomUuid()); - break; - case R4: - getR4().setId(org.hl7.fhir.r4.model.IdType.newRandomUuid()); - break; - default: - throw new UnsupportedOperationException(myFhirVersion + " not supported"); - } - - } -} diff --git a/hapi-fhir-jpaserver-model/src/main/java/ca/uhn/fhir/jpa/model/any/AnyListResource.java b/hapi-fhir-jpaserver-model/src/main/java/ca/uhn/fhir/jpa/model/any/AnyListResource.java deleted file mode 100644 index 4ac73881959..00000000000 --- a/hapi-fhir-jpaserver-model/src/main/java/ca/uhn/fhir/jpa/model/any/AnyListResource.java +++ /dev/null @@ -1,361 +0,0 @@ -package ca.uhn.fhir.jpa.model.any; - -/*- - * #%L - * HAPI FHIR Model - * %% - * Copyright (C) 2014 - 2020 University Health Network - * %% - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * #L% - */ - -import ca.uhn.fhir.context.FhirContext; -import ca.uhn.fhir.context.FhirVersionEnum; -import ca.uhn.fhir.rest.param.TokenParam; -import org.apache.commons.lang3.Validate; -import org.hl7.fhir.instance.model.api.IBaseReference; -import org.hl7.fhir.instance.model.api.IBaseResource; - -import java.util.List; -import java.util.stream.Stream; - -public class AnyListResource { - private final FhirVersionEnum myFhirVersion; - private final IBaseResource myListResource; - - public static AnyListResource fromFhirContext(FhirContext theFhirContext) { - FhirVersionEnum version = theFhirContext.getVersion().getVersion(); - switch (version) { - case DSTU2: - return new AnyListResource(new ca.uhn.fhir.model.dstu2.resource.ListResource()); - case DSTU3: - return new AnyListResource(new org.hl7.fhir.dstu3.model.ListResource()); - case R4: - return new AnyListResource(new org.hl7.fhir.r4.model.ListResource()); - case R5: - return new AnyListResource(new org.hl7.fhir.r5.model.ListResource()); - default: - throw new UnsupportedOperationException(version + " not supported"); - } - } - - public AnyListResource(ca.uhn.fhir.model.dstu2.resource.ListResource theListResourceR2) { - myFhirVersion = FhirVersionEnum.DSTU2; - myListResource = theListResourceR2; - } - - public AnyListResource(org.hl7.fhir.dstu3.model.ListResource theListResourceR3) { - myFhirVersion = FhirVersionEnum.DSTU3; - myListResource = theListResourceR3; - } - - public AnyListResource(org.hl7.fhir.r4.model.ListResource theListResourceR4) { - myFhirVersion = FhirVersionEnum.R4; - myListResource = theListResourceR4; - } - - public AnyListResource(org.hl7.fhir.r5.model.ListResource theListResourceR5) { - myFhirVersion = FhirVersionEnum.R5; - myListResource = theListResourceR5; - } - - public static AnyListResource fromResource(IBaseResource theListResource) { - if (theListResource instanceof ca.uhn.fhir.model.dstu2.resource.ListResource) { - return new AnyListResource((ca.uhn.fhir.model.dstu2.resource.ListResource) theListResource); - } else if (theListResource instanceof org.hl7.fhir.dstu3.model.ListResource) { - return new AnyListResource((org.hl7.fhir.dstu3.model.ListResource) theListResource); - } else if (theListResource instanceof org.hl7.fhir.r4.model.ListResource) { - return new AnyListResource((org.hl7.fhir.r4.model.ListResource) theListResource); - } else if (theListResource instanceof org.hl7.fhir.r5.model.ListResource) { - return new AnyListResource((org.hl7.fhir.r5.model.ListResource) theListResource); - } else { - throw new UnsupportedOperationException("Cannot convert " + theListResource.getClass().getName() + " to AnyList"); - } - } - - public IBaseResource get() { - return myListResource; - } - - public ca.uhn.fhir.model.dstu2.resource.ListResource getDstu2() { - Validate.isTrue(myFhirVersion == FhirVersionEnum.DSTU2); - return (ca.uhn.fhir.model.dstu2.resource.ListResource) get(); - } - - public org.hl7.fhir.dstu3.model.ListResource getDstu3() { - Validate.isTrue(myFhirVersion == FhirVersionEnum.DSTU3); - return (org.hl7.fhir.dstu3.model.ListResource) get(); - } - - public org.hl7.fhir.r4.model.ListResource getR4() { - Validate.isTrue(myFhirVersion == FhirVersionEnum.R4); - return (org.hl7.fhir.r4.model.ListResource) get(); - } - - public org.hl7.fhir.r5.model.ListResource getR5() { - Validate.isTrue(myFhirVersion == FhirVersionEnum.R5); - return (org.hl7.fhir.r5.model.ListResource) get(); - } - - public FhirVersionEnum getFhirVersion() { - return myFhirVersion; - } - - public void addCode(String theSystem, String theCode) { - switch (myFhirVersion) { - case DSTU3: - getDstu3().getCode().addCoding().setSystem(theSystem).setCode(theCode); - break; - case R4: - getR4().getCode().addCoding().setSystem(theSystem).setCode(theCode); - break; - case R5: - getR5().getCode().addCoding().setSystem(theSystem).setCode(theCode); - break; - default: - throw new UnsupportedOperationException(myFhirVersion + " not supported"); - } - } - - public void addIdentifier(String theSystem, String theValue) { - switch (myFhirVersion) { - case DSTU3: - getDstu3().getIdentifier().add(new org.hl7.fhir.dstu3.model.Identifier().setSystem(theSystem).setValue(theValue)); - break; - case R4: - getR4().getIdentifier().add(new org.hl7.fhir.r4.model.Identifier().setSystem(theSystem).setValue(theValue)); - break; - case R5: - getR5().getIdentifier().add(new org.hl7.fhir.r5.model.Identifier().setSystem(theSystem).setValue(theValue)); - break; - default: - throw new UnsupportedOperationException(myFhirVersion + " not supported"); - } - } - - public void addStringExtension(String theUrl, String theValue) { - switch (myFhirVersion) { - case DSTU3: - getDstu3().addExtension().setUrl(theUrl).setValue(new org.hl7.fhir.dstu3.model.StringType(theValue)); - break; - case R4: - getR4().addExtension().setUrl(theUrl).setValue(new org.hl7.fhir.r4.model.StringType(theValue)); - break; - case R5: - getR5().addExtension().setUrl(theUrl).setValue(new org.hl7.fhir.r5.model.StringType(theValue)); - break; - default: - throw new UnsupportedOperationException(myFhirVersion + " not supported"); - } - } - - public String getStringExtensionValueOrNull(String theUrl) { - switch (myFhirVersion) { - case DSTU3: - return getStringExtensionValueOrNullDstu3(theUrl); - case R4: - return getStringExtensionValueOrNullR4(theUrl); - case R5: - return getStringExtensionValueOrNullR5(theUrl); - default: - throw new UnsupportedOperationException(myFhirVersion + " not supported"); - } - } - - private String getStringExtensionValueOrNullDstu3(String theUrl) { - List targetTypes = getDstu3().getExtensionsByUrl(theUrl); - if (targetTypes.size() < 1) { - return null; - } - org.hl7.fhir.dstu3.model.StringType targetType = (org.hl7.fhir.dstu3.model.StringType) targetTypes.get(0).getValue(); - return targetType.getValue(); - } - - private String getStringExtensionValueOrNullR4(String theUrl) { - List targetTypes = getR4().getExtensionsByUrl(theUrl); - if (targetTypes.size() < 1) { - return null; - } - org.hl7.fhir.r4.model.StringType targetType = (org.hl7.fhir.r4.model.StringType) targetTypes.get(0).getValue(); - return targetType.getValue(); - } - - private String getStringExtensionValueOrNullR5(String theUrl) { - List targetTypes = getR5().getExtensionsByUrl(theUrl); - if (targetTypes.size() < 1) { - return null; - } - org.hl7.fhir.r5.model.StringType targetType = (org.hl7.fhir.r5.model.StringType) targetTypes.get(0).getValue(); - return targetType.getValue(); - } - - public void addReference(IBaseReference theReference) { - switch (myFhirVersion) { - case DSTU3: - getDstu3().addEntry().setItem((org.hl7.fhir.dstu3.model.Reference) theReference); - break; - case R4: - getR4().addEntry().setItem((org.hl7.fhir.r4.model.Reference) theReference); - break; - case R5: - getR5().addEntry().setItem((org.hl7.fhir.r5.model.Reference) theReference); - break; - default: - throw new UnsupportedOperationException(myFhirVersion + " not supported"); - } - } - - public void addReference(String theReferenceId) { - switch (myFhirVersion) { - case DSTU3: - getDstu3().addEntry().setItem(new org.hl7.fhir.dstu3.model.Reference(theReferenceId)); - break; - case R4: - getR4().addEntry().setItem(new org.hl7.fhir.r4.model.Reference(theReferenceId)); - break; - case R5: - getR5().addEntry().setItem(new org.hl7.fhir.r5.model.Reference(theReferenceId)); - break; - default: - throw new UnsupportedOperationException(myFhirVersion + " not supported"); - } - } - - public Stream getReferenceStream() { - switch (myFhirVersion) { - case DSTU3: - return getDstu3().getEntry().stream() - .map(entry -> entry.getItem().getReference()) - .map(reference -> new org.hl7.fhir.dstu3.model.IdType(reference).toUnqualifiedVersionless().getValue()); - case R4: - return getR4().getEntry().stream() - .map(entry -> entry.getItem().getReference()) - .map(reference -> new org.hl7.fhir.r4.model.IdType(reference).toUnqualifiedVersionless().getValue()); - case R5: - return getR5().getEntry().stream() - .map(entry -> entry.getItem().getReference()) - .map(reference -> new org.hl7.fhir.r5.model.IdType(reference).toUnqualifiedVersionless().getValue()); - default: - throw new UnsupportedOperationException(myFhirVersion + " not supported"); - } - } - - public boolean removeItem(String theReferenceId) { - switch (myFhirVersion) { - case DSTU3: - return removeItemDstu3(theReferenceId); - case R4: - return removeItemR4(theReferenceId); - case R5: - return removeItemR5(theReferenceId); - default: - throw new UnsupportedOperationException(myFhirVersion + " not supported"); - } - } - - private boolean removeItemDstu3(String theReferenceId) { - boolean removed = false; - for (org.hl7.fhir.dstu3.model.ListResource.ListEntryComponent entry : getDstu3().getEntry()) { - if (theReferenceId.equals(entry.getItem().getReference()) && !entry.getDeleted()) { - entry.setDeleted(true); - removed = true; - break; - } - } - - if (removed) { - getDstu3().getEntry().removeIf(entry -> entry.getDeleted()); - } - return removed; - } - - private boolean removeItemR4(String theReferenceId) { - boolean removed = false; - for (org.hl7.fhir.r4.model.ListResource.ListEntryComponent entry : getR4().getEntry()) { - if (theReferenceId.equals(entry.getItem().getReference()) && !entry.getDeleted()) { - entry.setDeleted(true); - removed = true; - break; - } - } - - if (removed) { - getR4().getEntry().removeIf(entry -> entry.getDeleted()); - } - return removed; - } - - private boolean removeItemR5(String theReferenceId) { - boolean removed = false; - for (org.hl7.fhir.r5.model.ListResource.ListResourceEntryComponent entry : getR5().getEntry()) { - if (theReferenceId.equals(entry.getItem().getReference()) && !entry.getDeleted()) { - entry.setDeleted(true); - removed = true; - break; - } - } - - if (removed) { - getR5().getEntry().removeIf(entry -> entry.getDeleted()); - } - return removed; - } - - public TokenParam getCodeFirstRep() { - switch (myFhirVersion) { - case DSTU3: - org.hl7.fhir.dstu3.model.Coding codingDstu3 = getDstu3().getCode().getCodingFirstRep(); - return new TokenParam(codingDstu3.getSystem(), codingDstu3.getCode()); - case R4: - org.hl7.fhir.r4.model.Coding codingR4 = getR4().getCode().getCodingFirstRep(); - return new TokenParam(codingR4.getSystem(), codingR4.getCode()); - case R5: - org.hl7.fhir.r5.model.Coding codingR5 = getR5().getCode().getCodingFirstRep(); - return new TokenParam(codingR5.getSystem(), codingR5.getCode()); - default: - throw new UnsupportedOperationException(myFhirVersion + " not supported"); - } - } - - public TokenParam getIdentifierirstRep() { - switch (myFhirVersion) { - case DSTU3: - org.hl7.fhir.dstu3.model.Identifier identDstu3 = getDstu3().getIdentifierFirstRep(); - return new TokenParam(identDstu3.getSystem(), identDstu3.getValue()); - case R4: - org.hl7.fhir.r4.model.Identifier identR4 = getR4().getIdentifierFirstRep(); - return new TokenParam(identR4.getSystem(), identR4.getValue()); - case R5: - org.hl7.fhir.r5.model.Identifier identR5 = getR5().getIdentifierFirstRep(); - return new TokenParam(identR5.getSystem(), identR5.getValue()); - default: - throw new UnsupportedOperationException(myFhirVersion + " not supported"); - } - } - - - - public boolean isEmpty() { - switch (myFhirVersion) { - case DSTU3: - return getDstu3().getEntry().isEmpty(); - case R4: - return getR4().getEntry().isEmpty(); - case R5: - return getR5().getEntry().isEmpty(); - default: - throw new UnsupportedOperationException(myFhirVersion + " not supported"); - } - } -} diff --git a/hapi-fhir-jpaserver-model/src/main/java/ca/uhn/fhir/jpa/model/any/AnyMeasure.java b/hapi-fhir-jpaserver-model/src/main/java/ca/uhn/fhir/jpa/model/any/AnyMeasure.java deleted file mode 100644 index c0ec30848f7..00000000000 --- a/hapi-fhir-jpaserver-model/src/main/java/ca/uhn/fhir/jpa/model/any/AnyMeasure.java +++ /dev/null @@ -1,451 +0,0 @@ -package ca.uhn.fhir.jpa.model.any; - -/*- - * #%L - * HAPI FHIR Model - * %% - * Copyright (C) 2014 - 2020 University Health Network - * %% - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * #L% - */ - -import ca.uhn.fhir.context.FhirContext; -import ca.uhn.fhir.context.FhirVersionEnum; -import ca.uhn.fhir.rest.param.TokenParam; -import org.apache.commons.lang3.Validate; -import org.hl7.fhir.instance.model.api.IBaseReference; -import org.hl7.fhir.instance.model.api.IBaseResource; - -import java.util.ArrayList; -import java.util.Date; -import java.util.List; - -public class AnyMeasure { - private final FhirVersionEnum myFhirVersion; - private final IBaseResource myMeasure; - - public static AnyMeasure fromFhirContext(FhirContext theFhirContext) { - FhirVersionEnum version = theFhirContext.getVersion().getVersion(); - switch (version) { - case DSTU3: - return new AnyMeasure(new org.hl7.fhir.dstu3.model.Measure()); - case R4: - return new AnyMeasure(new org.hl7.fhir.r4.model.Measure()); - default: - throw new UnsupportedOperationException(version + " not supported"); - } - } - - public AnyMeasure(org.hl7.fhir.dstu3.model.Measure theMeasureR3) { - myFhirVersion = FhirVersionEnum.DSTU3; - myMeasure = theMeasureR3; - } - - public AnyMeasure(org.hl7.fhir.r4.model.Measure theMeasureR4) { - myFhirVersion = FhirVersionEnum.R4; - myMeasure = theMeasureR4; - } - - public static AnyMeasure fromResource(IBaseResource theMeasure) { - if (theMeasure instanceof org.hl7.fhir.dstu3.model.Measure) { - return new AnyMeasure((org.hl7.fhir.dstu3.model.Measure) theMeasure); - } else if (theMeasure instanceof org.hl7.fhir.r4.model.Measure) { - return new AnyMeasure((org.hl7.fhir.r4.model.Measure) theMeasure); - } else { - throw new UnsupportedOperationException("Cannot convert " + theMeasure.getClass().getName() + " to AnyList"); - } - } - - public IBaseResource get() { - return myMeasure; - } - - public org.hl7.fhir.dstu3.model.Measure getDstu3() { - Validate.isTrue(myFhirVersion == FhirVersionEnum.DSTU3); - return (org.hl7.fhir.dstu3.model.Measure) get(); - } - - public org.hl7.fhir.r4.model.Measure getR4() { - Validate.isTrue(myFhirVersion == FhirVersionEnum.R4); - return (org.hl7.fhir.r4.model.Measure) get(); - } - - public void addIdentifier(String theSystem, String theValue) { - switch (myFhirVersion) { - case DSTU3: - getDstu3().getIdentifier().add(new org.hl7.fhir.dstu3.model.Identifier().setSystem(theSystem).setValue(theValue)); - break; - case R4: - getR4().getIdentifier().add(new org.hl7.fhir.r4.model.Identifier().setSystem(theSystem).setValue(theValue)); - break; - default: - throw new UnsupportedOperationException(myFhirVersion + " not supported"); - } - } - - public void addType(String theSystem, String theCode) { - switch (myFhirVersion) { - case DSTU3: - org.hl7.fhir.dstu3.model.CodeableConcept codeableConcept = new org.hl7.fhir.dstu3.model.CodeableConcept(); - codeableConcept.addCoding().setSystem(theSystem).setCode(theCode); - getDstu3().getType().add(codeableConcept); - break; - case R4: - org.hl7.fhir.r4.model.CodeableConcept codeableConceptR4 = new org.hl7.fhir.r4.model.CodeableConcept(); - codeableConceptR4.addCoding().setSystem(theSystem).setCode(theCode); - getR4().getType().add(codeableConceptR4); - break; - default: - throw new UnsupportedOperationException(myFhirVersion + " not supported"); - } - } - - public void addStringExtension(String theUrl, String theValue) { - switch (myFhirVersion) { - case DSTU3: - getDstu3().addExtension().setUrl(theUrl).setValue(new org.hl7.fhir.dstu3.model.StringType(theValue)); - break; - case R4: - getR4().addExtension().setUrl(theUrl).setValue(new org.hl7.fhir.r4.model.StringType(theValue)); - break; - default: - throw new UnsupportedOperationException(myFhirVersion + " not supported"); - } - } - - public String getStringExtensionValueOrNull(String theUrl) { - switch (myFhirVersion) { - case DSTU3: - return getStringExtensionValueOrNullDstu3(theUrl); - case R4: - return getStringExtensionValueOrNullR4(theUrl); - default: - throw new UnsupportedOperationException(myFhirVersion + " not supported"); - } - } - - private String getStringExtensionValueOrNullDstu3(String theUrl) { - List targetTypes = getDstu3().getExtensionsByUrl(theUrl); - if (targetTypes.size() < 1) { - return null; - } - org.hl7.fhir.dstu3.model.StringType targetType = (org.hl7.fhir.dstu3.model.StringType) targetTypes.get(0).getValue(); - return targetType.getValue(); - } - - private String getStringExtensionValueOrNullR4(String theUrl) { - List targetTypes = getR4().getExtensionsByUrl(theUrl); - if (targetTypes.size() < 1) { - return null; - } - org.hl7.fhir.r4.model.StringType targetType = (org.hl7.fhir.r4.model.StringType) targetTypes.get(0).getValue(); - return targetType.getValue(); - } - - public String getIdentifierFirstRep() { - switch (myFhirVersion) { - case DSTU3: - return getDstu3().getIdentifierFirstRep().getValue(); - case R4: - return getR4().getIdentifierFirstRep().getValue(); - default: - throw new UnsupportedOperationException(myFhirVersion + " not supported"); - } - } - - public void setComposedOf(String theReferenceId) { - switch (myFhirVersion) { - case DSTU3: - getRelatedArtifactDstu3(theReferenceId, org.hl7.fhir.dstu3.model.RelatedArtifact.RelatedArtifactType.COMPOSEDOF); - break; - case R4: - getRelatedArtifactR4(theReferenceId, org.hl7.fhir.r4.model.RelatedArtifact.RelatedArtifactType.COMPOSEDOF); - break; - default: - throw new UnsupportedOperationException(myFhirVersion + " not supported"); - } - } - - private void getRelatedArtifactDstu3(String theReferenceId, org.hl7.fhir.dstu3.model.RelatedArtifact.RelatedArtifactType theArtifactType) { - org.hl7.fhir.dstu3.model.RelatedArtifact artifact = new org.hl7.fhir.dstu3.model.RelatedArtifact(); - artifact.setType(theArtifactType); - artifact.setResource(new org.hl7.fhir.dstu3.model.Reference(theReferenceId)); - getDstu3().getRelatedArtifact().add(artifact); - } - - private void getRelatedArtifactR4(String theReferenceId, org.hl7.fhir.r4.model.RelatedArtifact.RelatedArtifactType theArtifactType) { - org.hl7.fhir.r4.model.RelatedArtifact artifact = new org.hl7.fhir.r4.model.RelatedArtifact(); - artifact.setType(theArtifactType); - artifact.setResource(theReferenceId); - getR4().getRelatedArtifact().add(artifact); - } - - public IBaseReference getComposedOf() { - switch (myFhirVersion) { - case DSTU3: - return getArtifactOfTypeDstu3(getDstu3(), org.hl7.fhir.dstu3.model.RelatedArtifact.RelatedArtifactType.COMPOSEDOF); - case R4: - return getArtifactOfTypeR4(getR4(), org.hl7.fhir.r4.model.RelatedArtifact.RelatedArtifactType.COMPOSEDOF); - default: - throw new UnsupportedOperationException(myFhirVersion + " not supported"); - } - } - - public void setPredecessor(String theReferenceId) { - switch (myFhirVersion) { - case DSTU3: - getRelatedArtifactDstu3(theReferenceId, org.hl7.fhir.dstu3.model.RelatedArtifact.RelatedArtifactType.PREDECESSOR); - break; - case R4: - getRelatedArtifactR4(theReferenceId, org.hl7.fhir.r4.model.RelatedArtifact.RelatedArtifactType.PREDECESSOR); - break; - default: - throw new UnsupportedOperationException(myFhirVersion + " not supported"); - } - } - - - public IBaseReference getPredecessor() { - switch (myFhirVersion) { - case DSTU3: - return getArtifactOfTypeDstu3(getDstu3(), org.hl7.fhir.dstu3.model.RelatedArtifact.RelatedArtifactType.PREDECESSOR); - case R4: - return getArtifactOfTypeR4(getR4(), org.hl7.fhir.r4.model.RelatedArtifact.RelatedArtifactType.PREDECESSOR); - default: - throw new UnsupportedOperationException(myFhirVersion + " not supported"); - } - } - - public IBaseReference getDerivedFrom() { - switch (myFhirVersion) { - case DSTU3: - return getArtifactOfTypeDstu3(getDstu3(), org.hl7.fhir.dstu3.model.RelatedArtifact.RelatedArtifactType.DERIVEDFROM); - case R4: - return getArtifactOfTypeR4(getR4(), org.hl7.fhir.r4.model.RelatedArtifact.RelatedArtifactType.DERIVEDFROM); - default: - throw new UnsupportedOperationException(myFhirVersion + " not supported"); - } - } - - public void setDerivedFrom(String theReferenceId) { - switch (myFhirVersion) { - case DSTU3: - getRelatedArtifactDstu3(theReferenceId, org.hl7.fhir.dstu3.model.RelatedArtifact.RelatedArtifactType.DERIVEDFROM); - break; - case R4: - getRelatedArtifactR4(theReferenceId, org.hl7.fhir.r4.model.RelatedArtifact.RelatedArtifactType.DERIVEDFROM); - break; - default: - throw new UnsupportedOperationException(myFhirVersion + " not supported"); - } - } - - public IBaseReference getSuccessor() { - switch (myFhirVersion) { - case DSTU3: - return getArtifactOfTypeDstu3(getDstu3(), org.hl7.fhir.dstu3.model.RelatedArtifact.RelatedArtifactType.SUCCESSOR); - case R4: - return getArtifactOfTypeR4(getR4(), org.hl7.fhir.r4.model.RelatedArtifact.RelatedArtifactType.SUCCESSOR); - default: - throw new UnsupportedOperationException(myFhirVersion + " not supported"); - } - } - - public void setSuccessor(String theReferenceId) { - switch (myFhirVersion) { - case DSTU3: - getRelatedArtifactDstu3(theReferenceId, org.hl7.fhir.dstu3.model.RelatedArtifact.RelatedArtifactType.SUCCESSOR); - break; - case R4: - getRelatedArtifactR4(theReferenceId, org.hl7.fhir.r4.model.RelatedArtifact.RelatedArtifactType.SUCCESSOR); - break; - default: - throw new UnsupportedOperationException(myFhirVersion + " not supported"); - } - } - - private IBaseReference getArtifactOfTypeDstu3(org.hl7.fhir.dstu3.model.Measure theMeasure, org.hl7.fhir.dstu3.model.RelatedArtifact.RelatedArtifactType theType) { - return theMeasure.getRelatedArtifact() - .stream() - .filter(artifact -> theType == artifact.getType()) - .map(org.hl7.fhir.dstu3.model.RelatedArtifact::getResource) - .findFirst() - .get(); - } - - private IBaseReference getArtifactOfTypeR4(org.hl7.fhir.r4.model.Measure theMeasure, org.hl7.fhir.r4.model.RelatedArtifact.RelatedArtifactType theType) { - return new org.hl7.fhir.r4.model.Reference(theMeasure.getRelatedArtifact() - .stream() - .filter(artifact -> theType == artifact.getType()) - .map(org.hl7.fhir.r4.model.RelatedArtifact::getResource) - .findFirst() - .get()); - } - - public void setPublisher(String thePublisher) { - switch (myFhirVersion) { - case DSTU3: - getDstu3().setPublisher(thePublisher); - break; - case R4: - getR4().setPublisher(thePublisher); - break; - default: - throw new UnsupportedOperationException(myFhirVersion + " not supported"); - } - } - - public String getPublisher() { - switch (myFhirVersion) { - case DSTU3: - return getDstu3().getPublisher(); - case R4: - return getR4().getPublisher(); - default: - throw new UnsupportedOperationException(myFhirVersion + " not supported"); - } - } - - public void setName(String theName) { - switch (myFhirVersion) { - case DSTU3: - getDstu3().setName(theName); - break; - case R4: - getR4().setName(theName); - break; - default: - throw new UnsupportedOperationException(myFhirVersion + " not supported"); - } - } - - public String getName() { - switch (myFhirVersion) { - case DSTU3: - return getDstu3().getName(); - case R4: - return getR4().getName(); - default: - throw new UnsupportedOperationException(myFhirVersion + " not supported"); - } - } - - public void setEffectivePeriod(Date start, Date end) { - switch (myFhirVersion) { - case DSTU3: - org.hl7.fhir.dstu3.model.Period effectivePeriod = new org.hl7.fhir.dstu3.model.Period(); - effectivePeriod.setStart(start); - effectivePeriod.setEnd(end); - getDstu3().setEffectivePeriod(effectivePeriod); - break; - case R4: - org.hl7.fhir.r4.model.Period effectivePeriodr4 = new org.hl7.fhir.r4.model.Period(); - effectivePeriodr4.setStart(start); - effectivePeriodr4.setEnd(end); - getR4().setEffectivePeriod(effectivePeriodr4); - break; - default: - throw new UnsupportedOperationException(myFhirVersion + " not supported"); - } - } - - public Date getEffectivePeriodStart() { - switch (myFhirVersion) { - case DSTU3: - return getDstu3().getEffectivePeriod().getStart(); - case R4: - return getR4().getEffectivePeriod().getStart(); - default: - throw new UnsupportedOperationException(myFhirVersion + " not supported"); - } - } - - public Date getEffectivePeriodEnd() { - switch (myFhirVersion) { - case DSTU3: - return getDstu3().getEffectivePeriod().getEnd(); - case R4: - return getR4().getEffectivePeriod().getEnd(); - default: - throw new UnsupportedOperationException(myFhirVersion + " not supported"); - } - } - - public void setTopics(List theTokenParamList) { - switch (myFhirVersion) { - case DSTU3: - setTopicsDstu3(theTokenParamList); - break; - case R4: - setTopicsR4(theTokenParamList); - break; - default: - throw new UnsupportedOperationException(myFhirVersion + " not supported"); - } - } - - private void setTopicsDstu3(List theTokenParamList) { - List topicList = new ArrayList<>(); - - for (TokenParam tokenParam : theTokenParamList) { - org.hl7.fhir.dstu3.model.CodeableConcept codeableConcept = new org.hl7.fhir.dstu3.model.CodeableConcept(); - codeableConcept.addCoding().setSystem(tokenParam.getSystem()).setCode(tokenParam.getValue()); - topicList.add(codeableConcept); - } - getDstu3().setTopic(topicList); - } - - private void setTopicsR4(List theTokenParamList) { - List topicList = new ArrayList<>(); - - for (TokenParam tokenParam : theTokenParamList) { - org.hl7.fhir.r4.model.CodeableConcept codeableConcept = new org.hl7.fhir.r4.model.CodeableConcept(); - codeableConcept.addCoding().setSystem(tokenParam.getSystem()).setCode(tokenParam.getValue()); - topicList.add(codeableConcept); - } - getR4().setTopic(topicList); - } - - public TokenParam getTopicFirstRep() { - switch (myFhirVersion) { - case DSTU3: - org.hl7.fhir.dstu3.model.Coding codingDstu3 = getDstu3().getTopicFirstRep().getCodingFirstRep(); - return new TokenParam(codingDstu3.getSystem(), codingDstu3.getCode()); - case R4: - org.hl7.fhir.r4.model.Coding codingR4 = getR4().getTopicFirstRep().getCodingFirstRep(); - return new TokenParam(codingR4.getSystem(), codingR4.getCode()); - default: - throw new UnsupportedOperationException(myFhirVersion + " not supported"); - } - } - - public TokenParam getTopicSecondRepOrNull() { - switch (myFhirVersion) { - case DSTU3: - if (getDstu3().getTopic().size() < 2) { - return null; - } - org.hl7.fhir.dstu3.model.Coding codingDstu3 = getDstu3().getTopic().get(1).getCodingFirstRep(); - return new TokenParam(codingDstu3.getSystem(), codingDstu3.getCode()); - case R4: - if (getR4().getTopic().size() < 2) { - return null; - } - org.hl7.fhir.r4.model.Coding codingR4 = getR4().getTopic().get(1).getCodingFirstRep(); - return new TokenParam(codingR4.getSystem(), codingR4.getCode()); - default: - throw new UnsupportedOperationException(myFhirVersion + " not supported"); - } - } -} diff --git a/hapi-fhir-jpaserver-model/src/test/java/ca/uhn/fhir/jpa/model/any/AnyListResourceTest.java b/hapi-fhir-jpaserver-model/src/test/java/ca/uhn/fhir/jpa/model/any/AnyListResourceTest.java deleted file mode 100644 index 46b71084710..00000000000 --- a/hapi-fhir-jpaserver-model/src/test/java/ca/uhn/fhir/jpa/model/any/AnyListResourceTest.java +++ /dev/null @@ -1,24 +0,0 @@ -package ca.uhn.fhir.jpa.model.any; - -import org.hl7.fhir.r5.model.ListResource; -import org.junit.Test; - -import static org.junit.Assert.assertEquals; - -public class AnyListResourceTest { - @Test - public void getCodeFirstRep() { - AnyListResource listResource = AnyListResource.fromResource(new ListResource()); - listResource.addCode("foo", "bar"); - assertEquals("foo", listResource.getCodeFirstRep().getSystem()); - assertEquals("bar", listResource.getCodeFirstRep().getValue()); - } - - @Test - public void getIdentifierFirstRep() { - AnyListResource listResource = AnyListResource.fromResource(new ListResource()); - listResource.addIdentifier("foo", "bar"); - assertEquals("foo", listResource.getIdentifierirstRep().getSystem()); - assertEquals("bar", listResource.getIdentifierirstRep().getValue()); - } -}